[flang-commits] [PATCH] D125116: [flang] Ensure that structure constructors fold parameter references

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri May 6 11:55:21 PDT 2022


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a project: All.
klausler requested review of this revision.

Structure contructors for instances of parameterized derived types
must have their components' values folded in the context of the values
of the type parameters.


https://reviews.llvm.org/D125116

Files:
  flang/lib/Evaluate/fold.cpp
  flang/test/Semantics/structconst05.f90


Index: flang/test/Semantics/structconst05.f90
===================================================================
--- /dev/null
+++ 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
Index: flang/lib/Evaluate/fold.cpp
===================================================================
--- flang/lib/Evaluate/fold.cpp
+++ flang/lib/Evaluate/fold.cpp
@@ -67,6 +67,7 @@
     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)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125116.427702.patch
Type: text/x-patch
Size: 1016 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220506/5e42dc40/attachment.bin>


More information about the flang-commits mailing list