public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-842] Bail in bounds_of_var_in_loop if scev returns NULL.
@ 2021-05-17 16:19 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2021-05-17 16:19 UTC (permalink / raw)
  To: gcc-cvs

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

commit r12-842-gce81282261c6c77883b17d0ebfbbe337bed76457
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Thu May 13 16:09:58 2021 -0400

    Bail in bounds_of_var_in_loop if scev returns NULL.
    
    Both initial_condition_in_loop_num and evolution_part_in_loop_num
    can return NULL.  This patch exits if either one is NULL.  Presumably
    this didn't happen before, because adjust_range_with_scev was called
    far less frequently than in ranger, which can call it for every PHI.
    
    gcc/ChangeLog:
    
            PR tree-optimization/100349
            * vr-values.c (bounds_of_var_in_loop): Bail if scev returns
              NULL.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/pr100349.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/pr100349.c | 16 ++++++++++++++++
 gcc/vr-values.c                 |  3 +++
 2 files changed, 19 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/pr100349.c b/gcc/testsuite/gcc.dg/pr100349.c
new file mode 100644
index 00000000000..dd7977ac0f9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr100349.c
@@ -0,0 +1,16 @@
+// { dg-do compile }
+// { dg-options "-O2 -w" }
+
+#include <stdint.h>
+uint8_t a;
+b(int8_t c) {
+  int d;
+e:
+  uint32_t f;
+  for (;;)
+    for (c = 10; c; c++)
+      if (0 > (a = c) ?: d) {
+        f = a;
+        goto e;
+      }
+}
diff --git a/gcc/vr-values.c b/gcc/vr-values.c
index 08b237b2632..b1bf53af9e0 100644
--- a/gcc/vr-values.c
+++ b/gcc/vr-values.c
@@ -1650,6 +1650,9 @@ bounds_of_var_in_loop (tree *min, tree *max, range_query *query,
   init = initial_condition_in_loop_num (chrec, loop->num);
   step = evolution_part_in_loop_num (chrec, loop->num);
 
+  if (!init || !step)
+    return false;
+
   /* If INIT is an SSA with a singleton range, set INIT to said
      singleton, otherwise leave INIT alone.  */
   if (TREE_CODE (init) == SSA_NAME)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-17 16:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 16:19 [gcc r12-842] Bail in bounds_of_var_in_loop if scev returns NULL Aldy Hernandez

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