gcc 13.0.0 20220529 snapshot (g:58a40e76ebadce78639644cd3d56e42b68336927) ICEs when compiling the following testcase, reduced from gcc/testsuite/gcc.dg/vect/tsvc/vect-tsvc-s255.c, w/ -Os -fno-tree-vectorize:#pragma GCC optimize "-fno-tree-vectorize" void foo (void) { void bar (void); } % powerpc-e300c3-linux-gnu-gcc-13.0.0 -Os -fno-tree-vectorize -c sgyptdev.c sgyptdev.c: In function 'foo': sgyptdev.c:7:3: internal compiler error: 'global_options' are modified in local context 7 | bar (void); | ^~~ 0xd5b42b cl_optimization_compare(gcc_options*, gcc_options*) /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-13.0.0_p20220529/work/build/gcc/options-save.cc:14281 0x8e9234 handle_optimize_attribute /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-13.0.0_p20220529/work/gcc-13-20220529/gcc/c-family/c-attribs.cc:5581 0x7e0fa4 decl_attributes(tree_node**, tree_node*, int, tree_node*) /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-13.0.0_p20220529/work/gcc-13-20220529/gcc/attribs.cc:872 0x7fe1b7 start_decl(c_declarator*, c_declspecs*, bool, tree_node*, unsigned int*) /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-13.0.0_p20220529/work/gcc-13-20220529/gcc/c/c-decl.cc:5232 0x8625f5 c_parser_declaration_or_fndef /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-13.0.0_p20220529/work/gcc-13-20220529/gcc/c/c-parser.cc:2315 0x841333 c_parser_compound_statement_nostart /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-13.0.0_p20220529/work/gcc-13-20220529/gcc/c/c-parser.cc:5720 0x862085 c_parser_compound_statement /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-13.0.0_p20220529/work/gcc-13-20220529/gcc/c/c-parser.cc:5617 0x863c18 c_parser_declaration_or_fndef /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-13.0.0_p20220529/work/gcc-13-20220529/gcc/c/c-parser.cc:2552 0x86c003 c_parser_external_declaration /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-13.0.0_p20220529/work/gcc-13-20220529/gcc/c/c-parser.cc:1787 0x86ca5b c_parser_translation_unit /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-13.0.0_p20220529/work/gcc-13-20220529/gcc/c/c-parser.cc:1660 0x86ca5b c_parse_file() /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-13.0.0_p20220529/work/gcc-13-20220529/gcc/c/c-parser.cc:23416 0x8cfb71 c_common_parse_file() /var/tmp/portage/cross-powerpc-e300c3-linux-gnu/gcc-13.0.0_p20220529/work/gcc-13-20220529/gcc/c-family/c-opts.cc:1235
Sorry, there's a newline missing after the first paragraph, so the testcase looks like this: #pragma GCC optimize "-fno-tree-vectorize" void foo (void) { void bar (void); }
Confirmed, failed on powerpc*-linux-gnu.
The different flag bit is OPTION_MASK_SAVE_TOC_INDIRECT. if ((rs6000_isa_flags_explicit & OPTION_MASK_SAVE_TOC_INDIRECT) == 0 && flag_shrink_wrap_separate && optimize_function_for_speed_p (cfun)) rs6000_isa_flags |= OPTION_MASK_SAVE_TOC_INDIRECT; When parsing function foo, the call to optimize_function_for_speed_p return OPTIMIZE_SIZE_MAX as expected, at that time function struct is null. while parsing the decl bar, the cfun is the one created for foo, although there is no cgraph node for it, optimize_function_for_speed_p return OPTIMIZE_SIZE_NO. I think when none cgraph node is found we should still return OPTIMIZE_SIZE_MAX if optimize_size is set. It can fix this issue.
Filed PR108184 to avoid to use optimize_function_for_speed_p too early, fixing it can cover this exposed ICE, but IMHO this is still a separated issue, the case found on aarch64 can still show that the information on size/speed is inconsistent and this issue is worth to fixing.