Skip to content

Commit 91ee6a4

Browse files
committed
Auto merge of #145886 - GuillaumeGomez:rollup-9qv7jhv, r=GuillaumeGomez
Rollup of 11 pull requests Successful merges: - #144373 (remove deprecated Error::description in impls) - #144551 (Add aarch64_be-unknown-linux-musl target) - #145076 (Add new Tier-3 target: riscv64a23-unknown-linux-gnu) - #145481 (Add parentheses for closure when suggesting calling closure) - #145596 (Losslessly optimize PNG files) - #145615 (Fix doc of `std::os::windows::io::BorrowedSocket::borrow_raw`) - #145841 (Always build miri for the host in `x run miri`) - #145861 (bootstrap: vendor `clippy_test_deps` too) - #145863 (formatting_options: Make all methods `const`) - #145867 (cg_llvm: Assert that LLVM range-attribute values don't exceed 128 bits) - #145875 (Make bootstrap command caching opt-in) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5ab6924 + 0f30dcc commit 91ee6a4

File tree

84 files changed

+486
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+486
-445
lines changed

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,11 +1929,17 @@ unsafe extern "C" {
19291929
C: &Context,
19301930
effects: MemoryEffects,
19311931
) -> &Attribute;
1932+
/// ## Safety
1933+
/// - Each of `LowerWords` and `UpperWords` must point to an array that is
1934+
/// long enough to fully define an integer of size `NumBits`, i.e. each
1935+
/// pointer must point to `NumBits.div_ceil(64)` elements or more.
1936+
/// - The implementation will make its own copy of the pointed-to `u64`
1937+
/// values, so the pointers only need to outlive this function call.
19321938
pub(crate) fn LLVMRustCreateRangeAttribute(
19331939
C: &Context,
1934-
num_bits: c_uint,
1935-
lower_words: *const u64,
1936-
upper_words: *const u64,
1940+
NumBits: c_uint,
1941+
LowerWords: *const u64,
1942+
UpperWords: *const u64,
19371943
) -> &Attribute;
19381944

19391945
// Operations on functions

compiler/rustc_codegen_llvm/src/llvm/mod.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,26 @@ pub(crate) fn CreateAllocKindAttr(llcx: &Context, kind_arg: AllocKindFlags) -> &
112112

113113
pub(crate) fn CreateRangeAttr(llcx: &Context, size: Size, range: WrappingRange) -> &Attribute {
114114
let lower = range.start;
115+
// LLVM treats the upper bound as exclusive, but allows wrapping.
115116
let upper = range.end.wrapping_add(1);
116-
let lower_words = [lower as u64, (lower >> 64) as u64];
117-
let upper_words = [upper as u64, (upper >> 64) as u64];
117+
118+
// Pass each `u128` endpoint value as a `[u64; 2]` array, least-significant part first.
119+
let as_u64_array = |x: u128| [x as u64, (x >> 64) as u64];
120+
let lower_words: [u64; 2] = as_u64_array(lower);
121+
let upper_words: [u64; 2] = as_u64_array(upper);
122+
123+
// To ensure that LLVM doesn't try to read beyond the `[u64; 2]` arrays,
124+
// we must explicitly check that `size_bits` does not exceed 128.
125+
let size_bits = size.bits();
126+
assert!(size_bits <= 128);
127+
// More robust assertions that are redundant with `size_bits <= 128` and
128+
// should be optimized away.
129+
assert!(size_bits.div_ceil(64) <= u64::try_from(lower_words.len()).unwrap());
130+
assert!(size_bits.div_ceil(64) <= u64::try_from(upper_words.len()).unwrap());
131+
let size_bits = c_uint::try_from(size_bits).unwrap();
132+
118133
unsafe {
119-
LLVMRustCreateRangeAttribute(
120-
llcx,
121-
size.bits().try_into().unwrap(),
122-
lower_words.as_ptr(),
123-
upper_words.as_ptr(),
124-
)
134+
LLVMRustCreateRangeAttribute(llcx, size_bits, lower_words.as_ptr(), upper_words.as_ptr())
125135
}
126136
}
127137

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
279279
}
280280
("loongarch32" | "loongarch64", "32s") if get_version().0 < 21 => None,
281281
// Filter out features that are not supported by the current LLVM version
282-
("riscv32" | "riscv64", "zacas") if get_version().0 < 20 => None,
282+
("riscv32" | "riscv64", "zacas" | "rva23u64" | "supm") if get_version().0 < 20 => None,
283283
(
284284
"s390x",
285285
"message-security-assist-extension12"

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ extern "C" LLVMAttributeRef
488488
LLVMRustCreateRangeAttribute(LLVMContextRef C, unsigned NumBits,
489489
const uint64_t LowerWords[],
490490
const uint64_t UpperWords[]) {
491+
// FIXME(Zalathar): There appears to be no stable guarantee that C++
492+
// `AttrKind` values correspond directly to the `unsigned KindID` values
493+
// accepted by LLVM-C API functions, though in practice they currently do.
491494
return LLVMCreateConstantRangeAttribute(C, Attribute::Range, NumBits,
492495
LowerWords, UpperWords);
493496
}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,7 @@ supported_targets! {
19541954
("armv7-unknown-linux-musleabihf", armv7_unknown_linux_musleabihf),
19551955
("aarch64-unknown-linux-gnu", aarch64_unknown_linux_gnu),
19561956
("aarch64-unknown-linux-musl", aarch64_unknown_linux_musl),
1957+
("aarch64_be-unknown-linux-musl", aarch64_be_unknown_linux_musl),
19571958
("x86_64-unknown-linux-musl", x86_64_unknown_linux_musl),
19581959
("i686-unknown-linux-musl", i686_unknown_linux_musl),
19591960
("i586-unknown-linux-musl", i586_unknown_linux_musl),
@@ -2149,6 +2150,7 @@ supported_targets! {
21492150
("riscv64gc-unknown-none-elf", riscv64gc_unknown_none_elf),
21502151
("riscv64gc-unknown-linux-gnu", riscv64gc_unknown_linux_gnu),
21512152
("riscv64gc-unknown-linux-musl", riscv64gc_unknown_linux_musl),
2153+
("riscv64a23-unknown-linux-gnu", riscv64a23_unknown_linux_gnu),
21522154

21532155
("sparc-unknown-none-elf", sparc_unknown_none_elf),
21542156

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use rustc_abi::Endian;
2+
3+
use crate::spec::{
4+
FramePointer, SanitizerSet, StackProbeType, Target, TargetMetadata, TargetOptions, base,
5+
};
6+
7+
pub(crate) fn target() -> Target {
8+
let mut base = base::linux_musl::opts();
9+
base.max_atomic_width = Some(128);
10+
base.supports_xray = true;
11+
base.features = "+v8a,+outline-atomics".into();
12+
base.stack_probes = StackProbeType::Inline;
13+
base.supported_sanitizers = SanitizerSet::ADDRESS
14+
| SanitizerSet::CFI
15+
| SanitizerSet::LEAK
16+
| SanitizerSet::MEMORY
17+
| SanitizerSet::THREAD;
18+
19+
Target {
20+
llvm_target: "aarch64_be-unknown-linux-musl".into(),
21+
metadata: TargetMetadata {
22+
description: Some("ARM64 Linux (big-endian) with musl-libc 1.2.5".into()),
23+
tier: Some(3),
24+
host_tools: Some(false),
25+
std: Some(true),
26+
},
27+
pointer_width: 64,
28+
data_layout: "E-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
29+
arch: "aarch64".into(),
30+
options: TargetOptions {
31+
// the AAPCS64 expects use of non-leaf frame pointers per
32+
// https://github.com/ARM-software/abi-aa/blob/4492d1570eb70c8fd146623e0db65b2d241f12e7/aapcs64/aapcs64.rst#the-frame-pointer
33+
// and we tend to encounter interesting bugs in AArch64 unwinding code if we do not
34+
frame_pointer: FramePointer::NonLeaf,
35+
mcount: "\u{1}_mcount".into(),
36+
endian: Endian::Big,
37+
..base
38+
},
39+
}
40+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::borrow::Cow;
2+
3+
use crate::spec::{CodeModel, SplitDebuginfo, Target, TargetMetadata, TargetOptions, base};
4+
5+
pub(crate) fn target() -> Target {
6+
Target {
7+
llvm_target: "riscv64-unknown-linux-gnu".into(),
8+
metadata: TargetMetadata {
9+
description: Some("RISC-V Linux (kernel 6.8.0, glibc 2.39)".into()),
10+
tier: Some(3),
11+
host_tools: Some(true),
12+
std: Some(true),
13+
},
14+
pointer_width: 64,
15+
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(),
16+
arch: "riscv64".into(),
17+
options: TargetOptions {
18+
code_model: Some(CodeModel::Medium),
19+
cpu: "generic-rv64".into(),
20+
features: "+rva23u64".into(),
21+
llvm_abiname: "lp64d".into(),
22+
max_atomic_width: Some(64),
23+
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
24+
..base::linux_gnu::opts()
25+
},
26+
}
27+
}

compiler/rustc_target/src/target_features.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,49 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
601601
),
602602
("m", Stable, &[]),
603603
("relax", Unstable(sym::riscv_target_feature), &[]),
604+
(
605+
"rva23u64",
606+
Unstable(sym::riscv_target_feature),
607+
&[
608+
"m",
609+
"a",
610+
"f",
611+
"d",
612+
"c",
613+
"b",
614+
"v",
615+
"zicsr",
616+
"zicntr",
617+
"zihpm",
618+
"ziccif",
619+
"ziccrse",
620+
"ziccamoa",
621+
"zicclsm",
622+
"zic64b",
623+
"za64rs",
624+
"zihintpause",
625+
"zba",
626+
"zbb",
627+
"zbs",
628+
"zicbom",
629+
"zicbop",
630+
"zicboz",
631+
"zfhmin",
632+
"zkt",
633+
"zvfhmin",
634+
"zvbb",
635+
"zvkt",
636+
"zihintntl",
637+
"zicond",
638+
"zimop",
639+
"zcmop",
640+
"zcb",
641+
"zfa",
642+
"zawrs",
643+
"supm",
644+
],
645+
),
646+
("supm", Unstable(sym::riscv_target_feature), &[]),
604647
("unaligned-scalar-mem", Unstable(sym::riscv_target_feature), &[]),
605648
("unaligned-vector-mem", Unstable(sym::riscv_target_feature), &[]),
606649
("v", Unstable(sym::riscv_target_feature), &["zvl128b", "zve64d"]),

compiler/rustc_thread_pool/src/lib.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -787,18 +787,7 @@ impl ThreadPoolBuildError {
787787
}
788788
}
789789

790-
const GLOBAL_POOL_ALREADY_INITIALIZED: &str =
791-
"The global thread pool has already been initialized.";
792-
793790
impl Error for ThreadPoolBuildError {
794-
#[allow(deprecated)]
795-
fn description(&self) -> &str {
796-
match self.kind {
797-
ErrorKind::GlobalPoolAlreadyInitialized => GLOBAL_POOL_ALREADY_INITIALIZED,
798-
ErrorKind::IOError(ref e) => e.description(),
799-
}
800-
}
801-
802791
fn source(&self) -> Option<&(dyn Error + 'static)> {
803792
match &self.kind {
804793
ErrorKind::GlobalPoolAlreadyInitialized => None,
@@ -810,7 +799,9 @@ impl Error for ThreadPoolBuildError {
810799
impl fmt::Display for ThreadPoolBuildError {
811800
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
812801
match &self.kind {
813-
ErrorKind::GlobalPoolAlreadyInitialized => GLOBAL_POOL_ALREADY_INITIALIZED.fmt(f),
802+
ErrorKind::GlobalPoolAlreadyInitialized => {
803+
"The global thread pool has already been initialized.".fmt(f)
804+
}
814805
ErrorKind::IOError(e) => e.fmt(f),
815806
}
816807
}

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -820,16 +820,20 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
820820
if matches!(obligation.cause.code(), ObligationCauseCode::FunctionArg { .. })
821821
&& obligation.cause.span.can_be_used_for_suggestions()
822822
{
823+
let (span, sugg) = if let Some(snippet) =
824+
self.tcx.sess.source_map().span_to_snippet(obligation.cause.span).ok()
825+
&& snippet.starts_with("|")
826+
{
827+
(obligation.cause.span, format!("({snippet})({args})"))
828+
} else {
829+
(obligation.cause.span.shrink_to_hi(), format!("({args})"))
830+
};
831+
823832
// When the obligation error has been ensured to have been caused by
824833
// an argument, the `obligation.cause.span` points at the expression
825834
// of the argument, so we can provide a suggestion. Otherwise, we give
826835
// a more general note.
827-
err.span_suggestion_verbose(
828-
obligation.cause.span.shrink_to_hi(),
829-
msg,
830-
format!("({args})"),
831-
Applicability::HasPlaceholders,
832-
);
836+
err.span_suggestion_verbose(span, msg, sugg, Applicability::HasPlaceholders);
833837
} else if let DefIdOrName::DefId(def_id) = def_id_or_name {
834838
let name = match self.tcx.hir_get_if_local(def_id) {
835839
Some(hir::Node::Expr(hir::Expr {

0 commit comments

Comments
 (0)