public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/40751 (can't change alignment of enum)
@ 2016-01-21 20:24 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2016-01-21 20:24 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 296 bytes --]

The problem here was that when copy_type_enum updates the size and 
alignment of the enum to match its underlying type, it was clobbering 
any explicit alignment.  I've fixed similar issues in other places, but 
this one needed the update as well.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 40751.patch --]
[-- Type: text/x-patch, Size: 1235 bytes --]

commit 0dc9dc45a5a9d2a0efc7456a72e13dab38551d4c
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jan 21 14:22:05 2016 -0500

    	PR c++/40751
    	PR c++/64987
    	* decl.c (copy_type_enum): Respect TYPE_USER_ALIGN.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d995654..020e9bd 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13030,8 +13030,12 @@ copy_type_enum (tree dst, tree src)
       TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
       SET_TYPE_MODE (dst, TYPE_MODE (src));
       TYPE_PRECISION (t) = TYPE_PRECISION (src);
-      TYPE_ALIGN (t) = TYPE_ALIGN (src);
-      TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
+      unsigned valign = TYPE_ALIGN (src);
+      if (TYPE_USER_ALIGN (t))
+	valign = MAX (valign, TYPE_ALIGN (t));
+      else
+	TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
+      TYPE_ALIGN (t) = valign;
       TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
     }
 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/alignas5.C b/gcc/testsuite/g++.dg/cpp0x/alignas5.C
new file mode 100644
index 0000000..2820ca7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alignas5.C
@@ -0,0 +1,6 @@
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert(X,#X)
+
+enum alignas(16) E {};
+SA(alignof(E) == 16);

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

only message in thread, other threads:[~2016-01-21 20:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-21 20:24 C++ PATCH for c++/40751 (can't change alignment of enum) Jason Merrill

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).