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/Panic in clippy_lints::functions::Functions #3747

Closed
martinsp opened this issue Feb 6, 2019 · 3 comments · Fixed by #3805
Closed

ICE/Panic in clippy_lints::functions::Functions #3747

martinsp opened this issue Feb 6, 2019 · 3 comments · Fixed by #3805
Assignees
Labels
I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ T-macros Type: Issues with macros and macro expansion

Comments

@martinsp
Copy link
Contributor

martinsp commented Feb 6, 2019

When running cargo clippy on https://github.com/Marwes/combine commit: d102591
Clippy fails with an error: "error: internal compiler error: unexpected panic"

rustc 1.34.0-nightly (4b1e39b 2019-02-05)
cargo 1.34.0-nightly (245818076 2019-01-27)
clippy 0.0.212 (3bda548 2019-02-03)

RUST_BACKTRACE=full cargo clippy --verbose
thread 'rustc' panicked at 'begin <= end (599 <= 288) when slicing `pub)
            $(#[$derive])*
            struct $type_name;
            type PartialState = (());
            $(#[$attr])*
            fn $name [$($type_params)*]($($arg : $arg_type),*)($input_type) -> $output_type
                where [$($where_clause`[...]', src/libcore/str/mod.rs:2030:5
stack backtrace:
   0:        0x112160ab3 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::ha1ab82cbb4d6f11c
   1:        0x1121598a2 - std::sys_common::backtrace::_print::h47aa5266c1122f38
   2:        0x11215d0a6 - std::panicking::default_hook::{{closure}}::h6025bf67340fffb6
   3:        0x11215cdb1 - std::panicking::default_hook::hd2ffbd67b944c8bd
   4:        0x1107950f1 - rustc::util::common::panic_hook::hd849485fe2261c61
   5:        0x11215d8f6 - std::panicking::rust_panic_with_hook::h7a5caae104289559
   6:        0x11215d34c - std::panicking::continue_panic_fmt::hc28906cb7d739d65
   7:        0x11215d238 - rust_begin_unwind
   8:        0x112185581 - core::panicking::panic_fmt::h602d6010de239117
   9:        0x112187a80 - core::str::slice_error_fail::h0a6327d8f0dedf0c
  10:        0x10df08b63 - core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::RangeFrom<usize>>::index::{{closure}}::h117fd6feb2ac7996
  11:        0x10df190a8 - <clippy_lints::functions::Functions as rustc::lint::LateLintPass<'a, 'tcx>>::check_fn::h34c461502c97d641
  12:        0x11044ca1d - <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn::hab73580c424b9152
  13:        0x11079fe4a - rustc::hir::intravisit::walk_item::h90f74b5c6bc09e29
  14:        0x11044b8c0 - <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item::h03734fcaf896086f
  15:        0x11044de6e - <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod::hf8703dff7658a9c7
  16:        0x11079fb6b - rustc::hir::intravisit::walk_item::h90f74b5c6bc09e29
  17:        0x11044b8c0 - <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item::h03734fcaf896086f
  18:        0x11044de6e - <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod::hf8703dff7658a9c7
  19:        0x11079fb6b - rustc::hir::intravisit::walk_item::h90f74b5c6bc09e29
  20:        0x11044b8c0 - <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item::h03734fcaf896086f
  21:        0x11044de6e - <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod::hf8703dff7658a9c7
  22:        0x11079a730 - rustc::hir::intravisit::walk_crate::h57b0d5e573659763
  23:        0x110450646 - rustc::lint::context::check_crate::h442ccfb7bca93304
  24:        0x10e411c26 - rustc::util::common::time::h668ff82752432600
  25:        0x10e3fc533 - <std::thread::local::LocalKey<T>>::with::h3871b7c8edad0c47
  26:        0x10e3a2cae - rustc::ty::context::TyCtxt::create_and_enter::h1e37fb2793e7410a
  27:        0x10e46e243 - rustc_driver::driver::compile_input::h7031c7b83d4fdee0
  28:        0x10e41af36 - rustc_driver::run_compiler_with_pool::h3638dc7dc27c0a19
  29:        0x10e3b639e - <scoped_tls::ScopedKey<T>>::set::h78384758c2378251
  30:        0x10e419ea8 - rustc_driver::run_compiler::h09bc4bbb4983c6f9
  31:        0x10dd8eb9b - <scoped_tls::ScopedKey<T>>::set::h4f9f78ea9739d6be
  32:        0x10dd80f6d - std::sys_common::backtrace::__rust_begin_short_backtrace::he6028cd38f2f7ad6
  33:        0x11216d33e - __rust_maybe_catch_panic
  34:        0x10dd8259d - <F as alloc::boxed::FnBox<A>>::call_box::h49377575077b31ed
  35:        0x11216c2ab - std::sys::unix::thread::Thread::new::thread_start::hda92a3e89ce02644
  36:     0x7fff65034304 - _pthread_body
  37:     0x7fff6503726e - _pthread_start
query stack during panic:
end of query stack

error: internal compiler error: unexpected panic

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.34.0-nightly (4b1e39b7b 2019-02-05) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `combine`.

I have created a reduced test case (I think it triggers the same bug)
Test case
macro_rules! prepend_2 {
    (
        ( $($pub_: tt)* )
        $(#[$derive:meta])*
        struct $type_name: ident;
        $(#[$attr:meta])*
        fn $name: ident ()
        $parser: block
    ) => {
        $(#[$attr])*
        #[inline(always)]
        $($pub_)* fn $name() {
            println!("Prepended 2");
            $parser
        }
    };
}

macro_rules! prepend_1 {
    (
        $(#[$derive:meta])*
        pub struct $type_name: ident;
        $(#[$attr:meta])*
        pub fn $name: ident ()
        $parser: block
    ) => {
        prepend_2! {
            (pub)
            $(#[$derive])*
            struct $type_name;
            fn $name () {
                println!("Prepended 1");
                $parser
            }
        }
    };
}

prepend_1! {
    #[derive(Copy, Clone)]
    pub struct StructOne;
    /// Prints "Hello World!".
    pub fn say_hello() {
        println!("Hello World!");
    }
}

fn main() {
    say_hello();
}

cargo is compiling and running the code
cargo run
Prepended 2
Prepended 1
Hello World!

Running clippy fails with a panic
RUST_BACKTRACE=full cargo clippy --verbose
thread 'rustc' panicked at 'begin <= end (36 <= 0) when slicing `}
    };
}

macro_rules! prepend_1 {
    (
        $(#[$derive:meta])*
        pub struct $type_name: ident;
        $(#[$attr:meta])*
        pub fn $name: ident ()
        $parser: block
    ) => {
        prepend_2! {
            (pub`', src/libcore/str/mod.rs:2030:5
stack backtrace:
   0:        0x10fafdab3 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::ha1ab82cbb4d6f11c
   1:        0x10faf68a2 - std::sys_common::backtrace::_print::h47aa5266c1122f38
   2:        0x10fafa0a6 - std::panicking::default_hook::{{closure}}::h6025bf67340fffb6
   3:        0x10faf9db1 - std::panicking::default_hook::hd2ffbd67b944c8bd
   4:        0x10e1260f1 - rustc::util::common::panic_hook::hd849485fe2261c61
   5:        0x10fafa8f6 - std::panicking::rust_panic_with_hook::h7a5caae104289559
   6:        0x10fafa34c - std::panicking::continue_panic_fmt::hc28906cb7d739d65
   7:        0x10fafa238 - rust_begin_unwind
   8:        0x10fb22581 - core::panicking::panic_fmt::h602d6010de239117
   9:        0x10fb24a80 - core::str::slice_error_fail::h0a6327d8f0dedf0c
  10:        0x10b89cb63 - core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::RangeFrom<usize>>::index::{{closure}}::h117fd6feb2ac7996
  11:        0x10b8ad0a8 - <clippy_lints::functions::Functions as rustc::lint::LateLintPass<'a, 'tcx>>::check_fn::h34c461502c97d641
  12:        0x10dddda1d - <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn::hab73580c424b9152
  13:        0x10e130e4a - rustc::hir::intravisit::walk_item::h90f74b5c6bc09e29
  14:        0x10dddc8c0 - <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item::h03734fcaf896086f
  15:        0x10dddee6e - <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod::hf8703dff7658a9c7
  16:        0x10e12b730 - rustc::hir::intravisit::walk_crate::h57b0d5e573659763
  17:        0x10dde1646 - rustc::lint::context::check_crate::h442ccfb7bca93304
  18:        0x10bda7c26 - rustc::util::common::time::h668ff82752432600
  19:        0x10bd92533 - <std::thread::local::LocalKey<T>>::with::h3871b7c8edad0c47
  20:        0x10bd38cae - rustc::ty::context::TyCtxt::create_and_enter::h1e37fb2793e7410a
  21:        0x10be04243 - rustc_driver::driver::compile_input::h7031c7b83d4fdee0
  22:        0x10bdb0f36 - rustc_driver::run_compiler_with_pool::h3638dc7dc27c0a19
  23:        0x10bd4c39e - <scoped_tls::ScopedKey<T>>::set::h78384758c2378251
  24:        0x10bdafea8 - rustc_driver::run_compiler::h09bc4bbb4983c6f9
  25:        0x10b722b9b - <scoped_tls::ScopedKey<T>>::set::h4f9f78ea9739d6be
  26:        0x10b714f6d - std::sys_common::backtrace::__rust_begin_short_backtrace::he6028cd38f2f7ad6
  27:        0x10fb0a33e - __rust_maybe_catch_panic
  28:        0x10b71659d - <F as alloc::boxed::FnBox<A>>::call_box::h49377575077b31ed
  29:        0x10fb092ab - std::sys::unix::thread::Thread::new::thread_start::hda92a3e89ce02644
  30:     0x7fff65034304 - _pthread_body
  31:     0x7fff6503726e - _pthread_start
query stack during panic:
end of query stack

error: internal compiler error: unexpected panic

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.34.0-nightly (4b1e39b7b 2019-02-05) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden
@phansch phansch added I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ T-macros Type: Issues with macros and macro expansion labels Feb 6, 2019
@phansch
Copy link
Member

phansch commented Feb 6, 2019

Thanks for the report and testcase!

@phansch phansch self-assigned this Feb 6, 2019
@jfirebaugh
Copy link

Further reduced:

macro_rules! a {
    ( $pub:tt $($attr:tt)* ) => {
        $($attr)* $pub fn say_hello() {}
    };
}

macro_rules! b {
    () => { a! { pub } };
}

b! {}

This crashes on the playground, but for some reason I couldn't reproduce locally.

@mati865
Copy link
Contributor

mati865 commented Feb 17, 2019

@jfirebaugh it does panic with nightly-2019-02-07:

thread 'rustc' panicked at 'begin <= end (28 <= 0) when slicing `}
    };
}

macro_rules! b {
    () => { a! { pub`', src/libcore/str/mod.rs:2030:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:482
   6: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:385
   7: rust_begin_unwind
             at src/libstd/panicking.rs:312
   8: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
   9: core::str::slice_error_fail
             at src/libcore/str/mod.rs:0
  10: core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::RangeFrom<usize>>::index::{{closure}}
  11: <clippy_lints::functions::Functions as rustc::lint::LateLintPass<'a, 'tcx>>::check_fn
  12: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn
  13: rustc::hir::intravisit::walk_item
  14: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  15: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod
  16: rustc::hir::intravisit::walk_crate
  17: rustc::lint::context::check_crate
  18: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::{{closure}}
  19: rustc::util::common::time
  20: <std::thread::local::LocalKey<T>>::with
  21: rustc::ty::context::TyCtxt::create_and_enter
  22: rustc_driver::driver::compile_input
  23: <scoped_tls::ScopedKey<T>>::set
  24: rustc_driver::run_compiler
  25: <scoped_tls::ScopedKey<T>>::set
query stack during panic:
end of query stack

bors added a commit that referenced this issue Feb 25, 2019
Fix ICE #3747

I'm not sure if this was the correct approach.

I don't know if I put tests/ui/crashses/ice-3747.rs in correct place because the test always passed when I ran it with `cargo test`, even without the fix applied.

If I run that test with `env CLIPPY_TESTS=true cargo run --bin clippy-driver -- -L ./target/debug tests/ui/crashes/ice-3747.rs` then the test correctly fails without the fix applied

fixes #3747
phansch added a commit to phansch/rust-clippy that referenced this issue Apr 13, 2019
repo link: https://github.com/Marwes/combine

`combine` uses a lot of macros internally, has been downloaded more than 200_000
times and is also a dependency of [`redis-rs`](https://crates.io/crates/redis).

Clippy also previously ICEd on combine in rust-lang#3747 so I think it would be
good to have this crate as an integration test.
bors added a commit that referenced this issue Apr 13, 2019
Add Marwes/combine to integration tests

repo link: https://github.com/Marwes/combine

`combine` uses a lot of macros internally, has been downloaded more than 200_000
times and is also a dependency of [`redis-rs`](https://crates.io/crates/redis).

Clippy also previously ICEd on combine in #3747 so I think it would be
good to have this crate as an integration test.
bors added a commit that referenced this issue Apr 14, 2019
Add Marwes/combine to integration tests

repo link: https://github.com/Marwes/combine

`combine` uses a lot of macros internally, has been downloaded more than 200_000
times and is also a dependency of [`redis-rs`](https://crates.io/crates/redis).

Clippy also previously ICEd on combine in #3747 so I think it would be
good to have this crate as an integration test.
bors added a commit that referenced this issue Apr 14, 2019
Add Marwes/combine to integration tests

repo link: https://github.com/Marwes/combine

`combine` uses a lot of macros internally, has been downloaded more than 200_000
times and is also a dependency of [`redis-rs`](https://crates.io/crates/redis).

Clippy also previously ICEd on combine in #3747 so I think it would be
good to have this crate as an integration test.
bors added a commit that referenced this issue Apr 14, 2019
Add Marwes/combine to integration tests

repo link: https://github.com/Marwes/combine

`combine` uses a lot of macros internally, has been downloaded more than 200_000
times and is also a dependency of [`redis-rs`](https://crates.io/crates/redis).

Clippy also previously ICEd on combine in #3747 so I think it would be
good to have this crate as an integration test.
Manishearth pushed a commit that referenced this issue Apr 19, 2019
[Martins Polakovs, John Firebaugh]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants