Hi,
this patch fixes the initialization of modified to fix PR128602.
Bootstrapped and regtested on x86_64-linux without regressions.

Pre-approved by Martin Jambor, committed.

Best regards,
Josef

-- >8 --

This patch changes the initialization of modified to better handle cases
when m_adj_params is NULL.  That case could mean that either the
function had parameters and they were all removed (and thus modified
should be TRUE), or that the function had no parameters to begin with
(and modified should be FALSE).  If the flag is set incorrectly, some
attributes may not be dropped when they were supposed to, leading to
issues such as in PR128602.  The new initialization takes both cases
into account.

        PR ipa/128602

gcc/ChangeLog:

        * ipa-param-manipulation.cc
        (ipa_param_adjustments::build_new_function_type): Fix initialization
        of modified.

gcc/testsuite/ChangeLog:

        * gcc.dg/ipa/pr128602.c: New test.

Signed-off-by: Josef Melcr <[email protected]>
---
 gcc/ipa-param-manipulation.cc       |  3 ++-
 gcc/testsuite/gcc.dg/ipa/pr128602.c | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/pr128602.c

diff --git a/gcc/ipa-param-manipulation.cc b/gcc/ipa-param-manipulation.cc
index fd70274e9b8..887140c2804 100644
--- a/gcc/ipa-param-manipulation.cc
+++ b/gcc/ipa-param-manipulation.cc
@@ -522,7 +522,8 @@ ipa_param_adjustments::build_new_function_type (
 
   /* Check if any params type cares about are modified.  In this case will
      need to drop some type attributes.  */
-  bool modified = false;
+  bool modified = m_adj_params == NULL && TYPE_ARG_TYPES (old_type)
+                 && m_always_copy_start > 0;
   size_t index = 0;
   if (m_adj_params)
     for (tree t = TYPE_ARG_TYPES (old_type);
diff --git a/gcc/testsuite/gcc.dg/ipa/pr128602.c 
b/gcc/testsuite/gcc.dg/ipa/pr128602.c
new file mode 100644
index 00000000000..d5e292454a7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr128602.c
@@ -0,0 +1,26 @@
+/* PR ipa/128602 */
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-ipa-cp-details" } */
+
+int counter;
+
+static void
+kernel (int k)
+{
+  for (int i = 0; i < k; i++)
+    counter += i;
+}
+
+__attribute__ ((noinline, callback_only (1, 2))) static void
+dispatch (void (*fn) (int), int k)
+{
+  fn (k);
+}
+
+void
+run (void)
+{
+  dispatch (kernel, 3);
+}
+
+/* { dg-final { scan-ipa-dump "no longer has any callback attributes" cp } } */
-- 
2.56.0

Reply via email to