OSDN Git Service

2009-04-22 Andrew Pinski <andrew_pinski@playstation.sony.com>
authorpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 22 Apr 2009 23:22:53 +0000 (23:22 +0000)
committerpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 22 Apr 2009 23:22:53 +0000 (23:22 +0000)
        PR C/31499
        * c-typeck.c (process_init_element): Treat VECTOR_TYPE like ARRAY_TYPE
        and RECORD_TYPE/UNION_TYPE.  When outputing the actual element and the
        value is a VECTOR_CST, the element type is the element type of the
        vector.

2009-04-22  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR C/31499
        * gcc.dg/vector-init-1.c: New testcase.
        * gcc.dg/vector-init-2.c: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@146628 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vector-init-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vector-init-2.c [new file with mode: 0644]

index 9b32e3a..e6a6470 100644 (file)
@@ -1,3 +1,11 @@
+2009-04-22  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       PR C/31499
+       * c-typeck.c (process_init_element): Treat VECTOR_TYPE like ARRAY_TYPE
+       and RECORD_TYPE/UNION_TYPE.  When outputing the actual element and the
+       value is a VECTOR_CST, the element type is the element type of the
+       vector.
+
 2009-04-22  DJ Delorie  <dj@redhat.com>
 
        * config/m32c/m32c.h: Update GTY annotations to new syntax.
index 1ff6e9b..34960a0 100644 (file)
@@ -7287,7 +7287,8 @@ process_init_element (struct c_expr value, bool implicit)
           || TREE_CODE (constructor_type) == UNION_TYPE)
          && constructor_fields == 0)
        process_init_element (pop_init_level (1), true);
-      else if (TREE_CODE (constructor_type) == ARRAY_TYPE
+      else if ((TREE_CODE (constructor_type) == ARRAY_TYPE
+               || TREE_CODE (constructor_type) == VECTOR_TYPE)
               && (constructor_max_index == 0
                   || tree_int_cst_lt (constructor_max_index,
                                       constructor_index)))
@@ -7359,7 +7360,7 @@ process_init_element (struct c_expr value, bool implicit)
                   && value.value != error_mark_node
                   && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype
                   && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
-                      || fieldcode == UNION_TYPE))
+                      || fieldcode == UNION_TYPE || fieldcode == VECTOR_TYPE))
            {
              push_init_level (1);
              continue;
@@ -7450,7 +7451,7 @@ process_init_element (struct c_expr value, bool implicit)
                   && value.value != error_mark_node
                   && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != fieldtype
                   && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
-                      || fieldcode == UNION_TYPE))
+                      || fieldcode == UNION_TYPE || fieldcode == VECTOR_TYPE))
            {
              push_init_level (1);
              continue;
@@ -7491,7 +7492,7 @@ process_init_element (struct c_expr value, bool implicit)
                   && value.value != error_mark_node
                   && TYPE_MAIN_VARIANT (TREE_TYPE (value.value)) != elttype
                   && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
-                      || eltcode == UNION_TYPE))
+                      || eltcode == UNION_TYPE || eltcode == VECTOR_TYPE))
            {
              push_init_level (1);
              continue;
@@ -7540,9 +7541,13 @@ process_init_element (struct c_expr value, bool implicit)
 
          /* Now output the actual element.  */
          if (value.value)
-           output_init_element (value.value, value.original_type,
-                                strict_string, elttype,
-                                constructor_index, 1, implicit);
+           {
+             if (TREE_CODE (value.value) == VECTOR_CST)
+               elttype = TYPE_MAIN_VARIANT (constructor_type);
+             output_init_element (value.value, value.original_type,
+                                  strict_string, elttype,
+                                  constructor_index, 1, implicit);
+           }
 
          constructor_index
            = size_binop (PLUS_EXPR, constructor_index, bitsize_one_node);
index 8002f79..8869fc1 100644 (file)
@@ -1,3 +1,9 @@
+2009-04-22  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       PR C/31499
+       * gcc.dg/vector-init-1.c: New testcase.
+       * gcc.dg/vector-init-2.c: New testcase.
+
 2009-04-22  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/enum2.adb: New test.
diff --git a/gcc/testsuite/gcc.dg/vector-init-1.c b/gcc/testsuite/gcc.dg/vector-init-1.c
new file mode 100644 (file)
index 0000000..5baf956
--- /dev/null
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+
+/* PR C/31499, test that the C front-end treats vectors like an array. */
+
+#define vector __attribute__((__vector_size__(4*sizeof(int)) ))
+vector signed int v1[]={0,1,2,3,4,5,6,7};
diff --git a/gcc/testsuite/gcc.dg/vector-init-2.c b/gcc/testsuite/gcc.dg/vector-init-2.c
new file mode 100644 (file)
index 0000000..6527f49
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do run } */
+
+/* PR C/31499, test that the C front-end treats vectors like an array
+   and that it works at runtime. */
+
+#define vector __attribute__((__vector_size__(4*sizeof(int)) ))
+vector signed int v1[]={0,1,2,3,4,5,6,7};
+
+
+int main(void)
+{
+  int i;
+  for (i = 0; i < sizeof(v1)/sizeof(v1[0]); i++)
+  {
+    vector int t = v1[i];
+    int *d = (int*)&t;
+    int j;
+    for (j = 0; j < 4; j++)
+      {
+        if (d[j] != i * 4 + j)
+         __builtin_abort ();
+      }
+  }
+  return 0;
+}
\ No newline at end of file