[PATCH] tree-optimization/101154 - fix out-of bound access in SLP

Richard Biener rguenther@suse.de
Tue Jun 22 09:01:03 GMT 2021


This fixes an out-of-bound access of matches.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2021-06-22  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/101154
	* tree-vect-slp.c (vect_build_slp_tree_2): Fix out-of-bound access.
---
 gcc/tree-vect-slp.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index a32f86b8bc7..b9f91e7c7ba 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -1963,15 +1963,15 @@ vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
 	      if (dt == vect_constant_def
 		  || dt == vect_external_def)
 		{
-		/* We can always build those.  Might want to sort last
-		   or defer building.  */
-		   vec<tree> ops;
-		   ops.create (group_size);
-		   for (lane = 0; lane < group_size; ++lane)
-		     ops.quick_push (chains[lane][n].op);
-		   slp_tree child = vect_create_new_slp_node (ops);
-		   SLP_TREE_DEF_TYPE (child) = dt;
-		   children.safe_push (child);
+		  /* We can always build those.  Might want to sort last
+		     or defer building.  */
+		  vec<tree> ops;
+		  ops.create (group_size);
+		  for (lane = 0; lane < group_size; ++lane)
+		    ops.quick_push (chains[lane][n].op);
+		  slp_tree child = vect_create_new_slp_node (ops);
+		  SLP_TREE_DEF_TYPE (child) = dt;
+		  children.safe_push (child);
 		}
 	      else if (dt != vect_internal_def)
 		{
@@ -2036,9 +2036,10 @@ vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
 			dump_printf_loc (MSG_NOTE, vect_location,
 					 "failed to match up op %d\n", n);
 		      op_stmts.release ();
-		      matches[lane] = false;
 		      if (lane != group_size - 1)
 			matches[0] = false;
+		      else
+			matches[lane] = false;
 		      goto out;
 		    }
 		  if (dump_enabled_p ())
-- 
2.26.2


More information about the Gcc-patches mailing list