diff options
| author | bors <bors@rust-lang.org> | 2022-11-07 10:36:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-11-07 10:36:48 +0000 |
| commit | 391ba78ab442610a63310b9a3d24646082628081 (patch) | |
| tree | d7f040dbbf3af4db099f42b3aa41ec54655a3f5e /src | |
| parent | ca08a3265511d3b0c2f3c3cf06e7acc10b73a5ce (diff) | |
| parent | b97ec85e96ae4d724bf12ad0d1acb05c80158891 (diff) | |
| download | rust-391ba78ab442610a63310b9a3d24646082628081.tar.gz rust-391ba78ab442610a63310b9a3d24646082628081.zip | |
Auto merge of #101395 - saethlin:strict-provenance-codegen, r=nikic
Add a codegen test for rust-lang/rust#96152 This is a regression test for https://github.com/rust-lang/rust/issues/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`
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/assembly/strict_provenance.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/test/assembly/strict_provenance.rs b/src/test/assembly/strict_provenance.rs new file mode 100644 index 00000000000..01f1957d5f6 --- /dev/null +++ b/src/test/assembly/strict_provenance.rs @@ -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) +} |
