[flang-commits] [PATCH] D109931: [flang] Catch error: base of DATA statement object can't be a pointer

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Sep 16 14:48:36 PDT 2021


klausler created this revision.
klausler added a reviewer: clementval.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.

A pointer with subscripts, substring indices, or components cannot
be initialized by a DATA statement (although of course a whole pointer
can be so).  Catch the missing cases.


https://reviews.llvm.org/D109931

Files:
  flang/lib/Semantics/check-data.cpp
  flang/test/Semantics/data04.f90


Index: flang/test/Semantics/data04.f90
===================================================================
--- flang/test/Semantics/data04.f90
+++ flang/test/Semantics/data04.f90
@@ -65,6 +65,10 @@
       type(large) :: largeNumberArray(i)
       type(large) :: largeArray(5)
       character :: name(i)
+      type small
+        real :: x
+      end type
+      type(small), pointer :: sp
       !C877
       !ERROR: Default-initialized 'largenumber' must not be initialized in a DATA statement
       DATA(largeNumber % numsArray(j) % headOfTheList, j = 1, 10) / 10 * NULL() /
@@ -92,6 +96,8 @@
       !C876
       !ERROR: Automatic variable 'name' must not be initialized in a DATA statement
       DATA name( : 2) / 'Ancd' /
+      !ERROR: Target of pointer 'sp' must not be initialized in a DATA statement
+      DATA sp%x / 1.0 /
     end
   end
 
Index: flang/lib/Semantics/check-data.cpp
===================================================================
--- flang/lib/Semantics/check-data.cpp
+++ flang/lib/Semantics/check-data.cpp
@@ -70,7 +70,9 @@
                 : IsHostAssociated(symbol, scope)  ? "Host-associated object"
                 : IsUseAssociated(symbol, scope)   ? "USE-associated object"
                 : symbol.has<AssocEntityDetails>() ? "Construct association"
-                                                   : nullptr}) {
+                : IsPointer(symbol) && (hasComponent_ || hasSubscript_)
+                ? "Target of pointer"
+                : nullptr}) {
       context_.Say(source_,
           "%s '%s' must not be initialized in a DATA statement"_err_en_US,
           whyNot, symbol.name());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109931.373080.patch
Type: text/x-patch
Size: 1645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210916/e051b44f/attachment.bin>


More information about the flang-commits mailing list