Hi, this patch fixes miscompilation of gnatmake. Modref attempts to track memory accesses relative to the base pointers which are parameters of functions. If it fails, it still makes difference between unknown memory access and global memory access. The second makes it possible to disambiguate with memory that is not accessible from outside world (i.e. everything that does not escape from the caller function). This is useful so we do not punt when unknown function is called.
Now I added ref_may_access_global_memory_p to tree-ssa-alias whic is using ptr_deref_may_alias_global_p. There is however a shift in meaning of this predicate: the second tests that the dereference may alias with global variable. In the testcase we are disambiguating heap allocated escaping memory which is not a global variable but it is still a global memory in the modref's sense. So we need to test in addition contains_escaped. The patch simply copies logic from the predicate and adds the check. I am not sure if there is better way to handle this? I apologize for taking so long time to look into the PR (and other my bugs). Will try to handle them quickly now. Bootstrapped/regtested x86_64-linux. Honza gcc/ChangeLog: 2022-04-07 Jan Hubicka <hubi...@ucw.cz> PR 104303 * tree-ssa-alias.cc (ref_may_access_global_memory_p): Fix handling of refs. diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc index 50bd47b31f3..9e34f76c3cb 100644 --- a/gcc/tree-ssa-alias.cc +++ b/gcc/tree-ssa-alias.cc @@ -2578,8 +2578,24 @@ ref_may_access_global_memory_p (ao_ref *ref) if (TREE_CODE (base) == MEM_REF || TREE_CODE (base) == TARGET_MEM_REF) { - if (ptr_deref_may_alias_global_p (TREE_OPERAND (base, 0))) + struct ptr_info_def *pi; + tree ptr = TREE_OPERAND (base, 0); + + /* If we end up with a pointer constant here that may point + to global memory. */ + if (TREE_CODE (ptr) != SSA_NAME) + return true; + + pi = SSA_NAME_PTR_INFO (ptr); + + /* If we do not have points-to information for this variable, + we have to punt. */ + if (!pi) return true; + + /* ??? This does not use TBAA to prune globals ptr may not access. */ + return pt_solution_includes_global (&pi->pt) + || pi->pt.vars_contains_escaped; } else {