public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Iain Buclaw <ibuclaw@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-9898] d: Respect explicit align(N) type alignment (PR100935) Date: Wed, 9 Jun 2021 18:03:37 +0000 (GMT) [thread overview] Message-ID: <20210609180337.240A43857C4F@sourceware.org> (raw) 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) Diff: --- gcc/d/dmd/mtype.c | 5 ++++- gcc/testsuite/gdc.test/compilable/aggr_alignment.d | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gcc/d/dmd/mtype.c b/gcc/d/dmd/mtype.c index c11772a7740..0ec577d0c1e 100644 --- a/gcc/d/dmd/mtype.c +++ b/gcc/d/dmd/mtype.c @@ -2060,7 +2060,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
reply other threads:[~2021-06-09 18:03 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210609180337.240A43857C4F@sourceware.org \ --to=ibuclaw@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).