Skip to content

Conversation

@kparzysz
Copy link
Contributor

The "workshare" construct is only present in Fortran. The common OpenMP code does treat it as any other directive, but in clang we need to reject it, and do so gracefully before it encounters an internal assertion.

Fixes #139424

The "workshare" construct is only present in Fortran. The common OpenMP
code does treat it as any other directive, but in clang we need to reject
it, and do so gracefully before it encounters an internal assertion.

Fixes llvm#139424
@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 13, 2025
@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-clang

Author: Krzysztof Parzyszek (kparzysz)

Changes

The "workshare" construct is only present in Fortran. The common OpenMP code does treat it as any other directive, but in clang we need to reject it, and do so gracefully before it encounters an internal assertion.

Fixes #139424


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

2 Files Affected:

  • (modified) clang/lib/Parse/ParseOpenMP.cpp (+5)
  • (added) clang/test/OpenMP/openmp_workshare.c (+8)
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 85838feae77d3..2f4a1103cc3b3 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2738,6 +2738,11 @@ 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.
+    DKind = OMPD_unknown;
+  }
 
   StmtResult Directive = StmtError();
 
diff --git a/clang/test/OpenMP/openmp_workshare.c b/clang/test/OpenMP/openmp_workshare.c
new file mode 100644
index 0000000000000..0302eb19f9ef4
--- /dev/null
+++ b/clang/test/OpenMP/openmp_workshare.c
@@ -0,0 +1,8 @@
+// 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 kparzysz merged commit 3abd77a into llvm:main May 14, 2025
15 checks passed
@kparzysz kparzysz deleted the users/kparzysz/cxx-workshare branch May 14, 2025 12:06
@AaronBallman
Copy link
Collaborator

Thank you for the quick fix!

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.

[OpenMP] UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/Basic/OpenMPKinds.cpp:855!

4 participants