Skip to content

[flang][openacc] Warn about misplaced end loop directive and ignore it #69512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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