Hello all,

mktime() function test can't be passed with gcc 4.3.0. With this version of 
gcc, the
following loop (which exploits an integer overflow) will never exited (with -O2 
and above):

...
for (j = 1; 0 < j; j *= 2)
  if (! bigtime_test (j))
    return 1;
...

Consider the following program:

#include <stdio.h>

int
main ()
{
  int j;

  for (j = 1; j > 0; j *= 2)
    printf ("%d\n", j);
}

With '-O2' it gives:

1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
131072
262144
524288
1048576
2097152
4194304
8388608
16777216
33554432
67108864
134217728
268435456
536870912
1073741824
-2147483648
0
0
0
[loop forever with 0]
...

But with '-O2 -fno-tree-vrp', it works as expected:

1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
131072
262144
524288
1048576
2097152
4194304
8388608
16777216
33554432
67108864
134217728
268435456
536870912
1073741824

This looks a bit surprisingly, but GCC developers says 
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35581)
that this is normal behavior since integer overflow is undefined.

I would like to see a warning from the compiler here, but unfortunately this is 
not the case for now.

Dmitry



Reply via email to