Skip to content

[i128] C FFI mismatch on GNU/Linux with gcc #38762

Closed
@est31

Description

@est31

Given the following setup:

test.rs:

#![feature(i128_type)]

#[repr(C)]
#[derive(Copy, Clone, PartialEq, Debug)]
struct Foo {
    a: i128,
    b: i8,
    c: u16,
}

#[link(name = "test", kind = "static")]
extern "C" {
    fn foo(f: Foo) -> Foo;
}

fn main() {
    unsafe {
        let a = Foo { a: 1, b: 2, c: 3 };
        let b = foo(a);
        assert_eq!(a, b);
    }
}

test.c:

#include <stdint.h>

struct Foo {
    __int128 a;
    int8_t b;
    uint16_t c;
};

struct Foo foo(struct Foo foo) {
    return foo;
}

gcc version 6.2.0, rust of current master (ac5cd3b), and a 64 bit gnu/linux platform, main will panic:

thread 'main' panicked at 'assertion failed: `(left == right)` (left: `Foo { a: 139755467620616, b: 2, c: 3 }`, right: `Foo { a: 1, b: 2, c: 3 }`)'

cc #35118 (tracking issue)
cc @nagisa , me

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions