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

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 15:24:02 PDT 2020


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

Changed prior to commit:
  https://reviews.llvm.org/D87535?vs=291682&id=291707#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87535

Files:
  flang/lib/Semantics/expression.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
@@ -72,9 +72,8 @@
 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)
+  !ERROR: Cannot construct value for derived type 't2' before it is defined
   parameter(y=t2(12.3))
   type t2
     real :: c
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -1996,11 +1996,18 @@
       const auto &designator{std::get<parser::ProcedureDesignator>(call.t)};
       if (const auto *name{std::get_if<parser::Name>(&designator.u)}) {
         semantics::Scope &scope{context_.FindScope(name->source)};
+        semantics::DerivedTypeSpec dtSpec{
+            name->source, derivedType.GetUltimate()};
+        if (dtSpec.IsForwardReferenced()) {
+          Say(call.source,
+              "Cannot construct value for derived type '%s' "
+              "before it is defined"_err_en_US,
+              name->source);
+          return std::nullopt;
+        }
         const semantics::DeclTypeSpec &type{
-            semantics::FindOrInstantiateDerivedType(scope,
-                semantics::DerivedTypeSpec{
-                    name->source, derivedType.GetUltimate()},
-                context_)};
+            semantics::FindOrInstantiateDerivedType(
+                scope, std::move(dtSpec), context_)};
         auto &mutableRef{const_cast<parser::FunctionReference &>(funcRef)};
         *structureConstructor =
             mutableRef.ConvertToStructureConstructor(type.derivedTypeSpec());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87535.291707.patch
Type: text/x-patch
Size: 1869 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200914/3e0a790e/attachment.bin>


More information about the llvm-commits mailing list