Skip to content

Commit 00a4083

Browse files
authored
[CIR] Backport support for GNUNullExpr (#1981)
Backport support for GNUNullExpr from the upstream
1 parent e7f2f63 commit 00a4083

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
212212
return emitNullValue(E->getType(), CGF.getLoc(E->getSourceRange()));
213213
}
214214
mlir::Value VisitGNUNullExpr(const GNUNullExpr *E) {
215-
llvm_unreachable("NYI");
215+
return emitNullValue(E->getType(), CGF.getLoc(E->getSourceRange()));
216216
}
217217
mlir::Value VisitOffsetOfExpr(OffsetOfExpr *E) {
218218
// Try folding the offsetof to a constant.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang_cc1 -std=c++20 -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 -std=c++20 -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 -std=c++20 -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 gnu_null_expr() {
9+
long a = __null;
10+
int *b = __null;
11+
}
12+
13+
// CIR: %[[A_ADDR:.*]] = cir.alloca !s64i, !cir.ptr<!s64i>, ["a", init]
14+
// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["b", init]
15+
// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s64i
16+
// CIR: cir.store {{.*}} %[[CONST_0]], %[[A_ADDR]] : !s64i, !cir.ptr<!s64i>
17+
// CIR: %[[CONST_NULL:.*]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i>
18+
// CIR: cir.store {{.*}} %[[CONST_NULL]], %[[B_ADDR]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
19+
20+
// LLVM: %[[A_ADDR:.*]] = alloca i64, i64 1, align 8
21+
// LLVM: %[[B_ADDR:.*]] = alloca ptr, i64 1, align 8
22+
// LLVM: store i64 0, ptr %[[A_ADDR]], align 8
23+
// LLVM: store ptr null, ptr %[[B_ADDR]], align 8
24+
25+
// OGCG: %[[A_ADDR:.*]] = alloca i64, align 8
26+
// OGCG: %[[B_ADDR:.*]] = alloca ptr, align 8
27+
// OGCG: store i64 0, ptr %[[A_ADDR]], align 8
28+
// OGCG: store ptr null, ptr %[[B_ADDR]], align 8

0 commit comments

Comments
 (0)