public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "manu at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/36902] Array bound warning with dead code after optimization
Date: Fri, 22 Aug 2008 16:45:00 -0000	[thread overview]
Message-ID: <20080822164423.1517.qmail@sourceware.org> (raw)
In-Reply-To: <bug-36902-682@http.gcc.gnu.org/bugzilla/>



------- Comment #17 from manu at gcc dot gnu dot org  2008-08-22 16:44 -------
The location passed to check_array_ref is correct but the new way to check if
we are in system headers does not work well with the %H hack. This will go away
soon  hopefully when everything takes an explicit location. The fix is to use
warning_at. This kind of thing may happen in the middle-end and in the
front-end. This doesn't fix the bogus warning though, it just suppresses it
within system headers.


Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c      (revision 139373)
+++ gcc/tree-vrp.c      (working copy)
@@ -4811,11 +4811,11 @@ insert_range_assertions (void)
    range. If the array subscript is a RANGE, warn if it is
    non-overlapping with valid range.
    IGNORE_OFF_BY_ONE is true if the ARRAY_REF is inside a ADDR_EXPR.  */

 static void
-check_array_ref (tree ref, const location_t *location, bool ignore_off_by_one)
+check_array_ref (tree ref, location_t location, bool ignore_off_by_one)
 {
   value_range_t* vr = NULL;
   tree low_sub, up_sub;
   tree low_bound, up_bound = array_ref_up_bound (ref);

@@ -4850,12 +4850,12 @@ check_array_ref (tree ref, const locatio
       if (TREE_CODE (up_sub) == INTEGER_CST
           && tree_int_cst_lt (up_bound, up_sub)
           && TREE_CODE (low_sub) == INTEGER_CST
           && tree_int_cst_lt (low_sub, low_bound))
         {
-          warning (OPT_Warray_bounds,
-                   "%Harray subscript is outside array bounds", location);
+          warning_at (location, OPT_Warray_bounds,
+                     "array subscript is outside array bounds");
           TREE_NO_WARNING (ref) = 1;
         }
     }
   else if (TREE_CODE (up_sub) == INTEGER_CST
            && tree_int_cst_lt (up_bound, up_sub)
@@ -4865,28 +4865,28 @@ check_array_ref (tree ref, const locatio
                                                         up_bound,
                                                         integer_one_node,
                                                         0),
                                        up_sub)))
     {
-      warning (OPT_Warray_bounds, "%Harray subscript is above array bounds",
-               location);
+      warning_at (location, OPT_Warray_bounds,
+                 "array subscript is above array bounds");
       TREE_NO_WARNING (ref) = 1;
     }
   else if (TREE_CODE (low_sub) == INTEGER_CST
            && tree_int_cst_lt (low_sub, low_bound))
     {
-      warning (OPT_Warray_bounds, "%Harray subscript is below array bounds",
-               location);
+      warning_at (location, OPT_Warray_bounds,
+                 "array subscript is below array bounds");
       TREE_NO_WARNING (ref) = 1;
     }
 }

 /* Searches if the expr T, located at LOCATION computes
    address of an ARRAY_REF, and call check_array_ref on it.  */

 static void
-search_for_addr_array(tree t, const location_t *location)
+search_for_addr_array(tree t, location_t location)
 {
   while (TREE_CODE (t) == SSA_NAME)
     {
       gimple g = SSA_NAME_DEF_STMT (t);

@@ -4925,11 +4925,11 @@ search_for_addr_array(tree t, const loca
 static tree
 check_array_bounds (tree *tp, int *walk_subtree, void *data)
 {
   tree t = *tp;
   struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
-  const location_t *location = (const location_t *) wi->info;
+  location_t location = *((location_t *) wi->info);

   *walk_subtree = TRUE;

   if (TREE_CODE (t) == ARRAY_REF)
     check_array_ref (t, location, false /*ignore_off_by_one*/);
@@ -4972,11 +4972,11 @@ check_all_array_refs (void)
          continue;
       }
       for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
        {
          gimple stmt = gsi_stmt (si);
-         const location_t *location = gimple_location_ptr (stmt);
+         location_t location = gimple_location (stmt);
          struct walk_stmt_info wi;
          if (!gimple_has_location (stmt))
            continue;

          if (is_gimple_call (stmt))
@@ -4990,12 +4990,12 @@ check_all_array_refs (void)
                }
            }
          else
            {
              memset (&wi, 0, sizeof (wi));
-             wi.info = CONST_CAST (void *, (const void *) location);
-
+             /*              wi.info = CONST_CAST (void *, (const void *)
&location);*/
+             wi.info = (void *) &location;
              walk_gimple_op (gsi_stmt (si),
                              check_array_bounds,
                              &wi);
            }
        }


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36902


  parent reply	other threads:[~2008-08-22 16:45 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-22 18:44 [Bug c/36902] New: [4.3/4.4 Regression]: Bogus array bound warning hjl dot tools at gmail dot com
2008-07-22 20:51 ` [Bug middle-end/36902] " pinskia at gcc dot gnu dot org
2008-07-22 21:13 ` hjl dot tools at gmail dot com
2008-07-22 21:19 ` [Bug middle-end/36902] Array bound warning with dead code after optimization pinskia at gcc dot gnu dot org
2008-07-22 21:27 ` paolo dot carlini at oracle dot com
2008-07-22 21:29 ` hjl dot tools at gmail dot com
2008-07-22 21:31 ` hjl dot tools at gmail dot com
2008-07-22 21:33 ` paolo dot carlini at oracle dot com
2008-07-22 21:43 ` hjl dot tools at gmail dot com
2008-07-22 22:54 ` paolo dot carlini at oracle dot com
2008-07-23  1:05 ` hjl dot tools at gmail dot com
2008-07-23  1:16 ` paolo dot carlini at oracle dot com
2008-07-23  1:24 ` hjl dot tools at gmail dot com
2008-07-23  1:29 ` paolo dot carlini at oracle dot com
2008-08-15 20:12 ` manu at gcc dot gnu dot org
2008-08-15 20:19 ` manu at gcc dot gnu dot org
2008-08-15 20:38 ` paolo dot carlini at oracle dot com
2008-08-22 16:45 ` manu at gcc dot gnu dot org [this message]
2008-08-22 17:06 ` manu at gcc dot gnu dot org
2008-08-22 17:31 ` pinskia at gcc dot gnu dot org
2008-08-22 17:38 ` hjl dot tools at gmail dot com
2008-08-22 17:55 ` manu at gcc dot gnu dot org
2008-08-25  8:01 ` mueller at gcc dot gnu dot org
2008-08-25 10:51 ` manu at gcc dot gnu dot org
2008-10-26 22:07 ` hjl dot tools at gmail dot com
2008-10-27  0:18 ` pinskia at gcc dot gnu dot org
2008-11-15  0:09 ` pinskia at gcc dot gnu dot org
2008-11-18 10:18 ` paolo dot carlini at oracle dot com
2008-11-18 14:43 ` hjl dot tools at gmail dot com
2008-11-18 15:23 ` manu at gcc dot gnu dot org
2008-11-18 15:27 ` paolo dot carlini at oracle dot com
2008-11-18 15:45 ` manu at gcc dot gnu dot org
2008-11-18 15:49 ` paolo dot carlini at oracle dot com
2008-11-18 16:07 ` manu at gcc dot gnu dot org
2009-04-18  9:25 ` manu at gcc dot gnu dot org
2009-04-18  9:30 ` manu at gcc dot gnu dot org
     [not found] <bug-36902-4@http.gcc.gnu.org/bugzilla/>
2021-10-21  2:03 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080822164423.1517.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).