Skip to content

Commit e11d354

Browse files
authored
[CIR] Upstream GenericSelectionExpr (#146211)
Upstream GenericSelectionExpr for ScalarExpr
1 parent 67f1eb5 commit e11d354

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
127127

128128
mlir::Value VisitParenExpr(ParenExpr *pe) { return Visit(pe->getSubExpr()); }
129129

130+
mlir::Value VisitGenericSelectionExpr(GenericSelectionExpr *ge) {
131+
return Visit(ge->getResultExpr());
132+
}
133+
130134
/// Emits the address of the l-value, then loads and returns the result.
131135
mlir::Value emitLoadOfLValue(const Expr *e) {
132136
LValue lv = cgf.emitLValue(e);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
6+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
7+
8+
void foo() {
9+
int a;
10+
int r = _Generic(a, double: 1, float: 2, int: 3, default: 4);
11+
}
12+
13+
// CIR: %[[A:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a"]
14+
// CIR: %[[RES:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["r", init]
15+
// CIR: %[[RES_VAL:.*]] = cir.const #cir.int<3> : !s32i
16+
// CIR: cir.store{{.*}} %[[RES_VAL]], %[[RES]] : !s32i, !cir.ptr<!s32i>
17+
18+
// LLVM: %[[A:.*]] = alloca i32, i64 1, align 4
19+
// LLVM: %[[RES:.*]] = alloca i32, i64 1, align 4
20+
// LLVM: store i32 3, ptr %[[RES]], align 4
21+
22+
// OGCG: %[[A:.*]] = alloca i32, align 4
23+
// OGCG: %[[RES:.*]] = alloca i32, align 4
24+
// OGCG: store i32 3, ptr %[[RES]], align 4

0 commit comments

Comments
 (0)