https://gcc.gnu.org/g:00e5d96cb4ca1a17666a823cec041b9729960e18

commit r17-6374-g00e5d96cb4ca1a17666a823cec041b9729960e18
Author: Andrea Pinski <[email protected]>
Date:   Tue Nov 17 14:05:15 2026 -0800

    range-op: Fix operator_pointer_diff's op1_op2_relation when rhs1 is 
undefined [PR128759]
    
    I had missed that rhs1 could be undefined and then getting
    the type of it would cause an ICE. Note this is unlike operator_minus's
    op1_op2_relation which uses overflow_free and overflow_free has the
    check there.
    
    Committed the fix as obvious after a bootstrap/test on x86_64-linux-gnu.
    
            PR tree-optimization/128759
    
    gcc/ChangeLog:
    
            * range-op-ptr.cc (operator_pointer_diff::op1_op2_relation): Fix
            rhs1 being undefined.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/torture/pr128759-1.c: New test.
    
    Signed-off-by: Andrea Pinski <[email protected]>

Diff:
---
 gcc/range-op-ptr.cc                       |  3 ++-
 gcc/testsuite/gcc.dg/torture/pr128759-1.c | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc
index d58769b59d42..687974d5cb89 100644
--- a/gcc/range-op-ptr.cc
+++ b/gcc/range-op-ptr.cc
@@ -542,7 +542,8 @@ operator_pointer_diff::op1_op2_relation (const irange &lhs, 
const prange &rhs1,
   // When a - b does not overflow and signed,
   // we can figure out the relationship between
   // a and b if the result is non-negative or non-positive.
-  if (TYPE_OVERFLOW_UNDEFINED (rhs1.type ()))
+  if (!rhs1.undefined_p ()
+      && TYPE_OVERFLOW_UNDEFINED (rhs1.type ()))
     {
       if (lhs.nonnegative_p ())
        return contains_z ? VREL_GE : VREL_GT;
diff --git a/gcc/testsuite/gcc.dg/torture/pr128759-1.c 
b/gcc/testsuite/gcc.dg/torture/pr128759-1.c
new file mode 100644
index 000000000000..0a20edf8e4f2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr128759-1.c
@@ -0,0 +1,10 @@
+int b, c;
+void k() {
+  int * ak;
+  int * al;
+  b = al - ak;
+  if (b)
+  {
+    bool d = ak == al;
+  }
+}

Reply via email to