public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix wrong code in gnatmake
@ 2022-04-07 11:26 Jan Hubicka
  2022-04-07 12:25 ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Hubicka @ 2022-04-07 11:26 UTC (permalink / raw)
  To: gcc-patches, rguenther

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  <hubicka@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
     {

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-04-12 15:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 11:26 Fix wrong code in gnatmake Jan Hubicka
2022-04-07 12:25 ` Richard Biener
2022-04-07 12:58   ` Jan Hubicka
2022-04-07 13:04     ` Richard Biener
2022-04-12 13:11       ` Thomas Schwinge
2022-04-12 13:45         ` Richard Biener
2022-04-12 15:07           ` Thomas Schwinge
2022-04-12 15:51             ` Richard Biener

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