D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16563 - [REG 2.072.0-b1] Wrong struct size/alignment in local struct
Summary: [REG 2.072.0-b1] Wrong struct size/alignment in local struct
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2016-09-28 18:35 UTC by Vladimir Panteleev
Modified: 2016-11-04 09:05 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vladimir Panteleev 2016-09-28 18:35:04 UTC
/////////////// 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 uplink.coder 2016-09-29 01:11:12 UTC
The reason is that the _scope of the AlignDeclarartion does not get set.
Comment 2 uplink.coder 2016-09-29 01:30:23 UTC
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 Martin Nowak 2016-10-08 21:03:48 UTC
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 Vladimir Panteleev 2016-10-08 23:43:09 UTC
(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 Martin Nowak 2016-10-14 19:54:32 UTC
(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 github-bugzilla 2016-10-15 05:48:13 UTC
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 github-bugzilla 2016-10-19 23:14:13 UTC
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 github-bugzilla 2016-11-04 09:05:33 UTC
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