Skip to content

LLVM assert failure with struct pointers and foreign functions #6504

Closed
@brandonson

Description

@brandonson

Say we have a crate file A.rc which includes mod A and mod B, file B is a module that defines an extern function that takes a pointer to a struct, and file C is a module that uses file B using mod B.

I get the following error:

rust/src/llvm/include/llvm/Support/Casting.h:231: typename llvm::enable_if<llvm::is_same<Y, typename llvm::simplify_type<From>::SimpleType>, typename llvm::cast_retty<X, Y*>::ret_type>::type llvm::cast(Y*) [with X = llvm::Function; Y = llvm::Value; typename llvm::enable_if<llvm::is_same<Y, typename llvm::simplify_type<From>::SimpleType>, typename llvm::cast_retty<X, Y*>::ret_type>::type = llvm::Function*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

I managed to bring it down to a simple example that reproduces the problem:

crate.rc

#[crate_type = "lib"];
mod other;
mod other2;

other.rs

struct Foo{
  bar: libc::c_int
}

#[link_args = "-lSDL2"]
extern{
  fn externFunc(param:&Foo) -> libc::c_int;
}

other2.rs

mod other;

Note that this does not happen when the parameters to the extern fn are not pointers to a struct. It also does not happen when compiling just other.rs, or without crate.rc depending on other2.rs.

I'm running ubuntu 13.04 with gcc 4.7.3, and I've had this occur with rust builds from both the master and auto branches, and also with rust 0.6.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationI-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions