[flang-commits] [flang] [flang][openacc][NFC] Issue better error message when directive is wrong (PR #69034)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Fri Oct 13 15:24:51 PDT 2023
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/69034
None
>From 51d50a301ae24207c463b1955171b7acc727c26d Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Fri, 13 Oct 2023 15:23:15 -0700
Subject: [PATCH] [flang][openacc][NFC] Issue better error message when
directive is wrong
---
flang/lib/Parser/openacc-parsers.cpp | 32 ++++++++++++----------
flang/test/Semantics/OpenACC/acc-error.f90 | 15 ++++++++++
2 files changed, 33 insertions(+), 14 deletions(-)
create mode 100644 flang/test/Semantics/OpenACC/acc-error.f90
diff --git a/flang/lib/Parser/openacc-parsers.cpp b/flang/lib/Parser/openacc-parsers.cpp
index 09b30e679de0e06..75aeffd29f92f10 100644
--- a/flang/lib/Parser/openacc-parsers.cpp
+++ b/flang/lib/Parser/openacc-parsers.cpp
@@ -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),
@@ -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 >>
diff --git a/flang/test/Semantics/OpenACC/acc-error.f90 b/flang/test/Semantics/OpenACC/acc-error.f90
new file mode 100644
index 000000000000000..b1c3b7784742992
--- /dev/null
+++ b/flang/test/Semantics/OpenACC/acc-error.f90
@@ -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
More information about the flang-commits
mailing list