Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[clang][OpenMP] Improve handling of non-C/C++ directives #139961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 15, 2025

Conversation

kparzysz
Copy link
Contributor

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.

kparzysz added 3 commits May 14, 2025 14:35
Add a logical (boolean) "not" operator.
The official languages that OpenMP recognizes are C/C++ and Fortran.
Some OpenMP directives are language-specific, some are C/C++-only,
some are Fortran-only.

Add a property to the TableGen definition of Directive that will be the
list of languages that allow the directive.

The TableGen backend will then generate a bitmask-like enumeration
SourceLanguages, and a function
  SourceLanguages getDirectiveLanguages(Directive D);
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.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang labels May 14, 2025
@llvmbot
Copy link
Member

llvmbot commented May 14, 2025

@llvm/pr-subscribers-clang

Author: Krzysztof Parzyszek (kparzysz)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/139961.diff

3 Files Affected:

  • (modified) clang/lib/Parse/ParseOpenMP.cpp (+2-3)
  • (added) clang/test/OpenMP/openmp_non_c_directives.c (+12)
  • (removed) clang/test/OpenMP/openmp_workshare.c (-8)
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index c409409602e75..a53fd6b2964cb 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}}
-}
-

@kparzysz
Copy link
Contributor Author

Previous PR: #139960

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for the general fix!

Base automatically changed from users/kparzysz/spr/n02-tablegen-lang to main May 15, 2025 12:36
@kparzysz kparzysz merged commit 9273091 into main May 15, 2025
15 checks passed
@kparzysz kparzysz deleted the users/kparzysz/spr/n03-clang-unknown branch May 15, 2025 12:37
TIFitis pushed a commit to TIFitis/llvm-project that referenced this pull request May 19, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.