[Bug tree-optimization/92860] [8/9/10 regression] Global flags affected by -O settings are clobbered by optimize attribute

marxin at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Dec 11 14:45:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92860

--- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> ---
Example 1:

$ cat tc.c
void linker_error();
__attribute__ ((optimize("-O0")))
int a ()
{
}

static int remove_me ()
{
  linker_error ();
}

void
main()
{
}

$ ./xgcc -B. -Os tc.c -c -momit-leaf-frame-pointer -m32
global_options difference in flag_merge_constants (1/0)
global_options difference in flag_merge_constants (1/0)
global_options difference in flag_omit_frame_pointer (1/0)
global_options difference in flag_ree (1/0)
tc.c:4:1: internal compiler error: in handle_optimize_attribute, at
c-family/c-attribs.c:4505
    4 | {
      | ^
0x925d14 handle_optimize_attribute
        /home/marxin/Programming/gcc/gcc/c-family/c-attribs.c:4505
0x81fa2e decl_attributes(tree_node**, tree_node*, int, tree_node*)
        /home/marxin/Programming/gcc/gcc/attribs.c:713
0x83ab20 start_function(c_declspecs*, c_declarator*, tree_node*)
        /home/marxin/Programming/gcc/gcc/c/c-decl.c:9110
0x892c57 c_parser_declaration_or_fndef
        /home/marxin/Programming/gcc/gcc/c/c-parser.c:2403
0x89af13 c_parser_external_declaration
        /home/marxin/Programming/gcc/gcc/c/c-parser.c:1742
0x89b961 c_parser_translation_unit
        /home/marxin/Programming/gcc/gcc/c/c-parser.c:1615
0x89b961 c_parse_file()
        /home/marxin/Programming/gcc/gcc/c/c-parser.c:21653
0x8f213b c_common_parse_file()
        /home/marxin/Programming/gcc/gcc/c-family/c-opts.c:1186

Where flag_omit_frame_pointer is overwritten here based on
USE_IX86_FRAME_POINTER aka -momit-leaf-frame-pointer:

   │1624              if (opts->x_optimize >= 1)│
   │1625                  SET_OPTION_IF_UNSET (opts, opts_set,
flag_omit_frame_pointer,│
   │1626                                       !(USE_IX86_FRAME_POINTER ||
opts->x_optimize_size));│
  >│1627              if (opts->x_flag_asynchronous_unwind_tables == 2)│
   │1628                opts->x_flag_asynchronous_unwind_tables =
!USE_IX86_FRAME_POINTER;│

flag_merge_constants is not optimization and is changed due to when we switch
optimization level:
gcc/opts.c:    { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 },

I do not know why -free is changed:
gcc/common.opt:Common Report Var(flag_ree) Init(0)


More information about the Gcc-bugs mailing list