avoid using uninitialized offset (PR 92622)

Message ID acefc7a7-8529-3f1a-72f0-0aff073f8cac@gmail.com
State New
Headers show
Series
  • avoid using uninitialized offset (PR 92622)
Related show

Commit Message

Martin Sebor Dec. 5, 2019, 10:22 p.m.
I've isolated the intermittent failures of a test for a recent
enhancement to -Warray-bounds reported in PR 92622 to the use
of an offset left uninitialized by a failed call to
get_addr_base_and_unit_offset.

The attached patch makes sure the variable is only used if
the call succeeds.  I will commit it tomorrow unless there
are objections/suggestions for changes.

Martin

Comments

Jeff Law Dec. 5, 2019, 10:34 p.m. | #1
On Thu, 2019-12-05 at 15:22 -0700, Martin Sebor wrote:
> PR middle-end/92622 - FAIL: gcc.dg/Warray-bounds-22.c on ILP32:

> missing warnings for VLA on lines 67 and 69

> 

> gcc/ChangeLog:

> 

> 	PR testsuite/92622

> 	* tree-vrp.c (vrp_prop::check_array_ref): Avoid using a

> variable

> 	left uninitialized by get_addr_base_and_unit_offset ofn

> failure.

OK
jeff

Patch

PR middle-end/92622 - FAIL: gcc.dg/Warray-bounds-22.c on ILP32: missing warnings for VLA on lines 67 and 69

gcc/ChangeLog:

	PR testsuite/92622
	* tree-vrp.c (vrp_prop::check_array_ref): Avoid using a variable
	left uninitialized by get_addr_base_and_unit_offset ofn failure.

Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c	(revision 279008)
+++ gcc/tree-vrp.c	(working copy)
@@ -3516,7 +3516,6 @@  vrp_prop::check_array_ref (location_t location, tr
 	  tree ptrdiff_max = TYPE_MAX_VALUE (ptrdiff_type_node);
 	  tree maxbound = ptrdiff_max;
 	  tree arg = TREE_OPERAND (ref, 0);
-	  poly_int64 off;
 
 	  const bool compref = TREE_CODE (arg) == COMPONENT_REF;
 	  if (compref)
@@ -3535,19 +3534,22 @@  vrp_prop::check_array_ref (location_t location, tr
 		 size wouldn't necessarily be correct if the reference is
 		 to its flexible array member initialized in a different
 		 translation unit.  */
-	      tree base = get_addr_base_and_unit_offset (arg, &off);
-	      if (!compref && base && DECL_P (base))
-		if (tree basesize = DECL_SIZE_UNIT (base))
-		  if (TREE_CODE (basesize) == INTEGER_CST)
-		    {
-		      maxbound = basesize;
-		      decl = base;
-		    }
+	      poly_int64 off;
+	      if (tree base = get_addr_base_and_unit_offset (arg, &off))
+		{
+		  if (!compref && DECL_P (base))
+		    if (tree basesize = DECL_SIZE_UNIT (base))
+		      if (TREE_CODE (basesize) == INTEGER_CST)
+			{
+			  maxbound = basesize;
+			  decl = base;
+			}
 
-	      if (known_gt (off, 0))
-		maxbound = wide_int_to_tree (sizetype,
-					     wi::sub (wi::to_wide (maxbound),
-						      off));
+		  if (known_gt (off, 0))
+		    maxbound = wide_int_to_tree (sizetype,
+						 wi::sub (wi::to_wide (maxbound),
+							  off));
+		}
 	    }
 	  else
 	    maxbound = fold_convert (sizetype, maxbound);