Skip to content

Commit a201416

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

26 files changed

+203
-31
lines changed

compiler/rustc_abi/src/lib.rs

+12-4
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

+11
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

+1-1
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

+1
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

+27-11
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

+2
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

+2-1
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

+1-1
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

+1-1
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

+1-1
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(),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub(crate) fn target() -> Target {
1010
std: Some(true),
1111
},
1212
pointer_width: 32,
13-
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
13+
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(),
1414
arch: "aarch64".into(),
1515
options: TargetOptions {
1616
abi: "ilp32".into(),

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

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(crate) fn target() -> Target {
1414
data_layout: "E-m:e-p:32:32-i64:64-i128:128-f128:64-n32-S64".into(),
1515
arch: "sparc".into(),
1616
options: TargetOptions {
17+
features: "+v8plus".into(),
1718
cpu: "v9".into(),
1819
endian: Endian::Big,
1920
late_link_args: TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[

compiler/rustc_target/src/target_features.rs

+10
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,14 @@ const IBMZ_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
545545
// tidy-alphabetical-end
546546
];
547547

548+
const SPARC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
549+
// tidy-alphabetical-start
550+
("leoncasa", Unstable(sym::sparc_target_feature), &[]),
551+
("v8plus", Unstable(sym::sparc_target_feature), &[]),
552+
("v9", Unstable(sym::sparc_target_feature), &[]),
553+
// tidy-alphabetical-end
554+
];
555+
548556
/// When rustdoc is running, provide a list of all known features so that all their respective
549557
/// primitives may be documented.
550558
///
@@ -563,6 +571,7 @@ pub fn all_rust_features() -> impl Iterator<Item = (&'static str, Stability)> {
563571
.chain(CSKY_FEATURES)
564572
.chain(LOONGARCH_FEATURES)
565573
.chain(IBMZ_FEATURES)
574+
.chain(SPARC_FEATURES)
566575
.cloned()
567576
.map(|(f, s, _)| (f, s))
568577
}
@@ -582,6 +591,7 @@ impl super::spec::Target {
582591
"csky" => CSKY_FEATURES,
583592
"loongarch64" => LOONGARCH_FEATURES,
584593
"s390x" => IBMZ_FEATURES,
594+
"sparc" | "sparc64" => SPARC_FEATURES,
585595
_ => &[],
586596
}
587597
}

src/etc/rust_analyzer_helix.toml

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# This config uses a separate build directory for rust-analyzer,
2+
# so that r-a's checks don't block user `x` commands and vice-verse.
3+
# R-a's build directory is located in `build/rust-analyzer`.
4+
#
5+
# To build rustfmt and proc macro server for r-a run the following command:
6+
# ```
7+
# x b proc-macro-srv-cli rustfmt --stage 0 --build-dir build/rust-analyzer
8+
# ```
9+
110
[language-server.rust-analyzer.config]
211
linkedProjects = [
312
"Cargo.toml",
@@ -17,16 +26,18 @@ overrideCommand = [
1726
"x.py",
1827
"check",
1928
"--json-output",
29+
"--build-dir",
30+
"build/rust-analyzer",
2031
]
2132

2233
[language-server.rust-analyzer.config.rustfmt]
2334
overrideCommand = [
24-
"build-rust-analyzer/host/rustfmt/bin/rustfmt",
35+
"build/rust-analyzer/host/rustfmt/bin/rustfmt",
2536
"--edition=2021"
2637
]
2738

2839
[language-server.rust-analyzer.config.procMacro]
29-
server = "build-rust-analyzer/host/stage0/libexec/rust-analyzer-proc-macro-srv"
40+
server = "build/rust-analyzer/host/stage0/libexec/rust-analyzer-proc-macro-srv"
3041
enable = true
3142

3243
[language-server.rust-analyzer.config.rustc]
@@ -47,4 +58,6 @@ overrideCommand = [
4758
"x.py",
4859
"check",
4960
"--json-output",
61+
"--build-dir",
62+
"build/rust-analyzer",
5063
]

tests/codegen/function-arguments.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ compile-flags: -O -C no-prepopulate-passes
22
#![crate_type = "lib"]
3+
#![feature(rustc_attrs)]
34
#![feature(dyn_star)]
45
#![feature(allocator_api)]
56

@@ -143,13 +144,28 @@ pub fn indirect_struct(_: S) {}
143144
#[no_mangle]
144145
pub fn borrowed_struct(_: &S) {}
145146

146-
// CHECK: @option_borrow(ptr noalias noundef readonly align 4 dereferenceable_or_null(4) %x)
147+
// CHECK: @option_borrow(ptr noalias noundef readonly align 4 dereferenceable_or_null(4) %_x)
147148
#[no_mangle]
148-
pub fn option_borrow(x: Option<&i32>) {}
149+
pub fn option_borrow(_x: Option<&i32>) {}
149150

150-
// CHECK: @option_borrow_mut(ptr noalias noundef align 4 dereferenceable_or_null(4) %x)
151+
// CHECK: @option_borrow_mut(ptr noalias noundef align 4 dereferenceable_or_null(4) %_x)
151152
#[no_mangle]
152-
pub fn option_borrow_mut(x: Option<&mut i32>) {}
153+
pub fn option_borrow_mut(_x: Option<&mut i32>) {}
154+
155+
// Function that must NOT have `dereferenceable` or `align`.
156+
#[rustc_layout_scalar_valid_range_start(16)]
157+
pub struct RestrictedAddress(&'static i16);
158+
enum E {
159+
A(RestrictedAddress),
160+
B,
161+
C,
162+
}
163+
// If the `nonnull` ever goes missing, you might have to tweak the
164+
// scalar_valid_range on `RestrictedAddress` to get it back. You
165+
// might even have to add a `rustc_layout_scalar_valid_range_end`.
166+
// CHECK: @nonnull_and_nondereferenceable(ptr noundef nonnull %_x)
167+
#[no_mangle]
168+
pub fn nonnull_and_nondereferenceable(_x: E) {}
153169

154170
// CHECK: @raw_struct(ptr noundef %_1)
155171
#[no_mangle]

tests/codegen/try_question_mark_nop.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
//@ compile-flags: -O -Z merge-functions=disabled --edition=2021
22
//@ only-x86_64
33
// FIXME: Remove the `min-llvm-version`.
4+
//@ revisions: NINETEEN TWENTY
5+
//@[NINETEEN] min-llvm-version: 19
6+
//@[NINETEEN] ignore-llvm-version: 20-99
7+
//@[TWENTY] min-llvm-version: 20
48
//@ min-llvm-version: 19
59

610
#![crate_type = "lib"]
@@ -13,8 +17,11 @@ use std::ptr::NonNull;
1317
#[no_mangle]
1418
pub fn option_nop_match_32(x: Option<u32>) -> Option<u32> {
1519
// CHECK: start:
20+
// TWENTY-NEXT: %trunc = trunc nuw i32 %0 to i1
21+
// TWENTY-NEXT: %.2 = select i1 %trunc, i32 %1, i32 undef
1622
// CHECK-NEXT: [[REG1:%.*]] = insertvalue { i32, i32 } poison, i32 %0, 0
17-
// CHECK-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } [[REG1]], i32 %1, 1
23+
// NINETEEN-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } [[REG1]], i32 %1, 1
24+
// TWENTY-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } [[REG1]], i32 %.2, 1
1825
// CHECK-NEXT: ret { i32, i32 } [[REG2]]
1926
match x {
2027
Some(x) => Some(x),
@@ -26,6 +33,8 @@ pub fn option_nop_match_32(x: Option<u32>) -> Option<u32> {
2633
#[no_mangle]
2734
pub fn option_nop_traits_32(x: Option<u32>) -> Option<u32> {
2835
// CHECK: start:
36+
// TWENTY-NEXT: %trunc = trunc nuw i32 %0 to i1
37+
// TWENTY-NEXT: %.1 = select i1 %trunc, i32 %1, i32 undef
2938
// CHECK-NEXT: insertvalue { i32, i32 }
3039
// CHECK-NEXT: insertvalue { i32, i32 }
3140
// CHECK-NEXT: ret { i32, i32 }

tests/ui/abi/sparcv8plus.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//@ revisions: sparc sparcv8plus sparc_cpu_v9 sparc_feature_v8plus sparc_cpu_v9_feature_v8plus
2+
//@[sparc] compile-flags: --target sparc-unknown-none-elf
3+
//@[sparc] needs-llvm-components: sparc
4+
//@[sparcv8plus] compile-flags: --target sparc-unknown-linux-gnu
5+
//@[sparcv8plus] needs-llvm-components: sparc
6+
//@[sparc_cpu_v9] compile-flags: --target sparc-unknown-none-elf -C target-cpu=v9
7+
//@[sparc_cpu_v9] needs-llvm-components: sparc
8+
//@[sparc_feature_v8plus] compile-flags: --target sparc-unknown-none-elf -C target-feature=+v8plus
9+
//@[sparc_feature_v8plus] needs-llvm-components: sparc
10+
//@[sparc_cpu_v9_feature_v8plus] compile-flags: --target sparc-unknown-none-elf -C target-cpu=v9 -C target-feature=+v8plus
11+
//@[sparc_cpu_v9_feature_v8plus] needs-llvm-components: sparc
12+
//@ min-llvm-version: 19
13+
14+
#![crate_type = "rlib"]
15+
#![feature(no_core, rustc_attrs, lang_items)]
16+
#![no_core]
17+
18+
#[lang = "sized"]
19+
trait Sized {}
20+
#[lang = "copy"]
21+
trait Copy {}
22+
23+
#[rustc_builtin_macro]
24+
macro_rules! compile_error {
25+
() => {};
26+
}
27+
28+
#[cfg(all(not(target_feature = "v8plus"), not(target_feature = "v9")))]
29+
compile_error!("-v8plus,-v9");
30+
//[sparc]~^ ERROR -v8plus,-v9
31+
32+
// FIXME: sparc_cpu_v9 should be in "-v8plus,+v9" group (fixed in LLVM 20)
33+
#[cfg(all(target_feature = "v8plus", target_feature = "v9"))]
34+
compile_error!("+v8plus,+v9");
35+
//[sparcv8plus,sparc_cpu_v9_feature_v8plus,sparc_cpu_v9]~^ ERROR +v8plus,+v9
36+
37+
// FIXME: should be rejected
38+
#[cfg(all(target_feature = "v8plus", not(target_feature = "v9")))]
39+
compile_error!("+v8plus,-v9 (FIXME)");
40+
//[sparc_feature_v8plus]~^ ERROR +v8plus,-v9 (FIXME)
41+
42+
#[cfg(all(not(target_feature = "v8plus"), target_feature = "v9"))]
43+
compile_error!("-v8plus,+v9");

tests/ui/abi/sparcv8plus.sparc.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: -v8plus,-v9
2+
--> $DIR/sparcv8plus.rs:29:1
3+
|
4+
LL | compile_error!("-v8plus,-v9");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)