Skip to content

Commit f8dca5c

Browse files
committed
Auto merge of rust-lang#138185 - compiler-errors:rollup-omp1jxu, r=compiler-errors
Rollup of 8 pull requests Successful merges: - rust-lang#136642 (Put the alloc unit tests in a separate alloctests package) - rust-lang#137337 (Add verbatim linker to AIXLinker) - rust-lang#137363 (compiler: factor Windows x86-32 ABI impl into its own file) - rust-lang#137685 (self-contained linker: conservatively default to `-znostart-stop-gc` on x64 linux) - rust-lang#138000 (atomic: clarify that failing conditional RMW operations are not 'writes') - rust-lang#138063 (Improve `-Zunpretty=hir` for parsed attrs) - rust-lang#138137 (setTargetTriple now accepts Triple rather than string) - rust-lang#138173 (Delay bug for negative auto trait rather than ICEing) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f5a1ef7 + 92e7038 commit f8dca5c

Some content is hidden

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

96 files changed

+800
-683
lines changed

compiler/rustc_attr_data_structures/src/lib.rs

+30-22
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,39 @@ pub trait HashStableContext: rustc_ast::HashStableContext + rustc_abi::HashStabl
3535
/// like [`Span`]s and empty tuples, are gracefully skipped so they don't clutter the
3636
/// representation much.
3737
pub trait PrintAttribute {
38-
fn print_something(&self) -> bool;
38+
/// Whether or not this will render as something meaningful, or if it's skipped
39+
/// (which will force the containing struct to also skip printing a comma
40+
/// and the field name).
41+
fn should_render(&self) -> bool;
42+
3943
fn print_attribute(&self, p: &mut Printer);
4044
}
4145

4246
impl<T: PrintAttribute> PrintAttribute for &T {
43-
fn print_something(&self) -> bool {
44-
T::print_something(self)
47+
fn should_render(&self) -> bool {
48+
T::should_render(self)
4549
}
4650

4751
fn print_attribute(&self, p: &mut Printer) {
4852
T::print_attribute(self, p)
4953
}
5054
}
5155
impl<T: PrintAttribute> PrintAttribute for Option<T> {
52-
fn print_something(&self) -> bool {
53-
self.as_ref().is_some_and(|x| x.print_something())
56+
fn should_render(&self) -> bool {
57+
self.as_ref().is_some_and(|x| x.should_render())
5458
}
59+
5560
fn print_attribute(&self, p: &mut Printer) {
5661
if let Some(i) = self {
5762
T::print_attribute(i, p)
5863
}
5964
}
6065
}
6166
impl<T: PrintAttribute> PrintAttribute for ThinVec<T> {
62-
fn print_something(&self) -> bool {
63-
self.is_empty() || self[0].print_something()
67+
fn should_render(&self) -> bool {
68+
self.is_empty() || self[0].should_render()
6469
}
70+
6571
fn print_attribute(&self, p: &mut Printer) {
6672
let mut last_printed = false;
6773
p.word("[");
@@ -70,15 +76,15 @@ impl<T: PrintAttribute> PrintAttribute for ThinVec<T> {
7076
p.word_space(",");
7177
}
7278
i.print_attribute(p);
73-
last_printed = i.print_something();
79+
last_printed = i.should_render();
7480
}
7581
p.word("]");
7682
}
7783
}
7884
macro_rules! print_skip {
7985
($($t: ty),* $(,)?) => {$(
8086
impl PrintAttribute for $t {
81-
fn print_something(&self) -> bool { false }
87+
fn should_render(&self) -> bool { false }
8288
fn print_attribute(&self, _: &mut Printer) { }
8389
})*
8490
};
@@ -87,7 +93,7 @@ macro_rules! print_skip {
8793
macro_rules! print_disp {
8894
($($t: ty),* $(,)?) => {$(
8995
impl PrintAttribute for $t {
90-
fn print_something(&self) -> bool { true }
96+
fn should_render(&self) -> bool { true }
9197
fn print_attribute(&self, p: &mut Printer) {
9298
p.word(format!("{}", self));
9399
}
@@ -97,7 +103,7 @@ macro_rules! print_disp {
97103
macro_rules! print_debug {
98104
($($t: ty),* $(,)?) => {$(
99105
impl PrintAttribute for $t {
100-
fn print_something(&self) -> bool { true }
106+
fn should_render(&self) -> bool { true }
101107
fn print_attribute(&self, p: &mut Printer) {
102108
p.word(format!("{:?}", self));
103109
}
@@ -106,37 +112,39 @@ macro_rules! print_debug {
106112
}
107113

108114
macro_rules! print_tup {
109-
(num_print_something $($ts: ident)*) => { 0 $(+ $ts.print_something() as usize)* };
115+
(num_should_render $($ts: ident)*) => { 0 $(+ $ts.should_render() as usize)* };
110116
() => {};
111117
($t: ident $($ts: ident)*) => {
112118
#[allow(non_snake_case, unused)]
113119
impl<$t: PrintAttribute, $($ts: PrintAttribute),*> PrintAttribute for ($t, $($ts),*) {
114-
fn print_something(&self) -> bool {
120+
fn should_render(&self) -> bool {
115121
let ($t, $($ts),*) = self;
116-
print_tup!(num_print_something $t $($ts)*) != 0
122+
print_tup!(num_should_render $t $($ts)*) != 0
117123
}
118124

119125
fn print_attribute(&self, p: &mut Printer) {
120126
let ($t, $($ts),*) = self;
121-
let parens = print_tup!(num_print_something $t $($ts)*) > 1;
127+
let parens = print_tup!(num_should_render $t $($ts)*) > 1;
122128
if parens {
123-
p.word("(");
129+
p.popen();
124130
}
125131

126-
let mut printed_anything = $t.print_something();
132+
let mut printed_anything = $t.should_render();
127133

128134
$t.print_attribute(p);
129135

130136
$(
131-
if printed_anything && $ts.print_something() {
132-
p.word_space(",");
137+
if $ts.should_render() {
138+
if printed_anything {
139+
p.word_space(",");
140+
}
133141
printed_anything = true;
134142
}
135143
$ts.print_attribute(p);
136144
)*
137145

138146
if parens {
139-
p.word(")");
147+
p.pclose();
140148
}
141149
}
142150
}
@@ -147,5 +155,5 @@ macro_rules! print_tup {
147155

148156
print_tup!(A B C D E F G H);
149157
print_skip!(Span, ());
150-
print_disp!(Symbol, u16, bool, NonZero<u32>);
151-
print_debug!(UintTy, IntTy, Align, AttrStyle, CommentKind, Transparency);
158+
print_disp!(u16, bool, NonZero<u32>);
159+
print_debug!(Symbol, UintTy, IntTy, Align, AttrStyle, CommentKind, Transparency);

compiler/rustc_codegen_cranelift/patches/0029-stdlib-Disable-f16-and-f128-in-compiler-builtins.patch

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ index 7165c3e48af..968552ad435 100644
1212
--- a/library/alloc/Cargo.toml
1313
+++ b/library/alloc/Cargo.toml
1414
@@ -11,7 +11,7 @@ test = { path = "../test" }
15-
edition = "2021"
15+
bench = false
1616

1717
[dependencies]
1818
core = { path = "../core", public = true }
1919
-compiler_builtins = { version = "=0.1.151", features = ['rustc-dep-of-std'] }
2020
+compiler_builtins = { version = "=0.1.151", features = ['rustc-dep-of-std', 'no-f16-f128'] }
2121

22-
[dev-dependencies]
23-
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
22+
[features]
23+
compiler-builtins-mem = ['compiler_builtins/mem']
2424
--
2525
2.34.1
2626

compiler/rustc_codegen_ssa/src/back/link.rs

+29
Original file line numberDiff line numberDiff line change
@@ -3382,6 +3382,35 @@ fn add_lld_args(
33823382
// this, `wasm-component-ld`, which is overridden if this option is passed.
33833383
if !sess.target.is_like_wasm {
33843384
cmd.cc_arg("-fuse-ld=lld");
3385+
3386+
// On ELF platforms like at least x64 linux, GNU ld and LLD have opposite defaults on some
3387+
// section garbage-collection features. For example, the somewhat popular `linkme` crate and
3388+
// its dependents rely in practice on this difference: when using lld, they need `-z
3389+
// nostart-stop-gc` to prevent encapsulation symbols and sections from being
3390+
// garbage-collected.
3391+
//
3392+
// More information about all this can be found in:
3393+
// - https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
3394+
// - https://lld.llvm.org/ELF/start-stop-gc
3395+
//
3396+
// So when using lld, we restore, for now, the traditional behavior to help migration, but
3397+
// will remove it in the future.
3398+
// Since this only disables an optimization, it shouldn't create issues, but is in theory
3399+
// slightly suboptimal. However, it:
3400+
// - doesn't have any visible impact on our benchmarks
3401+
// - reduces the need to disable lld for the crates that depend on this
3402+
//
3403+
// Note that lld can detect some cases where this difference is relied on, and emits a
3404+
// dedicated error to add this link arg. We could make use of this error to emit an FCW. As
3405+
// of writing this, we don't do it, because lld is already enabled by default on nightly
3406+
// without this mitigation: no working project would see the FCW, so we do this to help
3407+
// stabilization.
3408+
//
3409+
// FIXME: emit an FCW if linking fails due its absence, and then remove this link-arg in the
3410+
// future.
3411+
if sess.target.llvm_target == "x86_64-unknown-linux-gnu" {
3412+
cmd.link_arg("-znostart-stop-gc");
3413+
}
33853414
}
33863415

33873416
if !flavor.is_gnu() {

compiler/rustc_codegen_ssa/src/back/linker.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1655,9 +1655,9 @@ impl<'a> Linker for AixLinker<'a> {
16551655
}
16561656
}
16571657

1658-
fn link_dylib_by_name(&mut self, name: &str, _verbatim: bool, _as_needed: bool) {
1658+
fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, _as_needed: bool) {
16591659
self.hint_dynamic();
1660-
self.link_or_cc_arg(format!("-l{name}"));
1660+
self.link_or_cc_arg(if verbatim { String::from(name) } else { format!("-l{name}") });
16611661
}
16621662

16631663
fn link_dylib_by_path(&mut self, path: &Path, _as_needed: bool) {
@@ -1668,7 +1668,7 @@ impl<'a> Linker for AixLinker<'a> {
16681668
fn link_staticlib_by_name(&mut self, name: &str, verbatim: bool, whole_archive: bool) {
16691669
self.hint_static();
16701670
if !whole_archive {
1671-
self.link_or_cc_arg(format!("-l{name}"));
1671+
self.link_or_cc_arg(if verbatim { String::from(name) } else { format!("-l{name}") });
16721672
} else {
16731673
let mut arg = OsString::from("-bkeepfile:");
16741674
arg.push(find_native_static_library(name, verbatim, self.sess));

compiler/rustc_hir_analysis/src/check/always_applicable.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ pub(crate) fn check_negative_auto_trait_impl<'tcx>(
124124
// be implemented here to handle non-ADT rigid types.
125125
Ok(())
126126
} else {
127-
span_bug!(tcx.def_span(impl_def_id), "incoherent impl of negative auto trait");
127+
Err(tcx.dcx().span_delayed_bug(
128+
tcx.def_span(impl_def_id),
129+
"incoherent impl of negative auto trait",
130+
))
128131
}
129132
}
130133
}

compiler/rustc_hir_pretty/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ impl<'a> State<'a> {
118118
self.hardbreak()
119119
}
120120
hir::Attribute::Parsed(pa) => {
121-
self.word("#[attr=\"");
121+
self.word("#[attr = ");
122122
pa.print_attribute(self);
123-
self.word("\")]");
123+
self.word("]");
124124
self.hardbreak()
125125
}
126126
}

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,12 @@ extern "C" LLVMContextRef LLVMRustContextCreate(bool shouldDiscardNames) {
152152
}
153153

154154
extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M,
155-
const char *Triple) {
156-
unwrap(M)->setTargetTriple(Triple::normalize(Triple));
155+
const char *Target) {
156+
#if LLVM_VERSION_GE(21, 0)
157+
unwrap(M)->setTargetTriple(Triple(Triple::normalize(Target)));
158+
#else
159+
unwrap(M)->setTargetTriple(Triple::normalize(Target));
160+
#endif
157161
}
158162

159163
extern "C" void LLVMRustPrintPassTimings(RustStringRef OutBuf) {

compiler/rustc_macros/src/print_attribute.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
1616
let name = field.ident.as_ref().unwrap();
1717
let string_name = name.to_string();
1818
disps.push(quote! {
19-
if __printed_anything && #name.print_something() {
20-
__p.word_space(",");
19+
if #name.should_render() {
20+
if __printed_anything {
21+
__p.word_space(",");
22+
}
23+
__p.word(#string_name);
24+
__p.word_space(":");
2125
__printed_anything = true;
2226
}
23-
__p.word(#string_name);
24-
__p.word_space(":");
2527
#name.print_attribute(__p);
2628
});
2729
field_names.push(name);
@@ -31,10 +33,11 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
3133
quote! { {#(#field_names),*} },
3234
quote! {
3335
__p.word(#string_name);
34-
if true #(&& !#field_names.print_something())* {
36+
if true #(&& !#field_names.should_render())* {
3537
return;
3638
}
3739

40+
__p.nbsp();
3841
__p.word("{");
3942
#(#disps)*
4043
__p.word("}");
@@ -48,8 +51,10 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
4851
for idx in 0..fields_unnamed.unnamed.len() {
4952
let name = format_ident!("f{idx}");
5053
disps.push(quote! {
51-
if __printed_anything && #name.print_something() {
52-
__p.word_space(",");
54+
if #name.should_render() {
55+
if __printed_anything {
56+
__p.word_space(",");
57+
}
5358
__printed_anything = true;
5459
}
5560
#name.print_attribute(__p);
@@ -62,13 +67,13 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
6267
quote! {
6368
__p.word(#string_name);
6469

65-
if true #(&& !#field_names.print_something())* {
70+
if true #(&& !#field_names.should_render())* {
6671
return;
6772
}
6873

69-
__p.word("(");
74+
__p.popen();
7075
#(#disps)*
71-
__p.word(")");
76+
__p.pclose();
7277
},
7378
quote! { true },
7479
)
@@ -138,7 +143,7 @@ pub(crate) fn print_attribute(input: Structure<'_>) -> TokenStream {
138143
input.gen_impl(quote! {
139144
#[allow(unused)]
140145
gen impl PrintAttribute for @Self {
141-
fn print_something(&self) -> bool { #printed }
146+
fn should_render(&self) -> bool { #printed }
142147
fn print_attribute(&self, __p: &mut rustc_ast_pretty::pp::Printer) { #code }
143148
}
144149
})

compiler/rustc_target/src/callconv/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mod sparc64;
3131
mod wasm;
3232
mod x86;
3333
mod x86_64;
34+
mod x86_win32;
3435
mod x86_win64;
3536
mod xtensa;
3637

@@ -649,7 +650,11 @@ impl<'a, Ty> FnAbi<'a, Ty> {
649650
};
650651
let reg_struct_return = cx.x86_abi_opt().reg_struct_return;
651652
let opts = x86::X86Options { flavor, regparm, reg_struct_return };
652-
x86::compute_abi_info(cx, self, opts);
653+
if spec.is_like_msvc {
654+
x86_win32::compute_abi_info(cx, self, opts);
655+
} else {
656+
x86::compute_abi_info(cx, self, opts);
657+
}
653658
}
654659
"x86_64" => match abi {
655660
ExternAbi::SysV64 { .. } => x86_64::compute_abi_info(cx, self),

compiler/rustc_target/src/callconv/x86.rs

+2-22
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ where
3636
if t.abi_return_struct_as_int || opts.reg_struct_return {
3737
// According to Clang, everyone but MSVC returns single-element
3838
// float aggregates directly in a floating-point register.
39-
if !t.is_like_msvc && fn_abi.ret.layout.is_single_fp_element(cx) {
39+
if fn_abi.ret.layout.is_single_fp_element(cx) {
4040
match fn_abi.ret.layout.size.bytes() {
4141
4 => fn_abi.ret.cast_to(Reg::f32()),
4242
8 => fn_abi.ret.cast_to(Reg::f64()),
@@ -64,31 +64,11 @@ where
6464
continue;
6565
}
6666

67-
// FIXME: MSVC 2015+ will pass the first 3 vector arguments in [XYZ]MM0-2
68-
// See https://reviews.llvm.org/D72114 for Clang behavior
69-
7067
let t = cx.target_spec();
7168
let align_4 = Align::from_bytes(4).unwrap();
7269
let align_16 = Align::from_bytes(16).unwrap();
7370

74-
if t.is_like_msvc
75-
&& arg.layout.is_adt()
76-
&& let Some(max_repr_align) = arg.layout.max_repr_align
77-
&& max_repr_align > align_4
78-
{
79-
// MSVC has special rules for overaligned arguments: https://reviews.llvm.org/D72114.
80-
// Summarized here:
81-
// - Arguments with _requested_ alignment > 4 are passed indirectly.
82-
// - For backwards compatibility, arguments with natural alignment > 4 are still passed
83-
// on stack (via `byval`). For example, this includes `double`, `int64_t`,
84-
// and structs containing them, provided they lack an explicit alignment attribute.
85-
assert!(
86-
arg.layout.align.abi >= max_repr_align,
87-
"abi alignment {:?} less than requested alignment {max_repr_align:?}",
88-
arg.layout.align.abi,
89-
);
90-
arg.make_indirect();
91-
} else if arg.layout.is_aggregate() {
71+
if arg.layout.is_aggregate() {
9272
// We need to compute the alignment of the `byval` argument. The rules can be found in
9373
// `X86_32ABIInfo::getTypeStackAlignInBytes` in Clang's `TargetInfo.cpp`. Summarized
9474
// here, they are:

0 commit comments

Comments
 (0)