Skip to content

Commit 779f40c

Browse files
[Flang][OpenMP] Give better errors during parsing failures (#90480)
Similar to OpenACC handling. Fixes #90452
1 parent 981aa6f commit 779f40c

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -634,18 +634,20 @@ TYPE_PARSER(
634634

635635
// Declarative constructs
636636
TYPE_PARSER(startOmpLine >>
637-
sourced(construct<OpenMPDeclarativeConstruct>(
638-
Parser<OpenMPDeclareReductionConstruct>{}) ||
639-
construct<OpenMPDeclarativeConstruct>(
640-
Parser<OpenMPDeclareSimdConstruct>{}) ||
641-
construct<OpenMPDeclarativeConstruct>(
642-
Parser<OpenMPDeclareTargetConstruct>{}) ||
643-
construct<OpenMPDeclarativeConstruct>(
644-
Parser<OpenMPDeclarativeAllocate>{}) ||
645-
construct<OpenMPDeclarativeConstruct>(
646-
Parser<OpenMPRequiresConstruct>{}) ||
647-
construct<OpenMPDeclarativeConstruct>(Parser<OpenMPThreadprivate>{})) /
648-
endOmpLine)
637+
withMessage("expected OpenMP construct"_err_en_US,
638+
sourced(construct<OpenMPDeclarativeConstruct>(
639+
Parser<OpenMPDeclareReductionConstruct>{}) ||
640+
construct<OpenMPDeclarativeConstruct>(
641+
Parser<OpenMPDeclareSimdConstruct>{}) ||
642+
construct<OpenMPDeclarativeConstruct>(
643+
Parser<OpenMPDeclareTargetConstruct>{}) ||
644+
construct<OpenMPDeclarativeConstruct>(
645+
Parser<OpenMPDeclarativeAllocate>{}) ||
646+
construct<OpenMPDeclarativeConstruct>(
647+
Parser<OpenMPRequiresConstruct>{}) ||
648+
construct<OpenMPDeclarativeConstruct>(
649+
Parser<OpenMPThreadprivate>{})) /
650+
endOmpLine))
649651

650652
// Block Construct
651653
TYPE_PARSER(construct<OpenMPBlockConstruct>(
@@ -681,17 +683,18 @@ TYPE_PARSER(construct<OpenMPSectionsConstruct>(
681683

682684
TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
683685
startOmpLine >>
684-
first(construct<OpenMPConstruct>(Parser<OpenMPSectionsConstruct>{}),
685-
construct<OpenMPConstruct>(Parser<OpenMPLoopConstruct>{}),
686-
construct<OpenMPConstruct>(Parser<OpenMPBlockConstruct>{}),
687-
// OpenMPBlockConstruct is attempted before
688-
// OpenMPStandaloneConstruct to resolve !$OMP ORDERED
689-
construct<OpenMPConstruct>(Parser<OpenMPStandaloneConstruct>{}),
690-
construct<OpenMPConstruct>(Parser<OpenMPAtomicConstruct>{}),
691-
construct<OpenMPConstruct>(Parser<OpenMPExecutableAllocate>{}),
692-
construct<OpenMPConstruct>(Parser<OpenMPAllocatorsConstruct>{}),
693-
construct<OpenMPConstruct>(Parser<OpenMPDeclarativeAllocate>{}),
694-
construct<OpenMPConstruct>(Parser<OpenMPCriticalConstruct>{})))
686+
withMessage("expected OpenMP construct"_err_en_US,
687+
first(construct<OpenMPConstruct>(Parser<OpenMPSectionsConstruct>{}),
688+
construct<OpenMPConstruct>(Parser<OpenMPLoopConstruct>{}),
689+
construct<OpenMPConstruct>(Parser<OpenMPBlockConstruct>{}),
690+
// OpenMPBlockConstruct is attempted before
691+
// OpenMPStandaloneConstruct to resolve !$OMP ORDERED
692+
construct<OpenMPConstruct>(Parser<OpenMPStandaloneConstruct>{}),
693+
construct<OpenMPConstruct>(Parser<OpenMPAtomicConstruct>{}),
694+
construct<OpenMPConstruct>(Parser<OpenMPExecutableAllocate>{}),
695+
construct<OpenMPConstruct>(Parser<OpenMPAllocatorsConstruct>{}),
696+
construct<OpenMPConstruct>(Parser<OpenMPDeclarativeAllocate>{}),
697+
construct<OpenMPConstruct>(Parser<OpenMPCriticalConstruct>{}))))
695698

696699
// END OMP Block directives
697700
TYPE_PARSER(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
! RUN: not %flang_fc1 -fsyntax-only -fopenmp %s 2>&1 | FileCheck %s
2+
3+
! CHECK: error: expected OpenMP construct
4+
!$omp parallel
5+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
! RUN: not %flang_fc1 -fsyntax-only -fopenmp %s 2>&1 | FileCheck %s
2+
3+
! CHECK: error: expected OpenMP construct
4+
!$omp dummy
5+
end

0 commit comments

Comments
 (0)