static void
ipa_record_return_value_range_1 (cgraph_node *n, value_range val)
{
+ // Remove local invariant from return values.
+ if (is_a<prange> (val))
+ {
+ const prange &pr = as_a <prange> (val);
+ tree t = pr.pt_invariant ();
+ if (t && !is_gimple_ip_invariant (t))
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Could not record return range of %s:", n->dump_name ());
+ val.dump (dump_file);
+ fprintf (dump_file, "\n");
+ fprintf (dump_file, "Because uses non ipa invariant\n");
+ }
+ return;
+ }
+ }
if (!ipa_return_value_sum)
{
if (!ipa_vr_hash_table)
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* PR tree-optimization/125857 */
+
+/* Make sure we don't ICE when returning the address to a local variable
+ and using it in the other function. */
+int *a, **b = &a, c;
+int *d() {
+ int e, *f = &e;
+ for (; c; c++)
+ __builtin_abort();
+ if (!b)
+ __builtin_abort();
+ return f; /* { dg-warning "function may return address of local variable" } */
+}
+int main() { *b = d(); }