When querying dominators for cache values, ignore back edges in
read-only mode.
PR tree-optimization/109238
gcc/
* gimple-range-cache.cc (ranger_cache::resolve_dom): Ignore
predecessors which this block dominates.
gcc/testsuite/
* gcc.dg/pr109238.c: New.
Value_Range er (TREE_TYPE (name));
FOR_EACH_EDGE (e, ei, bb->preds)
{
+ // If the predecessor is dominated by this block, then there is a back
+ // edge, and won't provide anything useful. We'll actually end up with
+ // VARYING as we will not resolve this node.
+ if (dominated_by_p (CDI_DOMINATORS, e->src, bb))
+ continue;
edge_range (er, e, name, RFD_READ_ONLY);
r.union_ (er);
}
--- /dev/null
+/* PR tree-optimization/109238 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall" } */
+
+void foo (void *) __attribute__((noreturn));
+void bar (void *);
+
+void
+baz (void *p)
+{
+ void *c = __builtin_realloc (p, 16);
+ if (c)
+ foo (c);
+ for (;;)
+ bar (__builtin_realloc (p, 8)); /* { dg-bogus "pointer 'p' may be used after '__builtin_realloc'" } */
+}