re PR c++/53094 (constexpr vector subscripting)
authorMarc Glisse <marc.glisse@inria.fr>
Tue, 11 Dec 2012 20:20:23 +0000 (21:20 +0100)
committerMarc Glisse <glisse@gcc.gnu.org>
Tue, 11 Dec 2012 20:20:23 +0000 (20:20 +0000)
2012-12-11  Marc Glisse  <marc.glisse@inria.fr>

PR c++/53094
cp/
* tree.c (cp_tree_equal): Handle VECTOR_CST.
* semantics.c (cxx_eval_bare_aggregate): Protect a dereference.
Handle VECTOR_CST.
testsuite/
* g++.dg/cpp0x/constexpr-53094-1.C: New testcase.
* g++.dg/cpp0x/constexpr-53094-2.C: Likewise.
* g++.dg/cpp0x/constexpr-53094-3.C: Likewise.

From-SVN: r194421

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-53094-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/constexpr-53094-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/constexpr-53094-3.C [new file with mode: 0644]

index 2cd295b5b53d2666b0b2592ab4cb5cfb874dc004..5e75a143aa9673bcb405ddf17f526c9aa707d2ad 100644 (file)
@@ -1,3 +1,10 @@
+2012-12-11  Marc Glisse  <marc.glisse@inria.fr>
+
+       PR c++/53094
+       * tree.c (cp_tree_equal): Handle VECTOR_CST.
+       * semantics.c (cxx_eval_bare_aggregate): Protect a dereference.
+       Handle VECTOR_CST.
+
 2012-12-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/55643
index ad33c658fba5134c0fbc323590794c69d505781d..f6493993b37c242befc444f0d2778c82c10fb674 100644 (file)
@@ -7123,7 +7123,7 @@ cxx_eval_bare_aggregate (const constexpr_call *call, tree t,
        goto fail;
       if (elt != ce->value)
        changed = true;
-      if (TREE_CODE (ce->index) == COMPONENT_REF)
+      if (ce->index && TREE_CODE (ce->index) == COMPONENT_REF)
        {
          /* This is an initialization of a vfield inside a base
             subaggregate that we already initialized; push this
@@ -7131,7 +7131,7 @@ cxx_eval_bare_aggregate (const constexpr_call *call, tree t,
          constructor_elt *inner = base_field_constructor_elt (n, ce->index);
          inner->value = elt;
        }
-      else if (TREE_CODE (ce->index) == NOP_EXPR)
+      else if (ce->index && TREE_CODE (ce->index) == NOP_EXPR)
        {
          /* This is an initializer for an empty base; now that we've
             checked that it's constant, we can ignore it.  */
@@ -7148,6 +7148,8 @@ cxx_eval_bare_aggregate (const constexpr_call *call, tree t,
     }
   t = build_constructor (TREE_TYPE (t), n);
   TREE_CONSTANT (t) = true;
+  if (TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
+    t = fold (t);
   return t;
 }
 
index 00fe53f521477d55374eaac89037b88d6989b62f..c4302371b73910a351f5c28050ee099deb2639bd 100644 (file)
@@ -2468,6 +2468,9 @@ cp_tree_equal (tree t1, tree t2)
       return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
        && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
 
+    case VECTOR_CST:
+      return operand_equal_p (t1, t2, OEP_ONLY_CONST);
+
     case CONSTRUCTOR:
       /* We need to do this when determining whether or not two
         non-type pointer to member function template arguments
index ef71057069e42edcf7a25ae72a8fcf2beecfd1b6..2f80e7df4191f7c7275d4e187f7003eb07b35d60 100644 (file)
@@ -1,3 +1,10 @@
+2012-12-11  Marc Glisse  <marc.glisse@inria.fr>
+
+       PR c++/53094
+       * g++.dg/cpp0x/constexpr-53094-1.C: New testcase.
+       * g++.dg/cpp0x/constexpr-53094-2.C: Likewise.
+       * g++.dg/cpp0x/constexpr-53094-3.C: Likewise.
+
 2012-12-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/55643
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-53094-1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-53094-1.C
new file mode 100644 (file)
index 0000000..c24ff60
--- /dev/null
@@ -0,0 +1,6 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+
+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 *-*-* } }
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-53094-2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-53094-2.C
new file mode 100644 (file)
index 0000000..af4b8d9
--- /dev/null
@@ -0,0 +1,6 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+
+typedef float __attribute__ ((vector_size (4 * sizeof (float)))) V4;
+constexpr V4 build (float x, float y, float z) { return (V4){ x, y, z, 0 };}
+constexpr V4 x = build (1, 0, 0);
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-53094-3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-53094-3.C
new file mode 100644 (file)
index 0000000..bd17ac7
--- /dev/null
@@ -0,0 +1,19 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+
+typedef float __attribute__ ((vector_size (4 * sizeof (float)))) V4;
+
+struct Rot3 {
+  typedef float T;
+  typedef V4 Vec;
+  Vec axis[3];
+  constexpr Rot3 (V4 ix, V4 iy, V4 iz) : axis {ix, iy, iz} {}
+
+  constexpr Rot3(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz) :
+    Rot3((Vec) { xx, xy, xz, 0 },
+        (Vec) { yx, yy, yz, 0 },
+        (Vec) { zx, zy, zz, 0 }) {}
+
+};
+
+constexpr Rot3 r1( 0, 1 ,0, 0, 0, 1,  1, 0, 0);