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