Skip to content

LLVM assertion failure calling extern fn pointer after panic! #18576

Closed
@mprobinson

Description

@mprobinson

The following causes an LLVM assertion failure:

#![crate_type = "dylib"]
#![feature(globs, lang_items, linkage, phase)]
#![no_std]
#[phase(plugin, link)]
extern crate core;
use core::prelude::*;

static mut FunctionPointer: Option<extern "C" fn ()> = None;

pub unsafe extern "C" fn llvm_assert_fail() {
    panic!("");
    FunctionPointer.unwrap()();
}

#[lang = "stack_exhausted"]
unsafe extern fn stack_exhausted() {}
#[lang = "eh_personality"]
extern fn eh_personality() {}
#[lang = "panic_fmt"]
unsafe extern fn panic_fmt() -> ! { loop {} }
$ cargo build 
   Compiling rust-libretro v0.0.1 (file:///home/mike/libretro/rust-libretro)
/home/mike/libretro/rust-libretro/src/lib.rs:12:5: 12:31 warning: unreachable expression, #[warn(unreachable_code)] on by default
/home/mike/libretro/rust-libretro/src/lib.rs:12     FunctionPointer.unwrap()();
                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
rustc: /home/mike/rust/src/llvm/include/llvm/Support/Casting.h:237: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::FunctionType; Y = llvm::Type; typename llvm::cast_retty<X, Y*>::ret_type = llvm::FunctionType*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Could not compile `rust-libretro`.

Removing the panic! prevents the assertion failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions