[clang] [CIR] Implement ChooseExpr for AggregateExpr (PR #160999)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 29 11:32:46 PDT 2025


================
@@ -93,3 +93,27 @@ void f3() {
 // OGCG:   %[[O:.*]] = alloca %struct.Outer, align 4
 // OGCG:   %[[O_I:.*]] = getelementptr inbounds nuw %struct.Outer, ptr %[[O]], i32 0, i32 0
 // OGCG:   %[[O_I_N:.*]] = getelementptr inbounds nuw %struct.Inner, ptr %[[O_I]], i32 0, i32 0
+
+void choose_expr() {
+  CompleteS a;
+  CompleteS b;
+  CompleteS c = __builtin_choose_expr(true, a, b);
+}
+
+// CIR: cir.func{{.*}} @_Z11choose_exprv()
+// CIR:   %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a"]
+// CIR:   %[[B_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["b"]
+// CIR:   %[[C_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["c", init]
+// CIR:   cir.call @_ZN9CompleteSC1ERKS_(%[[C_ADDR]], %[[A_ADDR]]) nothrow : (!cir.ptr<!rec_CompleteS>, !cir.ptr<!rec_CompleteS>) -> ()
----------------
andykaylor wrote:

Can you add a comment somewhere that this should be replaced by `cir.copy` and maybe create an iffue to track it? The incubator does that in LoweringPrepare, but I'm not sure why we are generating a call to a default trivial copy constructor at all.

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


More information about the cfe-commits mailing list