Skip to content

Incomplete array generated wrong layout #455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
flier opened this issue Jan 28, 2017 · 2 comments
Closed

Incomplete array generated wrong layout #455

flier opened this issue Jan 28, 2017 · 2 comments

Comments

@flier
Copy link
Contributor

flier commented Jan 28, 2017

As you know, GNU C and C++ supports Arrays of Length Zero in different syntax. For int A[], LLVM has a IncompleteArrayType where the size is unspecified.

For example, we have two array in a class

class C {
    int a;
    // More than rust limits (32)
    char big_array[33];
    char zero_length_array[0];
    char incomplete_array[];
};

The incomplete array will be generated as a pointer, which cause the layout test failed

#[repr(C)]
 pub struct C {
     pub a: ::std::os::raw::c_int,
     pub big_array: [::std::os::raw::c_char; 33usize],
     pub zero_length_array: [::std::os::raw::c_char; 0usize],
     pub incomplete_array: *mut ::std::os::raw::c_char,
}
 #[test]
 fn bindgen_test_layout_C() {
     assert_eq!(::std::mem::size_of::<C>() , 40usize);
     assert_eq!(::std::mem::align_of::<C>() , 4usize);
 }

failures:

---- bindgen_test_layout_C stdout ----
thread 'bindgen_test_layout_C' panicked at 'assertion failed: (left == right) (left: 48, right: 40)', tests/class.rs:40

We should treat the incomplete array as a zero length array, or add a helper class like __BindgenUnionField<T> did.

flier added a commit to flier/rust-bindgen that referenced this issue Jan 28, 2017
bors-servo pushed a commit that referenced this issue Jan 29, 2017
treat incomplete array as zero length array

fix issue #455
@emilio
Copy link
Contributor

emilio commented Jan 29, 2017

This is fixed now. I'm landing tests for its use in statics here: #457

@emilio
Copy link
Contributor

emilio commented Jan 29, 2017

Thanks again for fixing this :)

@emilio emilio closed this as completed Jan 29, 2017
ian-h-chamberlain added a commit to ian-h-chamberlain/console_3ds that referenced this issue Apr 16, 2022
This should actually be treated as a pointer (zero-sized array in Rust),
rather than a true Rust array.

rust-lang/rust-bindgen#455
ian-h-chamberlain added a commit to ian-h-chamberlain/console_3ds that referenced this issue Apr 16, 2022
This should actually be treated as a pointer (zero-sized array in Rust),
rather than a true Rust array.

rust-lang/rust-bindgen#455

Also adjust regex to remove more unused vars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants