[flang-commits] [flang] [flang][OpenMP] Provide reasons for calculated depths (PR #187781)

Michael Kruse via flang-commits flang-commits at lists.llvm.org
Mon Mar 23 08:27:42 PDT 2026


================
@@ -1157,45 +1157,68 @@ std::optional<int64_t> LoopSequence::getNestedLength() const {
 }
 
 LoopSequence::Depth LoopSequence::calculateDepths() const {
-  auto plus{[](std::optional<int64_t> a,
-                std::optional<int64_t> b) -> std::optional<int64_t> {
-    if (a && b) {
-      return *a + *b;
-    }
-    return std::nullopt;
-  }};
-
-  // The sequence length is calculated first, so we already know if this
-  // sequence is a nest or not.
-  if (!isNest()) {
-    return Depth{0, 0};
-  }
-
   // Get the length of the nested sequence. The invalidIC_ and opaqueIC_
   // members do not count canonical loop nests, but there can only be one
   // for depth to make sense.
   std::optional<int64_t> length{getNestedLength()};
   // Get the depths of the code nested in this sequence (e.g. contained in
   // entry_), and use it as the basis for the depths of entry_->owner.
   auto [semaDepth, perfDepth]{getNestedDepths()};
-  if (invalidIC_ || length.value_or(0) != 1) {
-    semaDepth = perfDepth = 0;
-  } else if (opaqueIC_ || length.value_or(0) != 1) {
-    perfDepth = 0;
+  if (invalidIC_) {
+    parser::CharBlock source{*parser::GetSource(*invalidIC_)};
+    if (semaDepth.value > 9) {
+      semaDepth.value = 0;
+      semaDepth.reason.Say(
+          source, "This is not a valid intervening code"_because_en_US);
+    }
+    if (perfDepth.value > 0) {
+      perfDepth.value = 0;
+      perfDepth.reason.Say(
+          source, "This is not a valid intervening code"_because_en_US);
+    }
+  } else if (opaqueIC_) {
+    parser::CharBlock source{*parser::GetSource(*opaqueIC_)};
+    if (perfDepth.value > 0) {
+      perfDepth.value = 0;
+      perfDepth.reason.Say(
+          source, "This code prevents perfect nesting"_because_en_US);
+    }
+  }
+  if (length.value_or(0) != 1) {
+    // This may simply be the bottom of the loop nest. Only emit messages
+    // if the depths are reset back to 0.
+    if (entry_->owner) {
+      parser::CharBlock source{*parser::GetSource(*entry_->owner)};
+      if (semaDepth.value > 0) {
+        semaDepth.reason.Say(source,
+            "This construct does not contain a loop nest"_because_en_US);
----------------
Meinersbur wrote:

No test for this message?

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


More information about the flang-commits mailing list