Fix PR86046

Message ID alpine.LSU.2.20.1806051158410.5043@zhemvz.fhfr.qr
State New
Headers show
Series
  • Fix PR86046
Related show

Commit Message

Richard Biener June 5, 2018, 9:59 a.m.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

From 0001b7c690860b4bcd643c4431918bc5aed08d41 Mon Sep 17 00:00:00 2001
From: Richard Guenther <rguenther@suse.de>

Date: Tue, 5 Jun 2018 10:20:51 +0200
Subject: [PATCH] fix-pr86046

2018-06-05  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/86046
	* tree-ssa.c (maybe_optimize_var): Clear DECL_GIMPLE_REG_P
	if required after clearing TREE_ADDRESSABLE.

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

Patch

diff --git a/gcc/testsuite/gcc.dg/pr86046.c b/gcc/testsuite/gcc.dg/pr86046.c
new file mode 100644
index 00000000000..6d4c948cf8a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr86046.c
@@ -0,0 +1,8 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+typedef int V __attribute__ ((vector_size(4)));
+void fn1 ()
+{
+  (V){(1,0)}[1] = 0;  // out-of-bound access
+}
diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c
index d197f99bdd2..f1b322f2de6 100644
--- a/gcc/tree-ssa.c
+++ b/gcc/tree-ssa.c
@@ -1565,6 +1565,12 @@  maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
 	  || !bitmap_bit_p (not_reg_needs, DECL_UID (var))))
     {
       TREE_ADDRESSABLE (var) = 0;
+      /* If we cleared TREE_ADDRESSABLE make sure DECL_GIMPLE_REG_P
+         is unset if we cannot rewrite the var into SSA.  */
+      if ((TREE_CODE (TREE_TYPE (var)) == VECTOR_TYPE
+	   || TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE)
+	  && bitmap_bit_p (not_reg_needs, DECL_UID (var)))
+	DECL_GIMPLE_REG_P (var) = 0;
       if (is_gimple_reg (var))
 	bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
       if (dump_file)