* [PATCH] Fix PR61564 - optimize attribute/pragma accepting any option
@ 2016-06-07 8:15 Richard Biener
2016-06-07 8:21 ` Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2016-06-07 8:15 UTC (permalink / raw)
To: gcc-patches; +Cc: Jakub Jelinek
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?
Note this also points to the unfortunate ways the FEs apply
the pragma to functions which seems to be via adding optimize
attributes literally rather than copying a tree optimization
node constructable by parse_optimize_options. That results
in excessive diagnostics also reproducable without the patch
if you use sth like #pragma GCC optimize ("-Xhost").
Thanks,
Richard.
2016-06-07 Richard Biener <rguenther@suse.de>
PR c/61564
* c-common.c (parse_optimize_options): Only apply CL_OPTIMIZATION
options and warn about others.
* gcc.dg/Wpragmas-1.c: New testcase.
* gcc.dg/Wattributes-4.c: Likewise.
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" } */
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR61564 - optimize attribute/pragma accepting any option
2016-06-07 8:15 [PATCH] Fix PR61564 - optimize attribute/pragma accepting any option Richard Biener
@ 2016-06-07 8:21 ` Jakub Jelinek
2016-06-07 8:22 ` Richard Biener
2016-06-07 12:16 ` Richard Biener
0 siblings, 2 replies; 4+ messages in thread
From: Jakub Jelinek @ 2016-06-07 8:21 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
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).
> 2016-06-07 Richard Biener <rguenther@suse.de>
>
> PR c/61564
> * c-common.c (parse_optimize_options): Only apply CL_OPTIMIZATION
> options and warn about others.
>
> * gcc.dg/Wpragmas-1.c: New testcase.
> * gcc.dg/Wattributes-4.c: Likewise.
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR61564 - optimize attribute/pragma accepting any option
2016-06-07 8:21 ` Jakub Jelinek
@ 2016-06-07 8:22 ` Richard Biener
2016-06-07 12:16 ` Richard Biener
1 sibling, 0 replies; 4+ messages in thread
From: Richard Biener @ 2016-06-07 8:22 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
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).
Yes, I was surprised by that as well...
Richard.
> > 2016-06-07 Richard Biener <rguenther@suse.de>
> >
> > PR c/61564
> > * c-common.c (parse_optimize_options): Only apply CL_OPTIMIZATION
> > options and warn about others.
> >
> > * gcc.dg/Wpragmas-1.c: New testcase.
> > * gcc.dg/Wattributes-4.c: Likewise.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR61564 - optimize attribute/pragma accepting any option
2016-06-07 8:21 ` Jakub Jelinek
2016-06-07 8:22 ` Richard Biener
@ 2016-06-07 12:16 ` Richard Biener
1 sibling, 0 replies; 4+ messages in thread
From: Richard Biener @ 2016-06-07 12:16 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
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 <rguenther@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)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-06-07 12:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-07 8:15 [PATCH] Fix PR61564 - optimize attribute/pragma accepting any option Richard Biener
2016-06-07 8:21 ` Jakub Jelinek
2016-06-07 8:22 ` Richard Biener
2016-06-07 12:16 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).