[flang-commits] [PATCH] D143822: [flang] Catch obscure structure constructor error

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Feb 13 15:24:51 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb57bc158ea46: [flang] Catch obscure structure constructor error (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143822/new/

https://reviews.llvm.org/D143822

Files:
  flang/lib/Semantics/expression.cpp
  flang/test/Semantics/data01.f90
  flang/test/Semantics/structconst06.f90


Index: flang/test/Semantics/structconst06.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/structconst06.f90
@@ -0,0 +1,9 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! Don't expand scalars for allocatable components.
+module m
+  type t
+    real, allocatable :: a(:)
+  end type
+  !ERROR: Scalar value cannot be expanded to shape of array component 'a'
+  type(t) :: x = t(0.)
+end module
Index: flang/test/Semantics/data01.f90
===================================================================
--- flang/test/Semantics/data01.f90
+++ flang/test/Semantics/data01.f90
@@ -12,7 +12,7 @@
   integer :: myAge = 2
   type(person) associated
   type hasAlloc
-    integer, allocatable :: a(:)
+    integer, allocatable :: a
   end type
 end
 
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -2024,8 +2024,9 @@
                         "component", "value")};
                 if (checked && *checked && GetRank(*componentShape) > 0 &&
                     GetRank(*valueShape) == 0 &&
-                    !IsExpandableScalar(*converted, GetFoldingContext(),
-                        *componentShape, true /*admit PURE call*/)) {
+                    (IsDeferredShape(*symbol) ||
+                        !IsExpandableScalar(*converted, GetFoldingContext(),
+                            *componentShape, true /*admit PURE call*/))) {
                   AttachDeclaration(
                       Say(expr.source,
                           "Scalar value cannot be expanded to shape of array component '%s'"_err_en_US,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143822.497132.patch
Type: text/x-patch
Size: 1727 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230213/d3e2e9cb/attachment.bin>


More information about the flang-commits mailing list