[flang-commits] [flang] b57bc15 - [flang] Catch obscure structure constructor error
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Mon Feb 13 15:24:46 PST 2023
Author: Peter Klausler
Date: 2023-02-13T15:24:35-08:00
New Revision: b57bc158ea462c897211aa64c3b4071fdac2f12c
URL: https://github.com/llvm/llvm-project/commit/b57bc158ea462c897211aa64c3b4071fdac2f12c
DIFF: https://github.com/llvm/llvm-project/commit/b57bc158ea462c897211aa64c3b4071fdac2f12c.diff
LOG: [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
Added:
flang/test/Semantics/structconst06.f90
Modified:
flang/lib/Semantics/expression.cpp
flang/test/Semantics/data01.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 14dcb716b76e..8f20fc73a3a1 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 4de7ff917446..9046487fa176 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 000000000000..d5a40410ea63
--- /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
More information about the flang-commits
mailing list