[C] Fix PR83415

Message ID alpine.LSU.2.20.1712140954230.12252@zhemvz.fhfr.qr
State New
Headers show
Series
  • [C] Fix PR83415
Related show

Commit Message

Richard Biener Dec. 14, 2017, 8:55 a.m.
The C FE fails to handle VIEW_CONVERT_EXPR properly when folding
it in a lvalue context.  Fixed as follows.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Will commit as obvious.

Thanks,
Richard.

2017-12-14  Richard Biener  <rguenther@suse.de>

	PR c/83415
	c/
	* c-fold.c (c_fully_fold_internal): Treat VIEW_CONVERT_EXPR
	like REALPART_EXPR for the behavior of whether its operand
	is an lvalue.

	* gcc.dg/pr83415.c: New testcase.

Patch

Index: gcc/c/c-fold.c
===================================================================
--- gcc/c/c-fold.c	(revision 255622)
+++ gcc/c/c-fold.c	(working copy)
@@ -434,6 +434,7 @@  c_fully_fold_internal (tree expr, bool i
       goto unary;
     case REALPART_EXPR:
     case IMAGPART_EXPR:
+    case VIEW_CONVERT_EXPR:
       op0_lval = lval;
       /* FALLTHRU */
     case INDIRECT_REF:
@@ -441,7 +442,6 @@  c_fully_fold_internal (tree expr, bool i
     case FLOAT_EXPR:
     CASE_CONVERT:
     case ADDR_SPACE_CONVERT_EXPR:
-    case VIEW_CONVERT_EXPR:
     case NON_LVALUE_EXPR:
     case NEGATE_EXPR:
     case BIT_NOT_EXPR:
Index: gcc/testsuite/gcc.dg/pr83415.c
===================================================================
--- gcc/testsuite/gcc.dg/pr83415.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/pr83415.c	(working copy)
@@ -0,0 +1,12 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+const short __attribute__((vector_size(16))) y = { 0, 1, 2, 3, 4, 5, 6, 7 };
+
+int
+main (int argc, short *argv[])
+{
+  int i = argc;
+  y[i] = 7 - i; /* { dg-warning "read-only" } */
+  return 0;
+}