1050 Commits

Author SHA1 Message Date
James Barford-Evans
df74b1fe51 Remove ConstExt from ./compiler 2026-10-13 07:02:00 +01:00
Guillaume Gomez
2aff4c41cd Merge commit 'd9fb254f648445b916a2c2182ca3eb834b419221' into HEAD 2026-10-12 10:28:58 +02:00
Jonathan Brouwer
b1d98858d2 Rollup merge of #163745 - lcnr:use-existing-typing-env-where-possible, r=adwinwhite
replace `fully_monomorphized` with `cx.typing_env()`

cc rust-lang/rust#163724

reasoning about whether a given `TypingEnv` is correct is non-trivial, so if we've got a context which already provides the correct `TypingEnv`, using that is easier.
2026-10-09 22:07:09 +02:00
Guillaume Gomez
9b9dff9b77 Merge commit 'b011f71e23302b6c387a91e3bed7704e6ea53d7a' into HEAD 2026-10-08 21:20:35 +02:00
Jonathan Brouwer
1ee201c276 Rollup merge of #162758 - bjorn3:pass_mode_indirect_unsized, r=beetrees
Split PassMode::IndirectUnsized out of PassMode::Indirect

This prevents nonsensical combinations like unsized+on_stack and forces all users to explicitly handle the difference between sized and unsized arguments. In a couple of places unsized arguments were handled incorrectly if they would ever manage to reach that code.
2026-10-08 08:55:36 +02:00
Jonathan Brouwer
dfca88b125 Rollup merge of #162741 - dianqk:codegen-discriminants-cast, r=saethlin
codegen: tell LLVM that the discriminant is a power of two

Fixes https://github.com/rust-lang/rust/issues/162513.

We should not disable the pattern in MatchBranchSimplification. The two forms exhaustive match and cast are equivalent, but the cast is better represented in MIR: no branches, only one statement.

AFAIK, LLVM does not handle multiple disjoint intervals well. As an workaround, the patch emits `assume(ctpop(val) == 1)` to tell LLVM that the discriminant is a power of two.

LLM disclosure: search the codebase and fix grammer.
2026-10-08 08:55:35 +02:00
dianqk
23fa0f40cf codegen: tell LLVM that the discriminant is a power of two
We should not disable the pattern in MatchBranchSimplification.
The two forms exhaustive match and cast are equivalent, but the cast is better represented in MIR: no branches, only one statement.

AFAIK, LLVM does not handle multiple disjoint intervals well.
As an workaround, the patch emits `assume(ctpop(val) == 1)` to tell LLVM that
the discriminant is a power of two.
2026-10-07 22:44:29 +08:00
Folkert de Vries
3f3f4f05d3 add Float::PpcF128 and RegKind::PpcF128 2026-10-07 00:18:37 +02:00
Jonathan Brouwer
762d317361 Rollup merge of #163533 - Kobzol:cg-gcc-tests, r=bjorn3
Run cg_gcc tests with the correct compiler

Seems like we have been running the tests with the stage 0 compiler all along :surprised: The tests crash with:
```
[BUILD] mini_core
[BUILD] example
[AOT] mini_core_hello_world
warning: the feature `never_type` has been stable since 1.101.0-dev and no longer requires an attribute to enable
 --> example/mini_core_hello_world.rs:4:44
  |
4 |     no_core, unboxed_closures, lang_items, never_type, linkage,
  |                                            ^^^^^^^^^^
  |
  = note: `#[warn(stable_features)]` on by default

thread 'rustc' (1671953) panicked at compiler/rustc_codegen_ssa/src/mir/rvalue.rs:1114:5:
assertion `left == right` failed
  left: __int8_t *  __attribute__((aligned(8)))
 right: void *
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/cbae9b4cae2b108f6a3d18cfe6075714bb739463/library/std/src/panicking.rs:679:5
   1: core::panicking::panic_fmt
             at /rustc/cbae9b4cae2b108f6a3d18cfe6075714bb739463/library/core/src/panicking.rs:80:14
   2: core::panicking::assert_failed_inner
             at /rustc/cbae9b4cae2b108f6a3d18cfe6075714bb739463/library/core/src/panicking.rs:452:17
   3: core::panicking::assert_failed::<gccjit::types::Type, gccjit::types::Type>
             at /rustc/cbae9b4cae2b108f6a3d18cfe6075714bb739463/library/core/src/panicking.rs:407:5
   4: transmute_scalar<rustc_codegen_gcc::builder::Builder>
   5: codegen_transmute_operand<rustc_codegen_gcc::builder::Builder>
             at /home/bjorn/rust/compiler/rustc_codegen_ssa/src/mir/rvalue.rs:419:21
   6: codegen_rvalue_operand<rustc_codegen_gcc::builder::Builder>
             at /home/bjorn/rust/compiler/rustc_codegen_ssa/src/mir/rvalue.rs:625:30
   7: codegen_statement<rustc_codegen_gcc::builder::Builder>
             at /home/bjorn/rust/compiler/rustc_codegen_ssa/src/mir/statement.rs:37:52
```

I'll need help with resolving that from the cg_gcc side (CC @antoyo).

Fixes: https://github.com/rust-lang/rust/issues/163527
2026-10-04 21:28:21 +02:00
Jakub Beránek
c3bee7bbb1 Pass -Zforce-unstable-if-unmarked when building cg_gcc's minitests 2026-10-04 13:34:20 +02:00
lcnr
b6d09f9517 replacefully_monomorphized with cx.typing_env() 2026-10-04 11:42:25 +02:00
Trevor Gross
e9b0eeb99d intrinsics: Rename abort to abort_immediate
The semantics of `intrinsics::abort()` are closer to what we have
unstably as `abort_immediate()` than to `process::abort()` or
`libc::abort()`. Rename it to make more clear that the intrinsic is more
of an intentional crash with platform-specific behavior than what
`libc::abort()` tries to be (i.e. raising `SIGABRT`).
2026-10-02 18:56:41 +00:00
bors
a5c10c3912 Auto merge of #163609 - JonathanBrouwer:rollup-VGVBPvm, r=JonathanBrouwer
Rollup of 20 pull requests

Successful merges:

 - rust-lang/rust#163483 (Bump bootstrap compiler to 1.100.0 beta)
 - rust-lang/rust#161380 (only rerun const eval in next-solver if the const actually references opaques)
 - rust-lang/rust#162900 (Some refactorings around metadata encoding)
 - rust-lang/rust#163461 (Improve diagnostic deduplication)
 - rust-lang/rust#163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - rust-lang/rust#163584 ([triagebot] Ping me for debugger visualizer changes)
 - rust-lang/rust#159021 (windows-gnu: enable native TLS)
 - rust-lang/rust#161467 (wfcheck: name the item that discards an unused type parameter)
 - rust-lang/rust#162618 (trait_selection: Preserve eager normalization failures)
 - rust-lang/rust#162904 (Fix ICE for ambiguous candidates on method probing)
 - rust-lang/rust#163064 (Avoid computing overflowed goal chains for crate dependencies)
 - rust-lang/rust#163281 (Add `f16` inline ASM support to `spirv.rs`)
 - rust-lang/rust#163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - rust-lang/rust#163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - rust-lang/rust#163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - rust-lang/rust#163405 (Remove some #[linkage] options)
 - rust-lang/rust#163530 (`const impl PartialEq` for `f16b`)
 - rust-lang/rust#163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - rust-lang/rust#163590 (Make `AllocatorNightly` less clever)
 - rust-lang/rust#163599 (Add union pattern reference change to relnotes)
2026-10-02 01:56:57 +00:00
Philipp Krones
3c02ed033b Allow unresolvable names in cg_gcc/clippy.toml
The `disallowed-method` lint gave:

    `gccjit::types::Type::add_attribute` does not refer to a reachable function

because this function is behind a `cfg` gate and is not always
available.
2026-10-01 16:05:07 +02:00
bjorn3
d731edabc0 Remove #[linkage = "common"]
A common definition is like a weak definition except that it must be a
zero-initialized static and when merging two common symbols with the
same name, the size and alignment are set to the higher of both symbols.
This is used for tentative definitions in C and doesn't have any reason
to exist outside of that. This behavior doesn't work across dylibs and
common symbols have inconsistent behavior across linkers [1]. It is also
fragile to rely on getting the largest size of all common symbol
definitions as a (possibly smaller) global definition can override it.

Link: https://maskray.me/blog/all-about-common-symbols [1]
2026-09-30 16:59:42 +02:00
bjorn3
6d02b772e3 Remove #[linkage = "external"]
Rustc already defaults to this for #[no_mangle]/#[export_name] items.
There is no reason to explicitly use it.
2026-09-30 16:59:28 +02:00
bjorn3
7c35df5fd9 Remove #[linkage = "internal"]
Rustc already defaults to this for regular items whenever possible.
Overriding it would only lead to linker errors. And for
depending on the exact codegen unit partitioning rustc uses, so there it
is a bad idea to use it too.
2026-09-30 16:59:27 +02:00
Jakub Beránek
c7e5a82943 Add rustc_private to cg_gcc examples 2026-09-30 12:10:33 +02:00
Guillaume Gomez
71d1c023c1 Merge commit '8c858fb5fbb077eaa776302b9601cf084f12aa46' into HEAD 2026-09-29 22:21:49 +02:00
Jonathan Brouwer
1c87a25d83 Rollup merge of #163250 - mejrs:hir_imports3, r=JonathanBrouwer
Remove rustc_hir's attribute re-exports

Followup to https://github.com/rust-lang/rust/pull/160336, see also rust-lang/rust#163170, rust-lang/rust#163207 and rust-lang/rust-clippy/pull/17714

Very minor touchups here and there, nothing involving code changes.

r? @JonathanBrouwer
2026-09-27 18:58:12 +02:00
mejrs
564f208ba9 compiler: remove rustc_hir attr re-exports 2026-09-25 18:39:43 +02:00
Ariel Ben-Yehuda
c6dc51196d address comments by bjorn3 2026-09-25 15:17:18 +03:00
Ariel Ben-Yehuda
5237e38fdd Support -Z merge-functions with gcc and add stack-protector asm tests
This is a part of the stack-protector work.

Adding support for merge-functions is not strictly needed, but it does
prevent breakage if the GCC function merging logic changes.

Not adding tests for -Z merge-functions since I don't see any such tests for the
LLVM side of it.
2026-09-25 15:17:18 +03:00
Guillaume Gomez
8a11b818eb Merge commit 'ffb7eef504d4d9507583825e8e411d283c4e357e' 2026-09-24 13:00:28 +02:00
bjorn3
483372d915 Split PassMode::IndirectUnsized out of PassMode::Indirect
This prevents nonsensical combinations like unsized+on_stack and forces
all users to explicitly handle the difference between sized and unsized
arguments. In a couple of places unsized arguments were handled
incorrectly if they would ever manage to reach that code.
2026-09-24 11:58:45 +02:00
Flakebi
039b8bcadc Add address_space and byref to abi PassMode::Indirect
Both will be used by the amdgpu target to implement the `gpu-kernel`
ABI.

`address_space` specifies the address space of an indirect argument.

`AmdgpuKernelArg` translates to LLVM’s byref, which is similar to
on_stack/byval, however, there is no extra copy made, the pointer may
not point to the stack but can point to some other address space, and
the passed argument should not be modified.

byval and byref are mutually exclusive, so change on_stack to an enum
with the new states, Pointer (none), OnStack and AmdgpuKernelArg.
2026-09-23 09:56:28 +02:00
James Barford-Evans
af2f1f375c use ConstExt for methods that do not yet exist in rustc_type_ir 2026-09-22 13:04:44 +01:00
bors
c64de18c55 Auto merge of #162499 - GuillaumeGomez:subtree-update_cg_gcc_2026-09-08, r=antoyo
`rustc_codegen_gcc` subtree update



r? antoyo
2026-09-22 08:08:25 +00:00
James Barford-Evans
c56a9917d8 Wire up f16b in backends 2026-09-21 08:57:52 +01:00
Guillaume Gomez
cf4bee6837 Remove forgotten file 2026-09-18 22:52:45 +02:00
Guillaume Gomez
c10c4cf936 Fix source code divergence 2026-09-18 20:56:48 +02:00
Guillaume Gomez
f5965de6c2 Merge commit '39f626bc72757517b75d8e2dde50fa832b8d6c03' 2026-09-18 20:51:24 +02:00
Nicholas Nethercote
8515e12560 Remove global_backend_features query
It's now possible to get the backend features (a `Vec<String>`) when the
codegen backend is started, pass it back through `CodegenBackendInit`,
and just store it in the `Session`. This removes the need for the query.

Also:

- `WriteBackendMethods::target_machine_factory` no longer needs the
  `target_features` parameter, because it's now available through the
  `sess` parameter.

- `CodegenContext` no longer needs the `backend_features` field because
  we can use `sess.global_backend_features` instead.

- `CodegenBackend::provide` is now a no-op for all the in-tree backends.
  I haven't removed it because out-of-tree backends still rely on it.
2026-09-16 15:29:44 +10:00
Nicholas Nethercote
81210c9d79 Change CodegenBackend::init to take &mut self
It currently takes `&self`, which is a bit strange for an `init` method.
As a result, the Cranelift and GCC backends have to use types with
interior mutability.

This commit changes it to `&mut self`. Benefits:

- The Cranelift backend can use `Option` instead of `OnceCell` to
  indicate uninit vs. init.

- The GCC backend can avoid `Mutex`, and use `bool` instead of
  `AtomicBool`, which makes things much simpler. The commit also
  restructures `GccCodegenBackend` to mirror `CraneliftCodegenBackend`:
  just contain an `Option<BackendConfig>`, which makes the uninit vs.
  init distinction foolproof. (E.g. no need to set `lto_supported` to
  false and then later overwrite it with the real value.) As part of
  this the `LockedTargetInfo` type is renamed `SharedTargetInfo` because
  that better matches its new internals. (All this compiles both with
  and without the "master" feature set.)
2026-09-16 15:29:44 +10:00
Nicholas Nethercote
51673f89e1 Split build_session
Session creation is currently awkward: we build a mostly-initialized
session, then use it to initialize a codegen backend, and then use the
codegen backend to finish initializing the session.

And it's not just awkward: within the Cranelift backend's `init` method
`sess.lto()` is called, which consults `sess.thin_lto_supported`,
*before* that field has been properly set! In practice it had no effect
but it's worth fixing.

This commit cleans up this mess. It introduces `EarlySession`, which
contains just four `Session` fields, the ones that are needed for
codegen backend initialization. It is now a field within `Session`, and
`Session` derefs to `EarlySession` to avoid changing a zillion
`sess.target`/`sess.opts`/etc. occurrences. `EarlySession` is passed to
`init`, which returns a `CodegenBackendInit` that contains the
backend-specific information needed to build a `Session`. (It replaces
the `replaced_intrinsics`, `fallback_intrinsics`, and
`thin_lto_supported` methods.) The `Session` can then be built in a
single step. No more `Session`/`CodegenBackend` initialization
intermingling.

A few functions that previously took a `Session` now take something
else, e.g. a `Target`. Some `Session` methods are now `EarlySession`
methods. And a new `early_lto` method is used for Cranelift's LTO check.
2026-09-16 15:29:42 +10:00
mejrs
6aaabbb863 compiler: fix bug and span_bug imports 2026-09-15 16:20:18 +02:00
Jonathan Brouwer
7cd747decf Rollup merge of #160023 - antoyo:ssa-indirect-return, r=workingjubilee
Refactor the way cg_ssa handles indirect returns (returns via `sret`) — Take 2

This continues the work that @FractalFir done in rust-lang/rust#144976.

**I managed to make this work, so this confirms the original approach works and is ready to merge.**

r? workingjubilee

(assigning the same reviewer as the original PR)

# The problem

The current way `cg_ssa` handles `PassMode::Indirect` is fundamentally incompatible with the requirements of the GCC backend. This is currently worked around in a very brittle way, that breaks on ARM.

In order to function correctly, `cg_gcc` requires the `sret`(indirect return) pointer to be treated in a special way.

# The solution

This PR separates the `sret` pointer from all the other arguments, allowing each backend to decide how it wants to handle that pointer. This will allow GCC to do it's own thing, while changing nothing on the LLVM side. Currently, the PR just makes both backends preappend the sret arg, mimicking the previous behaviour.

The PR is based on this [zulip suggestion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Bootstrap.20of.20rustc.20with.20rustc_codegen_gcc/near/526487725).

# Assumptions I made.

The PR makes certain assumptions about the ABI handling.

1. No LLVM intrinsic returns via sret. [According to my sources](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Can.20LLVM.20intrinsics.20return.20via.20PassMode.3A.3AIndirect.3F), this is always true.
2. Tail calls don't currently return via `sret`. From [asking about](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Can.20tail.20calls.20return.20indirectly.28via.20a.20pointer.29.3F/near/532984507), it seems like the tail call handling does not currently support indirect returns. So, I did not add support for that.
3. TLS shims don't perform indirect returns, and asserts and drops also don't perform indirect returns(since they return nothing) - those assumptions seemed reasonable.
4. Inline assembly calls don't use indirect returns. I *assumed* functions like `inline_asm_call` will not need the `sret` handling code. I am not 100% sure about this, tough.
2026-09-11 12:45:02 +02:00
bjorn3
052ee70292 Don't rely on codegen emitting fn_abi_of_* errors in abi checks
This avoids a delayed bug if compilation is aborted between checking
function ABIs and codegening all functions.
2026-09-10 09:40:28 +02:00
Antoni Boucher
a714a9e8df Improve the new indirect return API 2026-09-09 11:29:11 -04:00
Antoni Boucher
43965ead44 Add missing indirect return argument to new calls 2026-09-09 11:28:44 -04:00
Fractal Fir(Michał Kostrubiec)
74bba56ab9 Apply suggestions from code review
Co-authored-by: Jubilee <workingjubilee@gmail.com>
2026-09-09 11:14:31 -04:00
FractalFir
e6b7dc8152 Ported cg_gcc to the new cg_ssa version 2026-09-09 11:14:31 -04:00
Jonathan Brouwer
f04af2086f Rollup merge of #160197 - susitsm:restrict-inline-asm-cookies, r=petrochenkov
Restrict LLVM inline asm location cookie usage. Fixes #150451

The parallel frontend makes the cookies nondeterministic in their current form, resulting in nondeterministic outputs when bitcode is emitted or LTO is used.

Causes minor diagnostic regression for inline asm in release builds. See rust-lang/rust#150451 for details.

Fixes rust-lang/rust#150451

r? bjorn3
2026-09-07 17:08:07 +02:00
Matyas Susits
970cb98f0e Disable inline asm line info cookies when llvm bitcode is saved or LTO is enabled
The parallel frontend makes the cookies nondeterministic in their
current form, resulting in nondeterministic outputs when bitcode is
emitted or LTO is used.

Causes minor diagnostic regression for inline asm in release builds.
2026-09-05 11:52:40 +02:00
Amanieu d'Antras
51b3f52eab Merge zreg into vreg and keep ffr in a clobber-only class 2026-09-04 13:29:17 +00:00
Reuben Cruise
7b2bfecd72 Adds support for AArch64 SVE to inline assembly
Adds new `zreg` register type and `SveVec*` variants to `InlineAsmType`
2026-09-04 13:29:17 +00:00
Jonathan Brouwer
f9090000f4 Rollup merge of #160989 - N1ark:08-12-generic-float-intrinsincs, r=folkertdev
Make sin, cos, exp, exp2, log, log2, log10 generic

Rebased and smaller version of rust-lang/rust#153934

Following `fabs`, make the `sin`, `cos`, `exp`, `exp2`, `log`, `log2` and `log10` intrinsics generic over the float type, rather than having four variants per float type.

The first two commits are purely stylistic:
- reorganised Cranelift code to make following changes simpler
- moved a misplaced comment in `compiler/rustc_codegen_llvm/src/intrinsic.rs` that caused `x fmt` to give up

The last commit actually makes them generic! Most code is a bit simpler, ~~and this will also hopefully simplify adding support for these intrinsics for the future [`bf16` type](https://github.com/rust-lang/rust/pull/160859)~~ :)

Unfortunately both GCC and Cranelift backend changes are a bit churny. Their code is a bit, opaque, to put it kindly, and I didn't want to refactor those here.

r? @folkertdev
cc @RalfJung
2026-09-01 13:27:38 +02:00
Jonathan Brouwer
1aeb21ba42 Rollup merge of #137720 - folkertdev:naked-function-target-feature, r=Amanieu
support `#[target_feature(enable = ...)]` on `#[naked]` functions

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

Instructions that are part of a target feature require a special directive on some targets. This PR adds those for the most common targets.

This is very WIP, but I'm hoping to collect some feedback on what is (not) supported and how to report that to users.

r? @ghost

cc @taiki-e @Amanieu
2026-09-01 13:27:35 +02:00
N1ark
edcae4441d Make sin, cos, exp, exp2, log, log2, log10 generic 2026-08-31 18:57:54 +01:00
Folkert de Vries
178eb4b50f attach naked function target features to module assembly 2026-08-31 00:25:34 +02:00