Skip to content

Commit 4fdc774

Browse files
AmrDeveloperaokblast
authored andcommitted
[CIR] Implement CXXDefaultInitExpr for Constants (llvm#164509)
Implement the CXXDefaultInitExpr for Constants
1 parent 261f8eb commit 4fdc774

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,9 +1011,9 @@ class ConstExprEmitter
10111011
}
10121012

10131013
mlir::Attribute VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die, QualType t) {
1014-
cgm.errorNYI(die->getBeginLoc(),
1015-
"ConstExprEmitter::VisitCXXDefaultInitExpr");
1016-
return {};
1014+
// No need for a DefaultInitExprScope: we don't handle 'this' in a
1015+
// constant expression.
1016+
return Visit(die->getExpr(), t);
10171017
}
10181018

10191019
mlir::Attribute VisitExprWithCleanups(ExprWithCleanups *e, QualType t) {

clang/test/CIR/CodeGen/struct-init.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ S partial_init = { 1 };
1515
// LLVM: @partial_init = global %struct.S { i32 1, i32 0, i32 0 }
1616
// OGCG: @partial_init = global %struct.S { i32 1, i32 0, i32 0 }
1717

18+
struct StructWithDefaultInit {
19+
int a = 2;
20+
};
21+
22+
StructWithDefaultInit swdi = {};
23+
24+
// CIR: cir.global external @swdi = #cir.const_record<{#cir.int<2> : !s32i}> : !rec_StructWithDefaultInit
25+
// LLVM: @swdi = global %struct.StructWithDefaultInit { i32 2 }, align 4
26+
// OGCG: @swdi = global %struct.StructWithDefaultInit { i32 2 }, align 4
27+
1828
void init() {
1929
S s1 = {1, 2, 3};
2030
S s2 = {4, 5};

0 commit comments

Comments
 (0)