Skip to content

Commit 9573c62

Browse files
authored
[flang][OpenMP] Accept modern syntax of FLUSH construct (llvm#128975)
The syntax with the object list following the memory-order clause has been removed in OpenMP 5.2. Still, accept that syntax with versions >= 5.2, but treat it as deprecated (and emit a warning).
1 parent 5470dff commit 9573c62

File tree

7 files changed

+69
-19
lines changed

7 files changed

+69
-19
lines changed

flang/include/flang/Parser/parse-tree.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4897,12 +4897,23 @@ struct OpenMPDispatchConstruct {
48974897
t;
48984898
};
48994899

4900-
// 2.17.8 flush -> FLUSH [memory-order-clause] [(variable-name-list)]
4900+
// [4.5:162-165], [5.0:242-246], [5.1:275-279], [5.2:315-316], [6.0:498-500]
4901+
//
4902+
// flush-construct ->
4903+
// FLUSH [(list)] // since 4.5, until 4.5
4904+
// flush-construct ->
4905+
// FLUSH [memory-order-clause] [(list)] // since 5.0, until 5.1
4906+
// flush-construct ->
4907+
// FLUSH [(list)] [clause-list] // since 5.2
4908+
//
4909+
// memory-order-clause -> // since 5.0, until 5.1
4910+
// ACQ_REL | RELEASE | ACQUIRE | // since 5.0
4911+
// SEQ_CST // since 5.1
49014912
struct OpenMPFlushConstruct {
49024913
TUPLE_CLASS_BOILERPLATE(OpenMPFlushConstruct);
49034914
CharBlock source;
4904-
std::tuple<Verbatim, std::optional<std::list<OmpMemoryOrderClause>>,
4905-
std::optional<OmpObjectList>>
4915+
std::tuple<Verbatim, std::optional<OmpObjectList>,
4916+
std::optional<OmpClauseList>, /*TrailingClauses=*/bool>
49064917
t;
49074918
};
49084919

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3275,13 +3275,12 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
32753275
const auto &objectList =
32763276
std::get<std::optional<parser::OmpObjectList>>(flushConstruct.t);
32773277
const auto &clauseList =
3278-
std::get<std::optional<std::list<parser::OmpMemoryOrderClause>>>(
3279-
flushConstruct.t);
3278+
std::get<std::optional<parser::OmpClauseList>>(flushConstruct.t);
32803279
ObjectList objects =
32813280
objectList ? makeObjects(*objectList, semaCtx) : ObjectList{};
32823281
List<Clause> clauses =
3283-
clauseList ? makeList(*clauseList,
3284-
[&](auto &&s) { return makeClause(s.v, semaCtx); })
3282+
clauseList ? makeList(clauseList->v,
3283+
[&](auto &&s) { return makeClause(s, semaCtx); })
32853284
: List<Clause>{};
32863285
mlir::Location currentLocation = converter.genLocation(verbatim.source);
32873286

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,25 @@ TYPE_PARSER(sourced(construct<OmpAtomicClauseList>(
11041104
TYPE_PARSER(sourced(construct<OpenMPDepobjConstruct>(verbatim("DEPOBJ"_tok),
11051105
parenthesized(Parser<OmpObject>{}), sourced(Parser<OmpClause>{}))))
11061106

1107-
TYPE_PARSER(sourced(construct<OpenMPFlushConstruct>(verbatim("FLUSH"_tok),
1108-
many(maybe(","_tok) >> sourced(Parser<OmpMemoryOrderClause>{})),
1109-
maybe(parenthesized(Parser<OmpObjectList>{})))))
1107+
static OpenMPFlushConstruct makeFlushFromOldSyntax(Verbatim &&text,
1108+
std::optional<OmpClauseList> &&clauses,
1109+
std::optional<OmpObjectList> &&objects) {
1110+
bool oldSyntax{
1111+
clauses && !clauses->v.empty() && objects && !objects->v.empty()};
1112+
return OpenMPFlushConstruct{std::move(text), std::move(objects),
1113+
std::move(clauses),
1114+
/*TrailingClauses=*/!oldSyntax};
1115+
}
1116+
1117+
TYPE_PARSER(sourced( //
1118+
construct<OpenMPFlushConstruct>( //
1119+
applyFunction<OpenMPFlushConstruct>(makeFlushFromOldSyntax,
1120+
verbatim("FLUSH"_tok), maybe(Parser<OmpClauseList>{}),
1121+
maybe(parenthesized(Parser<OmpObjectList>{})))) ||
1122+
1123+
construct<OpenMPFlushConstruct>( //
1124+
verbatim("FLUSH"_tok), maybe(parenthesized(Parser<OmpObjectList>{})),
1125+
Parser<OmpClauseList>{}, pure(/*TrailingClauses=*/true))))
11101126

11111127
// Simple Standalone Directives
11121128
TYPE_PARSER(sourced(construct<OmpSimpleStandaloneDirective>(first(

flang/lib/Parser/unparse.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,9 +2884,14 @@ class UnparseVisitor {
28842884
}
28852885
void Unparse(const OpenMPFlushConstruct &x) {
28862886
BeginOpenMP();
2887-
Word("!$OMP FLUSH ");
2888-
Walk(std::get<std::optional<std::list<OmpMemoryOrderClause>>>(x.t));
2889-
Walk(" (", std::get<std::optional<OmpObjectList>>(x.t), ")");
2887+
Word("!$OMP FLUSH");
2888+
if (std::get</*ClausesTrailing=*/bool>(x.t)) {
2889+
Walk("(", std::get<std::optional<OmpObjectList>>(x.t), ")");
2890+
Walk(" ", std::get<std::optional<OmpClauseList>>(x.t));
2891+
} else {
2892+
Walk(" ", std::get<std::optional<OmpClauseList>>(x.t));
2893+
Walk(" (", std::get<std::optional<OmpObjectList>>(x.t), ")");
2894+
}
28902895
Put("\n");
28912896
EndOpenMP();
28922897
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,16 +2139,26 @@ void OmpStructureChecker::Enter(const parser::OpenMPFlushConstruct &x) {
21392139
}
21402140

21412141
void OmpStructureChecker::Leave(const parser::OpenMPFlushConstruct &x) {
2142+
auto &flushList{std::get<std::optional<parser::OmpObjectList>>(x.t)};
2143+
21422144
if (FindClause(llvm::omp::Clause::OMPC_acquire) ||
21432145
FindClause(llvm::omp::Clause::OMPC_release) ||
21442146
FindClause(llvm::omp::Clause::OMPC_acq_rel)) {
2145-
if (const auto &flushList{
2146-
std::get<std::optional<parser::OmpObjectList>>(x.t)}) {
2147+
if (flushList) {
21472148
context_.Say(parser::FindSourceLocation(flushList),
21482149
"If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items "
21492150
"must not be specified on the FLUSH directive"_err_en_US);
21502151
}
21512152
}
2153+
2154+
unsigned version{context_.langOptions().OpenMPVersion};
2155+
if (version >= 52) {
2156+
if (!std::get</*TrailingClauses=*/bool>(x.t)) {
2157+
context_.Say(parser::FindSourceLocation(flushList),
2158+
"The syntax \"FLUSH clause (object, ...)\" has been deprecated, use \"FLUSH(object, ...) clause\" instead"_warn_en_US);
2159+
}
2160+
}
2161+
21522162
dirContext_.pop_back();
21532163
}
21542164

flang/test/Semantics/OpenMP/flush01.f90

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
1+
! REQUIRES: openmp_runtime
2+
3+
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags -fopenmp-version=50
24

35
! 2.17.8 Flush construct [OpenMP 5.0]
46
! memory-order-clause ->
@@ -22,13 +24,13 @@
2224
array = (/1, 2, 3, 4, 5, 6, 7, 8, 9, 10/)
2325
!$omp flush acquire
2426

25-
!ERROR: expected end of line
27+
!ERROR: PRIVATE clause is not allowed on the FLUSH directive
2628
!$omp flush private(array)
27-
!ERROR: expected end of line
29+
!ERROR: NUM_THREADS clause is not allowed on the FLUSH directive
2830
!$omp flush num_threads(4)
2931

3032
! Mix allowed and not allowed clauses.
31-
!ERROR: expected end of line
33+
!ERROR: NUM_THREADS clause is not allowed on the FLUSH directive
3234
!$omp flush num_threads(4) acquire
3335
end if
3436
!$omp end parallel
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp -fopenmp-version=52 -Werror
2+
3+
subroutine f00(x)
4+
integer :: x
5+
!ERROR: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead
6+
!$omp flush seq_cst (x)
7+
end

0 commit comments

Comments
 (0)