https://gcc.gnu.org/g:0183d3736acc311cf489d66e42a3bd84cab261d3

commit r17-6310-g0183d3736acc311cf489d66e42a3bd84cab261d3
Author: Josef Melcr <[email protected]>
Date:   Mon Nov 16 13:03:56 2026 +0100

    ipa: Fix modified initialization in build_new_function_type [PR128602]
    
    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]>

Diff:
---
 gcc/ipa-param-manipulation.cc       |  3 ++-
 gcc/testsuite/gcc.dg/ipa/pr128602.c | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-param-manipulation.cc b/gcc/ipa-param-manipulation.cc
index fd70274e9b89..887140c28040 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 000000000000..556f3ebfdd54
--- /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 } } */

Reply via email to