Skip to content

Commit d3892b7

Browse files
authored
[CIR] Implement VisitOpaqueValueExpr for ComplexType (#1877)
Implement VisitOpaqueValueExpr for ComplexType
1 parent a85297d commit d3892b7

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
119119
}
120120

121121
mlir::Value VisitOpaqueValueExpr(OpaqueValueExpr *E) {
122-
llvm_unreachable("NYI");
122+
if (E->isGLValue())
123+
return emitLoadOfLValue(CGF.getOrCreateOpaqueLValueMapping(E),
124+
E->getExprLoc());
125+
126+
// Otherwise, assume the mapping is the scalar directly.
127+
return CGF.getOrCreateOpaqueRValueMapping(E).getScalarVal();
123128
}
124129

125130
mlir::Value VisitPseudoObjectExpr(PseudoObjectExpr *E) {

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,21 @@ void complex_init_atomic() {
228228
// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[A_ADDR]], i32 0, i32 1
229229
// OGCG: store float 1.000000e+00, ptr %[[A_REAL_PTR]], align 8
230230
// OGCG: store float 2.000000e+00, ptr %[[A_IMAG_PTR]], align 4
231+
232+
void complex_opaque_value_expr() {
233+
float _Complex a;
234+
float b = 1.0f ?: __real__ a;
235+
}
236+
237+
// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a"]
238+
// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["b", init]
239+
// CIR: %[[CONST_1:.*]] = cir.const #cir.fp<1.000000e+00> : !cir.float
240+
// CIR: cir.store align(4) %[[CONST_1]], %[[B_ADDR]] : !cir.float, !cir.ptr<!cir.float>
241+
242+
// LLVM: %[[A_ADDR:.*]] = alloca { float, float }, i64 1, align 4
243+
// LLVM: %[[B_ADDR:.*]] = alloca float, i64 1, align 4
244+
// LLVM: store float 1.000000e+00, ptr %[[B_ADDR]], align 4
245+
246+
// OGCG: %[[A_ADDR:.*]] = alloca { float, float }, align 4
247+
// OGCG: %[[B_ADDR:.*]] = alloca float, align 4
248+
// OGCG: store float 1.000000e+00, ptr %[[B_ADDR]], align 4

0 commit comments

Comments
 (0)