Skip to content

The improper_ctypes lint is very weak #36464

Description

@amluto

This code compiles without warnings. I think that the improper_ctypes lint should catch both of the extern declarations.

#[allow(dead_code)]

#[repr(C)]
enum NotSoGood {
    A,
    B(i32),
}

extern "C" {
    fn foo(a: [u8; 16]);
    fn bar(a: NotSoGood);
}

#[no_mangle]
pub extern fn test() {
    unsafe {
        foo([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
        bar(NotSoGood::B(0));
    }
}

The array case (foo) is particularly nasty. On brief, insufficiently careful inspection, it looks like it matches:

void foo(uint8_t a[16]);

But it actually doesn't match that and instead seems to try to pass the array in packed form in xmm0 on x86_64. This is extra nasty because I think I've caught rust-bindgen generating bindings like this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions