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

From: Rich Felker <[email-masked]>
Date: Fri, 28 Jan 2011 12:37:59 -0500

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 invokes undefined
> > behavior?
> 
> Your version of the code provokes similar undefined behavior
> when computing TYPE_MINIMUM, which means that overall it's
> no more reliable than what's there now.  An advantage of
> the current approach is that there's a clear relationship
> between TYPE_MINIMUM and TYPE_MAXIMUM, and this aids understanding.
> If it could be done just as clearly by other means, that would
> be OK too.

My version only computes the maximum. The minimum is -max if the type
is sign/magnitude or ones complement and -max-1 if the type is twos
complement. Testing which of the three allowable signed integer
representations is used is easy: compare ~(t)1 against and -(t)1 and
-(t)2.

Rich