Skip to content

Commit 5da800f

Browse files
authored
[CIR] Implement GenericSelectionExpr (#1718)
Support codgen for GenericSelectionExpr
1 parent 3235864 commit 5da800f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
158158
return Visit(E->getReplacement());
159159
}
160160
mlir::Value VisitGenericSelectionExpr(GenericSelectionExpr *GE) {
161-
llvm_unreachable("NYI");
161+
return Visit(GE->getResultExpr());
162162
}
163163
mlir::Value VisitCoawaitExpr(CoawaitExpr *S) {
164164
return CGF.emitCoawaitExpr(*S).getScalarVal();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -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 -fclangir -emit-llvm %s -o %t.ll
4+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
5+
6+
void foo() {
7+
int a;
8+
int r = _Generic(a, double: 1, float: 2, int: 3, default: 4);
9+
}
10+
11+
// CIR: %[[A:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a"]
12+
// CIR: %[[RES:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["r", init]
13+
// CIR: %[[RES_VAL:.*]] = cir.const #cir.int<3> : !s32i
14+
// CIR: cir.store{{.*}} %[[RES_VAL]], %[[RES]] : !s32i, !cir.ptr<!s32i>
15+
16+
// LLVM: %[[A:.*]] = alloca i32, i64 1, align 4
17+
// LLVM: %[[RES:.*]] = alloca i32, i64 1, align 4
18+
// LLVM: store i32 3, ptr %[[RES]], align 4

0 commit comments

Comments
 (0)