https://gcc.gnu.org/g:946580776e85db57b914c0a883f455caaa59b92d

commit r16-6782-g946580776e85db57b914c0a883f455caaa59b92d
Author: Martin Jambor <[email protected]>
Date:   Wed Jan 14 20:41:57 2026 +0100

    ipa-cp: Always return the right type in ipa_value_from_jfunc (PR123542)
    
    PR 123542 is about triggering a checking assert that verifies that we
    indeed clone a function for the constant value we started evaluating.
    The issue is that we get a double 2 instead of a float 2 which comes
    down to function ipa_value_from_jfunc not doing the necessary
    conversion when dealing directly with constants (and ancestor jump
    functions but that is very unlikley to cause problems).
    
    This patch makes sure the required conversion is performed in all
    cases (even for the ancestor JFs) and checks that the result type is
    known, because when the function is invoked from ipa-modref.cc or
    ipa-fnsummary.cc that may not be the case.
    
    gcc/ChangeLog:
    
    2026-01-14  Martin Jambor  <[email protected]>
    
            PR ipa/123542
            * ipa-cp.cc (ipa_value_from_jfunc): Always use
            ipacp_value_safe_for_type.  Bail out if parm_type is NULL.
    
    gcc/testsuite/ChangeLog:
    
    2026-01-14  Martin Jambor  <[email protected]>
    
            PR ipa/123542
            * gcc.dg/ipa/pr123542.c: New test.

Diff:
---
 gcc/ipa-cp.cc                       | 10 ++++++----
 gcc/testsuite/gcc.dg/ipa/pr123542.c | 13 +++++++++++++
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index 9f61f682d58e..8e2aafc7923e 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -1627,8 +1627,10 @@ tree
 ipa_value_from_jfunc (class ipa_node_params *info, struct ipa_jump_func *jfunc,
                      tree parm_type)
 {
+  if (!parm_type)
+    return NULL_TREE;
   if (jfunc->type == IPA_JF_CONST)
-    return ipa_get_jf_constant (jfunc);
+    return ipacp_value_safe_for_type (parm_type, ipa_get_jf_constant (jfunc));
   else if (jfunc->type == IPA_JF_PASS_THROUGH
           || jfunc->type == IPA_JF_ANCESTOR)
     {
@@ -1660,8 +1662,6 @@ ipa_value_from_jfunc (class ipa_node_params *info, struct 
ipa_jump_func *jfunc,
 
       if (jfunc->type == IPA_JF_PASS_THROUGH)
        {
-         if (!parm_type)
-           return NULL_TREE;
          enum tree_code opcode = ipa_get_jf_pass_through_operation (jfunc);
          tree op2 = ipa_get_jf_pass_through_operand (jfunc);
          tree op_type
@@ -1671,7 +1671,9 @@ ipa_value_from_jfunc (class ipa_node_params *info, struct 
ipa_jump_func *jfunc,
          return ipacp_value_safe_for_type (parm_type, cstval);
        }
       else
-       return ipa_get_jf_ancestor_result (jfunc, input);
+       return ipacp_value_safe_for_type (parm_type,
+                                         ipa_get_jf_ancestor_result (jfunc,
+                                                                     input));
     }
   else
     return NULL_TREE;
diff --git a/gcc/testsuite/gcc.dg/ipa/pr123542.c 
b/gcc/testsuite/gcc.dg/ipa/pr123542.c
new file mode 100644
index 000000000000..76af651b7974
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr123542.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -std=gnu89" } */
+
+double cos(double);
+void sub(p1, p2, p3, p4, p5, p6) float p1, p2, p3, *p4, p5, p6;
+{
+  float ar2 = cos(*p4);
+  if (p2)
+    ar2 = 0.0;
+  for (;;)
+    *p4 += ar2;
+}
+void main() { sub(1.0, 2.0); }

Reply via email to