[flang-commits] [flang] fac8453 - [flang] Fix an assert on duplicate initializations

Peter Steinfeld via flang-commits flang-commits at lists.llvm.org
Thu Jul 30 12:58:51 PDT 2020


Author: Peter Steinfeld
Date: 2020-07-30T12:58:28-07:00
New Revision: fac84536bcb9fbca2b3517ca83d382329d0e6c55

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

LOG: [flang] Fix an assert on duplicate initializations

When declaring the same variable twice with an initialization, we were failing
an internal check.  I fixed this by checking to see if the associated symbol
already had an error.

I added tests for pointer and non-pointer initialization of duplicate names.

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

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/resolve91.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 744eee19ba43..eb7dd697b274 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5680,22 +5680,25 @@ void DeclarationVisitor::NonPointerInitialization(const parser::Name &name,
     const parser::ConstantExpr &expr, bool inComponentDecl) {
   if (name.symbol) {
     Symbol &ultimate{name.symbol->GetUltimate()};
-    if (IsPointer(ultimate)) {
-      Say(name, "'%s' is a pointer but is not initialized like one"_err_en_US);
-    } else if (auto *details{ultimate.detailsIf<ObjectEntityDetails>()}) {
-      CHECK(!details->init());
-      Walk(expr);
-      // TODO: check C762 - all bounds and type parameters of component
-      // are colons or constant expressions if component is initialized
-      if (inComponentDecl) {
-        // Can't convert to type of component, which might not yet
-        // be known; that's done later during instantiation.
-        if (MaybeExpr value{EvaluateExpr(expr)}) {
-          details->set_init(std::move(*value));
+    if (!context().HasError(ultimate)) {
+      if (IsPointer(ultimate)) {
+        Say(name,
+            "'%s' is a pointer but is not initialized like one"_err_en_US);
+      } else if (auto *details{ultimate.detailsIf<ObjectEntityDetails>()}) {
+        CHECK(!details->init());
+        Walk(expr);
+        // TODO: check C762 - all bounds and type parameters of component
+        // are colons or constant expressions if component is initialized
+        if (inComponentDecl) {
+          // Can't convert to type of component, which might not yet
+          // be known; that's done later during instantiation.
+          if (MaybeExpr value{EvaluateExpr(expr)}) {
+            details->set_init(std::move(*value));
+          }
+        } else if (MaybeExpr folded{EvaluateConvertedExpr(
+                       ultimate, expr, expr.thing.value().source)}) {
+          details->set_init(std::move(*folded));
         }
-      } else if (MaybeExpr folded{EvaluateConvertedExpr(
-                     ultimate, expr, expr.thing.value().source)}) {
-        details->set_init(std::move(*folded));
       }
     }
   }

diff  --git a/flang/test/Semantics/resolve91.f90 b/flang/test/Semantics/resolve91.f90
index 2fbcaa384dfc..c94cda458f3f 100644
--- a/flang/test/Semantics/resolve91.f90
+++ b/flang/test/Semantics/resolve91.f90
@@ -63,3 +63,14 @@ module m7
   !ERROR: Derived type 'ubound' not found
   integer :: ivar = ubound(iarray)(1)
 end module m7
+
+module m8
+  integer :: iVar = 3
+  !ERROR: The type of 'ivar' has already been declared
+  integer :: iVar = 4
+  integer, target :: jVar = 5
+  integer, target :: kVar = 5
+  integer, pointer :: pVar => jVar
+  !ERROR: The type of 'pvar' has already been declared
+  integer, pointer :: pVar => kVar
+end module m8


        


More information about the flang-commits mailing list