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

via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 20 06:58:30 PDT 2025


https://github.com/Ritanya-B-Bharadwaj updated https://github.com/llvm/llvm-project/pull/148583

>From cc247bc1eb330dd2d3ccebabc7c1d3b524073627 Mon Sep 17 00:00:00 2001
From: Ritanya B Bharadwaj <ritanya.b.bharadwaj at gmail.com>
Date: Mon, 14 Jul 2025 03:18:25 -0500
Subject: [PATCH 1/2] [Clang][OpenMP] Fixing error - 147336

---
 clang/lib/Parse/ParseOpenMP.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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();

>From d6c4b97a36125e300e079905038ff9d93d1319b5 Mon Sep 17 00:00:00 2001
From: Ritanya B Bharadwaj <ritanya.b.bharadwaj at gmail.com>
Date: Thu, 17 Jul 2025 00:37:04 -0500
Subject: [PATCH 2/2] Adding a lit test case

---
 clang/test/OpenMP/metadirective_messages.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang/test/OpenMP/metadirective_messages.cpp b/clang/test/OpenMP/metadirective_messages.cpp
index 9d2934f8b1e10..7426f915bf99e 100644
--- a/clang/test/OpenMP/metadirective_messages.cpp
+++ b/clang/test/OpenMP/metadirective_messages.cpp
@@ -47,6 +47,10 @@ void foo() {
       ;
     #pragma omp metadirective when(device = {arch(nvptx)} : parallel) xyz() //expected-error {{expected at least one clause on '#pragma omp metadirective' directive}} 
       ;
+    int a = 0;
+    int b = 1;
+    #pragma omp metadirective when(user={condition(a)}: parallel for simd) when(user={condition(b)}: target teams distribute parallel for simd)
+      for (int i = 0; i < 10; ++i) {}
   #endif
   }
 



More information about the cfe-commits mailing list