Skip to content

properly handle compiler ICEs #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 23 additions & 29 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::collections::{HashSet, VecDeque};
use std::ffi::OsString;
use std::num::NonZeroUsize;
use std::path::{Component, Path, PathBuf, Prefix};
use std::process::{Command, ExitStatus};
use std::process::{Command, ExitStatus, Output};
use std::thread;

use crate::parser::{Comments, Condition};
Expand Down Expand Up @@ -606,28 +606,13 @@ impl dyn TestStatus {
let mut cmd = build_command(path, config, revision, comments)?;
cmd.args(&extra_args);

let (status, stderr, stdout) = self.run_command(&mut cmd);
let (cmd, status, stderr, stdout) = self.run_command(cmd)?;

let mode = config.mode.maybe_override(comments, revision)?;

match *mode {
Mode::Run { .. } if Mode::Pass.ok(status).is_ok() => {
return run_test_binary(mode, path, revision, comments, cmd, config)
}
Mode::Panic | Mode::Yolo { .. } => {}
Mode::Run { .. } | Mode::Pass | Mode::Fail { .. } => {
if status.code() == Some(101) {
let stderr = String::from_utf8_lossy(&stderr);
let stdout = String::from_utf8_lossy(&stdout);
return Err(Errored {
command: cmd,
errors: vec![Error::Bug(format!(
"test panicked: stderr:\n{stderr}\nstdout:\n{stdout}",
))],
stderr: vec![],
stdout: vec![],
});
}
if let Mode::Run { .. } = *mode {
if Mode::Pass.ok(status).is_ok() {
return run_test_binary(mode, path, revision, comments, cmd, config);
}
}
check_test_result(
Expand All @@ -641,15 +626,24 @@ impl dyn TestStatus {

/// Run a command, and if it takes more than 100ms, start appending the last stderr/stdout
/// line to the current status spinner.
fn run_command(&self, cmd: &mut Command) -> (ExitStatus, Vec<u8>, Vec<u8>) {
let output = cmd.output().unwrap_or_else(|err| {
panic!(
"could not spawn `{:?}` as a process: {err}",
cmd.get_program()
)
});

(output.status, output.stderr, output.stdout)
fn run_command(
&self,
mut cmd: Command,
) -> Result<(Command, ExitStatus, Vec<u8>, Vec<u8>), Errored> {
match cmd.output() {
Err(err) => Err(Errored {
errors: vec![],
stderr: err.to_string().into_bytes(),
stdout: format!("could not spawn `{:?}` as a process", cmd.get_program())
.into_bytes(),
command: cmd,
}),
Ok(Output {
status,
stdout,
stderr,
}) => Ok((cmd, status, stderr, stdout)),
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fn main() -> Result<()> {
"The system cannot find the file specified.",
"No such file or directory",
);
config.filter("RUSTC_BOOTSTRAP=\"1\" ", "");
// The order of the `/deps` directory flag is flaky
config.stdout_filter("/deps", "");
config.path_filter(std::path::Path::new(path), "$DIR");
Expand All @@ -55,7 +56,9 @@ fn main() -> Result<()> {
.insert(0, (Match::Exact(b"\\\\".to_vec()), b"\\"));
config.filter("\\.exe", b"");
config.stdout_filter(r#"(panic.*)\.rs:[0-9]+:[0-9]+"#, "$1.rs");
config.filter(" [0-9]: .*", "");
config.filter("(\\+)? +[0-9]+: .*\n", "");
config.filter("(\\+)? +at /.*\n", "");
config.filter(" running on .*", "");
config.stdout_filter("/target/[^/]+/[^/]+/debug", "/target/$$TMP/$$TRIPLE/debug");
config.stdout_filter("/target/.tmp[^/ \"]+", "/target/$$TMP");
// Normalize proc macro filenames on windows to their linux repr
Expand Down
9 changes: 0 additions & 9 deletions tests/integrations/basic-fail/Cargo.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,12 @@ Error: failed to parse rustc version info: invalid_foobarlaksdfalsdfj

Caused by:



Location:
$DIR/src/config.rs:LL:CC
error: test failed, to rerun pass `--test ui_tests_invalid_program`

Caused by:
process didn't exit successfully: `$DIR/target/ui/debug/deps/ui_tests_invalid_program-HASH` (exit status: 1)
thread '<unnamed>' panicked at 'could not spawn `"invalid_foobarlaksdfalsdfj"` as a process: No such file or directory', $DIR/src/lib.rs:LL:CC
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at 'could not spawn `"invalid_foobarlaksdfalsdfj"` as a process: No such file or directory', $DIR/src/lib.rs:LL:CC
thread '<unnamed>' panicked at 'could not spawn `"invalid_foobarlaksdfalsdfj"` as a process: No such file or directory', $DIR/src/lib.rs:LL:CC
thread '<unnamed>' panicked at 'could not spawn `"invalid_foobarlaksdfalsdfj"` as a process: No such file or directory', $DIR/src/lib.rs:LL:CC
thread '<unnamed>' panicked at 'could not spawn `"invalid_foobarlaksdfalsdfj"` as a process: No such file or directory', $DIR/src/lib.rs:LL:CC
thread '<unnamed>' panicked at 'could not spawn `"invalid_foobarlaksdfalsdfj"` as a process: No such file or directory', $DIR/src/lib.rs:LL:CC
Error: tests failed

Location:
Expand Down
112 changes: 80 additions & 32 deletions tests/integrations/basic-fail/Cargo.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tests/actual_tests/filters.rs ... FAILED
tests/actual_tests/foomp.rs ... FAILED
tests/actual_tests/foomp2.rs ... FAILED
tests/actual_tests/pattern_too_many_arrow.rs ... FAILED
tests/actual_tests/rustc_ice.rs ... FAILED

tests/actual_tests/bad_pattern.rs FAILED:
command: "rustc" "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug" "--out-dir" "$TMP "tests/actual_tests/bad_pattern.rs" "--edition" "2021"
Expand Down Expand Up @@ -227,6 +228,53 @@ full stderr:
full stdout:



tests/actual_tests/rustc_ice.rs FAILED:
command: "rustc" "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug" "--out-dir" "$TMP "tests/actual_tests/rustc_ice.rs" "-Ztreat-err-as-bug" "--edition" "2021"

fail test got exit status: 101, but expected 1

error: substring `mismatched types` not found in stderr output
--> tests/actual_tests/rustc_ice.rs:10:17
|
10 | //~^ ERROR: mismatched types
| ^^^^^^^^^^^^^^^^ expected because of this pattern
|

error: There were 1 unmatched diagnostics
--> tests/actual_tests/rustc_ice.rs:9:5
|
9 | add("42", 3);
| ^^^^^^^^^^^^ Ice: no errors reported for args
|

full stderr:
error: internal compiler error: no errors reported for args
--> tests/actual_tests/rustc_ice.rs:9:5
|
9 | add("42", 3);
| ^^^^^^^^^^^^

thread 'rustc' panicked at 'aborting due to `-Z treat-err-as-bug=1`', compiler/rustc_errors/src/lib.rs
stack backtrace:

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.72.0 (5680fa18f 2023-08-23)

note: compiler flags: -Z treat-err-as-bug

query stack during panic:
#0 [typeck] type-checking `main`
#1 [used_trait_imports] finding used_trait_imports `main`
#2 [analysis] running analysis passes on this crate
end of query stack

full stdout:


FAILURES:
tests/actual_tests/bad_pattern.rs
tests/actual_tests/executable.rs
Expand All @@ -236,8 +284,9 @@ FAILURES:
tests/actual_tests/foomp.rs
tests/actual_tests/foomp2.rs
tests/actual_tests/pattern_too_many_arrow.rs
tests/actual_tests/rustc_ice.rs

test result: FAIL. 8 failed;
test result: FAIL. 9 failed;

Building dependencies ... ok
tests/actual_tests_bless/aux_build_not_found.rs ... FAILED
Expand Down Expand Up @@ -773,49 +822,42 @@ tests/actual_tests/filters.rs ... FAILED
tests/actual_tests/foomp.rs ... FAILED
tests/actual_tests/foomp2.rs ... FAILED
tests/actual_tests/pattern_too_many_arrow.rs ... FAILED
tests/actual_tests/rustc_ice.rs ... FAILED

tests/actual_tests/bad_pattern.rs FAILED:
command: "<unknown>"

A bug in `ui_test` occurred: could not spawn `"invalid_foobarlaksdfalsdfj"` as a process: No such file or directory
command: "$CMD" "tests/actual_tests/bad_pattern.rs" "--edition" "2021"

full stderr:

No such file or directory
full stdout:

could not spawn `"invalid_foobarlaksdfalsdfj"` as a process


tests/actual_tests/executable.rs FAILED:
command: "<unknown>"

A bug in `ui_test` occurred: could not spawn `"invalid_foobarlaksdfalsdfj"` as a process: No such file or directory
command: "$CMD" "tests/actual_tests/executable.rs" "--edition" "2021"

full stderr:

No such file or directory
full stdout:

could not spawn `"invalid_foobarlaksdfalsdfj"` as a process


tests/actual_tests/executable_compile_err.rs FAILED:
command: "<unknown>"

A bug in `ui_test` occurred: could not spawn `"invalid_foobarlaksdfalsdfj"` as a process: No such file or directory
command: "$CMD" "tests/actual_tests/executable_compile_err.rs" "--edition" "2021"

full stderr:

No such file or directory
full stdout:

could not spawn `"invalid_foobarlaksdfalsdfj"` as a process


tests/actual_tests/exit_code_fail.rs FAILED:
command: "<unknown>"

A bug in `ui_test` occurred: could not spawn `"invalid_foobarlaksdfalsdfj"` as a process: No such file or directory
command: "$CMD" "tests/actual_tests/exit_code_fail.rs" "--edition" "2021"

full stderr:

No such file or directory
full stdout:

could not spawn `"invalid_foobarlaksdfalsdfj"` as a process


tests/actual_tests/filters.rs FAILED:
Expand All @@ -835,25 +877,21 @@ full stdout:


tests/actual_tests/foomp.rs FAILED:
command: "<unknown>"

A bug in `ui_test` occurred: could not spawn `"invalid_foobarlaksdfalsdfj"` as a process: No such file or directory
command: "$CMD" "tests/actual_tests/foomp.rs" "--edition" "2021"

full stderr:

No such file or directory
full stdout:

could not spawn `"invalid_foobarlaksdfalsdfj"` as a process


tests/actual_tests/foomp2.rs FAILED:
command: "<unknown>"

A bug in `ui_test` occurred: could not spawn `"invalid_foobarlaksdfalsdfj"` as a process: No such file or directory
command: "$CMD" "tests/actual_tests/foomp2.rs" "--edition" "2021"

full stderr:

No such file or directory
full stdout:

could not spawn `"invalid_foobarlaksdfalsdfj"` as a process


tests/actual_tests/pattern_too_many_arrow.rs FAILED:
Expand All @@ -871,6 +909,15 @@ full stderr:
full stdout:



tests/actual_tests/rustc_ice.rs FAILED:
command: "$CMD" "tests/actual_tests/rustc_ice.rs" "-Ztreat-err-as-bug" "--edition" "2021"

full stderr:
No such file or directory
full stdout:
could not spawn `"invalid_foobarlaksdfalsdfj"` as a process

FAILURES:
tests/actual_tests/bad_pattern.rs
tests/actual_tests/executable.rs
Expand All @@ -880,8 +927,9 @@ FAILURES:
tests/actual_tests/foomp.rs
tests/actual_tests/foomp2.rs
tests/actual_tests/pattern_too_many_arrow.rs
tests/actual_tests/rustc_ice.rs

test result: FAIL. 8 failed;
test result: FAIL. 9 failed;


running 0 tests
Expand Down
11 changes: 11 additions & 0 deletions tests/integrations/basic-fail/tests/actual_tests/rustc_ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@compile-flags: -Ztreat-err-as-bug
//@rustc-env: RUSTC_BOOTSTRAP=1
//@normalize-stderr-test: " +[0-9]+: .*\n" -> ""
//@normalize-stderr-test: " +at /.*\n" -> ""
//@normalize-stderr-test: " running on .*" -> ""
use basic_fail::add;

fn main() {
add("42", 3);
//~^ ERROR: mismatched types
}
22 changes: 22 additions & 0 deletions tests/integrations/basic-fail/tests/actual_tests/rustc_ice.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: internal compiler error: no errors reported for args
--> $DIR/rustc_ice.rs:9:5
|
9 | add("42", 3);
| ^^^^^^^^^^^^

thread 'rustc' panicked at 'aborting due to `-Z treat-err-as-bug=1`', compiler/rustc_errors/src/lib.rs:1712:30
stack backtrace:

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.72.0 (5680fa18f 2023-08-23)

note: compiler flags: -Z treat-err-as-bug

query stack during panic:
#0 [typeck] type-checking `main`
#1 [used_trait_imports] finding used_trait_imports `main`
#2 [analysis] running analysis passes on this crate
end of query stack