Skip to content

Commit d0ee49c

Browse files
ChuanqiXu9smeenai
authored andcommitted
[CIR][CIRGen] Implement Nullpointer arithmatic extension (llvm#861)
See the test for example.
1 parent adff797 commit d0ee49c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ static mlir::Value buildPointerArithmetic(CIRGenFunction &CGF,
12451245
//
12461246
if (BinaryOperator::isNullPointerArithmeticExtension(
12471247
CGF.getContext(), op.Opcode, expr->getLHS(), expr->getRHS()))
1248-
llvm_unreachable("null pointer arithmetic extension is NYI");
1248+
return CGF.getBuilder().createIntToPtr(index, pointer.getType());
12491249

12501250
// Differently from LLVM codegen, ABI bits for index sizes is handled during
12511251
// LLVM lowering.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-cir %s -o - | FileCheck %s
2+
3+
#define NULL ((void *)0)
4+
5+
char *foo() {
6+
return (char*)NULL + 1;
7+
}
8+
9+
// CHECK: cir.func no_proto @foo()
10+
// CHECK: [[CONST_1:%[0-9]+]] = cir.const #cir.int<1> : !s32i
11+
// CHECK: {{.*}} = cir.cast(int_to_ptr, [[CONST_1]] : !s32i)
12+
// CHECK: cir.return

0 commit comments

Comments
 (0)