[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
This commit is contained in:
sameeran joshi 2020-10-31 23:43:58 +05:30 committed by Sameeran joshi
parent 46a734621d
commit 2f7a41b2a7
8 changed files with 63 additions and 14 deletions

View File

@ -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;
};

View File

@ -508,7 +508,7 @@ public:
// 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_; }

View File

@ -243,6 +243,15 @@ public:
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 @@ public:
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 @@ private:
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

View File

@ -197,7 +197,6 @@ use omp_lib
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 @@ use omp_lib
!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 @@ use omp_lib
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 @@ use omp_lib
!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 @@ use omp_lib
!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

View File

@ -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

View File

@ -1,5 +1,4 @@
! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
! XFAIL: *
! OpenMP Version 4.5
! 2.7.1 Loop Construct

View File

@ -1,5 +1,4 @@
! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
! XFAIL: *
! OpenMP Version 4.5
! 2.8.3 Loop simd Construct

View File

@ -1,5 +1,4 @@
! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
! XFAIL: *
! OpenMP Version 4.5
! 2.8.1 simd Construct