Skip to content

Commit

Permalink
[flang][openacc][NFC] Issue better error message when directive is wr…
Browse files Browse the repository at this point in the history
…ong (#69034)
  • Loading branch information
clementval committed Oct 16, 2023
1 parent 144c5b6 commit 6ade518
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
32 changes: 18 additions & 14 deletions flang/lib/Parser/openacc-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,12 @@ TYPE_PARSER(sourced(construct<AccLoopDirective>(
TYPE_PARSER(construct<AccBeginLoopDirective>(
sourced(Parser<AccLoopDirective>{}), Parser<AccClauseList>{}))

TYPE_PARSER(construct<AccEndLoop>(startAccLine >> "END LOOP"_tok))
TYPE_PARSER(construct<AccEndLoop>("END LOOP"_tok))

TYPE_PARSER(construct<OpenACCLoopConstruct>(
sourced(Parser<AccBeginLoopDirective>{} / endAccLine),
maybe(Parser<DoConstruct>{}), maybe(Parser<AccEndLoop>{} / endAccLine)))
maybe(Parser<DoConstruct>{}),
maybe(startAccLine >> Parser<AccEndLoop>{} / endAccLine)))

// 2.15.1 Routine directive
TYPE_PARSER(sourced(construct<OpenACCRoutineConstruct>(verbatim("ROUTINE"_tok),
Expand Down Expand Up @@ -227,22 +228,25 @@ TYPE_PARSER(construct<OpenACCStandaloneConstruct>(
TYPE_PARSER(construct<OpenACCStandaloneDeclarativeConstruct>(
sourced(Parser<AccDeclarativeDirective>{}), Parser<AccClauseList>{}))

TYPE_PARSER(
startAccLine >> first(sourced(construct<OpenACCDeclarativeConstruct>(
Parser<OpenACCStandaloneDeclarativeConstruct>{})),
sourced(construct<OpenACCDeclarativeConstruct>(
Parser<OpenACCRoutineConstruct>{}))))
TYPE_PARSER(startAccLine >>
withMessage("expected OpenACC directive"_err_en_US,
first(sourced(construct<OpenACCDeclarativeConstruct>(
Parser<OpenACCStandaloneDeclarativeConstruct>{})),
sourced(construct<OpenACCDeclarativeConstruct>(
Parser<OpenACCRoutineConstruct>{})))))

// OpenACC constructs
TYPE_CONTEXT_PARSER("OpenACC construct"_en_US,
startAccLine >>
first(construct<OpenACCConstruct>(Parser<OpenACCBlockConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCCombinedConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCLoopConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCStandaloneConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCCacheConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCWaitConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCAtomicConstruct>{})))
withMessage("expected OpenACC directive"_err_en_US,
first(construct<OpenACCConstruct>(Parser<OpenACCBlockConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCCombinedConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCLoopConstruct>{}),
construct<OpenACCConstruct>(
Parser<OpenACCStandaloneConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCCacheConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCWaitConstruct>{}),
construct<OpenACCConstruct>(Parser<OpenACCAtomicConstruct>{}))))

TYPE_PARSER(startAccLine >>
sourced(construct<AccEndCombinedDirective>(sourced("END"_tok >>
Expand Down
15 changes: 15 additions & 0 deletions flang/test/Semantics/OpenACC/acc-error.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenacc

! Check parser specific error for OpenACC


subroutine test(a, n)
integer :: a(n)
!ERROR: expected OpenACC directive
!$acc p
integer :: i,j

i = 0
!ERROR: expected OpenACC directive
!$acc p
end subroutine

0 comments on commit 6ade518

Please sign in to comment.