public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] IPA: MODREF should skip EAF_* flags for indirect calls
@ 2021-08-20 14:27 Martin Liška
  2021-08-21  9:35 ` Martin Jambor
  2021-08-22 12:38 ` Jan Hubicka
  0 siblings, 2 replies; 11+ messages in thread
From: Martin Liška @ 2021-08-20 14:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Biener, Jan Hubicka

Hello.

As showed in the PR, returning (EAF_NOCLOBBER | EAF_NOESCAPE) for an argument
that is a function pointer is problematic. Doing such a function call is a clobber.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

	PR 101949

gcc/ChangeLog:

	* ipa-modref.c (analyze_ssa_name_flags): Do not propagate EAF
	  flags arguments for indirect functions.

gcc/testsuite/ChangeLog:

	* gcc.dg/lto/pr101949_0.c: New test.
	* gcc.dg/lto/pr101949_1.c: New test.

Co-Authored-By: Richard Biener <rguenther@suse.de>
---
  gcc/ipa-modref.c                      |  3 +++
  gcc/testsuite/gcc.dg/lto/pr101949_0.c | 20 ++++++++++++++++++++
  gcc/testsuite/gcc.dg/lto/pr101949_1.c |  4 ++++
  3 files changed, 27 insertions(+)
  create mode 100644 gcc/testsuite/gcc.dg/lto/pr101949_0.c
  create mode 100644 gcc/testsuite/gcc.dg/lto/pr101949_1.c

diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
index fafd804d4ba..380ba6926b9 100644
--- a/gcc/ipa-modref.c
+++ b/gcc/ipa-modref.c
@@ -1715,6 +1715,9 @@ analyze_ssa_name_flags (tree name, vec<modref_lattice> &lattice, int depth,
  	  else if (callee && !ipa && recursive_call_p (current_function_decl,
  						  callee))
  	    lattice[index].merge (0);
+	  /* Ignore indirect calls (PR101949).  */
+	  else if (callee == NULL_TREE)
+	    lattice[index].merge (0);
  	  else
  	    {
  	      int ecf_flags = gimple_call_flags (call);
diff --git a/gcc/testsuite/gcc.dg/lto/pr101949_0.c b/gcc/testsuite/gcc.dg/lto/pr101949_0.c
new file mode 100644
index 00000000000..142dffe8780
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr101949_0.c
@@ -0,0 +1,20 @@
+/* { dg-lto-do run } */
+/* { dg-lto-options { "-O2 -fipa-pta -flto -flto-partition=1to1" } } */
+
+extern int bar (int (*)(int *), int *);
+
+static int x;
+
+static int __attribute__ ((noinline)) foo (int *p)
+{
+  *p = 1;
+  x = 0;
+  return *p;
+}
+
+int main ()
+{
+  if (bar (foo, &x) != 0)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/lto/pr101949_1.c b/gcc/testsuite/gcc.dg/lto/pr101949_1.c
new file mode 100644
index 00000000000..871d15c9bfb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr101949_1.c
@@ -0,0 +1,4 @@
+int __attribute__((noinline,noclone)) bar (int (*fn)(int *), int *p)
+{
+  return fn (p);
+}
-- 
2.32.0


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

end of thread, other threads:[~2021-08-23 12:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20 14:27 [PATCH] IPA: MODREF should skip EAF_* flags for indirect calls Martin Liška
2021-08-21  9:35 ` Martin Jambor
2021-08-22 12:38 ` Jan Hubicka
2021-08-22 17:32   ` Jan Hubicka
2021-08-22 21:46     ` H.J. Lu
2021-08-23  8:11       ` Christophe Lyon
2021-08-23  7:53     ` Martin Liška
2021-08-23  9:06       ` Jan Hubicka
2021-08-23  9:43     ` Richard Biener
2021-08-23 12:02       ` Jan Hubicka
2021-08-23 12:42         ` 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).