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

LLVM assert when defining same native function with different types #1866

Closed
brson opened this issue Feb 18, 2012 · 8 comments
Closed

LLVM assert when defining same native function with different types #1866

brson opened this issue Feb 18, 2012 · 8 comments
Labels
A-codegen Area: Code generation I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@brson
Copy link
Contributor

brson commented Feb 18, 2012

mod a {
    type rust_task = uint;
    native mod rustrt {
        fn rust_task_is_unwinding(rt: *rust_task) -> bool;
    }
}

mod b {
    type rust_task = bool;
    native mod rustrt {
        fn rust_task_is_unwinding(rt: *rust_task) -> bool;
    }
}

fn main() { }
rustc: /home/banderson/Dev/rust2/src/llvm/include/llvm/Support/Casting.h:194: typename llvm::cast_retty<To, From>::ret_type llvm::cast(const Y&) [with X = llvm::Function, Y = llvm::Value*, typename llvm::cast_retty<To, From>::ret_type = llvm::Function*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
@lht
Copy link
Contributor

lht commented Apr 9, 2012

llvm Module::getOrInsertFunction:
http://llvm.org/docs/doxygen/html/Module_8cpp_source.html#l00139

If a function with the name is found but type is different, llvm bitcasts the found function type to the requested type and returns it. Later, when we set calling convention, the given function's type isn't consistent with the one (before conversion) in llvm symbol table.

After all, without mangling type information, we cannot have functions with the same name, right?

@ghost ghost assigned brson Apr 12, 2012
@catamorphism
Copy link
Contributor

Still a bug as of 6/21/2012.

@mitsuhiko
Copy link
Contributor

I have a very similar case:

mod llt {
    pub enum SDL_Window {}
}

#[link_name = "SDL2"]
extern mod ll {
    use llt::*;
    pub fn SDL_CreateWindow(title: *c_char, x: c_int, y: c_int,
                            w: c_int, h: c_int, flags: uint32_t) -> *SDL_Window;
}

This causes:

Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of
  incompatible type!"), function cast, file
  ~/Development/rust/src/llvm/include/llvm/Support/Casting.h, line 197.

If I remove the -> *SDL_Window and replace it with an c_int it works.

@emberian
Copy link
Member

Still a bug as of 6/22/2013 (good timing, past @catamorphism).

In test suite, xfailed, as issue-1866.rs

@brson
Copy link
Contributor Author

brson commented Jul 10, 2013

nominating production ready

@graydon
Copy link
Contributor

graydon commented Jul 11, 2013

accepted for production-ready milestone

@nikomatsakis
Copy link
Contributor

I believe that I fixed this bug as part of the PR for #3678 (which has not yet
landed). My fix was to cast the type of native fns where necessary.

metajack added a commit to metajack/rust that referenced this issue Sep 5, 2013
@metajack
Copy link
Contributor

metajack commented Sep 5, 2013

This is indeed fixed. I submitted #8986 to remove the xfail comment on the test, but the test was already moved to run-pass some time ago.

@metajack metajack closed this as completed Sep 5, 2013
jumbatm added a commit to jumbatm/rust that referenced this issue Apr 18, 2020
jumbatm added a commit to jumbatm/rust that referenced this issue May 20, 2020
- Allow ClashingExternDecl for lint-dead-code-3
- Update test case for rust-lang#5791
- Update test case for rust-lang#1866
- Update extern-abi-from-macro test case
jumbatm added a commit to jumbatm/rust that referenced this issue May 23, 2020
- Allow ClashingExternDecl for lint-dead-code-3
- Update test case for rust-lang#5791
- Update test case for rust-lang#1866
- Update extern-abi-from-macro test case
jumbatm added a commit to jumbatm/rust that referenced this issue May 30, 2020
- Allow ClashingExternDecl for lint-dead-code-3
- Update test case for rust-lang#5791
- Update test case for rust-lang#1866
- Update extern-abi-from-macro test case
jumbatm added a commit to jumbatm/rust that referenced this issue Jun 20, 2020
- Allow ClashingExternDecl for lint-dead-code-3
- Update test case for rust-lang#5791
- Update test case for rust-lang#1866
- Update extern-abi-from-macro test case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

8 participants