This is the mail archive of the gcc-patches@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: [tree-ssa] Fix handling of undefined predicates in CCP [patch]


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.


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