Commit 7edaa4d2 by Marc Glisse Committed by Jason Merrill

re PR c++/51033 (generic vector subscript and shuffle support was not added to C++)

	PR c++/51033
gcc/
	* c-typeck.c (build_array_ref): Call
	convert_vector_to_pointer_for_subscript.
gcc/c-family
	* c-common.c (convert_vector_to_pointer_for_subscript): New function.
	* c-common.h (convert_vector_to_pointer_for_subscript): Declare it.
gcc/cp/
	* typeck.c (cp_build_array_ref): Handle VECTOR_TYPE.
	* decl2.c (grok_array_decl): Likewise.

From-SVN: r186994
parent f45d8c45
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> 2012-04-30 Uros Bizjak <ubizjak@gmail.com>
* config/i386/i386.md (and<mode>3): Change runtime operand mode checks * 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> 2012-04-30 Dodji Seketeli <dodji@redhat.com>
Add -Wvarargs option Add -Wvarargs option
......
...@@ -10833,4 +10833,30 @@ build_userdef_literal (tree suffix_id, tree value, tree num_string) ...@@ -10833,4 +10833,30 @@ build_userdef_literal (tree suffix_id, tree value, tree num_string)
return literal; 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" #include "gt-c-family-c-common.h"
...@@ -1119,4 +1119,6 @@ struct GTY(()) tree_userdef_literal { ...@@ -1119,4 +1119,6 @@ struct GTY(()) tree_userdef_literal {
extern tree build_userdef_literal (tree suffix_id, tree value, tree num_string); 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 */ #endif /* ! GCC_C_COMMON_H */
...@@ -2340,26 +2340,7 @@ build_array_ref (location_t loc, tree array, tree index) ...@@ -2340,26 +2340,7 @@ build_array_ref (location_t loc, tree array, tree index)
gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE); gcc_assert (TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE);
/* For vector[index], convert the vector to a convert_vector_to_pointer_for_subscript (loc, &array, index);
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);
}
if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE) if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
{ {
......
2012-04-30 Marc Glisse <marc.glisse@inria.fr> 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 PR c++/51314
* parser.c (cp_parser_sizeof_operand): Require parentheses for * parser.c (cp_parser_sizeof_operand): Require parentheses for
sizeof... sizeof...
......
...@@ -373,7 +373,7 @@ grok_array_decl (tree array_expr, tree index_exp) ...@@ -373,7 +373,7 @@ grok_array_decl (tree array_expr, tree index_exp)
It is a little-known fact that, if `a' is an array and `i' is 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 an int, you can write `i[a]', which means the same thing as
`a[i]'. */ `a[i]'. */
if (TREE_CODE (type) == ARRAY_TYPE) if (TREE_CODE (type) == ARRAY_TYPE || TREE_CODE (type) == VECTOR_TYPE)
p1 = array_expr; p1 = array_expr;
else else
p1 = build_expr_type_conversion (WANT_POINTER, array_expr, false); p1 = build_expr_type_conversion (WANT_POINTER, array_expr, false);
......
...@@ -2915,6 +2915,8 @@ cp_build_array_ref (location_t loc, tree array, tree idx, ...@@ -2915,6 +2915,8 @@ cp_build_array_ref (location_t loc, tree array, tree idx,
break; break;
} }
convert_vector_to_pointer_for_subscript (loc, &array, idx);
if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE) if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
{ {
tree rval, type; tree rval, type;
......
...@@ -6823,7 +6823,7 @@ a = 2 * b; /* a = @{2,2,2,2@} * b; */ ...@@ -6823,7 +6823,7 @@ a = 2 * b; /* a = @{2,2,2,2@} * b; */
a = l + a; /* Error, cannot convert long to int. */ a = l + a; /* Error, cannot convert long to int. */
@end smallexample @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 the same number of elements and base type. Out of bound accesses
invoke undefined behavior at runtime. Warnings for out of bound invoke undefined behavior at runtime. Warnings for out of bound
accesses for vector subscription can be enabled with accesses for vector subscription can be enabled with
......
2012-04-30 Marc Glisse <marc.glisse@inria.fr> 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 PR c++/51314
* g++.dg/cpp0x/vt-51314.C: New test. * g++.dg/cpp0x/vt-51314.C: New test.
* g++.dg/cpp0x/variadic76.C: Fix. * g++.dg/cpp0x/variadic76.C: Fix.
......
...@@ -18,4 +18,3 @@ int f(void) ...@@ -18,4 +18,3 @@ int f(void)
a1 = a1 & b1; a1 = a1 & b1;
a1 = a1 ^ b1; a1 = a1 ^ b1;
} }
...@@ -2,4 +2,7 @@ ...@@ -2,4 +2,7 @@
/* Check that we error out when using vector_size on the bool type. */ /* 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 "" } */ __attribute__((vector_size(16) )) _Bool a; /* { dg-error "" } */
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
float vf(vector float a) float vf(vector float a)
{ {
return 0[a]; /* { dg-error "subscripted value is neither array nor pointer nor vector" } */ return 0[a]; /* { dg-error "subscripted value is neither array nor pointer nor vector|invalid types .* for array subscript" } */
} }
...@@ -14,4 +14,3 @@ float fv(vector float a) ...@@ -14,4 +14,3 @@ float fv(vector float a)
{ {
return a[0]; return a[0];
} }
...@@ -10,4 +10,3 @@ float vf(int i) ...@@ -10,4 +10,3 @@ float vf(int i)
register vector float a; register vector float a;
return a[0]; return a[0];
} }
...@@ -16,4 +16,3 @@ int test1(void) ...@@ -16,4 +16,3 @@ int test1(void)
vector int a; vector int a;
return a[-1]; /* { dg-warning "index value is out of bound" } */ return a[-1]; /* { dg-warning "index value is out of bound" } */
} }
// { 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" }
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment