[clang] [CIR] Upstream initial for-loop support (PR #132266)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 20 11:55:06 PDT 2025


================
@@ -280,3 +313,77 @@ mlir::LogicalResult CIRGenFunction::emitReturnStmt(const ReturnStmt &s) {
 
   return mlir::success();
 }
+
+mlir::LogicalResult CIRGenFunction::emitForStmt(const ForStmt &s) {
+  cir::ForOp forOp;
+
+  // TODO: pass in an array of attributes.
+  auto forStmtBuilder = [&]() -> mlir::LogicalResult {
+    mlir::LogicalResult loopRes = mlir::success();
+    // Evaluate the first part before the loop.
+    if (s.getInit())
----------------
andykaylor wrote:

We are creating a lexical scope. This lambda gets called from the `builder.create<ScopeOp>` call on line 377, which also creates the lexical scope and sets that as the insertion point.

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


More information about the cfe-commits mailing list