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 with mir-opt-level=2: store_with_flags: invalid ScalarPair layout #66856

Closed
bytwise opened this issue Nov 28, 2019 · 1 comment · Fixed by #66870
Closed

ICE with mir-opt-level=2: store_with_flags: invalid ScalarPair layout #66856

bytwise opened this issue Nov 28, 2019 · 1 comment · Fixed by #66870
Assignees
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bytwise
Copy link
Contributor

bytwise commented Nov 28, 2019

PR #66282 introduced an ICE in the following code with -Z mir-opt-level=2:

enum Src {
    Foo(u8),
    Bar,
}

enum Dst {
    Foo(u8),
}

fn main() {
    let e: Src = Src::Foo(0);
    let _: Dst = match e {
        Src::Foo(x) => Dst::Foo(x),
        Src::Bar => Dst::Foo(0),
    };
}

Compiler output

error: internal compiler error: src/librustc_codegen_ssa/mir/operand.rs:329: store_with_flags: invalid ScalarPair layout: TyLayout {
    ty: Dst,
    details: LayoutDetails {
        variants: Single {
            index: 0,
        },
        fields: Arbitrary {
            offsets: [
                Size {
                    raw: 0,
                },
            ],
            memory_index: [
                0,
            ],
        },
        abi: Scalar(
            Scalar {
                value: Int(
                    I8,
                    false,
                ),
                valid_range: 0..=255,
            },
        ),
        largest_niche: None,
        align: AbiAndPrefAlign {
            abi: Align {
                pow2: 0,
            },
            pref: Align {
                pow2: 3,
            },
        },
        size: Size {
            raw: 1,
        },
    },
}

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:892:9
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: std::panicking::begin_panic
   8: rustc_errors::HandlerInner::bug
   9: rustc_errors::Handler::bug
  10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  11: rustc::ty::context::tls::with_opt::{{closure}}
  12: rustc::ty::context::tls::with_opt
  13: rustc::util::bug::opt_span_bug_fmt
  14: rustc::util::bug::bug_fmt
  15: rustc_codegen_ssa::mir::operand::OperandValue<V>::store_with_flags
  16: rustc_codegen_ssa::mir::rvalue::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_rvalue
  17: rustc_codegen_ssa::mir::codegen_mir
  18: rustc_codegen_ssa::base::codegen_instance
  19: <rustc::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
  20: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  21: rustc::dep_graph::graph::DepGraph::with_task
  22: rustc_codegen_llvm::base::compile_codegen_unit
  23: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  24: rustc_interface::passes::start_codegen::{{closure}}
  25: rustc_interface::passes::start_codegen
  26: rustc::ty::context::tls::enter_global
  27: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  28: rustc_interface::passes::create_global_ctxt::{{closure}}
  29: rustc_interface::passes::BoxedGlobalCtxt::enter
  30: rustc_interface::queries::Query<T>::compute
  31: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
  32: rustc_interface::interface::run_compiler_in_existing_thread_pool
  33: std::thread::local::LocalKey<T>::with
  34: scoped_tls::ScopedKey<T>::set
  35: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.41.0-nightly (e87a205c2 2019-11-27) running on x86_64-apple-darwin

note: compiler flags: -Z mir-opt-level=2

query stack during panic:
end of query stack
error: aborting due to previous error
@scottmcm scottmcm added A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Nov 29, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 29, 2019
@scottmcm
Copy link
Member

scottmcm commented Nov 29, 2019

cc @Centril

with mir-opt-level=1:

    bb3: {
        StorageLive(_4);                 // bb3[0]: scope 1 at ./example.rs:13:18: 13:19
        _4 = ((_1 as Foo).0: u8);        // bb3[1]: scope 1 at ./example.rs:13:18: 13:19
        StorageLive(_5);                 // bb3[2]: scope 3 at ./example.rs:13:33: 13:34
        _5 = _4;                         // bb3[3]: scope 3 at ./example.rs:13:33: 13:34
        ((_2 as Foo).0: u8) = move _5;   // bb3[4]: scope 3 at ./example.rs:13:24: 13:35
        discriminant(_2) = 0;            // bb3[5]: scope 3 at ./example.rs:13:24: 13:35
        StorageDead(_5);                 // bb3[6]: scope 3 at ./example.rs:13:34: 13:35
        StorageDead(_4);                 // bb3[7]: scope 1 at ./example.rs:13:35: 13:36
        goto -> bb4;                     // bb3[8]: scope 1 at ./example.rs:12:18: 15:6
    }

with mir-opt-level=2:

    bb3: {
        _2 = move _1;                    // bb3[0]: scope 1 at ./example.rs:13:18: 13:19
        goto -> bb4;                     // bb3[1]: scope 1 at ./example.rs:12:18: 15:6
    }

Where the types are

    let _1: Src as UserTypeProjection { base: UserType(0), projs: [] }; // in scope 0 at ./example.rs:11:9: 11:10
    let mut _2: Dst;                     // in scope 0 at ./example.rs:12:18: 15:6

@nagisa nagisa added the requires-nightly This issue requires a nightly compiler in some way. label Nov 29, 2019
@Centril Centril self-assigned this Nov 29, 2019
@bors bors closed this as completed in 472bee2 Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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