Skip to content

Commit 6ade518

Browse files
authored
[flang][openacc][NFC] Issue better error message when directive is wrong (llvm#69034)
1 parent 144c5b6 commit 6ade518

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

flang/lib/Parser/openacc-parsers.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,12 @@ TYPE_PARSER(sourced(construct<AccLoopDirective>(
150150
TYPE_PARSER(construct<AccBeginLoopDirective>(
151151
sourced(Parser<AccLoopDirective>{}), Parser<AccClauseList>{}))
152152

153-
TYPE_PARSER(construct<AccEndLoop>(startAccLine >> "END LOOP"_tok))
153+
TYPE_PARSER(construct<AccEndLoop>("END LOOP"_tok))
154154

155155
TYPE_PARSER(construct<OpenACCLoopConstruct>(
156156
sourced(Parser<AccBeginLoopDirective>{} / endAccLine),
157-
maybe(Parser<DoConstruct>{}), maybe(Parser<AccEndLoop>{} / endAccLine)))
157+
maybe(Parser<DoConstruct>{}),
158+
maybe(startAccLine >> Parser<AccEndLoop>{} / endAccLine)))
158159

159160
// 2.15.1 Routine directive
160161
TYPE_PARSER(sourced(construct<OpenACCRoutineConstruct>(verbatim("ROUTINE"_tok),
@@ -227,22 +228,25 @@ TYPE_PARSER(construct<OpenACCStandaloneConstruct>(
227228
TYPE_PARSER(construct<OpenACCStandaloneDeclarativeConstruct>(
228229
sourced(Parser<AccDeclarativeDirective>{}), Parser<AccClauseList>{}))
229230

230-
TYPE_PARSER(
231-
startAccLine >> first(sourced(construct<OpenACCDeclarativeConstruct>(
232-
Parser<OpenACCStandaloneDeclarativeConstruct>{})),
233-
sourced(construct<OpenACCDeclarativeConstruct>(
234-
Parser<OpenACCRoutineConstruct>{}))))
231+
TYPE_PARSER(startAccLine >>
232+
withMessage("expected OpenACC directive"_err_en_US,
233+
first(sourced(construct<OpenACCDeclarativeConstruct>(
234+
Parser<OpenACCStandaloneDeclarativeConstruct>{})),
235+
sourced(construct<OpenACCDeclarativeConstruct>(
236+
Parser<OpenACCRoutineConstruct>{})))))
235237

236238
// OpenACC constructs
237239
TYPE_CONTEXT_PARSER("OpenACC construct"_en_US,
238240
startAccLine >>
239-
first(construct<OpenACCConstruct>(Parser<OpenACCBlockConstruct>{}),
240-
construct<OpenACCConstruct>(Parser<OpenACCCombinedConstruct>{}),
241-
construct<OpenACCConstruct>(Parser<OpenACCLoopConstruct>{}),
242-
construct<OpenACCConstruct>(Parser<OpenACCStandaloneConstruct>{}),
243-
construct<OpenACCConstruct>(Parser<OpenACCCacheConstruct>{}),
244-
construct<OpenACCConstruct>(Parser<OpenACCWaitConstruct>{}),
245-
construct<OpenACCConstruct>(Parser<OpenACCAtomicConstruct>{})))
241+
withMessage("expected OpenACC directive"_err_en_US,
242+
first(construct<OpenACCConstruct>(Parser<OpenACCBlockConstruct>{}),
243+
construct<OpenACCConstruct>(Parser<OpenACCCombinedConstruct>{}),
244+
construct<OpenACCConstruct>(Parser<OpenACCLoopConstruct>{}),
245+
construct<OpenACCConstruct>(
246+
Parser<OpenACCStandaloneConstruct>{}),
247+
construct<OpenACCConstruct>(Parser<OpenACCCacheConstruct>{}),
248+
construct<OpenACCConstruct>(Parser<OpenACCWaitConstruct>{}),
249+
construct<OpenACCConstruct>(Parser<OpenACCAtomicConstruct>{}))))
246250

247251
TYPE_PARSER(startAccLine >>
248252
sourced(construct<AccEndCombinedDirective>(sourced("END"_tok >>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenacc
2+
3+
! Check parser specific error for OpenACC
4+
5+
6+
subroutine test(a, n)
7+
integer :: a(n)
8+
!ERROR: expected OpenACC directive
9+
!$acc p
10+
integer :: i,j
11+
12+
i = 0
13+
!ERROR: expected OpenACC directive
14+
!$acc p
15+
end subroutine

0 commit comments

Comments
 (0)