Skip to content

Commit b97ec85

Browse files
committed
Add a codegen test for #96152
1 parent 6b8d9dd commit b97ec85

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// assembly-output: emit-asm
2+
// compile-flags: -Copt-level=1
3+
// only-x86_64
4+
// min-llvm-version: 15.0
5+
#![crate_type = "rlib"]
6+
7+
// CHECK-LABEL: old_style
8+
// CHECK: movq %{{.*}}, %rax
9+
// CHECK: orq $1, %rax
10+
// CHECK: retq
11+
#[no_mangle]
12+
pub fn old_style(a: *mut u8) -> *mut u8 {
13+
(a as usize | 1) as *mut u8
14+
}
15+
16+
// CHECK-LABEL: cheri_compat
17+
// CHECK: movq %{{.*}}, %rax
18+
// CHECK: orq $1, %rax
19+
// CHECK: retq
20+
#[no_mangle]
21+
pub fn cheri_compat(a: *mut u8) -> *mut u8 {
22+
let old = a as usize;
23+
let new = old | 1;
24+
let diff = new.wrapping_sub(old);
25+
a.wrapping_add(diff)
26+
}
27+
28+
// CHECK-LABEL: definitely_not_a_null_pointer
29+
// CHECK: movq %{{.*}}, %rax
30+
// CHECK: orq $1, %rax
31+
// CHECK: retq
32+
#[no_mangle]
33+
pub fn definitely_not_a_null_pointer(a: *mut u8) -> *mut u8 {
34+
let old = a as usize;
35+
let new = old | 1;
36+
a.wrapping_sub(old).wrapping_add(new)
37+
}

0 commit comments

Comments
 (0)