1
Fork 0
rust/compiler/rustc_codegen_llvm/src
bors 5dcb678ad8 Auto merge of #122917 - 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 #0 !dbg !7 {
start:
  %0 = alloca ptr, align 8, !dbg !12
  %val = inttoptr i64 %v to ptr, !dbg !12
  call void `@llvm.lifetime.start.p0(i64` 8, ptr %0), !dbg !28
  %1 = ptrtoint ptr %val to i64, !dbg !28
  %2 = atomicrmw add ptr %a, i64 %1 monotonic, align 8, !dbg !28
  store i64 %2, ptr %0, align 8, !dbg !28
  %self = load ptr, ptr %0, align 8, !dbg !28
  call void `@llvm.lifetime.end.p0(i64` 8, ptr %0), !dbg !28
  ret ptr %self, !dbg !33
}
```

r? `@RalfJung`
cc `@nikic`
2024-04-15 08:07:47 +00:00
..
back Set target-abi module flag for RISC-V targets 2024-04-09 05:25:51 +02:00
coverageinfo Auto merge of #123455 - matthiaskrgr:rollup-b6nu296, r=matthiaskrgr 2024-04-04 13:10:22 +00:00
debuginfo Set target-abi module flag for RISC-V targets 2024-04-09 05:25:51 +02:00
llvm Pass value and valueLen to create a StringRef 2024-04-09 08:53:11 +02:00
abi.rs Put PlaceValue into OperandValue::Ref, rather than 3 tuple fields 2024-04-11 00:10:10 -07:00
allocator.rs Add -Zuse-sync-unwind 2023-12-31 15:27:43 +08:00
asm.rs Add support for Arm64EC inline assembly 2024-04-10 10:06:44 -07:00
attributes.rs Use the Align type when parsing alignment attributes 2024-04-01 03:05:55 +01:00
base.rs compiler: replace cstr macro with c str literals in compiler and few other c str replacements 2023-12-03 14:54:09 +03:00
builder.rs Auto merge of #122917 - saethlin:atomicptr-to-int, r=nikic 2024-04-15 08:07:47 +00:00
callee.rs Fix clippy::needless_borrow in the compiler 2023-11-21 20:13:40 +01:00
common.rs Add+Use mir::BinOp::Cmp 2024-03-23 23:23:41 -07:00
consts.rs Some comment nits 2024-03-12 08:51:20 +00:00
context.rs Pass value and valueLen to create a StringRef 2024-04-09 08:53:11 +02:00
declare.rs sanitizers: Create the rustc_sanitizers crate 2024-04-08 12:05:41 -07:00
errors.rs Rename IntoDiagnostic as Diagnostic. 2024-03-11 09:15:09 +11:00
intrinsic.rs Add load/store helpers that take PlaceValue 2024-04-11 00:10:10 -07:00
lib.rs compiler: use addr_of! 2024-02-24 18:53:48 +03:00
llvm_util.rs Register LLVM handlers for bad-alloc / OOM 2024-03-15 15:49:06 -07:00
mono_item.rs Some comment nits 2024-03-12 08:51:20 +00:00
type_.rs Remove my scalar_copy_backend_type optimization attempt 2024-04-09 08:51:32 -07:00
type_of.rs Remove my scalar_copy_backend_type optimization attempt 2024-04-09 08:51:32 -07:00
va_arg.rs Add arm64ec-pc-windows-msvc target 2024-03-06 17:49:37 -08:00
value.rs