Skip to content

Commit 895ea0c

Browse files
committed
Require sram target feature on AVR
1 parent 8cbc623 commit 895ea0c

6 files changed

Lines changed: 44 additions & 7 deletions

File tree

compiler/rustc_target/src/target_features.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ static AVR_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
915915
("rmw", Unstable(sym::avr_target_feature), &[]),
916916
("spm", Unstable(sym::avr_target_feature), &[]),
917917
("spmx", Unstable(sym::avr_target_feature), &[]),
918-
("sram", Unstable(sym::avr_target_feature), &[]),
918+
("sram", Forbidden { reason: "devices that have no SRAM are unsupported" }, &[]),
919919
("tinyencoding", Unstable(sym::avr_target_feature), &[]),
920920
// tidy-alphabetical-end
921921
];
@@ -1020,11 +1020,7 @@ impl Target {
10201020
Arch::Sparc | Arch::Sparc64 => SPARC_FEATURES,
10211021
Arch::M68k => M68K_FEATURES,
10221022
Arch::Avr => AVR_FEATURES,
1023-
Arch::AmdGpu
1024-
| Arch::Msp430
1025-
| Arch::SpirV
1026-
| Arch::Xtensa
1027-
| Arch::Other(_) => &[],
1023+
Arch::AmdGpu | Arch::Msp430 | Arch::SpirV | Arch::Xtensa | Arch::Other(_) => &[],
10281024
}
10291025
}
10301026

@@ -1247,6 +1243,12 @@ impl Target {
12471243
// because the vector and float registers overlap.
12481244
FeatureConstraints { required: &[], incompatible: &["soft-float"] }
12491245
}
1246+
Arch::Avr => {
1247+
// SRAM is minimum requirement for C/C++ in both avr-gcc and Clang,
1248+
// and backends of them only support assembly for devices have no SRAM.
1249+
// See the discussion in https://github.com/rust-lang/rust/pull/146900 for more.
1250+
FeatureConstraints { required: &["sram"], incompatible: &[] }
1251+
}
12501252
_ => NOTHING,
12511253
}
12521254
}

src/doc/rustc/src/platform-support/avr-none.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ the possible variants:
6868

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

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

7375
You can use [`simavr`](https://github.com/buserror/simavr) to emulate the
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
warning: target feature `sram` cannot be disabled with `-Ctarget-feature`: devices that have no SRAM are unsupported
2+
|
3+
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4+
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
5+
6+
warning: target feature `sram` must be enabled to ensure that the ABI of the current target can be implemented correctly
7+
|
8+
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
10+
11+
warning: 2 warnings emitted
12+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
warning: target feature `sram` must be enabled to ensure that the ABI of the current target can be implemented correctly
2+
|
3+
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4+
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
5+
6+
warning: 1 warning emitted
7+

tests/ui/abi/avr-sram.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ revisions: has_sram no_sram disable_sram
2+
//@ build-pass
3+
//@[has_sram] compile-flags: --target avr-none -C target-cpu=atmega328p
4+
//@[has_sram] needs-llvm-components: avr
5+
//@[no_sram] compile-flags: --target avr-none -C target-cpu=attiny11
6+
//@[no_sram] needs-llvm-components: avr
7+
//@[disable_sram] compile-flags: --target avr-none -C target-cpu=atmega328p -C target-feature=-sram
8+
//@[disable_sram] needs-llvm-components: avr
9+
//@ ignore-backends: gcc
10+
//[no_sram,disable_sram]~? WARN target feature `sram` must be enabled
11+
//[disable_sram]~? WARN target feature `sram` cannot be disabled with `-Ctarget-feature`
12+
13+
#![feature(no_core)]
14+
#![no_core]
15+
#![crate_type = "lib"]

tests/ui/check-cfg/target_feature.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
323323
`spe`
324324
`spm`
325325
`spmx`
326-
`sram`
327326
`ssbs`
328327
`sse`
329328
`sse2`

0 commit comments

Comments
 (0)