[flang-commits] [flang] [Flang][OpenMP] Give better errors during parsing failures (PR #90480)
Kiran Chandramohan via flang-commits
flang-commits at lists.llvm.org
Mon Apr 29 07:40:10 PDT 2024
https://github.com/kiranchandramohan created https://github.com/llvm/llvm-project/pull/90480
Similar to OpenACC handling.
Fixes #90452
>From c66b6efbd1719e5200c3260759ed5a6e597c185c Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan <kiran.chandramohan at arm.com>
Date: Mon, 29 Apr 2024 13:27:28 +0000
Subject: [PATCH] [Flang][OpenMP] Give better errors during parsing failures
Similar to OpenACC handling.
---
flang/lib/Parser/openmp-parsers.cpp | 49 +++++++++++---------
flang/test/Parser/OpenMP/fail-construct1.f90 | 5 ++
flang/test/Parser/OpenMP/fail-construct2.f90 | 5 ++
3 files changed, 36 insertions(+), 23 deletions(-)
create mode 100644 flang/test/Parser/OpenMP/fail-construct1.f90
create mode 100644 flang/test/Parser/OpenMP/fail-construct2.f90
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index eae4784169146e..48f213794247da 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -634,18 +634,20 @@ TYPE_PARSER(
// Declarative constructs
TYPE_PARSER(startOmpLine >>
- sourced(construct<OpenMPDeclarativeConstruct>(
- Parser<OpenMPDeclareReductionConstruct>{}) ||
- construct<OpenMPDeclarativeConstruct>(
- Parser<OpenMPDeclareSimdConstruct>{}) ||
- construct<OpenMPDeclarativeConstruct>(
- Parser<OpenMPDeclareTargetConstruct>{}) ||
- construct<OpenMPDeclarativeConstruct>(
- Parser<OpenMPDeclarativeAllocate>{}) ||
- construct<OpenMPDeclarativeConstruct>(
- Parser<OpenMPRequiresConstruct>{}) ||
- construct<OpenMPDeclarativeConstruct>(Parser<OpenMPThreadprivate>{})) /
- endOmpLine)
+ withMessage("expected OpenMP construct"_err_en_US,
+ sourced(construct<OpenMPDeclarativeConstruct>(
+ Parser<OpenMPDeclareReductionConstruct>{}) ||
+ construct<OpenMPDeclarativeConstruct>(
+ Parser<OpenMPDeclareSimdConstruct>{}) ||
+ construct<OpenMPDeclarativeConstruct>(
+ Parser<OpenMPDeclareTargetConstruct>{}) ||
+ construct<OpenMPDeclarativeConstruct>(
+ Parser<OpenMPDeclarativeAllocate>{}) ||
+ construct<OpenMPDeclarativeConstruct>(
+ Parser<OpenMPRequiresConstruct>{}) ||
+ construct<OpenMPDeclarativeConstruct>(
+ Parser<OpenMPThreadprivate>{})) /
+ endOmpLine))
// Block Construct
TYPE_PARSER(construct<OpenMPBlockConstruct>(
@@ -681,17 +683,18 @@ TYPE_PARSER(construct<OpenMPSectionsConstruct>(
TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
startOmpLine >>
- first(construct<OpenMPConstruct>(Parser<OpenMPSectionsConstruct>{}),
- construct<OpenMPConstruct>(Parser<OpenMPLoopConstruct>{}),
- construct<OpenMPConstruct>(Parser<OpenMPBlockConstruct>{}),
- // OpenMPBlockConstruct is attempted before
- // OpenMPStandaloneConstruct to resolve !$OMP ORDERED
- construct<OpenMPConstruct>(Parser<OpenMPStandaloneConstruct>{}),
- construct<OpenMPConstruct>(Parser<OpenMPAtomicConstruct>{}),
- construct<OpenMPConstruct>(Parser<OpenMPExecutableAllocate>{}),
- construct<OpenMPConstruct>(Parser<OpenMPAllocatorsConstruct>{}),
- construct<OpenMPConstruct>(Parser<OpenMPDeclarativeAllocate>{}),
- construct<OpenMPConstruct>(Parser<OpenMPCriticalConstruct>{})))
+ withMessage("expected OpenMP construct"_err_en_US,
+ first(construct<OpenMPConstruct>(Parser<OpenMPSectionsConstruct>{}),
+ construct<OpenMPConstruct>(Parser<OpenMPLoopConstruct>{}),
+ construct<OpenMPConstruct>(Parser<OpenMPBlockConstruct>{}),
+ // OpenMPBlockConstruct is attempted before
+ // OpenMPStandaloneConstruct to resolve !$OMP ORDERED
+ construct<OpenMPConstruct>(Parser<OpenMPStandaloneConstruct>{}),
+ construct<OpenMPConstruct>(Parser<OpenMPAtomicConstruct>{}),
+ construct<OpenMPConstruct>(Parser<OpenMPExecutableAllocate>{}),
+ construct<OpenMPConstruct>(Parser<OpenMPAllocatorsConstruct>{}),
+ construct<OpenMPConstruct>(Parser<OpenMPDeclarativeAllocate>{}),
+ construct<OpenMPConstruct>(Parser<OpenMPCriticalConstruct>{}))))
// END OMP Block directives
TYPE_PARSER(
diff --git a/flang/test/Parser/OpenMP/fail-construct1.f90 b/flang/test/Parser/OpenMP/fail-construct1.f90
new file mode 100644
index 00000000000000..f0ee22125cee03
--- /dev/null
+++ b/flang/test/Parser/OpenMP/fail-construct1.f90
@@ -0,0 +1,5 @@
+! RUN: not %flang_fc1 -fsyntax-only -fopenmp %s 2>&1 | FileCheck %s
+
+! CHECK: error: expected OpenMP construct
+!$omp parallel
+end
diff --git a/flang/test/Parser/OpenMP/fail-construct2.f90 b/flang/test/Parser/OpenMP/fail-construct2.f90
new file mode 100644
index 00000000000000..b7f5736d1329b1
--- /dev/null
+++ b/flang/test/Parser/OpenMP/fail-construct2.f90
@@ -0,0 +1,5 @@
+! RUN: not %flang_fc1 -fsyntax-only -fopenmp %s 2>&1 | FileCheck %s
+
+! CHECK: error: expected OpenMP construct
+!$omp dummy
+end
More information about the flang-commits
mailing list