Skip to content

Commit ffa62b5

Browse files
authored
[CIR] Implement ChooseExpr for ComplexType (#1693)
Implement ChooseExpr for ComplexType
1 parent 7bef37f commit ffa62b5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,10 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
313313
VisitAbstractConditionalOperator(const AbstractConditionalOperator *CO) {
314314
llvm_unreachable("NYI");
315315
}
316-
mlir::Value VisitChooseExpr(ChooseExpr *CE) { llvm_unreachable("NYI"); }
316+
317+
mlir::Value VisitChooseExpr(ChooseExpr *CE) {
318+
return Visit(CE->getChosenSubExpr());
319+
}
317320

318321
mlir::Value VisitInitListExpr(InitListExpr *E);
319322

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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_choose_expr() {
7+
int _Complex a;
8+
int _Complex b;
9+
int _Complex r = __builtin_choose_expr(true, a, b);
10+
}
11+
12+
// CIR: %[[COMPLEX_A:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a"]
13+
// CIR: %[[RESULT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["r", init]
14+
// CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[COMPLEX_A]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
15+
// CIR: cir.store{{.*}} %[[TMP_A]], %[[RESULT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
16+
17+
// LLVM: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, i64 1, align 4
18+
// LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
19+
// LLVM: %[[RESULT:.*]] = alloca { i32, i32 }, i64 1, align 4
20+
// LLVM: %[[TMP_A:.*]] = load { i32, i32 }, ptr %[[COMPLEX_A]], align 4
21+
// LLVM: store { i32, i32 } %[[TMP_A]], ptr %[[RESULT]], align 4

0 commit comments

Comments
 (0)