From: Peter Klausler Date: Tue, 7 Feb 2023 23:09:03 +0000 (-0800) Subject: [flang] Catch obscure structure constructor error X-Git-Tag: upstream/17.0.6~17647 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b57bc158ea462c897211aa64c3b4071fdac2f12c;p=platform%2Fupstream%2Fllvm.git [flang] Catch obscure structure constructor error A scalar value in a structure constructor may correspond to an array component in the derived type only when that component has a shape to which the scalar value may be expanded. Differential Revision: https://reviews.llvm.org/D143822 --- diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp index 14dcb71..8f20fc7 100644 --- a/flang/lib/Semantics/expression.cpp +++ b/flang/lib/Semantics/expression.cpp @@ -2024,8 +2024,9 @@ MaybeExpr ExpressionAnalyzer::Analyze( "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, diff --git a/flang/test/Semantics/data01.f90 b/flang/test/Semantics/data01.f90 index 4de7ff9..9046487 100644 --- a/flang/test/Semantics/data01.f90 +++ b/flang/test/Semantics/data01.f90 @@ -12,7 +12,7 @@ module m1 integer :: myAge = 2 type(person) associated type hasAlloc - integer, allocatable :: a(:) + integer, allocatable :: a end type end diff --git a/flang/test/Semantics/structconst06.f90 b/flang/test/Semantics/structconst06.f90 new file mode 100644 index 0000000..d5a4041 --- /dev/null +++ b/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