https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92860
Bug ID: 92860 Summary: [8,9,10 regression] Global flags affected by -O settings are clobbered by optimize attribute Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: hubicka at gcc dot gnu.org Target Milestone: --- Hi, the following testcase: void linker_error(); __attribute__ ((optimize("-O0"))) int a () { } static int remove_me () { linker_error (); } void main() { } builds with GCC6 but not with GCC8, GCC9 and GCC10: hubicka@lomikamen-jh:/aux/hubicka/trunk4/gcc$ gcc -O2 t.c hubicka@lomikamen-jh:/aux/hubicka/trunk4/gcc$ /aux/hubicka/trunk-install/bin/gcc -O2 t.c /usr/local/bin/ld: /tmp/cckSFE5R.o: in function `remove_me': t.c:(.text+0x17): undefined reference to `linker_error' collect2: error: ld returned 1 exit status The problem is that while processing the optimize attribute for a we overwritte flag_toplevel_reorder that is affected by optimization flag but not marked as Optimization. I suppose there are other cases like this.