Patchwork : issue warning about -f(no-)strict-aliasing in function optimize attribute

login
register
mail settings
Submitter Bingfeng Mei
Date Nov. 10, 2010, 4:43 p.m.
Message ID <7FB04A5C213E9943A72EE127DB74F0ADA69190944C@SJEXCHCCR02.corp.ad.broadcom.com>
Download mbox | patch
Permalink /patch/70648/
State New
Headers show

Comments

Bingfeng Mei - Nov. 10, 2010, 4:43 p.m.
Hello,
Currently, if we specify a different -f(no-)strict-aliasing option
in function optimize attribute. GCC just quietly ignores it. 
http://gcc.gnu.org/ml/gcc/2010-11/msg00091.html It is error-prone as
it is not expected by a programmer. 

The patch issues a warning in such situation. One thing I am not sure is that
Richard Guenther - Nov. 10, 2010, 4:54 p.m.
On Wed, Nov 10, 2010 at 5:43 PM, Bingfeng Mei <bmei@broadcom.com> wrote:
> Hello,
> Currently, if we specify a different -f(no-)strict-aliasing option
> in function optimize attribute. GCC just quietly ignores it.
> http://gcc.gnu.org/ml/gcc/2010-11/msg00091.html It is error-prone as
> it is not expected by a programmer.
>
> The patch issues a warning in such situation. One thing I am not sure is that
> different optimizing levels also have different setting for strict-aliasing.
> Should I also warn that (will make some existing tests fail), or make it
> an exception? This patch ignores such case.
>
> Bootstrapped and tested with x86_64-unknown-linux-gnu.
>
> Thanks,
> Bingfeng Mei
>
>
> 2010-11-10  Bingfeng Mei  <bmei@broadcom.com>
>        * c-family/c-common.c (parse_optimize_options): Issue warning about
>        -f(no-)strict-aliasing in optimize attribute.
>
>
> Index: c-family/c-common.c
> ===================================================================
> --- c-family/c-common.c (revision 166523)
> +++ c-family/c-common.c (working copy)
> @@ -7808,6 +7808,16 @@ parse_optimize_options (tree args, bool
>
>   targetm.override_options_after_change();
>
> +  /* Currently GCC doesn't support function-specific -f(no-)strict-aliasing
> +    Issue a warning under such case.
> +    Ignore cases where difference is caused by different optimization
> +    levels. (strict aliasing is disabled < -O2 )
> +  */
> +  if ((!flag_strict_aliasing && saved_flag_strict_aliasing && optimize >= 2)
> +     || (flag_strict_aliasing && !saved_flag_strict_aliasing && optimize < 2))
> +    warning (OPT_Wattributes,
> +             "-f(no-)strict-aliasing option in optimize attribute ignored");
> +
>   /* Don't allow changing -fstrict-aliasing.  */
>   flag_strict_aliasing = saved_flag_strict_aliasing;

I think an easier test is

   if (flag_strict_aliasing != saved_flag_strict_aliasing)
     warning (OPT_Wattributes,
                  "changes in strict-aliasing behavior ignored");

or sth like that.

Richard.

>
Bingfeng Mei - Nov. 10, 2010, 5:30 p.m.
Then it will warn in following situation

__attribute__ ((optimize (-O2))
void foo()
{
}

And the file itself is compiled as -O1. There are several
tests like that. Should I adopt your suggestion and modify
those tests then? 

Cheers,
Bingfeng. 

> -----Original Message-----
> From: Richard Guenther [mailto:richard.guenther@gmail.com]
> Sent: 10 November 2010 16:55
> To: Bingfeng Mei
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH]: issue warning about -f(no-)strict-aliasing in
> function optimize attribute
> 
> On Wed, Nov 10, 2010 at 5:43 PM, Bingfeng Mei <bmei@broadcom.com> wrote:
> > Hello,
> > Currently, if we specify a different -f(no-)strict-aliasing option
> > in function optimize attribute. GCC just quietly ignores it.
> > http://gcc.gnu.org/ml/gcc/2010-11/msg00091.html It is error-prone as
> > it is not expected by a programmer.
> >
> > The patch issues a warning in such situation. One thing I am not sure
> is that
> > different optimizing levels also have different setting for strict-
> aliasing.
> > Should I also warn that (will make some existing tests fail), or make
> it
> > an exception? This patch ignores such case.
> >
> > Bootstrapped and tested with x86_64-unknown-linux-gnu.
> >
> > Thanks,
> > Bingfeng Mei
> >
> >
> > 2010-11-10  Bingfeng Mei  <bmei@broadcom.com>
> >        * c-family/c-common.c (parse_optimize_options): Issue warning
> about
> >        -f(no-)strict-aliasing in optimize attribute.
> >
> >
> > Index: c-family/c-common.c
> > ===================================================================
> > --- c-family/c-common.c (revision 166523)
> > +++ c-family/c-common.c (working copy)
> > @@ -7808,6 +7808,16 @@ parse_optimize_options (tree args, bool
> >
> >   targetm.override_options_after_change();
> >
> > +  /* Currently GCC doesn't support function-specific -f(no-)strict-
> aliasing
> > +    Issue a warning under such case.
> > +    Ignore cases where difference is caused by different
> optimization
> > +    levels. (strict aliasing is disabled < -O2 )
> > +  */
> > +  if ((!flag_strict_aliasing && saved_flag_strict_aliasing &&
> optimize >= 2)
> > +     || (flag_strict_aliasing && !saved_flag_strict_aliasing &&
> optimize < 2))
> > +    warning (OPT_Wattributes,
> > +             "-f(no-)strict-aliasing option in optimize attribute
> ignored");
> > +
> >   /* Don't allow changing -fstrict-aliasing.  */
> >   flag_strict_aliasing = saved_flag_strict_aliasing;
> 
> I think an easier test is
> 
>    if (flag_strict_aliasing != saved_flag_strict_aliasing)
>      warning (OPT_Wattributes,
>                   "changes in strict-aliasing behavior ignored");
> 
> or sth like that.
> 
> Richard.
> 
> >
Richard Guenther - Nov. 10, 2010, 8:09 p.m.
On Wed, Nov 10, 2010 at 6:30 PM, Bingfeng Mei <bmei@broadcom.com> wrote:
> Then it will warn in following situation
>
> __attribute__ ((optimize (-O2))
> void foo()
> {
> }
>
> And the file itself is compiled as -O1. There are several
> tests like that. Should I adopt your suggestion and modify
> those tests then?

Hmm.  I suppose we could instead check
saved_flag_strict_aliasing && !flag_strict_aliasing, thus assume it's safe
to not enable strict-aliasing even when asked to and only refrain from
silently ignoring disabling of strict aliasing.

Richard.

> Cheers,
> Bingfeng.
>
>> -----Original Message-----
>> From: Richard Guenther [mailto:richard.guenther@gmail.com]
>> Sent: 10 November 2010 16:55
>> To: Bingfeng Mei
>> Cc: gcc-patches@gcc.gnu.org
>> Subject: Re: [PATCH]: issue warning about -f(no-)strict-aliasing in
>> function optimize attribute
>>
>> On Wed, Nov 10, 2010 at 5:43 PM, Bingfeng Mei <bmei@broadcom.com> wrote:
>> > Hello,
>> > Currently, if we specify a different -f(no-)strict-aliasing option
>> > in function optimize attribute. GCC just quietly ignores it.
>> > http://gcc.gnu.org/ml/gcc/2010-11/msg00091.html It is error-prone as
>> > it is not expected by a programmer.
>> >
>> > The patch issues a warning in such situation. One thing I am not sure
>> is that
>> > different optimizing levels also have different setting for strict-
>> aliasing.
>> > Should I also warn that (will make some existing tests fail), or make
>> it
>> > an exception? This patch ignores such case.
>> >
>> > Bootstrapped and tested with x86_64-unknown-linux-gnu.
>> >
>> > Thanks,
>> > Bingfeng Mei
>> >
>> >
>> > 2010-11-10  Bingfeng Mei  <bmei@broadcom.com>
>> >        * c-family/c-common.c (parse_optimize_options): Issue warning
>> about
>> >        -f(no-)strict-aliasing in optimize attribute.
>> >
>> >
>> > Index: c-family/c-common.c
>> > ===================================================================
>> > --- c-family/c-common.c (revision 166523)
>> > +++ c-family/c-common.c (working copy)
>> > @@ -7808,6 +7808,16 @@ parse_optimize_options (tree args, bool
>> >
>> >   targetm.override_options_after_change();
>> >
>> > +  /* Currently GCC doesn't support function-specific -f(no-)strict-
>> aliasing
>> > +    Issue a warning under such case.
>> > +    Ignore cases where difference is caused by different
>> optimization
>> > +    levels. (strict aliasing is disabled < -O2 )
>> > +  */
>> > +  if ((!flag_strict_aliasing && saved_flag_strict_aliasing &&
>> optimize >= 2)
>> > +     || (flag_strict_aliasing && !saved_flag_strict_aliasing &&
>> optimize < 2))
>> > +    warning (OPT_Wattributes,
>> > +             "-f(no-)strict-aliasing option in optimize attribute
>> ignored");
>> > +
>> >   /* Don't allow changing -fstrict-aliasing.  */
>> >   flag_strict_aliasing = saved_flag_strict_aliasing;
>>
>> I think an easier test is
>>
>>    if (flag_strict_aliasing != saved_flag_strict_aliasing)
>>      warning (OPT_Wattributes,
>>                   "changes in strict-aliasing behavior ignored");
>>
>> or sth like that.
>>
>> Richard.
>>
>> >
>
>
>

Patch

different optimizing levels also have different setting for strict-aliasing.
Should I also warn that (will make some existing tests fail), or make it
an exception? This patch ignores such case. 

Bootstrapped and tested with x86_64-unknown-linux-gnu. 

Thanks,
Bingfeng Mei


2010-11-10  Bingfeng Mei  <bmei@broadcom.com>
	* c-family/c-common.c (parse_optimize_options): Issue warning about
	-f(no-)strict-aliasing in optimize attribute. 
        

Index: c-family/c-common.c
===================================================================
--- c-family/c-common.c (revision 166523)
+++ c-family/c-common.c (working copy)
@@ -7808,6 +7808,16 @@  parse_optimize_options (tree args, bool

   targetm.override_options_after_change();

+  /* Currently GCC doesn't support function-specific -f(no-)strict-aliasing
+    Issue a warning under such case.
+    Ignore cases where difference is caused by different optimization
+    levels. (strict aliasing is disabled < -O2 )
+  */
+  if ((!flag_strict_aliasing && saved_flag_strict_aliasing && optimize >= 2)
+     || (flag_strict_aliasing && !saved_flag_strict_aliasing && optimize < 2))
+    warning (OPT_Wattributes,
+             "-f(no-)strict-aliasing option in optimize attribute ignored");
+
   /* Don't allow changing -fstrict-aliasing.  */
   flag_strict_aliasing = saved_flag_strict_aliasing;