Skip to content

Commit 8044557

Browse files
committed
Auto merge of #132800 - matthiaskrgr:rollup-c1kkj56, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #132552 (Add v9, v8plus, and leoncasa target feature to sparc and use v8plus in create_object_file) - #132745 (pointee_info_at: fix logic for recursing into enums) - #132777 (try_question_mark_nop: update test for LLVM 20) - #132785 (rustc_target: more target string fixes for LLVM 20) - #132794 (Use a separate dir for r-a builds consistently in helix config) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4b198d6 + 70a59ae commit 8044557

26 files changed

+203
-31
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,15 +1743,23 @@ pub enum PointerKind {
17431743
Box { unpin: bool, global: bool },
17441744
}
17451745

1746-
/// Note that this information is advisory only, and backends are free to ignore it.
1747-
/// It can only be used to encode potential optimizations, but no critical information.
1746+
/// Encodes extra information we have about a pointer.
1747+
/// Note that this information is advisory only, and backends are free to ignore it:
1748+
/// if the information is wrong, that can cause UB, but if the information is absent,
1749+
/// that must always be okay.
17481750
#[derive(Copy, Clone, Debug)]
17491751
pub struct PointeeInfo {
1750-
pub size: Size,
1751-
pub align: Align,
17521752
/// If this is `None`, then this is a raw pointer, so size and alignment are not guaranteed to
17531753
/// be reliable.
17541754
pub safe: Option<PointerKind>,
1755+
/// If `safe` is `Some`, then the pointer is either null or dereferenceable for this many bytes.
1756+
/// On a function argument, "dereferenceable" here means "dereferenceable for the entire duration
1757+
/// of this function call", i.e. it is UB for the memory that this pointer points to to be freed
1758+
/// while this function is still running.
1759+
/// The size can be zero if the pointer is not dereferenceable.
1760+
pub size: Size,
1761+
/// If `safe` is `Some`, then the pointer is aligned as indicated.
1762+
pub align: Align,
17551763
}
17561764

17571765
impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
228228
"x86"
229229
} else if sess.target.arch == "arm64ec" {
230230
"aarch64"
231+
} else if sess.target.arch == "sparc64" {
232+
"sparc"
231233
} else {
232234
&*sess.target.arch
233235
};
@@ -280,6 +282,13 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
280282
// Support for `wide-arithmetic` will first land in LLVM 20 as part of
281283
// llvm/llvm-project#111598
282284
("wasm32" | "wasm64", "wide-arithmetic") if get_version() < (20, 0, 0) => None,
285+
("sparc", "leoncasa") => Some(LLVMFeature::new("hasleoncasa")),
286+
// In LLVM 19, there is no `v8plus` feature and `v9` means "SPARC-V9 instruction available and SPARC-V8+ ABI used".
287+
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp#L27-L28
288+
// Before LLVM 19, there is no `v8plus` feature and `v9` means "SPARC-V9 instruction available".
289+
// https://github.com/llvm/llvm-project/blob/llvmorg-18.1.0/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp#L26
290+
("sparc", "v8plus") if get_version().0 == 19 => Some(LLVMFeature::new("v9")),
291+
("sparc", "v8plus") if get_version().0 < 19 => None,
283292
(_, s) => Some(LLVMFeature::new(s)),
284293
}
285294
}
@@ -619,6 +628,8 @@ pub(crate) fn global_llvm_features(
619628
.features
620629
.split(',')
621630
.filter(|v| !v.is_empty() && backend_feature_name(sess, v).is_some())
631+
// Drop +v8plus feature introduced in LLVM 20.
632+
.filter(|v| *v != "+v8plus" || get_version() >= (20, 0, 0))
622633
.map(String::from),
623634
);
624635

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
212212
"riscv32" => (Architecture::Riscv32, None),
213213
"riscv64" => (Architecture::Riscv64, None),
214214
"sparc" => {
215-
if sess.target.options.cpu == "v9" {
215+
if sess.unstable_target_features.contains(&sym::v8plus) {
216216
// Target uses V8+, aka EM_SPARC32PLUS, aka 64-bit V9 but in 32-bit mode
217217
(Architecture::Sparc32Plus, None)
218218
} else {

compiler/rustc_feature/src/unstable.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ declare_features! (
336336
(unstable, riscv_target_feature, "1.45.0", Some(44839)),
337337
(unstable, rtm_target_feature, "1.35.0", Some(44839)),
338338
(unstable, s390x_target_feature, "1.82.0", Some(44839)),
339+
(unstable, sparc_target_feature, "CURRENT_RUSTC_VERSION", Some(132783)),
339340
(unstable, sse4a_target_feature, "1.27.0", Some(44839)),
340341
(unstable, tbm_target_feature, "1.27.0", Some(44839)),
341342
(unstable, wasm_target_feature, "1.30.0", Some(44839)),

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,25 +1011,41 @@ where
10111011
}
10121012

10131013
_ => {
1014-
let mut data_variant = match this.variants {
1014+
let mut data_variant = match &this.variants {
10151015
// Within the discriminant field, only the niche itself is
10161016
// always initialized, so we only check for a pointer at its
10171017
// offset.
10181018
//
1019-
// If the niche is a pointer, it's either valid (according
1020-
// to its type), or null (which the niche field's scalar
1021-
// validity range encodes). This allows using
1022-
// `dereferenceable_or_null` for e.g., `Option<&T>`, and
1023-
// this will continue to work as long as we don't start
1024-
// using more niches than just null (e.g., the first page of
1025-
// the address space, or unaligned pointers).
1019+
// Our goal here is to check whether this represents a
1020+
// "dereferenceable or null" pointer, so we need to ensure
1021+
// that there is only one other variant, and it must be null.
1022+
// Below, we will then check whether the pointer is indeed
1023+
// dereferenceable.
10261024
Variants::Multiple {
1027-
tag_encoding: TagEncoding::Niche { untagged_variant, .. },
1025+
tag_encoding:
1026+
TagEncoding::Niche { untagged_variant, niche_variants, niche_start },
10281027
tag_field,
1028+
variants,
10291029
..
1030-
} if this.fields.offset(tag_field) == offset => {
1031-
Some(this.for_variant(cx, untagged_variant))
1030+
} if variants.len() == 2 && this.fields.offset(*tag_field) == offset => {
1031+
let tagged_variant = if untagged_variant.as_u32() == 0 {
1032+
VariantIdx::from_u32(1)
1033+
} else {
1034+
VariantIdx::from_u32(0)
1035+
};
1036+
assert_eq!(tagged_variant, *niche_variants.start());
1037+
if *niche_start == 0 {
1038+
// The other variant is encoded as "null", so we can recurse searching for
1039+
// a pointer here. This relies on the fact that the codegen backend
1040+
// only adds "dereferenceable" if there's also a "nonnull" proof,
1041+
// and that null is aligned for all alignments so it's okay to forward
1042+
// the pointer's alignment.
1043+
Some(this.for_variant(cx, *untagged_variant))
1044+
} else {
1045+
None
1046+
}
10321047
}
1048+
Variants::Multiple { .. } => None,
10331049
_ => Some(this),
10341050
};
10351051

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,7 @@ symbols! {
18671867
slice_patterns,
18681868
slicing_syntax,
18691869
soft,
1870+
sparc_target_feature,
18701871
specialization,
18711872
speed,
18721873
spotlight,
@@ -2109,6 +2110,7 @@ symbols! {
21092110
usize_legacy_fn_max_value,
21102111
usize_legacy_fn_min_value,
21112112
usize_legacy_mod,
2113+
v8plus,
21122114
va_arg,
21132115
va_copy,
21142116
va_end,

compiler/rustc_target/src/callconv/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ pub struct ArgAttributes {
143143
pub regular: ArgAttribute,
144144
pub arg_ext: ArgExtension,
145145
/// The minimum size of the pointee, guaranteed to be valid for the duration of the whole call
146-
/// (corresponding to LLVM's dereferenceable and dereferenceable_or_null attributes).
146+
/// (corresponding to LLVM's dereferenceable_or_null attributes, i.e., it is okay for this to be
147+
/// set on a null pointer, but all non-null pointers must be dereferenceable).
147148
pub pointee_size: Size,
148149
pub pointee_align: Option<Align>,
149150
}

compiler/rustc_target/src/spec/targets/aarch64_be_unknown_linux_gnu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(crate) fn target() -> Target {
1111
std: Some(true),
1212
},
1313
pointer_width: 64,
14-
data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
14+
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(),
1515
arch: "aarch64".into(),
1616
options: TargetOptions {
1717
features: "+v8a,+outline-atomics".into(),

compiler/rustc_target/src/spec/targets/aarch64_be_unknown_linux_gnu_ilp32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) fn target() -> Target {
1414
std: Some(true),
1515
},
1616
pointer_width: 32,
17-
data_layout: "E-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
17+
data_layout: "E-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
1818
arch: "aarch64".into(),
1919
options: TargetOptions {
2020
abi: "ilp32".into(),

compiler/rustc_target/src/spec/targets/aarch64_be_unknown_netbsd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(crate) fn target() -> Target {
1111
std: Some(true),
1212
},
1313
pointer_width: 64,
14-
data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
14+
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(),
1515
arch: "aarch64".into(),
1616
options: TargetOptions {
1717
mcount: "__mcount".into(),

0 commit comments

Comments
 (0)