Skip to content

Commit d2e7a15

Browse files
authored
[flang][openacc] Warn about misplaced end loop directive and ignore it (llvm#69512)
Instead of raising an error for a misplaced `end loop directive`, just warn about it and ignore it. This directive is an extension and is optional.
1 parent 21e1b13 commit d2e7a15

File tree

7 files changed

+34
-2
lines changed

7 files changed

+34
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ class ParseTreeDumper {
568568
NODE(parser, OpenACCCombinedConstruct)
569569
NODE(parser, OpenACCConstruct)
570570
NODE(parser, OpenACCDeclarativeConstruct)
571+
NODE(parser, OpenACCEndConstruct)
571572
NODE(parser, OpenACCLoopConstruct)
572573
NODE(parser, OpenACCRoutineConstruct)
573574
NODE(parser, OpenACCStandaloneDeclarativeConstruct)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4257,6 +4257,11 @@ struct OpenACCLoopConstruct {
42574257
t;
42584258
};
42594259

4260+
struct OpenACCEndConstruct {
4261+
WRAPPER_CLASS_BOILERPLATE(OpenACCEndConstruct, llvm::acc::Directive);
4262+
CharBlock source;
4263+
};
4264+
42604265
struct OpenACCStandaloneConstruct {
42614266
TUPLE_CLASS_BOILERPLATE(OpenACCStandaloneConstruct);
42624267
CharBlock source;
@@ -4267,7 +4272,7 @@ struct OpenACCConstruct {
42674272
UNION_CLASS_BOILERPLATE(OpenACCConstruct);
42684273
std::variant<OpenACCBlockConstruct, OpenACCCombinedConstruct,
42694274
OpenACCLoopConstruct, OpenACCStandaloneConstruct, OpenACCCacheConstruct,
4270-
OpenACCWaitConstruct, OpenACCAtomicConstruct>
4275+
OpenACCWaitConstruct, OpenACCAtomicConstruct, OpenACCEndConstruct>
42714276
u;
42724277
};
42734278

flang/lib/Lower/OpenACC.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,6 +3358,9 @@ void Fortran::lower::genOpenACCConstruct(
33583358
[&](const Fortran::parser::OpenACCAtomicConstruct &atomicConstruct) {
33593359
genACC(converter, eval, atomicConstruct);
33603360
},
3361+
[&](const Fortran::parser::OpenACCEndConstruct &) {
3362+
// No op
3363+
},
33613364
},
33623365
accConstruct.u);
33633366
}

flang/lib/Parser/openacc-parsers.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ TYPE_PARSER(startAccLine >>
235235
sourced(construct<OpenACCDeclarativeConstruct>(
236236
Parser<OpenACCRoutineConstruct>{})))))
237237

238+
TYPE_PARSER(sourced(construct<OpenACCEndConstruct>(
239+
"END"_tok >> "LOOP"_tok >> pure(llvm::acc::Directive::ACCD_loop))))
240+
238241
// OpenACC constructs
239242
TYPE_CONTEXT_PARSER("OpenACC construct"_en_US,
240243
startAccLine >>
@@ -246,7 +249,8 @@ TYPE_CONTEXT_PARSER("OpenACC construct"_en_US,
246249
Parser<OpenACCStandaloneConstruct>{}),
247250
construct<OpenACCConstruct>(Parser<OpenACCCacheConstruct>{}),
248251
construct<OpenACCConstruct>(Parser<OpenACCWaitConstruct>{}),
249-
construct<OpenACCConstruct>(Parser<OpenACCAtomicConstruct>{}))))
252+
construct<OpenACCConstruct>(Parser<OpenACCAtomicConstruct>{}),
253+
construct<OpenACCConstruct>(Parser<OpenACCEndConstruct>{}))))
250254

251255
TYPE_PARSER(startAccLine >>
252256
sourced(construct<AccEndCombinedDirective>(sourced("END"_tok >>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ void AccStructureChecker::Enter(const parser::AccClause::If &x) {
673673
GetContext().clauseSource, "Must have LOGICAL or INTEGER type"_err_en_US);
674674
}
675675

676+
void AccStructureChecker::Enter(const parser::OpenACCEndConstruct &x) {
677+
context_.Say(x.source, "Misplaced OpenACC end directive"_warn_en_US);
678+
}
679+
676680
void AccStructureChecker::Enter(const parser::Module &) {
677681
declareSymbols.clear();
678682
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class AccStructureChecker
6363
void Enter(const parser::OpenACCCacheConstruct &);
6464
void Leave(const parser::OpenACCCacheConstruct &);
6565
void Enter(const parser::AccAtomicUpdate &);
66+
void Enter(const parser::OpenACCEndConstruct &);
6667

6768
// Clauses
6869
void Leave(const parser::AccClauseList &);

flang/test/Semantics/OpenACC/acc-error.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,17 @@ subroutine test(a, n)
1313
!ERROR: expected OpenACC directive
1414
!$acc p
1515
end subroutine
16+
17+
subroutine test2(a, n)
18+
integer :: a(n)
19+
integer :: i
20+
21+
!$acc parallel
22+
!$acc loop
23+
DO i = 1, n
24+
END DO
25+
!$acc end parallel
26+
!WARN: Misplaced OpenACC end directive
27+
!$acc end loop
28+
29+
end subroutine

0 commit comments

Comments
 (0)