Skip to content

Commit 71d8ddc

Browse files
authored
[CIR] Upstream ParenExpr for AggregateExpr (#160998)
Upstream ParenExpr support for AggregateExpr
1 parent ccf1fb0 commit 71d8ddc

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
131131
std::string("AggExprEmitter::VisitStmt: ") +
132132
s->getStmtClassName());
133133
}
134-
void VisitParenExpr(ParenExpr *pe) {
135-
cgf.cgm.errorNYI(pe->getSourceRange(), "AggExprEmitter: VisitParenExpr");
136-
}
134+
void VisitParenExpr(ParenExpr *pe) { Visit(pe->getSubExpr()); }
137135
void VisitGenericSelectionExpr(GenericSelectionExpr *ge) {
138136
cgf.cgm.errorNYI(ge->getSourceRange(),
139137
"AggExprEmitter: VisitGenericSelectionExpr");

clang/test/CIR/CodeGen/struct.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,39 @@ void f3() {
9393
// OGCG: %[[O:.*]] = alloca %struct.Outer, align 4
9494
// OGCG: %[[O_I:.*]] = getelementptr inbounds nuw %struct.Outer, ptr %[[O]], i32 0, i32 0
9595
// OGCG: %[[O_I_N:.*]] = getelementptr inbounds nuw %struct.Inner, ptr %[[O_I]], i32 0, i32 0
96+
97+
void paren_expr() {
98+
struct Point {
99+
int x;
100+
int y;
101+
};
102+
103+
Point a = (Point{});
104+
Point b = (a);
105+
}
106+
107+
// CIR: cir.func{{.*}} @_Z10paren_exprv()
108+
// CIR: %[[A_ADDR:.*]] = cir.alloca !rec_Point, !cir.ptr<!rec_Point>, ["a", init]
109+
// CIR: %[[B_ADDR:.*]] = cir.alloca !rec_Point, !cir.ptr<!rec_Point>, ["b", init]
110+
// CIR: %[[X_ELEM_PTR:.*]] = cir.get_member %[[A_ADDR]][0] {name = "x"} : !cir.ptr<!rec_Point> -> !cir.ptr<!s32i>
111+
// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i
112+
// CIR: cir.store{{.*}} %[[CONST_0]], %[[X_ELEM_PTR]] : !s32i, !cir.ptr<!s32i>
113+
// CIR: %[[Y_ELEM_PTR:.*]] = cir.get_member %[[A_ADDR]][1] {name = "y"} : !cir.ptr<!rec_Point> -> !cir.ptr<!s32i>
114+
// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i
115+
// CIR: cir.store{{.*}} %[[CONST_0]], %[[Y_ELEM_PTR]] : !s32i, !cir.ptr<!s32i>
116+
// CIR: cir.call @_ZZ10paren_exprvEN5PointC1ERKS_(%[[B_ADDR]], %[[A_ADDR]]) nothrow : (!cir.ptr<!rec_Point>, !cir.ptr<!rec_Point>) -> ()
117+
118+
// LLVM: define{{.*}} void @_Z10paren_exprv()
119+
// LLVM: %[[A_ADDR:.*]] = alloca %struct.Point, i64 1, align 4
120+
// LLVM: %[[B_ADDR:.*]] = alloca %struct.Point, i64 1, align 4
121+
// LLVM: %[[X_ELEM_PTR:.*]] = getelementptr %struct.Point, ptr %[[A_ADDR]], i32 0, i32 0
122+
// LLVM: store i32 0, ptr %[[X_ELEM_PTR]], align 4
123+
// LLVM: %[[Y_ELEM_PTR:.*]] = getelementptr %struct.Point, ptr %[[A_ADDR]], i32 0, i32 1
124+
// LLVM: store i32 0, ptr %[[Y_ELEM_PTR]], align 4
125+
// LLVM: call void @_ZZ10paren_exprvEN5PointC1ERKS_(ptr %[[B_ADDR]], ptr %[[A_ADDR]])
126+
127+
// OGCG: define{{.*}} void @_Z10paren_exprv()
128+
// OGCG: %[[A_ADDR:.*]] = alloca %struct.Point, align 4
129+
// OGCG: %[[B_ADDR:.*]] = alloca %struct.Point, align 4
130+
// OGCG: call void @llvm.memset.p0.i64(ptr align 4 %[[A_ADDR]], i8 0, i64 8, i1 false)
131+
// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[B_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)

0 commit comments

Comments
 (0)