Commit Graph

99 Commits

Author SHA1 Message Date
sayantn a5372be2a1 Add target arch verification for LLVM intrinsics 2026-04-12 23:33:27 +05:30
sayantn c21f4ee437 Check for AutoUpgraded intrinsics, and lint on uses of deprecated intrinsics 2026-04-12 23:33:15 +05:30
sayantn aa1a5f8a93 Codegen non-overloaded LLVM intrinsics using their name 2026-04-12 19:00:17 +05:30
Eddy (Eduard) Stefes f39fa9e4c0 add rustc option -Zpacked-stack
this enables packed-stack just as -mpacked-stack in clang and gcc.
packed-stack is needed on s390x for kernel development.

Co-authored-by: Ralf Jung <post@ralfj.de>
2026-03-31 09:06:31 +02:00
Mark Rousskov 6458ca5349 Unknown -> Unsupported compression algorithm
Both zstd and zlib are *known* compression algorithms, they just may not
be supported by the backend. We shouldn't mislead users into e.g.
thinking they made a typo.
2026-03-22 08:27:50 -04:00
Josh Stone 52dfa94cdc Update the minimum external LLVM to 21 2026-03-12 16:45:42 -07:00
Jonathan Brouwer 10eb844bac Remove eagerly_format_to_string from DiagCtxt 2026-03-06 18:52:11 +01:00
Jonathan Brouwer d8092147fe Rename translation -> formatting 2026-03-04 17:47:24 +01:00
Jonathan Brouwer 018a5efcf7 Rename inline_fluent! to msg! 2026-02-14 13:47:52 +01:00
bjorn3 2d07e81a5c Move target machine factory error reporting into codegen backend 2026-02-11 10:53:38 +00:00
bjorn3 70587ce07c Remove a couple of unused errors 2026-02-11 10:39:48 +00:00
Jonathan Brouwer edd43c9e1f Fix existing messages in the diag structs 2026-02-07 09:11:34 +01:00
bjorn3 d2a0557afb Convert to inline diagnostics in all codegen backends 2026-02-04 13:12:49 +00:00
sgasho 14ac6a1d3a Modified to output error messages appropriate to the situation 2026-01-07 00:33:57 +09:00
sgasho d7fa6e527f enrich error info when tries to dlopen Enzyme 2026-01-04 22:56:17 +09:00
Manuel Drehwald 3fdc6da2aa adding proper error handling for offload 2025-12-23 05:20:11 -08:00
Manuel Drehwald c34ea6e56d remove llvm_enzyme and enzyme fallbacks from most places, enable the autodiff frontend on nightly 2025-12-19 11:02:57 -08:00
Manuel Drehwald 793d990d11 Emit a proper error if we fail to find libEnzyme 2025-12-16 21:33:28 +01:00
Marcelo Domínguez 5128ce10a0 Implement offload intrinsic 2025-11-25 20:04:27 +01:00
Manuel Drehwald 63f4b36406 provide an error if an autodiff user does not set in their Cargo.toml 2025-11-11 23:44:06 -05:00
bjorn3 fe2eeabe27 Use the object crate rather than LLVM for extracting bitcode sections 2025-07-25 11:21:28 +00:00
bjorn3 1c8dc6f440 Move LTO symbol export calculation from backends to cg_ssa 2025-07-21 07:58:44 +00: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
Ralf Jung cd08652faa move -Ctarget-feature handling into shared code 2025-06-19 09:44:01 +09:00
Andrew Zhogin 5601490c9d -Zretpoline and -Zretpoline-external-thunk flags (target modifiers) to enable retpoline-related target features 2025-06-09 21:29:59 +07:00
Folkert de Vries a50bd7ca24 store target.min_global_align as an Align 2025-06-07 22:06:42 +02:00
Ramon de C Valle a98546b961 KCFI: Add KCFI arity indicator support
Adds KCFI arity indicator support to the Rust compiler (see rust-lang/rust#138311,
https://github.com/llvm/llvm-project/pull/121070, and
https://lore.kernel.org/lkml/CANiq72=3ghFxy8E=AU9p+0imFxKr5iU3sd0hVUXed5BA+KjdNQ@mail.gmail.com/).
2025-04-05 04:05:04 +00:00
Manuel Drehwald e2d250c3f6 update autodiff flags 2025-02-21 21:51:20 -05:00
Daniel Paoliello bfdc96114c [cg_llvm] Remove dead error message 2025-02-13 15:04:39 -08:00
bors feb32c6546 Auto merge of #134794 - RalfJung:abi-required-target-features, r=workingjubilee
Add a notion of "some ABIs require certain target features"

I think I finally found the right shape for the data and checks that I recently added in https://github.com/rust-lang/rust/pull/133099, https://github.com/rust-lang/rust/pull/133417, https://github.com/rust-lang/rust/pull/134337: we have a notion of "this ABI requires the following list of target features, and it is incompatible with the following list of target features". Both `-Ctarget-feature` and `#[target_feature]` are updated to ensure we follow the rules of the ABI.  This removes all the "toggleability" stuff introduced before, though we do keep the notion of a fully "forbidden" target feature -- this is needed to deal with target features that are actual ABI switches, and hence are needed to even compute the list of required target features.

We always explicitly (un)set all required and in-conflict features, just to avoid potential trouble caused by the default features of whatever the base CPU is. We do this *before* applying `-Ctarget-feature` to maintain backward compatibility; this poses a slight risk of missing some implicit feature dependencies in LLVM but has the advantage of not breaking users that deliberately toggle ABI-relevant target features. They get a warning but the feature does get toggled the way they requested.

For now, our logic supports x86, ARM, and RISC-V (just like the previous logic did). Unsurprisingly, RISC-V is the nicest. ;)

As a side-effect this also (unstably) allows *enabling* `x87` when that is harmless. I used the opportunity to mark SSE2 as required on x86-64, to better match the actual logic in LLVM and because all x86-64 chips do have SSE2. This infrastructure also prepares us for requiring SSE on x86-32 when we want to use that for our ABI (and for float semantics sanity), see https://github.com/rust-lang/rust/issues/133611, but no such change is happening in this PR.

r? `@workingjubilee`
2025-01-05 23:21:06 +00:00
Manuel Drehwald d753cbf779 upstream rustc_codegen_llvm changes for enzyme/autodiff 2025-01-01 21:42:45 +01:00
Ralf Jung 2bf27e09be explicitly model that certain ABIs require/forbid certain target features 2024-12-31 12:41:20 +01:00
Ralf Jung ffad9aac27 mark some target features as 'forbidden' so they cannot be (un)set
For now, this is just a warning, but should become a hard error in the future
2024-11-04 22:56:47 +01:00
David Wood 207bc77e15 codegen_ssa: consolidate tied feature checking
`rustc_codegen_llvm` and `rustc_codegen_gcc` duplicated logic for
checking if tied target features were partially enabled. This commit
consolidates these checks into `rustc_codegen_ssa` in the
`codegen_fn_attrs` query, which also is run pre-monomorphisation for
each function, which ensures that this check is run for unused functions,
as would be expected.
2024-09-24 15:48:49 +01:00
Matthias Krüger 110c3df7fd Rollup merge of #126013 - nnethercote:unreachable_pub, r=Urgau
Add `#[warn(unreachable_pub)]` to a bunch of compiler crates

By default `unreachable_pub` identifies things that need not be `pub` and tells you to make them `pub(crate)`. But sometimes those things don't need any kind of visibility. So they way I did these was to remove the visibility entirely for each thing the lint identifies, and then add `pub(crate)` back in everywhere the compiler said it was necessary. (Or occasionally `pub(super)` when context suggested that was appropriate.) Tedious, but results in more `pub` removal.

There are plenty more crates to do but this seems like enough for a first PR.

r? `@compiler-errors`
2024-08-27 00:41:57 +02:00
Chris Denton 0156eb57a1 Always use ar_archive_writer for import libs 2024-08-17 19:10:46 +00:00
Nicholas Nethercote 61627438eb Add warn(unreachable_pub) to rustc_codegen_llvm. 2024-08-16 08:46:57 +10:00
bjorn3 216686bfa5 Move mingw dlltool invocation to cg_ssa 2024-07-30 10:33:33 +00:00
Nicholas Nethercote 84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Oli Scherer 3f34196839 Remove redundant argument from subdiagnostic method 2024-06-18 15:42:11 +00:00
Oli Scherer 7ba82d61eb Use a dedicated type instead of a reference for the diagnostic context
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-18 15:42:11 +00:00
Alice Ryhl b780fa9219 Use an error struct instead of a panic 2024-05-15 11:14:45 +02:00
Nicholas Nethercote 7a294e998b Rename IntoDiagnostic as Diagnostic.
To match `derive(Diagnostic)`.

Also rename `into_diagnostic` as `into_diag`.
2024-03-11 09:15:09 +11:00
Nicholas Nethercote 899cb40809 Rename DiagnosticBuilder as Diag.
Much better!

Note that this involves renaming (and updating the value of)
`DIAGNOSTIC_BUILDER` in clippy.
2024-02-28 08:55:35 +11:00
Nicholas Nethercote b38ed1afa6 Overhaul Diagnostic args.
First, introduce a typedef `DiagnosticArgMap`.

Second, make the `args` field public, and remove the `args` getter and
`replace_args` setter. These were necessary previously because the getter
had a `#[allow(rustc::potential_query_instability)]` attribute, but that
was removed in #120931 when the args were changed from `FxHashMap` to
`FxIndexMap`. (All the other `Diagnostic` fields are public.)
2024-02-22 12:51:05 +11:00
David Wood b80fc5d4e8 errors: only eagerly translate subdiagnostics
Subdiagnostics don't need to be lazily translated, they can always be
eagerly translated. Eager translation is slightly more complex as we need
to have a `DiagCtxt` available to perform the translation, which involves
slightly more threading of that context.

This slight increase in complexity should enable later simplifications -
like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages
into the diagnostic structs rather than having them in separate files
(working on that was what led to this change).

Signed-off-by: David Wood <david@davidtw.co>
2024-02-15 10:34:41 +00:00
Matthias Krüger 8906977542 Rollup merge of #120631 - saethlin:invalid-target-ice, r=compiler-errors
Emit a diagnostic for invalid target options

This turns the ICE in https://github.com/rust-lang/rust/issues/120625 into a translatable diagnostic.
2024-02-06 19:40:08 +01:00
Ben Kimock 934618fe47 Emit a diagnostic for invalid target options 2024-02-03 22:03:25 -05:00
Nicholas Nethercote a9a2e1565a Diagnostic cleanups
- `emitted_at` isn't used outside the crate.
- `code` and `messages` are public fields, so there's no point have
  trivial getters/setters for them.
- `suggestions` is public, so the comment about "functionality on
  `Diagnostic`" isn't needed.
2024-02-03 09:02:50 +11:00
David Wood 46652dd254 llvm: simplify data layout check
Don't skip the inconsistent data layout check for custom LLVMs.

With #118708, all targets will have a simple test that would trigger this
check if LLVM's data layouts do change - so data layouts would be
corrected during the LLVM upgrade. Therefore, with builtin targets, this
check won't trigger with our LLVM because each target will have been
confirmed to work. With non-builtin targets, this check is probably
useful to have because you can change the data layout in your target and
if its wrong then that could lead to bugs.

When using a custom LLVM, the same justification makes sense for
non-builtin targets as with our LLVM, the user can update their target to
match their LLVM and that's probably a good thing to do. However, with
a custom LLVM, the user cannot change the builtin target data layouts if
they don't match - though given that the compiler's data layout is used
for layout computation and a bunch of other things - you could get some
bugs because of the mismatch and probably want to know about that.

`CFG_LLVM_ROOT` was also always set during local development with
`download-ci-llvm` so this bug would never trigger locally.

Signed-off-by: David Wood <david@davidtw.co>
2024-01-18 10:46:03 +00:00