about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa
AgeCommit message (Collapse)AuthorLines
2025-03-12Auto merge of #138083 - nnethercote:rm-NtItem-NtStmt, r=petrochenkovbors-0/+1
Remove `NtItem` and `NtStmt` Another piece of #124141. r? `@petrochenkov`
2025-03-12Don't `alloca` just to look at a discriminantScott McMurray-139/+147
Today we're making LLVM do a bunch of extra work for every enum you match on, even trivial stuff like `Option<bool>`. Let's not.
2025-03-12Move methods from `Map` to `TyCtxt`, part 4.Nicholas Nethercote-5/+5
Continuing the work from #137350. Removes the unused methods: `expect_variant`, `expect_field`, `expect_foreign_item`. Every method gains a `hir_` prefix.
2025-03-11Rollup merge of #138231 - Sa4dUs:autodiff-ice, r=ZuseZ4Matthias Krüger-12/+1
Prevent ICE in autodiff validation by emitting user-friendly errors This PR moves `valid_ret_activity` and `valid_input_activity` checks to the macro expansion phase in compiler/rustc_builtin_macros/src/autodiff.rs, replacing the following internal compiler error (ICE): ``` error: internal compiler error: compiler/rustc_codegen_ssa/src/codegen_attrs.rs:935:13: Invalid input activity Dual for Reverse mode ``` with a more user-friendly message. The issue specifically affected the test file `tests/ui/autodiff/autodiff_illegal.rs`, impacting the functions `f5` and `f6`. The ICE can be reproduced by following [Enzyme's Rustbook](https://enzymead.github.io/rustbook/installation.html) installation guide. Additionally, this PR adds tests for invalid return activity in `autodiff_illegal.rs`, which previously triggered an unnoticed ICE before these fixes. r? ``@oli-obk``
2025-03-11Auto merge of #137586 - nnethercote:SetImpliedBits, r=bjorn3bors-4/+7
Speed up target feature computation The LLVM backend calls `LLVMRustHasFeature` twice for every feature. In short-running rustc invocations, this accounts for a surprising amount of work. r? `@bjorn3`
2025-03-11Fix ICE for invalid return activity and proper error handlingMarcelo Domínguez-18/+1
2025-03-11Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-11Auto merge of #138302 - matthiaskrgr:rollup-an2up80, r=matthiaskrgrbors-84/+160
Rollup of 8 pull requests Successful merges: - #136395 (Update to rand 0.9.0) - #137279 (Make some invalid codegen attr errors structured/translatable) - #137585 (Update documentation to consistently use 'm' in atomic synchronization example) - #137926 (Add a test for `-znostart-stop-gc` usage with LLD) - #138074 (Support `File::seek` for Hermit) - #138238 (Fix dyn -> param suggestion in struct ICEs) - #138270 (chore: Fix some comments) - #138286 (triagebot.toml: Don't label `test/rustdoc-json` as A-rustdoc-search (…) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-11naked functions: on windows emit `.endef` without the symbol nameFolkert de Vries-1/+1
also add test with `fastcall`, which on i686 uses a different mangling scheme
2025-03-10Revert "Use workspace lints for crates in `compiler/` #138084"许杰友 Jieyou Xu (Joe)-3/+1
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to consider options that avoids breaking downstream usages of cargo on distributed `rustc-src` artifacts, where such cargo invocations fail due to inability to inherit `lints` from workspace root manifest's `workspace.lints` (this is only valid for the source rust-lang/rust workspace, but not really the distributed `rustc-src` artifacts). This breakage was reported in <https://github.com/rust-lang/rust/issues/138304>. This reverts commit 48caf81484b50dca5a5cebb614899a3df81ca898, reversing changes made to c6662879b27f5161e95f39395e3c9513a7b97028.
2025-03-10Rollup merge of #137279 - estebank:codegen-structured-errors, r=nnethercoteMatthias Krüger-84/+160
Make some invalid codegen attr errors structured/translatable
2025-03-09metadata: Ignore sysroot when doing the manual native lib search in rustcVadim Petrochenkov-14/+12
2025-03-09Rollup merge of #138084 - nnethercote:workspace-lints, r=jieyouxuMatthias Krüger-1/+3
Use workspace lints for crates in `compiler/` This is nicer and hopefully less error prone than specifying lints via bootstrap. r? ``@jieyouxu``
2025-03-09Rollup merge of #138040 - thaliaarchi:use-prelude-size-of.compiler, ↵Matthias Krüger-1/+1
r=compiler-errors compiler: Use `size_of` from the prelude instead of imported Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. Apply this change across the compiler. These functions were added to all preludes in Rust 1.80. r? ``@compiler-errors``
2025-03-09Auto merge of #137513 - scottmcm:identity-transmute, r=saethlinbors-0/+7
Don't re-`assume` in `transmute`s that don't change niches I noticed in nightly 2025-02-21 that `transmute` is emitting way more `assume`s than necessary for newtypes. For example, the three transmutes in <https://rust.godbolt.org/z/fW1KaTc4o> emits ```rust define noundef range(i32 1, 0) i32 `@repeatedly_transparent_transmute(i32` noundef range(i32 1, 0) %_1) unnamed_addr { start: %0 = sub i32 %_1, 1 %1 = icmp ule i32 %0, -2 call void `@llvm.assume(i1` %1) %2 = sub i32 %_1, 1 %3 = icmp ule i32 %2, -2 call void `@llvm.assume(i1` %3) %4 = sub i32 %_1, 1 %5 = icmp ule i32 %4, -2 call void `@llvm.assume(i1` %5) %6 = sub i32 %_1, 1 %7 = icmp ule i32 %6, -2 call void `@llvm.assume(i1` %7) %8 = sub i32 %_1, 1 %9 = icmp ule i32 %8, -2 call void `@llvm.assume(i1` %9) %10 = sub i32 %_1, 1 %11 = icmp ule i32 %10, -2 call void `@llvm.assume(i1` %11) ret i32 %_1 } ``` But those are all just newtypes that don't change size or niches, so none of it's needed. After this PR it's down to just ```rust define noundef range(i32 1, 0) i32 `@repeatedly_transparent_transmute(i32` noundef range(i32 1, 0) %_1) unnamed_addr { start: ret i32 %_1 } ``` because none of those `assume`s in the original actually did anything. (Transmuting to something with a difference niche, though, still has the assumes -- the other tests continue to pass checking that.)
2025-03-08Auto merge of #137500 - scottmcm:trunc-br, r=saethlinbors-0/+34
Use `trunc nuw`+`br` for 0/1 branches even in optimized builds Rather than needing to use `switch` for them to include the `unreachable` arm.
2025-03-08support XCOFF in `naked_asm!`Folkert de Vries-9/+41
2025-03-08Rollup merge of #137685 - lqd:nostart-stop-gc, r=petrochenkovJacob Pratt-0/+29
self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux To help stabilization, this PR disables an LLD optimization on x64 linux with respect to `--gc-sections` and encapsulation symbols: it will reduce the number of crates needing to opt-out of lld due to this bfd / lld difference. For example, all the people using [linkme](https://github.com/dtolnay/linkme), which [doesn't work with lld](https://github.com/dtolnay/linkme/issues/63) or on nightly, need to disable lld. More information about all this, and the historical differences, can be found in: - https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order - https://lld.llvm.org/ELF/start-stop-gc This optimization has [no visible impact](https://github.com/rust-lang/rust/pull/137685#issuecomment-2686116312) on our benchmarks, so we can use it by default and have a safer/more conservative starting point to remove friction during migration. We can them emit an FCW for the cases where lld detects reliance on encapsulation symbols without `-znostart-stop-gc`, and then revert back to lld's default after a while. No one compiling on nightly relies on this difference, obviously, so doing an FCW is not necessary until after lld is used on stable. I've tested that this correctly links on `linkme` examples. I've also quickly tried to crate an rmake test but the setup with encapsulation symbols is annoying to reproduce: a few link section/name attributes is not enough, we also need to collect symbols between the encapsulation symbols, without referencing them in code, for `-znostart-stop-gc` to only impact this... It should of course be doable though, maybe ````@Kobzol```` will look into it if they have time. r? ````@petrochenkov````
2025-03-07Rollup merge of #137337 - dalvescb:master, r=petrochenkovJacob Pratt-3/+3
Add verbatim linker to AIXLinker This adds support for the "verbatim" native link modifier on AIX, will successfully pass the `native-link-modifier-verbatim-linker test case`
2025-03-07Make some invalid codegen attr errors structured/translatableEsteban Küber-84/+160
2025-03-08Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
(Except for `rustc_codegen_cranelift`.) It's no longer necessary now that `unreachable_pub` is in the workspace lints.
2025-03-08Specify rust lints for `compiler/` crates via Cargo.Nicholas Nethercote-0/+3
By naming them in `[workspace.lints.rust]` in the top-level `Cargo.toml`, and then making all `compiler/` crates inherit them with `[lints] workspace = true`. (I omitted `rustc_codegen_{cranelift,gcc}`, because they're a bit different.) The advantages of this over the current approach: - It uses a standard Cargo feature, rather than special handling in bootstrap. So, easier to understand, and less likely to get accidentally broken in the future. - It works for proc macro crates. It's a shame it doesn't work for rustc-specific lints, as the comments explain.
2025-03-07compiler: Use size_of from the prelude instead of importedThalia Archibald-1/+1
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-03-07Rollup merge of #137549 - oli-obk:llvm-ffi, r=davidtwcoMatthias Krüger-12/+12
Clean up various LLVM FFI things in codegen_llvm cc ```@ZuseZ4``` I touched some autodiff parts The major change of this PR is [bfd88ce](https://github.com/rust-lang/rust/pull/137549/commits/bfd88cead0dd79717f123ad7e9a26ecad88653cb) which makes `CodegenCx` generic just like `GenericBuilder` The other commits mostly took advantage of the new feature of making extern functions safe, but also just used some wrappers that were already there and shrunk unsafe blocks. best reviewed commit-by-commit
2025-03-06Use `trunc nuw`+`br` for 0/1 branches even in optimized buildsScott McMurray-0/+34
Rather than needing to use `switch` for them to include the `unreachable` arm
2025-03-07Increase recursion_limit in numerous crates.Nicholas Nethercote-0/+1
This is temporarily needed for `x doc compiler` to work. They can be removed once the `Nonterminal` is removed (#124141).
2025-03-06Lower BinOp::Cmp to llvm.{s,u}cmp.* intrinsicsDaniPopes-0/+15
Lowers `mir::BinOp::Cmp` (`three_way_compare` intrinsic) to the corresponding LLVM `llvm.{s,u}cmp.i8.*` intrinsics, added in LLVM 19.
2025-03-05linux x64: default to `-znostart-stop-gc`Rémy Rakic-0/+29
This will help stabilization of lld.
2025-03-05Change signature of `target_features_cfg`.Nicholas Nethercote-3/+6
Currently it is called twice, once with `allow_unstable` set to true and once with it set to false. This results in some duplicated work. Most notably, for the LLVM backend, `LLVMRustHasFeature` is called twice for every feature, and it's moderately slow. For very short running compilations on platforms with many features (e.g. a `check` build of hello-world on x86) this is a significant fraction of runtime. This commit changes `target_features_cfg` so it is only called once, and it now returns a pair of feature sets. This halves the number of `LLVMRustHasFeature` calls.
2025-03-05Simplify `implied_target_features`.Nicholas Nethercote-1/+1
Currently its argument is an iterator, but in practice it's always a singleton.
2025-03-04Auto merge of #135695 - Noratrieb:elf-raw-dylib, r=bjorn3bors-197/+480
Support raw-dylib link kind on ELF raw-dylib is a link kind that allows rustc to link against a library without having any library files present. This currently only exists on Windows. rustc will take all the symbols from raw-dylib link blocks and put them in an import library, where they can then be resolved by the linker. While import libraries don't exist on ELF, it would still be convenient to have this same functionality. Not having the libraries present at build-time can be convenient for several reasons, especially cross-compilation. With raw-dylib, code linking against a library can be cross-compiled without needing to have these libraries available on the build machine. If the libc crate makes use of this, it would allow cross-compilation without having any libc available on the build machine. This is not yet possible with this implementation, at least against libc's like glibc that use symbol versioning. The raw-dylib kind could be extended with support for symbol versioning in the future. This implementation is very experimental and I have not tested it very well. I have tested it for a toy example and the lz4-sys crate, where it was able to successfully link a binary despite not having a corresponding library at build-time. I was inspired by Björn's comments in https://internals.rust-lang.org/t/bundle-zig-cc-in-rustup-by-default/22096/27 Tracking issue: #135694 r? bjorn3 try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: test-various
2025-03-04Auto merge of #137959 - matthiaskrgr:rollup-62vjvwr, r=matthiaskrgrbors-62/+24
Rollup of 12 pull requests Successful merges: - #135767 (Future incompatibility warning `unsupported_fn_ptr_calling_conventions`: Also warn in dependencies) - #137852 (Remove layouting dead code for non-array SIMD types.) - #137863 (Fix pretty printing of unsafe binders) - #137882 (do not build additional stage on compiler paths) - #137894 (Revert "store ScalarPair via memset when one side is undef and the other side can be memset") - #137902 (Make `ast::TokenKind` more like `lexer::TokenKind`) - #137921 (Subtree update of `rust-analyzer`) - #137922 (A few cleanups after the removal of `cfg(not(parallel))`) - #137939 (fix order on shl impl) - #137946 (Fix docker run-local docs) - #137955 (Always allow rustdoc-json tests to contain long lines) - #137958 (triagebot.toml: Don't label `test/rustdoc-json` as A-rustdoc-search) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-03Rollup merge of #137894 - compiler-errors:no-scalar-pair-opt, r=oli-obkMatthias Krüger-62/+24
Revert "store ScalarPair via memset when one side is undef and the other side can be memset" cc #137892 reverts #135335 r? oli-obk
2025-03-03Auto merge of #137914 - matthiaskrgr:rollup-phaxe6f, r=matthiaskrgrbors-12/+44
Rollup of 6 pull requests Successful merges: - #137103 ({json|html}docck: catch and error on deprecated syntax) - #137632 (rustdoc: when merging target features, keep the highest stability) - #137684 (Add rustdoc support for `--emit=dep-info[=path]`) - #137794 (make qnx pass a test) - #137801 (tests: Unignore target modifier tests on all platforms) - #137826 (test(codegen): add looping_over_ne_bytes test for #133528) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-03Rollup merge of #137632 - RalfJung:rustdoc-target-features, r=workingjubileeMatthias Krüger-12/+44
rustdoc: when merging target features, keep the highest stability This addresses https://github.com/rust-lang/rust/issues/137366. (Not closing since we might consider a backport.) rustdoc wants to pretend that it runs for all targets at once and has all target features, so `tcx.rust_target_features()` will actually be all the target features. For target features that exist on multiple targets, the stability info for one of the targets will be picked (first or last in the list, I guess). All the code consuming that query has to be aware that the data is basically nonsense when running in rustdoc, but the logic checking for unstable or forbidden `#[target_feature]` attributes was not aware of that. This PR makes the `tcx.rust_target_features()` info in rustdoc slightly less nonsensical (and decidedly less random) by having the "most stable" target feature take precedent. That deals with #137366 (a conflict between a stable and a "forbidden" target feature of the same name for different targets), and also deals with the situation (that we did not seem to have yet) of a conflict between a stable and an unstable target feature of the same name. Note that if there are two unstable target features of the same name, rustdoc might still require the "wrong" nightly feature to be enabled -- but this can only possibly affect unstable code so I guess we can wait until that actually happens, and then someone will have to rewrite this entire thing to be less hacky.
2025-03-02Prevent ICE in autodiff validation by emitting user-friendly errorsSa4dUs-2/+8
2025-03-02Rollup merge of #137851 - folkertdev:simd-intrinsic-mask-signed, ↵Matthias Krüger-1/+3
r=workingjubilee improve `simd_select` error message when used with invalid mask type followup to https://github.com/rust-lang/rust/pull/137828 This PR improves the error message for an invalid `simd_select` mask type, and adds testing for `simd_scatter` and `simd_gather` being used with invalid mask types. the `simd_masked_load` and `simd_masked_store` intrinsics already generated a better error message: https://github.com/rust-lang/rust/blob/0c72c0d11adeba449886089c6bd5d48363f7a2cd/tests/ui/simd/masked-load-store-build-fail.rs#L24-L37 r? `@workingjubilee`
2025-03-02Revert "Auto merge of #135335 - oli-obk:push-zxwssomxxtnq, r=saethlin"Michael Goulet-62/+24
This reverts commit a7a6c64a657f68113301c2ffe0745b49a16442d1, reversing changes made to ebbe63891f1fae21734cb97f2f863b08b1d44bf8.
2025-03-01Rollup merge of #137830 - LuigiPiucco:incompatible-isa-fix, r=workingjubileeMatthias Krüger-1/+5
Fix link failure on AVR (incompatible ISA error) Fixes #137739. A reproducer of the issue is present there. I believe the root cause was introducing the avr-none target (which has no CPU by default) while also trying to get the ISA revision from the target spec. This commit uses the `target-cpu` option instead, which is already required to be present for the target. r? compiler cc ``@Patryk27``
2025-03-01Rollup merge of #137804 - RalfJung:backend-repr-simd-vector, r=workingjubileeMatthias Krüger-5/+5
rename BackendRepr::Vector → SimdVector For many Rustaceans, "vector" does not imply "SIMD", so let's be more clear in this type that is used pervasively in the compiler. r? `@workingjubilee`
2025-03-01also skip abi_required_features check in rustdocRalf Jung-6/+11
2025-03-01improve error message and testing of using an unsigned simd maskFolkert de Vries-1/+3
2025-03-01Auto merge of #133250 - DianQK:embed-bitcode-pgo, r=nikicbors-4/+28
The embedded bitcode should always be prepared for LTO/ThinLTO Fixes #115344. Fixes #117220. There are currently two methods for generating bitcode that used for LTO. One method involves using `-C linker-plugin-lto` to emit object files as bitcode, which is the typical setting used by cargo. The other method is through `-C embed-bitcode=yes`. When using with `-C embed-bitcode=yes -C lto=no`, we run a complete non-LTO LLVM pipeline to obtain bitcode, then the bitcode is used for LTO. We run the Call Graph Profile Pass twice on the same module. This PR is doing something similar to LLVM's `buildFatLTODefaultPipeline`, obtaining the bitcode for embedding after running `buildThinLTOPreLinkDefaultPipeline`. r? nikic
2025-03-01Auto merge of #137796 - jieyouxu:rollup-qt9yr1g, r=jieyouxubors-2/+6
Rollup of 10 pull requests Successful merges: - #134943 (Add FileCheck annotations to mir-opt/issues) - #137017 (Don't error when adding a staticlib with bitcode files compiled by newer LLVM) - #137197 (Update some comparison codegen tests now that they pass in LLVM20) - #137540 (Fix (more) test directives that were accidentally ignored) - #137551 (import `simd_` intrinsics) - #137599 (tests: use minicore more) - #137673 (Fix Windows `Command` search path bug) - #137676 (linker: Fix escaping style for response files on Windows) - #137693 (Re-enable `--generate-link-to-defintion` for tools internal rustdoc) - #137770 (Fix sized constraint for unsafe binder) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-28Fix link failure on AVR (incompatible ISA error)Luigi Sartor Piucco-1/+5
Fixes #137739. A reproducer of the issue is present there. I believe the root cause was introducing the avr-none target (which has no CPU by default) and trying to get the ISA revision from there. This commit uses the `target-cpu` option instead, which is already required to be present for the target. Co-authored-by: tones111 <tones111@users.noreply.github.com>
2025-02-28rename BackendRepr::Vector → SimdVectorRalf Jung-5/+5
2025-02-28Rollup merge of #137676 - petrochenkov:winresp, r=Kobzol许杰友 Jieyou Xu (Joe)-2/+6
linker: Fix escaping style for response files on Windows If we use a С/С++ compiler as linker, then Posix-style escaping should be used. Also temporarily fixup rustbuild to not fail at least in common scenarios, until the bootstrap compiler is updated. Fixes https://github.com/rust-lang/rust/issues/137498
2025-02-28compiler: bump `cc` to 1.2.16 to fix `x86` Windows jobs on newest Windows SDK许杰友 Jieyou Xu (Joe)-1/+1
See <https://github.com/rust-lang/rust/issues/137733>.
2025-02-26Support raw-dylib link kind on ELFNoratrieb-197/+480
raw-dylib is a link kind that allows rustc to link against a library without having any library files present. This currently only exists on Windows. rustc will take all the symbols from raw-dylib link blocks and put them in an import library, where they can then be resolved by the linker. While import libraries don't exist on ELF, it would still be convenient to have this same functionality. Not having the libraries present at build-time can be convenient for several reasons, especially cross-compilation. With raw-dylib, code linking against a library can be cross-compiled without needing to have these libraries available on the build machine. If the libc crate makes use of this, it would allow cross-compilation without having any libc available on the build machine. This is not yet possible with this implementation, at least against libc's like glibc that use symbol versioning. The raw-dylib kind could be extended with support for symbol versioning in the future. This implementation is very experimental and I have not tested it very well. I have tested it for a toy example and the lz4-sys crate, where it was able to successfully link a binary despite not having a corresponding library at build-time.
2025-02-26Rollup merge of #137201 - estebank:structured-errors-long-ty, r=oli-obkLeón Orell Valerian Liehr-3/+3
Teach structured errors to display short `Ty<'_>` Make it so that in every structured error annotated with `#[derive(Diagnostic)]` that has a field of type `Ty<'_>`, the printing of that value into a `String` will look at the thread-local storage `TyCtxt` in order to shorten to a length appropriate with the terminal width. When this happen, the resulting error will have a note with the file where the full type name was written to. ``` error[E0618]: expected function, found `((..., ..., ..., ...), ..., ..., ...)`` --> long.rs:7:5 | 6 | fn foo(x: D) { //~ `x` has type `(... | - `x` has type `((..., ..., ..., ...), ..., ..., ...)` 7 | x(); //~ ERROR expected function, found `(... | ^-- | | | call expression requires function | = note: the full name for the type has been written to 'long.long-type-14182675702747116984.txt' = note: consider using `--verbose` to print the full type name to the console ``` Follow up to and response to the comments on #136898. r? ``@oli-obk``