Fix per-field alignment attribute being dropped during transpilation - #1974
Conversation
|
The commits here claim to be authored by "Your Name" from an account with activity set to private, and the interactions from the PR author here read like unedited LLM output without a spark of human involvement. While we do want this bug fixed, this is fairly disrespectful of the time spent by human collaborators here and it doesn't make me happy to see. I encourage the human responsible for the @user3polarjet account to drop by and say hello in their own words. |
869c905 to
a093987
Compare
fw-immunant
left a comment
There was a problem hiding this comment.
The code changes from the LLM look reasonable, including comments which seem informative and appropriate. This does seem to address the relevant issue, which is a deficiency we've wanted to fix for some time.
|
CI is failing because the added test imports |
a093987 to
45fe5d9
Compare
[...] my intent was to try to transpile x264 encoder to rust. It extensively uses alignment attributes for msvc, clang, gcc. And i hit this bug. It kinda pissed me off, so i tried to fix it [with an LLM, generating this change].
LLM-generated PR description follows.
Summary
__attribute__((aligned(N)))on whole structs but silently dropped it when applied to an individual field, since the alignment was never captured by the AST exporter, threaded throughCDeclKind::Field, or used when laying out the generated struct.reprtoalign(M)(M = max manual alignment among its fields) and inserts the padding needed to reach the field's real byte offset, matching clang's layout without inflating the field's own size (an initial#[repr(align(N))]-wrapper-type approach was tried and rejected after direct testing showed it inflates the field's size to a multiple of N, which clang's per-field attribute does not).__alignof__/_Alignofapplied directly to such a field is also fixed to report the manual alignment instead of the field's natural type alignment.Test plan
FieldAlignStruct/test_field_alignmenttotests/unit/structs, covering alignment, offset, size, and read/write through the field.clang-compiled output directly (not just the Rust side) for a__attribute__((aligned(16)))field.tests/unit/structs/src/structs.c(existing struct/bitfield/packing/alignment coverage) still compiles unaffected.