Skip to content

ICE with extern C functions receiving/returning structs by value with f32/f64 members on x86_64 #5874

Closed
@SiegeLord

Description

@SiegeLord

Structs that contain f32/f64 and have a total size of <= 128 bytes produce an out of bounds error at src/librustc/middle/trans/cabi_x86_64.rs:259 . Tested with incoming at a9247e0.

Here is a collection of structs that produce an ICE and some that don't. I haven't tested whether the ones that do compile produce correct code.

// rust: task failed at 'index out of bounds: the len is 1 but the index is 1', /home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs:259
struct f64_1
{
    a : f64,
}

// rust: task failed at 'index out of bounds: the len is 2 but the index is 2', /home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs:259
struct f64_2
{
    a : f64,
    b : f64
}

// No ICE
struct f64_3
{
    a : f64,
    b : f64,
    c : f64
}

// No ICE
struct f64_4
{
    a : f64,
    b : f64,
    c : f64,
    d : f64
}

// No ICE
struct f64_5
{
    a : f64,
    b : f64,
    c : f64,
    d : f64,
    e : f64
}

// rust: task failed at 'index out of bounds: the len is 1 but the index is 1', /home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs:259
struct f32_1
{
    a : f32
}

// rust: task failed at 'index out of bounds: the len is 1 but the index is 1', /home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs:259
struct f32_2
{
    a : f32,
    b : f32
}

// rust: task failed at 'index out of bounds: the len is 2 but the index is 2', /home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs:259
struct f32_3
{
    a : f32,
    b : f32,
    c : f32
}

// rust: task failed at 'index out of bounds: the len is 2 but the index is 2', /home/siege/src/rust2/src/librustc/middle/trans/cabi_x86_64.rs:259
struct f32_4
{
    a : f32,
    b : f32,
    c : f32,
    d : f32,
}

// No ICE
struct f32_5
{
    a : f32,
    b : f32,
    c : f32,
    d : f32,
    e : f32,
}

type T = f32_1;

extern "C"
{
    fn test1(a : T);
    fn test2() -> T;
}

fn main()
{
}

Here's a representative backtrace, if it's useful:

/usr/local/bin/../lib/librustrt.so(_ZN9rust_task13begin_failureEPKcS1_m+0x4b)[0x7fcb85a20c8b]
/usr/local/bin/../lib/librustrt.so(+0x2aa79)[0x7fcb85a31a79]
/usr/local/bin/../lib/librustrt.so(upcall_fail+0x1a8)[0x7fcb85a22a78]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0x10911b)[0x7fcb875f611b]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0x4f15e)[0x7fcb8753c15e]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(_ZN8unstable4lang17fail_bounds_check16_6fb13a2fe60974b6_07preE+0x23a)[0x7fcb875454da]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x305e2d)[0x7fcb85f68e2d]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x3066f4)[0x7fcb85f696f4]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle5trans11cabi_x86_6414__extensions__10meth_3501512compute_info17_63f5244ae590c1b66_07preE+0x11e)[0x7fcb85f698fe]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x309fea)[0x7fcb85f6cfea]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x30b52d)[0x7fcb85f6e52d]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x30b210)[0x7fcb85f6e210]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle5trans7foreign17trans_foreign_mod17_f7e97aff939386996_07preE+0x11e)[0x7fcb85ee75ee]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle5trans4base10trans_item17_e83b64764568c7be6_07preE+0x499)[0x7fcb85d7b909]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle5trans4base9trans_mod17_d740d055c716f9476_07preE+0xa3)[0x7fcb85ee73d3]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle5trans4base11trans_crate15_4f38ab124cab2e6_07preE+0x13c4)[0x7fcb85f073e4]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x8ddce4)[0x7fcb86540ce4]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x89b8b0)[0x7fcb864fe8b0]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6driver6driver12compile_rest15_58068714615f2b6_07preE+0x336a)[0x7fcb864fb90a]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x8ddce4)[0x7fcb86540ce4]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6driver6driver12compile_upto17_3ccd839185751c4f6_07preE+0x108)[0x7fcb864feac8]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6driver6driver13compile_input17_7bc345e59d22cba06_07preE+0xca)[0x7fcb864fef0a]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN12run_compiler16_aa88c3dc13843746_07preE+0x20a0)[0x7fcb86531720]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x8db691)[0x7fcb8653e691]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x8d7bba)[0x7fcb8653abba]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x8ddce4)[0x7fcb86540ce4]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0xd0fbf)[0x7fcb875bdfbf]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0x152264)[0x7fcb8763f264]
/usr/local/bin/../lib/librustrt.so(_Z18task_start_wrapperP10spawn_args+0x24)[0x7fcb85a214d4]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions