Skip to content

Missing FFI type safety checks #2038

@philberty

Description

@philberty

I tried this code: https://github.com/rust-lang/rust/blob/aa3ca1994904f2e056679fce1f185db8c7ed2703/src/test/ui/issue-14309.rs

https://godbolt.org/z/GjGG3jTh4

struct A {
    x: i32
}

#[repr(C, packed)]
struct B {
    x: i32,
    y: A
}

#[repr(C)]
struct C {
    x: i32
}

type A2 = A;
type B2 = B;
type C2 = C;

#[repr(C)]
struct D {
    x: C,
    y: A
}

extern "C" {
    fn foo(x: A); //~ ERROR type `A` which is not FFI-safe
    fn bar(x: B); //~ ERROR type `A`
    fn baz(x: C);
    fn qux(x: A2); //~ ERROR type `A`
    fn quux(x: B2); //~ ERROR type `A`
    fn corge(x: C2);
    fn fred(x: D); //~ ERROR type `A`
}

fn main() { }

I expected to see this happen: errors that type 'A' is not FFI-safe

Instead, this happened: compile-without error

Meta

  • What version of Rust GCC were you using, git sha if possible. be27571

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdiagnosticdiagnostic static analysis

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions