[PATCH] D87535: [flang] Fix bug for forward referenced type

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 12:05:11 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG398fcf224b8d: [flang] Fix bug for forward referenced type (authored by PeteSteinfeld).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87535

Files:
  flang/lib/Semantics/symbol.cpp
  flang/test/Semantics/bad-forward-type.f90


Index: flang/test/Semantics/bad-forward-type.f90
===================================================================
--- flang/test/Semantics/bad-forward-type.f90
+++ flang/test/Semantics/bad-forward-type.f90
@@ -70,3 +70,13 @@
   type, extends(undef) :: t
   end type
 end subroutine
+
+subroutine s8
+  !ERROR: Derived type 't2' was used but never defined
+  !ERROR: The derived type 't2' was forward-referenced but not defined
+  implicit type(t2)(x)
+  parameter(y=t2(12.3))
+  type t2
+    real :: c
+  end type
+end subroutine
Index: flang/lib/Semantics/symbol.cpp
===================================================================
--- flang/lib/Semantics/symbol.cpp
+++ flang/lib/Semantics/symbol.cpp
@@ -541,13 +541,11 @@
 
 const Symbol *Symbol::GetParentComponent(const Scope *scope) const {
   if (const auto *dtDetails{detailsIf<DerivedTypeDetails>()}) {
-    if (!scope) {
-      scope = scope_;
+    if (const Scope * localScope{scope ? scope : scope_}) {
+      return dtDetails->GetParentComponent(DEREF(localScope));
     }
-    return dtDetails->GetParentComponent(DEREF(scope));
-  } else {
-    return nullptr;
   }
+  return nullptr;
 }
 
 void DerivedTypeDetails::add_component(const Symbol &symbol) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87535.291308.patch
Type: text/x-patch
Size: 1225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200911/750163ed/attachment.bin>


More information about the llvm-commits mailing list