[flang-commits] [flang] 2f7a41b - [Flang][OpenMP] Fix 'Internal: no symbol found' for OpenMP aligned and linear clause.

Sameeran joshi via flang-commits flang-commits at lists.llvm.org
Tue Nov 10 09:17:42 PST 2020


Author: sameeran joshi
Date: 2020-11-10T22:47:13+05:30
New Revision: 2f7a41b2a70c45eff8a1f064174be0d1af9f8afa

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

LOG: [Flang][OpenMP] Fix 'Internal: no symbol found' for OpenMP aligned and linear clause.

The initial approach was to go with changing parser nodes from `std::list<parser::Name>` to `OmpObjectList`, but that might have lead to illegal programs.
Resolving the symbols inside `OmpAttributeVisitor`.
Fix a couple of `XFAIL` tests.

Reviewed By: kiranchandramohan

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

Added: 
    

Modified: 
    flang/include/flang/Parser/parse-tree.h
    flang/include/flang/Semantics/symbol.h
    flang/lib/Semantics/resolve-directives.cpp
    flang/test/Semantics/omp-clause-validity01.f90
    flang/test/Semantics/omp-declarative-directive.f90
    flang/test/Semantics/omp-do03.f90
    flang/test/Semantics/omp-loop-simd01.f90
    flang/test/Semantics/omp-simd02.f90

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 5a491575c929..91ba14f88edf 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3375,6 +3375,7 @@ struct OmpIfClause {
 // 2.8.1 aligned-clause -> ALIGNED (variable-name-list[ : scalar-constant])
 struct OmpAlignedClause {
   TUPLE_CLASS_BOILERPLATE(OmpAlignedClause);
+  CharBlock source;
   std::tuple<std::list<Name>, std::optional<ScalarIntConstantExpr>> t;
 };
 

diff  --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index eab88d2f4dac..29b2696d82e5 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -508,7 +508,7 @@ class Symbol {
       // OpenMP miscellaneous flags
       OmpCommonBlock, OmpReduction, OmpAllocate, OmpDeclareSimd,
       OmpDeclareTarget, OmpThreadprivate, OmpDeclareReduction, OmpFlushed,
-      OmpCriticalLock, OmpIfSpecified, OmpNone, OmpPreDetermined);
+      OmpCriticalLock, OmpIfSpecified, OmpNone, OmpPreDetermined, OmpAligned);
   using Flags = common::EnumSet<Flag, Flag_enumSize>;
 
   const Scope &owner() const { return *owner_; }

diff  --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 130eb8e1c422..2c0a4c730a98 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -243,6 +243,15 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
   bool Pre(const parser::OpenMPSectionsConstruct &);
   void Post(const parser::OpenMPSectionsConstruct &) { PopContext(); }
 
+  bool Pre(const parser::OpenMPDeclareSimdConstruct &x) {
+    PushContext(x.source, llvm::omp::Directive::OMPD_declare_simd);
+    const auto &name{std::get<std::optional<parser::Name>>(x.t)};
+    if (name) {
+      ResolveOmpName(*name, Symbol::Flag::OmpDeclareSimd);
+    }
+    return true;
+  }
+  void Post(const parser::OpenMPDeclareSimdConstruct &) { PopContext(); }
   bool Pre(const parser::OpenMPThreadprivate &);
   void Post(const parser::OpenMPThreadprivate &) { PopContext(); }
 
@@ -273,7 +282,27 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
     ResolveOmpObjectList(x.v, Symbol::Flag::OmpCopyIn);
     return false;
   }
-
+  bool Pre(const parser::OmpLinearClause &x) {
+    std::visit(common::visitors{
+                   [&](const parser::OmpLinearClause::WithoutModifier
+                           &linearWithoutModifier) {
+                     ResolveOmpNameList(
+                         linearWithoutModifier.names, Symbol::Flag::OmpLinear);
+                   },
+                   [&](const parser::OmpLinearClause::WithModifier
+                           &linearWithModifier) {
+                     ResolveOmpNameList(
+                         linearWithModifier.names, Symbol::Flag::OmpLinear);
+                   },
+               },
+        x.u);
+    return false;
+  }
+  bool Pre(const parser::OmpAlignedClause &x) {
+    const auto &alignedNameList{std::get<std::list<parser::Name>>(x.t)};
+    ResolveOmpNameList(alignedNameList, Symbol::Flag::OmpAligned);
+    return false;
+  }
   void Post(const parser::Name &);
 
 private:
@@ -323,6 +352,9 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
   Symbol *ResolveOmp(const parser::Name &, Symbol::Flag, Scope &);
   Symbol *ResolveOmp(Symbol &, Symbol::Flag, Scope &);
   Symbol *ResolveOmpCommonBlockName(const parser::Name *);
+  void ResolveOmpNameList(const std::list<parser::Name> &, Symbol::Flag);
+  void ResolveOmpName(const parser::Name &, Symbol::Flag);
+  Symbol *ResolveName(const parser::Name *);
   Symbol *DeclareOrMarkOtherAccessEntity(const parser::Name &, Symbol::Flag);
   Symbol *DeclareOrMarkOtherAccessEntity(Symbol &, Symbol::Flag);
   void CheckMultipleAppearances(
@@ -925,6 +957,34 @@ void OmpAttributeVisitor::Post(const parser::Name &name) {
   } // within OpenMP construct
 }
 
+Symbol *OmpAttributeVisitor::ResolveName(const parser::Name *name) {
+  if (auto *resolvedSymbol{
+          name ? GetContext().scope.FindSymbol(name->source) : nullptr}) {
+    name->symbol = resolvedSymbol;
+    return resolvedSymbol;
+  } else {
+    return nullptr;
+  }
+}
+
+void OmpAttributeVisitor::ResolveOmpName(
+    const parser::Name &name, Symbol::Flag ompFlag) {
+  if (ResolveName(&name)) {
+    if (auto *resolvedSymbol{ResolveOmp(name, ompFlag, currScope())}) {
+      if (dataSharingAttributeFlags.test(ompFlag)) {
+        AddToContextObjectWithDSA(*resolvedSymbol, ompFlag);
+      }
+    }
+  }
+}
+
+void OmpAttributeVisitor::ResolveOmpNameList(
+    const std::list<parser::Name> &nameList, Symbol::Flag ompFlag) {
+  for (const auto &name : nameList) {
+    ResolveOmpName(name, ompFlag);
+  }
+}
+
 Symbol *OmpAttributeVisitor::ResolveOmpCommonBlockName(
     const parser::Name *name) {
   if (auto *prev{name

diff  --git a/flang/test/Semantics/omp-clause-validity01.f90 b/flang/test/Semantics/omp-clause-validity01.f90
index a4e668d29f4f..aa51dfd9dcbb 100644
--- a/flang/test/Semantics/omp-clause-validity01.f90
+++ b/flang/test/Semantics/omp-clause-validity01.f90
@@ -197,7 +197,6 @@
   enddo
 
   !ERROR: A modifier may not be specified in a LINEAR clause on the DO directive
-  !ERROR: Internal: no symbol found for 'b'
   !$omp do linear(ref(b))
   do i = 1, N
      a = 3.14
@@ -217,8 +216,6 @@
 
   !ERROR: The parameter of the ORDERED clause must be a constant positive integer expression
   !ERROR: A loop directive may not have both a LINEAR clause and an ORDERED clause with a parameter
-  !ERROR: Internal: no symbol found for 'b'
-  !ERROR: Internal: no symbol found for 'a'
   !$omp do ordered(1-1) private(b) linear(b) linear(a)
   do i = 1, N
      a = 3.14
@@ -369,7 +366,6 @@
   enddo
 
   !ERROR: The ALIGNMENT parameter of the ALIGNED clause must be a constant positive integer expression
-  !ERROR: Internal: no symbol found for 'b'
   !$omp simd aligned(b:-2)
   do i = 1, N
      a = 3.14
@@ -388,7 +384,6 @@
 
   !ERROR: At most one PROC_BIND clause can appear on the PARALLEL DO directive
   !ERROR: A modifier may not be specified in a LINEAR clause on the PARALLEL DO directive
-  !ERROR: Internal: no symbol found for 'b'
   !$omp parallel do proc_bind(master) proc_bind(close) linear(val(b))
   do i = 1, N
      a = 3.14
@@ -558,7 +553,6 @@
 
   !ERROR: The parameter of the SIMDLEN clause must be a constant positive integer expression
   !ERROR: The ALIGNMENT parameter of the ALIGNED clause must be a constant positive integer expression
-  !ERROR: Internal: no symbol found for 'a'
   !$omp taskloop simd simdlen(-1) aligned(a:-2)
   do i = 1, N
      a = 3.14

diff  --git a/flang/test/Semantics/omp-declarative-directive.f90 b/flang/test/Semantics/omp-declarative-directive.f90
index e732cec61f32..dd5e7fd564e8 100644
--- a/flang/test/Semantics/omp-declarative-directive.f90
+++ b/flang/test/Semantics/omp-declarative-directive.f90
@@ -9,8 +9,6 @@
 
 subroutine declare_simd_1(a, b)
   real(8), intent(inout) :: a, b
-  !ERROR: Internal: no symbol found for 'declare_simd_1'
-  !ERROR: Internal: no symbol found for 'a'
   !$omp declare simd(declare_simd_1) aligned(a)
   a = 3.14 + b
 end subroutine declare_simd_1
@@ -27,7 +25,6 @@ end module m1
 subroutine declare_simd_2
   use m1
   procedure (sub) sub1
-  !ERROR: Internal: no symbol found for 'sub1'
   !ERROR: NOTINBRANCH and INBRANCH clauses are mutually exclusive and may not appear on the same DECLARE SIMD directive
   !$omp declare simd(sub1) inbranch notinbranch
   procedure (sub), pointer::p

diff  --git a/flang/test/Semantics/omp-do03.f90 b/flang/test/Semantics/omp-do03.f90
index e60a2ed3c337..0153d72881fd 100644
--- a/flang/test/Semantics/omp-do03.f90
+++ b/flang/test/Semantics/omp-do03.f90
@@ -1,5 +1,4 @@
 ! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
-! XFAIL: *
 
 ! OpenMP Version 4.5
 ! 2.7.1 Loop Construct

diff  --git a/flang/test/Semantics/omp-loop-simd01.f90 b/flang/test/Semantics/omp-loop-simd01.f90
index 9d2596f6d95e..d39bb830a3a9 100644
--- a/flang/test/Semantics/omp-loop-simd01.f90
+++ b/flang/test/Semantics/omp-loop-simd01.f90
@@ -1,5 +1,4 @@
 ! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
-! XFAIL: *
 
 ! OpenMP Version 4.5
 ! 2.8.3 Loop simd Construct

diff  --git a/flang/test/Semantics/omp-simd02.f90 b/flang/test/Semantics/omp-simd02.f90
index 5665d31a6fba..b3c497b94f17 100644
--- a/flang/test/Semantics/omp-simd02.f90
+++ b/flang/test/Semantics/omp-simd02.f90
@@ -1,5 +1,4 @@
 ! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
-! XFAIL: *
 
 ! OpenMP Version 4.5
 ! 2.8.1 simd Construct


        


More information about the flang-commits mailing list