[clang] [OpenMP] Add runtime selection for metadirective with non-constant conditions. (PR #192455)

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 28 12:47:01 PDT 2026


================
@@ -2689,6 +2722,88 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
     // A single match is returned for OpenMP 5.0
     int BestIdx = getBestVariantMatchForContext(VMIs, OMPCtx);
 
+    // Check if we have any user conditions.
+    bool HasUserCondition = false;
+    for (OMPTraitInfo *TI : TraitInfos) {
+      if (TI && TI->hasUserCondition()) {
+        HasUserCondition = true;
+        break;
+      }
+    }
+    // If we have user conditions, collect all variants.
+    if (HasUserCondition) {
+      // Collect all variants with their conditions.
+      SmallVector<OpenMPDirectiveKind, 4> DirectiveKinds;
+      SmallVector<Expr *, 4> Conditions;
+      SmallVector<OpenMPClauseKind, 4> ClauseKinds;
+      SmallVector<Stmt *, 4> VariantDirectives;
+
+      while (Tok.isNot(tok::annot_pragma_openmp_end)) {
+        OpenMPClauseKind CKind = Tok.isAnnotation()
+                                     ? OMPC_unknown
+                                     : getOpenMPClauseKind(PP.getSpelling(Tok));
+        SourceLocation ClauseLoc = ConsumeToken();
+
+        // Parse '('.
+        T.consumeOpen();
+
+        Expr *Condition = nullptr;
+        if (CKind == OMPC_when) {
+          OMPTraitInfo &TI = Actions.getASTContext().getNewOMPTraitInfo();
+          parseOMPContextSelectors(ClauseLoc, TI);
+
+          // Extract user condition if present.
+          TI.anyScoreOrCondition([&](Expr *&E, bool IsScore) {
+            if (!IsScore && E) {
+              Condition = E;
+              return true;
+            }
+            return false;
+          });
----------------
alexey-bataev wrote:

What if Condition remains nullptr here?

https://github.com/llvm/llvm-project/pull/192455


More information about the cfe-commits mailing list