public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] tree-optimization/107561 - reduce -Wstringop-overflow false positives
       [not found] <20230329121203.002E43858434@sourceware.org>
@ 2023-03-31 14:13 ` Jeff Law
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff Law @ 2023-03-31 14:13 UTC (permalink / raw)
  To: gcc-patches



On 3/29/23 06:11, Richard Biener via Gcc-patches wrote:
> The following tells pointer-query to prefer a zero size when we
> are querying for the size range for a write into an object we've
> determined is of zero size.  That avoids diagnostics about really
> varying size arguments that just get a meaningful range for example
> because they are multiplied by an element size.
> 
> I've adjusted only one call to get_size_range since that's what
> I have a testcase for.  I think this is the most sensible
> "workaround" for some of the false positives we see.
> 
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
> 
> OK if it succeeds?
> 
> Thanks,
> Richard.
> 
> 	PR tree-optimization/107561
> 	* gimple-ssa-warn-access.cc (get_size_range): Add flags
> 	argument and pass it on.
> 	(check_access): When querying for the size range pass
> 	SR_ALLOW_ZERO when the known destination size is zero.
> 
> 	* g++.dg/pr71488.C: Remove XFAILed bogus diagnostic again.
> 	* g++.dg/warn/Warray-bounds-16.C: Likewise.
OK.
jeff

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tree-optimization/107561 - reduce -Wstringop-overflow false positives
@ 2023-03-30 11:16 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2023-03-30 11:16 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

On Wed, 29 Mar 2023, Richard Biener wrote:

> The following tells pointer-query to prefer a zero size when we
> are querying for the size range for a write into an object we've
> determined is of zero size.  That avoids diagnostics about really
> varying size arguments that just get a meaningful range for example
> because they are multiplied by an element size.
> 
> I've adjusted only one call to get_size_range since that's what
> I have a testcase for.  I think this is the most sensible
> "workaround" for some of the false positives we see.
> 
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
> 
> OK if it succeeds?

It did, I have now pushed this, it seems like an obvious improvement.

Richard.

> Thanks,
> Richard.
> 
> 	PR tree-optimization/107561
> 	* gimple-ssa-warn-access.cc (get_size_range): Add flags
> 	argument and pass it on.
> 	(check_access): When querying for the size range pass
> 	SR_ALLOW_ZERO when the known destination size is zero.
> 
> 	* g++.dg/pr71488.C: Remove XFAILed bogus diagnostic again.
> 	* g++.dg/warn/Warray-bounds-16.C: Likewise.
> ---
>  gcc/gimple-ssa-warn-access.cc                | 19 +++++++++++++------
>  gcc/testsuite/g++.dg/pr71488.C               |  1 -
>  gcc/testsuite/g++.dg/warn/Warray-bounds-16.C |  1 -
>  3 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
> index 88d44690ade..b3de4b77924 100644
> --- a/gcc/gimple-ssa-warn-access.cc
> +++ b/gcc/gimple-ssa-warn-access.cc
> @@ -1198,10 +1198,10 @@ warn_for_access (location_t loc, tree func, tree expr, int opt,
>  
>  static void
>  get_size_range (range_query *query, tree bound, gimple *stmt, tree range[2],
> -		const offset_int bndrng[2])
> +		int flags, const offset_int bndrng[2])
>  {
>    if (bound)
> -    get_size_range (query, bound, stmt, range);
> +    get_size_range (query, bound, stmt, range, flags);
>  
>    if (!bndrng || (bndrng[0] == 0 && bndrng[1] == HOST_WIDE_INT_M1U))
>      return;
> @@ -1347,7 +1347,12 @@ check_access (GimpleOrTree exp, tree dstwrite,
>    /* Set RANGE to that of DSTWRITE if non-null, bounded by PAD->DST_BNDRNG
>       if valid.  */
>    gimple *stmt = pad ? pad->stmt : nullptr;
> -  get_size_range (rvals, dstwrite, stmt, range, pad ? pad->dst_bndrng : NULL);
> +  get_size_range (rvals, dstwrite, stmt, range,
> +		  /* If the destination has known zero size prefer a zero
> +		     size range to avoid false positives if that's a
> +		     possibility.  */
> +		  integer_zerop (dstsize) ? SR_ALLOW_ZERO : 0,
> +		  pad ? pad->dst_bndrng : NULL);
>  
>    tree func = get_callee_fndecl (exp);
>    /* Read vs write access by built-ins can be determined from the const
> @@ -1442,7 +1447,8 @@ check_access (GimpleOrTree exp, tree dstwrite,
>      {
>        /* Set RANGE to that of MAXREAD, bounded by PAD->SRC_BNDRNG if
>  	 PAD is nonnull and BNDRNG is valid.  */
> -      get_size_range (rvals, maxread, stmt, range, pad ? pad->src_bndrng : NULL);
> +      get_size_range (rvals, maxread, stmt, range, 0,
> +		      pad ? pad->src_bndrng : NULL);
>  
>        location_t loc = get_location (exp);
>        tree size = dstsize;
> @@ -1489,7 +1495,8 @@ check_access (GimpleOrTree exp, tree dstwrite,
>      {
>        /* Set RANGE to that of MAXREAD, bounded by PAD->SRC_BNDRNG if
>  	 PAD is nonnull and BNDRNG is valid.  */
> -      get_size_range (rvals, maxread, stmt, range, pad ? pad->src_bndrng : NULL);
> +      get_size_range (rvals, maxread, stmt, range, 0,
> +		      pad ? pad->src_bndrng : NULL);
>        /* Set OVERREAD for reads starting just past the end of an object.  */
>        overread = pad->src.sizrng[1] - pad->src.offrng[0] < pad->src_bndrng[0];
>        range[0] = wide_int_to_tree (sizetype, pad->src_bndrng[0]);
> @@ -2679,7 +2686,7 @@ pass_waccess::check_strncmp (gcall *stmt)
>    /* Determine the range of the bound first and bail if it fails; it's
>       cheaper than computing the size of the objects.  */
>    tree bndrng[2] = { NULL_TREE, NULL_TREE };
> -  get_size_range (m_ptr_qry.rvals, bound, stmt, bndrng, adata1.src_bndrng);
> +  get_size_range (m_ptr_qry.rvals, bound, stmt, bndrng, 0, adata1.src_bndrng);
>    if (!bndrng[0] || integer_zerop (bndrng[0]))
>      return;
>  
> diff --git a/gcc/testsuite/g++.dg/pr71488.C b/gcc/testsuite/g++.dg/pr71488.C
> index a89e6465a94..ffe30f1afeb 100644
> --- a/gcc/testsuite/g++.dg/pr71488.C
> +++ b/gcc/testsuite/g++.dg/pr71488.C
> @@ -3,7 +3,6 @@
>  // { dg-options "-O3 -std=c++11" }
>  // { dg-additional-options "-msse4" { target sse4_runtime } }
>  // { dg-require-effective-target c++11 }
> -// { dg-bogus "size 0 overflows" "pr107561" { xfail *-*-* } 0 }
>  
>  #include <valarray>
>  
> diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C b/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C
> index 49d3437fa1b..89cbadb91c7 100644
> --- a/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C
> +++ b/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C
> @@ -20,7 +20,6 @@ struct S
>  
>      for (int i = 0; i < m; i++)
>        new (p + i) int (); /* { dg-bogus "bounds" "pr102690" { xfail *-*-* } } */
> -    // { dg-bogus "size 0 overflows" "pr107561" { xfail ilp32 } .-1 }
>    }
>  };
>  
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] tree-optimization/107561 - reduce -Wstringop-overflow false positives
@ 2023-03-29 12:11 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2023-03-29 12:11 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

The following tells pointer-query to prefer a zero size when we
are querying for the size range for a write into an object we've
determined is of zero size.  That avoids diagnostics about really
varying size arguments that just get a meaningful range for example
because they are multiplied by an element size.

I've adjusted only one call to get_size_range since that's what
I have a testcase for.  I think this is the most sensible
"workaround" for some of the false positives we see.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

OK if it succeeds?

Thanks,
Richard.

	PR tree-optimization/107561
	* gimple-ssa-warn-access.cc (get_size_range): Add flags
	argument and pass it on.
	(check_access): When querying for the size range pass
	SR_ALLOW_ZERO when the known destination size is zero.

	* g++.dg/pr71488.C: Remove XFAILed bogus diagnostic again.
	* g++.dg/warn/Warray-bounds-16.C: Likewise.
---
 gcc/gimple-ssa-warn-access.cc                | 19 +++++++++++++------
 gcc/testsuite/g++.dg/pr71488.C               |  1 -
 gcc/testsuite/g++.dg/warn/Warray-bounds-16.C |  1 -
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index 88d44690ade..b3de4b77924 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -1198,10 +1198,10 @@ warn_for_access (location_t loc, tree func, tree expr, int opt,
 
 static void
 get_size_range (range_query *query, tree bound, gimple *stmt, tree range[2],
-		const offset_int bndrng[2])
+		int flags, const offset_int bndrng[2])
 {
   if (bound)
-    get_size_range (query, bound, stmt, range);
+    get_size_range (query, bound, stmt, range, flags);
 
   if (!bndrng || (bndrng[0] == 0 && bndrng[1] == HOST_WIDE_INT_M1U))
     return;
@@ -1347,7 +1347,12 @@ check_access (GimpleOrTree exp, tree dstwrite,
   /* Set RANGE to that of DSTWRITE if non-null, bounded by PAD->DST_BNDRNG
      if valid.  */
   gimple *stmt = pad ? pad->stmt : nullptr;
-  get_size_range (rvals, dstwrite, stmt, range, pad ? pad->dst_bndrng : NULL);
+  get_size_range (rvals, dstwrite, stmt, range,
+		  /* If the destination has known zero size prefer a zero
+		     size range to avoid false positives if that's a
+		     possibility.  */
+		  integer_zerop (dstsize) ? SR_ALLOW_ZERO : 0,
+		  pad ? pad->dst_bndrng : NULL);
 
   tree func = get_callee_fndecl (exp);
   /* Read vs write access by built-ins can be determined from the const
@@ -1442,7 +1447,8 @@ check_access (GimpleOrTree exp, tree dstwrite,
     {
       /* Set RANGE to that of MAXREAD, bounded by PAD->SRC_BNDRNG if
 	 PAD is nonnull and BNDRNG is valid.  */
-      get_size_range (rvals, maxread, stmt, range, pad ? pad->src_bndrng : NULL);
+      get_size_range (rvals, maxread, stmt, range, 0,
+		      pad ? pad->src_bndrng : NULL);
 
       location_t loc = get_location (exp);
       tree size = dstsize;
@@ -1489,7 +1495,8 @@ check_access (GimpleOrTree exp, tree dstwrite,
     {
       /* Set RANGE to that of MAXREAD, bounded by PAD->SRC_BNDRNG if
 	 PAD is nonnull and BNDRNG is valid.  */
-      get_size_range (rvals, maxread, stmt, range, pad ? pad->src_bndrng : NULL);
+      get_size_range (rvals, maxread, stmt, range, 0,
+		      pad ? pad->src_bndrng : NULL);
       /* Set OVERREAD for reads starting just past the end of an object.  */
       overread = pad->src.sizrng[1] - pad->src.offrng[0] < pad->src_bndrng[0];
       range[0] = wide_int_to_tree (sizetype, pad->src_bndrng[0]);
@@ -2679,7 +2686,7 @@ pass_waccess::check_strncmp (gcall *stmt)
   /* Determine the range of the bound first and bail if it fails; it's
      cheaper than computing the size of the objects.  */
   tree bndrng[2] = { NULL_TREE, NULL_TREE };
-  get_size_range (m_ptr_qry.rvals, bound, stmt, bndrng, adata1.src_bndrng);
+  get_size_range (m_ptr_qry.rvals, bound, stmt, bndrng, 0, adata1.src_bndrng);
   if (!bndrng[0] || integer_zerop (bndrng[0]))
     return;
 
diff --git a/gcc/testsuite/g++.dg/pr71488.C b/gcc/testsuite/g++.dg/pr71488.C
index a89e6465a94..ffe30f1afeb 100644
--- a/gcc/testsuite/g++.dg/pr71488.C
+++ b/gcc/testsuite/g++.dg/pr71488.C
@@ -3,7 +3,6 @@
 // { dg-options "-O3 -std=c++11" }
 // { dg-additional-options "-msse4" { target sse4_runtime } }
 // { dg-require-effective-target c++11 }
-// { dg-bogus "size 0 overflows" "pr107561" { xfail *-*-* } 0 }
 
 #include <valarray>
 
diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C b/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C
index 49d3437fa1b..89cbadb91c7 100644
--- a/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C
+++ b/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C
@@ -20,7 +20,6 @@ struct S
 
     for (int i = 0; i < m; i++)
       new (p + i) int (); /* { dg-bogus "bounds" "pr102690" { xfail *-*-* } } */
-    // { dg-bogus "size 0 overflows" "pr107561" { xfail ilp32 } .-1 }
   }
 };
 
-- 
2.35.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-31 14:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20230329121203.002E43858434@sourceware.org>
2023-03-31 14:13 ` [PATCH] tree-optimization/107561 - reduce -Wstringop-overflow false positives Jeff Law
2023-03-30 11:16 Richard Biener
  -- strict thread matches above, loose matches on Subject: below --
2023-03-29 12:11 Richard Biener

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).