public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1344] d: Respect explicit align(N) type alignment (PR100935)
@ 2021-06-09 18:00 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2021-06-09 18:00 UTC (permalink / raw)
  To: gcc-cvs

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.

Diff:
---
 gcc/d/dmd/MERGE                                    |  2 +-
 gcc/d/dmd/mtype.c                                  |  5 ++++-
 gcc/testsuite/gdc.test/compilable/aggr_alignment.d | 20 ++++++++++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index d29d462f42f..e22e3d1ebf7 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@
-b7d146c4c34469f876a63f26ff19091a7f9d54d7
+f3fdeb578f8cc6d9426d47d2fa144d2078f9ab29
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/mtype.c b/gcc/d/dmd/mtype.c
index 9ef8ab4e5f4..6cccf40df98 100644
--- a/gcc/d/dmd/mtype.c
+++ b/gcc/d/dmd/mtype.c
@@ -2040,7 +2040,10 @@ Expression *Type::getProperty(Loc loc, Identifier *ident, int flag)
     }
     else if (ident == Id::__xalignof)
     {
-        e = new IntegerExp(loc, alignsize(), Type::tsize_t);
+        unsigned explicitAlignment = alignment();
+        unsigned naturalAlignment = alignsize();
+        unsigned actualAlignment = (explicitAlignment == STRUCTALIGN_DEFAULT ? naturalAlignment : explicitAlignment);
+        e = new IntegerExp(loc, actualAlignment, Type::tsize_t);
     }
     else if (ident == Id::_init)
     {
diff --git a/gcc/testsuite/gdc.test/compilable/aggr_alignment.d b/gcc/testsuite/gdc.test/compilable/aggr_alignment.d
index bf602ff31a4..0c727e2fec5 100644
--- a/gcc/testsuite/gdc.test/compilable/aggr_alignment.d
+++ b/gcc/testsuite/gdc.test/compilable/aggr_alignment.d
@@ -27,6 +27,26 @@ static assert(C2.int1.offsetof == payloadOffset + 8);
 static assert(C2.alignof == size_t.sizeof);
 static assert(__traits(classInstanceSize, C2) == payloadOffset + 12);
 
+align(8) struct PaddedStruct
+{
+    bool flag;
+    align(2) S1 s1;
+}
+
+static assert(PaddedStruct.s1.offsetof == 2);
+static assert(PaddedStruct.alignof == 8);
+static assert(PaddedStruct.sizeof == 16);
+
+align(1) struct UglyStruct
+{
+    bool flag;
+    int i;
+    ubyte u;
+}
+
+static assert(UglyStruct.i.offsetof == 4);
+static assert(UglyStruct.alignof == 1);
+static assert(UglyStruct.sizeof == 9);
 
 /***************************************************/
 // https://issues.dlang.org/show_bug.cgi?id=19914


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-09 18:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09 18:00 [gcc r12-1344] d: Respect explicit align(N) type alignment (PR100935) Iain Buclaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).