Skip to content

Commit

Permalink
[flang][openacc] Warn about misplaced end loop directive and ignore it (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
clementval committed Oct 19, 2023
1 parent 21e1b13 commit d2e7a15
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions flang/include/flang/Parser/dump-parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ class ParseTreeDumper {
NODE(parser, OpenACCCombinedConstruct)
NODE(parser, OpenACCConstruct)
NODE(parser, OpenACCDeclarativeConstruct)
NODE(parser, OpenACCEndConstruct)
NODE(parser, OpenACCLoopConstruct)
NODE(parser, OpenACCRoutineConstruct)
NODE(parser, OpenACCStandaloneDeclarativeConstruct)
Expand Down
7 changes: 6 additions & 1 deletion flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -4257,6 +4257,11 @@ struct OpenACCLoopConstruct {
t;
};

struct OpenACCEndConstruct {
WRAPPER_CLASS_BOILERPLATE(OpenACCEndConstruct, llvm::acc::Directive);
CharBlock source;
};

struct OpenACCStandaloneConstruct {
TUPLE_CLASS_BOILERPLATE(OpenACCStandaloneConstruct);
CharBlock source;
Expand All @@ -4267,7 +4272,7 @@ struct OpenACCConstruct {
UNION_CLASS_BOILERPLATE(OpenACCConstruct);
std::variant<OpenACCBlockConstruct, OpenACCCombinedConstruct,
OpenACCLoopConstruct, OpenACCStandaloneConstruct, OpenACCCacheConstruct,
OpenACCWaitConstruct, OpenACCAtomicConstruct>
OpenACCWaitConstruct, OpenACCAtomicConstruct, OpenACCEndConstruct>
u;
};

Expand Down
3 changes: 3 additions & 0 deletions flang/lib/Lower/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3358,6 +3358,9 @@ void Fortran::lower::genOpenACCConstruct(
[&](const Fortran::parser::OpenACCAtomicConstruct &atomicConstruct) {
genACC(converter, eval, atomicConstruct);
},
[&](const Fortran::parser::OpenACCEndConstruct &) {
// No op
},
},
accConstruct.u);
}
Expand Down
6 changes: 5 additions & 1 deletion flang/lib/Parser/openacc-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ TYPE_PARSER(startAccLine >>
sourced(construct<OpenACCDeclarativeConstruct>(
Parser<OpenACCRoutineConstruct>{})))))

TYPE_PARSER(sourced(construct<OpenACCEndConstruct>(
"END"_tok >> "LOOP"_tok >> pure(llvm::acc::Directive::ACCD_loop))))

// OpenACC constructs
TYPE_CONTEXT_PARSER("OpenACC construct"_en_US,
startAccLine >>
Expand All @@ -246,7 +249,8 @@ TYPE_CONTEXT_PARSER("OpenACC construct"_en_US,
Parser<OpenACCStandaloneConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCCacheConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCWaitConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCAtomicConstruct>{}))))
construct<OpenACCConstruct>(Parser<OpenACCAtomicConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCEndConstruct>{}))))

TYPE_PARSER(startAccLine >>
sourced(construct<AccEndCombinedDirective>(sourced("END"_tok >>
Expand Down
4 changes: 4 additions & 0 deletions flang/lib/Semantics/check-acc-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@ void AccStructureChecker::Enter(const parser::AccClause::If &x) {
GetContext().clauseSource, "Must have LOGICAL or INTEGER type"_err_en_US);
}

void AccStructureChecker::Enter(const parser::OpenACCEndConstruct &x) {
context_.Say(x.source, "Misplaced OpenACC end directive"_warn_en_US);
}

void AccStructureChecker::Enter(const parser::Module &) {
declareSymbols.clear();
}
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Semantics/check-acc-structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class AccStructureChecker
void Enter(const parser::OpenACCCacheConstruct &);
void Leave(const parser::OpenACCCacheConstruct &);
void Enter(const parser::AccAtomicUpdate &);
void Enter(const parser::OpenACCEndConstruct &);

// Clauses
void Leave(const parser::AccClauseList &);
Expand Down
14 changes: 14 additions & 0 deletions flang/test/Semantics/OpenACC/acc-error.f90
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@ subroutine test(a, n)
!ERROR: expected OpenACC directive
!$acc p
end subroutine

subroutine test2(a, n)
integer :: a(n)
integer :: i

!$acc parallel
!$acc loop
DO i = 1, n
END DO
!$acc end parallel
!WARN: Misplaced OpenACC end directive
!$acc end loop

end subroutine

0 comments on commit d2e7a15

Please sign in to comment.