Hi,
My recent commit to emit asm name with -fdump-statistics-asmname
caused following ICE
for attached fortran test case.

during IPA pass: icf
power.fppized.f90:6:26:

    6 | END SUBROUTINE power_print
      |                          ^
internal compiler error: Segmentation fault
0xfddc13 crash_signal
        ../../gcc/gcc/toplev.cc:322
0x7f6f940de51f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0xfc909d get_function_name
        ../../gcc/gcc/statistics.cc:124
0xfc929f statistics_fini_pass_2(statistics_counter**, void*)
        ../../gcc/gcc/statistics.cc:175
0xfc94a4 void hash_table<stats_counter_hasher, false,
xcallocator>::traverse_noresize<void*,
&(statistics_fini_pass_2(statistics_counter**, void*))>(void*)
        ../../gcc/gcc/hash-table.h:1084
0xfc94a4 statistics_fini_pass()
        ../../gcc/gcc/statistics.cc:219
0xef12bc execute_todo
        ../../gcc/gcc/passes.cc:2142

This happens because fn was passed NULL in get_function_name.
The patch adds a check to see if fn is NULL before checking for
DECL_ASSEMBLER_NAME_SET_P, which fixes the issue.
In case the fn is NULL, it calls function_name(NULL) as per old behavior,
which returns "(nofn)".

Bootstrap+tested on x86_64-linux-gnu.
OK to commit ?

Thanks,
Prathamesh
diff --git a/gcc/statistics.cc b/gcc/statistics.cc
index 6c21415bf65..01ad353e3a9 100644
--- a/gcc/statistics.cc
+++ b/gcc/statistics.cc
@@ -121,7 +121,7 @@ static const char *
 get_function_name (struct function *fn)
 {
   if ((statistics_dump_flags & TDF_ASMNAME)
-      && DECL_ASSEMBLER_NAME_SET_P (fn->decl))
+      && fn && DECL_ASSEMBLER_NAME_SET_P (fn->decl))
     {
       tree asmname = decl_assembler_name (fn->decl);
       if (asmname)

Attachment: power.fppized.f90
Description: Binary data

Reply via email to