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: no_core #98010

Closed
Zymlex opened this issue Jun 11, 2022 · 11 comments
Closed

ICE: no_core #98010

Zymlex opened this issue Jun 11, 2022 · 11 comments
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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

@Zymlex
Copy link

Zymlex commented Jun 11, 2022

Code

#![no_std]
#![no_core]
#![no_main]
#![feature(no_core, lang_items)]

#[lang = "sized"]
trait Sized {}
#[lang = "sync"]
trait Sync {}
#[lang = "copy"]
trait Copy {}
#[lang = "freeze"]
trait Freeze {}

impl Sync for u32 {}
impl Sync for i32 {}

// impl Copy for u32 {} // if remove, it cause rustc crash

#[lang = "drop_in_place"]
#[allow(unconditional_recursion)]
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) { unsafe { drop_in_place(to_drop) } }

#[link(name = "Kernel32")]
extern "system" {
    pub fn ExitProcess(uexitcode: u32) -> !;
}

fn exit_process(exit_code: u32) -> ! { // Copying is necessary to pass the value through the function argument, and if this is avoided, there will be no error either.
    unsafe {
        ExitProcess(exit_code);
    }
}

#[no_mangle]
pub extern "C" fn wWinMainCRTStartup() -> i32 {
    exit_process(0);
}

#[no_mangle]
pub static _fltused: i32 = 1;

similar https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=7a195a8a96465739641bc5b737854d10

Cargo.toml:

[profile.release]
rustflags = [
    '-C', 'link-args=/NODEFAULTLIB /Zl /SUBSYSTEM:WINDOWS /SAFESEH:NO /DYNAMICBASE:NO /ENTRY:wWinMainCRTStartup /LTCG'
]
panic = "abort"

Meta

rustc --version --verbose:

rustc 1.63.0-nightly (ec55c6130 2022-06-10)
binary: rustc
commit-hash: ec55c61305eaf385fc1b93ac9a78284b4d887fe5
commit-date: 2022-06-10
host: x86_64-pc-windows-msvc
release: 1.63.0-nightly
LLVM version: 14.0.5

Error output

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: broken MIR in DefId(0:11 ~ test_no_core[9a43]::exit_process) (NoSolution): could not prove Binder(TraitPredicate(<u32 as Copy>, polarity:Positive), [])
  |
  = note: delayed at compiler\rustc_borrowck\src\type_check\canonical.rs:151:13

thread 'rustc' panicked at 'Box<dyn Any>', compiler\rustc_errors\src\lib.rs:1373:13
note: 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.63.0-nightly (ec55c6130 2022-06-10) running on x86_64-pc-windows-msvc
note: compiler flags: --crate-type bin -C opt-level=3 -C link-args=/NODEFAULTLIB /Zl /SUBSYSTEM:WINDOWS /SAFESEH:NO /DYNAMICBASE:NO /ENTRY:wWinMainCRTStartup /LTCG -C panic=abort -C lto=fat -C codegen-units=1 -C incremental -Z macro-backtrace
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
error: could not compile `test`; 3 warnings emitted
Process finished with exit code 101

Backtrace

stack backtrace:
   0:     0x7ffcc6c09d1f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5878974d3101c2c1
   1:     0x7ffcc6c44d6a - core::fmt::write::h58b91005b62f62cb
   2:     0x7ffcc6bfc119 - <std::io::IoSlice as core::fmt::Debug>::fmt::h47ce2c587850b386
   3:     0x7ffcc6c0d60b - std::panicking::default_hook::h1cf6e1ccf8670b6e
   4:     0x7ffcc6c0d28b - std::panicking::default_hook::h1cf6e1ccf8670b6e
   5:     0x7ffcb68eb786 - rustc_driver[a11d5e36637d6ef8]::pretty::print_after_hir_lowering
   6:     0x7ffcc6c0ddb2 - std::panicking::rust_panic_with_hook::h8d89018be48b3be7
   7:     0x7ffcbb0b9ae5 - <rustc_errors[233cc4104dd9fe30]::styled_buffer::StyledChar as core[23edea91be4138c2]::fmt::Debug>::fmt
   8:     0x7ffcbb0b5969 - <rustc_errors[233cc4104dd9fe30]::styled_buffer::StyledChar as core[23edea91be4138c2]::fmt::Debug>::fmt
   9:     0x7ffcbb3fadf9 - rustc_query_system[4ba9814639d8c6d8]::query::plumbing::incremental_verify_ich_cold
  10:     0x7ffcbb0649a9 - <rustc_feature[80ac22f20521dda7]::builtin_attrs::AttributeType as core[23edea91be4138c2]::fmt::Debug>::fmt
  11:     0x7ffcbb0686dc - <rustc_errors[233cc4104dd9fe30]::HandlerInner as core[23edea91be4138c2]::ops::drop::Drop>::drop
  12:     0x7ffcb686cd64 - <rustc_lint[6c4a321fe5b8ec79]::BuiltinCombinedModuleLateLintPass as rustc_lint[6c4a321fe5b8ec79]::passes::LateLintPass>::check_mod_post
  13:     0x7ffcb68717ba - <rustc_lint[6c4a321fe5b8ec79]::BuiltinCombinedModuleLateLintPass as rustc_lint[6c4a321fe5b8ec79]::passes::LateLintPass>::check_mod_post
  14:     0x7ffcb68e40fd - <rustc_middle[fa74f14430eff12]::ty::SymbolName as core[23edea91be4138c2]::fmt::Debug>::fmt
  15:     0x7ffcb68e2319 - <rustc_middle[fa74f14430eff12]::ty::SymbolName as core[23edea91be4138c2]::fmt::Debug>::fmt
  16:     0x7ffcb687846d - <rustc_lint[6c4a321fe5b8ec79]::BuiltinCombinedModuleLateLintPass as rustc_lint[6c4a321fe5b8ec79]::passes::LateLintPass>::check_mod_post
  17:     0x7ffcb68dee76 - <rustc_metadata[7439ebc3b5fbc24c]::rmeta::encoder::EncodeContext as rustc_serialize[3bc617203079c8a5]::serialize::Encoder>::emit_raw_bytes
  18:     0x7ffcb68a2398 - <rustc_driver[a11d5e36637d6ef8]::args::Error as core[23edea91be4138c2]::fmt::Debug>::fmt
  19:     0x7ffcc6c1ef5c - std::sys::windows::thread::Thread::new::h40e1d95cdd0a661f
  20:     0x7ffcf5d47974 - BaseThreadInitThunk
  21:     0x7ffcf86ca2f1 - RtlUserThreadStart

image

@Zymlex Zymlex added C-bug Category: This is a bug. 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. labels Jun 11, 2022
@compiler-errors
Copy link
Member

This ICE is expected because there are certain assumptions the compiler makes about built-in types. In this case, it's that u32 implements Copy. For example, that assumption is hard-coded here, in Ty::is_trivially_pure_clone_copy.

I think there's a general assumption that #![no_core] programs will ICE in a large number of cases unless very carefully written, and ICEs due to #![no_core] should not be investigated in general.

@Zymlex
Copy link
Author

Zymlex commented Jun 12, 2022

I think there's a general assumption that #![no_core] programs will ICE in a large number of cases unless very carefully written, and ICEs due to #![no_core] should not be investigated in general.

Then no_core will not be stabilized in the foreseeable future.
I understand that this is created for a limited number of people and not for samples like mine.

@eggyal
Copy link
Contributor

eggyal commented Jun 12, 2022

I think there's a general assumption that #![no_core] programs will ICE in a large number of cases unless very carefully written, and ICEs due to #![no_core] should not be investigated in general.

Contradicts #29639 (comment):

ICEs need to be reported and fixed in most cases, even in no_core.

@compiler-errors
Copy link
Member

@eggyal, this summarizes my opinions on #![no_core] ICEs a bit better:

#92495 (comment)

Personally, I don't think ICEs with #![no_core] are worth addressing. It's a perma-unstable feature, and lang items are effectively internal compiler code that happens to be written in a crate. We don't try to prevent ICEs in the face of modifications to the compiler itself (in fact, many internal compiler APIs will deliberately ICE when they are used incorrectly).

The only correct way to use #![no_core] is to copy-paste all of the lang items, types, and impls that you're using (and even then, leaving out "unused" ones is pretty dubious).

And regardless, this is a duplicate of that issue #92495.

@eggyal
Copy link
Contributor

eggyal commented Jun 12, 2022

Ah, thanks for that. I've quoted it over in the tracking issue too.

@bjorn3
Copy link
Member

bjorn3 commented Jun 12, 2022

@Zymlex Using #![no_std] in combination with LTO to allow whole program dead code elimination should give the same size benefits as using #![no_core] I think.

@crlf0710 crlf0710 added the requires-nightly This issue requires a nightly compiler in some way. label Jun 13, 2022
@Zymlex
Copy link
Author

Zymlex commented Jun 13, 2022

@Zymlex Using #![no_std] in combination with LTO to allow whole program dead code elimination should give the same size benefits as using #![no_core] I think.

I was interested in the possibility of creating a program without core.

@langston-barrett
Copy link
Contributor

Minimized with Icemelter:

#![no_core]
#![feature(no_core, lang_items)]
#[lang = "sized"]
trait Sync {}
#[lang = "copy"]
trait Freeze {}

extern "C" {
    fn ExitProcess(uexitcode: u32) -> !;
}

fn exit_process(exit_code: u32) -> ! {
    unsafe {
        ExitProcess(exit_code);
    }
}
Details

Icemelter version: v0.2.0

@rustbot label +S-bug-has-mcve

@rustbot rustbot added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Mar 18, 2023
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 21, 2023
@JohnTitor
Copy link
Member

Fixed on the latest nightly, marking as E-needs-test (or, feel free to close if we have a sufficient regression test)
@rustbot labels: +E-needs-test

@rustbot rustbot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 15, 2023
@jruderman
Copy link
Contributor

glacier/fixed/98010.rs still ICEs for me

So does langston's minimization (if I add fn main() {})

Using rustc 1.75.0-nightly (fee5518 2023-11-05) on x86_64-apple-darwin

ICE output
warning: the feature `lang_items` is internal to the compiler or standard library
 --> /Users/jruderman/code/glacier/fixed/98010.rs:4:21
  |
4 | #![feature(no_core, lang_items)]
  |                     ^^^^^^^^^^
  |
  = note: using it is strongly discouraged
  = note: `#[warn(internal_features)]` on by default

warning: function `main` is never used
  --> /Users/jruderman/code/glacier/fixed/98010.rs:46:4
   |
46 | fn main() {}
   |    ^^^^
   |
   = note: `#[warn(dead_code)]` on by default

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: error performing ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: ProvePredicate { predicate: Binder { value: TraitPredicate(<u32 as Copy>, polarity:Positive), bound_vars: [] } } }
  --> /Users/jruderman/code/glacier/fixed/98010.rs:34:21
   |
34 |         ExitProcess(exit_code);
   |                     ^^^^^^^^^
   |
note: delayed at /Users/jruderman/code/rust/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs:163:36
         0: std::backtrace::Backtrace::create
         1: std::backtrace::Backtrace::capture
         2: <rustc_errors::HandlerInner>::emit_diagnostic
         3: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         4: <rustc_session::session::Session>::delay_span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         5: <rustc_middle::ty::ParamEnvAnd<rustc_middle::traits::query::type_op::ProvePredicate> as rustc_trait_selection::traits::query::type_op::TypeOp>::fully_perform
         6: <rustc_borrowck::type_check::TypeChecker>::fully_perform_op::<(), rustc_middle::ty::ParamEnvAnd<rustc_middle::traits::query::type_op::ProvePredicate>>
         7: <rustc_borrowck::type_check::TypeChecker>::prove_predicate::<rustc_middle::ty::sty::Binder<rustc_type_ir::predicate_kind::PredicateKind<rustc_middle::ty::context::TyCtxt>>>
         8: <rustc_borrowck::type_check::TypeChecker>::prove_trait_ref
         9: <rustc_borrowck::type_check::TypeVerifier>::sanitize_place
        10: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_rvalue
        11: <rustc_borrowck::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::super_body
        12: rustc_borrowck::type_check::type_check
        13: rustc_borrowck::nll::compute_regions
        14: rustc_borrowck::do_mir_borrowck
        15: rustc_borrowck::mir_borrowck
        16: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        17: <rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
        18: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<rustc_query_system::query::plumbing::execute_job_non_incr<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt>::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        19: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        20: rustc_query_impl::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
        21: std::panicking::try::<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::parallel::disabled::par_for_each_in<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_interface::passes::analysis::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}::{closure#0}>>
        22: <rustc_data_structures::sync::parallel::ParallelGuard>::run::<(), rustc_data_structures::sync::parallel::disabled::par_for_each_in<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_interface::passes::analysis::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}::{closure#0}>
        23: rustc_data_structures::sync::parallel::disabled::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_interface::passes::analysis::{closure#1}::{closure#0}>::{closure#0}>
        24: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#1}>
        25: rustc_interface::passes::analysis
        26: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        27: <rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
        28: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<rustc_query_system::query::plumbing::execute_job_non_incr<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt>::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        29: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        30: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        31: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#6}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        32: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#6}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        33: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
        34: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
        35: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        36: rustc_span::create_session_globals_then::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}>
        37: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        38: std::panicking::try::<core::result::Result<(), rustc_span::ErrorGuaranteed>, core::panic::unwind_safe::AssertUnwindSafe<<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1}::{closure#0}>>
        39: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        40: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
        41: std::sys::unix::thread::Thread::new::thread_start
        42: __pthread_start
  --> /Users/jruderman/code/glacier/fixed/98010.rs:34:21
   |
34 |         ExitProcess(exit_code);
   |                     ^^^^^^^^^

note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly

note: please attach the file at `/Users/jruderman/code/tt/rustc-ice-2023-11-07T20_16_33-18017.txt` to your bug report

query stack during panic:
end of query stack
error: aborting due to 2 previous errors; 2 warnings emitted

@compiler-errors
Copy link
Member

@jruderman: No need to test no_core code for ICEs. See fuzzing docs (ctrl+F for no_core).

I'm gonna close this since this is an obvious misuse of compiler-internal machinery.

@compiler-errors compiler-errors closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2023
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. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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

No branches or pull requests

10 participants