[tree-ssa] Fix handling of undefined predicates in CCP [patch]

Fergus Henderson fjh@cs.mu.OZ.AU
Sun Apr 6 15:53:00 GMT 2003

On 06-Apr-2003, Diego Novillo <dnovillo@redhat.com> wrote:
> On Sun, 06 Apr 2003, Fergus Henderson wrote:
> > According to the C standard, this program has undefined behaviour.
> > So optimizing it to just "main() {}" is a valid optimization.
> Interesting.  So, if the program has a single undefined
> construct, the compiler is free to do any arbitrary
> transformations to it?

Yes, so long as the compiler can prove that the undefined construct
will be reached.  Or so long as it can prove that the undefined
construct will be reached if the code which is being transformed
is reached.

> Even if the construct is dead?

No.  If the problematic construct (the one which would have undefined
behaviour were it to be evaluated) is not reachable, then the behaviour
of the program is not undefined.  But in the test case which you posted,
the construct with undefined behaviour was always reached.

> In any case, I wasn't thinking about C in particular when I fixed
> the bug.

Good point.  The optimization is valid for C and C++, but it may
not be valid for other languages.

Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

More information about the Gcc-patches mailing list