Bug 34197 - array overflow warning without line number
Summary: array overflow warning without line number
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 32546 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-11-22 18:47 UTC by marcus
Modified: 2007-11-23 23:11 UTC (History)
6 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: i586-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2007-11-22 19:28:25


Attachments
relay16.i (196 bytes, text/plain)
2007-11-22 18:48 UTC, marcus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description marcus 2007-11-22 18:47:40 UTC
LANG=C /home/marcus/projects/gcc/BIN/bin/gcc  -c  -O2 -Wall -g -o xx.o relay16.i -m32
relay16.i: In function 'f':
cc1: warning: array subscript is above array bounds


-m32 seems necessary
Comment 1 marcus 2007-11-22 18:48:02 UTC
Created attachment 14612 [details]
relay16.i

testcase
Comment 2 Richard Biener 2007-11-22 19:28:25 UTC
The expression warned about is

   call_5(D)->ret[5]

and I suspect the mapped locations make the location information wrong.
Comment 3 Richard Biener 2007-11-22 19:34:35 UTC
Indeed.  EXPR_LOCUS no longer is NULL if there is no location, but one has
to use EXPR_HAS_LOCATION instead.  Like

Index: tree-vrp.c
===================================================================
--- tree-vrp.c  (revision 130323)
+++ tree-vrp.c  (working copy)
@@ -4492,8 +4492,9 @@ check_all_array_refs (void)
          continue;
       }
       for (si = bsi_start (bb); !bsi_end_p (si); bsi_next (&si))
-       walk_tree (bsi_stmt_ptr (si), check_array_bounds,
-                  bsi_stmt (si), NULL);
+        if (expr_has_location (bsi_stmt (si)))
+         walk_tree (bsi_stmt_ptr (si), check_array_bounds,
+                    bsi_stmt (si), NULL);
     }
 }
 

which gets rid of the warning.
Comment 4 Dirk Mueller 2007-11-22 22:34:49 UTC
thanks for the analysis. I would go for a slightly more verbose version of the same patch: 

--- gcc/tree-vrp.c      (revision 130297)
+++ gcc/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)

Comment 5 Dirk Mueller 2007-11-22 22:40:29 UTC
*** Bug 32546 has been marked as a duplicate of this bug. ***
Comment 6 Dirk Mueller 2007-11-23 23:02:34 UTC
Subject: Bug 34197

Author: mueller
Date: Fri Nov 23 23:02:21 2007
New Revision: 130385

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130385
Log:
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().


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree-vrp.c

Comment 7 Dirk Mueller 2007-11-23 23:11:34 UTC
Fixed for 4.3