Skip to content

Commit b20436b

Browse files
committed
Add regression test for rustc/rustdoc broken pipe ICEs
1 parent 328bc7e commit b20436b

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/bootstrap/src/bin/rustc.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,8 @@ fn main() {
136136
cmd.args(lint_flags.split_whitespace());
137137
}
138138

139-
// Conditionally pass `-Zon-broken-pipe=kill` to rustc bin shim when this shim is *not* used to
140-
// build cargo itself, i.e. set `-Zon-broken-pipe=kill` only when building non-cargo tools.
141-
//
142-
// See <https://github.com/rust-lang/rust/issues/131059> for more context.
139+
// Conditionally pass `-Zon-broken-pipe=kill` to underlying rustc. Not all binaries want
140+
// `-Zon-broken-pipe=kill`, which includes cargo itself.
143141
if env::var_os("FORCE_ON_BROKEN_PIPE_KILL").is_some() {
144142
cmd.arg("-Z").arg("on-broken-pipe=kill");
145143
}
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//! Check that `rustc` and `rustdoc` does not ICE upon encountering a broken pipe due to unhandled
2+
//! panics from raw std `println!` usages.
3+
//!
4+
//! Regression test for <https://github.com/rust-lang/rust/issues/34376>.
5+
6+
//@ ignore-cross-compile (needs to run test binary)
7+
8+
#![feature(anonymous_pipe)]
9+
10+
use std::io::Read;
11+
use std::os::unix::process::ExitStatusExt;
12+
use std::process::{Command, Stdio};
13+
14+
use run_make_support::{env_var, libc};
15+
16+
fn check_broken_pipe_handled_gracefully(name: &str, mut cmd: Command) {
17+
let (reader, writer) = std::pipe::pipe().unwrap();
18+
drop(reader); // close read-end
19+
cmd.stdout(writer).stderr(Stdio::piped());
20+
21+
let mut child = cmd.spawn().unwrap();
22+
23+
let mut stderr = String::new();
24+
child.stderr.as_mut().unwrap().read_to_string(&mut stderr).unwrap();
25+
let status = child.wait().unwrap();
26+
27+
assert!(!status.success(), "{name}");
28+
29+
const PANIC_ICE_EXIT_STATUS: i32 = 101;
30+
assert_ne!(status.code(), Some(101), "{name}");
31+
32+
assert!(stderr.is_empty(), "{name} stderr:\n{}", stderr);
33+
}
34+
35+
fn main() {
36+
let mut rustc = Command::new(env_var("RUSTC"));
37+
rustc.arg("--print=sysroot");
38+
check_broken_pipe_handled_gracefully("rustc", rustc);
39+
40+
let mut rustdoc = Command::new(env_var("RUSTDOC"));
41+
rustdoc.arg("--version");
42+
check_broken_pipe_handled_gracefully("rustdoc", rustdoc);
43+
}

0 commit comments

Comments
 (0)