llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
25.95k stars 10.59k forks source link

[Flang][OpenMP] Give better errors during parsing failures #90480

Closed kiranchandramohan closed 2 weeks ago

kiranchandramohan commented 2 weeks ago

Similar to OpenACC handling.

Fixes #90452

llvmbot commented 2 weeks ago

@llvm/pr-subscribers-flang-parser

@llvm/pr-subscribers-flang-openmp

Author: Kiran Chandramohan (kiranchandramohan)

Changes Similar to OpenACC handling. Fixes #90452 --- Full diff: https://github.com/llvm/llvm-project/pull/90480.diff 3 Files Affected: - (modified) flang/lib/Parser/openmp-parsers.cpp (+26-23) - (added) flang/test/Parser/OpenMP/fail-construct1.f90 (+5) - (added) flang/test/Parser/OpenMP/fail-construct2.f90 (+5) ``````````diff 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( - Parser{}) || - construct( - Parser{}) || - construct( - Parser{}) || - construct( - Parser{}) || - construct( - Parser{}) || - construct(Parser{})) / - endOmpLine) + withMessage("expected OpenMP construct"_err_en_US, + sourced(construct( + Parser{}) || + construct( + Parser{}) || + construct( + Parser{}) || + construct( + Parser{}) || + construct( + Parser{}) || + construct( + Parser{})) / + endOmpLine)) // Block Construct TYPE_PARSER(construct( @@ -681,17 +683,18 @@ TYPE_PARSER(construct( TYPE_CONTEXT_PARSER("OpenMP construct"_en_US, startOmpLine >> - first(construct(Parser{}), - construct(Parser{}), - construct(Parser{}), - // OpenMPBlockConstruct is attempted before - // OpenMPStandaloneConstruct to resolve !$OMP ORDERED - construct(Parser{}), - construct(Parser{}), - construct(Parser{}), - construct(Parser{}), - construct(Parser{}), - construct(Parser{}))) + withMessage("expected OpenMP construct"_err_en_US, + first(construct(Parser{}), + construct(Parser{}), + construct(Parser{}), + // OpenMPBlockConstruct is attempted before + // OpenMPStandaloneConstruct to resolve !$OMP ORDERED + construct(Parser{}), + construct(Parser{}), + construct(Parser{}), + construct(Parser{}), + construct(Parser{}), + construct(Parser{})))) // 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 ``````````