Hi,
this patch adjusts the check for modified in
ipa_param_adjustments::build_new_function_type to account for cases
where m_adj_params == NULL. That case means that we are removing all
parameters for the new function, but the guard for m_adj_params would
prevent us from setting modified to TRUE, although the removal of
parameters is clearly a modification. This is a problem for the
callback_only attribute in PR128602, but it could also show up for the
access or `fn spec` attribute as well, as their removal is also
dependent on this flag.
Bootstrapped and regtested on x86_64-linux without regressions. OK for
master?
Best regards,
Josef
-- >8 --
The detection of the modified flag in
ipa_param_adjustments::build_new_function_type would run only if
the param adjustments vector wasn't NULL. Since m_adj_params == NULL
means remove all parameters, the flag would be set to false, even though
the removal of all parameters is a modification. Attribute removal
depends on this flag and since it would be set to false, no attributes
would be removed, leading to issues such as in PR128602. This patch
adjusts the check to account for NULL m_adj_params as well.
PR ipa/128602
gcc/ChangeLog:
* ipa-param-manipulation.cc (build_new_function_type): Adjust
check for modified to handle m_adj_params == NULL.
gcc/testsuite/ChangeLog:
* gcc.dg/ipa/pr128602.c: New test.
Signed-off-by: Josef Melcr <[email protected]>
---
gcc/ipa-param-manipulation.cc | 13 ++++++-------
gcc/testsuite/gcc.dg/ipa/pr128602.c | 26 ++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 7 deletions(-)
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..ca73b15ef61 100644
--- a/gcc/ipa-param-manipulation.cc
+++ b/gcc/ipa-param-manipulation.cc
@@ -524,13 +524,12 @@ ipa_param_adjustments::build_new_function_type (
need to drop some type attributes. */
bool modified = false;
size_t index = 0;
- if (m_adj_params)
- for (tree t = TYPE_ARG_TYPES (old_type);
- t && (int)index < m_always_copy_start && !modified;
- t = TREE_CHAIN (t), index++)
- if (index >= m_adj_params->length ()
- || get_original_index (index) != (int)index)
- modified = true;
+ size_t length = vec_safe_length (m_adj_params);
+ for (tree t = TYPE_ARG_TYPES (old_type);
+ t && (int) index < m_always_copy_start && !modified;
+ t = TREE_CHAIN (t), index++)
+ if (index >= length || get_original_index (index) != (int) index)
+ modified = true;
if (args_modified)
*args_modified = modified;
diff --git a/gcc/testsuite/gcc.dg/ipa/pr128602.c
b/gcc/testsuite/gcc.dg/ipa/pr128602.c
new file mode 100644
index 00000000000..9bdf0a0d09b
--- /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