You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
emit-C ignores @[align(N)] (§16.4): a record's C struct is C's natural layout, not TypeLayout's (Al is 16 bytes in C, 64 in the model) #2022
Found while fixing #2017 (multi-field enum payloads in the C backend).
Spec §16.4 / with-abi.md §2: a field's @[align(N)] places it at TypeLayout's offset and gives the record that alignment. The C backend emits no alignment for it (grep _Alignas src/CCodegen.w is empty), so the C struct has C's natural layout while every TypeLayout-derived constant (comptime T.size(), element sizes) uses the model's.
type Al { a: i8, @[align(32)] b: i64 }
fn main:
var v: Vec[Al] = Vec.new()
for i in 0..4: v.push(Al { a: i as i8, b: i as i64 * 10 })
var s: i64 = 0
for x in v: s = s + x.b + x.a as i64
let addr1 = &raw const v[1].b
print(f"{s} {(addr1 as i64) % 32}")
emitted C: struct Al { int8_t a; int64_t b; }; (16 bytes; model 64, comptime Al.size() prints 64 in both backends)
LLVM backend prints 66 16, the emitted C program 66 8.
Expected: the C struct carries the model's alignment (_Alignas(N) on the field), so C's sizeof/offsets equal TypeLayout's, or emission refuses loudly. Note the LLVM backend's 16 is itself below the declared 32: a Vec buffer of an over-aligned element is not allocated at the element's alignment — that half may be its own bug.
Activity
Runtime: a Vec buffer is aligned for its element (#2022)
emit-C: records take TypeLayout's layout and prove it with _Static_as…
Over-aligned elements: Vec buffers aligned for their element; emit-C …
emit-C nullable-pointer Options (#2036); over-aligned heap cells and …