[flang-commits] [PATCH] D150712: [flang] Fix bogus errors about CONTIGUOUS attribute

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue May 16 13:14:30 PDT 2023


klausler created this revision.
klausler added a reviewer: vzakhari.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

Incorrect error messages were issuing for symbol table entries
with the CONTIGUOUS attribute that didn't deserve them, like
host association symbols.  Put the CONTIGUOUS check into
CheckObjectEntity().


https://reviews.llvm.org/D150712

Files:
  flang/lib/Semantics/check-declarations.cpp
  flang/test/Semantics/resolve14.f90


Index: flang/test/Semantics/resolve14.f90
===================================================================
--- flang/test/Semantics/resolve14.f90
+++ flang/test/Semantics/resolve14.f90
@@ -27,6 +27,12 @@
   contiguous w
   !ERROR: 'z' is use-associated from module 'm2' and cannot be re-declared
   integer z
+  real, target :: a(10)
+  real, contiguous, pointer :: p(:) => a
   !ERROR: Reference to 'y' is ambiguous
   y = 1
+ contains
+  subroutine inner
+    p(1) = 0. ! ok - check for regression on contiguous host assoc.
+  end subroutine
 end
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -261,19 +261,6 @@
     CheckExplicitSave(symbol);
   }
   const auto *object{symbol.detailsIf<ObjectEntityDetails>()};
-  if (symbol.attrs().test(Attr::CONTIGUOUS)) {
-    if ((!object && !symbol.has<UseDetails>()) ||
-        !((IsPointer(symbol) && symbol.Rank() > 0) || IsAssumedShape(symbol) ||
-            evaluate::IsAssumedRank(symbol))) {
-      if (symbol.owner().IsDerivedType()) { // C752
-        messages_.Say(
-            "A CONTIGUOUS component must be an array with the POINTER attribute"_err_en_US);
-      } else { // C830
-        messages_.Say(
-            "CONTIGUOUS entity must be an array pointer, assumed-shape, or assumed-rank"_err_en_US);
-      }
-    }
-  }
   CheckGlobalName(symbol);
   if (isDone) {
     return; // following checks do not apply
@@ -848,6 +835,17 @@
         "'%s' is a data object and may not be EXTERNAL"_err_en_US,
         symbol.name());
   }
+  if (symbol.attrs().test(Attr::CONTIGUOUS)) {
+    if ((IsPointer(symbol) && symbol.Rank() > 0) || IsAssumedShape(symbol) ||
+        evaluate::IsAssumedRank(symbol)) {
+    } else if (symbol.owner().IsDerivedType()) { // C752
+      messages_.Say(
+          "A CONTIGUOUS component must be an array with the POINTER attribute"_err_en_US);
+    } else { // C830
+      messages_.Say(
+          "CONTIGUOUS entity must be an array pointer, assumed-shape, or assumed-rank"_err_en_US);
+    }
+  }
 }
 
 void CheckHelper::CheckPointerInitialization(const Symbol &symbol) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150712.522754.patch
Type: text/x-patch
Size: 2241 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230516/d9f17e56/attachment-0001.bin>


More information about the flang-commits mailing list