[flang-commits] [flang] 12ec5b2 - [flang] Catch attempts to initialize allocatable components with DATA statement

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Dec 16 18:16:43 PST 2022


Author: Peter Klausler
Date: 2022-12-16T18:16:30-08:00
New Revision: 12ec5b20c2c12bb9fec37aebed8355577698c75a

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

LOG: [flang] Catch attempts to initialize allocatable components with DATA statement

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.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/initial-image.cpp b/flang/lib/Evaluate/initial-image.cpp
index cf70b6e888706..0dee0eae059b0 100644
--- a/flang/lib/Evaluate/initial-image.cpp
+++ b/flang/lib/Evaluate/initial-image.cpp
@@ -33,6 +33,8 @@ auto InitialImage::Add(ConstantSubscript offset, std::size_t bytes,
             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)};

diff  --git a/flang/test/Semantics/data01.f90 b/flang/test/Semantics/data01.f90
index 0bc50056ece81..4de7ff917446d 100644
--- a/flang/test/Semantics/data01.f90
+++ b/flang/test/Semantics/data01.f90
@@ -11,6 +11,9 @@ module m1
   integer, parameter :: repeat = -1
   integer :: myAge = 2
   type(person) associated
+  type hasAlloc
+    integer, allocatable :: a(:)
+  end type
 end
 
 subroutine CheckRepeat
@@ -63,4 +66,7 @@ subroutine CheckValue
   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


        


More information about the flang-commits mailing list