Skip to content

Commit 61bc256

Browse files
committed
Fix testcases
1 parent 0ff0218 commit 61bc256

File tree

3 files changed

+14
-34
lines changed

3 files changed

+14
-34
lines changed

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,8 +1499,8 @@ mlir::LogicalResult CIRToLLVMConstantOpLowering::matchAndRewrite(
14991499
return mlir::success();
15001500
}
15011501

1502-
uint64_t CIRToLLVMPtrDiffOpLowering::getTypeSize(mlir::Type type,
1503-
mlir::Operation &op) const {
1502+
static uint64_t getTypeSize(mlir::Type type,
1503+
mlir::Operation &op) {
15041504
mlir::DataLayout layout(op.getParentOfType<mlir::ModuleOp>());
15051505
// For LLVM purposes we treat void as u8.
15061506
if (isa<cir::VoidType>(type))

clang/test/CIR/CodeGen/ptrdiff.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
int addrcmp(const void* a, const void* b) {
77
// CIR-LABEL: addrcmp
88
// CIR: %[[R:.*]] = cir.ptr_diff
9-
// CIR: cir.cast integral %[[R]] : !s64i -> !s32
9+
// CIR: cir.cast integral %[[R]] : !s64i -> !s32i
1010

11-
// LLVM-LABEL: addrcmp
11+
// LLVM-LABEL: define dso_local i32 @addrcmp(
1212
// LLVM: %[[PTR_A:.*]] = ptrtoint ptr {{.*}} to i64
1313
// LLVM: %[[PTR_B:.*]] = ptrtoint ptr {{.*}} to i64
1414
// LLVM: %[[SUB:.*]] = sub i64 %[[PTR_A]], %[[PTR_B]]
@@ -19,14 +19,17 @@ int addrcmp(const void* a, const void* b) {
1919

2020
unsigned long long test_ptr_diff(int *a, int* b) {
2121
// CIR-LABEL: test_ptr_diff
22-
// CIR: %[[D:.*]] = cir.ptr_diff{{.*}} : !cir.ptr<!s32i> -> !u64i
23-
// CIR: cir.return %[[D]] : !u64i
22+
// CIR: %[[D:.*]] = cir.ptr_diff {{.*}} : !cir.ptr<!s32i> -> !s64i
23+
// CIR: %[[U:.*]] = cir.cast integral %[[D]] : !s64i -> !u64i
24+
// CIR: cir.return {{.*}} : !u64i
2425

25-
// LLVM-LABEL: @_Z13test_ptr_diffPiS_
26+
// LLVM-LABEL: define dso_local i64 @test_ptr_diff(
2627
// LLVM: %[[IA:.*]] = ptrtoint ptr %{{.*}} to i64
2728
// LLVM: %[[IB:.*]] = ptrtoint ptr %{{.*}} to i64
2829
// LLVM: %[[SUB:.*]] = sub i64 %[[IA]], %[[IB]]
29-
// LLVM: %[[Q:.*]] = sdiv exact i64 %[[SUB]], 4
30-
// LLVM: ret i64 %[[Q]]
30+
// LLVM: %[[Q:.*]] = sdiv{{( exact)?}} i64 %[[SUB]], 4
31+
// LLVM: store i64 %[[Q]], ptr %[[RETADDR:.*]], align
32+
// LLVM: %[[RETLOAD:.*]] = load i64, ptr %[[RETADDR]], align
33+
// LLVM: ret i64 %[[RETLOAD]]
3134
return a - b;
3235
}

clang/test/CIR/CodeGen/ptrdiff.cpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,13 @@
11
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
2-
// RUN: FileCheck --input-file=%t.cir %s
2+
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
33

44
typedef unsigned long size_type;
55

66
size_type size(unsigned long *_start, unsigned long *_finish) {
77
// CIR-LABEL: cir.func dso_local @_Z4sizePmS_
88
// CIR: %[[D:.*]] = cir.ptr_diff {{.*}} : !cir.ptr<!u64i> -> !s64i
99
// CIR: %[[U:.*]] = cir.cast integral %[[D]] : !s64i -> !u64i
10-
// CIR: cir.return %[[U]] : !u64i
10+
// CIR: cir.return {{.*}} : !u64i
1111

12-
// LLVM-LABEL: @_Z4sizePmS_
13-
// LLVM: ptrtoint ptr {{.*}} to i64
14-
// LLVM: ptrtoint ptr {{.*}} to i64
15-
// LLVM: %[[SUB:.*]] = sub i64 {{.*}}, {{.*}}
16-
// LLVM: %[[DIV:.*]] = sdiv exact i64 %[[SUB]], 8
17-
// LLVM: ret i64 %[[DIV]]
1812
return static_cast<size_type>(_finish - _start);
1913
}
20-
21-
long add(char *a, char *b) {
22-
// CIR-LABEL: cir.func dso_local @_Z3addPcS_
23-
// CIR: %[[D:.*]] = cir.ptr_diff {{.*}} : !cir.ptr<!s8i> -> !s64i
24-
// CIR: %[[C1:.*]] = cir.const #cir.int<1> : !s32i
25-
// CIR: %[[C1W:.*]] = cir.cast integral %[[C1]] : !s32i -> !s64i
26-
// CIR: %[[S:.*]] = cir.binop(add, %[[D]], %[[C1W]]) : !s64i
27-
// CIR: cir.return %[[S]] : !s64i
28-
29-
// LLVM-LABEL: @_Z3addPcS_
30-
// LLVM: ptrtoint ptr {{.*}} to i64
31-
// LLVM: ptrtoint ptr {{.*}} to i64
32-
// LLVM: %[[SUB:.*]] = sub i64 {{.*}}, {{.*}}
33-
// LLVM: %[[ADD1:.*]] = add i64 %[[SUB]], 1
34-
// LLVM: ret i64 %[[ADD1]]
35-
return a - b + 1;
36-
}

0 commit comments

Comments
 (0)