[clang] [CIR] Implement BinComma Expr for AggregateExpr (PR #161823)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 3 11:35:09 PDT 2025
================
@@ -183,3 +183,25 @@ void generic_selection() {
// OGCG: %[[C_ADDR:.*]] = alloca i32, align 4
// OGCG: %[[D_ADDR:.*]] = alloca %struct.CompleteS, align 4
// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[D_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)
+
+void bin_comma() {
+ CompleteS a = (CompleteS(), CompleteS());
+}
+
+// CIR: cir.func{{.*}} @_Z9bin_commav()
+// CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a", init]
+// CIR: %[[TMP_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["agg.tmp0"]
+// CIR: %[[ZERO:.*]] = cir.const #cir.zero : !rec_CompleteS
+// CIR: cir.store{{.*}} %[[ZERO]], %[[TMP_ADDR]] : !rec_CompleteS, !cir.ptr<!rec_CompleteS>
+// CIR: %[[ZERO:.*]] = cir.const #cir.zero : !rec_CompleteS
+// CIR: cir.store{{.*}} %[[ZERO]], %[[A_ADDR]] : !rec_CompleteS, !cir.ptr<!rec_CompleteS>
+
+// LLVM: define{{.*}} void @_Z9bin_commav()
+// LLVM: %[[A_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
+// LLVM: %[[TMP_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
----------------
AmrDeveloper wrote:
The difference is from `CodeGenFunction::EmitAnyExpr` there is extra param `ignoreResult` and the temporary is emitted only if ignoreResult is false which is false by default
OGCG: https://github.com/llvm/llvm-project/blob/eabfed8690a1e87056140c1b311f82457e27feb9/clang/lib/CodeGen/CGExpr.cpp#L273
https://github.com/llvm/llvm-project/blob/eabfed8690a1e87056140c1b311f82457e27feb9/clang/lib/CIR/CodeGen/CIRGenExpr.cpp#L1630
https://github.com/llvm/llvm-project/pull/161823
More information about the cfe-commits
mailing list