diff options
| author | Ben Kimock <kimockb@gmail.com> | 2024-03-22 18:07:43 -0400 |
|---|---|---|
| committer | Ben Kimock <kimockb@gmail.com> | 2024-03-23 00:07:02 -0400 |
| commit | 6b794f6c802600fc9ae0c68fcaed1143fc85ab0a (patch) | |
| tree | 9223eed12c04c0744fcbf65097f9e94807558eea /tests/codegen | |
| parent | b3df0d7e5ef5f7dbeeca3fb289c65680ad013f87 (diff) | |
| download | rust-6b794f6c802600fc9ae0c68fcaed1143fc85ab0a.tar.gz rust-6b794f6c802600fc9ae0c68fcaed1143fc85ab0a.zip | |
Add the missing inttoptr when we ptrtoint in ptr atomics
Diffstat (limited to 'tests/codegen')
| -rw-r--r-- | tests/codegen/atomicptr.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/codegen/atomicptr.rs b/tests/codegen/atomicptr.rs new file mode 100644 index 00000000000..cbbd5615512 --- /dev/null +++ b/tests/codegen/atomicptr.rs @@ -0,0 +1,38 @@ +// LLVM does not support some atomic RMW operations on pointers, so inside codegen we lower those +// to integer atomics, surrounded by casts to and from integer type. +// This test ensures that we do the round-trip correctly for AtomicPtr::fetch_byte_add, and also +// ensures that we do not have such a round-trip for AtomicPtr::swap, because LLVM supports pointer +// arguments to `atomicrmw xchg`. + +//@ compile-flags: -O -Cno-prepopulate-passes +#![crate_type = "lib"] + +#![feature(strict_provenance)] +#![feature(strict_provenance_atomic_ptr)] + +use std::sync::atomic::AtomicPtr; +use std::sync::atomic::Ordering::Relaxed; +use std::ptr::without_provenance_mut; + +// Portability hack so that we can say [[USIZE]] instead of i64/i32/i16 for usize. +// CHECK: @helper([[USIZE:i[0-9]+]] noundef %_1) +#[no_mangle] +pub fn helper(_: usize) {} + +// CHECK-LABEL: @atomicptr_fetch_byte_add +#[no_mangle] +pub fn atomicptr_fetch_byte_add(a: &AtomicPtr<u8>, v: usize) -> *mut u8 { + // CHECK: %[[INTPTR:.*]] = ptrtoint ptr %{{.*}} to [[USIZE]] + // CHECK-NEXT: %[[RET:.*]] = atomicrmw add ptr %{{.*}}, [[USIZE]] %[[INTPTR]] + // CHECK-NEXT: inttoptr [[USIZE]] %[[RET]] to ptr + a.fetch_byte_add(v, Relaxed) +} + +// CHECK-LABEL: @atomicptr_swap +#[no_mangle] +pub fn atomicptr_swap(a: &AtomicPtr<u8>, ptr: *mut u8) -> *mut u8 { + // CHECK-NOT: ptrtoint + // CHECK: atomicrmw xchg ptr %{{.*}}, ptr %{{.*}} monotonic + // CHECK-NOT: inttoptr + a.swap(ptr, Relaxed) +} |
