Hello,
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.
$ mips-unknown-elf-gcc -Os -mips32r2 -fdump-tree-einline
/opt/developer/oss/src/gcc/gcc/testsuite/gcc.target/mips/mips16-
attributes-5.c -DMIPS16='__attribute__((mips16))'
-DNOMIPS16='__attribute__((nomips16))'
during GIMPLE pass: einline
dump file: a-mips16-attributes-5.c.035t.einline
/opt/developer/oss/src/gcc/gcc/testsuite/gcc.target/mips/mips16-attributes-5.c:
In function 'f1':
/opt/developer/oss/src/gcc/gcc/testsuite/gcc.target/mips/mips16-attributes-5.c:13:1:
internal compiler error: Segmentation fault
13 | int NOMIPS16 f4 (void) { return i4 (); }
| ^~~
0x33c5347 internal_error(char const*, ...)
/opt/developer/oss/src/gcc/gcc/diagnostic-global-context.cc:787
0x1a2bc07 crash_signal
/opt/developer/oss/src/gcc/gcc/toplev.cc:325
0x186608c cl_target_option_print_diff(_IO_FILE*, int, cl_target_option*,
cl_target_option*)
/opt/developer/build/gcc/gcc/options-save.cc:10136
0x3184fe0 report_inline_failed_reason
/opt/developer/oss/src/gcc/gcc/ipa-inline.cc:299
0x31855b4 can_inline_edge_p
/opt/developer/oss/src/gcc/gcc/ipa-inline.cc:462
0x31868cb can_early_inline_edge_p
/opt/developer/oss/src/gcc/gcc/ipa-inline.cc:717
0x318e098 early_inline_small_functions
/opt/developer/oss/src/gcc/gcc/ipa-inline.cc:3093
0x318e992 early_inliner(function*)
/opt/developer/oss/src/gcc/gcc/ipa-inline.cc:3291
0x318ec79 execute
/opt/developer/oss/src/gcc/gcc/ipa-inline.cc:3397
The following patch adds NULL checks before calling
cl_target_option_print_diff to fix the crash.
Ok for master?
gcc/ChangeLog:
* ipa-inline.cc (report_inline_failed_reason): Check for NULL
before calling cl_target_option_print_diff.
diff --git gcc/ipa-inline.cc gcc/ipa-inline.cc
index 5a7615666cc..111593f45fd 100644
--- gcc/ipa-inline.cc
+++ gcc/ipa-inline.cc
@@ -294,10 +294,14 @@ report_inline_failed_reason (struct cgraph_edge *e)
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));
+ {
+ 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 (dump_file && 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