Skip to content

Commit

Permalink
Auto merge of rust-lang#101395 - saethlin:strict-provenance-codegen, …
Browse files Browse the repository at this point in the history
…r=nikic

Add a codegen test for rust-lang#96152

This is a regression test for rust-lang#96152, it is intended to check that our codegen for a particular strict provenance pattern is always as good as the ptr2int2ptr/provenance-ignoring style.

r? `@nikic`
  • Loading branch information
bors committed Nov 7, 2022
2 parents ca08a32 + b97ec85 commit 391ba78
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/test/assembly/strict_provenance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
}

0 comments on commit 391ba78

Please sign in to comment.