Skip to content

Commit 4586707

Browse files
AmrDeveloperlanza
authored andcommitted
[CIR] Backport functional cast to ComplexType (llvm#1737)
Backport functional cast to ComplexType
1 parent 52ea370 commit 4586707

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,12 @@ mlir::Value ComplexExprEmitter::emitCast(CastKind CK, Expr *Op,
419419

420420
// Atomic to non-atomic casts may be more than a no-op for some platforms and
421421
// for some types.
422+
case CK_NoOp:
422423
case CK_LValueToRValue:
423424
return Visit(Op);
424425

425426
case CK_AtomicToNonAtomic:
426427
case CK_NonAtomicToAtomic:
427-
case CK_NoOp:
428428
case CK_UserDefinedConversion:
429429
llvm_unreachable("NYI");
430430

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
4+
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5+
6+
void complex_functional_cast() {
7+
using IntComplex = int _Complex;
8+
int _Complex a = IntComplex{};
9+
}
10+
11+
// CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init]
12+
// CIR: %[[COMPLEX:.*]] = cir.const #cir.complex<#cir.int<0> : !s32i, #cir.int<0> : !s32i> : !cir.complex<!s32i>
13+
// CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
14+
15+
// LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4
16+
// LLVM: store { i32, i32 } zeroinitializer, ptr %[[INIT]], align 4

0 commit comments

Comments
 (0)