From 34284ac3d50238e30e090912c0de6fd53a867e7b Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 20 Jan 2017 13:09:22 +0100 Subject: [PATCH] Reload global options when strict aliasing is dropped (PR ipa/79043). 2017-01-20 Martin Liska Backport from mainline 2017-01-13 Martin Liska PR ipa/79043 * function.c (set_cfun): Add new argument force. * function.h (set_cfun): Likewise. * ipa-inline-transform.c (inline_call): Use the function when strict alising from is dropped for function we inline to. 2017-01-20 Martin Liska Backport from mainline 2017-01-13 Martin Liska PR ipa/79043 * gcc.c-torture/execute/pr79043.c: New test. From-SVN: r244709 --- gcc/ChangeLog | 11 ++++++++++ gcc/function.c | 4 ++-- gcc/function.h | 2 +- gcc/ipa-inline-transform.c | 7 +++++++ gcc/testsuite/ChangeLog | 8 +++++++ gcc/testsuite/gcc.c-torture/execute/pr79043.c | 21 +++++++++++++++++++ 6 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr79043.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 065ba81ef14c..b652f23dbadc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2017-01-20 Martin Liska + + Backport from mainline + 2017-01-13 Martin Liska + + PR ipa/79043 + * function.c (set_cfun): Add new argument force. + * function.h (set_cfun): Likewise. + * ipa-inline-transform.c (inline_call): Use the function when + strict alising from is dropped for function we inline to. + 2017-01-20 Martin Liska Backport from mainline diff --git a/gcc/function.c b/gcc/function.c index 5059cdf634b2..8b640584b0b7 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -4688,9 +4688,9 @@ invoke_set_current_function_hook (tree fndecl) /* cfun should never be set directly; use this function. */ void -set_cfun (struct function *new_cfun) +set_cfun (struct function *new_cfun, bool force) { - if (cfun != new_cfun) + if (cfun != new_cfun || force) { cfun = new_cfun; invoke_set_current_function_hook (new_cfun ? new_cfun->decl : NULL_TREE); diff --git a/gcc/function.h b/gcc/function.h index b89c5aeefb67..bfa6f80caeec 100644 --- a/gcc/function.h +++ b/gcc/function.h @@ -891,7 +891,7 @@ extern tree block_chainon (tree, tree); extern void number_blocks (tree); /* cfun shouldn't be set directly; use one of these functions instead. */ -extern void set_cfun (struct function *new_cfun); +extern void set_cfun (struct function *new_cfun, bool force = false); extern void push_cfun (struct function *new_cfun); extern void pop_cfun (void); diff --git a/gcc/ipa-inline-transform.c b/gcc/ipa-inline-transform.c index c56ada49c98d..855d2231c650 100644 --- a/gcc/ipa-inline-transform.c +++ b/gcc/ipa-inline-transform.c @@ -341,6 +341,8 @@ inline_call (struct cgraph_edge *e, bool update_original, if (DECL_FUNCTION_PERSONALITY (callee->decl)) DECL_FUNCTION_PERSONALITY (to->decl) = DECL_FUNCTION_PERSONALITY (callee->decl); + + bool reload_optimization_node = false; if (!opt_for_fn (callee->decl, flag_strict_aliasing) && opt_for_fn (to->decl, flag_strict_aliasing)) { @@ -354,8 +356,13 @@ inline_call (struct cgraph_edge *e, bool update_original, build_optimization_node (&opts); DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl) = build_optimization_node (&opts); + reload_optimization_node = true; } + /* Reload global optimization flags. */ + if (reload_optimization_node && DECL_STRUCT_FUNCTION (to->decl) == cfun) + set_cfun (cfun, true); + /* If aliases are involved, redirect edge to the actual destination and possibly remove the aliases. */ if (e->callee != callee) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 975a1e574224..26dc594ecd2b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2017-01-20 Martin Liska + + Backport from mainline + 2017-01-13 Martin Liska + + PR ipa/79043 + * gcc.c-torture/execute/pr79043.c: New test. + 2017-01-20 Martin Liska Backport from mainline diff --git a/gcc/testsuite/gcc.c-torture/execute/pr79043.c b/gcc/testsuite/gcc.c-torture/execute/pr79043.c new file mode 100644 index 000000000000..b7fcc8260dc3 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr79043.c @@ -0,0 +1,21 @@ +/* PR ipa/78791 */ + +int val; + +int *ptr = &val; +float *ptr2 = &val; + +static +__attribute__((always_inline, optimize ("-fno-strict-aliasing"))) +typepun () +{ + *ptr2=0; +} + +main() +{ + *ptr=1; + typepun (); + if (*ptr) + __builtin_abort (); +} -- 2.47.2