[flang-commits] [flang] a054c88 - [flang] Ensure that structure constructors fold parameter references
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Mon May 9 16:09:59 PDT 2022
Author: Peter Klausler
Date: 2022-05-09T16:09:49-07:00
New Revision: a054c882053e63e6fce7b412a93dc7fc228f11fd
URL: https://github.com/llvm/llvm-project/commit/a054c882053e63e6fce7b412a93dc7fc228f11fd
DIFF: https://github.com/llvm/llvm-project/commit/a054c882053e63e6fce7b412a93dc7fc228f11fd.diff
LOG: [flang] Ensure that structure constructors fold parameter references
Structure contructors for instances of parameterized derived types
must have their components' values folded in the context of the values
of the type parameters.
Differential Revision: https://reviews.llvm.org/D125116
Added:
flang/test/Semantics/structconst05.f90
Modified:
flang/lib/Evaluate/fold.cpp
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/fold.cpp b/flang/lib/Evaluate/fold.cpp
index ae8b586f4717..92ea4f130df6 100644
--- a/flang/lib/Evaluate/fold.cpp
+++ b/flang/lib/Evaluate/fold.cpp
@@ -67,6 +67,7 @@ Expr<SomeDerived> FoldOperation(
FoldingContext &context, StructureConstructor &&structure) {
StructureConstructor ctor{structure.derivedTypeSpec()};
bool isConstant{true};
+ auto restorer{context.WithPDTInstance(structure.derivedTypeSpec())};
for (auto &&[symbol, value] : std::move(structure)) {
auto expr{Fold(context, std::move(value.value()))};
if (IsPointer(symbol)) {
diff --git a/flang/test/Semantics/structconst05.f90 b/flang/test/Semantics/structconst05.f90
new file mode 100644
index 000000000000..236a890660d9
--- /dev/null
+++ b/flang/test/Semantics/structconst05.f90
@@ -0,0 +1,9 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! Ensure that PDT instance structure constructors can be folded to constants
+module m1
+ type :: pdt(k)
+ integer, len :: k
+ character(len=k) :: x, y = "def"
+ end type
+ type(pdt(4)) :: v = pdt(4)("abc")
+end module
More information about the flang-commits
mailing list