public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Pinski <apinski@marvell.com>
To: <gcc-patches@gcc.gnu.org>
Cc: Andrew Pinski <apinski@marvell.com>
Subject: [PATCH] Fix PR 106900: array-bounds warning inside simplify_builtin_call
Date: Tue, 16 May 2023 17:52:56 -0700	[thread overview]
Message-ID: <20230517005256.1718424-1-apinski@marvell.com> (raw)

The problem here is that VRP cannot figure out isize could not be 0
due to using integer_zerop. This patch removes the use of integer_zerop
and instead checks for 0 directly after converting the tree to
an unsigned HOST_WIDE_INT. This allows VRP to figure out isize is not 0
and `isize - 1` will always be >= 0.

This patch is just to avoid the warning that GCC could produce sometimes
and does not change any code generation or even VRP.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (simplify_builtin_call): Check
	against 0 instead of calling integer_zerop.
---
 gcc/tree-ssa-forwprop.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 06f19868ade..0326e6733e8 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -1231,14 +1231,14 @@ simplify_builtin_call (gimple_stmt_iterator *gsi_p, tree callee2)
 	  tree size = gimple_call_arg (stmt2, 2);
 	  /* Size must be a constant which is <= UNITS_PER_WORD and
 	     <= the string length.  */
-	  if (TREE_CODE (size) != INTEGER_CST || integer_zerop (size))
+	  if (TREE_CODE (size) != INTEGER_CST)
 	    break;
 
 	  if (!tree_fits_uhwi_p (size))
 	    break;
 
 	  unsigned HOST_WIDE_INT sz = tree_to_uhwi (size);
-	  if (sz > UNITS_PER_WORD || sz >= slen)
+	  if (sz == 0 || sz > UNITS_PER_WORD || sz >= slen)
 	    break;
 
 	  tree ch = gimple_call_arg (stmt2, 1);
-- 
2.31.1


             reply	other threads:[~2023-05-17  0:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17  0:52 Andrew Pinski [this message]
2023-05-17  6:29 ` Richard Biener

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=20230517005256.1718424-1-apinski@marvell.com \
    --to=apinski@marvell.com \
    --cc=gcc-patches@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).