2
0
Fork 0
mirror of https://github.com/rust-lang/rust-analyzer synced 2025-02-13 04:33:28 +00:00

Auto merge of - saethlin:atomicptr-to-int, r=nikic

Add the missing inttoptr when we ptrtoint in ptr atomics

Ralf noticed this here: https://github.com/rust-lang/rust/pull/122220#discussion_r1535172094

Our previous codegen forgot to add the cast back to integer type. The code compiles anyway, because of course all locals are in-memory to start with, so previous codegen would do the integer atomic, store the integer to a local, then load a pointer from that local. Which is definitely _not_ what we wanted: That's an integer-to-pointer transmute, so all pointers returned by these `AtomicPtr` methods didn't have provenance. Yikes.

Here's the IR for `AtomicPtr::fetch_byte_add` on 1.76: https://godbolt.org/z/8qTEjeraY
```llvm
define noundef ptr `@atomicptr_fetch_byte_add(ptr` noundef nonnull align 8 %a, i64 noundef %v) unnamed_addr  !dbg  {
start:
  %0 = alloca ptr, align 8, !dbg 
  %val = inttoptr i64 %v to ptr, !dbg 
  call void `@llvm.lifetime.start.p0(i64` 8, ptr %0), !dbg 
  %1 = ptrtoint ptr %val to i64, !dbg 
  %2 = atomicrmw add ptr %a, i64 %1 monotonic, align 8, !dbg 
  store i64 %2, ptr %0, align 8, !dbg 
  %self = load ptr, ptr %0, align 8, !dbg 
  call void `@llvm.lifetime.end.p0(i64` 8, ptr %0), !dbg 
  ret ptr %self, !dbg 
}
```

r? `@RalfJung`
cc `@nikic`
This commit is contained in:
bors 2024-04-15 08:07:47 +00:00
commit 2ab3444da4

Diff content is not available