Skip to content

Commit

Permalink
[Flang][OpenMP] Fix 'Internal: no symbol found' for OpenMP aligned an…
Browse files Browse the repository at this point in the history
…d 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
  • Loading branch information
Sameeranjoshi committed Nov 10, 2020
1 parent 46a7346 commit 2f7a41b
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 14 deletions.
1 change: 1 addition & 0 deletions flang/include/flang/Parser/parse-tree.h
Expand Up @@ -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;
};

Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Semantics/symbol.h
Expand Up @@ -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_; }
Expand Down
62 changes: 61 additions & 1 deletion flang/lib/Semantics/resolve-directives.cpp
Expand Up @@ -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(); }

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions flang/test/Semantics/omp-clause-validity01.f90
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions flang/test/Semantics/omp-declarative-directive.f90
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion 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
Expand Down
1 change: 0 additions & 1 deletion 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
Expand Down
1 change: 0 additions & 1 deletion 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
Expand Down

0 comments on commit 2f7a41b

Please sign in to comment.