Skip to content

Commit e3f2d28

Browse files
committed
Require sram target feature on AVR
1 parent c9f3a53 commit e3f2d28

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

compiler/rustc_target/src/target_features.rs

Lines changed: 8 additions & 6 deletions
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: "minimum requirement for Rust/C/C++" }, &[]),
906906
("tinyencoding", Unstable(sym::avr_target_feature), &[]),
907907
// tidy-alphabetical-end
908908
];
@@ -1038,11 +1038,7 @@ impl Target {
10381038
Arch::CSky => CSKY_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
10391039
// FIXME: for some tier3 targets, we are overly cautious and always give warnings
10401040
// when passing args in vector registers.
1041-
Arch::Msp430
1042-
| Arch::PowerPC64LE
1043-
| Arch::SpirV
1044-
| Arch::Xtensa
1045-
| Arch::Other(_) => &[],
1041+
Arch::Msp430 | Arch::PowerPC64LE | Arch::SpirV | Arch::Xtensa | Arch::Other(_) => &[],
10461042
}
10471043
}
10481044

@@ -1239,6 +1235,12 @@ impl Target {
12391235
// because the vector and float registers overlap.
12401236
FeatureConstraints { required: &[], incompatible: &["soft-float"] }
12411237
}
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+
}
12421244
_ => NOTHING,
12431245
}
12441246
}

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::*;

0 commit comments

Comments
 (0)