#include "tree-into-ssa.h"
#include "symtab-clones.h"
#include "gimple-range.h"
+#include "tree-dfa.h"
/* Summaries. */
fast_function_summary <ipa_fn_summary *, va_gc> *ipa_fn_summaries;
if (integer_zerop (t))
return flag_delete_null_pointer_checks;
if (TREE_CODE (t) == SSA_NAME)
- return !ptr_deref_may_alias_global_p (t);
+ {
+ /* For IPA passes we can consinder accesses to return slot local
+ even if it is not local in the sense that memory is dead by
+ the end of founction.
+ The outer function will see a store in the call assignment
+ and thus this will do right thing for all uses of this
+ function in the current IPA passes (modref, pure/const discovery
+ and inlining heuristics). */
+ if (DECL_RESULT (current_function_decl)
+ && DECL_BY_REFERENCE (DECL_RESULT (current_function_decl))
+ && t == ssa_default_def (cfun, DECL_RESULT (current_function_decl)))
+ return true;
+ return !ptr_deref_may_alias_global_p (t);
+ }
if (TREE_CODE (t) == ADDR_EXPR)
return refs_local_or_readonly_memory_p (TREE_OPERAND (t, 0));
return false;
We do not track memory locations, so assume that value
is used arbitrarily. */
if (memory_access_to (gimple_assign_rhs1 (assign), name))
- lattice[index].merge (0);
+ lattice[index].merge (deref_flags (0, false));
/* Handle *name = *exp. */
else if (memory_access_to (gimple_assign_lhs (assign), name))
lattice[index].merge_direct_store ();
--- /dev/null
+/* { dg-do link } */
+/* { dg-options "-O2 -fdump-tree-local-pure-const1 -fdump-tree-modref1 -std=gnu++2a" } */
+namespace {
+struct B {
+ int b;
+ struct B *bptr;
+ B() {b=1; }
+ B(B &src)
+ {
+ b=src.b;
+ bptr=0;
+ }
+ __attribute__ ((noinline))
+ static struct B genB()
+ {
+ struct B b;
+ b.b=2;
+ b.bptr = 0;
+ return b;
+ }
+};
+}
+void linker_error ();
+int main()
+{
+ struct B b1 = B::genB();
+ b1.b = 1;
+ struct B b2 = B::genB();
+ if (b1.b != 1 || b2.bptr == &b2)
+ linker_error ();
+ return 0;
+}
+/* { dg-final { scan-ipa-dump "Function found to be const: {anonymous}::B::genB" "local-pure-const1" } } */
+/* { dg-final { scan-ipa-dump "Retslot flags: direct noescape nodirectescape not_returned noread" "modref1" } } */
+