]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Do not fold ADDR_EXPR conditions leading to builtin_unreachable early.
authorAndrew MacLeod <amacleod@redhat.com>
Fri, 21 Apr 2023 19:03:43 +0000 (15:03 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Fri, 21 Apr 2023 20:34:05 +0000 (16:34 -0400)
Ranges can not represent &var globally yet, so we cannot fold these
expressions early or we lose the __builtin_unreachable information.

PR tree-optimization/109546
gcc/
* tree-vrp.cc (remove_unreachable::remove_and_update_globals): Do
not fold conditions with ADDR_EXPR early.

gcc/testsuite/
* gcc.dg/pr109546.c: New.

gcc/testsuite/gcc.dg/pr109546.c [new file with mode: 0644]
gcc/tree-vrp.cc

diff --git a/gcc/testsuite/gcc.dg/pr109546.c b/gcc/testsuite/gcc.dg/pr109546.c
new file mode 100644 (file)
index 0000000..ba8af0f
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-tree-optimized" } */
+
+void foo(void);
+static int a, c;
+static int *b = &a;
+static int **d = &b;
+void assert_fail() __attribute__((__noreturn__));
+int main() {
+  int *e = *d;
+  if (e == &a || e == &c);
+  else {
+    __builtin_unreachable();
+  assert_fail();
+  }
+  if (e == &a || e == &c);
+  else
+    foo();
+}
+
+/* { dg-final { scan-tree-dump-not "assert_fail" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "foo" "optimized" } } */
+
+
index f4d484526c77453faeaab85daabf31204c5ee9a0..9b870640e238e5dcd747c9914584aa8ec36ca359 100644 (file)
@@ -150,7 +150,9 @@ remove_unreachable::remove_and_update_globals (bool final_p)
       // If this is already a constant condition, don't look either
       if (!lhs_p && !rhs_p)
        continue;
-
+      // Do not remove addresses early. ie if (x == &y)
+      if (!final_p && lhs_p && TREE_CODE (gimple_cond_rhs (s)) == ADDR_EXPR)
+       continue;
       bool dominate_exit_p = true;
       FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori (), e->src, name)
        {