[gcc/devel/c++-coroutines] re PR tree-optimization/93156 (abused nonnull attribute evokes new segfault in gcc 10 since Nov 4 co

Iain D Sandoe iains@gcc.gnu.org
Fri Jan 17 11:04:00 GMT 2020


https://gcc.gnu.org/g:fb862fdfb53ecb189f8bd74b66de573a78045916

commit fb862fdfb53ecb189f8bd74b66de573a78045916
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Jan 7 11:05:14 2020 +0100

    re PR tree-optimization/93156 (abused nonnull attribute evokes new segfault in gcc 10 since Nov 4 commit, 0fb958ab8aa)
    
    	PR tree-optimization/93156
    	* tree-ssa-ccp.c (bit_value_binop): For x * x note that the second
    	least significant bit is always clear.
    
    	* gcc.dg/tree-ssa/pr93156.c: New test.
    
    From-SVN: r279951

Diff:
---
 gcc/ChangeLog                           |  6 +++++-
 gcc/testsuite/ChangeLog                 |  5 ++++-
 gcc/testsuite/gcc.dg/tree-ssa/pr93156.c | 23 +++++++++++++++++++++++
 gcc/tree-ssa-ccp.c                      | 11 +++++++++++
 4 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f90dc08..0ead18a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,4 +1,8 @@
-2019-01-07  Jakub Jelinek  <jakub@redhat.com>
+2020-01-07  Jakub Jelinek  <jakub@redhat.com>
+
+	PR tree-optimization/93156
+	* tree-ssa-ccp.c (bit_value_binop): For x * x note that the second
+	least significant bit is always clear.
 
 	PR tree-optimization/93118
 	* match.pd ((x >> c) << c -> x & (-1<<c)): Add nop_convert?.  Add new
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 403bc8a..b5c4bc0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,4 +1,7 @@
-2019-01-07  Jakub Jelinek  <jakub@redhat.com>
+2020-01-07  Jakub Jelinek  <jakub@redhat.com>
+
+	PR tree-optimization/93156
+	* gcc.dg/tree-ssa/pr93156.c: New test.
 
 	PR tree-optimization/93118
 	* gcc.dg/tree-ssa/pr93118.c: New test.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr93156.c b/gcc/testsuite/gcc.dg/tree-ssa/pr93156.c
new file mode 100644
index 0000000..b8c2af3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr93156.c
@@ -0,0 +1,23 @@
+/* PR tree-optimization/93156 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times "return 0;" 3 "optimized" } } */
+
+int
+foo (int x)
+{
+  return (x * x) & 2;
+}
+
+unsigned long long
+bar (unsigned long long x)
+{
+  return (x * x) & 2;
+}
+
+int
+baz (int x)
+{
+  x &= -2;
+  return (x * x) & 3;
+}
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index add3d3f..be6647d 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -1650,6 +1650,17 @@ bit_value_binop (enum tree_code code, tree type, tree rhs1, tree rhs2)
 		   TYPE_SIGN (TREE_TYPE (rhs2)), TYPE_PRECISION (TREE_TYPE (rhs2)),
 		   value_to_wide_int (r2val), r2val.mask);
 
+  /* (x * x) & 2 == 0.  */
+  if (code == MULT_EXPR && rhs1 == rhs2 && TYPE_PRECISION (type) > 1)
+    {
+      widest_int m = 2;
+      if (wi::sext (mask, TYPE_PRECISION (type)) != -1)
+	value = wi::bit_and_not (value, m);
+      else
+	value = 0;
+      mask = wi::bit_and_not (mask, m);
+    }
+
   if (wi::sext (mask, TYPE_PRECISION (type)) != -1)
     {
       val.lattice_val = CONSTANT;



More information about the Gcc-cvs mailing list