diff mbox

Handle vector increment/decrement in build_unary_op

Message ID 529456C0.8090908@mentor.com
State New
Headers show

Commit Message

Tom de Vries Nov. 26, 2013, 8:07 a.m. UTC
Jason,

This patch handles vector increment/decrement in build_unary_op and 
cp_build_binary_op.

In other words, we allow v++ and --v on a vector v.
v + 1 and v - 1 are already allowed.

This fixes an ICE when compiling a vector increment/decrement.

Bootstrapped and reg-tested on x86_64.

OK for trunk?

Thanks,
- Tom

2013-11-26  Tom de Vries  <tom@codesourcery.com>
	    Marc Glisse  <marc.glisse@inria.fr>

	PR c++/59032
	* c-typeck.c (build_unary_op): Allow vector increment and decrement.

	* typeck.c (cp_build_unary_op): Allow vector increment and decrement.

	* g++.dg/pr59032.C: New testcase.
	* gcc.dg/pr59032.c: Same.

Comments

Marc Glisse Nov. 26, 2013, 8:47 a.m. UTC | #1
On Tue, 26 Nov 2013, Tom de Vries wrote:

> 	* g++.dg/pr59032.C: New testcase.
> 	* gcc.dg/pr59032.c: Same.

I didn't check very carefully, but they look similar. If they are indeed 
the same, could it move to c-c++-common?
Jason Merrill Nov. 27, 2013, 12:21 a.m. UTC | #2
On 11/26/2013 03:47 AM, Marc Glisse wrote:
> On Tue, 26 Nov 2013, Tom de Vries wrote:
>
>>     * g++.dg/pr59032.C: New testcase.
>>     * gcc.dg/pr59032.c: Same.
>
> I didn't check very carefully, but they look similar. If they are indeed
> the same, could it move to c-c++-common?

OK with that change.

Jason
Tom de Vries Nov. 27, 2013, 11:23 p.m. UTC | #3
On 27-11-13 01:21, Jason Merrill wrote:
> On 11/26/2013 03:47 AM, Marc Glisse wrote:
>> On Tue, 26 Nov 2013, Tom de Vries wrote:
>>
>>>     * g++.dg/pr59032.C: New testcase.
>>>     * gcc.dg/pr59032.c: Same.
>>
>> I didn't check very carefully, but they look similar. If they are indeed
>> the same, could it move to c-c++-common?
>
> OK with that change.
>

Committed to trunk.

Also ok for 4.8 branch? It's a 4.8/4.9 regression.

Thanks,
- Tom

> Jason
>
Jason Merrill Nov. 28, 2013, 1:25 a.m. UTC | #4
On 11/27/2013 06:23 PM, Tom de Vries wrote:
> Also ok for 4.8 branch? It's a 4.8/4.9 regression.

Yes.

Jason
diff mbox

Patch

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 0c9c8c8..f602ca4 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -3982,7 +3982,7 @@  build_unary_op (location_t location,
 
       if (typecode != POINTER_TYPE && typecode != FIXED_POINT_TYPE
 	  && typecode != INTEGER_TYPE && typecode != REAL_TYPE
-	  && typecode != COMPLEX_TYPE)
+	  && typecode != COMPLEX_TYPE && typecode != VECTOR_TYPE)
 	{
 	  if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
 	    error_at (location, "wrong type argument to increment");
@@ -4047,7 +4047,9 @@  build_unary_op (location_t location,
 	  }
 	else
 	  {
-	    inc = integer_one_node;
+	    inc = VECTOR_TYPE_P (argtype)
+	      ? build_one_cst (argtype)
+	      : integer_one_node;
 	    inc = convert (argtype, inc);
 	  }
 
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index a4da037..9f9f7b6 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5748,7 +5748,9 @@  cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
 	    inc = cxx_sizeof_nowarn (TREE_TYPE (argtype));
 	  }
 	else
-	  inc = integer_one_node;
+	  inc = VECTOR_TYPE_P (argtype)
+	    ? build_one_cst (argtype)
+	    : integer_one_node;
 
 	inc = cp_convert (argtype, inc, complain);
 
diff --git a/gcc/testsuite/g++.dg/pr59032.C b/gcc/testsuite/g++.dg/pr59032.C
new file mode 100644
index 0000000..73f8889
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr59032.C
@@ -0,0 +1,31 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+void
+foo()
+{
+  float v __attribute__((vector_size(8)));
+  v++;
+}
+
+void
+foo2 ()
+{
+  float v __attribute__((vector_size(8)));
+  ++v;
+}
+
+void
+foo3 ()
+{
+  float v __attribute__((vector_size(8)));
+  v--;
+}
+
+void
+foo4 ()
+{
+  float v __attribute__((vector_size(8)));
+  --v;
+}
+
diff --git a/gcc/testsuite/gcc.dg/pr59032.c b/gcc/testsuite/gcc.dg/pr59032.c
new file mode 100644
index 0000000..0d8abc6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr59032.c
@@ -0,0 +1,30 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -std=gnu99" } */
+
+void
+foo()
+{
+  float v __attribute__((vector_size(8)));
+  v++;
+}
+
+void
+foo2 ()
+{
+  float v __attribute__((vector_size(8)));
+  ++v;
+}
+
+void
+foo3 ()
+{
+  float v __attribute__((vector_size(8)));
+  v--;
+}
+
+void
+foo4 ()
+{
+  float v __attribute__((vector_size(8)));
+  --v;
+}