765 Commits

Author SHA1 Message Date
Zachary S
baed55ccef Remove unreachable unsized arg handling in store_fn_arg/store_arg in codegen 2025-09-12 09:49:41 -05:00
Matthias Krüger
422c76adae
Rollup merge of #146178 - folkertdev:static-align, r=jdonszelmann,ralfjung,traviscross
Implement `#[rustc_align_static(N)]` on `static`s

Tracking issue: https://github.com/rust-lang/rust/issues/146177

```rust
#![feature(static_align)]

#[rustc_align_static(64)]
static SO_ALIGNED: u64 = 0;
```

We need a different attribute than `rustc_align` because unstable attributes are tied to their feature (we can't have two unstable features use the same unstable attribute). Otherwise this uses all of the same infrastructure as `#[rustc_align]`.

r? `@traviscross`
2025-09-10 14:17:38 +02:00
Folkert de Vries
cbacd00f10
allow #[rustc_align_static(N)] on statics
We need a different attribute than `rustc_align` because unstable attributes are
tied to their feature (we can't have two unstable features use the same
unstable attribute). Otherwise this uses all of the same infrastructure
as `#[rustc_align]`.
2025-09-09 21:54:54 +02:00
Boxy
e379c77586 erase_regions to erase_and_anonymize_regions 2025-09-09 14:49:16 +02:00
Matthias Krüger
92bad93f06
Rollup merge of #146209 - bjorn3:lto_refactors5, r=dianqk
Misc LTO cleanups

Follow up to https://github.com/rust-lang/rust/pull/145955.

* Remove want_summary argument from `prepare_thin`.
   Since https://github.com/rust-lang/rust/pull/133250 ThinLTO summary writing is instead done by `llvm_optimize`.
* Two minor cleanups
2025-09-07 20:02:27 +02:00
bjorn3
f2933b34a8 Remove want_summary argument from prepare_thin
It is always false nowadays. ThinLTO summary writing is instead done by
llvm_optimize.
2025-09-06 18:37:23 +00:00
bjorn3
e3d0b7d648 Remove thin_link_data method from ThinBufferMethods
It is only used within cg_llvm.
2025-09-06 18:37:23 +00:00
Jieyou Xu
1a2055a525
cg_gcc: run run-make-cargo tests 2025-09-05 21:39:51 +08:00
bjorn3
319fe230f0 Special case allocator module submission to avoid special casing it elsewhere
A lot of places had special handling just in case they would get an
allocator module even though most of these places could never get one or
would have a trivial implementation for the allocator module. Moving all
handling of the allocator module to a single place simplifies things a
fair bit.
2025-09-04 08:21:10 +00:00
Waffle Lapkin
6a3187af13
fix target-pointer-width in tests 2025-08-27 23:44:49 +02:00
Guillaume Gomez
a03a0f1d44 Fix sync conflict 2025-08-26 17:25:45 +02:00
Guillaume Gomez
17137135ae Merge commit 'feb42827f11a7ae241ceecc81e9ae556fb6ba214' into subtree-update_cg_gcc_2025-08-26 2025-08-26 17:18:15 +02:00
bjorn3
525c6a3562 Directly raise fatal errors inside the codegen backends
As opposed to passing it around through Result.
2025-08-24 11:20:41 +00:00
Marcelo Domínguez
250d77e5d7 Complete functionality and general cleanup 2025-08-14 16:30:15 +00:00
Sasha Pourcelot
d435197afc Port the #[linkage] attribute to the new attribute system 2025-08-13 21:01:37 +02:00
Trevor Gross
6fa6a854cd
Rollup merge of #144192 - RalfJung:atomicrmw-ptr, r=nikic
atomicrmw on pointers: move integer-pointer cast hacks into backend

Conceptually, we want to have atomic operations on pointers of the form `fn atomic_add(ptr: *mut T, offset: usize, ...)`. However, LLVM does not directly support such operations (https://github.com/llvm/llvm-project/issues/120837), so we have to cast the `offset` to a pointer somewhere.

This PR moves that hack into the LLVM backend, so that the standard library, intrinsic, and Miri all work with the conceptual operation we actually want. Hopefully, one day LLVM will gain a way to represent these operations without integer-pointer casts, and then the hack will disappear entirely.

Cc ```@nikic``` -- this is the best we can do right now, right?
Fixes https://github.com/rust-lang/rust/issues/134617
2025-08-08 14:22:44 -05:00
bjorn3
6c02653c4a Prevent name collisions with internal implementation details
The implementation of the linkage attribute inside extern blocks defines
symbols starting with _rust_extern_with_linkage_. If someone tries to
also define this symbol you will get a symbol conflict or even an ICE.
By adding an unpredictable component to the symbol name, this becomes
less of an issue.
2025-08-07 13:41:17 +00:00
bjorn3
e02cc40ec9 Revert "Preserve the .debug_gdb_scripts section"
This reverts commit 868bdde25b030e0b71a29a5dbc04a891036e702e.
2025-08-06 18:01:07 +00:00
Sebastian Poeplau
868bdde25b Preserve the .debug_gdb_scripts section
Make sure that compiler and linker don't optimize the section's contents
away by adding the global holding the data to "llvm.used". The volatile
load in the main shim is retained because "llvm.used", which translates
to SHF_GNU_RETAIN on ELF targets, requires a reasonably recent linker;
emitting the volatile load ensures compatibility with older linkers, at
least when libstd is used.

Pretty printers in dylib dependencies are now emitted by the main crate
instead of the dylib; apart from matching how rlibs are handled, this
approach has the advantage that `omit_gdb_pretty_printer_section` keeps
working with dylib dependencies.
2025-08-05 10:55:07 +02:00
Guillaume Gomez
21bd67796e Merge commit '482e8540a1b757ed7bccc2041c5400f051fdb01e' into subtree-update_cg_gcc_2025-08-04 2025-08-04 10:49:43 +02:00
Jana Dönszelmann
e1d3ad89c7
remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
Stuart Cook
8628b78f24
Rollup merge of #144232 - xacrimon:explicit-tail-call, r=WaffleLapkin
Implement support for `become` and explicit tail call codegen for the LLVM backend

This PR implements codegen of explicit tail calls via `become` in `rustc_codegen_ssa` and support within the LLVM backend. Completes a task on (https://github.com/rust-lang/rust/issues/112788). This PR implements all the necessary bits to make explicit tail calls usable, other backends have received stubs for now and will ICE if you use `become` on them. I suspect there is some bikeshedding to be done on how we should go about implementing this for other backends, but it should be relatively straightforward for GCC after this is merged.

During development I also put together a POC bytecode VM based on tail call dispatch to test these changes out and analyze the codegen to make sure it generates expected assembly. That is available [here](https://github.com/xacrimon/tcvm).
2025-07-31 15:42:00 +10:00
Jieyou Xu
a7fcc738c9
Update codegen_{cranelift,gcc} and opt-dist to use build.compiletest-allow-stage0 2025-07-30 19:55:07 +08:00
bjorn3
948f7798d7 Remove support for -Zcombine-cgu
Nobody seems to actually use this, while still adding some extra
complexity to the already rather complex codegen coordinator code.
It is also not supported by any backend other than the LLVM backend.
2025-07-26 13:52:24 +00:00
Joel Wejdenstål
a448837045
Implement support for explicit tail calls in the MIR block builders and the LLVM codegen backend. 2025-07-26 01:02:29 +02:00
bors
5d22242a3a Auto merge of #144062 - bjorn3:lto_refactors2, r=davidtwco
Various refactors to the LTO handling code (part 2)

Continuing from https://github.com/rust-lang/rust/pull/143388 this removes a bit of dead code and moves the LTO symbol export calculation from individual backends to cg_ssa.
2025-07-24 12:50:26 +00:00
Ralf Jung
de1b999ff6 atomicrmw on pointers: move integer-pointer cast hacks into backend 2025-07-23 08:32:55 +02:00
Guillaume Gomez
ed93c1783b Rename tests/assembly into tests/assembly-llvm 2025-07-22 14:27:48 +02:00
bjorn3
dadc4cae50 Remove each_linked_rlib_for_lto from CodegenContext 2025-07-21 07:58:44 +00:00
bjorn3
1a6f941d2b Move exported_symbols_for_lto out of CodegenContext 2025-07-21 07:58:44 +00:00
bjorn3
6e757354ad Merge exported_symbols computation into exported_symbols_for_lto
And move exported_symbols_for_lto call from backends to cg_ssa.
2025-07-21 07:58:44 +00:00
bjorn3
1c8dc6f440 Move LTO symbol export calculation from backends to cg_ssa 2025-07-21 07:58:44 +00:00
bjorn3
112799e637 Merge modules and cached_modules for fat LTO
The modules vec can already contain serialized modules and there is no
need to distinguish between cached and non-cached cgus at LTO time.
2025-07-21 07:58:44 +00:00
Guillaume Gomez
f16474f7bf Remove forgotten git annotations 2025-07-18 22:35:58 +02:00
Guillaume Gomez
66017df336 Merge commit 'f682d09eefc6700b9e5851ef193847959acf4fac' into subtree-update_cg_gcc_2025-07-18 2025-07-18 18:31:20 +02:00
Matthias Krüger
accf61dd42
Rollup merge of #143293 - folkertdev:naked-function-kcfi, r=compiler-errors
fix `-Zsanitizer=kcfi` on `#[naked]` functions

fixes https://github.com/rust-lang/rust/issues/143266

With `-Zsanitizer=kcfi`, indirect calls happen via generated intermediate shim that forwards the call. The generated shim preserves the attributes of the original, including `#[unsafe(naked)]`. The shim is not a naked function though, and violates its invariants (like having a body that consists of a single `naked_asm!` call).

My fix here is to match on the `InstanceKind`, and only use `codegen_naked_asm` when the instance is not a `ReifyShim`. That does beg the question whether there are other `InstanceKind`s that could come up. As far as I can tell the answer is no: calling via `dyn` seems to work find, and `#[track_caller]` is disallowed in combination with `#[naked]`.

r? codegen
````@rustbot```` label +A-naked
cc ````@maurer```` ````@rcvalle````
2025-07-18 04:27:51 +02:00
León Orell Valerian Liehr
be5f8f299d
Rollup merge of #143388 - bjorn3:lto_refactors, r=compiler-errors
Various refactors to the LTO handling code

In particular reducing the sharing of code paths between fat and thin-LTO and making the fat LTO implementation more self-contained. This also moves some autodiff handling out of cg_ssa into cg_llvm given that Enzyme only works with LLVM anyway and an implementation for another backend may do things entirely differently. This will also make it a bit easier to split LTO handling out of the coordinator thread main loop into a separate loop, which should reduce the complexity of the coordinator thread.
2025-07-17 03:58:28 +02:00
Folkert de Vries
9c8ab89187
use codegen_instance_attrs where an instance is (easily) available 2025-07-16 23:24:32 +02:00
bors
855e0fe46e Auto merge of #142911 - mejrs:unsized, r=compiler-errors
Remove support for dynamic allocas

Followup to rust-lang/rust#141811
2025-07-11 05:27:32 +00:00
Oli Scherer
486ffda9dc Add opaque TypeId handles for CTFE 2025-07-09 16:37:11 +00:00
mejrs
49421d1fa3 Remove support for dynamic allocas 2025-07-07 23:04:06 +02:00
bors
a2d45f73c7 Auto merge of #143601 - matthiaskrgr:rollup-9iw2sqk, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#132469 (Do not suggest borrow that is already there in fully-qualified call)
 - rust-lang/rust#143340 (awhile -> a while where appropriate)
 - rust-lang/rust#143438 (Fix the link in `rustdoc.md`)
 - rust-lang/rust#143539 (Regression tests for repr ICEs)
 - rust-lang/rust#143566 (Fix `x86_64-unknown-netbsd` platform support page)
 - rust-lang/rust#143572 (Remove unused allow attrs)
 - rust-lang/rust#143583 (`loop_match`: fix 'no terminator on block')
 - rust-lang/rust#143584 (make `Machine::load_mir` infallible)
 - rust-lang/rust#143591 (Fix missing words in future tracking issue)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-07 20:30:53 +00:00
bors
2f8eeb2bba Auto merge of #143182 - xdoardo:more-addrspace, r=workingjubilee
Allow custom default address spaces and parse `p-` specifications in the datalayout string

Some targets, such as CHERI, use as default an address space different from the "normal" default address space `0` (in the case of CHERI, [200 is used](https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-877.pdf)). Currently, `rustc` does not allow to specify custom address spaces and does not take into consideration [`p-` specifications in the datalayout string](https://llvm.org/docs/LangRef.html#langref-datalayout).

This patch tries to mitigate these problems by allowing targets to define a custom default address space (while keeping the default value to address space `0`) and adding the code to parse the `p-` specifications in `rustc_abi`. The main changes are that `TargetDataLayout` now uses functions to refer to pointer-related informations, instead of having specific fields for the size and alignment of pointers in the default address space; furthermore, the two `pointer_size` and `pointer_align` fields in `TargetDataLayout` are replaced with an `FxHashMap` that holds info for all the possible address spaces, as parsed by the `p-` specifications.

The potential performance drawbacks of not having ad-hoc fields for the default address space will be tested in this PR's CI run.

r? workingjubilee
2025-07-07 17:28:14 +00:00
Yotam Ofek
3b48407f93 Remove unused allow attrs 2025-07-07 12:58:16 +00:00
Edoardo Marangoni
93f1201c06
compiler: Parse p- specs in datalayout string, allow definition of custom default data address space 2025-07-07 09:04:53 +02:00
Diggory Blake
ea7b756875
Make tempfile a normal dependency 2025-07-05 17:24:22 +01:00
Diggory Blake
a839b071f7
Use object crate from crates.io to fix windows build error 2025-07-05 15:58:42 +01:00
Daniel Paoliello
2b22d0f0d2 Make __rust_alloc_error_handler_should_panic a function 2025-07-03 10:52:21 -07:00
bjorn3
21026cae8d Merge run_fat_lto, optimize_fat and autodiff into run_and_optimize_fat_lto 2025-07-03 16:22:32 +00:00
bjorn3
8d63c7a1d6 Remove unused config param from WriteBackendMethods::autodiff 2025-07-03 16:13:25 +00:00