+2012-04-30 Marc Glisse <marc.glisse@inria.fr>
+
+ PR c++/51033
+ * c-typeck.c (build_array_ref): Call
+ convert_vector_to_pointer_for_subscript.
+ * doc/extend.texi (Vector Extensions): Subscripting not just for C.
+
2012-04-30 Uros Bizjak <ubizjak@gmail.com>
* config/i386/i386.md (and<mode>3): Change runtime operand mode checks
+2012-04-30 Marc Glisse <marc.glisse@inria.fr>
+
+ PR c++/51033
+ * c-common.c (convert_vector_to_pointer_for_subscript): New function.
+ * c-common.h (convert_vector_to_pointer_for_subscript): Declare it.
+
2012-04-30 Dodji Seketeli <dodji@redhat.com>
Add -Wvarargs option
return literal;
}
+/* For vector[index], convert the vector to a
+ pointer of the underlying type. */
+void
+convert_vector_to_pointer_for_subscript (location_t loc,
+ tree* vecp, tree index)
+{
+ if (TREE_CODE (TREE_TYPE (*vecp)) == VECTOR_TYPE)
+ {
+ tree type = TREE_TYPE (*vecp);
+ tree type1;
+
+ if (TREE_CODE (index) == INTEGER_CST)
+ if (!host_integerp (index, 1)
+ || ((unsigned HOST_WIDE_INT) tree_low_cst (index, 1)
+ >= TYPE_VECTOR_SUBPARTS (type)))
+ warning_at (loc, OPT_Warray_bounds, "index value is out of bound");
+
+ c_common_mark_addressable_vec (*vecp);
+ type = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
+ type = build_pointer_type (type);
+ type1 = build_pointer_type (TREE_TYPE (*vecp));
+ *vecp = build1 (ADDR_EXPR, type1, *vecp);
+ *vecp = convert (type, *vecp);
+ }
+}
+
#include "gt-c-family-c-common.h"
extern tree build_userdef_literal (tree suffix_id, tree value, tree num_string);
+extern void convert_vector_to_pointer_for_subscript (location_t, tree*, tree);
+
#endif /* ! GCC_C_COMMON_H */
gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE);
- /* For vector[index], convert the vector to a
- pointer of the underlying type. */
- if (TREE_CODE (TREE_TYPE (array)) == VECTOR_TYPE)
- {
- tree type = TREE_TYPE (array);
- tree type1;
-
- if (TREE_CODE (index) == INTEGER_CST)
- if (!host_integerp (index, 1)
- || ((unsigned HOST_WIDE_INT) tree_low_cst (index, 1)
- >= TYPE_VECTOR_SUBPARTS (TREE_TYPE (array))))
- warning_at (loc, OPT_Warray_bounds, "index value is out of bound");
-
- c_common_mark_addressable_vec (array);
- type = build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
- type = build_pointer_type (type);
- type1 = build_pointer_type (TREE_TYPE (array));
- array = build1 (ADDR_EXPR, type1, array);
- array = convert (type, array);
- }
+ convert_vector_to_pointer_for_subscript (loc, &array, index);
if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
{
2012-04-30 Marc Glisse <marc.glisse@inria.fr>
+ PR c++/51033
+ * typeck.c (cp_build_array_ref): Handle VECTOR_TYPE.
+ * decl2.c (grok_array_decl): Likewise.
+
PR c++/51314
* parser.c (cp_parser_sizeof_operand): Require parentheses for
sizeof...
It is a little-known fact that, if `a' is an array and `i' is
an int, you can write `i[a]', which means the same thing as
`a[i]'. */
- if (TREE_CODE (type) == ARRAY_TYPE)
+ if (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == VECTOR_TYPE)
p1 = array_expr;
else
p1 = build_expr_type_conversion (WANT_POINTER, array_expr, false);
break;
}
+ convert_vector_to_pointer_for_subscript (loc, &array, idx);
+
if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
{
tree rval, type;
a = l + a; /* Error, cannot convert long to int. */
@end smallexample
-In C vectors can be subscripted as if the vector were an array with
+Vectors can be subscripted as if the vector were an array with
the same number of elements and base type. Out of bound accesses
invoke undefined behavior at runtime. Warnings for out of bound
accesses for vector subscription can be enabled with
2012-04-30 Marc Glisse <marc.glisse@inria.fr>
+ PR c++/51033
+ * gcc.dg/vector-1.c: Move to ...
+ * c-c++-common/vector-1.c: ... here.
+ * gcc.dg/vector-2.c: Move to ...
+ * c-c++-common/vector-2.c: ... here.
+ * gcc.dg/vector-3.c: Move to ...
+ * c-c++-common/vector-3.c: ... here. Adapt to C++.
+ * gcc.dg/vector-4.c: Move to ...
+ * c-c++-common/vector-4.c: ... here.
+ * gcc.dg/vector-init-1.c: Move to ...
+ * c-c++-common/vector-init-1.c: ... here.
+ * gcc.dg/vector-init-2.c: Move to ...
+ * c-c++-common/vector-init-2.c: ... here.
+ * gcc.dg/vector-subscript-1.c: Move to ... Adapt to C++.
+ * c-c++-common/vector-subscript-1.c: ... here.
+ * gcc.dg/vector-subscript-2.c: Move to ...
+ * c-c++-common/vector-subscript-2.c: ... here.
+ * gcc.dg/vector-subscript-3.c: Move to ...
+ * c-c++-common/vector-subscript-3.c: ... here.
+
PR c++/51314
* g++.dg/cpp0x/vt-51314.C: New test.
* g++.dg/cpp0x/variadic76.C: Fix.
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+/* Check for application of ~ on vector types. */
+
+#define vector __attribute__((vector_size(16) ))
+
+vector float a;
+vector int a1;
+
+int f(void)
+{
+ a = ~a; /* { dg-error "" } */
+ a1 = ~a1;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+/* Check for application of |, ^, and & on vector types. */
+#define vector __attribute__((vector_size(16) ))
+
+vector float a;
+vector int a1;
+vector float b;
+vector int b1;
+
+int f(void)
+{
+ a = a | b; /* { dg-error "" } */
+ a = a & b; /* { dg-error "" } */
+ a = a ^ b; /* { dg-error "" } */
+ a1 = a1 | b1;
+ a1 = a1 & b1;
+ a1 = a1 ^ b1;
+}
--- /dev/null
+/* { dg-do compile } */
+
+/* Check that we error out when using vector_size on the bool type. */
+
+#ifdef __cplusplus
+#define _Bool bool
+#endif
+__attribute__((vector_size(16) )) _Bool a; /* { dg-error "" } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-fno-common" { target { { hppa*-*-hpux* } && { ! lp64 } } } } */
+#define vector __attribute__((vector_size(4*sizeof(int)) ))
+
+vector int a, b, c;
+
+
+/* Test that remainder works for vectors. */
+void f(void)
+{
+ a = b % c;
+}
--- /dev/null
+/* { 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};
--- /dev/null
+/* { 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
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-w" } */
+
+#define vector __attribute__((vector_size(16) ))
+/* Check that vector[index] works and index[vector] is rejected. */
+
+float vf(vector float a)
+{
+ return 0[a]; /* { dg-error "subscripted value is neither array nor pointer nor vector|invalid types .* for array subscript" } */
+}
+
+
+float fv(vector float a)
+{
+ return a[0];
+}
--- /dev/null
+/* { dg-do compile } */
+
+/* Check that subscripting of vectors work with register storage class decls. */
+
+#define vector __attribute__((vector_size(16) ))
+
+
+float vf(int i)
+{
+ register vector float a;
+ return a[0];
+}
--- /dev/null
+/* Check the case when index is out of bound */
+/* { dg-do compile } */
+/* { dg-options "-Warray-bounds" } */
+
+#define vector __attribute__((vector_size(16) ))
+
+
+int test0(void)
+{
+ vector int a;
+ return a[10]; /* { dg-warning "index value is out of bound" } */
+}
+
+int test1(void)
+{
+ vector int a;
+ return a[-1]; /* { dg-warning "index value is out of bound" } */
+}
--- /dev/null
+// { dg-options "-std=c++11 -pedantic-errors" }
+// { dg-prune-output "invalid" }
+
+template<int>struct A{};
+template<class...U>void f(U...){
+ A<sizeof...U> x; // { dg-error "surrounded by parentheses" }
+}
+
+
+template<int...> struct Indices;
+template<class> struct Next_increasing_indices;
+template<int...I> struct Next_increasing_indices<Indices<I...> > {
+ typedef Indices<I...,sizeof...I> type; // { dg-error "surrounded by parentheses" }
+};
+++ /dev/null
-/* { dg-do compile } */
-/* { dg-options "" } */
-
-/* Check for application of ~ on vector types. */
-
-#define vector __attribute__((vector_size(16) ))
-
-vector float a;
-vector int a1;
-
-int f(void)
-{
- a = ~a; /* { dg-error "" } */
- a1 = ~a1;
-}
+++ /dev/null
-/* { dg-do compile } */
-/* { dg-options "" } */
-
-/* Check for application of |, ^, and & on vector types. */
-#define vector __attribute__((vector_size(16) ))
-
-vector float a;
-vector int a1;
-vector float b;
-vector int b1;
-
-int f(void)
-{
- a = a | b; /* { dg-error "" } */
- a = a & b; /* { dg-error "" } */
- a = a ^ b; /* { dg-error "" } */
- a1 = a1 | b1;
- a1 = a1 & b1;
- a1 = a1 ^ b1;
-}
-
+++ /dev/null
-/* { dg-do compile } */
-
-/* Check that we error out when using vector_size on the bool type. */
-
-__attribute__((vector_size(16) )) _Bool a; /* { dg-error "" } */
+++ /dev/null
-/* { dg-do compile } */
-/* { dg-options "-fno-common" { target { { hppa*-*-hpux* } && { ! lp64 } } } } */
-#define vector __attribute__((vector_size(4*sizeof(int)) ))
-
-vector int a, b, c;
-
-
-/* Test that remainder works for vectors. */
-void f(void)
-{
- a = b % c;
-}
+++ /dev/null
-/* { 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};
+++ /dev/null
-/* { 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
+++ /dev/null
-/* { dg-do compile } */
-/* { dg-options "-w" } */
-
-#define vector __attribute__((vector_size(16) ))
-/* Check that vector[index] works and index[vector] is rejected. */
-
-float vf(vector float a)
-{
- return 0[a]; /* { dg-error "subscripted value is neither array nor pointer nor vector" } */
-}
-
-
-float fv(vector float a)
-{
- return a[0];
-}
-
+++ /dev/null
-/* { dg-do compile } */
-
-/* Check that subscripting of vectors work with register storage class decls. */
-
-#define vector __attribute__((vector_size(16) ))
-
-
-float vf(int i)
-{
- register vector float a;
- return a[0];
-}
-
+++ /dev/null
-/* Check the case when index is out of bound */
-/* { dg-do compile } */
-/* { dg-options "-Warray-bounds" } */
-
-#define vector __attribute__((vector_size(16) ))
-
-
-int test0(void)
-{
- vector int a;
- return a[10]; /* { dg-warning "index value is out of bound" } */
-}
-
-int test1(void)
-{
- vector int a;
- return a[-1]; /* { dg-warning "index value is out of bound" } */
-}
-