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

Diego Novillo dnovillo@redhat.com
Sun Apr 6 15:25:00 GMT 2003


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?  Even if the construct is dead?

In any case, I wasn't thinking about C in particular when I fixed
the bug.  I was going for the principle of least surprise: If a
conditional expression has an undefined value at runtime, then
either branch may execute.  The previous behaviour was to assume
that neither branch would execute.

In this particular case, the assumption was causing the compiler
to optimize the whole function away, but if you put the undefined
conditional at the start of the function the result is reversed.
The optimizers do nothing.


> If GCC wants to provide guarantees beyond what the C standard guarantees,
> then IMHO these guarantees should be carefully documented.
> 
Well, if the test case is ill-formed, then it should probably be
discarded.  I don't know what the rules are for the testsuite,
but I guess having invalid programs is not a good idea.

Opinions?


Diego.



More information about the Gcc-patches mailing list