On Tue, 7 Jun 2016, Jakub Jelinek wrote: > On Tue, Jun 07, 2016 at 10:15:39AM +0200, Richard Biener wrote: > > > > This fixes PR61564 by diagnosing (and ignoring) options not marked with > > 'Optimization' being applied to #pragma GCC optimize or via the > > optimize attribute. > > > > The reason is that while we save/restore option state for 'Optimize' > > marked options we don't do that for other options. Thus while such > > options do not end up in the per-function optimize state applying them > > still clobbers the global state. > > > > Bootstrap and regtest running on x86_64-unknown-linux-gnu. > > > > Ok for trunk? > > Ok (though it surprises me we haven't done that from the beginning).
It exposed that gcc.dg/ipa/pr70646.c uses a non-Optimization option #pragma (fixed) and that -ffast-math is not marked Optimization (but its "components" are, likewise -funsafe-math-optimizations is). Fixed both, bootstrapped / tested on x86_64-unknown-linux-gnu and applied. Richard. 2016-06-07 Richard Biener <rguent...@suse.de> PR c/61564 * c-common.c (parse_optimize_options): Only apply CL_OPTIMIZATION options and warn about others. * common.opt (ffast-math): Make Optimization. * gcc.dg/Wpragmas-1.c: New testcase. * gcc.dg/Wattributes-4.c: Likewise. * gcc.dg/ipa/pr70646.c: Drop optimize pragma in favor of dg-option entry. Index: gcc/c-family/c-common.c =================================================================== *** gcc/c-family/c-common.c (revision 237167) --- gcc/c-family/c-common.c (working copy) *************** parse_optimize_options (tree args, bool *** 9580,9585 **** --- 9580,9608 ---- decode_cmdline_options_to_array_default_mask (opt_argc, opt_argv, &decoded_options, &decoded_options_count); + /* Drop non-Optimization options. */ + unsigned j = 1; + for (i = 1; i < decoded_options_count; ++i) + { + if (! (cl_options[decoded_options[i].opt_index].flags & CL_OPTIMIZATION)) + { + ret = false; + if (attr_p) + warning (OPT_Wattributes, + "bad option %s to optimize attribute", + decoded_options[i].orig_option_with_args_text); + else + warning (OPT_Wpragmas, + "bad option %s to pragma attribute", + decoded_options[i].orig_option_with_args_text); + continue; + } + if (i != j) + decoded_options[j] = decoded_options[i]; + j++; + } + decoded_options_count = j; + /* And apply them. */ decode_options (&global_options, &global_options_set, decoded_options, decoded_options_count, input_location, global_dc); Index: gcc/testsuite/gcc.dg/Wpragmas-1.c =================================================================== *** gcc/testsuite/gcc.dg/Wpragmas-1.c (revision 0) --- gcc/testsuite/gcc.dg/Wpragmas-1.c (working copy) *************** *** 0 **** --- 1,11 ---- + /* { dg-do compile } */ + + #pragma GCC push_options + #pragma GCC optimize ("-fno-lto") /* { dg-warning "bad option" } */ + int main(void){return 0;} + #pragma GCC pop_options + + /* ??? The FEs still apply the pragma string as optimize attribute to + all functions thus the diagnostic will be repeated for each function + affected. */ + /* { dg-message "bad option" "" { target *-*-* } 0 } */ Index: gcc/testsuite/gcc.dg/Wattributes-4.c =================================================================== *** gcc/testsuite/gcc.dg/Wattributes-4.c (revision 0) --- gcc/testsuite/gcc.dg/Wattributes-4.c (working copy) *************** *** 0 **** --- 1,3 ---- + /* { dg-do compile } */ + + int __attribute__((optimize("no-lto"))) main(void){return 0;} /* { dg-warning "bad option" } */ Index: gcc/testsuite/gcc.dg/ipa/pr70646.c =================================================================== *** gcc/testsuite/gcc.dg/ipa/pr70646.c (revision 237165) --- gcc/testsuite/gcc.dg/ipa/pr70646.c (working copy) *************** *** 1,7 **** /* { dg-do run } */ ! /* { dg-options "-O2" } */ ! ! #pragma GCC optimize("no-unit-at-a-time") typedef unsigned char u8; typedef unsigned long long u64; --- 1,5 ---- /* { dg-do run } */ ! /* { dg-options "-O2 -fno-unit-at-a-time" } */ typedef unsigned char u8; typedef unsigned long long u64; Index: gcc/common.opt =================================================================== *** gcc/common.opt (revision 237165) --- gcc/common.opt (working copy) *************** EnumValue *** 1287,1293 **** Enum(excess_precision) String(standard) Value(EXCESS_PRECISION_STANDARD) ffast-math ! Common ffat-lto-objects Common Var(flag_fat_lto_objects) --- 1287,1293 ---- Enum(excess_precision) String(standard) Value(EXCESS_PRECISION_STANDARD) ffast-math ! Common Optimization ffat-lto-objects Common Var(flag_fat_lto_objects)