[flang-commits] [PATCH] D140144: [flang] Catch attempts to initialize allocatable components with DATA statement

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Dec 15 11:43:35 PST 2022


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

Nice try, but no, you can't initialize an instance of a derived type using a
structure constructor that has a component corresponding to an allocatable
component.


https://reviews.llvm.org/D140144

Files:
  flang/lib/Evaluate/initial-image.cpp
  flang/test/Semantics/data01.f90


Index: flang/test/Semantics/data01.f90
===================================================================
--- flang/test/Semantics/data01.f90
+++ flang/test/Semantics/data01.f90
@@ -11,6 +11,9 @@
   integer, parameter :: repeat = -1
   integer :: myAge = 2
   type(person) associated
+  type hasAlloc
+    integer, allocatable :: a(:)
+  end type
 end
 
 subroutine CheckRepeat
@@ -63,4 +66,7 @@
   data y / a(i) /
   !ERROR: DATA statement value 'b(1_8)' for 'z' is not a constant
   data z / b(1) /
+  type(hasAlloc) ha
+  !ERROR: DATA statement value 'hasalloc(a=0_4)' for 'ha' is not a constant
+  data ha / hasAlloc(0) /
 end
Index: flang/lib/Evaluate/initial-image.cpp
===================================================================
--- flang/lib/Evaluate/initial-image.cpp
+++ flang/lib/Evaluate/initial-image.cpp
@@ -33,6 +33,8 @@
             return SizeMismatch;
           } else if (IsPointer(component)) {
             AddPointer(offset + component.offset(), indExpr.value());
+          } else if (IsAllocatable(component) || IsAutomatic(component)) {
+            return NotAConstant;
           } else {
             Result added{Add(offset + component.offset(), component.size(),
                 indExpr.value(), context)};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140144.483272.patch
Type: text/x-patch
Size: 1247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221215/6ba28878/attachment.bin>


More information about the flang-commits mailing list