Skip to content

Commit 9096f4f

Browse files
committed
Auto merge of #131302 - matthiaskrgr:rollup-56kbpzx, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #130555 ( Initial support for riscv32{e|em|emc}_unknown_none_elf) - #131280 (Handle `rustc_interface` cases of `rustc::potential_query_instability` lint) - #131281 (make Cell unstably const) - #131285 (clarify semantics of ConstantIndex MIR projection) - #131299 (fix typo in 'lang item with track_caller' message) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2b21f90 + 6a85c32 commit 9096f4f

19 files changed

+847
-14
lines changed

compiler/rustc_interface/src/passes.rs

-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
470470
})
471471
}
472472

473-
#[allow(rustc::potential_query_instability)]
474473
let extra_tracked_files = hash_iter_files(
475474
file_depinfo.iter().map(|path_sym| normalize_path(PathBuf::from(path_sym.as_str()))),
476475
checksum_hash_algo,

compiler/rustc_middle/src/mir/syntax.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1135,8 +1135,10 @@ pub enum ProjectionElem<V, T> {
11351135
ConstantIndex {
11361136
/// index or -index (in Python terms), depending on from_end
11371137
offset: u64,
1138-
/// The thing being indexed must be at least this long. For arrays this
1139-
/// is always the exact length.
1138+
/// The thing being indexed must be at least this long -- otherwise, the
1139+
/// projection is UB.
1140+
///
1141+
/// For arrays this is always the exact length.
11401142
min_length: u64,
11411143
/// Counting backwards from end? This is always false when indexing an
11421144
/// array.

compiler/rustc_passes/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ passes_lang_item_fn_with_target_feature =
391391
392392
passes_lang_item_fn_with_track_caller =
393393
{passes_lang_item_fn} is not allowed to have `#[track_caller]`
394-
.label = {passes_lang_item_fn} is not allowed to have `#[target_feature]`
394+
.label = {passes_lang_item_fn} is not allowed to have `#[track_caller]`
395395
396396
passes_lang_item_on_incorrect_target =
397397
`{$name}` lang item must be applied to a {$expected_target}

compiler/rustc_target/src/spec/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,10 @@ supported_targets! {
18411841
("riscv32imac-esp-espidf", riscv32imac_esp_espidf),
18421842
("riscv32imafc-esp-espidf", riscv32imafc_esp_espidf),
18431843

1844+
("riscv32e-unknown-none-elf", riscv32e_unknown_none_elf),
1845+
("riscv32em-unknown-none-elf", riscv32em_unknown_none_elf),
1846+
("riscv32emc-unknown-none-elf", riscv32emc_unknown_none_elf),
1847+
18441848
("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
18451849
("riscv32imafc-unknown-none-elf", riscv32imafc_unknown_none_elf),
18461850
("riscv32imac-unknown-xous-elf", riscv32imac_unknown_xous_elf),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};
2+
3+
pub(crate) fn target() -> Target {
4+
Target {
5+
// The below `data_layout` is explicitly specified by the ilp32e ABI in LLVM. See also
6+
// `options.llvm_abiname`.
7+
data_layout: "e-m:e-p:32:32-i64:64-n32-S32".into(),
8+
llvm_target: "riscv32".into(),
9+
metadata: crate::spec::TargetMetadata {
10+
description: Some("Bare RISC-V (RV32E ISA)".into()),
11+
tier: Some(3),
12+
host_tools: Some(false),
13+
std: Some(false),
14+
},
15+
pointer_width: 32,
16+
arch: "riscv32".into(),
17+
18+
options: TargetOptions {
19+
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
20+
linker: Some("rust-lld".into()),
21+
cpu: "generic-rv32".into(),
22+
// The ilp32e ABI specifies the `data_layout`
23+
llvm_abiname: "ilp32e".into(),
24+
max_atomic_width: Some(32),
25+
atomic_cas: false,
26+
features: "+e,+forced-atomics".into(),
27+
panic_strategy: PanicStrategy::Abort,
28+
relocation_model: RelocModel::Static,
29+
emit_debug_gdb_scripts: false,
30+
eh_frame_header: false,
31+
..Default::default()
32+
},
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};
2+
3+
pub(crate) fn target() -> Target {
4+
Target {
5+
// The below `data_layout` is explicitly specified by the ilp32e ABI in LLVM. See also
6+
// `options.llvm_abiname`.
7+
data_layout: "e-m:e-p:32:32-i64:64-n32-S32".into(),
8+
llvm_target: "riscv32".into(),
9+
metadata: crate::spec::TargetMetadata {
10+
description: Some("Bare RISC-V (RV32EM ISA)".into()),
11+
tier: Some(3),
12+
host_tools: Some(false),
13+
std: Some(false),
14+
},
15+
pointer_width: 32,
16+
arch: "riscv32".into(),
17+
18+
options: TargetOptions {
19+
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
20+
linker: Some("rust-lld".into()),
21+
cpu: "generic-rv32".into(),
22+
// The ilp32e ABI specifies the `data_layout`
23+
llvm_abiname: "ilp32e".into(),
24+
max_atomic_width: Some(32),
25+
atomic_cas: false,
26+
features: "+e,+m,+forced-atomics".into(),
27+
panic_strategy: PanicStrategy::Abort,
28+
relocation_model: RelocModel::Static,
29+
emit_debug_gdb_scripts: false,
30+
eh_frame_header: false,
31+
..Default::default()
32+
},
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};
2+
3+
pub(crate) fn target() -> Target {
4+
Target {
5+
// The below `data_layout` is explicitly specified by the ilp32e ABI in LLVM. See also
6+
// `options.llvm_abiname`.
7+
data_layout: "e-m:e-p:32:32-i64:64-n32-S32".into(),
8+
llvm_target: "riscv32".into(),
9+
metadata: crate::spec::TargetMetadata {
10+
description: Some("Bare RISC-V (RV32EMC ISA)".into()),
11+
tier: Some(3),
12+
host_tools: Some(false),
13+
std: Some(false),
14+
},
15+
pointer_width: 32,
16+
arch: "riscv32".into(),
17+
18+
options: TargetOptions {
19+
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
20+
linker: Some("rust-lld".into()),
21+
cpu: "generic-rv32".into(),
22+
// The ilp32e ABI specifies the `data_layout`
23+
llvm_abiname: "ilp32e".into(),
24+
max_atomic_width: Some(32),
25+
atomic_cas: false,
26+
features: "+e,+m,+c,+forced-atomics".into(),
27+
panic_strategy: PanicStrategy::Abort,
28+
relocation_model: RelocModel::Static,
29+
emit_debug_gdb_scripts: false,
30+
eh_frame_header: false,
31+
..Default::default()
32+
},
33+
}
34+
}

compiler/stable_mir/src/mir/body.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,10 @@ pub enum ProjectionElem {
768768
ConstantIndex {
769769
/// index or -index (in Python terms), depending on from_end
770770
offset: u64,
771-
/// The thing being indexed must be at least this long. For arrays this
772-
/// is always the exact length.
771+
/// The thing being indexed must be at least this long -- otherwise, the
772+
/// projection is UB.
773+
///
774+
/// For arrays this is always the exact length.
773775
min_length: u64,
774776
/// Counting backwards from end? This is always false when indexing an
775777
/// array.

library/core/src/cell.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,9 @@ impl<T> Cell<T> {
494494
/// ```
495495
#[inline]
496496
#[stable(feature = "move_cell", since = "1.17.0")]
497+
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
497498
#[rustc_confusables("swap")]
498-
pub fn replace(&self, val: T) -> T {
499+
pub const fn replace(&self, val: T) -> T {
499500
// SAFETY: This can cause data races if called from a separate thread,
500501
// but `Cell` is `!Sync` so this won't happen.
501502
mem::replace(unsafe { &mut *self.value.get() }, val)
@@ -535,7 +536,8 @@ impl<T: Copy> Cell<T> {
535536
/// ```
536537
#[inline]
537538
#[stable(feature = "rust1", since = "1.0.0")]
538-
pub fn get(&self) -> T {
539+
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
540+
pub const fn get(&self) -> T {
539541
// SAFETY: This can cause data races if called from a separate thread,
540542
// but `Cell` is `!Sync` so this won't happen.
541543
unsafe { *self.value.get() }
@@ -613,7 +615,8 @@ impl<T: ?Sized> Cell<T> {
613615
/// ```
614616
#[inline]
615617
#[stable(feature = "cell_get_mut", since = "1.11.0")]
616-
pub fn get_mut(&mut self) -> &mut T {
618+
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
619+
pub const fn get_mut(&mut self) -> &mut T {
617620
self.value.get_mut()
618621
}
619622

@@ -632,7 +635,8 @@ impl<T: ?Sized> Cell<T> {
632635
/// ```
633636
#[inline]
634637
#[stable(feature = "as_cell", since = "1.37.0")]
635-
pub fn from_mut(t: &mut T) -> &Cell<T> {
638+
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
639+
pub const fn from_mut(t: &mut T) -> &Cell<T> {
636640
// SAFETY: `&mut` ensures unique access.
637641
unsafe { &*(t as *mut T as *const Cell<T>) }
638642
}
@@ -686,7 +690,8 @@ impl<T> Cell<[T]> {
686690
/// assert_eq!(slice_cell.len(), 3);
687691
/// ```
688692
#[stable(feature = "as_cell", since = "1.37.0")]
689-
pub fn as_slice_of_cells(&self) -> &[Cell<T>] {
693+
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
694+
pub const fn as_slice_of_cells(&self) -> &[Cell<T>] {
690695
// SAFETY: `Cell<T>` has the same memory layout as `T`.
691696
unsafe { &*(self as *const Cell<[T]> as *const [Cell<T>]) }
692697
}
@@ -706,7 +711,8 @@ impl<T, const N: usize> Cell<[T; N]> {
706711
/// let array_cell: &[Cell<i32>; 3] = cell_array.as_array_of_cells();
707712
/// ```
708713
#[unstable(feature = "as_array_of_cells", issue = "88248")]
709-
pub fn as_array_of_cells(&self) -> &[Cell<T>; N] {
714+
#[rustc_const_unstable(feature = "as_array_of_cells", issue = "88248")]
715+
pub const fn as_array_of_cells(&self) -> &[Cell<T>; N] {
710716
// SAFETY: `Cell<T>` has the same memory layout as `T`.
711717
unsafe { &*(self as *const Cell<[T; N]> as *const [Cell<T>; N]) }
712718
}

src/bootstrap/src/core/sanity.rs

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub struct Finder {
3737
const STAGE0_MISSING_TARGETS: &[&str] = &[
3838
// just a dummy comment so the list doesn't get onelined
3939
"armv7-rtems-eabihf",
40+
"riscv32e-unknown-none-elf",
41+
"riscv32em-unknown-none-elf",
42+
"riscv32emc-unknown-none-elf",
4043
];
4144

4245
/// Minimum version threshold for libstdc++ required when using prebuilt LLVM

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

+3
Original file line numberDiff line numberDiff line change
@@ -413,5 +413,8 @@ target | std | host | notes
413413
[`riscv32imafc-unknown-nuttx-elf`](platform-support/nuttx.md) | * | | RISC-V 32bit with NuttX
414414
[`riscv64imac-unknown-nuttx-elf`](platform-support/nuttx.md) | * | | RISC-V 64bit with NuttX
415415
[`riscv64gc-unknown-nuttx-elf`](platform-support/nuttx.md) | * | | RISC-V 64bit with NuttX
416+
[`riscv32e-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | | Bare RISC-V (RV32E ISA)
417+
[`riscv32em-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | | Bare RISC-V (RV32EM ISA)
418+
[`riscv32emc-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | | Bare RISC-V (RV32EMC ISA)
416419

417420
[runs on NVIDIA GPUs]: https://github.com/japaric-archived/nvptx#targets

src/doc/rustc/src/platform-support/riscv32-unknown-none-elf.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ Rust test-suite on this target.
3535
## Cross-compilation toolchains and C code
3636

3737
This target supports C code. If interlinking with C or C++, you may need to use
38-
`riscv64-unknown-elf-gcc` as a linker instead of `rust-lld`.
38+
`riscv32-unknown-elf-gcc` as a linker instead of `rust-lld`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# `riscv32{e,em,emc}-unknown-none-elf`
2+
3+
**Tier: 3**
4+
5+
Bare-metal target for RISC-V CPUs with the RV32E, RV32EM and RV32EMC ISAs.
6+
7+
## Target maintainers
8+
9+
* Henri Lunnikivi, <henri.lunnikivi@gmail.com>, [@hegza](https://github.com/hegza)
10+
11+
## Requirements
12+
13+
The target is cross-compiled, and uses static linking. No external toolchain is
14+
required and the default `rust-lld` linker works, but you must specify a linker
15+
script.
16+
17+
## Building the target
18+
19+
This target is included in Rust and can be installed via `rustup`.
20+
21+
## Testing
22+
23+
This is a cross-compiled `no-std` target, which must be run either in a
24+
simulator or by programming them onto suitable hardware. It is not possible to
25+
run the Rust test-suite on this target.
26+
27+
## Cross-compilation toolchains and C code
28+
29+
This target supports C code. If interlinking with C or C++, you may need to use
30+
`riscv32-unknown-elf-gcc` as a linker instead of `rust-lld`.

tests/assembly/targets/targets-elf.rs

+9
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,15 @@
375375
//@ revisions: riscv32_wrs_vxworks
376376
//@ [riscv32_wrs_vxworks] compile-flags: --target riscv32-wrs-vxworks
377377
//@ [riscv32_wrs_vxworks] needs-llvm-components: riscv
378+
//@ revisions: riscv32e_unknown_none_elf
379+
//@ [riscv32e_unknown_none_elf] compile-flags: --target riscv32e-unknown-none-elf
380+
//@ [riscv32e_unknown_none_elf] needs-llvm-components: riscv
381+
//@ revisions: riscv32em_unknown_none_elf
382+
//@ [riscv32em_unknown_none_elf] compile-flags: --target riscv32em-unknown-none-elf
383+
//@ [riscv32em_unknown_none_elf] needs-llvm-components: riscv
384+
//@ revisions: riscv32emc_unknown_none_elf
385+
//@ [riscv32emc_unknown_none_elf] compile-flags: --target riscv32emc-unknown-none-elf
386+
//@ [riscv32emc_unknown_none_elf] needs-llvm-components: riscv
378387
//@ revisions: riscv32gc_unknown_linux_gnu
379388
//@ [riscv32gc_unknown_linux_gnu] compile-flags: --target riscv32gc-unknown-linux-gnu
380389
//@ [riscv32gc_unknown_linux_gnu] needs-llvm-components: riscv

0 commit comments

Comments
 (0)