Author: Krzysztof Parzyszek Date: 2025-05-15T07:37:41-05:00 New Revision: 9273091502994f9b68ca0d1fd04fadd02c0a36df
URL: https://github.com/llvm/llvm-project/commit/9273091502994f9b68ca0d1fd04fadd02c0a36df DIFF: https://github.com/llvm/llvm-project/commit/9273091502994f9b68ca0d1fd04fadd02c0a36df.diff LOG: [clang][OpenMP] Improve handling of non-C/C++ directives (#139961) The PR139793 added handling of the Fortran-only "workshare" directive, however there are more such directives, e.g. "allocators". Use the genDirectiveLanguages function to detect non-C/C++ directives instead of enumerating them. Added: clang/test/OpenMP/openmp_non_c_directives.c Modified: clang/lib/Parse/ParseOpenMP.cpp Removed: clang/test/OpenMP/openmp_workshare.c ################################################################################ diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index d7840d97e8d9b..cfffcdb01a514 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -2613,9 +2613,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( Diag(Tok, diag::err_omp_unknown_directive); return StmtError(); } - if (DKind == OMPD_workshare) { - // "workshare" is an executable, Fortran-only directive. Treat it - // as unknown. + if (!(getDirectiveLanguages(DKind) & SourceLanguage::C)) { + // Treat directives that are not allowed in C/C++ as unknown. DKind = OMPD_unknown; } diff --git a/clang/test/OpenMP/openmp_non_c_directives.c b/clang/test/OpenMP/openmp_non_c_directives.c new file mode 100644 index 0000000000000..844d7dad551bc --- /dev/null +++ b/clang/test/OpenMP/openmp_non_c_directives.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s + +// Test the reaction to some Fortran-only directives. + +void foo() { +#pragma omp allocators // expected-error {{expected an OpenMP directive}} +#pragma omp do // expected-error {{expected an OpenMP directive}} +#pragma omp end workshare // expected-error {{expected an OpenMP directive}} +#pragma omp parallel workshare // expected-warning {{extra tokens at the end of '#pragma omp parallel' are ignored}} +#pragma omp workshare // expected-error {{expected an OpenMP directive}} +} + diff --git a/clang/test/OpenMP/openmp_workshare.c b/clang/test/OpenMP/openmp_workshare.c deleted file mode 100644 index 0302eb19f9ef4..0000000000000 --- a/clang/test/OpenMP/openmp_workshare.c +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s - -// Workshare is a Fortran-only directive. - -void foo() { -#pragma omp workshare // expected-error {{expected an OpenMP directive}} -} - _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits