This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Clarification on Gcc's strict aliasing rules


Francis Moreau <francis.moro@gmail.com> writes:

> I mean that I find quite dangerous that a program can subtly break (or
> behave differently) depending on the optimisation level.

I think it's important to say clearly that only an invalid program can
subtly behave differently.  A valid program will work correctly at all
optimization levels.

> For example a user can rely on aliasing undefined behaviour (one reason
> is that is simply not aware of this fact), compile its program with no
> optimisation level, do some testings and find no problem so far. Then
> increase the level of optimisation and then the program start to behave
> incorrectly. I guess he's going to spend some time before discovering
> what's going on.
>
> Specially since no warnings can pop up with -O2 for example.

It is unfortunately very difficult to issue correct warnings for these
cases.  That's why -Wstrict-aliasing is optional: it produces both false
positives and false negatives.

>> Would you be helped if there was an example (or two) of the basic
>> problem first?
>
> An exhaustive list would be better I think.

I don't know how to write an exhaustive list except in terms of
optimizations that are not performed.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]