https://gcc.gnu.org/g:aefe058f869906315a7ba9c2638e258f13d65931
commit r17-4369-gaefe058f869906315a7ba9c2638e258f13d65931 Author: Senthil Kumar Selvaraj <[email protected]> Date: Wed Sep 16 20:18:44 2026 +0530 ipa: Fix segfault ICE with fdump-tree-einline on TARGET_OPTION_MISMATCH If a target rejects inlining via the TARGET_CAN_INLINE_P hook for reasons other than optimization options, the compiler currently crashes with a segfault. The MIPS target (mips.cc:mips_can_inline_p), for e.g., rejects inlining on conflicting target attributes, and compiling gcc.target/mips/mips16-attributes-5.c with -fdump-tree-einline segfaults - report_inline_failed_reason passes target_opts_for_fn's result to cl_target_option_print_diff even if NULL. Fix by checking for NULL for before calling cl_target_option_print_diff. gcc/ChangeLog: * ipa-inline.cc (report_inline_failed_reason): Check for NULL before calling cl_target_option_print_diff. Diff: --- gcc/ipa-inline.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc index 5a7615666cc1..ba8bf11b66ee 100644 --- a/gcc/ipa-inline.cc +++ b/gcc/ipa-inline.cc @@ -293,11 +293,16 @@ report_inline_failed_reason (struct cgraph_edge *e) e->caller->lto_file_data->file_name, e->callee->ultimate_alias_target ()->lto_file_data->file_name); } - if (e->inline_failed == CIF_TARGET_OPTION_MISMATCH) - if (dump_file) - cl_target_option_print_diff - (dump_file, 2, target_opts_for_fn (e->caller->decl), - target_opts_for_fn (e->callee->ultimate_alias_target ()->decl)); + if (e->inline_failed == CIF_TARGET_OPTION_MISMATCH + && dump_file) + { + struct cl_target_option *opt_caller + = target_opts_for_fn (e->caller->decl); + struct cl_target_option *opt_callee + = target_opts_for_fn (e->callee->ultimate_alias_target ()->decl); + if (opt_caller != NULL && opt_callee != NULL) + cl_target_option_print_diff (dump_file, 2, opt_caller, opt_callee); + } if (e->inline_failed == CIF_OPTIMIZATION_MISMATCH) if (dump_file) cl_optimization_print_diff
