Skip to content

Commit a585448

Browse files
authored
[flang][OpenMP] Move check of ALIGN clause to visitor function (#164261)
This replaces CheckAlignValue with an Enter function, and adds a check that the alignment is a power of 2.
1 parent 573b624 commit a585448

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,20 +1562,11 @@ void OmpStructureChecker::Leave(const parser::OpenMPRequiresConstruct &) {
15621562
dirContext_.pop_back();
15631563
}
15641564

1565-
void OmpStructureChecker::CheckAlignValue(const parser::OmpClause &clause) {
1566-
if (auto *align{std::get_if<parser::OmpClause::Align>(&clause.u)}) {
1567-
if (const auto &v{GetIntValue(align->v)}; v && *v <= 0) {
1568-
context_.Say(clause.source, "The alignment should be positive"_err_en_US);
1569-
}
1570-
}
1571-
}
1572-
15731565
void OmpStructureChecker::Enter(const parser::OpenMPDeclarativeAllocate &x) {
15741566
isPredefinedAllocator = true;
15751567
const auto &dir{std::get<parser::Verbatim>(x.t)};
15761568
const auto &objectList{std::get<parser::OmpObjectList>(x.t)};
15771569
PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_allocate);
1578-
const auto &clauseList{std::get<parser::OmpClauseList>(x.t)};
15791570
SymbolSourceMap currSymbols;
15801571
GetSymbolsInObjectList(objectList, currSymbols);
15811572
for (auto &[symbol, source] : currSymbols) {
@@ -1598,9 +1589,6 @@ void OmpStructureChecker::Enter(const parser::OpenMPDeclarativeAllocate &x) {
15981589
source.ToString());
15991590
}
16001591
}
1601-
for (const auto &clause : clauseList.v) {
1602-
CheckAlignValue(clause);
1603-
}
16041592
CheckVarIsNotPartOfAnotherVar(dir.source, objectList);
16051593
}
16061594

@@ -2007,9 +1995,6 @@ void OmpStructureChecker::Enter(const parser::OpenMPExecutableAllocate &x) {
20071995

20081996
isPredefinedAllocator = true;
20091997
const auto &objectList{std::get<std::optional<parser::OmpObjectList>>(x.t)};
2010-
for (const auto &clause : clauseList.v) {
2011-
CheckAlignValue(clause);
2012-
}
20131998
if (objectList) {
20141999
CheckVarIsNotPartOfAnotherVar(dir.source, *objectList);
20152000
}
@@ -3234,7 +3219,6 @@ CHECK_SIMPLE_CLAUSE(AdjustArgs, OMPC_adjust_args)
32343219
CHECK_SIMPLE_CLAUSE(AppendArgs, OMPC_append_args)
32353220
CHECK_SIMPLE_CLAUSE(MemoryOrder, OMPC_memory_order)
32363221
CHECK_SIMPLE_CLAUSE(Bind, OMPC_bind)
3237-
CHECK_SIMPLE_CLAUSE(Align, OMPC_align)
32383222
CHECK_SIMPLE_CLAUSE(Compare, OMPC_compare)
32393223
CHECK_SIMPLE_CLAUSE(OmpxAttribute, OMPC_ompx_attribute)
32403224
CHECK_SIMPLE_CLAUSE(Weak, OMPC_weak)
@@ -3898,6 +3882,19 @@ void OmpStructureChecker::CheckIsLoopIvPartOfClause(
38983882
}
38993883
}
39003884

3885+
void OmpStructureChecker::Enter(const parser::OmpClause::Align &x) {
3886+
CheckAllowedClause(llvm::omp::Clause::OMPC_align);
3887+
if (const auto &v{GetIntValue(x.v.v)}) {
3888+
if (*v <= 0) {
3889+
context_.Say(GetContext().clauseSource,
3890+
"The alignment should be positive"_err_en_US);
3891+
} else if (!llvm::isPowerOf2_64(*v)) {
3892+
context_.Say(GetContext().clauseSource,
3893+
"The alignment should be a power of 2"_err_en_US);
3894+
}
3895+
}
3896+
}
3897+
39013898
// Restrictions specific to each clause are implemented apart from the
39023899
// generalized restrictions.
39033900
void OmpStructureChecker::Enter(const parser::OmpClause::Aligned &x) {

flang/lib/Semantics/check-omp-structure.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,6 @@ class OmpStructureChecker
347347
void CheckAllowedRequiresClause(llvmOmpClause clause);
348348
bool deviceConstructFound_{false};
349349

350-
void CheckAlignValue(const parser::OmpClause &);
351-
352350
void AddEndDirectiveClauses(const parser::OmpClauseList &clauses);
353351

354352
void EnterDirectiveNest(const int index) { directiveNest_[index]++; }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=51
2+
3+
subroutine f00(y)
4+
integer :: x(10), y
5+
!ERROR: Must be a constant value
6+
!$omp allocate(x) align(y)
7+
end
8+
9+
subroutine f01()
10+
integer :: x(10)
11+
!ERROR: The alignment should be a power of 2
12+
!$omp allocate(x) align(7)
13+
end
14+
15+
subroutine f02()
16+
integer :: x(10)
17+
!ERROR: The alignment should be positive
18+
!$omp allocate(x) align(-8)
19+
end
20+

0 commit comments

Comments
 (0)