Skip to content

Commit 8667a30

Browse files
committed
Avoid ICE in non-check builds with bad #[coverage(..)] attributes
This code can sometimes witness malformed coverage attributes in builds that are going to fail, so use `span_delayed_bug` to avoid an inappropriate ICE in that case.
1 parent ad9c494 commit 8667a30

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

compiler/rustc_mir_transform/src/coverage/query.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
6363
Some([item]) if item.has_name(sym::on) => return true,
6464
Some(_) | None => {
6565
// Other possibilities should have been rejected by `rustc_parse::validate_attr`.
66-
tcx.dcx().span_bug(attr.span, "unexpected value of coverage attribute");
66+
// Use `span_delayed_bug` to avoid an ICE in failing builds (#127880).
67+
tcx.dcx().span_delayed_bug(attr.span, "unexpected value of coverage attribute");
6768
}
6869
}
6970
}

tests/crashes/127880.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[coverage]
2+
fn main() {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use run_make_support::rustc;
2+
3+
// Illegal `#[coverage(..)]` attributes should not cause an ICE in non-check
4+
// builds with `-Cinstrument-coverage`.
5+
// Regression test for <https://github.com/rust-lang/rust/issues/127880>.
6+
//
7+
// This currently can't be a UI test, because there's no way to force a
8+
// non-check build of a UI test that would also fail a check build.
9+
10+
fn main() {
11+
rustc()
12+
.edition("2021")
13+
.arg("-Cinstrument-coverage")
14+
.input("127880.rs")
15+
.run_fail()
16+
// The build should fail cleanly, but not ICE.
17+
.assert_exit_code(1)
18+
.assert_stderr_contains("error: malformed `coverage` attribute input");
19+
}

0 commit comments

Comments
 (0)