Bug 16563 – [REG 2.072.0-b1] Wrong struct size/alignment in local struct

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-09-28T18:35:00Z
Last change time
2016-11-04T09:05:33Z
Keywords
wrong-code
Assigned to
nobody
Creator
dlang-bugzilla

Comments

Comment #0 by dlang-bugzilla — 2016-09-28T18:35:04Z
/////////////// test.d ////////////// void test() { align(1) struct S { uint i; ubyte b; static assert(S.sizeof == 5); } } ///////////////////////////////////// Introduced in https://github.com/dlang/dmd/pull/5880.
Comment #1 by uplink.coder — 2016-09-29T01:11:12Z
The reason is that the _scope of the AlignDeclarartion does not get set.
Comment #2 by uplink.coder — 2016-09-29T01:30:23Z
The hacky fix for this looks like this: --- a/src/dstruct.d +++ b/src/dstruct.d @@ -299,7 +299,8 @@ extern (C++) class StructDeclaration : AggregateDeclaration if (semanticRun == PASSinit) { protection = sc.protection; - + if (sc && sc.aligndecl && !sc.aligndecl._scope && sc.parent._scope) + sc.aligndecl._scope = sc.parent._scope; alignment = sc.alignment();
Comment #3 by code — 2016-10-08T21:03:48Z
When filing regressions for master please use the current development version as tag so we can more easily see which release is affected.
Comment #4 by dlang-bugzilla — 2016-10-08T23:43:09Z
(In reply to Martin Nowak from comment #3) > When filing regressions for master please use the current development > version as tag so we can more easily see which release is affected. I don't think beta 1 was out at that point?
Comment #5 by code — 2016-10-14T19:54:32Z
(In reply to uplink.coder from comment #1) > The reason is that the _scope of the AlignDeclarartion does not get set. Yes, setScope isn't called for declarations in functions b/c there are no forward references in functions, hence no scope for early lookups is needed.
Comment #6 by github-bugzilla — 2016-10-15T05:48:13Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/07bbf2d0ef547339dee5e886a1a924691c3eb8b8 fix Issue 16563 - wrong alignment in function - function local declarations don't have the setScope pass b/c there are no forward references, therefor AlignDeclaration must not rely on setScope being called - pass Scope to getAlignment instead, either the normal semantic2 one or the one from Scope.alignment https://github.com/dlang/dmd/commit/bf1c25d74964ab3d32d91ecd37f00b99919e5bee Merge pull request #6196 from MartinNowak/fix16563 fix Issue 16563 - wrong alignment in function
Comment #7 by github-bugzilla — 2016-10-19T23:14:13Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/07bbf2d0ef547339dee5e886a1a924691c3eb8b8 fix Issue 16563 - wrong alignment in function https://github.com/dlang/dmd/commit/bf1c25d74964ab3d32d91ecd37f00b99919e5bee Merge pull request #6196 from MartinNowak/fix16563
Comment #8 by github-bugzilla — 2016-11-04T09:05:33Z
Commits pushed to newCTFE at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/07bbf2d0ef547339dee5e886a1a924691c3eb8b8 fix Issue 16563 - wrong alignment in function https://github.com/dlang/dmd/commit/bf1c25d74964ab3d32d91ecd37f00b99919e5bee Merge pull request #6196 from MartinNowak/fix16563