Skip to content
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

ICE: unexpected value of coverage attribute #127880

Closed
matthiaskrgr opened this issue Jul 17, 2024 · 1 comment · Fixed by #131187
Closed

ICE: unexpected value of coverage attribute #127880

matthiaskrgr opened this issue Jul 17, 2024 · 1 comment · Fixed by #131187
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

#[coverage]

fn main() {}
original code

original:

#![feature(coverage_attribute)]
//@ edition: 2021

// Demonstrates the diagnostics produced when using the syntax `#[coverage]`,
// which should not be allowed.
//
// The syntax is tested both in places that can have a coverage attribute,
// and in places that cannot have a coverage attribute, to demonstrate the
// interaction between multiple errors.

#[coverage]
//~^ ERROR malformed `coverage` attribute input
mod my_mod {}

mod my_mod_inner {
    #![coverage]
    //~^ ERROR malformed `coverage` attribute input
}

#[coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
struct MyStruct;

#[coverage]
//~^ ERROR malformed `coverage` attribute input
impl MyStruct {
    #[coverage]
    //~^ ERROR malformed `coverage` attribute input
    //~| ERROR attribute should be applied to a function definition or closure
    const X: u32 = 7;
}

#[coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
trait MyTrait {
    #[coverage]
    //~^ ERROR malformed `coverage` attribute input
    //~| ERROR attribute should be applied to a function definition or closure
    const X: u32;

    #[coverage]
    //~^ ERROR malformed `coverage` attribute input
    //~| ERROR attribute should be applied to a function definition or closure
    type T;
}

#[coverage]
//~^ ERROR malformed `coverage` attribute input
impl MyTrait for MyStruct {
    #[coverage]
    //~^ ERROR malformed `coverage` attribute input
    //~| ERROR attribute should be applied to a function definition or closure
    const X: u32 = 8;

    #[coverage]
    //~^ ERROR malformed `coverage` attribute input
    //~| ERROR attribute should be applied to a function definition or closure
    type T = ();
}

#[coverage]
//~^ ERROR malformed `coverage` attribute input
fn main() {}

Version information

rustc 1.81.0-nightly (fcc325f1b 2024-07-17)
binary: rustc
commit-hash: fcc325f1bc477975e2ce5ba534fe4c77ff8a8536
commit-date: 2024-07-17
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Cinstrument-coverage

Program output

error: malformed `coverage` attribute input
 --> /tmp/icemaker_global_tempdir.4O1Z9G3tMNfo/rustc_testrunner_tmpdir_reporting.c2V17EKwJr3h/mvce.rs:3:1
  |
3 | #[coverage]
  | ^^^^^^^^^^^
  |
help: the following are the possible correct uses
  |
3 | #[coverage(off)]
  |
3 | #[coverage(on)]
  |

error[E0658]: the `#[coverage]` attribute is an experimental feature
 --> /tmp/icemaker_global_tempdir.4O1Z9G3tMNfo/rustc_testrunner_tmpdir_reporting.c2V17EKwJr3h/mvce.rs:3:1
  |
3 | #[coverage]
  | ^^^^^^^^^^^
  |
  = note: see issue #84605 <https://github.com/rust-lang/rust/issues/84605> for more information
  = help: add `#![feature(coverage_attribute)]` to the crate attributes to enable
  = note: this compiler was built on 2024-07-17; consider upgrading it if it is out of date

error: internal compiler error: unexpected value of coverage attribute
 --> /tmp/icemaker_global_tempdir.4O1Z9G3tMNfo/rustc_testrunner_tmpdir_reporting.c2V17EKwJr3h/mvce.rs:3:1
  |
3 | #[coverage]
  | ^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_mir_transform/src/coverage/query.rs:65:27:
Box<dyn Any>
stack backtrace:
   0:     0x73b8a97783e5 - std::backtrace_rs::backtrace::libunwind::trace::h7d42dda8f80cfb99
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x73b8a97783e5 - std::backtrace_rs::backtrace::trace_unsynchronized::hd585f8afb233c9ee
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x73b8a97783e5 - std::sys::backtrace::_print_fmt::h224c15dbafc899ab
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/std/src/sys/backtrace.rs:65:5
   3:     0x73b8a97783e5 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hca750ad87bb2f1d4
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/std/src/sys/backtrace.rs:40:26
   4:     0x73b8a97c7e3b - core::fmt::rt::Argument::fmt::hf85ec79e8cf86c67
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/core/src/fmt/rt.rs:173:76
   5:     0x73b8a97c7e3b - core::fmt::write::h133a0eb20f0a6a5d
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/core/src/fmt/mod.rs:1182:21
   6:     0x73b8a976ce9f - std::io::Write::write_fmt::h0b1c7497ddea4e96
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/std/src/io/mod.rs:1827:15
   7:     0x73b8a977abd1 - std::sys::backtrace::BacktraceLock::print::h7ea149d21a641076
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/std/src/sys/backtrace.rs:43:9
   8:     0x73b8a977abd1 - std::panicking::default_hook::{{closure}}::h7dd45b5804215332
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/std/src/panicking.rs:269:22
   9:     0x73b8a977a8ac - std::panicking::default_hook::haed8ee3169af9669
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/std/src/panicking.rs:296:9
  10:     0x73b8a5bf5aa9 - std[a568119b01f6acf9]::panicking::update_hook::<alloc[bb4b795e710d07dc]::boxed::Box<rustc_driver_impl[8e1afaf50ebeb9ae]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x73b8a977b59f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h28c95c685643affe
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/alloc/src/boxed.rs:2084:9
  12:     0x73b8a977b59f - std::panicking::rust_panic_with_hook::h4bf66cb658082ab2
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/std/src/panicking.rs:808:13
  13:     0x73b8a5c30361 - std[a568119b01f6acf9]::panicking::begin_panic::<rustc_errors[3a77a9bae9c6f06]::ExplicitBug>::{closure#0}
  14:     0x73b8a5c23166 - std[a568119b01f6acf9]::sys::backtrace::__rust_end_short_backtrace::<std[a568119b01f6acf9]::panicking::begin_panic<rustc_errors[3a77a9bae9c6f06]::ExplicitBug>::{closure#0}, !>
  15:     0x73b8a5c23116 - std[a568119b01f6acf9]::panicking::begin_panic::<rustc_errors[3a77a9bae9c6f06]::ExplicitBug>
  16:     0x73b8a5c397e1 - <rustc_errors[3a77a9bae9c6f06]::diagnostic::BugAbort as rustc_errors[3a77a9bae9c6f06]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  17:     0x73b8a6346c45 - <rustc_errors[3a77a9bae9c6f06]::DiagCtxtHandle>::span_bug::<rustc_span[38ccacee260ae995]::span_encoding::Span, &str>
  18:     0x73b8a63cea53 - rustc_mir_transform[c43e2c3dc4f9025]::coverage::query::coverage_attr_on
  19:     0x73b8a6611be7 - rustc_query_impl[3b609057f07f1dcd]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3b609057f07f1dcd]::query_impl::coverage_attr_on::dynamic_query::{closure#2}::{closure#0}, rustc_middle[755ee31b8896a314]::query::erase::Erased<[u8; 1usize]>>
  20:     0x73b8a77014a4 - rustc_query_system[f2631fe58e40596f]::query::plumbing::try_execute_query::<rustc_query_impl[3b609057f07f1dcd]::DynamicConfig<rustc_query_system[f2631fe58e40596f]::query::caches::VecCache<rustc_span[38ccacee260ae995]::def_id::LocalDefId, rustc_middle[755ee31b8896a314]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[3b609057f07f1dcd]::plumbing::QueryCtxt, false>
  21:     0x73b8a6616ec1 - rustc_query_impl[3b609057f07f1dcd]::query_impl::coverage_attr_on::get_query_non_incr::__rust_end_short_backtrace
  22:     0x73b8a635e95c - rustc_middle[755ee31b8896a314]::query::plumbing::query_get_at::<rustc_query_system[f2631fe58e40596f]::query::caches::VecCache<rustc_span[38ccacee260ae995]::def_id::LocalDefId, rustc_middle[755ee31b8896a314]::query::erase::Erased<[u8; 1usize]>>>
  23:     0x73b8a63ce902 - rustc_mir_transform[c43e2c3dc4f9025]::coverage::query::is_eligible_for_coverage
  24:     0x73b8a77190a7 - <rustc_mir_build[896911fd54276e87]::build::Builder>::new
  25:     0x73b8a770ce7b - rustc_mir_build[896911fd54276e87]::build::mir_build
  26:     0x73b8a770bc92 - rustc_query_impl[3b609057f07f1dcd]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3b609057f07f1dcd]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[755ee31b8896a314]::query::erase::Erased<[u8; 8usize]>>
  27:     0x73b8a74e5773 - rustc_query_system[f2631fe58e40596f]::query::plumbing::try_execute_query::<rustc_query_impl[3b609057f07f1dcd]::DynamicConfig<rustc_query_system[f2631fe58e40596f]::query::caches::VecCache<rustc_span[38ccacee260ae995]::def_id::LocalDefId, rustc_middle[755ee31b8896a314]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[3b609057f07f1dcd]::plumbing::QueryCtxt, false>
  28:     0x73b8a74e528d - rustc_query_impl[3b609057f07f1dcd]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  29:     0x73b8a7675ebe - rustc_mir_build[896911fd54276e87]::check_unsafety::check_unsafety
  30:     0x73b8a7675c5d - rustc_query_impl[3b609057f07f1dcd]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3b609057f07f1dcd]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[755ee31b8896a314]::query::erase::Erased<[u8; 0usize]>>
  31:     0x73b8a7674e17 - rustc_query_system[f2631fe58e40596f]::query::plumbing::try_execute_query::<rustc_query_impl[3b609057f07f1dcd]::DynamicConfig<rustc_query_system[f2631fe58e40596f]::query::caches::VecCache<rustc_span[38ccacee260ae995]::def_id::LocalDefId, rustc_middle[755ee31b8896a314]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[3b609057f07f1dcd]::plumbing::QueryCtxt, false>
  32:     0x73b8a7674a5b - rustc_query_impl[3b609057f07f1dcd]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  33:     0x73b8a76799b8 - rustc_interface[a03dee3aea9b1fd5]::passes::analysis
  34:     0x73b8a7678b07 - rustc_query_impl[3b609057f07f1dcd]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3b609057f07f1dcd]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[755ee31b8896a314]::query::erase::Erased<[u8; 1usize]>>
  35:     0x73b8a80f1965 - rustc_query_system[f2631fe58e40596f]::query::plumbing::try_execute_query::<rustc_query_impl[3b609057f07f1dcd]::DynamicConfig<rustc_query_system[f2631fe58e40596f]::query::caches::SingleCache<rustc_middle[755ee31b8896a314]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[3b609057f07f1dcd]::plumbing::QueryCtxt, false>
  36:     0x73b8a80f16cf - rustc_query_impl[3b609057f07f1dcd]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  37:     0x73b8a7fc1285 - rustc_interface[a03dee3aea9b1fd5]::interface::run_compiler::<core[da8eb5c0cc453d3]::result::Result<(), rustc_span[38ccacee260ae995]::ErrorGuaranteed>, rustc_driver_impl[8e1afaf50ebeb9ae]::run_compiler::{closure#0}>::{closure#1}
  38:     0x73b8a7f97b49 - std[a568119b01f6acf9]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[a03dee3aea9b1fd5]::util::run_in_thread_with_globals<rustc_interface[a03dee3aea9b1fd5]::util::run_in_thread_pool_with_globals<rustc_interface[a03dee3aea9b1fd5]::interface::run_compiler<core[da8eb5c0cc453d3]::result::Result<(), rustc_span[38ccacee260ae995]::ErrorGuaranteed>, rustc_driver_impl[8e1afaf50ebeb9ae]::run_compiler::{closure#0}>::{closure#1}, core[da8eb5c0cc453d3]::result::Result<(), rustc_span[38ccacee260ae995]::ErrorGuaranteed>>::{closure#0}, core[da8eb5c0cc453d3]::result::Result<(), rustc_span[38ccacee260ae995]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[da8eb5c0cc453d3]::result::Result<(), rustc_span[38ccacee260ae995]::ErrorGuaranteed>>
  39:     0x73b8a7f978fa - <<std[a568119b01f6acf9]::thread::Builder>::spawn_unchecked_<rustc_interface[a03dee3aea9b1fd5]::util::run_in_thread_with_globals<rustc_interface[a03dee3aea9b1fd5]::util::run_in_thread_pool_with_globals<rustc_interface[a03dee3aea9b1fd5]::interface::run_compiler<core[da8eb5c0cc453d3]::result::Result<(), rustc_span[38ccacee260ae995]::ErrorGuaranteed>, rustc_driver_impl[8e1afaf50ebeb9ae]::run_compiler::{closure#0}>::{closure#1}, core[da8eb5c0cc453d3]::result::Result<(), rustc_span[38ccacee260ae995]::ErrorGuaranteed>>::{closure#0}, core[da8eb5c0cc453d3]::result::Result<(), rustc_span[38ccacee260ae995]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[da8eb5c0cc453d3]::result::Result<(), rustc_span[38ccacee260ae995]::ErrorGuaranteed>>::{closure#2} as core[da8eb5c0cc453d3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  40:     0x73b8a97855fb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hcba9444f62f4d2cf
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/alloc/src/boxed.rs:2070:9
  41:     0x73b8a97855fb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h370ba06625738899
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/alloc/src/boxed.rs:2070:9
  42:     0x73b8a97855fb - std::sys::pal::unix::thread::Thread::new::thread_start::he74bac229ff12ca4
                               at /rustc/fcc325f1bc477975e2ce5ba534fe4c77ff8a8536/library/std/src/sys/pal/unix/thread.rs:108:17
  43:     0x73b8a26a6ded - <unknown>
  44:     0x73b8a272a0dc - <unknown>
  45:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: rustc 1.81.0-nightly (fcc325f1b 2024-07-17) running on x86_64-unknown-linux-gnu

note: compiler flags: -C instrument-coverage -Z dump-mir-dir=dir

query stack during panic:
#0 [coverage_attr_on] checking for `#[coverage(..)]` on `main`
#1 [mir_built] building MIR for `main`
end of query stack
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0658`.

@rustbot label +F-coverage_attribute

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Jul 17, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 17, 2024
@GrigorenkoPV
Copy link
Contributor

Regression in #126721

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jul 23, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 4, 2024
@jieyouxu jieyouxu added the A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) label Sep 29, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 3, 2024
Avoid ICE in coverage 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.

Fixes rust-lang#127880.
@bors bors closed this as completed in 28b64d8 Oct 4, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 4, 2024
Rollup merge of rust-lang#131187 - Zalathar:bad-attr-ice, r=jieyouxu

Avoid ICE in coverage 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.

Fixes rust-lang#127880.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants