Author: Amr Hesham Date: 2025-10-22T08:43:44+02:00 New Revision: f70808c8bfdd7a6048347b2533ccddc34bbb4678
URL: https://github.com/llvm/llvm-project/commit/f70808c8bfdd7a6048347b2533ccddc34bbb4678 DIFF: https://github.com/llvm/llvm-project/commit/f70808c8bfdd7a6048347b2533ccddc34bbb4678.diff LOG: [CIR] Implement CXXDefaultInitExpr for Constants (#164509) Implement the CXXDefaultInitExpr for Constants Added: Modified: clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp clang/test/CIR/CodeGen/struct-init.cpp Removed: ################################################################################ diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp index 65e6a3915f241..800262aac8fa4 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp @@ -1011,9 +1011,9 @@ class ConstExprEmitter } mlir::Attribute VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die, QualType t) { - cgm.errorNYI(die->getBeginLoc(), - "ConstExprEmitter::VisitCXXDefaultInitExpr"); - return {}; + // No need for a DefaultInitExprScope: we don't handle 'this' in a + // constant expression. + return Visit(die->getExpr(), t); } mlir::Attribute VisitExprWithCleanups(ExprWithCleanups *e, QualType t) { diff --git a/clang/test/CIR/CodeGen/struct-init.cpp b/clang/test/CIR/CodeGen/struct-init.cpp index 2887e6f404ffc..cb509994d1cbf 100644 --- a/clang/test/CIR/CodeGen/struct-init.cpp +++ b/clang/test/CIR/CodeGen/struct-init.cpp @@ -15,6 +15,16 @@ S partial_init = { 1 }; // LLVM: @partial_init = global %struct.S { i32 1, i32 0, i32 0 } // OGCG: @partial_init = global %struct.S { i32 1, i32 0, i32 0 } +struct StructWithDefaultInit { + int a = 2; +}; + +StructWithDefaultInit swdi = {}; + +// CIR: cir.global external @swdi = #cir.const_record<{#cir.int<2> : !s32i}> : !rec_StructWithDefaultInit +// LLVM: @swdi = global %struct.StructWithDefaultInit { i32 2 }, align 4 +// OGCG: @swdi = global %struct.StructWithDefaultInit { i32 2 }, align 4 + void init() { S s1 = {1, 2, 3}; S s2 = {4, 5}; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
