[flang-commits] [flang] [flang][OpenMP] Tolerate compiler directives in loop constructs (PR #169346)

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Mon Nov 24 12:52:02 PST 2025


================
@@ -796,6 +796,28 @@ static void processTileSizesFromOpenMPConstruct(
   }
 }
 
+static pft::Evaluation *getNestedDoConstruct(pft::Evaluation &eval) {
+  for (pft::Evaluation &nested : eval.getNestedEvaluations()) {
+    // In an OpenMPConstruct there can be compiler directives:
+    // 1 <<OpenMPConstruct>>
+    //     2 CompilerDirective: !unroll
+    //     <<DoConstruct>> -> 8
+    if (nested.getIf<parser::CompilerDirective>())
+      continue;
+    // Within a DoConstruct, there can be compiler directives, plus
+    // there is a DoStmt before the body:
+    // <<DoConstruct>> -> 8
+    //     3 NonLabelDoStmt -> 7: do i = 1, n
+    //     <<DoConstruct>> -> 7
+    if (nested.getIf<parser::NonLabelDoStmt>())
+      continue;
+    assert(nested.getIf<parser::DoConstruct>() &&
+           "Unexpected construct in the nested evaluations");
+    return &nested;
+  }
+  llvm_unreachable("Expected do loop to be in the nested evaluations");
+}
----------------
kparzysz wrote:

`getNestedDoConstruct` is currently used in all cases where we traverse the nest, but it has the same limitations as the preexisting code.

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


More information about the flang-commits mailing list