about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
AgeCommit message (Collapse)AuthorLines
2025-06-30Rollup merge of #143196 - Periodic1911:link_section, r=oli-obkdianqk-10/+3
Port #[link_section] to the new attribute parsing infrastructure Ports link_section to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197 r? `@oli-obk` cc `@JonathanBrouwer` `@jdonszelmann`
2025-06-30fix bitcast of single-element SIMD vectorsFolkert de Vries-8/+2
2025-06-30Require either wrapping nullary intrinsincs in const blocks or explicitly ↵Oli Scherer-1/+22
deciding not to
2025-06-30Stop backends from needing to support nullary intrinsicsOli Scherer-4/+0
2025-06-29inherit `#[align]` from trait method prototypesFolkert de Vries-9/+22
2025-06-29Port #[link_section] to the new attribute parsing infrastructureAnne Stijns-10/+3
2025-06-29mir: Add a `new` method to `statement`dianqk-4/+4
Avoid introducing a large number of changes when adding optional initialization fields.
2025-06-29Rollup merge of #143138 - JonathanBrouwer:link_name_parser, r=jdonszelmannMatthias Krüger-1/+1
Port `#[link_name]` to the new attribute parsing infrastructure Ports `link_name` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197 r? `@jdonszelmann`
2025-06-29Rollup merge of #143088 - firefighterduck:improve-doc-discr-tag, r=RalfJungMatthias Krüger-10/+1
Improve documentation of `TagEncoding` This PR is follow-up from the [discussion here](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.E2.9C.94.20VariantId.3DDiscriminant.20when.20tag.20is.20niche.20encoded.3F/with/524384295). It aims at making the `TagEncoding` documentation less ambiguous and more detailed with references to relevant implementation sides. It especially clears up the ambiguous use of discriminant/variant index, which sparked the discussion referenced above. PS: While working with layout data, I somehow ended up looking at the docs for `FakeBorrowKind` and noticed that the one example was not in a doc comment. I hope that this is minor enough of a fix for it to be okay in this otherwise unrelated PR.
2025-06-29Rollup merge of #142641 - bjorn3:proc_macro_symbols_o, r=jieyouxuMatthias Krüger-2/+7
Generate symbols.o for proc-macros too To ensure used statics are functioning correctly for proc-macros too.
2025-06-28move discr=varid check to layout_sanity_checkFlorian Sextl-10/+1
2025-06-28Port `#[link_name]` to the new attribute parsing infrastructureJonathan Brouwer-1/+1
Co-authored-by: Anne Stijns <anstijns@gmail.com> Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-28Auto merge of #141759 - 1c3t3a:discriminants-query, r=saethlinbors-0/+6
Insert checks for enum discriminants when debug assertions are enabled Similar to the existing null-pointer and alignment checks, this checks for valid enum discriminants on creation of enums through unsafe transmutes. Essentially this sanitizes patterns like the following: ```rust let val: MyEnum = unsafe { std::mem::transmute<u32, MyEnum>(42) }; ``` An extension of this check will be done in a follow-up that explicitly sanitizes for extern enum values that come into Rust from e.g. C/C++. This check is similar to Miri's capabilities of checking for valid construction of enum values. This PR is inspired by saethlin@'s PR https://github.com/rust-lang/rust/pull/104862. Thank you so much for keeping this code up and the detailed comments! I also pair-programmed large parts of this together with vabr-g@. r? `@saethlin`
2025-06-27Rollup merge of #140809 - bjorn3:panic_runtime_cleanup, r=petrochenkovMatthias Krüger-21/+33
Reduce special casing for the panic runtime See the individual commits for more info.
2025-06-27Rollup merge of #143020 - RalfJung:codegen_fn_attrs, r=oli-obkGuillaume Gomez-1/+3
codegen_fn_attrs: make comment more precise Follow-up to https://github.com/rust-lang/rust/pull/142854. r? ``@oli-obk`` or ``@workingjubilee``
2025-06-27Generate symbols.o for proc-macros toobjorn3-2/+7
To ensure used statics are functioning correctly for proc-macros too.
2025-06-27Update commentsbjorn3-5/+5
2025-06-27Insert checks for enum discriminants when debug assertions are enabledBastian Kersting-0/+6
Similar to the existing nullpointer and alignment checks, this checks for valid enum discriminants on creation of enums through unsafe transmutes. Essentially this sanitizes patterns like the following: ```rust let val: MyEnum = unsafe { std::mem::transmute<u32, MyEnum>(42) }; ``` An extension of this check will be done in a follow-up that explicitly sanitizes for extern enum values that come into Rust from e.g. C/C++. This check is similar to Miri's capabilities of checking for valid construction of enum values. This PR is inspired by saethlin@'s PR https://github.com/rust-lang/rust/pull/104862. Thank you so much for keeping this code up and the detailed comments! I also pair-programmed large parts of this together with vabr-g@.
2025-06-27Split exported_symbols for generic and non-generic symbolsbjorn3-9/+27
This reduces metadata decoder overhead during the monomorphization collector.
2025-06-27Port `#[used]` to new attribute parsing infrastructureJonathan Brouwer-46/+5
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-27codegen_fn_attrs: make comment more preciseRalf Jung-1/+3
2025-06-26Move mixed export_name/no_mangle check to check_attr.rs and improve the errorJonathan Brouwer-66/+2
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-26Port `#[export_name]` to the new attribute parsing infrastructureJonathan Brouwer-18/+4
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-25Auto merge of #142879 - Mark-Simulacrum:opt-cleanup, r=WaffleLapkinbors-1/+1
Remove dead instructions in terminate blocks Terminate blocks look pretty in the IR I've looked at, so no actual perf delta from this. But it seems reasonable to note produce unused IR.
2025-06-24Rollup merge of #142825 - jdonszelmann:track-caller, r=oli-obkJubilee-28/+26
Port `#[track_caller]` to the new attribute system r? ``@oli-obk`` depends on https://github.com/rust-lang/rust/pull/142493 Closes rust-lang/rust#142783 (didn't add a test for this, this situation should simply never come up again, the code was simply wrong. lmk if I should add it, but it won't test something very useful)
2025-06-24Rollup merge of #142768 - scottmcm:avoid-unneeded-bitcast, r=WaffleLapkinJubilee-2/+8
Avoid a bitcast FFI call in transmuting For things that only change the valid ranges, we can just return the input, rather than making the `LLVMBuildBitCast` call and having *it* then do nothing. I tried to tweak this a bit more and broke stuff, so I also added some extra tests for that as we apparently didn't have coverage.
2025-06-24Auto merge of #142979 - matthiaskrgr:rollup-szqah4e, r=matthiaskrgrbors-7/+7
Rollup of 9 pull requests Successful merges: - rust-lang/rust#142645 (Also emit suggestions for usages in the `non_upper_case_globals` lint) - rust-lang/rust#142657 (mbe: Clean up code with non-optional `NonterminalKind`) - rust-lang/rust#142799 (rustc_session: Add a structure for keeping both explicit and default sysroots) - rust-lang/rust#142805 (Emit a single error when importing a path with `_`) - rust-lang/rust#142882 (Lazy init diagnostics-only local_names in borrowck) - rust-lang/rust#142883 (Add impl_trait_in_bindings tests from rust-lang/rust#61773) - rust-lang/rust#142943 (Don't include current rustc version string in feature removed help) - rust-lang/rust#142965 ([RTE-497] Ignore `c-link-to-rust-va-list-fn` test on SGX platform) - rust-lang/rust#142972 (Add a missing mailmap entry) r? `@ghost` `@rustbot` modify labels: rollup
2025-06-24Rewrite #[track_caller]Jana Dönszelmann-28/+26
2025-06-24Fix LTO for internalizing rustc_std_internal_symbol symbolsbjorn3-0/+15
2025-06-24Add all rustc_std_internal_symbol to symbols.objorn3-21/+18
rustc_std_internal_symbol is meant to call functions from crates where there is no direct dependency on said crate. As they either have to be added to symbols.o or rustc has to introduce an implicit dependency on them to avoid linker errors. The latter is done for some things like the panic runtime, but adding these symbols to symbols.o allows removing those implicit dependencies.
2025-06-24Rollup merge of #142742 - dpaoliello:arm64eclinking, r=bjorn3Guillaume Gomez-49/+141
[win][aarch64] Fix linking statics on Arm64EC, take 2 Arm64EC builds recently started to fail due to the linker not finding a symbol: ``` symbols.o : error LNK2001: unresolved external symbol #_ZN3std9panicking11EMPTY_PANIC17hc8d2b903527827f1E (EC Symbol) C:\Code\hello-world\target\arm64ec-pc-windows-msvc\debug\deps\hello_world.exe : fatal error LNK1120: 1 unresolved externals ``` It turns out that `EMPTY_PANIC` is a new static variable that was being exported then imported from the standard library, but when exporting LLVM didn't prepend the name with `#` (as only functions are prefixed with this character), whereas Rust was prefixing with `#` when attempting to import it. The fix is to have Rust not prefix statics with `#` when importing. Adding tests discovered another issue: we need to correctly mark static exported from dylibs with `DATA`, otherwise MSVC's linker assumes they are functions and complains that there is no exit thunk for them. Fixes rust-lang/rust#138541 Resurrects rust-lang/rust#140176 now that rust-lang/rust#141061 is merged, which removes the incompatibility with `__rust_no_alloc_shim_is_unstable`. r? ``@wesleywiser`` CC ``@bjorn3``
2025-06-24rustc_session: Add a structure for keeping both explicit and default sysrootsVadim Petrochenkov-7/+7
Also avoid creating and cloning sysroot unnecessarily.
2025-06-23Rollup merge of #142923 - folkertdev:min-function-alignment-no-attributes, ↵Jubilee-6/+4
r=workingjubilee fix `-Zmin-function-alignment` on functions without attributes tracking issue: https://github.com/rust-lang/rust/issues/82232 related: https://github.com/rust-lang/rust/pull/142854 The minimum function alignment was skipped on functions without attributes (because the logic was in a loop that only runs if there is at least one attribute). The underlying reason we didn't catch this before is that in our testing we generally apply `#[no_mangle]` to functions that are tested. I've added a test now that deliberately has no attributes. r? `@workingjubilee`
2025-06-23[Arm64EC] Only decorate functions with `#`Daniel Paoliello-49/+141
2025-06-23fix `-Zmin-function-alignment` without attributesFolkert de Vries-6/+4
the minimum function alignment was skipped on functions without attributes. That is because in our testing we generally apply `#[no_mangle]` to functions that are tested. I've added a test now that deliberately has no attributes
2025-06-23rewrite #[naked] parserJana Dönszelmann-1/+1
2025-06-23Rollup merge of #142854 - folkertdev:centralize-min-function-alignment, ↵Matthias Krüger-6/+8
r=workingjubilee centralize `-Zmin-function-alignment` logic tracking issue: https://github.com/rust-lang/rust/issues/82232 discussed in: https://github.com/rust-lang/rust/pull/142824#discussion_r2160056244 Apply the `-Zmin-function-alignment` value to the alignment field of the function attributes when those are created, so that individual backends don't need to consider it. The one exception right now is cranelift, because it can't yet set the alignment for individual functions, but it can (and does) set the global minimum function alignment. cc ``@RalfJung`` I think this is an improvement regardless, is there anything else that should be done for miri?
2025-06-22Port `#[no_mangle]` to new attribute parsing infrastructureJonathan Brouwer-24/+32
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-22Remove dead instructions in terminate blocksMark Rousskov-1/+1
2025-06-21target-feature: enable rust target features implied by target-cpuJed Brown-2/+13
Normally LLVM and rustc agree about what features are implied by target-cpu, but for NVPTX, LLVM considers sm_* and ptx* features to be exclusive, which makes sense for codegen purposes. But in Rust, we want to think of them as: sm_{sver} means that the target supports the hardware features of sver ptx{pver} means the driver supports PTX ISA pver Intrinsics usually require a minimum sm_{sver} and ptx{pver}. Prior to this commit, -Ctarget-cpu=sm_70 would activate only sm_70 and ptx60 (the minimum PTX version that supports sm_70, which maximizes driver compatibility). With this commit, it also activates all the implied target features (sm_20, ..., sm_62; ptx32, ..., ptx50).
2025-06-22centralize `-Zmin-function-alignment` logicFolkert de Vries-6/+8
2025-06-20Rollup merge of #142650 - camsteffen:refactor-translator, r=petrochenkovTrevor Gross-13/+7
Refactor Translator My main motivation was to simplify the usage of `SilentEmitter` for users like rustfmt. A few refactoring opportunities arose along the way. * Replace `Translate` trait with `Translator` struct * Replace `Emitter: Translate` with `Emitter::translator` * Split `SilentEmitter` into `FatalOnlyEmitter` and `SilentEmitter`
2025-06-20coldJana Dönszelmann-4/+15
2025-06-20Rollup merge of #140920 - RalfJung:target-feature-unification, ↵Trevor Gross-52/+347
r=nnethercote,WaffleLapkin Extract some shared code from codegen backend target feature handling There's a bunch of code duplication between the GCC and LLVM backends in target feature handling. This moves that into new shared helper functions in `rustc_codegen_ssa`. The first two commits should be purely refactoring. I am fairly sure the LLVM-side behavior stays the same; if the GCC side deliberately diverges from this then I may have missed that. I did account for one divergence, which I do not know is deliberate or not: GCC does not seem to use the `-Ctarget-feature` flag to populate `cfg(target_feature)`. That seems odd, since the `-Ctarget-feature` flag is used to populate the return value of `global_gcc_features` which controls the target features actually used by GCC. ``@GuillaumeGomez`` ``@antoyo`` is there a reason `target_config` ignores `-Ctarget-feature` but `global_gcc_features` does not? The second commit also cleans up a bunch of unneeded complexity added in https://github.com/rust-lang/rust/pull/135927. The third commit extracts some shared logic out of the functions that populate `cfg(target_feature)` and the backend target feature set, respectively. This one actually has some slight functional changes: - Before, with `-Ctarget-feature=-feat`, if there is some other feature `x` that implies `feat` we would *not* add `-x` to the backend target feature set. Now, we do. This fixes rust-lang/rust#134792. - The logic that removes `x` from `cfg(target_feature)` in this case also changed a bit, avoiding a large number of calls to the (uncached) `sess.target.implied_target_features` (if there were a large number of positive features listed before a negative feature) but instead constructing a full inverse implication map when encountering the first negative feature. Ideally this would be done with queries but the backend target feature logic runs before `tcx` so we can't use that... - Previously, if feature "a" implied "b" and "b" was unstable, then using `-Ctarget-feature=+a` would also emit a warning about `b`. I had to remove this since when accounting for negative implications, this emits a ton of warnings in a bunch of existing tests... I assume this was unintentional anyway. The fourth commit increases consistency of the GCC backend with the LLVM backend. The last commit does some further cleanup: - Get rid of RUSTC_SPECIAL_FEATURES. It was only needed for s390x "backchain", but since LLVM 19 that is always a regular target feature so we don't need this hack any more. The hack also has various unintended side-effects so we don't want to keep it. Fixes https://github.com/rust-lang/rust/issues/142412. - Move RUSTC_SPECIFIC_FEATURES handling into the shared parse_rust_feature_flag helper so all consumers of `-Ctarget-feature` that only care about actual target features (and not "crt-static") have it. Previously, we actually set `cfg(target_feature = "crt-static")` twice: once in the backend target feature logic, and once specifically for that one feature. IIUC, some targets are meant to ignore `-Ctarget-feature=+crt-static`, it seems like before this PR that flag still incorrectly enabled `cfg(target_feature = "crt-static")` (but I didn't test this). - Move fixed_x18 handling together with retpoline handling. - Forbid setting fixed_x18 as a regular target feature, even unstably. It must be set via the `-Z` flag. ``@bjorn3`` I did not touch the cranelift backend here, since AFAIK it doesn't really support target features. But if you ever do, please use the new helpers. :) Cc ``@workingjubilee``
2025-06-20Rollup merge of #138291 - jdonszelmann:optimize-attr, r=oli-obkTrevor Gross-41/+2
rewrite `optimize` attribute to use new attribute parsing infrastructure r? ```@oli-obk``` I'm afraid we'll get quite a few of these PRs in the future. If we get a lot of trivial changes I'll start merging multiple into one PR. They should be easy to review :) Waiting on #138165 first
2025-06-19Avoid a bitcast FFI call in transmutingScott McMurray-2/+8
For things that only change the valid ranges, we can just skip the `LLVMBuildBitCast` call. I tried to tweak this a bit more and broke stuff, so I also added some extra tests for that as we apparently didn't have coverage.
2025-06-19Extract Translator structCameron Steffen-13/+7
2025-06-19various minor target feature cleanupsRalf Jung-17/+12
2025-06-19line-wrap and extend comments, typosRalf Jung-9/+16
2025-06-19cg_gcc: properly populate cfg(target_features) with -Ctarget-featuresRalf Jung-9/+4