This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR34197 new bogus array overflow warnings


Hi, 

mapped_location requires to use EXPR_HAS_LOCATION. convert the code to use 
that. Thanks to Richard Guenther for the analysis.

The part in reg-stack.c is optional. the issue here is that 
with --disable-checking, the asserts are compiled out and gcc unrolls a lot 
of dead code (which caused the warning). The patch reduces text size by 102 
bytes (!) with disable-checking, and is just a noop with any other checking 
level.

bootstrapped/regtested on x86_64-suse-linux with no new regressions.


2007-11-23  Dirk Mueller  <dmueller@suse.de>
                    Richard Guenther <rguenther@suse.de>

	PR middle-end/34197
	* tree-vrp.c (check_array_ref): Move check for valid location..
	(check_array_bounds) here. Use EXPR_HAS_LOCATION().
	* reg-stack.c (swap_to_top): Add assert'ed expression to
	if() to prevent unroll of dead code. 


--- tree-vrp.c  (revision 130297)
+++ tree-vrp.c  (working copy)
@@ -4339,7 +4339,7 @@ check_array_ref (tree ref, location_t* l

   low_sub = up_sub = TREE_OPERAND (ref, 1);

-  if (!up_bound || !locus || TREE_NO_WARNING (ref)
+  if (!up_bound || TREE_NO_WARNING (ref)
       || TREE_CODE (up_bound) != INTEGER_CST
       /* Can not check flexible arrays.  */
       || (TYPE_SIZE (TREE_TYPE (ref)) == NULL_TREE
@@ -4441,6 +4441,11 @@ check_array_bounds (tree *tp, int *walk_
   tree stmt = (tree)data;
   location_t *location = EXPR_LOCUS (stmt);

+  if (!EXPR_HAS_LOCATION (stmt)) {
+      *walk_subtree = FALSE;
+      return NULL_TREE;
+  }
+
   *walk_subtree = TRUE;

   if (TREE_CODE (t) == ARRAY_REF)--- reg-stack.c (revision 130297)
+++ reg-stack.c (working copy)
@@ -925,7 +925,7 @@ swap_to_top (rtx insn, stack regstack, r
   /* Place operand 1 at the top of stack.  */
   regno = get_hard_regnum (&temp_stack, src1);
   gcc_assert (regno >= 0);
-  if (regno != FIRST_STACK_REG)
+  if (regno >= 0 && regno != FIRST_STACK_REG)
     {
       k = temp_stack.top - (regno - FIRST_STACK_REG);
       j = temp_stack.top;
@@ -938,7 +938,7 @@ swap_to_top (rtx insn, stack regstack, r
   /* Place operand 2 next on the stack.  */
   regno = get_hard_regnum (&temp_stack, src2);
   gcc_assert (regno >= 0);
-  if (regno != FIRST_STACK_REG + 1)
+  if (regno >= 0 && regno != FIRST_STACK_REG + 1)
     {
       k = temp_stack.top - (regno - FIRST_STACK_REG);
       j = temp_stack.top - 1;




-- 
RPMLINT information under http://en.opensuse.org/Packaging/RpmLintPR


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]