Skip to content

Commit d13a431

Browse files
committed
Auto merge of #142253 - tgross35:rollup-img49op, r=tgross35
Rollup of 5 pull requests Successful merges: - #140767 (Stabilize `sha512`, `sm3` and `sm4` for x86) - #141001 (Make NonZero<char> possible) - #141993 (Use the in-tree `compiler-builtins` for the sysroot) - #142208 (Always consider `const _` items as live for dead code analysis) - #142238 (stabilize nonnull_provenance) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 00b5262 + fd06f6d commit d13a431

File tree

35 files changed

+153
-71
lines changed

35 files changed

+153
-71
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,11 +3130,12 @@ dependencies = [
31303130

31313131
[[package]]
31323132
name = "rustc-build-sysroot"
3133-
version = "0.5.7"
3133+
version = "0.5.8"
31343134
source = "registry+https://github.com/rust-lang/crates.io-index"
3135-
checksum = "10edc2e4393515193bd766e2f6c050b0536a68e56f2b6d56c07ababfdc114ff0"
3135+
checksum = "16d115ad7e26e0d1337f64ae6598f758194696afc2e9f34c8a6f24582529c3dc"
31363136
dependencies = [
31373137
"anyhow",
3138+
"regex",
31383139
"rustc_version",
31393140
"tempfile",
31403141
"walkdir",

compiler/rustc_codegen_gcc/build_system/build_sysroot/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ resolver = "2"
66

77
[dependencies]
88
core = { path = "./sysroot_src/library/core" }
9-
compiler_builtins = "0.1"
109
alloc = { path = "./sysroot_src/library/alloc" }
1110
std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtrace"] }
1211
test = { path = "./sysroot_src/library/test" }
@@ -16,6 +15,7 @@ proc_macro = { path = "./sysroot_src/library/proc_macro" }
1615
rustc-std-workspace-core = { path = "./sysroot_src/library/rustc-std-workspace-core" }
1716
rustc-std-workspace-alloc = { path = "./sysroot_src/library/rustc-std-workspace-alloc" }
1817
rustc-std-workspace-std = { path = "./sysroot_src/library/rustc-std-workspace-std" }
18+
compiler_builtins = { path = "./sysroot_src/library/compiler-builtins/compiler-builtins" }
1919

2020
# For compiler-builtins we always use a high number of codegen units.
2121
# The goal here is to place every single intrinsic into its own object

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ declare_features! (
382382
(accepted, self_in_typedefs, "1.32.0", Some(49303)),
383383
/// Allows `Self` struct constructor (RFC 2302).
384384
(accepted, self_struct_ctor, "1.32.0", Some(51994)),
385+
/// Allows use of x86 SHA512, SM3 and SM4 target-features and intrinsics
386+
(accepted, sha512_sm_x86, "CURRENT_RUSTC_VERSION", Some(126624)),
385387
/// Shortern the tail expression lifetime
386388
(accepted, shorter_tail_lifetimes, "1.84.0", Some(123739)),
387389
/// Allows using subslice patterns, `[a, .., b]` and `[a, xs @ .., b]`.

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,6 @@ declare_features! (
627627
(unstable, return_type_notation, "1.70.0", Some(109417)),
628628
/// Allows `extern "rust-cold"`.
629629
(unstable, rust_cold_cc, "1.63.0", Some(97544)),
630-
/// Allows use of x86 SHA512, SM3 and SM4 target-features and intrinsics
631-
(unstable, sha512_sm_x86, "1.82.0", Some(126624)),
632630
/// Allows the use of SIMD types in functions declared in `extern` blocks.
633631
(unstable, simd_ffi, "1.0.0", Some(27731)),
634632
/// Allows specialization of implementations (RFC 1210).

compiler/rustc_passes/src/dead.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_middle::ty::{self, TyCtxt};
2222
use rustc_middle::{bug, span_bug};
2323
use rustc_session::lint::builtin::DEAD_CODE;
2424
use rustc_session::lint::{self, LintExpectationId};
25-
use rustc_span::{Symbol, sym};
25+
use rustc_span::{Symbol, kw, sym};
2626

2727
use crate::errors::{
2828
ChangeFields, IgnoredDerivedImpls, MultipleDeadCodes, ParentInfo, UselessAssignment,
@@ -793,6 +793,17 @@ fn check_item<'tcx>(
793793
// global_asm! is always live.
794794
worklist.push((id.owner_id.def_id, ComesFromAllowExpect::No));
795795
}
796+
DefKind::Const => {
797+
let item = tcx.hir_item(id);
798+
if let hir::ItemKind::Const(ident, ..) = item.kind
799+
&& ident.name == kw::Underscore
800+
{
801+
// `const _` is always live, as that syntax only exists for the side effects
802+
// of type checking and evaluating the constant expression, and marking them
803+
// as dead code would defeat that purpose.
804+
worklist.push((id.owner_id.def_id, ComesFromAllowExpect::No));
805+
}
806+
}
796807
_ => {}
797808
}
798809
}

compiler/rustc_target/src/target_features.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
455455
("rdseed", Stable, &[]),
456456
("rtm", Unstable(sym::rtm_target_feature), &[]),
457457
("sha", Stable, &["sse2"]),
458-
("sha512", Unstable(sym::sha512_sm_x86), &["avx2"]),
459-
("sm3", Unstable(sym::sha512_sm_x86), &["avx"]),
460-
("sm4", Unstable(sym::sha512_sm_x86), &["avx2"]),
458+
("sha512", Stable, &["avx2"]),
459+
("sm3", Stable, &["avx"]),
460+
("sm4", Stable, &["avx2"]),
461461
// This cannot actually be toggled, the ABI always fixes it, so it'd make little sense to
462462
// stabilize. It must be in this list for the ABI check to be able to use it.
463463
("soft-float", Stability::Unstable(sym::x87_target_feature), &[]),

library/Cargo.lock

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ dependencies = [
6262
[[package]]
6363
name = "compiler_builtins"
6464
version = "0.1.160"
65-
source = "registry+https://github.com/rust-lang/crates.io-index"
66-
checksum = "6376049cfa92c0aa8b9ac95fae22184b981c658208d4ed8a1dc553cd83612895"
6765
dependencies = [
6866
"cc",
69-
"rustc-std-workspace-core",
67+
"core",
7068
]
7169

7270
[[package]]
@@ -304,6 +302,7 @@ dependencies = [
304302
name = "rustc-std-workspace-core"
305303
version = "1.99.0"
306304
dependencies = [
305+
"compiler_builtins",
307306
"core",
308307
]
309308

library/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ rustc-demangle.opt-level = "s"
5050
rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
5151
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
5252
rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }
53+
compiler_builtins = { path = "compiler-builtins/compiler-builtins" }

library/alloc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bench = false
1616

1717
[dependencies]
1818
core = { path = "../core", public = true }
19-
compiler_builtins = { version = "=0.1.160", features = ['rustc-dep-of-std'] }
19+
compiler_builtins = { path = "../compiler-builtins/compiler-builtins", features = ["rustc-dep-of-std"] }
2020

2121
[features]
2222
compiler-builtins-mem = ['compiler_builtins/mem']

library/alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
#![feature(local_waker)]
132132
#![feature(maybe_uninit_slice)]
133133
#![feature(maybe_uninit_uninit_array_transpose)]
134-
#![feature(nonnull_provenance)]
135134
#![feature(panic_internals)]
136135
#![feature(pattern)]
137136
#![feature(pin_coerce_unsized_trait)]

library/alloctests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#![feature(iter_next_chunk)]
2929
#![feature(maybe_uninit_slice)]
3030
#![feature(maybe_uninit_uninit_array_transpose)]
31-
#![feature(nonnull_provenance)]
3231
#![feature(ptr_alignment_type)]
3332
#![feature(ptr_internals)]
3433
#![feature(sized_type_properties)]

library/compiler-builtins/compiler-builtins/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ doctest = false
1717
test = false
1818

1919
[dependencies]
20-
# For more information on this dependency see
21-
# https://github.com/rust-lang/rust/tree/master/library/rustc-std-workspace-core
22-
core = { version = "1.0.1", optional = true, package = "rustc-std-workspace-core" }
20+
core = { path = "../../core", optional = true }
2321

2422
[build-dependencies]
2523
cc = { optional = true, version = "1.2" }

library/compiler-builtins/compiler-builtins/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ fn main() {
2222

2323
println!("cargo:compiler-rt={}", cwd.join("compiler-rt").display());
2424

25+
println!("cargo::rustc-check-cfg=cfg(kernel_user_helpers)");
26+
println!("cargo::rustc-check-cfg=cfg(feature, values(\"mem-unaligned\"))");
27+
2528
// Emscripten's runtime includes all the builtins
2629
if target.os == "emscripten" {
2730
return;
@@ -47,7 +50,6 @@ fn main() {
4750
}
4851

4952
// These targets have hardware unaligned access support.
50-
println!("cargo::rustc-check-cfg=cfg(feature, values(\"mem-unaligned\"))");
5153
if target.arch.contains("x86_64")
5254
|| target.arch.contains("x86")
5355
|| target.arch.contains("aarch64")
@@ -78,7 +80,6 @@ fn main() {
7880
// Only emit the ARM Linux atomic emulation on pre-ARMv6 architectures. This
7981
// includes the old androideabi. It is deprecated but it is available as a
8082
// rustc target (arm-linux-androideabi).
81-
println!("cargo::rustc-check-cfg=cfg(kernel_user_helpers)");
8283
if llvm_target[0] == "armv4t"
8384
|| llvm_target[0] == "armv5te"
8485
|| target.triple == "arm-linux-androideabi"

library/compiler-builtins/compiler-builtins/src/aarch64_linux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! To avoid breaking backwards compat, C toolchains introduced a concept of "outlined atomics",
55
//! where atomic operations call into the compiler runtime to dispatch between two depending on
66
//! which is supported on the current CPU.
7-
//! See https://community.arm.com/arm-community-blogs/b/tools-software-ides-blog/posts/making-the-most-of-the-arm-architecture-in-gcc-10#:~:text=out%20of%20line%20atomics for more discussion.
7+
//! See <https://community.arm.com/arm-community-blogs/b/tools-software-ides-blog/posts/making-the-most-of-the-arm-architecture-in-gcc-10#:~:text=out%20of%20line%20atomics> for more discussion.
88
//!
99
//! Currently we only support LL/SC, because LSE requires `getauxval` from libc in order to do runtime detection.
1010
//! Use the `compiler-rt` intrinsics if you want LSE support.

library/compiler-builtins/compiler-builtins/src/arm_linux.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ use core::{arch, mem};
44
// Kernel-provided user-mode helper functions:
55
// https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt
66
unsafe fn __kuser_cmpxchg(oldval: u32, newval: u32, ptr: *mut u32) -> bool {
7-
let f: extern "C" fn(u32, u32, *mut u32) -> u32 = mem::transmute(0xffff0fc0usize as *const ());
7+
// FIXME(volatile): the third parameter is a volatile pointer
8+
// SAFETY: kernel docs specify a known address with the given signature
9+
let f = unsafe {
10+
mem::transmute::<_, extern "C" fn(u32, u32, *mut u32) -> u32>(0xffff0fc0usize as *const ())
11+
};
812
f(oldval, newval, ptr) == 0
913
}
1014

1115
unsafe fn __kuser_memory_barrier() {
12-
let f: extern "C" fn() = mem::transmute(0xffff0fa0usize as *const ());
16+
// SAFETY: kernel docs specify a known address with the given signature
17+
let f = unsafe { mem::transmute::<_, extern "C" fn()>(0xffff0fa0usize as *const ()) };
1318
f();
1419
}
1520

@@ -67,8 +72,10 @@ fn insert_aligned(aligned: u32, val: u32, shift: u32, mask: u32) -> u32 {
6772
/// - if `size_of::<T>() == 2`, `ptr` or `ptr` offset by 2 bytes must be valid for a relaxed atomic
6873
/// read of 2 bytes.
6974
/// - if `size_of::<T>() == 4`, `ptr` must be valid for a relaxed atomic read of 4 bytes.
75+
// FIXME: assert some of the preconditions in debug mode
7076
unsafe fn atomic_load_aligned<T>(ptr: *mut u32) -> u32 {
71-
if mem::size_of::<T>() == 4 {
77+
const { assert!(size_of::<T>() <= 4) };
78+
if size_of::<T>() == 4 {
7279
// SAFETY: As `T` has a size of 4, the caller garantees this is sound.
7380
unsafe { AtomicU32::from_ptr(ptr).load(Ordering::Relaxed) }
7481
} else {
@@ -100,11 +107,13 @@ unsafe fn atomic_rmw<T, F: Fn(u32) -> u32, G: Fn(u32, u32) -> u32>(ptr: *mut T,
100107
let (shift, mask) = get_shift_mask(ptr);
101108

102109
loop {
103-
let curval_aligned = atomic_load_aligned::<T>(aligned_ptr);
110+
// FIXME(safety): preconditions review needed
111+
let curval_aligned = unsafe { atomic_load_aligned::<T>(aligned_ptr) };
104112
let curval = extract_aligned(curval_aligned, shift, mask);
105113
let newval = f(curval);
106114
let newval_aligned = insert_aligned(curval_aligned, newval, shift, mask);
107-
if __kuser_cmpxchg(curval_aligned, newval_aligned, aligned_ptr) {
115+
// FIXME(safety): preconditions review needed
116+
if unsafe { __kuser_cmpxchg(curval_aligned, newval_aligned, aligned_ptr) } {
108117
return g(curval, newval);
109118
}
110119
}
@@ -116,13 +125,15 @@ unsafe fn atomic_cmpxchg<T>(ptr: *mut T, oldval: u32, newval: u32) -> u32 {
116125
let (shift, mask) = get_shift_mask(ptr);
117126

118127
loop {
119-
let curval_aligned = atomic_load_aligned::<T>(aligned_ptr);
128+
// FIXME(safety): preconditions review needed
129+
let curval_aligned = unsafe { atomic_load_aligned::<T>(aligned_ptr) };
120130
let curval = extract_aligned(curval_aligned, shift, mask);
121131
if curval != oldval {
122132
return curval;
123133
}
124134
let newval_aligned = insert_aligned(curval_aligned, newval, shift, mask);
125-
if __kuser_cmpxchg(curval_aligned, newval_aligned, aligned_ptr) {
135+
// FIXME(safety): preconditions review needed
136+
if unsafe { __kuser_cmpxchg(curval_aligned, newval_aligned, aligned_ptr) } {
126137
return oldval;
127138
}
128139
}
@@ -132,7 +143,14 @@ macro_rules! atomic_rmw {
132143
($name:ident, $ty:ty, $op:expr, $fetch:expr) => {
133144
intrinsics! {
134145
pub unsafe extern "C" fn $name(ptr: *mut $ty, val: $ty) -> $ty {
135-
atomic_rmw(ptr, |x| $op(x as $ty, val) as u32, |old, new| $fetch(old, new)) as $ty
146+
// FIXME(safety): preconditions review needed
147+
unsafe {
148+
atomic_rmw(
149+
ptr,
150+
|x| $op(x as $ty, val) as u32,
151+
|old, new| $fetch(old, new)
152+
) as $ty
153+
}
136154
}
137155
}
138156
};
@@ -149,7 +167,8 @@ macro_rules! atomic_cmpxchg {
149167
($name:ident, $ty:ty) => {
150168
intrinsics! {
151169
pub unsafe extern "C" fn $name(ptr: *mut $ty, oldval: $ty, newval: $ty) -> $ty {
152-
atomic_cmpxchg(ptr, oldval as u32, newval as u32) as $ty
170+
// FIXME(safety): preconditions review needed
171+
unsafe { atomic_cmpxchg(ptr, oldval as u32, newval as u32) as $ty }
153172
}
154173
}
155174
};
@@ -285,6 +304,7 @@ atomic_cmpxchg!(__sync_val_compare_and_swap_4, u32);
285304

286305
intrinsics! {
287306
pub unsafe extern "C" fn __sync_synchronize() {
288-
__kuser_memory_barrier();
307+
// SAFETY: preconditions are the same as the calling function.
308+
unsafe { __kuser_memory_barrier() };
289309
}
290310
}

library/compiler-builtins/compiler-builtins/src/mem/x86_64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, count: usize) {
6969
"rep movsb",
7070
"sub $7, %rsi",
7171
"sub $7, %rdi",
72-
"mov {qword_count}, %rcx",
72+
"mov {qword_count:r}, %rcx",
7373
"rep movsq",
7474
"test {pre_byte_count:e}, {pre_byte_count:e}",
7575
"add $7, %rsi",
@@ -212,7 +212,7 @@ pub unsafe fn c_string_length(mut s: *const core::ffi::c_char) -> usize {
212212
let x = {
213213
let r;
214214
asm!(
215-
"movdqa ({addr}), {dest}",
215+
"movdqa ({addr:r}), {dest}",
216216
addr = in(reg) s,
217217
dest = out(xmm_reg) r,
218218
options(att_syntax, nostack),
@@ -232,7 +232,7 @@ pub unsafe fn c_string_length(mut s: *const core::ffi::c_char) -> usize {
232232
let x = {
233233
let r;
234234
asm!(
235-
"movdqa ({addr}), {dest}",
235+
"movdqa ({addr:r}), {dest}",
236236
addr = in(reg) s,
237237
dest = out(xmm_reg) r,
238238
options(att_syntax, nostack),

library/core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@
197197
#![feature(riscv_target_feature)]
198198
#![feature(rtm_target_feature)]
199199
#![feature(s390x_target_feature)]
200-
#![feature(sha512_sm_x86)]
201200
#![feature(sse4a_target_feature)]
202201
#![feature(tbm_target_feature)]
203202
#![feature(wasm_target_feature)]

library/core/src/num/niche_types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ define_valid_range_type! {
131131
pub struct NonZeroI32Inner(i32 as u32 in 1..=0xffff_ffff);
132132
pub struct NonZeroI64Inner(i64 as u64 in 1..=0xffffffff_ffffffff);
133133
pub struct NonZeroI128Inner(i128 as u128 in 1..=0xffffffffffffffff_ffffffffffffffff);
134+
135+
pub struct NonZeroCharInner(char as u32 in 1..=0x10ffff);
134136
}
135137

136138
#[cfg(target_pointer_width = "16")]

library/core/src/num/nonzero.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ impl_zeroable_primitive!(
7979
NonZeroI64Inner(i64),
8080
NonZeroI128Inner(i128),
8181
NonZeroIsizeInner(isize),
82+
NonZeroCharInner(char),
8283
);
8384

8485
/// A value that is known not to equal zero.

library/core/src/ptr/non_null.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ impl<T: Sized> NonNull<T> {
8989
/// For more details, see the equivalent method on a raw pointer, [`ptr::without_provenance_mut`].
9090
///
9191
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
92-
#[unstable(feature = "nonnull_provenance", issue = "135243")]
92+
#[stable(feature = "nonnull_provenance", since = "CURRENT_RUSTC_VERSION")]
93+
#[rustc_const_stable(feature = "nonnull_provenance", since = "CURRENT_RUSTC_VERSION")]
9394
#[must_use]
9495
#[inline]
9596
pub const fn without_provenance(addr: NonZero<usize>) -> Self {
@@ -132,7 +133,7 @@ impl<T: Sized> NonNull<T> {
132133
/// For more details, see the equivalent method on a raw pointer, [`ptr::with_exposed_provenance_mut`].
133134
///
134135
/// This is an [Exposed Provenance][crate::ptr#exposed-provenance] API.
135-
#[unstable(feature = "nonnull_provenance", issue = "135243")]
136+
#[stable(feature = "nonnull_provenance", since = "CURRENT_RUSTC_VERSION")]
136137
#[inline]
137138
pub fn with_exposed_provenance(addr: NonZero<usize>) -> Self {
138139
// SAFETY: we know `addr` is non-zero.
@@ -329,7 +330,7 @@ impl<T: ?Sized> NonNull<T> {
329330
/// For more details, see the equivalent method on a raw pointer, [`pointer::expose_provenance`].
330331
///
331332
/// This is an [Exposed Provenance][crate::ptr#exposed-provenance] API.
332-
#[unstable(feature = "nonnull_provenance", issue = "135243")]
333+
#[stable(feature = "nonnull_provenance", since = "CURRENT_RUSTC_VERSION")]
333334
pub fn expose_provenance(self) -> NonZero<usize> {
334335
// SAFETY: The pointer is guaranteed by the type to be non-null,
335336
// meaning that the address will be non-zero.

library/coretests/tests/num/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,19 @@ mod u64;
2222
mod u8;
2323

2424
mod bignum;
25-
2625
mod const_from;
2726
mod dec2flt;
27+
mod float_iter_sum_identity;
2828
mod flt2dec;
29+
mod ieee754;
2930
mod int_log;
3031
mod int_sqrt;
3132
mod midpoint;
33+
mod nan;
34+
mod niche_types;
3235
mod ops;
3336
mod wrapping;
3437

35-
mod float_iter_sum_identity;
36-
mod ieee754;
37-
mod nan;
38-
3938
/// Adds the attribute to all items in the block.
4039
macro_rules! cfg_block {
4140
($(#[$attr:meta]{$($it:item)*})*) => {$($(

0 commit comments

Comments
 (0)