This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix enum __attribute__ ((mode (...)))


Hi!

The following testcase is miscompiled on both current gcc-3_4-branch and HEAD
(regression from 3.4.2 and earlier).
TYPE_MODE is not copied, which causes the writes into the structure below
as well as reads from it in the foo function be done in SImode rather than
QImode.  Ok to commit?
For 3.4 as well?

2005-01-07  Jakub Jelinek  <jakub@redhat.com>

	* c-common.c (handle_mode_attribute): For ENUMERAL_TYPE, also copy
	TYPE_MODE.

	* gcc.c-torture/execute/20050107-1.c: New test.

--- gcc/c-common.c.jj	2005-01-06 14:25:34.000000000 +0100
+++ gcc/c-common.c	2005-01-07 12:33:51.981894813 +0100
@@ -4341,6 +4341,7 @@ handle_mode_attribute (tree *node, tree 
 	  TYPE_MAX_VALUE (type) = TYPE_MAX_VALUE (typefm);
 	  TYPE_SIZE (type) = TYPE_SIZE (typefm);
 	  TYPE_SIZE_UNIT (type) = TYPE_SIZE_UNIT (typefm);
+	  TYPE_MODE (type) = TYPE_MODE (typefm);
 	  if (!TYPE_USER_ALIGN (type))
 	    TYPE_ALIGN (type) = TYPE_ALIGN (typefm);
 
--- gcc/testsuite/gcc.c-torture/execute/20050107-1.c.jj	2005-01-07 12:47:48.247093019 +0100
+++ gcc/testsuite/gcc.c-torture/execute/20050107-1.c	2005-01-07 11:58:42.000000000 +0100
@@ -0,0 +1,25 @@
+typedef enum { C = 1, D = 2 } B;
+extern void abort (void);
+
+struct S
+{
+  B __attribute__ ((mode (byte))) a;
+  B __attribute__ ((mode (byte))) b;
+};
+
+void
+foo (struct S *x)
+{
+  if (x->a != C || x->b != D)
+    abort ();
+}
+
+int
+main (void)
+{
+  struct S s;
+  s.a = C;
+  s.b = D;
+  foo (&s);
+  return 0;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]