Skip to content

Commit 9273091

Browse files
authored
[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.
1 parent 8e2ac7d commit 9273091

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,9 +2613,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
26132613
Diag(Tok, diag::err_omp_unknown_directive);
26142614
return StmtError();
26152615
}
2616-
if (DKind == OMPD_workshare) {
2617-
// "workshare" is an executable, Fortran-only directive. Treat it
2618-
// as unknown.
2616+
if (!(getDirectiveLanguages(DKind) & SourceLanguage::C)) {
2617+
// Treat directives that are not allowed in C/C++ as unknown.
26192618
DKind = OMPD_unknown;
26202619
}
26212620

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s
2+
3+
// Test the reaction to some Fortran-only directives.
4+
5+
void foo() {
6+
#pragma omp allocators // expected-error {{expected an OpenMP directive}}
7+
#pragma omp do // expected-error {{expected an OpenMP directive}}
8+
#pragma omp end workshare // expected-error {{expected an OpenMP directive}}
9+
#pragma omp parallel workshare // expected-warning {{extra tokens at the end of '#pragma omp parallel' are ignored}}
10+
#pragma omp workshare // expected-error {{expected an OpenMP directive}}
11+
}
12+

clang/test/OpenMP/openmp_workshare.c

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)