[clang] [CIR] Upstream support for range-based for loops (PR #138176)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu May 1 11:50:12 PDT 2025


================
@@ -547,6 +548,83 @@ mlir::LogicalResult CIRGenFunction::emitSwitchCase(const SwitchCase &s,
   llvm_unreachable("expect case or default stmt");
 }
 
+mlir::LogicalResult
+CIRGenFunction::emitCXXForRangeStmt(const CXXForRangeStmt &s,
+                                    ArrayRef<const Attr *> forAttrs) {
+  cir::ForOp forOp;
+
+  // TODO(cir): pass in array of attributes.
+  auto forStmtBuilder = [&]() -> mlir::LogicalResult {
+    mlir::LogicalResult loopRes = mlir::success();
+    // Evaluate the first pieces before the loop.
+    if (s.getInit())
----------------
erichkeane wrote:

can we have a test that shows an init?  Something like: 
```
void foo() {
    for (int arr[]{1,2,3,4}; auto x : arr){}
}
```

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


More information about the cfe-commits mailing list