Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,14 @@ mlir::Value ComplexExprEmitter::emitCast(CastKind CK, Expr *Op,
case CK_LValueBitCast:
llvm_unreachable("NYI");

case CK_LValueToRValueBitCast:
llvm_unreachable("NYI");
case CK_LValueToRValueBitCast: {
LValue SourceLVal = CGF.emitLValue(Op);
Address Addr = SourceLVal.getAddress().withElementType(
Builder, CGF.convertTypeForMem(DestTy));
LValue DestLV = CGF.makeAddrLValue(Addr, DestTy);
DestLV.setTBAAInfo(TBAAAccessInfo::getMayAliasInfo());
return emitLoadOfLValue(DestLV, Op->getExprLoc());
}

case CK_BitCast:
case CK_BaseToDerived:
Expand Down
23 changes: 23 additions & 0 deletions clang/test/CIR/CodeGen/complex-cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,29 @@ void complex_to_bool() {

// CHECK: }

struct CX {
double real;
double imag;
};

void lvalue_to_rvalue_bitcast() {
struct CX a;
double _Complex b = __builtin_bit_cast(double _Complex, a);
}

// CHECK-LABEL: @lvalue_to_rvalue_bitcast()

// CIR-BEFORE: %{{.+}} = cir.cast(bitcast, %{{.+}} : !cir.ptr<!rec_CX>), !cir.ptr<!cir.complex<!cir.double>>

// CIR-AFTER: %{{.+}} = cir.cast(bitcast, %{{.+}} : !cir.ptr<!rec_CX>), !cir.ptr<!cir.complex<!cir.double>>

// LLVM: %[[PTR_ADDR:.*]] = alloca %struct.CX, i64 1, align 8
// LLVM: %[[COMPLEX_ADDR:.*]] = alloca { double, double }, i64 1, align 8
// LLVM: %[[PTR_TO_COMPLEX:.*]] = load { double, double }, ptr %[[PTR_ADDR]], align 8
// LLVM: store { double, double } %[[PTR_TO_COMPLEX]], ptr %[[COMPLEX_ADDR]], align 8

// CHECK: }

void complex_to_complex_cast() {
cd = cf;
ci = cs;
Expand Down
Loading