aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2015-04-25 10:12:01 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2015-04-25 10:12:01 +0000
commit6c1db78eca5e8594a6d7f0b85362ac31cdc3d155 (patch)
treeb741b6d5a143c86b8739b94b471710bc0857833a
parent5962171edd2b172e59a33cb7ecdc899995b988ba (diff)
downloadgcc-6c1db78eca5e8594a6d7f0b85362ac31cdc3d155.zip
gcc-6c1db78eca5e8594a6d7f0b85362ac31cdc3d155.tar.gz
gcc-6c1db78eca5e8594a6d7f0b85362ac31cdc3d155.tar.bz2
re PR c/52085 (incomplete enum not completed correctly if packed was used)
PR c/52085 * c-decl.c (finish_enum): Copy over TYPE_ALIGN. Also check for "mode" attribute. * gcc.dg/enum-incomplete-2.c: New test. * gcc.dg/enum-mode-1.c: New test. From-SVN: r222440
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-decl.c6
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/enum-incomplete-2.c41
-rw-r--r--gcc/testsuite/gcc.dg/enum-mode-1.c10
5 files changed, 67 insertions, 2 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index c613e9d..938262a9 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2015-04-25 Marek Polacek <polacek@redhat.com>
+
+ PR c/52085
+ * c-decl.c (finish_enum): Copy over TYPE_ALIGN. Also check for "mode"
+ attribute.
+
2015-04-23 Marek Polacek <polacek@redhat.com>
PR c/65345
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 27ecd8b..4f6761d 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -8010,11 +8010,13 @@ finish_enum (tree enumtype, tree values, tree attributes)
TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (tem);
TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (tem);
TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (tem);
+ TYPE_ALIGN (enumtype) = TYPE_ALIGN (tem);
TYPE_SIZE (enumtype) = 0;
- /* If the precision of the type was specific with an attribute and it
+ /* If the precision of the type was specified with an attribute and it
was too small, give an error. Otherwise, use it. */
- if (TYPE_PRECISION (enumtype))
+ if (TYPE_PRECISION (enumtype)
+ && lookup_attribute ("mode", attributes))
{
if (precision > TYPE_PRECISION (enumtype))
error ("specified mode too small for enumeral values");
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d90c271..18a56e8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2015-04-25 Marek Polacek <polacek@redhat.com>
+
+ PR c/52085
+ * gcc.dg/enum-incomplete-2.c: New test.
+ * gcc.dg/enum-mode-1.c: New test.
+
2015-04-24 Michael Meissner <meissner@linux.vnet.ibm.com>
PR target/65849
diff --git a/gcc/testsuite/gcc.dg/enum-incomplete-2.c b/gcc/testsuite/gcc.dg/enum-incomplete-2.c
new file mode 100644
index 0000000..5970551
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/enum-incomplete-2.c
@@ -0,0 +1,41 @@
+/* PR c/52085 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+#define SA(X) _Static_assert((X),#X)
+
+enum e1;
+enum e1 { A } __attribute__ ((__packed__));
+enum e2 { B } __attribute__ ((__packed__));
+SA (sizeof (enum e1) == sizeof (enum e2));
+SA (_Alignof (enum e1) == _Alignof (enum e2));
+
+enum e3;
+enum e3 { C = 256 } __attribute__ ((__packed__));
+enum e4 { D = 256 } __attribute__ ((__packed__));
+SA (sizeof (enum e3) == sizeof (enum e4));
+SA (_Alignof (enum e3) == _Alignof (enum e4));
+
+enum e5;
+enum e5 { E = __INT_MAX__ } __attribute__ ((__packed__));
+enum e6 { F = __INT_MAX__ } __attribute__ ((__packed__));
+SA (sizeof (enum e5) == sizeof (enum e6));
+SA (_Alignof (enum e5) == _Alignof (enum e6));
+
+enum e7;
+enum e7 { G } __attribute__ ((__mode__(__byte__)));
+enum e8 { H } __attribute__ ((__mode__(__byte__)));
+SA (sizeof (enum e7) == sizeof (enum e8));
+SA (_Alignof (enum e7) == _Alignof (enum e8));
+
+enum e9;
+enum e9 { I } __attribute__ ((__packed__, __mode__(__byte__)));
+enum e10 { J } __attribute__ ((__packed__, __mode__(__byte__)));
+SA (sizeof (enum e9) == sizeof (enum e10));
+SA (_Alignof (enum e9) == _Alignof (enum e10));
+
+enum e11;
+enum e11 { K } __attribute__ ((__mode__(__word__)));
+enum e12 { L } __attribute__ ((__mode__(__word__)));
+SA (sizeof (enum e11) == sizeof (enum e12));
+SA (_Alignof (enum e11) == _Alignof (enum e12));
diff --git a/gcc/testsuite/gcc.dg/enum-mode-1.c b/gcc/testsuite/gcc.dg/enum-mode-1.c
new file mode 100644
index 0000000..a701123
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/enum-mode-1.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+enum e1 { A = 256 } __attribute__((__mode__(__byte__))); /* { dg-error "specified mode too small for enumeral values" } */
+enum e2 { B = 256 } __attribute__((__packed__, __mode__(__byte__))); /* { dg-error "specified mode too small for enumeral values" } */
+
+enum e3 { C = __INT_MAX__ } __attribute__((__mode__(__QI__))); /* { dg-error "specified mode too small for enumeral values" } */
+enum e4 { D = __INT_MAX__ } __attribute__((__packed__, __mode__(__QI__))); /* { dg-error "specified mode too small for enumeral values" } */
+
+enum e5 { E = __INT_MAX__ } __attribute__((__mode__(__HI__))); /* { dg-error "specified mode too small for enumeral values" } */
+enum e6 { F = __INT_MAX__ } __attribute__((__packed__, __mode__(__HI__))); /* { dg-error "specified mode too small for enumeral values" } */