Skip to content

[Clang][OpenMP] Fixing Clang error for metadirective with multiple when clauses and no otherwise #148583

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Ritanya-B-Bharadwaj
Copy link
Contributor

Fixing - #147336

@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 Jul 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 14, 2025

@llvm/pr-subscribers-clang

Author: None (Ritanya-B-Bharadwaj)

Changes

Fixing - #147336


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

1 Files Affected:

  • (modified) clang/lib/Parse/ParseOpenMP.cpp (+1-1)
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index aa6a0c61a2c17..5db2f2e2ccf86 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2704,7 +2704,7 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
     // If no match is found and no otherwise clause is present, skip
     // OMP5.2 Chapter 7.4: If no otherwise clause is specified the effect is as
     // if one was specified without an associated directive variant.
-    if (BestIdx == -1 && Idx == 1) {
+    if (BestIdx == -1 && Idx > 0) {
       assert(Tok.is(tok::annot_pragma_openmp_end) &&
              "Expecting the end of the pragma here");
       ConsumeAnnotationToken();

@zahiraam
Copy link
Contributor

You need to add a LIT test.

@Ritanya-B-Bharadwaj
Copy link
Contributor Author

You need to add a LIT test.

Done!

: parallel for) when(implementation = {extension(match_none)} \
: parallel)
for (int i=0; i<10; i++)
;
Copy link
Contributor

Choose a reason for hiding this comment

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

The LIT test is passing even without your change above. It needs a bit more work. Furthermore your patch doesn't seem to be enough. The reproducer in #147336 is still failing with your patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed the lit test case. The reproducer passes with this patch.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest adding this:
#pragma omp metadirective when(user = {condition(0)} \
: parallel for) when(user = {condition(0)} \
: target teams distribute parallel for)
for (int i = 0; i < 100; i++)
;

to OpenMP/metadirective_otherwise.cpp instead. You will need to edit the IR generated.

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.

3 participants