[flang-commits] [flang] e6373de - [flang] Allow assignment to host association in BLOCK in PURE subprogram

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Sun Aug 7 14:49:01 PDT 2022


Author: Peter Klausler
Date: 2022-08-07T14:48:53-07:00
New Revision: e6373de53d35ebc0e9b0d62e664b7718f589b28e

URL: https://github.com/llvm/llvm-project/commit/e6373de53d35ebc0e9b0d62e664b7718f589b28e
DIFF: https://github.com/llvm/llvm-project/commit/e6373de53d35ebc0e9b0d62e664b7718f589b28e.diff

LOG: [flang] Allow assignment to host association in BLOCK in PURE subprogram

We need to distinguish BLOCK host association from subprogram host
association when checking assignments in PURE subprograms.
The specific case that is not allowed is an assignment to a variable
from the scope around the PURE subprogram.

Differential Revision: https://reviews.llvm.org/D131098

Added: 
    

Modified: 
    flang/include/flang/Semantics/tools.h
    flang/lib/Semantics/assignment.cpp
    flang/lib/Semantics/tools.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Semantics/tools.h b/flang/include/flang/Semantics/tools.h
index 52bac01d3bb7c..4f2ad1d349506 100644
--- a/flang/include/flang/Semantics/tools.h
+++ b/flang/include/flang/Semantics/tools.h
@@ -88,6 +88,7 @@ bool DoesScopeContain(const Scope *maybeAncestor, const Scope &maybeDescendent);
 bool DoesScopeContain(const Scope *, const Symbol &);
 bool IsUseAssociated(const Symbol &, const Scope &);
 bool IsHostAssociated(const Symbol &, const Scope &);
+bool IsHostAssociatedIntoSubprogram(const Symbol &, const Scope &);
 inline bool IsStmtFunction(const Symbol &symbol) {
   const auto *subprogram{symbol.detailsIf<SubprogramDetails>()};
   return subprogram && subprogram->stmtFunction();

diff  --git a/flang/lib/Semantics/assignment.cpp b/flang/lib/Semantics/assignment.cpp
index c95c924e345df..ece504ce6b1c2 100644
--- a/flang/lib/Semantics/assignment.cpp
+++ b/flang/lib/Semantics/assignment.cpp
@@ -103,7 +103,7 @@ static const char *WhyBaseObjectIsSuspicious(
     const Symbol &x, const Scope &scope) {
   // See C1594, first paragraph.  These conditions enable checks on both
   // left-hand and right-hand sides in various circumstances.
-  if (IsHostAssociated(x, scope)) {
+  if (IsHostAssociatedIntoSubprogram(x, scope)) {
     return "host-associated";
   } else if (IsUseAssociated(x, scope)) {
     return "USE-associated";

diff  --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp
index 5bb16bd29441a..05a9317eb0a1e 100644
--- a/flang/lib/Semantics/tools.cpp
+++ b/flang/lib/Semantics/tools.cpp
@@ -255,6 +255,12 @@ bool IsHostAssociated(const Symbol &symbol, const Scope &scope) {
       GetProgramUnitOrBlockConstructContaining(scope));
 }
 
+bool IsHostAssociatedIntoSubprogram(const Symbol &symbol, const Scope &scope) {
+  return DoesScopeContain(
+      &GetProgramUnitOrBlockConstructContaining(FollowHostAssoc(symbol)),
+      GetProgramUnitContaining(scope));
+}
+
 bool IsInStmtFunction(const Symbol &symbol) {
   if (const Symbol * function{symbol.owner().symbol()}) {
     return IsStmtFunction(*function);


        


More information about the flang-commits mailing list