Paul Eggert <egg...@cs.ucla.edu> writes: > On 06/20/2012 10:43 AM, Simon Josefsson wrote: > >> Has this test worked on any 32-bit time_t machines? > > Sure, lots. > >> 190112132045.51 return value mismatch: got 0, expected 1 >> >> and that time corresponds to (time_t) -1. Any ideas? > > That time is corresponds to -2147483649 > (i.e., -2**31 - 1), not to -1.
Right. > On a host with 32-bit signed time_t, that test > case should be filtered out by this code: > > if (! (TYPE_MINIMUM (time_t) <= T[i].t_expected > && T[i].t_expected <= TYPE_MAXIMUM (time_t))) > { > printf ("skipping %s: result is out of range of your time_t\n", > T[i].in); > continue; > } > > because TYPE_MINIMUM (time_t) should evaluate to > -2**31, which is greater than -2**31 - 1. > > Conversely, that filter did *not* work for > 190112132045.52 (i.e., -2**31), as it complained > that the result is out of your time_t range, but > it is in range. > > Can you debug the program to see why the filter isn't > working? Perhaps disassemble it? I wouldn't be surprised > if it were a compiler bug. The reason was that the int64_t in T[i].t_expected initialized via this line: { "190112132045.51", 13, 1, -2147483649}, /* Fri Dec 13 20:45:51 1901 */ got the value 2147483647. Reproduce like this: root@glmega:~# cat foo.c #include <stdint.h> #include <stdio.h> int main (void) { int64_t i = -2147483649; printf ("i %lld\n", i); return 0; } root@glmega:~# gcc -o foo foo.c foo.c: In function ‘main’: foo.c:7:3: warning: this decimal constant is unsigned only in ISO C90 [enabled by default] root@glmega:~# ./foo i 2147483647 root@glmega:~# Interestingly, the following works fine and yields no warning. root@glmega:~# cat foo.c #include <stdint.h> #include <stdio.h> int main (void) { int64_t i = -62167219200; printf ("i %lld\n", i); return 0; } root@glmega:~# gcc -o foo foo.c root@glmega:~# ./foo i -62167219200 root@glmega:~# Experimenting, it seems values between -2^31-1 and -2^32-1 inclusive trigger this while -2^32 leads to no warning. Changing the line into { "190112132045.51", 13, 1, -2147483649LL}, /* Fri Dec 13 20:45:51 1901 */ makes the self-test work. /Simon