rust-lang / rust-lang/rust-bindgen

__attribute__((aligned(2), packed)) generates both repr(packed) and repr(aligned)

Open
#2,240 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-rustc bug
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header

part of MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/hfs/hfs_format.h

#define int8_t char

struct FndrOpaqueInfo {
        int8_t opaque[16];
} __attribute__((aligned(2), packed));
Bindgen Invocation
$ bindgen has_format.h
Actual Results
#[repr(C, packed(2))]
#[repr(align(2))]
#[derive(Debug, Copy, Clone)]
pub struct FndrOpaqueInfo {
    pub opaque: [::std::os::raw::c_char; 16usize],
}
Expected Results
#[repr(C, packed(2))]
#[derive(Debug, Copy, Clone)]
pub struct FndrOpaqueInfo {
    pub opaque: [::std::os::raw::c_char; 16usize],
}

The actual result is illegal in Rust.

#[repr(C, packed(2))]
#[repr(align(2))]

any of below will be accepted

#[repr(C, packed(2))]
#[repr(C)]
#[repr(align(2))]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the shown hfs_format.h input and the bindgen has_format.h invocation. Compare the generated FndrOpaqueInfo attributes with the expected output; done means the binding no longer emits both repr(packed(2)) and repr(align(2)).

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.