Skip to content

Commit 43a2166

Browse files
committed
Auto merge of #145949 - jhpratt:rollup-smzd7tr, r=jhpratt
Rollup of 5 pull requests Successful merges: - #145382 (Add assembly test for `-Zreg-struct-return` option) - #145746 (Fix STD build failing for target_os = "espidf") - #145826 (Use AcceptContext in AttribueParser::check_target) - #145894 (Ensure the coordinator thread terminates before its channels drop) - #145946 (Remove unnecessary `[dependencies.unicode-properties]` entries.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d36f964 + 27d6005 commit 43a2166

File tree

8 files changed

+179
-47
lines changed

8 files changed

+179
-47
lines changed

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
273273
(accept.accept_fn)(&mut cx, args);
274274
if !matches!(cx.stage.should_emit(), ShouldEmit::Nothing) {
275275
Self::check_type(accept.attribute_type, target, &mut cx);
276-
self.check_target(
277-
path.get_attribute_path(),
278-
attr.span,
279-
&accept.allowed_targets,
280-
target,
281-
target_id,
282-
&mut emit_lint,
283-
);
276+
Self::check_target(&accept.allowed_targets, target, &mut cx);
284277
}
285278
}
286279
} else {

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use std::borrow::Cow;
33
use rustc_ast::AttrStyle;
44
use rustc_errors::DiagArgValue;
55
use rustc_feature::{AttributeType, Features};
6-
use rustc_hir::lints::{AttributeLint, AttributeLintKind};
7-
use rustc_hir::{AttrPath, MethodKind, Target};
8-
use rustc_span::Span;
6+
use rustc_hir::lints::AttributeLintKind;
7+
use rustc_hir::{MethodKind, Target};
98

109
use crate::AttributeParser;
1110
use crate::context::{AcceptContext, Stage};
@@ -71,38 +70,34 @@ pub(crate) enum Policy {
7170

7271
impl<'sess, S: Stage> AttributeParser<'sess, S> {
7372
pub(crate) fn check_target(
74-
&self,
75-
attr_name: AttrPath,
76-
attr_span: Span,
7773
allowed_targets: &AllowedTargets,
7874
target: Target,
79-
target_id: S::Id,
80-
mut emit_lint: impl FnMut(AttributeLint<S::Id>),
75+
cx: &mut AcceptContext<'_, 'sess, S>,
8176
) {
8277
match allowed_targets.is_allowed(target) {
8378
AllowedResult::Allowed => {}
8479
AllowedResult::Warn => {
8580
let allowed_targets = allowed_targets.allowed_targets();
86-
let (applied, only) =
87-
allowed_targets_applied(allowed_targets, target, self.features);
88-
emit_lint(AttributeLint {
89-
id: target_id,
90-
span: attr_span,
91-
kind: AttributeLintKind::InvalidTarget {
92-
name: attr_name,
81+
let (applied, only) = allowed_targets_applied(allowed_targets, target, cx.features);
82+
let name = cx.attr_path.clone();
83+
let attr_span = cx.attr_span;
84+
cx.emit_lint(
85+
AttributeLintKind::InvalidTarget {
86+
name,
9387
target,
9488
only: if only { "only " } else { "" },
9589
applied,
9690
},
97-
});
91+
attr_span,
92+
);
9893
}
9994
AllowedResult::Error => {
10095
let allowed_targets = allowed_targets.allowed_targets();
101-
let (applied, only) =
102-
allowed_targets_applied(allowed_targets, target, self.features);
103-
self.dcx().emit_err(InvalidTarget {
104-
span: attr_span,
105-
name: attr_name,
96+
let (applied, only) = allowed_targets_applied(allowed_targets, target, cx.features);
97+
let name = cx.attr_path.clone();
98+
cx.dcx().emit_err(InvalidTarget {
99+
span: cx.attr_span.clone(),
100+
name,
106101
target: target.plural_name(),
107102
only: if only { "only " } else { "" },
108103
applied: DiagArgValue::StrListSepByAnd(

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,10 +1957,13 @@ impl<B: ExtraBackendMethods> Drop for Coordinator<B> {
19571957
pub struct OngoingCodegen<B: ExtraBackendMethods> {
19581958
pub backend: B,
19591959
pub crate_info: CrateInfo,
1960-
pub codegen_worker_receive: Receiver<CguMessage>,
1961-
pub shared_emitter_main: SharedEmitterMain,
19621960
pub output_filenames: Arc<OutputFilenames>,
1961+
// Field order below is intended to terminate the coordinator thread before two fields below
1962+
// drop and prematurely close channels used by coordinator thread. See `Coordinator`'s
1963+
// `Drop` implementation for more info.
19631964
pub coordinator: Coordinator<B>,
1965+
pub codegen_worker_receive: Receiver<CguMessage>,
1966+
pub shared_emitter_main: SharedEmitterMain,
19641967
}
19651968

19661969
impl<B: ExtraBackendMethods> OngoingCodegen<B> {

compiler/rustc_data_structures/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ena = "0.14.3"
1313
indexmap = "2.4.0"
1414
jobserver_crate = { version = "0.1.28", package = "jobserver" }
1515
measureme = "12.0.1"
16+
parking_lot = "0.12"
1617
rustc-hash = "2.0.0"
1718
rustc-stable-hash = { version = "0.1.0", features = ["nightly"] }
1819
rustc_arena = { path = "../rustc_arena" }
@@ -34,9 +35,6 @@ version = "0.15.2"
3435
default-features = false
3536
features = ["nightly"] # for may_dangle
3637

37-
[dependencies.parking_lot]
38-
version = "0.12"
39-
4038
[target.'cfg(windows)'.dependencies.windows]
4139
version = "0.61.0"
4240
features = [

compiler/rustc_lexer/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ Rust lexer used by rustc. No stability guarantees are provided.
1515
# Note that this crate purposefully does not depend on other rustc crates
1616
[dependencies]
1717
memchr.workspace = true
18+
unicode-properties = { version = "0.1.0", default-features = false, features = ["emoji"] }
1819
unicode-xid = "0.2.0"
1920

20-
[dependencies.unicode-properties]
21-
version = "0.1.0"
22-
default-features = false
23-
features = ["emoji"]
24-
2521
[dev-dependencies]
2622
expect-test = "1.4.0"

compiler/rustc_target/Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
bitflags.workspace = true
9+
object = { version = "0.37.0", default-features = false, features = ["elf", "macho"] }
910
rustc_abi = { path = "../rustc_abi" }
1011
rustc_data_structures = { path = "../rustc_data_structures" }
1112
rustc_error_messages = { path = "../rustc_error_messages" }
@@ -20,9 +21,3 @@ serde_path_to_error = "0.1.17"
2021
tracing.workspace = true
2122
# tidy-alphabetical-end
2223

23-
[dependencies.object]
24-
# tidy-alphabetical-start
25-
default-features = false
26-
features = ["elf", "macho"]
27-
version = "0.37.0"
28-
# tidy-alphabetical-end

library/std/src/sys/fs/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,18 @@ pub fn set_permissions(path: &Path, perm: FilePermissions) -> io::Result<()> {
117117
#[cfg(unix)]
118118
pub fn set_permissions_nofollow(path: &Path, perm: crate::fs::Permissions) -> io::Result<()> {
119119
use crate::fs::OpenOptions;
120-
use crate::os::unix::fs::OpenOptionsExt;
121120

122-
OpenOptions::new().custom_flags(libc::O_NOFOLLOW).open(path)?.set_permissions(perm)
121+
let mut options = OpenOptions::new();
122+
123+
// ESP-IDF and Horizon do not support O_NOFOLLOW, so we skip setting it.
124+
// Their filesystems do not have symbolic links, so no special handling is required.
125+
#[cfg(not(any(target_os = "espidf", target_os = "horizon")))]
126+
{
127+
use crate::os::unix::fs::OpenOptionsExt;
128+
options.custom_flags(libc::O_NOFOLLOW);
129+
}
130+
131+
options.open(path)?.set_permissions(perm)
123132
}
124133

125134
#[cfg(not(unix))]
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
//! Tests that -Zreg-struct-return changes ABI for small struct returns
2+
//! from hidden-pointer convention to register-return on x86_32.
3+
//! This test covers:
4+
//! * Callee side, verifying that the structs are correctly loaded into registers when
5+
//! `-Zreg-struct-return` is activated
6+
//! * Caller side, verifying callers do receive returned structs in registers when
7+
//! `-Zreg-struct-return` is activated
8+
//@ add-core-stubs
9+
//@ assembly-output: emit-asm
10+
//@ compile-flags: -O --target=i686-unknown-linux-gnu -Crelocation-model=static
11+
//@ revisions: WITH WITHOUT
12+
//@[WITH] compile-flags: -Zreg-struct-return
13+
//@ needs-llvm-components: x86
14+
15+
#![feature(no_core)]
16+
#![no_std]
17+
#![no_core]
18+
#![crate_type = "lib"]
19+
20+
extern crate minicore;
21+
use minicore::*;
22+
23+
// Verifies ABI changes for small structs, where both fields fit into one register.
24+
// WITH is expected to use register return, WITHOUT should use hidden pointer.
25+
mod Small {
26+
struct SmallStruct {
27+
a: i8,
28+
b: i8,
29+
}
30+
31+
unsafe extern "C" {
32+
fn small() -> SmallStruct;
33+
}
34+
35+
#[unsafe(no_mangle)]
36+
pub unsafe extern "C" fn small_callee() -> SmallStruct {
37+
// (42 << 8) | 42 = 10794
38+
39+
// WITH-LABEL: small_callee
40+
// WITH: movw $10794, %ax
41+
// WITH: retl
42+
43+
// WITHOUT-LABEL: small_callee
44+
// WITHOUT: movl 4(%esp), %e{{.*}}
45+
// WITHOUT: movw $10794, (%e{{.*}})
46+
// WITHOUT: retl $4
47+
SmallStruct { a: 42, b: 42 }
48+
}
49+
50+
#[unsafe(no_mangle)]
51+
pub unsafe extern "C" fn small_caller(dst: &mut SmallStruct) {
52+
// WITH-LABEL: small_caller
53+
// WITH: calll small
54+
// WITH: movw %ax, (%e{{.*}})
55+
56+
// WITHOUT-LABEL: small_caller
57+
// WITHOUT: calll small
58+
// WITHOUT: movzwl {{.*}}(%esp), %e[[TMP:..]]
59+
// WITHOUT: movw %[[TMP]], (%e{{..}})
60+
*dst = small();
61+
}
62+
}
63+
64+
// Verifies ABI changes for a struct of size 8, which is the maximum size
65+
// for reg-struct-return.
66+
// WITH is expected to still use register return, WITHOUT should use hidden
67+
// pointer.
68+
mod Pivot {
69+
struct PivotStruct {
70+
a: i32,
71+
b: i32,
72+
}
73+
74+
unsafe extern "C" {
75+
fn pivot() -> PivotStruct;
76+
}
77+
78+
#[unsafe(no_mangle)]
79+
pub unsafe extern "C" fn pivot_callee() -> PivotStruct {
80+
// WITH-LABEL: pivot_callee
81+
// WITH: movl $42, %e{{.*}}
82+
// WITH: movl $42, %e{{.*}}
83+
// WITH: retl
84+
85+
// WITHOUT-LABEL: pivot_callee
86+
// WITHOUT: movl 4(%esp), %e{{.*}}
87+
// WITHOUT-DAG: movl $42, (%e{{.*}})
88+
// WITHOUT-DAG: movl $42, 4(%e{{.*}})
89+
// WITHOUT: retl $4
90+
PivotStruct { a: 42, b: 42 }
91+
}
92+
93+
#[unsafe(no_mangle)]
94+
pub unsafe extern "C" fn pivot_caller(dst: &mut PivotStruct) {
95+
// WITH-LABEL: pivot_caller
96+
// WITH: calll pivot
97+
// WITH-DAG: movl %e{{.*}}, 4(%e{{.*}})
98+
// WITH-DAG: movl %e{{.*}}, (%e{{.*}})
99+
100+
// WITHOUT-LABEL: pivot_caller
101+
// WITHOUT: calll pivot
102+
// WITHOUT: movsd {{.*}}(%esp), %[[TMP:xmm.]]
103+
// WITHOUT: movsd %[[TMP]], (%e{{..}})
104+
*dst = pivot();
105+
}
106+
}
107+
108+
// Verifies ABI changes for a struct of size 12, which is larger than the
109+
// maximum size for reg-struct-return (8 bytes).
110+
// Here, the hidden pointer convention should be used even when `-Zreg-struct-return` is set.
111+
mod Large {
112+
struct LargeStruct {
113+
a: i32,
114+
b: i32,
115+
c: i32,
116+
}
117+
118+
unsafe extern "C" {
119+
fn large() -> LargeStruct;
120+
}
121+
122+
#[unsafe(no_mangle)]
123+
pub unsafe extern "C" fn large_callee() -> LargeStruct {
124+
// CHECK-LABEL: large_callee
125+
// CHECK: movl 4(%esp), %e{{.*}}
126+
// CHECK-DAG: movl $42, (%e{{.*}})
127+
// CHECK-DAG: movl $42, 4(%e{{.*}})
128+
// CHECK-DAG: movl $42, 8(%e{{.*}})
129+
// CHECK: retl $4
130+
LargeStruct { a: 42, b: 42, c: 42 }
131+
}
132+
133+
#[unsafe(no_mangle)]
134+
pub unsafe extern "C" fn large_caller(dst: &mut LargeStruct) {
135+
// CHECK-LABEL: large_caller
136+
// CHECK: calll large
137+
// CHECK-DAG: movl {{.*}}(%esp), %[[TMP1:e..]]
138+
// CHECK-DAG: movl %[[TMP1]], {{.*}}(%e{{..}})
139+
// CHECK-DAG: movsd {{.*}}(%esp), %[[TMP2:xmm.]]
140+
// CHECK-DAG: movsd %[[TMP2]], {{.*}}(%e{{..}})
141+
*dst = large();
142+
}
143+
}

0 commit comments

Comments
 (0)