Skip to content

fastffi attribute is sometimes ignored or incorrectly assigned #6660

Closed
@nikomatsakis

Description

@nikomatsakis

The following test, originally written for #3678, results in a segfault because insufficient stack is allocated (at least it does on the branch I plan to land that fixes #3678).

// Test what happens when we link to the same function name with
// different types. This situation can easily arise when linking two
// crates that make use of the same C library, for example.

mod A {
    pub struct TwoU32s {
        one: u32, two: u32
    }
    extern {
        pub fn rust_dbg_extern_return_TwoU32s() -> TwoU32s;
    }
}

mod B {
    pub struct TwoU32s {
        one: u32, two: u32
    }
    extern {
        pub fn rust_dbg_extern_return_TwoU32s() -> TwoU32s;
    }
}

fn wrapper() {
}

fn main() {
    unsafe {
        let a = A::rust_dbg_extern_return_TwoU32s();
        // println(fmt!("%?", a));
        // assert_eq!(a.one, 10);
        // assert_eq!(a.two, 20);
    }

    unsafe {
        let b = B::rust_dbg_extern_return_TwoU32s();
        // println(fmt!("%?", b));
        // assert_eq!(b.one, 10);
        // assert_eq!(b.two, 20);
    }
}

Paging @pcwalton, maybe you could take a look (once the PR for #3678 lands?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)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