[clang] [CIR][NFC] Fix loop op examples in CIROps.td (PR #216457)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 14 23:48:28 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clangir

Author: Jiahao Guo (E00N777)

<details>
<summary>Changes</summary>

### summary
The cir.while example had cond and body swapped, and several loop examples used outdated cir.condition / cir.for syntax. Also add short examples of the optional per-iteration cleanup region.

Generated by Grok 4.6, but manually reviewed.

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


1 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+23-7) 


``````````diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 0f034a4f1f7fa..aec0801fdb7be 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -996,8 +996,8 @@ def CIR_ConditionOp : CIR_Op<"condition", [
     Example:
 
     ```
-    cir.for cond {
-      cir.condition(%val) // Branches to `step` region or exits.
+    cir.for : cond {
+      cir.condition(%val) // Branches to `body` region or exits.
     } body {
       cir.yield
     } step {
@@ -2224,11 +2224,17 @@ def CIR_WhileOp : CIR_WhileOpBase<"while"> {
 
     ```
     cir.while {
-      cir.break
-    ^bb2:
+      cir.condition(%cond)
+    } do {
       cir.yield
+    }
+
+    cir.while {
+      cir.condition(%cond)
     } do {
-      cir.condition %cond : cir.bool
+      cir.yield
+    } cleanup all {
+      cir.yield
     }
     ```
   }];
@@ -2293,7 +2299,7 @@ def CIR_DoWhileOp : CIR_WhileOpBase<"do"> {
     ^bb2:
       cir.yield
     } while {
-      cir.condition %cond : cir.bool
+      cir.condition(%cond)
     }
     ```
   }];
@@ -2324,7 +2330,7 @@ def CIR_ForOp : CIR_LoopOpBase<"for"> {
     Example:
 
     ```
-    cir.for cond {
+    cir.for : cond {
       cir.condition(%val)
     } body {
       cir.break
@@ -2333,6 +2339,16 @@ def CIR_ForOp : CIR_LoopOpBase<"for"> {
     } step {
       cir.yield
     }
+
+    cir.for : cond {
+      cir.condition(%val)
+    } body {
+      cir.yield
+    } step {
+      cir.yield
+    } cleanup all {
+      cir.yield
+    }
     ```
   }];
 

``````````

</details>


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


More information about the cfe-commits mailing list