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

peter klausler via flang-commits flang-commits at lists.llvm.org
Wed Sep 22 14:41:56 PDT 2021


Author: peter klausler
Date: 2021-09-22T14:41:48-07:00
New Revision: 57705df2de9db50adca4a19ca32ee928990cc380

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

LOG: [flang] Catch error: base of DATA statement object can't be a pointer

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.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-data.cpp b/flang/lib/Semantics/check-data.cpp
index 7dd0a7a273b9b..338bd91f1da05 100644
--- a/flang/lib/Semantics/check-data.cpp
+++ b/flang/lib/Semantics/check-data.cpp
@@ -70,7 +70,9 @@ class DataVarChecker : public evaluate::AllTraverse<DataVarChecker, true> {
                 : 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());

diff  --git a/flang/test/Semantics/data04.f90 b/flang/test/Semantics/data04.f90
index 5d862b2c23460..b89078fc5e109 100644
--- a/flang/test/Semantics/data04.f90
+++ b/flang/test/Semantics/data04.f90
@@ -65,6 +65,10 @@ subroutine CheckObject(i)
       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 @@ subroutine CheckObject(i)
       !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
 


        


More information about the flang-commits mailing list