Re: [C++ PATCH] Handle VECTOR_CSTs in adjust_temp_type (PR c++/55573)

2012-12-06 Thread Jason Merrill

On 12/06/2012 02:16 AM, Jakub Jelinek wrote:

With Marc's recent changes to fold vector CONSTRUCTORs into VECTOR_CSTs
if possible, we now ICE in adjust_temp_type, because the type of VECTOR_CST
is not SCALAR_TYPE_P.  Either we can handle VECTOR_CSTs directly
(in that case ignore_overflows is also called on each VECTOR_CST constant,
but not sure if that is needed), as done in the patch below, or
Marc has an alternative patch to just change the assert into
gcc_assert (scalarish_type_p);
Which way do you prefer?


If Marc's patch works, let's go with that.


BTW, the PR and the referenced PR contains some other patches, e.g.
cp_tree_equal not handling VECTOR_CSTs.  For that it is a similar question,
either VECTOR_CSTs can be handled there using operand_equal_p, or
by calling cp_tree_equal on the VECTOR_CST elements.


Let's go with the operand_equal_p option; less code duplication is good.

Jason



[C++ PATCH] Handle VECTOR_CSTs in adjust_temp_type (PR c++/55573)

2012-12-05 Thread Jakub Jelinek
Hi!

With Marc's recent changes to fold vector CONSTRUCTORs into VECTOR_CSTs
if possible, we now ICE in adjust_temp_type, because the type of VECTOR_CST
is not SCALAR_TYPE_P.  Either we can handle VECTOR_CSTs directly
(in that case ignore_overflows is also called on each VECTOR_CST constant,
but not sure if that is needed), as done in the patch below, or
Marc has an alternative patch to just change the assert into
gcc_assert (scalarish_type_p);
Which way do you prefer?

This one has been bootstrapped/regtested on x86_64-linux and i686-linux.

BTW, the PR and the referenced PR contains some other patches, e.g.
cp_tree_equal not handling VECTOR_CSTs.  For that it is a similar question,
either VECTOR_CSTs can be handled there using operand_equal_p, or
by calling cp_tree_equal on the VECTOR_CST elements.

2012-12-06  Jakub Jelinek  ja...@redhat.com

PR c++/55573
* semantics.c (adjust_temp_type): Handle VECTOR_CST.

* g++.dg/cpp0x/constexpr-55573.C: New test.

--- gcc/cp/semantics.c.jj   2012-11-23 00:14:40.0 +0100
+++ gcc/cp/semantics.c  2012-12-03 14:02:54.407690163 +0100
@@ -6451,6 +6451,14 @@ adjust_temp_type (tree type, tree temp)
   /* Avoid wrapping an aggregate value in a NOP_EXPR.  */
   if (TREE_CODE (temp) == CONSTRUCTOR)
 return build_constructor (type, CONSTRUCTOR_ELTS (temp));
+  if (TREE_CODE (temp) == VECTOR_CST)
+{
+  int i, count = TYPE_VECTOR_SUBPARTS (type);
+  tree *vec = XALLOCAVEC (tree, count);
+  for (i = 0; i  count; i++)
+   vec[i] = cp_fold_convert (TREE_TYPE (type), VECTOR_CST_ELT (temp, i));
+  return build_vector (type, vec);
+}
   gcc_assert (SCALAR_TYPE_P (type));
   return cp_fold_convert (type, temp);
 }
--- gcc/testsuite/g++.dg/cpp0x/constexpr-55573.C.jj 2012-12-03 
14:21:05.367303150 +0100
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-55573.C2012-12-03 
14:19:42.0 +0100
@@ -0,0 +1,22 @@
+// PR c++/55573
+// { dg-do compile }
+// { dg-options -std=gnu++11 }
+
+template typename T, int N
+struct ExtVecTraits {
+  typedef T __attribute__((vector_size (N * sizeof (T type;
+};
+
+template typename T
+using Vec4 = typename ExtVecTraitsT,4::type;
+
+template typename T
+struct Rot3
+{
+  typedef Vec4T Vec;
+  Vec axis[3];
+  constexpr Rot3 (Vec4T ix, Vec4T iy, Vec4T iz) : axis {ix, iy, iz} {}
+};
+
+typedef Vec4float Vec;
+Rot3float r2 ((Vec) {0, 1, 0, 0}, (Vec){0, 0, 1, 0}, (Vec){1, 0, 0, 0});

Jakub