From 40e0364c5564fa3d9cab209ecafe22778bf4c25b Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Tue, 9 Jul 2013 17:58:36 +0200 Subject: re PR c++/53094 (constexpr vector subscripting) 2013-07-09 Marc Glisse PR c++/53094 gcc/cp/ * semantics.c (cxx_eval_bit_field_ref): Handle VECTOR_CST. gcc/testsuite/ * g++.dg/cpp0x/constexpr-53094-1.C: Adjust. * g++.dg/ext/vector24.C: New testcase. From-SVN: r200822 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/semantics.c | 8 +++++++- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/constexpr-53094-1.C | 2 +- gcc/testsuite/g++.dg/ext/vector24.C | 8 ++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/vector24.C (limited to 'gcc') diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6a04e58..9262813 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2013-07-09 Marc Glisse + PR c++/53094 + * semantics.c (cxx_eval_bit_field_ref): Handle VECTOR_CST. + +2013-07-09 Marc Glisse + PR c++/53000 * call.c (build_conditional_expr_1): Preserve xvalues. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 0a6c775..c9a292e 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -7197,7 +7197,9 @@ cxx_eval_bit_field_ref (const constexpr_call *call, tree t, return t; /* Don't VERIFY_CONSTANT here; we only want to check that we got a CONSTRUCTOR. */ - if (!*non_constant_p && TREE_CODE (whole) != CONSTRUCTOR) + if (!*non_constant_p + && TREE_CODE (whole) != VECTOR_CST + && TREE_CODE (whole) != CONSTRUCTOR) { if (!allow_non_constant) error ("%qE is not a constant expression", orig_whole); @@ -7206,6 +7208,10 @@ cxx_eval_bit_field_ref (const constexpr_call *call, tree t, if (*non_constant_p) return t; + if (TREE_CODE (whole) == VECTOR_CST) + return fold_ternary (BIT_FIELD_REF, TREE_TYPE (t), whole, + TREE_OPERAND (t, 1), TREE_OPERAND (t, 2)); + start = TREE_OPERAND (t, 2); istart = tree_low_cst (start, 0); isize = tree_low_cst (TREE_OPERAND (t, 1), 0); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 573d78a..a9b8829 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2013-07-09 Marc Glisse + PR c++/53094 + * g++.dg/cpp0x/constexpr-53094-1.C: Adjust. + * g++.dg/ext/vector24.C: New testcase. + +2013-07-09 Marc Glisse + PR c++/53000 * g++.dg/cpp0x/decltype17.C: Adjust. diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-53094-1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-53094-1.C index c24ff60..e49023d 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-53094-1.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-53094-1.C @@ -3,4 +3,4 @@ typedef float __attribute__ ((vector_size (4 * sizeof (float)))) V4; constexpr V4 v = { 1, 1, 1, 0 }; -constexpr V4 r = v[0] + v; // { dg-bogus "not a constant expression" "" { xfail *-*-* } } +constexpr V4 r = v[0] + v; diff --git a/gcc/testsuite/g++.dg/ext/vector24.C b/gcc/testsuite/g++.dg/ext/vector24.C new file mode 100644 index 0000000..3eca7fb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/vector24.C @@ -0,0 +1,8 @@ +// { dg-do compile { target c++11 } } + +typedef long vec __attribute__((vector_size(2*sizeof(long)))); +constexpr vec v = { 33, 42 }; +constexpr auto l0 = v[0]; +constexpr auto l1 = v[1]; +static_assert(l0==33,"Fail"); +static_assert(l1==42,"Fail"); -- cgit v1.1