This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH]: issue warning about -f(no-)strict-aliasing in function optimize attribute
On Wed, Nov 10, 2010 at 6:30 PM, Bingfeng Mei <firstname.lastname@example.org> 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.
>> -----Original Message-----
>> From: Richard Guenther [mailto:email@example.com]
>> Sent: 10 November 2010 16:55
>> To: Bingfeng Mei
>> Cc: firstname.lastname@example.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 <email@example.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-
>> > Should I also warn that (will make some existing tests fail), or make
>> > an exception? This patch ignores such case.
>> > Bootstrapped and tested with x86_64-unknown-linux-gnu.
>> > Thanks,
>> > Bingfeng Mei
>> > 2010-11-10 ?Bingfeng Mei ?<firstname.lastname@example.org>
>> > ? ? ? ?* c-family/c-common.c (parse_optimize_options): Issue warning
>> > ? ? ? ?-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-
>> > + ? ?Issue a warning under such case.
>> > + ? ?Ignore cases where difference is caused by different
>> > + ? ?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
>> > +
>> > ? /* 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.