tree-optimization/93661 properly guard tree_to_poly_int64
diff mbox series

Message ID nycvar.YFH.7.76.2002111051400.18835@zhemvz.fhfr.qr
State New
Headers show
Series
  • tree-optimization/93661 properly guard tree_to_poly_int64
Related show

Commit Message

Richard Biener Feb. 11, 2020, 9:52 a.m. UTC
Bootstrapped / tested on x86_64-unknown-linux-gnu, pushed.

Richard.

2020-02-11  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/93661
	PR tree-optimization/93662
	* tree-ssa-sccvn.c (vn_reference_lookup_3): Properly guard
	tree_to_poly_int64.
	* tree-sra.c (get_access_for_expr): Likewise.

	* gcc.dg/pr93661.c: New testcase.
---
 gcc/testsuite/gcc.dg/pr93661.c | 9 +++++++++
 gcc/tree-sra.c                 | 6 ++++--
 gcc/tree-ssa-sccvn.c           | 1 +
 3 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr93661.c

Comments

Hans-Peter Nilsson Feb. 14, 2020, 1:04 a.m. UTC | #1
On Tue, 11 Feb 2020, Richard Biener wrote:
> Bootstrapped / tested on x86_64-unknown-linux-gnu, pushed.

> diff --git a/gcc/testsuite/gcc.dg/pr93661.c b/gcc/testsuite/gcc.dg/pr93661.c
> new file mode 100644
> index 00000000000..e311ba545c4
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr93661.c
> @@ -0,0 +1,9 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */

Missing int32plus qualifier considering the assumed-to-fit
constants?

> +
> +int f ()
> +{
> +  unsigned x = 0xffffffff;
> +  __builtin_memset (1+(char *) &x, 0, -1); /* { dg-warning "maximum object size" } */
> +  return (x != 0xf0000000);

brgds, H-P
PS. no, doesn't fail for targets I care for, just random.

Patch
diff mbox series

diff --git a/gcc/testsuite/gcc.dg/pr93661.c b/gcc/testsuite/gcc.dg/pr93661.c
new file mode 100644
index 00000000000..e311ba545c4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr93661.c
@@ -0,0 +1,9 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int f ()
+{
+  unsigned x = 0xffffffff;
+  __builtin_memset (1+(char *) &x, 0, -1); /* { dg-warning "maximum object size" } */
+  return (x != 0xf0000000);
+}
diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c
index ea8594db193..f03ad3a586f 100644
--- a/gcc/tree-sra.c
+++ b/gcc/tree-sra.c
@@ -3605,8 +3605,10 @@  get_access_for_expr (tree expr)
 
   if (tree basesize = DECL_SIZE (base))
     {
-      poly_int64 sz = tree_to_poly_int64 (basesize);
-      if (offset < 0 || known_le (sz, offset))
+      poly_int64 sz;
+      if (offset < 0
+	  || !poly_int_tree_p (basesize, &sz)
+	  || known_le (sz, offset))
 	return NULL;
     }
 
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index b42a30ed3fc..15cc567f8fd 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -2527,6 +2527,7 @@  vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
       /* For now handle clearing memory with partial defs.  */
       else if (known_eq (ref->size, maxsize)
 	       && integer_zerop (gimple_call_arg (def_stmt, 1))
+	       && tree_fits_poly_int64_p (len)
 	       && tree_to_poly_int64 (len).is_constant (&leni)
 	       && offset.is_constant (&offseti)
 	       && offset2.is_constant (&offset2i)