[flang-commits] [flang] 398fcf2 - [flang] Fix bug for forward referenced type

Peter Steinfeld via flang-commits flang-commits at lists.llvm.org
Fri Sep 11 12:05:02 PDT 2020


Author: Peter Steinfeld
Date: 2020-09-11T11:58:53-07:00
New Revision: 398fcf224b8dd0968f27cdcc7e75bb0bc8ed6d09

URL: https://github.com/llvm/llvm-project/commit/398fcf224b8dd0968f27cdcc7e75bb0bc8ed6d09
DIFF: https://github.com/llvm/llvm-project/commit/398fcf224b8dd0968f27cdcc7e75bb0bc8ed6d09.diff

LOG: [flang] Fix bug for forward referenced type

A type name in an IMPLICIT declaration that was later used in a PARAMETER
statement caused problems because the default symbol scope had not yet been
initialized.  I avoided dereferencing in the situation where the default scope
was uninitialized and added a test that triggers the problem.

Differential Revision: https://reviews.llvm.org/D87535

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/symbol.cpp b/flang/lib/Semantics/symbol.cpp
index e0d80ec6d1c8..c15c60406c36 100644
--- a/flang/lib/Semantics/symbol.cpp
+++ b/flang/lib/Semantics/symbol.cpp
@@ -541,13 +541,11 @@ const DerivedTypeSpec *Symbol::GetParentTypeSpec(const Scope *scope) const {
 
 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) {

diff  --git a/flang/test/Semantics/bad-forward-type.f90 b/flang/test/Semantics/bad-forward-type.f90
index 5fe17ad833ad..2a8cbc0c9b1a 100644
--- a/flang/test/Semantics/bad-forward-type.f90
+++ b/flang/test/Semantics/bad-forward-type.f90
@@ -70,3 +70,13 @@ subroutine s7(x)
   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


        


More information about the flang-commits mailing list