[flang-commits] [flang] 66e8935 - [flang] Changes related to feedback from pull request flang-compiler/f18#551

Peter Steinfeld via flang-commits flang-commits at lists.llvm.org
Thu Apr 9 08:15:37 PDT 2020


Author: Peter Steinfeld
Date: 2019-07-10T12:53:56-07:00
New Revision: 66e8935dec74b7395bf116d88c5de13520ba4501

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

LOG: [flang] Changes related to feedback from pull request flang-compiler/f18#551

 - Changed the name a a function to FindOrDeclareEnclosingEntity
 - Changed that function to return a reference rather than a pointer
 - Polished the setting of the IMPLICIT flag on a declared entity in a
 locality-spec
 - Changed a test to remove an unreported error

Original-commit: flang-compiler/f18 at 0c1a00d7c2c67064801f9f6fb37c0a26224c0ea4
Reviewed-on: https://github.com/flang-compiler/f18/pull/551
Tree-same-pre-rewrite: false

Added: 
    

Modified: 
    flang/lib/semantics/resolve-names.cc
    flang/test/semantics/resolve35.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc
index fa742d563288..3a28aa0e70ac 100644
--- a/flang/lib/semantics/resolve-names.cc
+++ b/flang/lib/semantics/resolve-names.cc
@@ -747,7 +747,7 @@ class DeclarationVisitor : public ArraySpecVisitor,
   void EndDecl();
   Symbol &DeclareObjectEntity(const parser::Name &, Attrs);
   // Make sure that there's an entity in an enclosing scope called Name
-  Symbol *EnsureEnclosingEntity(const parser::Name &);
+  Symbol &FindOrDeclareEnclosingEntity(const parser::Name &);
   // Declare a LOCAL/LOCAL_INIT entity. If there isn't a type specified
   // it comes from the entity in the containing scope, or implicit rules.
   // Return pointer to the new symbol, or nullptr on error.
@@ -3791,7 +3791,8 @@ bool DeclarationVisitor::PassesLocalityChecks(
   return true;
 }
 
-Symbol *DeclarationVisitor::EnsureEnclosingEntity(const parser::Name &name) {
+Symbol &DeclarationVisitor::FindOrDeclareEnclosingEntity(
+    const parser::Name &name) {
   Symbol *prev{FindSymbol(name)};
   if (prev == nullptr) {
     // Declare the name as an object in the enclosing scope so that
@@ -3800,21 +3801,19 @@ Symbol *DeclarationVisitor::EnsureEnclosingEntity(const parser::Name &name) {
     ConvertToObjectEntity(*prev);
     ApplyImplicitRules(*prev);
   }
-  return prev;
+  return *prev;
 }
 
 Symbol *DeclarationVisitor::DeclareLocalEntity(const parser::Name &name) {
-  Symbol *prev{EnsureEnclosingEntity(name)};
-  if (!PassesLocalityChecks(name, *prev)) {
+  Symbol &prev{FindOrDeclareEnclosingEntity(name)};
+  if (!PassesLocalityChecks(name, prev)) {
     return nullptr;
   }
   name.symbol = nullptr;
   Symbol &symbol{DeclareEntity<ObjectEntityDetails>(name, {})};
-  if (auto *type{prev->GetType()}) {
+  if (auto *type{prev.GetType()}) {
     symbol.SetType(*type);
-    if (prev->test(Symbol::Flag::Implicit)) {
-      symbol.set(Symbol::Flag::Implicit);
-    }
+    symbol.set(Symbol::Flag::Implicit, prev.test(Symbol::Flag::Implicit));
   }
   return &symbol;
 }
@@ -4106,9 +4105,14 @@ bool ConstructVisitor::Pre(const parser::LocalitySpec::LocalInit &x) {
 
 bool ConstructVisitor::Pre(const parser::LocalitySpec::Shared &x) {
   for (const auto &name : x.v) {
-    Symbol *prev{EnsureEnclosingEntity(name)};
-    if (PassesSharedLocalityChecks(name, *prev)) {
-      auto &symbol{MakeSymbol(name, HostAssocDetails{*prev})};
+    if (!FindSymbol(name)) {
+      Say(name,
+          "Warning, variable '%s' with SHARED locality allocated"
+          " automatically and may be uninitialized"_en_US);
+    }
+    Symbol &prev{FindOrDeclareEnclosingEntity(name)};
+    if (PassesSharedLocalityChecks(name, prev)) {
+      auto &symbol{MakeSymbol(name, HostAssocDetails{prev})};
       symbol.set(Symbol::Flag::LocalityShared);
       name.symbol = &symbol;  // override resolution to parent
     }

diff  --git a/flang/test/semantics/resolve35.f90 b/flang/test/semantics/resolve35.f90
index c2ec8cc8811d..a733556628f1 100644
--- a/flang/test/semantics/resolve35.f90
+++ b/flang/test/semantics/resolve35.f90
@@ -89,7 +89,7 @@ subroutine s7
       !ERROR: 'j' is already declared in this scoping unit
       local_init(k, j) &
       shared(a)
-    a(i) = j + 1
+    a = j + 1
   end do
 end
 


        


More information about the flang-commits mailing list