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 ICE on BIT_FIELD_REF <VECTOR_CST> (PR regression/21897)


Hi!

Didn't know GCC creates VECTOR_CSTs that might not contain all elements.
The following patch fixes ICE caused by my recent patch.

I have also spotted that operand_equal_p will happily return 1
for (v4hi) { 12, 14 } and (v4hi) { 12, 14, 16, 18 }, even though they are
obviously not equal.

Ok for HEAD?

2005-06-04  Jakub Jelinek  <jakub@redhat.com>

	* fold-const.c (operand_equal_p): Don't return 1, if element
	chains for 2 VECTOR_CSTs are not the same length.

	PR regression/21897
	* fold-const.c (fold_ternary) <case BIT_FIELD_REF>: Don't crash if
	not all VECTOR_CST elements are given.

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

--- gcc/fold-const.c.jj	2005-05-30 21:06:56.000000000 +0200
+++ gcc/fold-const.c	2005-06-04 11:57:28.000000000 +0200
@@ -2458,7 +2458,7 @@ operand_equal_p (tree arg0, tree arg1, u
 	      v2 = TREE_CHAIN (v2);
 	    }
 
-	  return 1;
+	  return v1 == v2;
 	}
 
       case COMPLEX_CST:
@@ -10324,9 +10324,12 @@ fold_ternary (enum tree_code code, tree 
 		 < TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)))
 	    {
 	      tree elements = TREE_VECTOR_CST_ELTS (arg0);
-	      while (idx-- > 0)
+	      while (idx-- > 0 && elements)
 		elements = TREE_CHAIN (elements);
-	      return TREE_VALUE (elements);
+	      if (elements)
+		return TREE_VALUE (elements);
+	      else
+		return fold_convert (type, integer_zero_node);
 	    }
 	}
       return NULL_TREE;
--- gcc/testsuite/gcc.c-torture/execute/20050604-1.c.jj	2005-06-04 12:02:16.000000000 +0200
+++ gcc/testsuite/gcc.c-torture/execute/20050604-1.c	2005-06-04 11:48:33.000000000 +0200
@@ -0,0 +1,39 @@
+/* PR regression/21897 */
+
+extern void abort (void);
+
+typedef short v4hi __attribute__ ((vector_size (8)));
+typedef float v4sf __attribute__ ((vector_size (16)));
+
+union
+{
+  v4hi v;
+  short s[4];
+} u;
+
+union
+{
+  v4sf v;
+  float f[4];
+} v;
+
+void
+foo (void)
+{
+  unsigned int i;
+  for (i = 0; i < 2; i++)
+    u.v += (v4hi) { 12, 14 };
+  for (i = 0; i < 2; i++)
+    v.v += (v4sf) { 18.0, 20.0, 22 };
+}
+
+int
+main (void)
+{
+  foo ();
+  if (u.s[0] != 24 || u.s[1] != 28 || u.s[2] || u.s[3])
+    abort ();
+  if (v.f[0] != 36.0 || v.f[1] != 40.0 || v.f[2] != 44.0 || v.f[3] != 0.0)
+    abort ();
+  return 0;
+}

	Jakub


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