[flang-commits] [PATCH] D129681: [flang] Avoid crash from forward referenced derived type

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Jul 13 16:58:40 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb7f83142701b: [flang] Avoid crash from forward referenced derived type (authored by klausler).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129681

Files:
  flang/lib/Semantics/resolve-names.cpp
  flang/test/Semantics/symbol21.f90


Index: flang/test/Semantics/symbol21.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/symbol21.f90
@@ -0,0 +1,30 @@
+! RUN: %python %S/test_symbols.py %s %flang_fc1
+! Derived type forward reference regression case
+
+ !DEF: /MainProgram1/t2 DerivedType
+ type :: t2
+  !DEF: /MainProgram1/t1 DerivedType
+  !DEF: /MainProgram1/t2/ptr POINTER ObjectEntity TYPE(t1)
+  type(t1), pointer :: ptr
+ end type
+ !REF: /MainProgram1/t1
+ type :: t1
+  !DEF: /MainProgram1/t1/a ObjectEntity REAL(4)
+  real :: a
+  !REF: /MainProgram1/t2
+  !DEF: /MainProgram1/t1/p2 POINTER ObjectEntity TYPE(t2)
+  type(t2), pointer :: p2
+  !REF: /MainProgram1/t1
+  !DEF: /MainProgram1/t1/p1 POINTER ObjectEntity TYPE(t1)
+  type(t1), pointer :: p1
+ end type
+ !REF: /MainProgram1/t1
+ !DEF: /MainProgram1/x1 POINTER ObjectEntity TYPE(t1)
+ !DEF: /MainProgram1/x2 POINTER ObjectEntity TYPE(t1)
+ type(t1), pointer :: x1, x2
+ !REF: /MainProgram1/x2
+ !REF: /MainProgram1/t1/p1
+ !REF: /MainProgram1/t1/a
+ !REF: /MainProgram1/x1
+ x2%p1%a = x1%a
+end program
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -4418,7 +4418,6 @@
       spec->AddRawParamValue(optKeyword, std::move(param));
     }
   }
-
   // The DerivedTypeSpec *spec is used initially as a search key.
   // If it turns out to have the same name and actual parameter
   // value expressions as another DerivedTypeSpec in the current
@@ -6645,7 +6644,8 @@
       MakePlaceholder(component, miscKind);
       return &component;
     }
-  } else if (const DerivedTypeSpec * derived{type->AsDerived()}) {
+  } else if (DerivedTypeSpec * derived{type->AsDerived()}) {
+    derived->Instantiate(currScope()); // in case of forward referenced type
     if (const Scope * scope{derived->scope()}) {
       if (Resolve(component, scope->FindComponent(component.source))) {
         if (auto msg{


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129681.444463.patch
Type: text/x-patch
Size: 2047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220713/e1bd508d/attachment-0001.bin>


More information about the flang-commits mailing list