]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ipa-cp: Always return the right type in ipa_value_from_jfunc (PR123542)
authorMartin Jambor <mjambor@suse.cz>
Wed, 14 Jan 2026 19:41:57 +0000 (20:41 +0100)
committerMartin Jambor <jamborm@gcc.gnu.org>
Wed, 14 Jan 2026 19:42:58 +0000 (20:42 +0100)
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  <mjambor@suse.cz>

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  <mjambor@suse.cz>

PR ipa/123542
* gcc.dg/ipa/pr123542.c: New test.

gcc/ipa-cp.cc
gcc/testsuite/gcc.dg/ipa/pr123542.c [new file with mode: 0644]

index 9f61f682d58ea9fbef1c7e29c8fc1578a56d80c7..8e2aafc7923e16977147389b56e261279dbfff55 100644 (file)
@@ -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 (file)
index 0000000..76af651
--- /dev/null
@@ -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); }