While implementing something like mips16 as a __attribute__((thumb)) for the ARM port I discovered that the following testcase stripped down from a testcase in the gcc testsuite causes a segmentation fault in the compiler for the MIPS port as well.
static double __attribute__((mips16)) time_giop_encode (unsigned long); int main(int ac, char *av[]) { time_giop_encode (0); } static double __attribute__ ((mips16)) time_giop_encode (unsigned long l) { giop_encode_ulong (l); } A run through a valgrind showed that there was a write to an invalid address - ==7998== Invalid write of size 4 ==7998== at 0x8234A0E: gen_reg_rtx (emit-rtl.c:912) ==7998== by 0x830CD7B: expand_function_start (function.c:4416) ==7998== by 0x88BBF81: gimple_expand_cfg (cfgexpand.c:2512) ==7998== by 0x83D220C: execute_one_pass (passes.c:1289) ==7998== by 0x83D248B: execute_pass_list (passes.c:1338) ==7998== by 0x854C81F: tree_rest_of_compilation (tree-optimize.c:394) ==7998== by 0x86C524B: cgraph_expand_function (cgraphunit.c:1097) ==7998== by 0x86C7A4C: cgraph_optimize (cgraphunit.c:1156) ==7998== by 0x80BE9BA: c_write_global_declarations (c-decl.c:8593) ==7998== by 0x84F4255: toplev_main (toplev.c:1044) ==7998== by 0x8144A21: main (main.c:35) ==7998== Address 0x46811f0 is not stack'd, malloc'd or (recently) free'd ==7998== ==7998== Invalid write of size 4 ==7998== at 0x8234A0E: gen_reg_rtx (emit-rtl.c:912) ==7998== by 0x8304E0B: assign_parm_setup_reg (function.c:2780) ==7998== by 0x830AB61: assign_parms (function.c:3172) ==7998== by 0x830C938: expand_function_start (function.c:4432) ==7998== by 0x88BBF81: gimple_expand_cfg (cfgexpand.c:2512) ==7998== by 0x83D220C: execute_one_pass (passes.c:1289) ==7998== by 0x83D248B: execute_pass_list (passes.c:1338) ==7998== by 0x854C81F: tree_rest_of_compilation (tree-optimize.c:394) ==7998== by 0x86C524B: cgraph_expand_function (cgraphunit.c:1097) ==7998== by 0x86C7A4C: cgraph_optimize (cgraphunit.c:1156) ==7998== by 0x80BE9BA: c_write_global_declarations (c-decl.c:8593) ==7998== by 0x84F4255: toplev_main (toplev.c:1044) ==7998== Address 0x46811f4 is not stack'd, malloc'd or (recently) free'd ==7998== ==7998== Invalid write of size 1 ==7998== at 0x82351A2: mark_reg_pointer (emit-rtl.c:1120) ==7998== by 0x830522D: assign_parm_setup_reg (function.c:2945) ==7998== by 0x830AB61: assign_parms (function.c:3172) ==7998== by 0x830C938: expand_function_start (function.c:4432) ==7998== by 0x88BBF81: gimple_expand_cfg (cfgexpand.c:2512) ==7998== by 0x83D220C: execute_one_pass (passes.c:1289) ==7998== by 0x83D248B: execute_pass_list (passes.c:1338) ==7998== by 0x854C81F: tree_rest_of_compilation (tree-optimize.c:394) ==7998== by 0x86C524B: cgraph_expand_function (cgraphunit.c:1097) ==7998== by 0x86C7A4C: cgraph_optimize (cgraphunit.c:1156) ==7998== by 0x80BE9BA: c_write_global_declarations (c-decl.c:8593) ==7998== by 0x84F4255: toplev_main (toplev.c:1044) ==7998== Address 0x479423a is 1 bytes after a block of size 1 alloc'd ==7998== at 0x4026FDE: malloc (vg_replace_malloc.c:207) ==7998== by 0x89D8DC7: xrealloc (xmalloc.c:177) ==7998== by 0x8234A5E: gen_reg_rtx (emit-rtl.c:900) ==7998== by 0x830CD7B: expand_function_start (function.c:4416) ==7998== by 0x88BBF81: gimple_expand_cfg (cfgexpand.c:2512) ==7998== by 0x83D220C: execute_one_pass (passes.c:1289) ==7998== by 0x83D248B: execute_pass_list (passes.c:1338) ==7998== by 0x854C81F: tree_rest_of_compilation (tree-optimize.c:394) ==7998== by 0x86C524B: cgraph_expand_function (cgraphunit.c:1097) ==7998== by 0x86C7A4C: cgraph_optimize (cgraphunit.c:1156) The segfault is because reg_rtx_no is 0 and rtx_reg_no are uninitialized. It looks like the infrastructure of target_reinit is broken because these are not reinitialized correctly after inlining does its bit with setting and resetting this . init_function_start from tree_rest_of_compilation initializes these but the inlining bits call set_cfun and do a target_reinit which sets all these values to zero. expand_function_start gets called later and by this time since regno_reg_rtx is set to 0 you have gen_reg_rtx returning a hard register. -- Summary: __attribute__((mips16)) is broken on trunk. Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ramana at gcc dot gnu dot org GCC build triplet: i686-linux-gnu GCC host triplet: i686-linux-gnu GCC target triplet: mips-elf http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40419