mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
5dcb678ad8
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` |
||
---|---|---|
.. | ||
src | ||
Cargo.toml | ||
messages.ftl | ||
README.md |
The codegen
crate contains the code to convert from MIR into LLVM IR,
and then from LLVM IR into machine code. In general it contains code
that runs towards the end of the compilation process.
For more information about how codegen works, see the rustc dev guide.