Re: new clang report - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: new clang report
Date
Msg-id 1304622769.1250.5.camel@vanquo.pezone.net
Whole thread Raw
In response to Re: new clang report  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: new clang report  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On mån, 2011-05-02 at 14:45 -0400, Tom Lane wrote:
> > So issue here is actually that clang has an option
> 
> >        -fmath-errno
> >            Indicate that math functions should be treated as
> updating errno.
> 
> Really?  It looks to me like the issue is that pow() is returning NaN
> instead of Inf for an out-of-range result.  That's a bug: the correct
> result is *not* ill-defined, it's simply too large to represent.
> If that has anything to do with errno, it's an implementation artifact
> that's unrelated to the claimed meaning of the switch.
> 
> But I would also note that the Single Unix Spec is unequivocal about
> this case:
> 
>         If the correct value would cause overflow, +-HUGE_VAL is
>         returned, and errno is set to [ERANGE].
> 
> That's "IS set", not "may be set" as in some other cases.  So this
> behavior should not depend on any such compiler switch anyway, unless
> the intent of the switch is "ignore the standard and do whatever we
> feel like".

Well, the intent of the switch actually appears to be rather "follow the
standard and do what it says" with the default behavior being the
questionable one.  So we could easily settle on that you need to use
that switch, otherwise it's not supported.  (This is actually quite
similar to the old days when some systems had -ffast-math the default.)

Btw., when you build a simple test program in the default mode, pow()
indeed returns Inf on overflow.  There appear to be some code generation
or optimization problems when it builds the postgres code, because the
problem goes away with either -O0 or by inserting an elog or something
like that after the pow() call.




pgsql-hackers by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: Visibility map and hint bits
Next
From: Merlin Moncure
Date:
Subject: Re: Visibility map and hint bits