This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Fix handling of undefined predicates in CCP [patch]
- From: Fergus Henderson <fjh at cs dot mu dot OZ dot AU>
- To: Diego Novillo <dnovillo at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sun, 6 Apr 2003 13:20:38 +1000
- Subject: Re: [tree-ssa] Fix handling of undefined predicates in CCP [patch]
- References: <20030405151742.GB24328@tornado.toronto.redhat.com>
On 05-Apr-2003, Diego Novillo <dnovillo at redhat dot com> wrote:
> Fixes the bug exposed by this program:
>
> -----------------------------------------------------------------------------
> 1 main()
> 2 {
> 3 int i, j, k;
> 4
> 5 k = 0;
> 6 while (k < 10)
> 7 {
> 8 k++;
> 9 if (j > i)
> 10 j = 5;
> 11 else
> 12 j =3;
> 13 }
> 14
> 15 if (k != 10)
> 16 abort ();
> 17
> 18 return 0;
> 19 }
> -----------------------------------------------------------------------------
>
> Neither 'i' nor 'j' are ever initialized. This causes the if()
> at line 9 to be considered undefined. For some reason I can't
> really explain, I had added a short circuit in CCP that would
> cause it not to follow the edges coming out of undefined
> conditional expressions.
>
> This made the whole graph below the if() to be considered
> unreachable, which caused the program to implode into:
>
> -----------------------------------------------------------------------------
> main()
> {
> }
> -----------------------------------------------------------------------------
According to the C standard, this program has undefined behaviour.
So optimizing it to just "main() {}" is a valid optimization.
If GCC wants to provide guarantees beyond what the C standard guarantees,
then IMHO these guarantees should be carefully documented.
--
Fergus Henderson <fjh at cs dot mu dot oz dot 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.