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: cfi: encode_ty: unexpected 'CoroutineWitness' #122705

Closed
matthiaskrgr opened this issue Mar 18, 2024 · 6 comments
Closed

ICE: cfi: encode_ty: unexpected 'CoroutineWitness' #122705

matthiaskrgr opened this issue Mar 18, 2024 · 6 comments
Labels
C-bug Category: This is a bug. F-async_closure `#![feature(async_closure)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ PG-exploit-mitigations Project group: Exploit mitigations S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Mar 18, 2024

auto-reduced (treereduce-rust):

#![feature(async_closure)]

fn main() {
    let a = async move |a: i32, b: i32| {};
    let b = |a: i32, b: i32| {};
    a(1, 2);
    b(1, 2);
}
original code

original:

//@ compile-flags: --cfg something
//@ edition:2018

#![feature(async_closure)]
#![deny(unused_variables)]

async fn foo_async(
    a: i32,
    //~^ ERROR unused variable: `a`
    #[allow(unused_variables)] b: i32,
) {}
fn foo(
    #[allow(unused_variables)] a: i32,
    b: i32,
    //~^ ERROR unused variable: `b`
) {}

struct RefStruct {}
impl RefStruct {
    async fn bar_async(
        &self,
        a: i32,
        //~^ ERROR unused variable: `a`
        #[allow(unused_variables)] b: i32,
    ) {}
    fn bar(
        &self,
        #[allow(unused_variables)] a: i32,
        b: i32,
        //~^ ERROR unused variable: `b`
    ) {}
    fn issue_64682_associated_fn(
        #[allow(unused_variables)] a: i32,
        b: i32,
        //~^ ERROR unused variable: `b`
    ) {}
}
trait RefTrait {
    fn bar(
        &self,
        #[allow(unused_variables)] a: i32,
        b: i32,
        //~^ ERROR unused variable: `b`
    ) {}
    fn issue_64682_associated_fn(
        #[allow(unused_variables)] a: i32,
        b: i32,
        //~^ ERROR unused variable: `b`
    ) {}
}
impl RefTrait for RefStruct {
    fn bar(
        &self,
        #[allow(unused_variables)] a: i32,
        b: i32,
        //~^ ERROR unused variable: `b`
    ) {}
    fn issue_64682_associated_fn(
        #[allow(unused_variables)] a: i32,
        b: i32,
        //~^ ERROR unused variable: `b`
    ) {}
}

fn main() {
    let _: fn(_, _) = foo;
    let a = async move |
        a: i32,
        //~^ ERROR unused variable: `a`
        #[allow(unused_variables)] b: i32,
    | {};
    let b = |
        #[allow(unused_variables)] a: i32,
        b: i32,
        //~^ ERROR unused variable: `b`
    | {};
    a(1, 2);
    b(1, 2);
}

Version information

rustc 1.79.0-nightly (3cdcdaf31 2024-03-18)
binary: rustc
commit-hash: 3cdcdaf31b45f8045164aae9604573d23091970b
commit-date: 2024-03-18
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --edition=2021 --cap-lints=warn -Zsanitizer=cfi -Ccodegen-units=1 -Clto

Program output

warning: unused variable: `a`
 --> /tmp/icemaker_global_tempdir.Zzjtx1Evw50c/rustc_testrunner_tmpdir_reporting.EkN8stMQHPaP/mvce.rs:4:25
  |
4 |     let a = async move |a: i32, b: i32| {};
  |                         ^ help: if this is intentional, prefix it with an underscore: `_a`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `b`
 --> /tmp/icemaker_global_tempdir.Zzjtx1Evw50c/rustc_testrunner_tmpdir_reporting.EkN8stMQHPaP/mvce.rs:4:33
  |
4 |     let a = async move |a: i32, b: i32| {};
  |                                 ^ help: if this is intentional, prefix it with an underscore: `_b`

warning: unused variable: `a`
 --> /tmp/icemaker_global_tempdir.Zzjtx1Evw50c/rustc_testrunner_tmpdir_reporting.EkN8stMQHPaP/mvce.rs:5:14
  |
5 |     let b = |a: i32, b: i32| {};
  |              ^ help: if this is intentional, prefix it with an underscore: `_a`

warning: unused variable: `b`
 --> /tmp/icemaker_global_tempdir.Zzjtx1Evw50c/rustc_testrunner_tmpdir_reporting.EkN8stMQHPaP/mvce.rs:5:22
  |
5 |     let b = |a: i32, b: i32| {};
  |                      ^ help: if this is intentional, prefix it with an underscore: `_b`

warning: unused implementer of `Future` that must be used
 --> /tmp/icemaker_global_tempdir.Zzjtx1Evw50c/rustc_testrunner_tmpdir_reporting.EkN8stMQHPaP/mvce.rs:6:5
  |
6 |     a(1, 2);
  |     ^^^^^^^
  |
  = note: futures do nothing unless you `.await` or poll them
  = note: `#[warn(unused_must_use)]` on by default

error: internal compiler error: compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs:737:13: encode_ty: unexpected `CoroutineWitness(DefId(0:5 ~ mvce[abe4]::main::{closure#0}::{closure#0}), [])`

thread 'rustc' panicked at compiler/rustc_middle/src/util/bug.rs:35:44:
Box<dyn Any>
stack backtrace:
   0:     0x7fc2e75a1fa5 - std::backtrace_rs::backtrace::libunwind::trace::h14c26439c9e659cb
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7fc2e75a1fa5 - std::backtrace_rs::backtrace::trace_unsynchronized::h44d92edd05bbbfda
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fc2e75a1fa5 - std::sys_common::backtrace::_print_fmt::h13f1beea5570cb83
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7fc2e75a1fa5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb8ca44e969e3f71b
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fc2e75f2feb - core::fmt::rt::Argument::fmt::h5c946a89981df55e
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/core/src/fmt/rt.rs:142:9
   5:     0x7fc2e75f2feb - core::fmt::write::hd586e7360777cc96
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/core/src/fmt/mod.rs:1153:17
   6:     0x7fc2e7596cbf - std::io::Write::write_fmt::h710cbd7bbf99ccca
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/std/src/io/mod.rs:1843:15
   7:     0x7fc2e75a1d7e - std::sys_common::backtrace::_print::hf1afff5c335e465f
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fc2e75a1d7e - std::sys_common::backtrace::print::he54a51a147efc885
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fc2e75a49f9 - std::panicking::default_hook::{{closure}}::hcd08c4e3ffa464ca
  10:     0x7fc2e75a4763 - std::panicking::default_hook::h2663042b363aa298
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/std/src/panicking.rs:292:9
  11:     0x7fc2e41ba58f - std[f1ab4ce7166604a0]::panicking::update_hook::<alloc[ef09d9835563b69e]::boxed::Box<rustc_driver_impl[76e846938966200a]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fc2e75a5150 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hcd6186c20f61b1dd
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/alloc/src/boxed.rs:2034:9
  13:     0x7fc2e75a5150 - std::panicking::rust_panic_with_hook::h2a6da5de52d72055
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/std/src/panicking.rs:783:13
  14:     0x7fc2e41e6a54 - std[f1ab4ce7166604a0]::panicking::begin_panic::<rustc_errors[c906f5c4cf1f88ae]::ExplicitBug>::{closure#0}
  15:     0x7fc2e41e3976 - std[f1ab4ce7166604a0]::sys_common::backtrace::__rust_end_short_backtrace::<std[f1ab4ce7166604a0]::panicking::begin_panic<rustc_errors[c906f5c4cf1f88ae]::ExplicitBug>::{closure#0}, !>
  16:     0x7fc2e41e3656 - std[f1ab4ce7166604a0]::panicking::begin_panic::<rustc_errors[c906f5c4cf1f88ae]::ExplicitBug>
  17:     0x7fc2e41efed1 - <rustc_errors[c906f5c4cf1f88ae]::diagnostic::BugAbort as rustc_errors[c906f5c4cf1f88ae]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7fc2e4675b91 - rustc_middle[712e48954d6afe8b]::util::bug::opt_span_bug_fmt::<rustc_span[74819862fbf5924e]::span_encoding::Span>::{closure#0}
  19:     0x7fc2e4658ffa - rustc_middle[712e48954d6afe8b]::ty::context::tls::with_opt::<rustc_middle[712e48954d6afe8b]::util::bug::opt_span_bug_fmt<rustc_span[74819862fbf5924e]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7fc2e4658e98 - rustc_middle[712e48954d6afe8b]::ty::context::tls::with_context_opt::<rustc_middle[712e48954d6afe8b]::ty::context::tls::with_opt<rustc_middle[712e48954d6afe8b]::util::bug::opt_span_bug_fmt<rustc_span[74819862fbf5924e]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7fc2e239c5a0 - rustc_middle[712e48954d6afe8b]::util::bug::bug_fmt
  22:     0x7fc2e4b28802 - rustc_symbol_mangling[6a6f4f831c70879f]::typeid::typeid_itanium_cxx_abi::encode_ty
  23:     0x7fc2e4b260b7 - rustc_symbol_mangling[6a6f4f831c70879f]::typeid::typeid_itanium_cxx_abi::encode_args
  24:     0x7fc2e4b26a8f - rustc_symbol_mangling[6a6f4f831c70879f]::typeid::typeid_itanium_cxx_abi::encode_ty
  25:     0x7fc2e4b27252 - rustc_symbol_mangling[6a6f4f831c70879f]::typeid::typeid_itanium_cxx_abi::encode_ty
  26:     0x7fc2e4b2b5f2 - rustc_symbol_mangling[6a6f4f831c70879f]::typeid::typeid_itanium_cxx_abi::typeid_for_fnabi
  27:     0x7fc2e4b2a557 - rustc_symbol_mangling[6a6f4f831c70879f]::typeid::typeid_itanium_cxx_abi::typeid_for_instance
  28:     0x7fc2e29d368a - <rustc_codegen_llvm[4330239e0645e5fe]::context::CodegenCx as rustc_codegen_ssa[c5bbf89d97e47a4c]::traits::declare::PreDefineMethods>::predefine_fn
  29:     0x7fc2e6128613 - rustc_codegen_llvm[4330239e0645e5fe]::base::compile_codegen_unit::module_codegen
  30:     0x7fc2e6124956 - <rustc_codegen_llvm[4330239e0645e5fe]::LlvmCodegenBackend as rustc_codegen_ssa[c5bbf89d97e47a4c]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  31:     0x7fc2e631aceb - rustc_codegen_ssa[c5bbf89d97e47a4c]::base::codegen_crate::<rustc_codegen_llvm[4330239e0645e5fe]::LlvmCodegenBackend>
  32:     0x7fc2e630daa9 - <rustc_codegen_llvm[4330239e0645e5fe]::LlvmCodegenBackend as rustc_codegen_ssa[c5bbf89d97e47a4c]::traits::backend::CodegenBackend>::codegen_crate
  33:     0x7fc2e630d41f - rustc_interface[6e8cd5a4c59e5ecd]::passes::start_codegen
  34:     0x7fc2e630cbbf - <rustc_interface[6e8cd5a4c59e5ecd]::queries::Queries>::codegen_and_build_linker
  35:     0x7fc2e60900d7 - rustc_interface[6e8cd5a4c59e5ecd]::interface::run_compiler::<core[254dfe32d5b92b13]::result::Result<(), rustc_span[74819862fbf5924e]::ErrorGuaranteed>, rustc_driver_impl[76e846938966200a]::run_compiler::{closure#0}>::{closure#0}
  36:     0x7fc2e6160a45 - std[f1ab4ce7166604a0]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6e8cd5a4c59e5ecd]::util::run_in_thread_with_globals<rustc_interface[6e8cd5a4c59e5ecd]::util::run_in_thread_pool_with_globals<rustc_interface[6e8cd5a4c59e5ecd]::interface::run_compiler<core[254dfe32d5b92b13]::result::Result<(), rustc_span[74819862fbf5924e]::ErrorGuaranteed>, rustc_driver_impl[76e846938966200a]::run_compiler::{closure#0}>::{closure#0}, core[254dfe32d5b92b13]::result::Result<(), rustc_span[74819862fbf5924e]::ErrorGuaranteed>>::{closure#0}, core[254dfe32d5b92b13]::result::Result<(), rustc_span[74819862fbf5924e]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[254dfe32d5b92b13]::result::Result<(), rustc_span[74819862fbf5924e]::ErrorGuaranteed>>
  37:     0x7fc2e6160872 - <<std[f1ab4ce7166604a0]::thread::Builder>::spawn_unchecked_<rustc_interface[6e8cd5a4c59e5ecd]::util::run_in_thread_with_globals<rustc_interface[6e8cd5a4c59e5ecd]::util::run_in_thread_pool_with_globals<rustc_interface[6e8cd5a4c59e5ecd]::interface::run_compiler<core[254dfe32d5b92b13]::result::Result<(), rustc_span[74819862fbf5924e]::ErrorGuaranteed>, rustc_driver_impl[76e846938966200a]::run_compiler::{closure#0}>::{closure#0}, core[254dfe32d5b92b13]::result::Result<(), rustc_span[74819862fbf5924e]::ErrorGuaranteed>>::{closure#0}, core[254dfe32d5b92b13]::result::Result<(), rustc_span[74819862fbf5924e]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[254dfe32d5b92b13]::result::Result<(), rustc_span[74819862fbf5924e]::ErrorGuaranteed>>::{closure#1} as core[254dfe32d5b92b13]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x7fc2e75ae919 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h24cb68345bc0eeeb
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/alloc/src/boxed.rs:2020:9
  39:     0x7fc2e75ae919 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1d32c6c52d61212f
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/alloc/src/boxed.rs:2020:9
  40:     0x7fc2e75ae919 - std::sys::pal::unix::thread::Thread::new::thread_start::h789f3c93e78a3e64
                               at /rustc/3cdcdaf31b45f8045164aae9604573d23091970b/library/std/src/sys/pal/unix/thread.rs:108:17
  41:     0x7fc2e10a955a - <unknown>
  42:     0x7fc2e1126a3c - <unknown>
  43:                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: rustc 1.79.0-nightly (3cdcdaf31 2024-03-18) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z sanitizer=cfi -C codegen-units=1 -C lto -Z dump-mir-dir=dir

query stack during panic:
end of query stack
error: aborting due to 1 previous error; 5 warnings emitted


@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 Mar 18, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 18, 2024
@jieyouxu jieyouxu added F-async_closure `#![feature(async_closure)]` S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 19, 2024
@workingjubilee workingjubilee added the PG-exploit-mitigations Project group: Exploit mitigations label Mar 19, 2024
@workingjubilee
Copy link
Member

cc @rcvalle @maurer

@maurer

This comment was marked as outdated.

@workingjubilee
Copy link
Member

workingjubilee commented Mar 19, 2024

oh does it now? interesting.

@compiler-errors
Copy link
Member

@maurer: This doesn't change the way that TyKind::CoroutineClosure (i.e. async closures) are encoded in CFI, so this isn't a fix. This still ICEs, for example:

#![feature(async_closure)]

#[inline(never)]
fn foo<T>(x: T) {}

fn main() {
    let a = async move |a: i32, b: i32| {};
    foo(a);
}

Not sure why we're not just encoding the parent args for closures and coroutine-closures. I'll put up a PR.

@rustbot claim

@maurer
Copy link
Contributor

maurer commented Mar 19, 2024

Yes, you're right, we need to be able to encode these.

@compiler-errors
Copy link
Member

Well @rcvalle just pinged me and said he may have a PR that already addresses this, so I guess I'll wait for him to comment. If not, I'll put up a fix for this in a few days since I'm the expert on ty::CoroutineClosure.

@compiler-errors compiler-errors removed their assignment Mar 19, 2024
rcvalle added a commit to rcvalle/rust that referenced this issue Mar 21, 2024
Fix rust-lang#122705 by adding support for encoding `ty:CoroutineClosure`.
rcvalle added a commit to rcvalle/rust that referenced this issue Mar 22, 2024
Fix rust-lang#122705 by adding support for encoding `ty:CoroutineClosure`.
rcvalle added a commit to rcvalle/rust that referenced this issue Mar 22, 2024
Fix rust-lang#122705 by adding support for encoding `ty:CoroutineClosure`.
rcvalle added a commit to rcvalle/rust that referenced this issue Mar 22, 2024
Fix rust-lang#122705 by adding support for encoding `ty:CoroutineClosure`.
rcvalle added a commit to rcvalle/rust that referenced this issue Mar 22, 2024
Fix rust-lang#122705 by adding support for encoding `ty:CoroutineClosure`.
rcvalle added a commit to rcvalle/rust that referenced this issue Mar 22, 2024
Fix rust-lang#122705 by adding support for encoding `ty:CoroutineClosure`.
rcvalle added a commit to rcvalle/rust that referenced this issue Mar 22, 2024
Fix rust-lang#122705 by adding support for encoding `ty:CoroutineClosure`.
rcvalle added a commit to rcvalle/rust that referenced this issue Mar 22, 2024
Fix rust-lang#122705 by adding support for encoding `ty:CoroutineClosure`.
rcvalle added a commit to rcvalle/rust that referenced this issue Mar 23, 2024
Fix rust-lang#122705 by adding support for encoding `ty:CoroutineClosure`.
maurer added a commit to maurer/rust that referenced this issue Mar 27, 2024
maurer added a commit to maurer/rust that referenced this issue Mar 27, 2024
maurer added a commit to maurer/rust that referenced this issue Mar 27, 2024
maurer added a commit to maurer/rust that referenced this issue Mar 28, 2024
maurer added a commit to maurer/rust that referenced this issue Mar 28, 2024
maurer added a commit to maurer/rust that referenced this issue Mar 29, 2024
maurer added a commit to maurer/rust that referenced this issue Mar 30, 2024
@bors bors closed this as completed in e974570 Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-async_closure `#![feature(async_closure)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ PG-exploit-mitigations Project group: Exploit mitigations S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

6 participants