Re: bug#7928: mktime test in configure: UB resulting in infinite loop

2011-01-30 Thread Paul Eggert
On 01/27/2011 11:42 PM, Paul Eggert wrote: > If it could be done just as clearly by other means, that would > be OK too. To try to do that, I installed the following: --- ChangeLog| 13 + lib/intprops.h |4 ++-- lib/mktime.c |2 +- lib/strtol.c

Re: bug#7928: mktime test in configure: UB resulting in infinite loop

2011-01-28 Thread Rich Felker
On Fri, Jan 28, 2011 at 06:57:22PM +0100, Bruno Haible wrote: > Rich Felker wrote: > > Testing which of the three allowable signed integer > > representations is used is easy: compare ~(t)1 against and -(t)1 and > > -(t)2. > > Testing which of the three signed integer representations is in use > i

Re: bug#7928: mktime test in configure: UB resulting in infinite loop

2011-01-28 Thread Bruno Haible
Rich Felker wrote: > Testing which of the three allowable signed integer > representations is used is easy: compare ~(t)1 against and -(t)1 and > -(t)2. Testing which of the three signed integer representations is in use is not even needed: Your formula t) 1 << (sizeof (t) * CHAR_BIT - 2)) -

Re: bug#7928: mktime test in configure: UB resulting in infinite loop

2011-01-28 Thread Rich Felker
On Thu, Jan 27, 2011 at 11:42:25PM -0800, Paul Eggert wrote: > On 01/27/2011 02:08 PM, Rich Felker wrote: > > I mean to say that left-shifting a negative value *at all* is > > undefined behavior. I doubt gcc will ever break it, but why not use my > > version of the code that's 100% safe and never i

Re: bug#7928: mktime test in configure: UB resulting in infinite loop

2011-01-28 Thread Paul Eggert
On 01/27/2011 02:08 PM, Rich Felker wrote: > I mean to say that left-shifting a negative value *at all* is > undefined behavior. I doubt gcc will ever break it, but why not use my > version of the code that's 100% safe and never invokes undefined > behavior? Your version of the code provokes simil

Re: bug#7928: mktime test in configure: UB resulting in infinite loop

2011-01-27 Thread Rich Felker
On Thu, Jan 27, 2011 at 07:42:10PM +0100, Bruno Haible wrote: > Do you mean to say that GCC produces undefined behaviour for shifts of > negative values, even those where the result is negative (no overflow)? > I've never seen a sign of that. I mean to say that left-shifting a negative value *at a

Re: bug#7928: mktime test in configure: UB resulting in infinite loop

2011-01-27 Thread Bruno Haible
Rich Felker wrote: > > # define TYPE_MAXIMUM(t) \ > > ((t) (! TYPE_SIGNED (t) \ > > ? (t) -1 \ > > : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1 > > The last line of this macro has UB due to signed integer overflow in > the << operation. No there is no overflow here. The ~ oper

Re: bug#7928: mktime test in configure: UB resulting in infinite loop

2011-01-27 Thread Paul Eggert
On 01/27/11 10:15, Eric Blake wrote: > In other words, the problem is not about overflow, but about undefined > behavior. You're right that the behavior is not defined, but this should not be a problem in practice, any more than the * CHAR_BIT business should be a problem in practice (that also re

Re: bug#7928: mktime test in configure: UB resulting in infinite loop

2011-01-27 Thread Eric Blake
On 01/27/2011 10:57 AM, Paul Eggert wrote: # define TYPE_MAXIMUM(t) \ ((t) (! TYPE_SIGNED (t) \ ? (t) -1 \ : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1 >> The last line of this macro has UB due to signed integer overflow in >> the << operation. > > No it doe

Re: bug#7928: mktime test in configure: UB resulting in infinite loop

2011-01-27 Thread Paul Eggert
On 01/27/11 09:28, Rich Felker wrote: > On Thu, Jan 27, 2011 at 08:14:56AM -0700, Eric Blake wrote: >> > # define TYPE_MINIMUM(t) \ >> > ((t) (! TYPE_SIGNED (t) \ >> > ? (t) 0 \ >> > : TYPE_SIGNED_MAGNITUDE (t) \ >> > ? ~ (t) 0 \ >> > : ~ (t) 0 << (sizeof (t) * CHA

Re: bug#7928: mktime test in configure: UB resulting in infinite loop

2011-01-27 Thread Rich Felker
On Thu, Jan 27, 2011 at 08:14:56AM -0700, Eric Blake wrote: > # define TYPE_MINIMUM(t) \ > ((t) (! TYPE_SIGNED (t) \ > ? (t) 0 \ > : TYPE_SIGNED_MAGNITUDE (t) \ > ? ~ (t) 0 \ > : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) > # define TYPE_MAXIMUM(t) \ > ((t) (! TYPE

Re: bug#7928: mktime test in configure: UB resulting in infinite loop

2011-01-27 Thread Eric Blake
[adding bug-gnulib, as requested] On 01/26/2011 10:21 PM, Rich Felker wrote: > The configure test for mktime (m4/mktime.m4) contains the following > code: > > for (;;) > { > t = (time_t_max << 1) + 1; > if (t <= time_t_max) > break; > time_t_max = t; > } > > T