[3.4 PATCH] fix target/18583

Janis Johnson janis187@us.ibm.com
Sat Oct 8 01:36:00 GMT 2005


This patch fixes PR target/18583, a regression from 3.4.2 that only
affects the 3.4 branch.  The fix is part of a patch to mainline but
with vector_types_convertible_p updated to match that function in the
4.0 branch.  I had problems with the full patch so just backported the
little part needed to fix this bug to minimize the possibility of
adding new undetected regressions.

I'm not sure of the state of the 3.4 branch, but when it's open for
fixes is this OK?  Bootstrapped and regtested on powerpc64-linux.

2005-10-07  Janis Johnson  <janis187@us.ibm.com>

        Partial backport from mainline
	2004-05-04 Paolo Bonzini  <bonzini@gnu.org>
		   Richard Henderson  <rth@redhat.com>
	* c-common.c (vector_types_convertible_p): New function.
	* c-common.h: Declare it.
	* c-typeck.c (digest_init): Use it.

testsuite:

	* gcc.dg/altivec-pr18583.c: New test.

Index: gcc/c-common.c
===================================================================
RCS file: /opt/gcc-cvs/gcc/gcc/c-common.c,v
retrieving revision 1.476.4.12
diff -u -p -r1.476.4.12 c-common.c
--- gcc/c-common.c	7 Jan 2005 19:58:51 -0000	1.476.4.12
+++ gcc/c-common.c	7 Oct 2005 21:16:06 -0000
@@ -1273,6 +1273,18 @@ constant_fits_type_p (tree c, tree type)
   return !TREE_OVERFLOW (c);
 }
 
+/* Nonzero if vector types T1 and T2 can be converted to each other
+   without an explicit cast.  */
+int
+vector_types_convertible_p (tree t1, tree t2)
+{
+  return targetm.vector_opaque_p (t1)
+	 || targetm.vector_opaque_p (t2)
+         || (tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))
+	     && INTEGRAL_TYPE_P (TREE_TYPE (t1))
+		== INTEGRAL_TYPE_P (TREE_TYPE (t2)));
+}
+
 /* Convert EXPR to TYPE, warning about conversion problems with constants.
    Invoke this function on every expression that is converted implicitly,
    i.e. because of language rules and not because of an explicit cast.  */
Index: gcc/c-common.h
===================================================================
RCS file: /opt/gcc-cvs/gcc/gcc/c-common.h,v
retrieving revision 1.216.2.4
diff -u -p -r1.216.2.4 c-common.h
--- gcc/c-common.h	18 Feb 2004 00:09:01 -0000	1.216.2.4
+++ gcc/c-common.h	7 Oct 2005 21:17:40 -0000
@@ -1261,6 +1261,8 @@ extern tree finish_label_address_expr (t
    different implementations.  Used in c-common.c.  */
 extern tree lookup_label (tree);
 
+extern int vector_types_convertible_p (tree t1, tree t2);
+
 extern rtx c_expand_expr (tree, rtx, enum machine_mode, int, rtx *);
 
 extern int c_safe_from_p (rtx, tree);
Index: gcc/c-typeck.c
===================================================================
RCS file: /opt/gcc-cvs/gcc/gcc/c-typeck.c,v
retrieving revision 1.272.2.14
diff -u -p -r1.272.2.14 c-typeck.c
--- gcc/c-typeck.c	28 Jul 2005 22:55:46 -0000	1.272.2.14
+++ gcc/c-typeck.c	7 Oct 2005 21:17:02 -0000
@@ -4098,7 +4098,8 @@ digest_init (tree type, tree init, int r
      vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
      below and handle as a constructor.  */
   if (code == VECTOR_TYPE
-      && comptypes (TREE_TYPE (inside_init), type, COMPARE_STRICT)
+      && TREE_CODE (TREE_TYPE (inside_init)) == VECTOR_TYPE
+      && vector_types_convertible_p (TREE_TYPE (inside_init), type)
       && TREE_CONSTANT (inside_init))
     {
       if (TREE_CODE (inside_init) == VECTOR_CST
--- /dev/null	2004-06-24 11:06:20.000000000 -0700
+++ gcc/testsuite/gcc.dg/altivec-pr18583.c	2005-10-06 12:46:41.000000000 -0700
@@ -0,0 +1,8 @@
+/* { dg-do compile { target powerpc*-*-* } } */
+/* { dg-xfail-if "" { "powerpc-ibm-aix*" } { "-maltivec" } { "" } } */
+/* { dg-options "-maltivec" } */
+
+#include <altivec.h>
+
+static const vector signed short c[1] = 
+  {(const vector signed short){4095, 5681, 5351, 4816, 4095, 4816, 5351, 5681}};



More information about the Gcc-patches mailing list