Skip to content

Compiler panic when attempting to use non immediate as assembly parameter #54067

Closed
@crawford

Description

@crawford

Take the following code:

#![feature(asm)]

pub fn boot(addr: Option<u32>) {
    unsafe {
        asm!(
            "mov sp, $0"
             :
             : "r" (addr)
        );
    }
}

Attempting to compile this results in the following:

$ cargo build
   Compiling ice v0.1.0 (file:///home/alex/code/ice)                                                                                                                                           
error: internal compiler error: librustc_codegen_llvm/mir/operand.rs:145: not immediate: OperandRef(Pair((i32:  %7 = load i32, i32* %6, align 4, !dbg !29, !range !31), (i32:  %9 = load i32, i32* %8, align 4, !dbg !29)) @ TyLayout { ty: std::option::Option<u32>, details: LayoutDetails { variants: Tagged { tag: Scalar { value: Int(I32, false), valid_range: 0..=1 }, variants: [LayoutDetails { variants: Single { index: 0 }, fields: Arbitrary { offsets: [], memory_index: [] }, abi: Aggregate { sized: true }, align: Align { abi_pow2: 0, pref_pow2: 3 }, size: Size { raw: 4 } }, LayoutDetails { variants: Single { index: 1 }, fields: Arbitrary { offsets: [Size { raw: 4 }], memory_index: [0] }, abi: Aggregate { sized: true }, align: Align { abi_pow2: 2, pref_pow2: 3 }, size: Size { raw: 8 } }] }, fields: Arbitrary { offsets: [Size { raw: 0 }], memory_index: [0] }, abi: ScalarPair(Scalar { value: Int(I32, false), valid_range: 0..=1 }, Scalar { value: Int(I32, false), valid_range: 0..=4294967295 }), align: Align { abi_pow2: 2, pref_pow2: 3 }, size: Size { raw: 8 } } })

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:587:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: aborting due to previous error


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.30.0-nightly (fc81e3624 2018-09-07) running on x86_64-unknown-linux-gnu

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 `ice`.

I think the compiler should fail with something along the lines of "you attempted to use a complex type (Option<u32>) where I expected an immediate".

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions