diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-04-30 17:23:28 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-04-30 17:23:28 +0000 |
commit | 7059d45d7ce4e6a3ae1c50247b288d9a64685231 (patch) | |
tree | 49be9ae42e4ea26362131f6e948e29978abe950f | |
parent | df65c84d18307823b0092f07160f0e638d99026d (diff) | |
download | gcc-7059d45d7ce4e6a3ae1c50247b288d9a64685231.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186994 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c-family/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 26 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 2 | ||||
-rw-r--r-- | gcc/c-typeck.c | 21 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 2 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 2 | ||||
-rw-r--r-- | gcc/doc/extend.texi | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 20 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/vector-1.c (renamed from gcc/testsuite/gcc.dg/vector-1.c) | 0 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/vector-2.c (renamed from gcc/testsuite/gcc.dg/vector-2.c) | 1 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/vector-3.c (renamed from gcc/testsuite/gcc.dg/vector-3.c) | 3 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/vector-4.c (renamed from gcc/testsuite/gcc.dg/vector-4.c) | 0 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/vector-init-1.c (renamed from gcc/testsuite/gcc.dg/vector-init-1.c) | 0 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/vector-init-2.c (renamed from gcc/testsuite/gcc.dg/vector-init-2.c) | 0 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/vector-subscript-1.c (renamed from gcc/testsuite/gcc.dg/vector-subscript-1.c) | 3 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/vector-subscript-2.c (renamed from gcc/testsuite/gcc.dg/vector-subscript-2.c) | 1 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/vector-subscript-3.c (renamed from gcc/testsuite/gcc.dg/vector-subscript-3.c) | 1 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/vt-51314.C | 14 |
20 files changed, 88 insertions, 27 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5e7dadfbfc4..461f16208e6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +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 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 9f62db21b6d..7bd6ad7afa6 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +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 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 089c7576ddf..dce390260cd 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -10833,4 +10833,30 @@ build_userdef_literal (tree suffix_id, tree value, tree num_string) 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" diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index dd411032272..c3d679adcbc 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1119,4 +1119,6 @@ struct GTY(()) tree_userdef_literal { 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 */ diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 5e18a98d942..f45d1dcc342 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -2340,26 +2340,7 @@ build_array_ref (location_t loc, tree array, tree index) 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) { diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 282912a6a6b..e52149f023d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 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... diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 34c969c31fc..7088c675914 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -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 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); diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 4f1e965c65a..b59741c6471 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2915,6 +2915,8 @@ cp_build_array_ref (location_t loc, tree array, tree idx, break; } + convert_vector_to_pointer_for_subscript (loc, &array, idx); + if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE) { tree rval, type; diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 473339ec736..95cea834407 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -6823,7 +6823,7 @@ a = 2 * b; /* a = @{2,2,2,2@} * b; */ 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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6613970d23c..0a22ae4f05f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,25 @@ 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. diff --git a/gcc/testsuite/gcc.dg/vector-1.c b/gcc/testsuite/c-c++-common/vector-1.c index 288dd1e924c..288dd1e924c 100644 --- a/gcc/testsuite/gcc.dg/vector-1.c +++ b/gcc/testsuite/c-c++-common/vector-1.c diff --git a/gcc/testsuite/gcc.dg/vector-2.c b/gcc/testsuite/c-c++-common/vector-2.c index 5f9f9561d7f..e9f40a35892 100644 --- a/gcc/testsuite/gcc.dg/vector-2.c +++ b/gcc/testsuite/c-c++-common/vector-2.c @@ -18,4 +18,3 @@ int f(void) a1 = a1 & b1; a1 = a1 ^ b1; } - diff --git a/gcc/testsuite/gcc.dg/vector-3.c b/gcc/testsuite/c-c++-common/vector-3.c index 3f86698b83f..0f5d3c41157 100644 --- a/gcc/testsuite/gcc.dg/vector-3.c +++ b/gcc/testsuite/c-c++-common/vector-3.c @@ -2,4 +2,7 @@ /* 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 "" } */ diff --git a/gcc/testsuite/gcc.dg/vector-4.c b/gcc/testsuite/c-c++-common/vector-4.c index cc4d5041f63..cc4d5041f63 100644 --- a/gcc/testsuite/gcc.dg/vector-4.c +++ b/gcc/testsuite/c-c++-common/vector-4.c diff --git a/gcc/testsuite/gcc.dg/vector-init-1.c b/gcc/testsuite/c-c++-common/vector-init-1.c index 5baf9568840..5baf9568840 100644 --- a/gcc/testsuite/gcc.dg/vector-init-1.c +++ b/gcc/testsuite/c-c++-common/vector-init-1.c diff --git a/gcc/testsuite/gcc.dg/vector-init-2.c b/gcc/testsuite/c-c++-common/vector-init-2.c index 6527f495d81..6527f495d81 100644 --- a/gcc/testsuite/gcc.dg/vector-init-2.c +++ b/gcc/testsuite/c-c++-common/vector-init-2.c diff --git a/gcc/testsuite/gcc.dg/vector-subscript-1.c b/gcc/testsuite/c-c++-common/vector-subscript-1.c index 7cc50af999b..c18b7b674ab 100644 --- a/gcc/testsuite/gcc.dg/vector-subscript-1.c +++ b/gcc/testsuite/c-c++-common/vector-subscript-1.c @@ -6,7 +6,7 @@ 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) { return a[0]; } - diff --git a/gcc/testsuite/gcc.dg/vector-subscript-2.c b/gcc/testsuite/c-c++-common/vector-subscript-2.c index 3a8d522ad42..84d55b91d20 100644 --- a/gcc/testsuite/gcc.dg/vector-subscript-2.c +++ b/gcc/testsuite/c-c++-common/vector-subscript-2.c @@ -10,4 +10,3 @@ float vf(int i) register vector float a; return a[0]; } - diff --git a/gcc/testsuite/gcc.dg/vector-subscript-3.c b/gcc/testsuite/c-c++-common/vector-subscript-3.c index 55ed2b37025..22cd089adee 100644 --- a/gcc/testsuite/gcc.dg/vector-subscript-3.c +++ b/gcc/testsuite/c-c++-common/vector-subscript-3.c @@ -16,4 +16,3 @@ int test1(void) vector int a; return a[-1]; /* { dg-warning "index value is out of bound" } */ } - diff --git a/gcc/testsuite/g++.dg/cpp0x/vt-51314.C b/gcc/testsuite/g++.dg/cpp0x/vt-51314.C new file mode 100644 index 00000000000..9f8c646336e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/vt-51314.C @@ -0,0 +1,14 @@ +// { 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" } +}; |