Bug 100935 - d: T.alignof ignores explicit align(N) type alignment
Summary: d: T.alignof ignores explicit align(N) type alignment
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: d (show other bugs)
Version: 9.4.1
: P3 normal
Target Milestone: ---
Assignee: Iain Buclaw
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-06 21:16 UTC by Iain Buclaw
Modified: 2021-06-09 18:06 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Iain Buclaw 2021-06-06 21:16:34 UTC
T.alignof currently always returns the natural alignment of a type:

align(8) struct Aligned { int a; }
static assert(Aligned.alignof == 8); // fails, 4
align(1) struct Packed { int a; }
static assert(Packed.alignof == 1);  // fails, 4
Comment 1 CVS Commits 2021-06-09 18:00:25 UTC
The master branch has been updated by Iain Buclaw <ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:04fea2d66bd680beb1a204e62f2f459307000813

commit r12-1344-g04fea2d66bd680beb1a204e62f2f459307000813
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Wed Jun 9 19:37:22 2021 +0200

    d: Respect explicit align(N) type alignment (PR100935)
    
    It was previously the natural type alignment, defined as the maximum of
    the field alignments for an aggregate.  Make sure an explicit align(N)
    overrides it.
    
    Reviewed-on: https://github.com/dlang/dmd/pull/12646
    
    gcc/d/ChangeLog:
    
            PR d/100935
            * dmd/MERGE: Merge upstream dmd f3fdeb578.
Comment 2 CVS Commits 2021-06-09 18:01:47 UTC
The releases/gcc-11 branch has been updated by Iain Buclaw <ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:c6c3ed60276b842114aefce54d73e30e578fdd6d

commit r11-8535-gc6c3ed60276b842114aefce54d73e30e578fdd6d
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Wed Jun 9 19:37:22 2021 +0200

    d: Respect explicit align(N) type alignment (PR100935)
    
    It was previously the natural type alignment, defined as the maximum of
    the field alignments for an aggregate.  Make sure an explicit align(N)
    overrides it.
    
    gcc/d/ChangeLog:
    
            PR d/100935
            * dmd/mtype.c (Type::getProperty): Prefer explicit alignment over
            natural alignment for alignof property.
    
    gcc/testsuite/ChangeLog:
    
            PR d/100935
            * gdc.test/compilable/aggr_alignment.d: Add test cases.
    
    (cherry picked from commit 04fea2d66bd680beb1a204e62f2f459307000813)
Comment 3 CVS Commits 2021-06-09 18:03:38 UTC
The releases/gcc-10 branch has been updated by Iain Buclaw <ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:f7ece1a32000a9943f5bd5ac597d6ce3829aff8e

commit r10-9898-gf7ece1a32000a9943f5bd5ac597d6ce3829aff8e
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Wed Jun 9 19:37:22 2021 +0200

    d: Respect explicit align(N) type alignment (PR100935)
    
    It was previously the natural type alignment, defined as the maximum of
    the field alignments for an aggregate.  Make sure an explicit align(N)
    overrides it.
    
    gcc/d/ChangeLog:
    
            PR d/100935
            * dmd/mtype.c (Type::getProperty): Prefer explicit alignment over
            natural alignment for alignof property.
    
    gcc/testsuite/ChangeLog:
    
            PR d/100935
            * gdc.test/compilable/aggr_alignment.d: Add test cases.
    
    (cherry picked from commit 3ba036dd1a752d29764ad44adca6e68bec9599fe)
Comment 4 CVS Commits 2021-06-09 18:04:21 UTC
The releases/gcc-9 branch has been updated by Iain Buclaw <ibuclaw@gcc.gnu.org>:

https://gcc.gnu.org/g:fe555102dc224b4d946becc8a9db514ecec66161

commit r9-9575-gfe555102dc224b4d946becc8a9db514ecec66161
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Wed Jun 9 19:37:22 2021 +0200

    d: Respect explicit align(N) type alignment (PR100935)
    
    It was previously the natural type alignment, defined as the maximum of
    the field alignments for an aggregate.  Make sure an explicit align(N)
    overrides it.
    
    gcc/d/ChangeLog:
    
            PR d/100935
            * dmd/mtype.c (Type::getProperty): Prefer explicit alignment over
            natural alignment for alignof property.
    
    gcc/testsuite/ChangeLog:
    
            PR d/100935
            * gdc.test/compilable/aggr_alignment.d: Add test cases.
    
    (cherry picked from commit 3ba036dd1a752d29764ad44adca6e68bec9599fe)
Comment 5 Iain Buclaw 2021-06-09 18:06:03 UTC
Fix committed.