aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2012-11-29 16:40:16 +0100
committerMarc Glisse <glisse@gcc.gnu.org>2012-11-29 15:40:16 +0000
commitd5a1053a0d44116b1cbd887928276517ed8f458a (patch)
tree3dce990d568815390898750b07c2fbe8db67abb2 /gcc/fold-const.c
parent6c5bf58a15d900b2e721b487f8a844b2bc604c47 (diff)
downloadgcc-d5a1053a0d44116b1cbd887928276517ed8f458a.zip
gcc-d5a1053a0d44116b1cbd887928276517ed8f458a.tar.gz
gcc-d5a1053a0d44116b1cbd887928276517ed8f458a.tar.bz2
re PR c++/53094 (constexpr vector subscripting)
2012-11-29 Marc Glisse <marc.glisse@inria.fr> PR c++/53094 gcc/ * fold-const.c (fold): Replace a CONSTRUCTOR with a VECTOR_CST. gcc/cp/ * cvt.c (ocp_convert): Call convert_to_vector. gcc/testsuite/ * g++.dg/ext/vector20.C: New testcase. From-SVN: r193938
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index e4693cd..071fb8c 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -14387,6 +14387,35 @@ fold (tree expr)
return t;
}
+ /* Return a VECTOR_CST if possible. */
+ case CONSTRUCTOR:
+ {
+ tree type = TREE_TYPE (t);
+ if (TREE_CODE (type) != VECTOR_TYPE)
+ return t;
+
+ tree *vec = XALLOCAVEC (tree, TYPE_VECTOR_SUBPARTS (type));
+ unsigned HOST_WIDE_INT idx, pos = 0;
+ tree value;
+
+ FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), idx, value)
+ {
+ if (!CONSTANT_CLASS_P (value))
+ return t;
+ if (TREE_CODE (value) == VECTOR_CST)
+ {
+ for (unsigned i = 0; i < VECTOR_CST_NELTS (value); ++i)
+ vec[pos++] = VECTOR_CST_ELT (value, i);
+ }
+ else
+ vec[pos++] = value;
+ }
+ for (; pos < TYPE_VECTOR_SUBPARTS (type); ++pos)
+ vec[pos] = build_zero_cst (TREE_TYPE (type));
+
+ return build_vector (type, vec);
+ }
+
case CONST_DECL:
return fold (DECL_INITIAL (t));