Skip to content

Commit 518771f

Browse files
authored
[CIR] Implement UserDefinedConversion for ComplexType (#1839)
Support UserDefinedConversion for ComplexType
1 parent 0a3d11c commit 518771f

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,15 @@ mlir::Value ComplexExprEmitter::emitCast(CastKind CK, Expr *Op,
446446
case CK_Dependent:
447447
llvm_unreachable("dependent cast kind in IR gen!");
448448

449-
// Atomic to non-atomic casts may be more than a no-op for some platforms and
450-
// for some types.
451449
case CK_NoOp:
452450
case CK_LValueToRValue:
451+
case CK_UserDefinedConversion:
453452
return Visit(Op);
454453

454+
// Atomic to non-atomic casts may be more than a no-op for some platforms
455+
// and for some types.
455456
case CK_AtomicToNonAtomic:
456457
case CK_NonAtomicToAtomic:
457-
case CK_UserDefinedConversion:
458458
llvm_unreachable("NYI");
459459

460460
case CK_LValueBitCast: {

clang/test/CIR/CodeGen/complex-cast.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,27 @@ void complex_lvalue_bitcast() {
1919

2020
// LLVM: %[[A_ADDR:.*]] = alloca %struct.CX, i64 1, align 8
2121
// LLVM: store { double, double } zeroinitializer, ptr %[[A_ADDR]], align 8
22+
23+
void complex_user_defined_cast() {
24+
struct Point {
25+
int x;
26+
int y;
27+
operator int _Complex() const { return {x, y}; }
28+
};
29+
30+
Point p{1, 2};
31+
int _Complex c = p;
32+
}
33+
34+
// CIR-AFTER: %[[P_ADDR:.*]] = cir.alloca !rec_Point, !cir.ptr<!rec_Point>, ["p"]
35+
// CIR-AFTER: %[[C_ADDR:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
36+
// CIR-AFTER: %[[P_CONST:.*]] = cir.const #cir.const_record<{#cir.int<1> : !s32i, #cir.int<2> : !s32i}> : !rec_Point
37+
// CIR-AFTER: cir.store{{.*}} %[[P_CONST]], %[[P_ADDR]] : !rec_Point, !cir.ptr<!rec_Point>
38+
// CIR-AFTER: %[[POINT_TO_COMPLEX:.*]] = cir.call @_ZZ25complex_user_defined_castvENK5PointcvCiEv(%[[P_ADDR]]) : (!cir.ptr<!rec_Point>) -> !cir.complex<!s32i>
39+
// CIR-AFTER: cir.store{{.*}} %[[POINT_TO_COMPLEX]], %[[C_ADDR]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
40+
41+
// LLVM: %[[P_ADDR:.*]] = alloca %struct.Point, i64 1, align 4
42+
// LLVM: %[[C_ADDR:.*]] = alloca { i32, i32 }, i64 1, align 4
43+
// LLVM: store %struct.Point { i32 1, i32 2 }, ptr %[[P_ADDR]], align 4
44+
// LLVM: %[[POINT_TO_COMPLEX:.*]] = call { i32, i32 } @_ZZ25complex_user_defined_castvENK5PointcvCiEv(ptr %[[P_ADDR]])
45+
// LLVM: store { i32, i32 } %[[POINT_TO_COMPLEX]], ptr %[[C_ADDR]], align 4

0 commit comments

Comments
 (0)