Skip to content

Commit 9679ae0

Browse files
committed
Auto merge of rust-lang#116924 - fmease:rollup-aznzvf8, r=fmease
Rollup of 4 pull requests Successful merges: - rust-lang#116037 (Add `-Zstack-protector` test for Windows targets) - rust-lang#116132 (Make TCP connect handle EINTR correctly) - rust-lang#116810 (Add FileCheck annotations to mir-opt tests.) - rust-lang#116896 (Only check in a single place if a pass is enabled.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 36b61e5 + b6f4522 commit 9679ae0

File tree

362 files changed

+2338
-609
lines changed

Some content is hidden

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

362 files changed

+2338
-609
lines changed

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
383383
let is_fn_like = tcx.def_kind(def).is_fn_like();
384384
if is_fn_like {
385385
// Do not compute the mir call graph without said call graph actually being used.
386-
if inline::Inline.is_enabled(&tcx.sess) {
386+
if pm::should_run_pass(tcx, &inline::Inline) {
387387
tcx.ensure_with_value().mir_inliner_callees(ty::InstanceDef::Item(def.to_def_id()));
388388
}
389389
}

compiler/rustc_mir_transform/src/pass_manager.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,25 @@ pub fn run_passes<'tcx>(
8383
run_passes_inner(tcx, body, passes, phase_change, true);
8484
}
8585

86+
pub fn should_run_pass<'tcx, P>(tcx: TyCtxt<'tcx>, pass: &P) -> bool
87+
where
88+
P: MirPass<'tcx> + ?Sized,
89+
{
90+
let name = pass.name();
91+
92+
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
93+
let overridden =
94+
overridden_passes.iter().rev().find(|(s, _)| s == &*name).map(|(_name, polarity)| {
95+
trace!(
96+
pass = %name,
97+
"{} as requested by flag",
98+
if *polarity { "Running" } else { "Not running" },
99+
);
100+
*polarity
101+
});
102+
overridden.unwrap_or_else(|| pass.is_enabled(&tcx.sess))
103+
}
104+
86105
fn run_passes_inner<'tcx>(
87106
tcx: TyCtxt<'tcx>,
88107
body: &mut Body<'tcx>,
@@ -100,19 +119,9 @@ fn run_passes_inner<'tcx>(
100119
for pass in passes {
101120
let name = pass.name();
102121

103-
let overridden = overridden_passes.iter().rev().find(|(s, _)| s == &*name).map(
104-
|(_name, polarity)| {
105-
trace!(
106-
pass = %name,
107-
"{} as requested by flag",
108-
if *polarity { "Running" } else { "Not running" },
109-
);
110-
*polarity
111-
},
112-
);
113-
if !overridden.unwrap_or_else(|| pass.is_enabled(&tcx.sess)) {
122+
if !should_run_pass(tcx, *pass) {
114123
continue;
115-
}
124+
};
116125

117126
let dump_enabled = pass.is_mir_dump_enabled();
118127

library/std/src/sys/hermit/net.rs

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ impl Socket {
5656
unimplemented!()
5757
}
5858

59+
pub fn connect(&self, addr: &SocketAddr) -> io::Result<()> {
60+
let (addr, len) = addr.into_inner();
61+
cvt_r(|| unsafe { netc::connect(self.as_raw_fd(), addr.as_ptr(), len) })?;
62+
Ok(())
63+
}
64+
5965
pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
6066
self.set_nonblocking(true)?;
6167
let r = unsafe {

library/std/src/sys/solid/net.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,15 @@ impl Socket {
233233
}
234234
}
235235

236+
pub fn connect(&self, addr: &SocketAddr) -> io::Result<()> {
237+
let (addr, len) = addr.into_inner();
238+
cvt(unsafe { netc::connect(self.0.raw(), addr.as_ptr(), len) })?;
239+
Ok(())
240+
}
241+
236242
pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
237243
self.set_nonblocking(true)?;
238-
let r = unsafe {
239-
let (addr, len) = addr.into_inner();
240-
cvt(netc::connect(self.0.raw(), addr.as_ptr(), len))
241-
};
244+
let r = self.connect(addr);
242245
self.set_nonblocking(false)?;
243246

244247
match r {

library/std/src/sys/unix/net.rs

+17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::net::{Shutdown, SocketAddr};
66
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
77
use crate::str;
88
use crate::sys::fd::FileDesc;
9+
use crate::sys::unix::IsMinusOne;
910
use crate::sys_common::net::{getsockopt, setsockopt, sockaddr_to_addr};
1011
use crate::sys_common::{AsInner, FromInner, IntoInner};
1112
use crate::time::{Duration, Instant};
@@ -140,6 +141,22 @@ impl Socket {
140141
unimplemented!()
141142
}
142143

144+
pub fn connect(&self, addr: &SocketAddr) -> io::Result<()> {
145+
let (addr, len) = addr.into_inner();
146+
loop {
147+
let result = unsafe { libc::connect(self.as_raw_fd(), addr.as_ptr(), len) };
148+
if result.is_minus_one() {
149+
let err = crate::sys::os::errno();
150+
match err {
151+
libc::EINTR => continue,
152+
libc::EISCONN => return Ok(()),
153+
_ => return Err(io::Error::from_raw_os_error(err)),
154+
}
155+
}
156+
return Ok(());
157+
}
158+
}
159+
143160
pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
144161
self.set_nonblocking(true)?;
145162
let r = unsafe {

library/std/src/sys/windows/net.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,15 @@ impl Socket {
140140
}
141141
}
142142

143+
pub fn connect(&self, addr: &SocketAddr) -> io::Result<()> {
144+
let (addr, len) = addr.into_inner();
145+
let result = unsafe { c::connect(self.as_raw(), addr.as_ptr(), len) };
146+
cvt(result).map(drop)
147+
}
148+
143149
pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
144150
self.set_nonblocking(true)?;
145-
let result = {
146-
let (addr, len) = addr.into_inner();
147-
let result = unsafe { c::connect(self.as_raw(), addr.as_ptr(), len) };
148-
cvt(result).map(drop)
149-
};
151+
let result = self.connect(addr);
150152
self.set_nonblocking(false)?;
151153

152154
match result {

library/std/src/sys_common/net.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ impl TcpStream {
226226
init();
227227

228228
let sock = Socket::new(addr, c::SOCK_STREAM)?;
229-
230-
let (addr, len) = addr.into_inner();
231-
cvt_r(|| unsafe { c::connect(sock.as_raw(), addr.as_ptr(), len) })?;
229+
sock.connect(addr)?;
232230
Ok(TcpStream { inner: sock })
233231
}
234232

src/tools/compiletest/src/runtest.rs

+26-39
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::json;
1515
use crate::read2::{read2_abbreviated, Truncated};
1616
use crate::util::{add_dylib_path, dylib_env_var, logv, PathBufExt};
1717
use crate::ColorConfig;
18+
use miropt_test_tools::{files_for_miropt_test, MiroptTest, MiroptTestFile};
1819
use regex::{Captures, Regex};
1920
use rustfix::{apply_suggestions, get_suggestions_from_json, Filter};
2021

@@ -229,6 +230,7 @@ enum Emit {
229230
None,
230231
Metadata,
231232
LlvmIr,
233+
Mir,
232234
Asm,
233235
LinkArgsAsm,
234236
}
@@ -2506,6 +2508,9 @@ impl<'test> TestCx<'test> {
25062508
Emit::LlvmIr => {
25072509
rustc.args(&["--emit", "llvm-ir"]);
25082510
}
2511+
Emit::Mir => {
2512+
rustc.args(&["--emit", "mir"]);
2513+
}
25092514
Emit::Asm => {
25102515
rustc.args(&["--emit", "asm"]);
25112516
}
@@ -3984,11 +3989,17 @@ impl<'test> TestCx<'test> {
39843989
fn run_mir_opt_test(&self) {
39853990
let pm = self.pass_mode();
39863991
let should_run = self.should_run(pm);
3987-
let emit_metadata = self.should_emit_metadata(pm);
3988-
let passes = self.get_passes();
39893992

3990-
let proc_res = self.compile_test_with_passes(should_run, emit_metadata, passes);
3991-
self.check_mir_dump();
3993+
let mut test_info = files_for_miropt_test(
3994+
&self.testpaths.file,
3995+
self.config.get_pointer_width(),
3996+
self.config.target_cfg().panic.for_miropt_test_tools(),
3997+
);
3998+
3999+
let passes = std::mem::take(&mut test_info.passes);
4000+
4001+
let proc_res = self.compile_test_with_passes(should_run, Emit::Mir, passes);
4002+
self.check_mir_dump(test_info);
39924003
if !proc_res.status.success() {
39934004
self.fatal_proc_rec("compilation failed!", &proc_res);
39944005
}
@@ -4002,37 +4013,12 @@ impl<'test> TestCx<'test> {
40024013
}
40034014
}
40044015

4005-
fn get_passes(&self) -> Vec<String> {
4006-
let files = miropt_test_tools::files_for_miropt_test(
4007-
&self.testpaths.file,
4008-
self.config.get_pointer_width(),
4009-
self.config.target_cfg().panic.for_miropt_test_tools(),
4010-
);
4011-
4012-
let mut out = Vec::new();
4013-
4014-
for miropt_test_tools::MiroptTestFiles {
4015-
from_file: _,
4016-
to_file: _,
4017-
expected_file: _,
4018-
passes,
4019-
} in files
4020-
{
4021-
out.extend(passes);
4022-
}
4023-
out
4024-
}
4025-
4026-
fn check_mir_dump(&self) {
4016+
fn check_mir_dump(&self, test_info: MiroptTest) {
40274017
let test_dir = self.testpaths.file.parent().unwrap();
40284018
let test_crate =
40294019
self.testpaths.file.file_stem().unwrap().to_str().unwrap().replace("-", "_");
40304020

4031-
let suffix = miropt_test_tools::output_file_suffix(
4032-
&self.testpaths.file,
4033-
self.config.get_pointer_width(),
4034-
self.config.target_cfg().panic.for_miropt_test_tools(),
4035-
);
4021+
let MiroptTest { run_filecheck, suffix, files, passes: _ } = test_info;
40364022

40374023
if self.config.bless {
40384024
for e in
@@ -4047,14 +4033,7 @@ impl<'test> TestCx<'test> {
40474033
}
40484034
}
40494035

4050-
let files = miropt_test_tools::files_for_miropt_test(
4051-
&self.testpaths.file,
4052-
self.config.get_pointer_width(),
4053-
self.config.target_cfg().panic.for_miropt_test_tools(),
4054-
);
4055-
for miropt_test_tools::MiroptTestFiles { from_file, to_file, expected_file, passes: _ } in
4056-
files
4057-
{
4036+
for MiroptTestFile { from_file, to_file, expected_file } in files {
40584037
let dumped_string = if let Some(after) = to_file {
40594038
self.diff_mir_files(from_file.into(), after.into())
40604039
} else {
@@ -4095,6 +4074,14 @@ impl<'test> TestCx<'test> {
40954074
}
40964075
}
40974076
}
4077+
4078+
if run_filecheck {
4079+
let output_path = self.output_base_name().with_extension("mir");
4080+
let proc_res = self.verify_with_filecheck(&output_path);
4081+
if !proc_res.status.success() {
4082+
self.fatal_proc_rec("verification with 'FileCheck' failed", &proc_res);
4083+
}
4084+
}
40984085
}
40994086

41004087
fn diff_mir_files(&self, before: PathBuf, after: PathBuf) -> String {

src/tools/miropt-test-tools/src/lib.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
use std::fs;
22
use std::path::Path;
33

4-
pub struct MiroptTestFiles {
4+
pub struct MiroptTestFile {
55
pub expected_file: std::path::PathBuf,
66
pub from_file: String,
77
pub to_file: Option<String>,
8+
}
9+
10+
pub struct MiroptTest {
11+
pub run_filecheck: bool,
12+
pub suffix: String,
13+
pub files: Vec<MiroptTestFile>,
814
/// Vec of passes under test to be dumped
915
pub passes: Vec<String>,
1016
}
@@ -14,11 +20,7 @@ pub enum PanicStrategy {
1420
Abort,
1521
}
1622

17-
pub fn output_file_suffix(
18-
testfile: &Path,
19-
bit_width: u32,
20-
panic_strategy: PanicStrategy,
21-
) -> String {
23+
fn output_file_suffix(testfile: &Path, bit_width: u32, panic_strategy: PanicStrategy) -> String {
2224
let mut each_bit_width = false;
2325
let mut each_panic_strategy = false;
2426
for line in fs::read_to_string(testfile).unwrap().lines() {
@@ -47,16 +49,22 @@ pub fn files_for_miropt_test(
4749
testfile: &std::path::Path,
4850
bit_width: u32,
4951
panic_strategy: PanicStrategy,
50-
) -> Vec<MiroptTestFiles> {
52+
) -> MiroptTest {
5153
let mut out = Vec::new();
5254
let test_file_contents = fs::read_to_string(&testfile).unwrap();
5355

5456
let test_dir = testfile.parent().unwrap();
5557
let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace('-', "_");
5658

5759
let suffix = output_file_suffix(testfile, bit_width, panic_strategy);
60+
let mut run_filecheck = true;
61+
let mut passes = Vec::new();
5862

5963
for l in test_file_contents.lines() {
64+
if l.starts_with("// skip-filecheck") {
65+
run_filecheck = false;
66+
continue;
67+
}
6068
if l.starts_with("// EMIT_MIR ") {
6169
let test_name = l.trim_start_matches("// EMIT_MIR ").trim();
6270
let mut test_names = test_name.split(' ');
@@ -65,7 +73,6 @@ pub fn files_for_miropt_test(
6573
let mut expected_file;
6674
let from_file;
6775
let to_file;
68-
let mut passes = Vec::new();
6976

7077
if test_name.ends_with(".diff") {
7178
let trimmed = test_name.trim_end_matches(".diff");
@@ -114,9 +121,9 @@ pub fn files_for_miropt_test(
114121
}
115122
let expected_file = test_dir.join(expected_file);
116123

117-
out.push(MiroptTestFiles { expected_file, from_file, to_file, passes });
124+
out.push(MiroptTestFile { expected_file, from_file, to_file });
118125
}
119126
}
120127

121-
out
128+
MiroptTest { run_filecheck, suffix, files: out, passes }
122129
}

src/tools/tidy/src/mir_opt_tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ fn check_unused_files(path: &Path, bless: bool, bad: &mut bool) {
2626
for file in rs_files {
2727
for bw in [32, 64] {
2828
for ps in [PanicStrategy::Unwind, PanicStrategy::Abort] {
29-
for output_file in miropt_test_tools::files_for_miropt_test(&file, bw, ps) {
29+
let mir_opt_test = miropt_test_tools::files_for_miropt_test(&file, bw, ps);
30+
for output_file in mir_opt_test.files {
3031
output_files.remove(&output_file.expected_file);
3132
}
3233
}

0 commit comments

Comments
 (0)