Commit Graph

848 Commits

Author SHA1 Message Date
Jacob Pratt
31e12ee467 Rollup merge of #160124 - scottmcm:simd-count, r=oli-obk
Structurally prevent zero-count `BackendRepr::SimdVector`s

This is already *supposed* to be impossible in layout, but this emphasizes that better.  This PR makes no behaviour changes; just `BackendLaneCount` instead of `u64` in https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/enum.BackendRepr.html

Ironically I was inspired to do this as part of [looking at making `Simd<T, 0>` *work*](https://rust-lang.zulipchat.com/#narrow/channel/257879-project-portable-simd/topic/Allow.20N.3D.3D0.3F/with/613345298), but importantly if that's going to happen I think it should be `BackendRepr::Memory` like other ZSTs, *not* a `BackendRepr::ScalarVector` that would need to carry around a useless LLVM value in `OperandValue::Immediate` (where it's not even clear what the LLVM type of that value would be).
2026-07-31 22:25:12 -04:00
Scott McMurray
6da3077db9 Structurally prevent zero-count BackendRepr::SimdVectors
This is already *supposed* to be impossible in layout, but this emphasizes that better.

Ironically I was inspired to do this as part of looking at making `Simd<T, 0>` *work*, but importantly if that's going to happen I think it should be `BackendRepr::Memory` like other ZSTs, *not* a `BackendRepr::ScalarVector` that would need to carry around a useless LLVM value in `OperandValue::Immediate` (where it's not even clear what the LLVM type of that value would be).
2026-07-30 19:48:24 -07:00
Jacob Pratt
504ee5c04b Rollup merge of #160148 - GuillaumeGomez:rename-errors, r=JonathanBrouwer
Rename `errors.rs` file to `diagnostics.rs` (15/N)

Follow-up of https://github.com/rust-lang/rust/pull/157485.

r? @JonathanBrouwer
2026-07-29 20:48:22 -04:00
Guillaume Gomez
31918e4edd Rename rustc_codegen_gcc/errors.rs into rustc_codegen_gcc/diagnostics.rs 2026-07-29 14:18:32 +02:00
Mike Hommey
7158341ec7 Revert "codegen: add OperandValue::Uninit to skip stores for entirely-uninit constants"
This reverts commit ed9de1e466.
2026-07-28 18:47:39 +09:00
Jacob Pratt
0e238fd6c3 Rollup merge of #138618 - nbdd0121:asm_const_ptr, r=bjorn3
Support using const pointers in asm `const` operand

Implements [RFC#3848](https://github.com/rust-lang/rfcs/pull/3848) with tracking issue rust-lang/rust#128464

This adds support of const pointers for asm `const` in addition to plain integers.

The inline `asm!` support is implemented using `i` constraint, and the `global_asm!` and `naked_asm!` support is implemented by inserting `symbol + offset` and make `symbol` compiler-used. For unnamed consts, it will create additional internal & hidden symbols so that they can be referenced by global_asm.

~~The feature is also implemented for GCC backend but it's untested.~~ Tested now.
2026-07-26 00:21:39 -04:00
Gary Guo
c95d35e96f Generate unique symbol names if const pointers refer to promoted static 2026-07-22 14:34:42 +01:00
Gary Guo
338d560eaf Handle pointers with offset for asm const 2026-07-22 13:47:31 +01:00
Gary Guo
4c39d62eb9 Unify handling of GlobalAlloc inside backend
With the previous commit, now we can see there are some code duplication
for the handling of `GlobalAlloc` inside backends. Do some clean up to
unify them.
2026-07-22 13:47:31 +01:00
Gary Guo
ca4033987e Unify handling of asm const and sym using CTFE
This gives the asm-const code the basic ability to deal wiht pointer and
provenances, which lays the ground work for asm_const_ptr.

Note that `SymStatic` is not fully removed, a specialized is kept and
renamed as `SymThreadLocalStatic`, for `#[thread_local]` statics where CTFE
does not support naming. The `#[thread_local]` is unstable feature and it's
not clear if we want to support this in `sym`, but removal of it should be
a separate PR.
2026-07-22 13:47:31 +01:00
Gary Guo
b44bea2b5d Delay stringification of const to backend 2026-07-22 13:47:31 +01:00
Mike Hommey
ed9de1e466 codegen: add OperandValue::Uninit to skip stores for entirely-uninit constants
MIR GVN propagates MaybeUninit::uninit() as `const <uninit>` in aggregate
constructions and codegen emits a memcpy from an `[N x i8] undef` global for
each such field, which LLVM materializes as zero-initialization.

Instead of special-casing `all_bytes_uninit` at each call site, add a new
`OperandValue::Uninit` variant that `eval_mir_constant_to_operand` returns for
any all-bytes-uninit constant. `store_with_flags` is a no-op for this variant,
so the fix applies uniformly across `Rvalue::Use`, `Rvalue::Repeat`, and
`Rvalue::Aggregate` without per-site checks. The variant propagates through
field extraction and transmutes, and is handled appropriately at the remaining
call sites (function arguments, discriminant reads, debug info, etc.).
2026-07-21 11:46:36 +09:00
Jonathan Brouwer
8e9fb78173 Rollup merge of #150732 - kulst:cpu_is_target_modifier, r=bjorn3
Convert `-Ctarget-cpu` into a target-modifier for AVR, AMDGCN and NVPTX

Crates built for AVR, AMDGCN and NVPTX that specify different values for `-Ctarget-cpu` cannot be soundly linked together.
This PR attempts to make `rustc` ensure that no crates with disagreeing values for `-Ctarget-cpu` are linked together. This is achieved by converting `-Ctarget-cpu` into a target-modifier depending on `--target`.
To do this, the consistency check for `-Ctarget-cpu` considers mismatching values as inconsistent only for targets for which the new flag `requires_consistent_cpu` is set in their target spec.

**Why should `-Ctarget-cpu` be a target-modifier for `nvptx`?**
<details><summary>PTX is a single-module contract</summary>
<p>
PTX requires a binary to start with .version (`ptx$$`) then .target (`sm_$$`). If the ptx contains instructions that are not supported by either .version or .target, the binary is ill-formed and will be rejected by ptxas. The concept of features that can be mixed and matched in a binary does not exist for nvptx and is therefore not supported by LLVM.
</p>
</details>

<details><summary>It prevents the production of bitcode that cannot be codegen'd after linking</summary>
<p>
A target modifier should prevent configurations that are not composable across crates when those crates are linked together. The most prominent example is when enabling a target feature changes the ABI, making cross-crate calls inherently unsound.

In the case of nvptx, ABI mismatch is (at least for now) not the core problem motivating target modifiers. NVIDIA’s documented PTX calling convention has [remained stable since ptx20](https://docs.nvidia.com/cuda/ptx-writers-guide-to-interoperability/index.html#function-calling-sequence).

However, in the current state it is possible to produce bitcode that cannot be codegen'd after linking, because some operations are only lowerable for sufficiently new SM/PTX levels. In the best case this results in an LLVM error during the final llc step, but this is not something we should rely on for correctness.

nvptx has a special compilation pipeline where instead of linking the final PTX object, instead LLVM bitcode is linked. The resulting artifact is then compiled in one invocation.
Now consider crate A which is independently compiled into bitcode with the following rustc arguments:

```Rust
//@ compile-flags: --target nvptx64-nvidia-cuda -C target-cpu=sm_70 --crate-type=rlib
#[cfg(target_feature = "sm_70")]
fn foo() {
    // cannot be lowered to ptx before "sm_70: so currently produces an LLVM error
}
#[cfg(not(target_feature = "sm_70"))]
fn foo() {
    // can be lowered to ptx before "sm_70"
}
pub fn bar() {
    foo()
}
```
Crate A is a dependency of crate B. In the *rustc* invocation of crate B
1. crate B is compiled into bitcode, too
2. both bitcode artifacts are bitcode-linked by *llvm-link*
3. the resulting bitcode artifact is compiled by *llc -mcpu=sm_60*

This should now ideally create an LLVM error, because the linked bitcode contains code paths that were selected under `sm_70` assumptions but the final NVPTX codegen is targeting `sm_60`, where those operations are not lowerable. An LLVM error here is better than silent miscompilation, but it’s not a promise we should rely on.

A real example where this could happen is the lowering of atomic loads and stores with non-relaxed orderings, which is known to depend on the selected SM level.
</p>
</details>

**Why should `-Ctarget-cpu` be a target-modifier for `amdgcn` and `avr`?**
- In case of AVR the target-cpu defines the ISA, which is encoded in the ELF header flags, amdgcn also encodes the cpu directly into those flags
- To not rely on *lld* which currently prevents it for both by looking at those flags [AVR](597ffbe09d/lld/test/ELF/avr-flags.s) and [amdgcn](597ffbe09d/lld/test/ELF/amdgpu-elf-flags-err.s)

Previous discussions about the topic can be found [here](https://github.com/rust-lang/rust/issues/131799#issuecomment-3390563329) and [here](https://github.com/rust-lang/rust/issues/141468).

I also created a [Zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Making.20-Ctarget-cpu.20a.20target-modifier.20on.20NVPTX/with/566622679).

I am unsure if a MCP is needed before proceeding. If you think so please let me know.

Creating *target-modifiers* for NVPTX *target-features* is to be done in a follow-up.

cc @kjetilkjeka as target maintainer for NVPTX
cc @flakebi as target maintainer for amdgcn
cc @Patryk27 as target maintainer for AVR
cc @RalfJung you were very involved in the discussions so far

Target modifier tracking issue: https://github.com/rust-lang/rust/issues/136966
2026-07-19 23:26:25 +02:00
Jacob Pratt
4200fb100f Rollup merge of #159164 - scottmcm:remove-is-backend-blah, r=workingjubilee
[cg_ssa] Eliminate the `is_backend_{immediate,scalar_pair,ref}` methods

These methods are just mostly just matches on [`BackendRepr`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/enum.BackendRepr.html) now, which makes then not not very valuable.  Notably, `cg_clif` gets along just fine without them.  In general, it's much nicer to match on `BackendRepr` than to use an `if`-`else` chain of `is_zst`+`is_backend_immediate`+`is_backend_scalar_pair`.

And having them be on `LayoutTypeCodegenMethods` means you need a context to use them, making it more annoying to use them in things like [`OperandValue::is_expected_variant_for_type`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/mir/operand/enum.OperandValue.html#method.is_expected_variant_for_type).

So this just removes them, as well as the `is_llvm_*` and `is_gcc_*` versions.

How I migrated callers:
- `is_backend_ref` becomes a (logical-not-ed) call to a new `.is_ssa_standalone()` method.  (Better name suggestions welcome for this one.  I wanted something to hopefully phrase intent better and positively.)
- `is_backend_immediate` becomes a call to `.backend_repr.is_scalar_or_simd()`.
- `is_backend_scalar_pair` becomes a pattern-match against `BackendRepr::ScalarPair { .. }`.
- some places that used multiples just became a match over `BackendRepr`.

The intent is that this has zero impact on the codegen.  It should be a refactor only.

r? codegen
2026-07-17 23:33:30 -04:00
kulst
76d5107658 Treat -Ctarget-cpu as a target-modifier when targeting AVR, AMDGCN and NVPTX
For AVR, AMDGCN, and NVPTX, crates built with different target CPU values are
not generally link-compatible.

Add a `requires_consistent_cpu` flag to the target spec and enable it for these
targets. When the flag is set, treat `-Ctarget-cpu` as a target modifier and
require all linked crates to agree on its value.

Reject `-Ctarget-cpu=native` before codegen for targets that set
`requires_consistent_cpu` to true. Also do not include `native` in the printed
`target-cpus` list for such targets.

Add tests covering:
- which built-in targets set `requires-consistent-cpu`
- cross-crate behavior with and without `requires-consistent-cpu`
- that an omitted `-Ctarget-cpu` compares equal to an explicitly specified
  default CPU
- rejection and printing behavior for `native`
- precedence of repeated `-Ctarget-cpu` flags in metadata comparison and LLVM IR
2026-07-17 15:46:00 +02:00
Guillaume Gomez
db1695d47e Update uses of rustc_codegen_ssa::errors 2026-07-15 17:23:13 +02:00
Jakub Chlanda
00f9612daf Document -Zpointer-authentication option 2026-07-14 09:13:12 +00:00
Jakub Chlanda
abd56e9039 Pointer authentication config and user facing options
This patch brings:
* unified handling of pointer authentication options through:
  `-Zpointer-authentication`, with possible values:
  `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`,
  `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`,
  `init-fini-address-discrimination`, `return-addresses`. Toggled with
  `+`/`-`.
* centralized handling of pointer authentication features. Session holds
  `pointer_auth_config: Option<PointerAuthConfig>`
* encapsulation of schema for function pointers and init/fini through
  `PointerAuthSchema`. This allowed for retiring of `PacMetadata`.
* refactor enabling of pointer authentication in code, instead of
  relying on the target (`pauthtest`) use the session
2026-07-14 08:48:56 +00:00
Scott McMurray
d93df7f412 [cg_ssa] Eliminate the is_backend_{immediate,scalar_pair,ref} methods 2026-07-11 21:42:19 -07:00
Jacob Pratt
731d820cde Rollup merge of #158899 - scottmcm:better-volatile-store, r=saethlin
Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`

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

There seems to be no reason to have this flag at all, as anything that wants it should just adjust the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/mir/place/struct.PlaceValue.html#structfield.align instead.

r? codegen
2026-07-10 02:49:30 -04:00
Scott McMurray
2efdc665a7 Carry the b_offset inside BackendRepr::ScalarPair 2026-07-07 01:15:36 -07:00
Scott McMurray
9116f7db7b Fix unaligned_volatile_store by removing MemFlags::UNALIGNED 2026-07-07 00:41:13 -07:00
Jacob Pratt
95adef7b5c Rollup merge of #158364 - heiher:loong-asm-simd, r=wesleywiser
rustc_target/asm: add LoongArch LSX/LASX inline asm register support

Add support for LoongArch LSX and LASX registers in inline assembly by introducing the `vreg` and `xreg` register classes, along with their associated vector types and operand modifiers. The new register classes are gated behind the `asm_experimental_reg` feature. Also model the overlap between FPU, LSX, and LASX registers so register conflict checking works correctly for aliased registers.
2026-07-01 17:42:28 -04:00
Jacob Pratt
9272c6d92a Rollup merge of #158542 - scottmcm:scalar-but-packed, r=workingjubilee
Rename `align` to `default_align` on `Scalar` and `Primitive`

To emphasize that just because you see a `Scalar(I32)` that doesn't really tell you anything about the alignment it has -- one should be looking at the type (well, the place) for that.

(The `size` method doesn't really have that problem -- i32 is always 4 bytes, no matter the context -- so is left untouched.)

No actual layout or behaviour changes in *this* PR.  Just the rename and some comments.

r? @workingjubilee
2026-07-01 01:03:18 -04:00
Jonathan Brouwer
d1462c2ed4 Rollup merge of #158560 - bjorn3:ssa_refactor_debuginfo, r=Kivooeo
Move per-function debuginfo methods from codegen to builder methods

In cg_clif the debuginfo for the function we are currently codegening is stored in `FunctionDebugContext`, which is stored in the `FunctionCx`, not in the per-cgu `DebugContext`.
2026-06-30 12:58:24 +02:00
Jonathan Brouwer
67b5ab7707 Rollup merge of #155722 - jchlanda:jakub/pac, r=davidtwco
Introduce aarch64-unknown-linux-pauthtest target

This target enables Pointer Authentication Code (PAC) support in Rust on AArch64
ELF-based Linux systems. It uses the `aarch64-unknown-linux-pauthtest` LLVM
target and a pointer-authentication-enabled sysroot with a custom musl as a
reference libc implementation. Dynamic linking is required, with a dynamic
linker acting as the ELF interpreter that can resolve pauth relocations and
enforce pointer authentication constraints.

### Supported features include:
* authentication of signed function pointers for extern "C" calls (corresponds
  to LLVM's `-fptrauth-calls`)
* signing of return addresses before spilling to the stack and authentication
  after restoring for non-leaf functions (corresponds to `-fptrauth-returns`)
* trapping on authentication failure when the FPAC feature is not present
  (corresponds to `-fptrauth-auth-traps`)
* signing of init/fini array entries using the LLVM-defined pointer
  authentication scheme (corresponds to `-fptrauth-init-fini` and
  `-fptrauth-init-fini-address-discrimination`)
* non-ABI-affecting indirect control-flow hardening features as implemented in
  LLVM (corresponds to `-faarch64-jump-table-hardening` and
  `-fptrauth-indirect-gotos`)
* signed ELF GOT entries (gated behind `-Z ptrauth-elf-got`, off by default)

Existing compiler support, such as enabling branch authentication instructions
(i.e.: `-Z branch-protection`) provide limited functionality, mainly signing
return addresses (`pac-ret`). The new target goes further by enabling ABI-level
pointer authentication support.

This target does not define a new ABI; it builds on the existing C/C++ language
ABI with pointer authentication support added. However, different authentication
features, encoded in the signing schema, are not ABI-compatible with one
another.

### Useful links:
* Earlier PR: https://github.com/rust-lang/rust/pull/154759
* Part of: https://github.com/rust-lang/rust/issues/148640
* Project goal: https://rust-lang.github.io/rust-project-goals/2026/aarch64_pointer_authentication_pauthtest.html
* Clang pointer authentication documentation:
  https://clang.llvm.org/docs/PointerAuthentication.html
* LLVM pointer authentication documentation:
  https://llvm.org/docs/PointerAuth.html
* PAuth ABI Extension to ELF for the AArch64 architecture:
  https://github.com/ARM-software/abi-aa/blob/main/pauthabielf64/pauthabielf64.rst

### Tier 3 check list
> - A tier 3 target must have a designated developer or developers (the "target
>   maintainers") on record to be CCed when issues arise regarding the target.
>   (The mechanism to track and CC such developers may evolve over time.)

I pledge to do my best maintaining it.

> - Targets must use naming consistent with any existing targets; for instance, a
>   target for the same CPU or OS as an existing Rust target should use the same
>   name for that CPU or OS. Targets should normally use the same names and
>   naming conventions as used elsewhere in the broader ecosystem beyond Rust
>   (such as in other toolchains), unless they have a very good reason to
>   diverge. Changing the name of a target can be highly disruptive, especially
>   once the target reaches a higher tier, so getting the name right is important
>   even for a tier 3 target.

The name chosen for the target is `aarch64-unknown-linux-pauthtest` which
mirrors the [LLVM target naming](https://github.com/llvm/llvm-project/blob/main/llvm/unittests/TargetParser/TripleTest.cpp#L1407).

>   - Target names should not introduce undue confusion or ambiguity unless
>     absolutely necessary to maintain ecosystem compatibility. For example, if
>     the name of the target makes people extremely likely to form incorrect
>     beliefs about what it targets, the name should be changed or augmented to
>     disambiguate it.

There should be no confusion, the name follows naming convention and is
descriptive.

>   - If possible, use only letters, numbers, dashes and underscores for the name.
>     Periods (`.`) are known to cause issues in Cargo.

Letters, numbers and dashes only.

> - Tier 3 targets may have unusual requirements to build or use, but must not
>   create legal issues or impose onerous legal terms for the Rust project or for
>   Rust developers or users.

The target requires system `clang` and `lld` available as well as custom libc
([musl](https://github.com/access-softek/musl) based) and sysroot, provided [through the build scripts](https://github.com/access-softek/pauth-toolchain-build-scripts/tree/master).

>   - The target must not introduce license incompatibilities.

There are no license implications.

>   - Anything added to the Rust repository must be under the standard Rust
>     license (`MIT OR Apache-2.0`).

Understood.

>   - The target must not cause the Rust tools or libraries built for any other
>     host (even when supporting cross-compilation to the target) to depend
>     on any new dependency less permissive than the Rust licensing policy. This
>     applies whether the dependency is a Rust crate that would require adding
>     new license exceptions (as specified by the `tidy` tool in the
>     rust-lang/rust repository), or whether the dependency is a native library
>     or binary. In other words, the introduction of the target must not cause a
>     user installing or running a version of Rust or the Rust tools to be
>     subject to any new license requirements.

There are no new dependencies or requirements.

>   - Compiling, linking, and emitting functional binaries, libraries, or other
>     code for the target (whether hosted on the target itself or cross-compiling
>     from another target) must not depend on proprietary (non-FOSS) libraries.
>     Host tools built for the target itself may depend on the ordinary runtime
>     libraries supplied by the platform and commonly used by other applications
>     built for the target, but those libraries must not be required for code
>     generation for the target; cross-compilation to the target must not require
>     such libraries at all. For instance, `rustc` built for the target may
>     depend on a common proprietary C runtime library or console output library,
>     but must not depend on a proprietary code generation library or code
>     optimization library. Rust's license permits such combinations, but the
>     Rust project has no interest in maintaining such combinations within the
>     scope of Rust itself, even at tier 3.

The target only relies on open source tools.

>   - "onerous" here is an intentionally subjective term. At a minimum, "onerous"
>     legal/licensing terms include but are *not* limited to: non-disclosure
>     requirements, non-compete requirements, contributor license agreements
>     (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms,
>     requirements conditional on the employer or employment of any particular
>     Rust developers, revocable terms, any requirements that create liability
>     for the Rust project or its developers or users, or any requirements that
>     adversely affect the livelihood or prospects of the Rust project or its
>     developers or users.

No such terms present.

> - Neither this policy nor any decisions made regarding targets shall create any
>   binding agreement or estoppel by any party. If any member of an approving
>   Rust team serves as one of the maintainers of a target, or has any legal or
>   employment requirement (explicit or implicit) that might affect their
>   decisions regarding a target, they must recuse themselves from any approval
>   decisions regarding the target's tier status, though they may otherwise
>   participate in discussions.

Understood.

>   - This requirement does not prevent part or all of this policy from being
>     cited in an explicit contract or work agreement (e.g. to implement or
>     maintain support for a target). This requirement exists to ensure that a
>     developer or team responsible for reviewing and approving a target does not
>     face any legal threats or obligations that would prevent them from freely
>     exercising their judgment in such approval, even if such judgment involves
>     subjective matters or goes beyond the letter of these requirements.

Understood.

> - Tier 3 targets should attempt to implement as much of the standard libraries
>   as possible and appropriate (`core` for most targets, `alloc` for targets
>   that can support dynamic memory allocation, `std` for targets with an
>   operating system or equivalent layer of system-provided functionality), but
>   may leave some code unimplemented (either unavailable or stubbed out as
>   appropriate), whether because the target makes it impossible to implement or
>   challenging to implement. The authors of pull requests are not obligated to
>   avoid calling any portions of the standard library on the basis of a tier 3
>   target not implementing those portions.

`aarch64-unknown-linux-pauthtest target` has std library support, moreover all
`library` tests pass for the target.

> - The target must provide documentation for the Rust community explaining how
>   to build for the target, using cross-compilation if possible. If the target
>   supports running binaries, or running tests (even if they do not pass), the
>   documentation must explain how to run such binaries or tests for the target,
>   using emulation if possible or dedicated hardware if necessary.

Platform support document covers building instructions.

> - Tier 3 targets must not impose burden on the authors of pull requests, or
>   other developers in the community, to maintain the target. In particular,
>   do not post comments (automated or manual) on a PR that derail or suggest a
>   block on the PR based on a tier 3 target. Do not send automated messages or
>   notifications (via any medium, including via `@`) to a PR author or others
>   involved with a PR regarding a tier 3 target, unless they have opted into
>   such messages.

Understood.

>   - Backlinks such as those generated by the issue/PR tracker when linking to
>     an issue or PR are not considered a violation of this policy, within
>     reason. However, such messages (even on a separate repository) must not
>     generate notifications to anyone involved with a PR who has not requested
>     such notifications.

Understood.

> - Patches adding or updating tier 3 targets must not break any existing tier 2
>   or tier 1 target, and must not knowingly break another tier 3 target without
>   approval of either the compiler team or the maintainers of the other tier 3
>   target.

Understood.

>   - In particular, this may come up when working on closely related targets,
>     such as variations of the same architecture with different features. Avoid
>     introducing unconditional uses of features that another variation of the
>     target may not have; use conditional compilation or runtime detection, as
>     appropriate, to let each target run code supported by that target.

Understood.

> - Tier 3 targets must be able to produce assembly using at least one of
>   rustc's supported backends from any host target. (Having support in a fork
>   of the backend is not sufficient, it must be upstream.)

It is expected that the target should be able to compile binaries on any systems
that are capable of compiling `aarch64` code.
2026-06-30 03:41:22 +02:00
Scott McMurray
f98365f1f3 Rename align to platform_align on Scalar and Primitive
To emphasize that just because you see a `Scalar(I32)` that doesn't really tell you anything about the alignment it has -- one should be looking at the type (well, the place) for that.

No actual layout or behaviour changes in *this* PR.
2026-06-29 09:48:16 -07:00
bjorn3
0943c50eac Pass &mut self to all debuginfo builder methods 2026-06-29 14:21:54 +02:00
bjorn3
aa81c219de Move a couple more debuginfo functions from codegen to builder methods
These functions are scoped to a single codegened function
2026-06-29 14:21:54 +02:00
bjorn3
324705718e Move a bunch of debuginfo functions from codegen to builder methods
These functions are scoped to a single codegened function
2026-06-29 14:21:54 +02:00
bjorn3
67c85cc756 Remove debuginfo_finalize from DebugInfoCodegenMethods
It isn't called from cg_ssa.
2026-06-29 14:21:54 +02:00
Jacob Pratt
6bc6675972 Rollup merge of #158497 - folkertdev:stdarch-sync-2026-06-27, r=folkertdev
stdarch subtree update

Subtree update of `stdarch` to 62d559568a.

Created using https://github.com/rust-lang/josh-sync.

r? @ghost
2026-06-27 22:13:44 -04:00
Folkert de Vries
3515461784 use "llvm.prefetch.p0" instead of "llvm.prefetch"
LLVM updated the name, the old one still works but stdarch is now using the new one
2026-06-27 23:14:21 +02:00
Jonathan Brouwer
6fddd30dd3 Rollup merge of #157127 - scottmcm:tweak-layout-of-alternative, r=nikic
cg_LLVM: Stop needing an alloca for volatile loads

This ended up also being reimplementing it to not use `load` of the `llvm_type`, since without doing that everything blew up horribly.  cc the zulip conversation [#t-opsem > Defining volatile splitting @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/Defining.20volatile.20splitting/near/597451615).

And while I'm here, improve the tests to check that the unaligned ones are actually unaligned, since `unaligned_volatile_load::<u8>` doesn't actually test anything.

r? @nikic
cc @RalfJung
MCP tracking issue rust-lang/rust#153250
2026-06-26 20:22:19 +02:00
Jakub Chlanda
844c6f4a02 New signature of get_fn_addr, teach Rust how to sign fn pointers
Allow PAC metadata to be passed to `get_fn_addr` and related API
changes.
2026-06-26 13:23:09 +00:00
bors
eb6346c659 Auto merge of #158403 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update

r? Manishearth
2026-06-26 10:54:14 +00:00
Philipp Krones
91c04dfcad cg_gcc: Fix Clippy lint fallout 2026-06-26 10:33:49 +02:00
WANG Rui
7cddcd6fec rustc_target/asm: add LoongArch LSX/LASX inline asm register support
Add support for LoongArch LSX and LASX registers in inline assembly by
introducing the `vreg` and `xreg` register classes, along with their
associated vector types and operand modifiers. The new register classes
are gated behind the `asm_experimental_reg` feature. Also model the overlap
between FPU, LSX, and LASX registers so register conflict checking works
correctly for aliased registers.
2026-06-26 16:01:55 +08:00
Scott McMurray
9b188dd6c5 cg_LLVM: Stop needing an alloca for volatile loads
And while I'm here, improve the tests to check that the unaligned ones are actually unaligned, since `unaligned_volatile_load::<u8>` doesn't actually test anything.
2026-06-25 20:57:58 -07:00
David Wood
cfc4211b6e codegen_ssa: multiply scalable vec size by vscale
When emitting a `memcpy` for a scalable vector, the size computed by
rustc (`num_vectors * element_count * element_ty`), since
rust-lang/rust#157915, needs to be multiplied by `vscale`.
2026-06-22 15:06:35 +00:00
Jacob Pratt
fcfdcb86a3 Rollup merge of #157627 - folkertdev:remove-llvm-va_end, r=RalfJung
remove LLVM `va_end` calls

tracking issue: https://github.com/rust-lang/rust/issues/44930

The operation is a no-op, so we skip it.
2026-06-15 16:16:08 -04:00
Folkert de Vries
d297af408d remove LLVM va_end calls
The operation is a no-op, so we skip it.
2026-06-15 19:52:50 +02:00
Jacob Pratt
c454aaee6e Rollup merge of #157722 - cjgillot:ssa-create-scope-map, r=oli-obk
Move create_scope_map to rustc_codegen_ssa.

This resolves an old FIXME and allows to deduplicate code between LLVM and GCC.
2026-06-11 23:15:26 -04:00
Camille Gillot
5296ed33e4 Move create_scope_map to rustc_codegen_ssa. 2026-06-10 16:55:05 +00:00
Flakebi
e699f5a6b6 Add inline asm support for amdgpu
Add support for inline assembly for the amdgpu backend (the
amdgcn-amd-amdhsa target).
Add register classes for `vgpr` (vector general purpose register) and
`sgpr` (scalar general purpose register).
The LLVM backend supports two more classes, `reg`, which is either VGPR
or SGPR, up to the compiler to decide. As instructions often rely on a
register being either a VGPR or SGPR for the assembly to be valid, reg
doesn’t seem that useful (I struggled to write correct tests for it), so
I didn’t end up adding it.
The fourth register class is AGPRs, which only exist on some hardware
versions (not the consumer ones) and they have restricted ways to write
and read from them, which makes it hard to write a Rust variable into
them. They could be used inside assembly blocks, but I didn’t add them
as Rust register class.

There are a few change affecting general inline assembly code, that is
`InlineAsmReg::name()` now returns a `Cow` instead of a `&'static str`.
Because amdgpu has many registers, 256 VGPRs plus combinations of 2 or 4
VGPRs, and I didn’t want to list hundreds of static strings, the amdgpu
reg stores the register number(s) and a non-static String is generated
at runtime for the register name.
Similar for register classes and supported_types.

Vectors of 64-bit types are supported by the LLVM backend, but omitted
here to make the code simpler. There is currently no systematic support
in LLVM of which vectors of 64-bit types are supported. Also, they are
likely seldomly unused, vectors of 16- and 32-bit types are important.
2026-06-10 09:57:20 +02:00
Jonathan Brouwer
de70798fa7 Rollup merge of #147302 - esp-rs:xtensa-asm, r=Amanieu
asm! support for the Xtensa architecture

This implements the asm! support for Xtensa. We've been using this code for a few years in [our fork](https://github.com/esp-rs/rust) and it's been working well. I finally found some time to clean it up a bit and start the upstreaming process. This should be one of the final PRs for Xtensa support on the Rust side (minus bug fixes of course). After this, we're mostly just waiting on the LLVM upstreaming which is going well. This PR doesn't cover all possible asm options for Xtensa, but the base ISA plus a few extras that are used in Espressif chips.

r? Amanieu
2026-06-08 17:11:05 +02:00
Scott Mabin
768fc10e9d asm! support for the Xtensa architecture
Co-authored-by: Taiki Endo <te316e89@gmail.com>
Co-authored-by: Kerry Jones <kerry@iodrive.co.za>
2026-06-08 11:53:15 +01:00
bjorn3
9419baeee8 Use WorkProductMap instead of FxIndexMap
This is an UnordMap internally. Iteration order for the work product map
should not matter aside from the place it is serialized where sorting by
WorkProductId is sufficient.
2026-06-07 13:24:12 +00:00
Folkert de Vries
4e59f4c54b add extern "tail" calling convention 2026-06-05 20:19:51 +02:00
Jonathan Brouwer
99bb120cf8 Rollup merge of #157130 - alexcrichton:refactor-cast-target-internals, r=nnethercote
Use a `ArrayVec` in `CastTarget`

This commit switches a fixed-size list of `[Option<Reg>; 8]` to instead
holding `ArrayVec<Reg, 8>` in the `CastTarget` type used when
calculating ABIs. This is inspired by [discussion on Zulip][link] where
I'm hoping to in the near future extend the usage of this to possibly
beyond 8 elements for a new WebAssembly ABI taking advantage of
multi-value. For now though this mostly just switches to
array/slice-like idioms of accessors rather than dealing with
`Option<Reg>` as the unit.

[link]: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Using.20.60ArgAbi.3A.3Amake_direct_deprecated.60/with/598607139
2026-06-02 13:20:49 +02:00