-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[flang] fix scoping of cray pointer declarations and add check for initialization #136776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-flang-fir-hlfir Author: Andre Kuhlenschmidt (akuhlens) ChangesThis PR:
Closes #135579 Full diff: https://github.com/llvm/llvm-project/pull/136776.diff 5 Files Affected:
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 8d5e034f8624b..6cc4665532385 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -963,7 +963,17 @@ void CheckHelper::CheckObjectEntity(
"'%s' is a data object and may not be EXTERNAL"_err_en_US,
symbol.name());
}
-
+ if (symbol.test(Symbol::Flag::CrayPointee)) {
+ // NB, IsSaved was too smart here.
+ if (details.init()) {
+ messages_.Say(
+ "Cray pointee '%s' may not be initialized"_err_en_US, symbol.name());
+ } else if (symbol.attrs().test(Attr::SAVE) ||
+ symbol.implicitAttrs().test(Attr::SAVE)) {
+ messages_.Say(
+ "Cray pointee '%s' may not be SAVE"_err_en_US, symbol.name());
+ }
+ }
if (derived) {
bool isUnsavedLocal{
isLocalVariable && !IsAllocatable(symbol) && !IsSaved(symbol)};
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index f1d2ba4078236..e0550b3724bef 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -6650,7 +6650,7 @@ bool DeclarationVisitor::Pre(const parser::BasedPointer &) {
void DeclarationVisitor::Post(const parser::BasedPointer &bp) {
const parser::ObjectName &pointerName{std::get<0>(bp.t)};
- auto *pointer{FindSymbol(pointerName)};
+ auto *pointer{FindInScope(pointerName)};
if (!pointer) {
pointer = &MakeSymbol(pointerName, ObjectEntityDetails{});
} else if (!ConvertToObjectEntity(*pointer)) {
diff --git a/flang/lib/Semantics/semantics.cpp b/flang/lib/Semantics/semantics.cpp
index 10a01039ea0ae..e07054f8ec564 100644
--- a/flang/lib/Semantics/semantics.cpp
+++ b/flang/lib/Semantics/semantics.cpp
@@ -731,6 +731,7 @@ void DoDumpSymbols(llvm::raw_ostream &os, const Scope &scope, int indent) {
for (const auto &[pointee, pointer] : scope.crayPointers()) {
os << " (" << pointer->name() << ',' << pointee << ')';
}
+ os << '\n';
}
for (const auto &pair : scope.commonBlocks()) {
const auto &symbol{*pair.second};
diff --git a/flang/test/Lower/OpenMP/cray-pointers01.f90 b/flang/test/Lower/OpenMP/cray-pointers01.f90
index 87692ccbadfe3..d3a5a3cdd39a3 100644
--- a/flang/test/Lower/OpenMP/cray-pointers01.f90
+++ b/flang/test/Lower/OpenMP/cray-pointers01.f90
@@ -33,7 +33,7 @@ subroutine set_cray_pointer
end module
program test_cray_pointers_01
- real*8, save :: var(*)
+ real*8 :: var(*)
! CHECK: %[[BOX_ALLOCA:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf64>>>
! CHECK: %[[IVAR_ALLOCA:.*]] = fir.alloca i64 {bindc_name = "ivar", uniq_name = "_QFEivar"}
! CHECK: %[[IVAR_DECL_01:.*]]:2 = hlfir.declare %[[IVAR_ALLOCA]] {uniq_name = "_QFEivar"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
diff --git a/flang/test/Semantics/declarations08.f90 b/flang/test/Semantics/declarations08.f90
index bd14131b33c28..140ff710228c1 100644
--- a/flang/test/Semantics/declarations08.f90
+++ b/flang/test/Semantics/declarations08.f90
@@ -5,4 +5,10 @@
!ERROR: Cray pointee 'x' may not be a member of a COMMON block
common x
equivalence(y,z)
+!ERROR: Cray pointee 'v' may not be initialized
+real :: v = 42.0
+pointer(p,v)
+!ERROR: Cray pointee 'u' may not be SAVE
+save u
+pointer(p, u)
end
|
@llvm/pr-subscribers-flang-openmp Author: Andre Kuhlenschmidt (akuhlens) ChangesThis PR:
Closes #135579 Full diff: https://github.com/llvm/llvm-project/pull/136776.diff 5 Files Affected:
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 8d5e034f8624b..6cc4665532385 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -963,7 +963,17 @@ void CheckHelper::CheckObjectEntity(
"'%s' is a data object and may not be EXTERNAL"_err_en_US,
symbol.name());
}
-
+ if (symbol.test(Symbol::Flag::CrayPointee)) {
+ // NB, IsSaved was too smart here.
+ if (details.init()) {
+ messages_.Say(
+ "Cray pointee '%s' may not be initialized"_err_en_US, symbol.name());
+ } else if (symbol.attrs().test(Attr::SAVE) ||
+ symbol.implicitAttrs().test(Attr::SAVE)) {
+ messages_.Say(
+ "Cray pointee '%s' may not be SAVE"_err_en_US, symbol.name());
+ }
+ }
if (derived) {
bool isUnsavedLocal{
isLocalVariable && !IsAllocatable(symbol) && !IsSaved(symbol)};
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index f1d2ba4078236..e0550b3724bef 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -6650,7 +6650,7 @@ bool DeclarationVisitor::Pre(const parser::BasedPointer &) {
void DeclarationVisitor::Post(const parser::BasedPointer &bp) {
const parser::ObjectName &pointerName{std::get<0>(bp.t)};
- auto *pointer{FindSymbol(pointerName)};
+ auto *pointer{FindInScope(pointerName)};
if (!pointer) {
pointer = &MakeSymbol(pointerName, ObjectEntityDetails{});
} else if (!ConvertToObjectEntity(*pointer)) {
diff --git a/flang/lib/Semantics/semantics.cpp b/flang/lib/Semantics/semantics.cpp
index 10a01039ea0ae..e07054f8ec564 100644
--- a/flang/lib/Semantics/semantics.cpp
+++ b/flang/lib/Semantics/semantics.cpp
@@ -731,6 +731,7 @@ void DoDumpSymbols(llvm::raw_ostream &os, const Scope &scope, int indent) {
for (const auto &[pointee, pointer] : scope.crayPointers()) {
os << " (" << pointer->name() << ',' << pointee << ')';
}
+ os << '\n';
}
for (const auto &pair : scope.commonBlocks()) {
const auto &symbol{*pair.second};
diff --git a/flang/test/Lower/OpenMP/cray-pointers01.f90 b/flang/test/Lower/OpenMP/cray-pointers01.f90
index 87692ccbadfe3..d3a5a3cdd39a3 100644
--- a/flang/test/Lower/OpenMP/cray-pointers01.f90
+++ b/flang/test/Lower/OpenMP/cray-pointers01.f90
@@ -33,7 +33,7 @@ subroutine set_cray_pointer
end module
program test_cray_pointers_01
- real*8, save :: var(*)
+ real*8 :: var(*)
! CHECK: %[[BOX_ALLOCA:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf64>>>
! CHECK: %[[IVAR_ALLOCA:.*]] = fir.alloca i64 {bindc_name = "ivar", uniq_name = "_QFEivar"}
! CHECK: %[[IVAR_DECL_01:.*]]:2 = hlfir.declare %[[IVAR_ALLOCA]] {uniq_name = "_QFEivar"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
diff --git a/flang/test/Semantics/declarations08.f90 b/flang/test/Semantics/declarations08.f90
index bd14131b33c28..140ff710228c1 100644
--- a/flang/test/Semantics/declarations08.f90
+++ b/flang/test/Semantics/declarations08.f90
@@ -5,4 +5,10 @@
!ERROR: Cray pointee 'x' may not be a member of a COMMON block
common x
equivalence(y,z)
+!ERROR: Cray pointee 'v' may not be initialized
+real :: v = 42.0
+pointer(p,v)
+!ERROR: Cray pointee 'u' may not be SAVE
+save u
+pointer(p, u)
end
|
@llvm/pr-subscribers-flang-semantics Author: Andre Kuhlenschmidt (akuhlens) ChangesThis PR:
Closes #135579 Full diff: https://github.com/llvm/llvm-project/pull/136776.diff 5 Files Affected:
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 8d5e034f8624b..6cc4665532385 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -963,7 +963,17 @@ void CheckHelper::CheckObjectEntity(
"'%s' is a data object and may not be EXTERNAL"_err_en_US,
symbol.name());
}
-
+ if (symbol.test(Symbol::Flag::CrayPointee)) {
+ // NB, IsSaved was too smart here.
+ if (details.init()) {
+ messages_.Say(
+ "Cray pointee '%s' may not be initialized"_err_en_US, symbol.name());
+ } else if (symbol.attrs().test(Attr::SAVE) ||
+ symbol.implicitAttrs().test(Attr::SAVE)) {
+ messages_.Say(
+ "Cray pointee '%s' may not be SAVE"_err_en_US, symbol.name());
+ }
+ }
if (derived) {
bool isUnsavedLocal{
isLocalVariable && !IsAllocatable(symbol) && !IsSaved(symbol)};
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index f1d2ba4078236..e0550b3724bef 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -6650,7 +6650,7 @@ bool DeclarationVisitor::Pre(const parser::BasedPointer &) {
void DeclarationVisitor::Post(const parser::BasedPointer &bp) {
const parser::ObjectName &pointerName{std::get<0>(bp.t)};
- auto *pointer{FindSymbol(pointerName)};
+ auto *pointer{FindInScope(pointerName)};
if (!pointer) {
pointer = &MakeSymbol(pointerName, ObjectEntityDetails{});
} else if (!ConvertToObjectEntity(*pointer)) {
diff --git a/flang/lib/Semantics/semantics.cpp b/flang/lib/Semantics/semantics.cpp
index 10a01039ea0ae..e07054f8ec564 100644
--- a/flang/lib/Semantics/semantics.cpp
+++ b/flang/lib/Semantics/semantics.cpp
@@ -731,6 +731,7 @@ void DoDumpSymbols(llvm::raw_ostream &os, const Scope &scope, int indent) {
for (const auto &[pointee, pointer] : scope.crayPointers()) {
os << " (" << pointer->name() << ',' << pointee << ')';
}
+ os << '\n';
}
for (const auto &pair : scope.commonBlocks()) {
const auto &symbol{*pair.second};
diff --git a/flang/test/Lower/OpenMP/cray-pointers01.f90 b/flang/test/Lower/OpenMP/cray-pointers01.f90
index 87692ccbadfe3..d3a5a3cdd39a3 100644
--- a/flang/test/Lower/OpenMP/cray-pointers01.f90
+++ b/flang/test/Lower/OpenMP/cray-pointers01.f90
@@ -33,7 +33,7 @@ subroutine set_cray_pointer
end module
program test_cray_pointers_01
- real*8, save :: var(*)
+ real*8 :: var(*)
! CHECK: %[[BOX_ALLOCA:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf64>>>
! CHECK: %[[IVAR_ALLOCA:.*]] = fir.alloca i64 {bindc_name = "ivar", uniq_name = "_QFEivar"}
! CHECK: %[[IVAR_DECL_01:.*]]:2 = hlfir.declare %[[IVAR_ALLOCA]] {uniq_name = "_QFEivar"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
diff --git a/flang/test/Semantics/declarations08.f90 b/flang/test/Semantics/declarations08.f90
index bd14131b33c28..140ff710228c1 100644
--- a/flang/test/Semantics/declarations08.f90
+++ b/flang/test/Semantics/declarations08.f90
@@ -5,4 +5,10 @@
!ERROR: Cray pointee 'x' may not be a member of a COMMON block
common x
equivalence(y,z)
+!ERROR: Cray pointee 'v' may not be initialized
+real :: v = 42.0
+pointer(p,v)
+!ERROR: Cray pointee 'u' may not be SAVE
+save u
+pointer(p, u)
end
|
…itialization (llvm#136776) This PR: - makes Cray pointer declarations shadow previous bindings instead of modifying them, - errors when the pointee of a cray pointee has the SAVE attribute, and - adds a missing newline after dumping the list of cray pointers in a scope. Closes llvm#135579
…itialization (llvm#136776) This PR: - makes Cray pointer declarations shadow previous bindings instead of modifying them, - errors when the pointee of a cray pointee has the SAVE attribute, and - adds a missing newline after dumping the list of cray pointers in a scope. Closes llvm#135579
…itialization (llvm#136776) This PR: - makes Cray pointer declarations shadow previous bindings instead of modifying them, - errors when the pointee of a cray pointee has the SAVE attribute, and - adds a missing newline after dumping the list of cray pointers in a scope. Closes llvm#135579
…itialization (llvm#136776) This PR: - makes Cray pointer declarations shadow previous bindings instead of modifying them, - errors when the pointee of a cray pointee has the SAVE attribute, and - adds a missing newline after dumping the list of cray pointers in a scope. Closes llvm#135579
This PR:
Closes #135579