From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id AE237385801D; Tue, 24 Aug 2021 07:29:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE237385801D Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/backport-11)] Clear EAF_NOCLOBBER for indirect calls X-Act-Checkin: gcc X-Git-Author: Jan Hubicka X-Git-Refname: refs/users/marxin/heads/backport-11 X-Git-Oldrev: c62cf32d051fcbb403e82000207ede6a91dc26e8 X-Git-Newrev: 25005a033794d66ef01504ddbb740bf53ae7b2f6 Message-Id: <20210824072953.AE237385801D@sourceware.org> Date: Tue, 24 Aug 2021 07:29:53 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Aug 2021 07:29:53 -0000 https://gcc.gnu.org/g:25005a033794d66ef01504ddbb740bf53ae7b2f6 commit 25005a033794d66ef01504ddbb740bf53ae7b2f6 Author: Jan Hubicka Date: Sun Aug 22 20:57:19 2021 +0200 Clear EAF_NOCLOBBER for indirect calls gcc/ChangeLog: 2021-08-22 Jan Hubicka Martin Liska PR middle-end/101949 * ipa-modref.c (analyze_ssa_name_flags): Indirect call implies ~EAF_NOCLOBBER. gcc/testsuite/ChangeLog: 2021-08-22 Jan Hubicka Martin Liska * gcc.dg/lto/pr101949_0.c: New test. * gcc.dg/lto/pr101949_1.c: New test. (cherry picked from commit 9b08f7764cecd16cba84944f2a8b67a7f73a7ce7) Diff: --- gcc/ipa-modref.c | 9 +++++++++ gcc/testsuite/gcc.dg/lto/pr101949_0.c | 20 ++++++++++++++++++++ gcc/testsuite/gcc.dg/lto/pr101949_1.c | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c index ef5e62beb0e..dc5ee8cc2d0 100644 --- a/gcc/ipa-modref.c +++ b/gcc/ipa-modref.c @@ -1621,6 +1621,15 @@ analyze_ssa_name_flags (tree name, vec &lattice, int depth, else if (gcall *call = dyn_cast (use_stmt)) { tree callee = gimple_call_fndecl (call); + + /* IPA PTA internally it treats calling a function as "writing" to + the argument space of all functions the function pointer points to + (PR101949). We can not drop EAF_NOCLOBBER only when ipa-pta + is on since that would allow propagation of this from -fno-ipa-pta + to -fipa-pta functions. */ + if (gimple_call_fn (use_stmt) == name) + lattice[index].merge (~EAF_NOCLOBBER); + /* Return slot optimization would require bit of propagation; give up for now. */ if (gimple_call_return_slot_opt_p (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); +}