Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #131302

Merged
merged 17 commits into from
Oct 5, 2024
Merged
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
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
})
}

#[allow(rustc::potential_query_instability)]
let extra_tracked_files = hash_iter_files(
file_depinfo.iter().map(|path_sym| normalize_path(PathBuf::from(path_sym.as_str()))),
checksum_hash_algo,
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,10 @@ pub enum ProjectionElem<V, T> {
ConstantIndex {
/// index or -index (in Python terms), depending on from_end
offset: u64,
/// The thing being indexed must be at least this long. For arrays this
/// is always the exact length.
/// The thing being indexed must be at least this long -- otherwise, the
/// projection is UB.
///
/// For arrays this is always the exact length.
min_length: u64,
/// Counting backwards from end? This is always false when indexing an
/// array.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ passes_lang_item_fn_with_target_feature =

passes_lang_item_fn_with_track_caller =
{passes_lang_item_fn} is not allowed to have `#[track_caller]`
.label = {passes_lang_item_fn} is not allowed to have `#[target_feature]`
.label = {passes_lang_item_fn} is not allowed to have `#[track_caller]`

passes_lang_item_on_incorrect_target =
`{$name}` lang item must be applied to a {$expected_target}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,10 @@ supported_targets! {
("riscv32imac-esp-espidf", riscv32imac_esp_espidf),
("riscv32imafc-esp-espidf", riscv32imafc_esp_espidf),

("riscv32e-unknown-none-elf", riscv32e_unknown_none_elf),
("riscv32em-unknown-none-elf", riscv32em_unknown_none_elf),
("riscv32emc-unknown-none-elf", riscv32emc_unknown_none_elf),

("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
("riscv32imafc-unknown-none-elf", riscv32imafc_unknown_none_elf),
("riscv32imac-unknown-xous-elf", riscv32imac_unknown_xous_elf),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};

pub(crate) fn target() -> Target {
Target {
// The below `data_layout` is explicitly specified by the ilp32e ABI in LLVM. See also
// `options.llvm_abiname`.
data_layout: "e-m:e-p:32:32-i64:64-n32-S32".into(),
llvm_target: "riscv32".into(),
metadata: crate::spec::TargetMetadata {
description: Some("Bare RISC-V (RV32E ISA)".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(false),
},
pointer_width: 32,
arch: "riscv32".into(),

options: TargetOptions {
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
linker: Some("rust-lld".into()),
cpu: "generic-rv32".into(),
// The ilp32e ABI specifies the `data_layout`
llvm_abiname: "ilp32e".into(),
max_atomic_width: Some(32),
atomic_cas: false,
features: "+e,+forced-atomics".into(),
panic_strategy: PanicStrategy::Abort,
relocation_model: RelocModel::Static,
emit_debug_gdb_scripts: false,
eh_frame_header: false,
..Default::default()
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};

pub(crate) fn target() -> Target {
Target {
// The below `data_layout` is explicitly specified by the ilp32e ABI in LLVM. See also
// `options.llvm_abiname`.
data_layout: "e-m:e-p:32:32-i64:64-n32-S32".into(),
llvm_target: "riscv32".into(),
metadata: crate::spec::TargetMetadata {
description: Some("Bare RISC-V (RV32EM ISA)".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(false),
},
pointer_width: 32,
arch: "riscv32".into(),

options: TargetOptions {
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
linker: Some("rust-lld".into()),
cpu: "generic-rv32".into(),
// The ilp32e ABI specifies the `data_layout`
llvm_abiname: "ilp32e".into(),
max_atomic_width: Some(32),
atomic_cas: false,
features: "+e,+m,+forced-atomics".into(),
panic_strategy: PanicStrategy::Abort,
relocation_model: RelocModel::Static,
emit_debug_gdb_scripts: false,
eh_frame_header: false,
..Default::default()
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};

pub(crate) fn target() -> Target {
Target {
// The below `data_layout` is explicitly specified by the ilp32e ABI in LLVM. See also
// `options.llvm_abiname`.
data_layout: "e-m:e-p:32:32-i64:64-n32-S32".into(),
llvm_target: "riscv32".into(),
metadata: crate::spec::TargetMetadata {
description: Some("Bare RISC-V (RV32EMC ISA)".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(false),
},
pointer_width: 32,
arch: "riscv32".into(),

options: TargetOptions {
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
linker: Some("rust-lld".into()),
cpu: "generic-rv32".into(),
// The ilp32e ABI specifies the `data_layout`
llvm_abiname: "ilp32e".into(),
max_atomic_width: Some(32),
atomic_cas: false,
features: "+e,+m,+c,+forced-atomics".into(),
panic_strategy: PanicStrategy::Abort,
relocation_model: RelocModel::Static,
emit_debug_gdb_scripts: false,
eh_frame_header: false,
..Default::default()
},
}
}
6 changes: 4 additions & 2 deletions compiler/stable_mir/src/mir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,10 @@ pub enum ProjectionElem {
ConstantIndex {
/// index or -index (in Python terms), depending on from_end
offset: u64,
/// The thing being indexed must be at least this long. For arrays this
/// is always the exact length.
/// The thing being indexed must be at least this long -- otherwise, the
/// projection is UB.
///
/// For arrays this is always the exact length.
min_length: u64,
/// Counting backwards from end? This is always false when indexing an
/// array.
Expand Down
18 changes: 12 additions & 6 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,9 @@ impl<T> Cell<T> {
/// ```
#[inline]
#[stable(feature = "move_cell", since = "1.17.0")]
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
#[rustc_confusables("swap")]
pub fn replace(&self, val: T) -> T {
pub const fn replace(&self, val: T) -> T {
// SAFETY: This can cause data races if called from a separate thread,
// but `Cell` is `!Sync` so this won't happen.
mem::replace(unsafe { &mut *self.value.get() }, val)
Expand Down Expand Up @@ -535,7 +536,8 @@ impl<T: Copy> Cell<T> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get(&self) -> T {
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
pub const fn get(&self) -> T {
// SAFETY: This can cause data races if called from a separate thread,
// but `Cell` is `!Sync` so this won't happen.
unsafe { *self.value.get() }
Expand Down Expand Up @@ -613,7 +615,8 @@ impl<T: ?Sized> Cell<T> {
/// ```
#[inline]
#[stable(feature = "cell_get_mut", since = "1.11.0")]
pub fn get_mut(&mut self) -> &mut T {
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
pub const fn get_mut(&mut self) -> &mut T {
self.value.get_mut()
}

Expand All @@ -632,7 +635,8 @@ impl<T: ?Sized> Cell<T> {
/// ```
#[inline]
#[stable(feature = "as_cell", since = "1.37.0")]
pub fn from_mut(t: &mut T) -> &Cell<T> {
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
pub const fn from_mut(t: &mut T) -> &Cell<T> {
// SAFETY: `&mut` ensures unique access.
unsafe { &*(t as *mut T as *const Cell<T>) }
}
Expand Down Expand Up @@ -686,7 +690,8 @@ impl<T> Cell<[T]> {
/// assert_eq!(slice_cell.len(), 3);
/// ```
#[stable(feature = "as_cell", since = "1.37.0")]
pub fn as_slice_of_cells(&self) -> &[Cell<T>] {
#[rustc_const_unstable(feature = "const_cell", issue = "131283")]
pub const fn as_slice_of_cells(&self) -> &[Cell<T>] {
// SAFETY: `Cell<T>` has the same memory layout as `T`.
unsafe { &*(self as *const Cell<[T]> as *const [Cell<T>]) }
}
Expand All @@ -706,7 +711,8 @@ impl<T, const N: usize> Cell<[T; N]> {
/// let array_cell: &[Cell<i32>; 3] = cell_array.as_array_of_cells();
/// ```
#[unstable(feature = "as_array_of_cells", issue = "88248")]
pub fn as_array_of_cells(&self) -> &[Cell<T>; N] {
#[rustc_const_unstable(feature = "as_array_of_cells", issue = "88248")]
pub const fn as_array_of_cells(&self) -> &[Cell<T>; N] {
// SAFETY: `Cell<T>` has the same memory layout as `T`.
unsafe { &*(self as *const Cell<[T; N]> as *const [Cell<T>; N]) }
}
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub struct Finder {
const STAGE0_MISSING_TARGETS: &[&str] = &[
// just a dummy comment so the list doesn't get onelined
"armv7-rtems-eabihf",
"riscv32e-unknown-none-elf",
"riscv32em-unknown-none-elf",
"riscv32emc-unknown-none-elf",
];

/// Minimum version threshold for libstdc++ required when using prebuilt LLVM
Expand Down
3 changes: 3 additions & 0 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,8 @@ target | std | host | notes
[`riscv32imafc-unknown-nuttx-elf`](platform-support/nuttx.md) | * | | RISC-V 32bit with NuttX
[`riscv64imac-unknown-nuttx-elf`](platform-support/nuttx.md) | * | | RISC-V 64bit with NuttX
[`riscv64gc-unknown-nuttx-elf`](platform-support/nuttx.md) | * | | RISC-V 64bit with NuttX
[`riscv32e-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | | Bare RISC-V (RV32E ISA)
[`riscv32em-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | | Bare RISC-V (RV32EM ISA)
[`riscv32emc-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | | Bare RISC-V (RV32EMC ISA)

[runs on NVIDIA GPUs]: https://github.com/japaric-archived/nvptx#targets
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ Rust test-suite on this target.
## Cross-compilation toolchains and C code

This target supports C code. If interlinking with C or C++, you may need to use
`riscv64-unknown-elf-gcc` as a linker instead of `rust-lld`.
`riscv32-unknown-elf-gcc` as a linker instead of `rust-lld`.
30 changes: 30 additions & 0 deletions src/doc/rustc/src/platform-support/riscv32e-unknown-none-elf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# `riscv32{e,em,emc}-unknown-none-elf`

**Tier: 3**

Bare-metal target for RISC-V CPUs with the RV32E, RV32EM and RV32EMC ISAs.

## Target maintainers

* Henri Lunnikivi, <[email protected]>, [@hegza](https://github.com/hegza)

## Requirements

The target is cross-compiled, and uses static linking. No external toolchain is
required and the default `rust-lld` linker works, but you must specify a linker
script.

## Building the target

This target is included in Rust and can be installed via `rustup`.

## Testing

This is a cross-compiled `no-std` target, which must be run either in a
simulator or by programming them onto suitable hardware. It is not possible to
run the Rust test-suite on this target.

## Cross-compilation toolchains and C code

This target supports C code. If interlinking with C or C++, you may need to use
`riscv32-unknown-elf-gcc` as a linker instead of `rust-lld`.
9 changes: 9 additions & 0 deletions tests/assembly/targets/targets-elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,15 @@
//@ revisions: riscv32_wrs_vxworks
//@ [riscv32_wrs_vxworks] compile-flags: --target riscv32-wrs-vxworks
//@ [riscv32_wrs_vxworks] needs-llvm-components: riscv
//@ revisions: riscv32e_unknown_none_elf
//@ [riscv32e_unknown_none_elf] compile-flags: --target riscv32e-unknown-none-elf
//@ [riscv32e_unknown_none_elf] needs-llvm-components: riscv
//@ revisions: riscv32em_unknown_none_elf
//@ [riscv32em_unknown_none_elf] compile-flags: --target riscv32em-unknown-none-elf
//@ [riscv32em_unknown_none_elf] needs-llvm-components: riscv
//@ revisions: riscv32emc_unknown_none_elf
//@ [riscv32emc_unknown_none_elf] compile-flags: --target riscv32emc-unknown-none-elf
//@ [riscv32emc_unknown_none_elf] needs-llvm-components: riscv
//@ revisions: riscv32gc_unknown_linux_gnu
//@ [riscv32gc_unknown_linux_gnu] compile-flags: --target riscv32gc-unknown-linux-gnu
//@ [riscv32gc_unknown_linux_gnu] needs-llvm-components: riscv
Expand Down
Loading
Loading