Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ declare_features! (
(unstable, async_for_loop, "1.77.0", Some(118898)),
/// Allows `async` trait bound modifier.
(unstable, async_trait_bounds, "1.85.0", Some(62290)),
/// Target features on avr.
(unstable, avr_target_feature, "CURRENT_RUSTC_VERSION", Some(146889)),
/// Allows using Intel AVX10 target features and intrinsics
(unstable, avx10_target_feature, "1.88.0", Some(138843)),
/// Target features on bpf.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ symbols! {
automatically_derived,
available_externally,
avr,
avr_target_feature,
avx,
avx10_target_feature,
avx512_target_feature,
Expand Down
41 changes: 33 additions & 8 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,28 @@ static M68K_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-end
];

static AVR_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("addsubiw", Unstable(sym::avr_target_feature), &[]),
("break", Unstable(sym::avr_target_feature), &[]),
Copy link
Contributor

@Patryk27 Patryk27 Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: what about name collisions? 👀

The RFC doesn't seem to mention this, but I can see AVR's break (or other "generic" word like mul) accidentally colliding with another arch in future - on the other hand, keeping the mapping 1:1 with LLVM (FeatureBREAK in this case) is important as well, IMO.

Other than that LGTM.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Target feature name collisions with other architectures are fine. (e.g., the aes target feature exists on x86/x86_64 (AES-NI) and arm/aarch64/arm64ec (FEAT_AES) respectively.)

("eijmpcall", Unstable(sym::avr_target_feature), &[]),
("elpm", Unstable(sym::avr_target_feature), &[]),
("elpmx", Unstable(sym::avr_target_feature), &[]),
("ijmpcall", Unstable(sym::avr_target_feature), &[]),
("jmpcall", Unstable(sym::avr_target_feature), &[]),
("lowbytefirst", Unstable(sym::avr_target_feature), &[]),
("lpm", Unstable(sym::avr_target_feature), &[]),
("lpmx", Unstable(sym::avr_target_feature), &[]),
("movw", Unstable(sym::avr_target_feature), &[]),
("mul", Unstable(sym::avr_target_feature), &[]),
("rmw", Unstable(sym::avr_target_feature), &[]),
("spm", Unstable(sym::avr_target_feature), &[]),
("spmx", Unstable(sym::avr_target_feature), &[]),
("sram", Forbidden { reason: "devices that have no SRAM are unsupported" }, &[]),
("tinyencoding", Unstable(sym::avr_target_feature), &[]),
// tidy-alphabetical-end
];

/// When rustdoc is running, provide a list of all known features so that all their respective
/// primitives may be documented.
///
Expand All @@ -906,6 +928,7 @@ pub fn all_rust_features() -> impl Iterator<Item = (&'static str, Stability)> {
.chain(IBMZ_FEATURES)
.chain(SPARC_FEATURES)
.chain(M68K_FEATURES)
.chain(AVR_FEATURES)
.cloned()
.map(|(f, s, _)| (f, s))
}
Expand Down Expand Up @@ -983,12 +1006,8 @@ impl Target {
Arch::S390x => IBMZ_FEATURES,
Arch::Sparc | Arch::Sparc64 => SPARC_FEATURES,
Arch::M68k => M68K_FEATURES,
Arch::AmdGpu
| Arch::Avr
| Arch::Msp430
| Arch::SpirV
| Arch::Xtensa
| Arch::Other(_) => &[],
Arch::Avr => AVR_FEATURES,
Arch::AmdGpu | Arch::Msp430 | Arch::SpirV | Arch::Xtensa | Arch::Other(_) => &[],
}
}

Expand All @@ -1010,11 +1029,11 @@ impl Target {
MIPS_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI
}
Arch::AmdGpu => AMDGPU_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
Arch::Nvptx64 | Arch::Bpf | Arch::M68k => &[], // no vector ABI
Arch::Nvptx64 | Arch::Bpf | Arch::M68k | Arch::Avr => &[], // no vector ABI
Arch::CSky => CSKY_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
// FIXME: for some tier3 targets, we are overly cautious and always give warnings
// when passing args in vector registers.
Arch::Avr | Arch::Msp430 | Arch::SpirV | Arch::Xtensa | Arch::Other(_) => &[],
Arch::Msp430 | Arch::SpirV | Arch::Xtensa | Arch::Other(_) => &[],
}
}

Expand Down Expand Up @@ -1211,6 +1230,12 @@ impl Target {
// because the vector and float registers overlap.
FeatureConstraints { required: &[], incompatible: &["soft-float"] }
}
Arch::Avr => {
// SRAM is minimum requirement for C/C++ in both avr-gcc and Clang,
// and backends of them only support assembly for devices have no SRAM.
// See the discussion in https://github.com/rust-lang/rust/pull/146900 for more.
FeatureConstraints { required: &["sram"], incompatible: &[] }
}
_ => NOTHING,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/doc/rustc/src/platform-support/avr-none.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ the possible variants:

https://github.com/llvm/llvm-project/blob/093d4db2f3c874d4683fb01194b00dbb20e5c713/clang/lib/Basic/Targets/AVR.cpp#L32

Note that devices that have no SRAM are not supported, same as when compiling C/C++ programs with avr-gcc or Clang.

## Testing

You can use [`simavr`](https://github.com/buserror/simavr) to emulate the
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/abi/avr-sram.disable_sram.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
warning: target feature `sram` cannot be disabled with `-Ctarget-feature`: devices that have no SRAM are unsupported
|
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>

warning: target feature `sram` must be enabled to ensure that the ABI of the current target can be implemented correctly
|
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>

warning: 2 warnings emitted

7 changes: 7 additions & 0 deletions tests/ui/abi/avr-sram.no_sram.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
warning: target feature `sram` must be enabled to ensure that the ABI of the current target can be implemented correctly
|
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>

warning: 1 warning emitted

19 changes: 19 additions & 0 deletions tests/ui/abi/avr-sram.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ add-minicore
//@ revisions: has_sram no_sram disable_sram
//@ build-pass
//@[has_sram] compile-flags: --target avr-none -C target-cpu=atmega328p
//@[has_sram] needs-llvm-components: avr
//@[no_sram] compile-flags: --target avr-none -C target-cpu=attiny11
//@[no_sram] needs-llvm-components: avr
//@[disable_sram] compile-flags: --target avr-none -C target-cpu=atmega328p -C target-feature=-sram
//@[disable_sram] needs-llvm-components: avr
//@ ignore-backends: gcc
//[no_sram,disable_sram]~? WARN target feature `sram` must be enabled
//[disable_sram]~? WARN target feature `sram` cannot be disabled with `-Ctarget-feature`

#![feature(no_core)]
#![no_core]
#![crate_type = "lib"]

extern crate minicore;
use minicore::*;
16 changes: 16 additions & 0 deletions tests/ui/check-cfg/target_feature.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
`7e10`
`a`
`aclass`
`addsubiw`
`adx`
`aes`
`altivec`
Expand Down Expand Up @@ -57,6 +58,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
`bf16`
`bmi1`
`bmi2`
`break`
`bti`
`bulk-memory`
`c`
Expand All @@ -83,6 +85,9 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
`e2`
`ecv`
`edsp`
`eijmpcall`
`elpm`
`elpmx`
`elrw`
`enhanced-sort`
`ermsb`
Expand Down Expand Up @@ -134,6 +139,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
`hvx-length128b`
`hwdiv`
`i8mm`
`ijmpcall`
`isa-68000`
`isa-68010`
`isa-68020`
Expand All @@ -142,6 +148,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
`isa-68060`
`isa-68881`
`isa-68882`
`jmpcall`
`jsconv`
`kl`
`lahfsahf`
Expand All @@ -152,6 +159,9 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
`ld-seq-sa`
`leoncasa`
`lor`
`lowbytefirst`
`lpm`
`lpmx`
`lse`
`lse128`
`lse2`
Expand All @@ -173,11 +183,13 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
`mops`
`movbe`
`movrs`
`movw`
`mp`
`mp1e2`
`msa`
`msync`
`mte`
`mul`
`multivalue`
`mutable-globals`
`neon`
Expand Down Expand Up @@ -242,6 +254,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
`reference-types`
`relax`
`relaxed-simd`
`rmw`
`rtm`
`rva23u64`
`sb`
Expand Down Expand Up @@ -294,6 +307,8 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
`sme2p1`
`soft-float`
`spe`
`spm`
`spmx`
`ssbs`
`sse`
`sse2`
Expand All @@ -318,6 +333,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
`tbm`
`thumb-mode`
`thumb2`
`tinyencoding`
`tme`
`transactional-execution`
`trust`
Expand Down
1 change: 1 addition & 0 deletions tests/ui/target-feature/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// gate-test-sparc_target_feature
// gate-test-x87_target_feature
// gate-test-m68k_target_feature
// gate-test-avr_target_feature

#[target_feature(enable = "x87")]
//~^ ERROR: currently unstable
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/target-feature/gate.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: the target feature `x87` is currently unstable
--> $DIR/gate.rs:24:18
--> $DIR/gate.rs:25:18
|
LL | #[target_feature(enable = "x87")]
| ^^^^^^^^^^^^^^
Expand Down
Loading