Bug 20754 – Aggregates inherit alignment of its members

Status
RESOLVED
Resolution
WONTFIX
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2020-04-20T15:40:08Z
Last change time
2021-02-18T11:07:18Z
Assigned to
No Owner
Creator
Bastiaan Veelo

Comments

Comment #0 by Bastiaan — 2020-04-20T15:40:08Z
From 2.074.1 and onward, this fails: ``` struct S { align (1): byte a; int b; long c; } void main() { assert(S.sizeof == 16); } ``` which in violation of the specification: https://dlang.org/spec/attribute.html#align The actual size returned by the affected versions is 13, which according to the spec would require specifying the alignment on the struct itself as well: ``` align (1) struct S { align (1): byte a; int b; long c; } void main() { assert(S.sizeof == 13); } ```
Comment #1 by moonlightsentinel — 2020-06-05T13:22:27Z
Digger: commit 7eff206e3b44485652e2214a1a900df9749ea46c Author: The Dlang Bot <[email protected]> Date: Sun May 28 14:02:47 2017 +0200 dmd: Merge pull request #6754 from kinke/fix17277 https://github.com/dlang/dmd/pull/6754 Fix alignment/size of packed aggregates (issue #17277) merged-on-behalf-of: Daniel Murphy <[email protected]>
Comment #2 by kinke — 2020-06-05T13:38:40Z
(In reply to Bastiaan Veelo from comment #0) > which in violation of the specification: > https://dlang.org/spec/attribute.html#align I don't see any violation at all. If the aggregate has no explicit alignment, its natural alignment is the max of its field alignments (that was my fix; it's not spec'd, but the obvious correct habevior), which in this case is 1, so the aggregate's alignment is 1 too, and accordingly no useless tail padding is added. So S.alignof is 1 since 2.075, and used to be 8 before that (as it was based on the max field size IIRC - also ignoring field alignments > their size). So this 'issue' is clearly invalid IMO.
Comment #3 by kinke — 2020-06-05T17:05:10Z
(In reply to kinke from comment #2) > I don't see any violation at all. Ah sry, I see the faulty spec code example + sentence ('The alignment for the fields of an aggregate does not affect the alignment of the aggregate itself') now.
Comment #4 by kinke — 2020-06-05T17:35:44Z
Comment #5 by razvan.nitu1305 — 2021-02-18T11:07:18Z
The spec was updated so I'm gonna close this issue as WONTFIX.