This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix output of VECTOR_CSTs (PR c/29091)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 4 Oct 2006 12:24:45 -0400
- Subject: [PATCH] Fix output of VECTOR_CSTs (PR c/29091)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
This patch fixes a P1 4.[012] regression where a vector initialized from
incomplete initializer. It seems most of the code that handles VECTOR_CSTs
is aware that TREE_VECTOR_CST_ELTS can be NULL or the chain can be shorter
than the number of vector elements and handles that correctly, but
output_constant clearly does not.
Here is a fix, ok for 4.1/trunk?
2006-10-04 Jakub Jelinek <jakub@redhat.com>
PR c/29091
* varasm.c (output_constant): If TREE_VECTOR_CST_ELTS chain is shorter than
the number of vector elements fill the rest with zeros.
* gcc.dg/pr29091.c: New test.
--- gcc/varasm.c.jj 2006-09-22 10:29:56.000000000 +0200
+++ gcc/varasm.c 2006-10-04 17:52:27.000000000 +0200
@@ -4128,8 +4128,12 @@ output_constant (tree exp, unsigned HOST
link = TREE_VECTOR_CST_ELTS (exp);
output_constant (TREE_VALUE (link), elt_size, align);
+ thissize = elt_size;
while ((link = TREE_CHAIN (link)) != NULL)
- output_constant (TREE_VALUE (link), elt_size, nalign);
+ {
+ output_constant (TREE_VALUE (link), elt_size, nalign);
+ thissize += elt_size;
+ }
break;
}
default:
--- gcc/testsuite/gcc.dg/pr29091.c.jj 2006-10-04 18:02:09.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr29091.c 2006-10-04 18:05:33.000000000 +0200
@@ -0,0 +1,44 @@
+/* PR c/29091 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+extern void abort (void);
+
+__attribute__ ((vector_size (sizeof (int) * 4))) int a = { 1, 2 };
+int d = 3;
+__attribute__ ((vector_size (sizeof (int) * 4))) int b = { 4, 5, 6 };
+int e = 7;
+__attribute__ ((vector_size (sizeof (int) * 4))) int c = { };
+
+int
+main (void)
+{
+ int *p = (int *) &a;
+ if (p[0] != 1)
+ abort ();
+ if (p[1] != 2)
+ abort ();
+ if (p[2] != 0)
+ abort ();
+ if (p[3] != 0)
+ abort ();
+ p = (int *) &b;
+ if (p[0] != 4)
+ abort ();
+ if (p[1] != 5)
+ abort ();
+ if (p[2] != 6)
+ abort ();
+ if (p[3] != 0)
+ abort ();
+ p = (int *) &c;
+ if (p[0] != 0)
+ abort ();
+ if (p[1] != 0)
+ abort ();
+ if (p[2] != 0)
+ abort ();
+ if (p[3] != 0)
+ abort ();
+ return 0;
+}
Jakub