Message ID | 20140117195808.GM892@tucnak.redhat.com |
---|---|
State | New |
Headers | show |
On Fri, Jan 17, 2014 at 8:58 PM, Jakub Jelinek <jakub@redhat.com> wrote: > It makes no sense to warn about unused macros that weren't defined > by the user, but the compiler instead injected them, the user > has no control on them. > For macros predefined at the beginning of the CU we don't get warnings > because they don't match MAIN_FILE_P, but macros added for #pragma GCC target > get location_t from the location of the pragma (and without libcpp hacks > that could possibly slow down preprocessing I don't see how to get around > it), so the following hack seems to be easiest. All newly created macros > when -Wunused-macros isn't on are initialized with macro->used = true, > and never warned about for this warning, so this patch just arranges for > all the cpp_define calls from #pragma GCC target to set that. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2014-01-17 Jakub Jelinek <jakub@redhat.com> > > PR target/58944 > * config/i386/i386-c.c (ix86_pragma_target_parse): Temporarily > clear cpp_get_options (parse_in)->warn_unused_macros for > ix86_target_macros_internal with cpp_define. > > * gcc.target/i386/pr58944.c: Drop -march=native from dg-options. > Remove dg-prune-output lines. OK. Thanks, Uros.
--- gcc/config/i386/i386-c.c.jj 2014-01-03 11:41:06.000000000 +0100 +++ gcc/config/i386/i386-c.c 2014-01-17 14:24:15.828447673 +0100 @@ -458,6 +458,13 @@ ix86_pragma_target_parse (tree args, tre (enum fpmath_unit) prev_opt->x_ix86_fpmath, cpp_undef); + /* For the definitions, ensure all newly defined macros are considered + as used for -Wunused-macros. There is no point warning about the + compiler predefined macros. */ + cpp_options *cpp_opts = cpp_get_options (parse_in); + unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros; + cpp_opts->warn_unused_macros = 0; + /* Define all of the macros for new options that were just turned on. */ ix86_target_macros_internal (cur_isa & diff_isa, cur_arch, @@ -465,6 +472,8 @@ ix86_pragma_target_parse (tree args, tre (enum fpmath_unit) cur_opt->x_ix86_fpmath, cpp_define); + cpp_opts->warn_unused_macros = saved_warn_unused_macros; + return true; } --- gcc/testsuite/gcc.target/i386/pr58944.c.jj 2013-12-03 08:27:22.000000000 +0100 +++ gcc/testsuite/gcc.target/i386/pr58944.c 2014-01-17 14:29:53.288756542 +0100 @@ -1,11 +1,7 @@ /* { dg-do compile } */ -/* { dg-options "-Wunused-macros -march=native" } */ +/* { dg-options "-Wunused-macros" } */ #pragma GCC push_options #pragma GCC target("xsaveopt") void fn1(void) {} #pragma GCC pop_options - -/* { dg-prune-output "macro \"__code_model_" } */ -/* { dg-prune-output "macro \"__XSAVE__\" is not used" } */ -/* { dg-prune-output "macro \"__XSAVEOPT__\" is not used" } */