Skip to content

Commit 0d13763

Browse files
committed
Require sram target feature on AVR
1 parent 9a07350 commit 0d13763

5 files changed

Lines changed: 32 additions & 2 deletions

File tree

compiler/rustc_target/src/target_features.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ static AVR_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
902902
("rmw", Unstable(sym::avr_target_feature), &[]),
903903
("spm", Unstable(sym::avr_target_feature), &[]),
904904
("spmx", Unstable(sym::avr_target_feature), &[]),
905-
("sram", Unstable(sym::avr_target_feature), &[]),
905+
("sram", Forbidden { reason: "devices that have no SRAM are unsupported" }, &[]),
906906
("tinyencoding", Unstable(sym::avr_target_feature), &[]),
907907
// tidy-alphabetical-end
908908
];
@@ -1235,6 +1235,12 @@ impl Target {
12351235
// because the vector and float registers overlap.
12361236
FeatureConstraints { required: &[], incompatible: &["soft-float"] }
12371237
}
1238+
Arch::Avr => {
1239+
// SRAM is minimum requirement for C/C++ in both avr-gcc and Clang,
1240+
// and backends of them only support assembly for devices have no SRAM.
1241+
// See the discussion in https://github.com/rust-lang/rust/pull/146900 for more.
1242+
FeatureConstraints { required: &["sram"], incompatible: &[] }
1243+
}
12381244
_ => NOTHING,
12391245
}
12401246
}

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: 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ add-minicore
2+
//@ revisions: has_sram no_sram
3+
//@ build-pass
4+
//@[has_sram] compile-flags: --target avr-none -C target-cpu=atmega328p
5+
//@[has_sram] needs-llvm-components: avr
6+
//@[no_sram] compile-flags: --target avr-none -C target-cpu=attiny11
7+
//@[no_sram] needs-llvm-components: avr
8+
//@ ignore-backends: gcc
9+
//[no_sram]~? WARN target feature `sram` must be enabled to ensure that the ABI of the current target can be implemented correctly
10+
11+
#![feature(no_core)]
12+
#![no_core]
13+
#![crate_type = "lib"]
14+
15+
extern crate minicore;
16+
use minicore::*;

tests/ui/check-cfg/target_feature.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
309309
`spe`
310310
`spm`
311311
`spmx`
312-
`sram`
313312
`ssbs`
314313
`sse`
315314
`sse2`

0 commit comments

Comments
 (0)