https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128952

            Bug ID: 128952
           Summary: [17 Regression] ICE in gimple_call_fntype /
                    ipa_get_callee_param_type during IPA inline in
                    g++.dg/lto/pr68057 after r17-6339-g610d42e09ff
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: danglin at gcc dot gnu.org
                CC: hubicka at gcc dot gnu.org
  Target Milestone: ---
              Host: hppa64-hp-hpux11.11
            Target: hppa64-hp-hpux11.11
             Build: hppa64-hp-hpux11.11

Description

Following commit 610d42e09ff8443b8e7e3d69e03e24bd0a4dd0ca (Fold ancestor and
arithmetic aggregate jump functions after inlining), g++.dg/lto/pr68057 ICEs in
lto1 during IPA pass: inline:
text
during IPA pass: inline
lto1: internal compiler error: Segmentation fault
0x40000000020c566b internal_error(char const*, ...)
        ../../gcc/gcc/diagnostic-global-context.cc:787
0x4000000000e3316b crash_signal
        ../../gcc/gcc/toplev.cc:325
0x4000000000b2f798 gimple_call_fntype(gcall const*)
        ../../gcc/gcc/gimple.h:3209
0x4000000000b2f798 ipa_get_callee_param_type(cgraph_edge*, int)
        ../../gcc/gcc/ipa-prop.cc:2534
0x4000000000b3a0af update_jump_functions_after_inlining
        ../../gcc/gcc/ipa-prop.cc:4078
0x4000000000b3af43 propagate_info_to_inlined_callees
        ../../gcc/gcc/ipa-prop.cc:5035
0x4000000000b3af0b propagate_info_to_inlined_callees
        ../../gcc/gcc/ipa-prop.cc:5031
0x4000000000b4372b ipa_propagate_indirect_call_infos(cgraph_edge*,
vec<cgraph_edge*, va_heap, vl_ptr>*)
        ../../gcc/gcc/ipa-prop.cc:5208
0x4000000000b03803 inline_call(cgraph_edge*, bool, vec<cgraph_edge*, va_heap,
vl_ptr>*, int*, bool, bool*)
        ../../gcc/gcc/ipa-inline-transform.cc:577
0x4000000001df3c67 inline_small_functions
        ../../gcc/gcc/ipa-inline.cc:2441
0x4000000001df3c67 ipa_inline
        ../../gcc/gcc/ipa-inline.cc:2923
0x4000000001df3c67 execute
        ../../gcc/gcc/ipa-inline.cc:3446
Use code with caution.

Cause

In update_jump_functions_after_inlining (gcc/ipa-prop.cc:4078), commit
610d42e09ff added:

         if (src->type == IPA_JF_CONST)
           {
             tree parm_type = ipa_get_callee_param_type (e, i);
             tree cst = ipa_get_jf_ancestor_result (dst,
                                                    ipa_get_jf_constant (src));
             if (cst && parm_type)
               cst = ipacp_value_safe_for_type (parm_type, cst);

During LTO (lto1), e->call_stmt can be NULL on unmaterialized cgraph edges.
When ipa_get_callee_param_type (e, i) cannot obtain TYPE_ARG_TYPES from
e->callee (e.g., on an indirect edge or K&R/unprototyped callee), it calls
gimple_call_fntype (e->call_stmt) without checking e->call_stmt != NULL,
dereferencing NULL.

Guarding e->call_stmt (either in ipa_get_callee_param_type or at the call site
in update_jump_functions_after_inlining, since parm_type is already checked for
non-null before calling ipacp_value_safe_for_type) avoids the crash:

Untested fix:

--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -4075,7 +4075,8 @@ update_jump_functions_after_inlining (struct cgraph_edge
*cs,

          if (src->type == IPA_JF_CONST)
            {
-             tree parm_type = ipa_get_callee_param_type (e, i);
+             tree parm_type
+               = e->call_stmt ? ipa_get_callee_param_type (e, i) : NULL_TREE;
              tree cst = ipa_get_jf_ancestor_result (dst,
                                                     ipa_get_jf_constant
(src));
              if (cst && parm_type)

Fails:

FAIL: g++.dg/lto/pr68057 cp_lto_pr68057_0.o-cp_lto_pr68057_1.o link, -O2 -flto 
(internal compiler error: Segmentation fault)
FAIL: g++.dg/lto/pr68057 cp_lto_pr68057_0.o-cp_lto_pr68057_1.o link, -O2 -flto
-flto-partition=1to1  (internal compiler error: Segmentation fault)
FAIL: g++.dg/lto/pr68057 cp_lto_pr68057_0.o-cp_lto_pr68057_1.o link, -O2 -flto
-flto-partition=none  (internal compiler error: Segmentation fault)

Reply via email to