]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/53094 (constexpr vector subscripting)
authorMarc Glisse <marc.glisse@inria.fr>
Tue, 9 Jul 2013 15:58:36 +0000 (17:58 +0200)
committerMarc Glisse <glisse@gcc.gnu.org>
Tue, 9 Jul 2013 15:58:36 +0000 (15:58 +0000)
2013-07-09  Marc Glisse  <marc.glisse@inria.fr>

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
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-53094-1.C
gcc/testsuite/g++.dg/ext/vector24.C [new file with mode: 0644]

index 6a04e58fcd3b2ebb1c63c56a4f16cda981676f61..9262813ef2eb6516309280c54b93e4f7f5f8fb55 100644 (file)
@@ -1,3 +1,8 @@
+2013-07-09  Marc Glisse  <marc.glisse@inria.fr>
+
+       PR c++/53094
+       * semantics.c (cxx_eval_bit_field_ref): Handle VECTOR_CST.
+
 2013-07-09  Marc Glisse  <marc.glisse@inria.fr>
 
        PR c++/53000
index 0a6c77541a6ff944d27619cd3ab7842357a33bf3..c9a292e824944151462741da07a55e0c2ee19b15 100644 (file)
@@ -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);
index 573d78a2726c4808349f744a9bb9792496649520..a9b8829d24c97b445bf30ddb258d486192bbbbfc 100644 (file)
@@ -1,3 +1,9 @@
+2013-07-09  Marc Glisse  <marc.glisse@inria.fr>
+
+       PR c++/53094
+       * g++.dg/cpp0x/constexpr-53094-1.C: Adjust.
+       * g++.dg/ext/vector24.C: New testcase.
+
 2013-07-09  Marc Glisse  <marc.glisse@inria.fr>
 
        PR c++/53000
index c24ff60219d7bbf8b04df6a36fa4e9a91820f04f..e49023d869e110b9284c675014b37fb82a247367 100644 (file)
@@ -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 (file)
index 0000000..3eca7fb
--- /dev/null
@@ -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");