[cfe-dev] SIGFPE received when a program is compiled with Clang but not with GCC

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Wed Nov 18 19:19:06 PST 2015


On Wed, Nov 18, 2015 at 7:04 PM, Shriramana Sharma <samjnaa at gmail.com>
wrote:

> On 11/19/15, Reid Kleckner <rnk at google.com> wrote:
> > LLVM believes that floating point division will never trap, and
> speculates
> > it to make code like this:
> > float tmp = 1.0 / scale;
> > scale = scale == 0.0 ? scale : tmp;
>
> I don't get it. In what way is the above code more efficient than:
>
> if (scale != 0) scale = 1 / scale;
>
> ... that the compiler should replace this with that?
>
> > Normally, FP division produces NaN. The only way that I'm aware of to
> make
> > FP div trap is to use fenv.h, which isn't supported:
> > https://llvm.org/bugs/show_bug.cgi?id=8100
>
> But the code above is perfectly legal, logical and safe C/C++ code,
> and that Clang doesn't support it (in the sense of emitting code that
> causes a SIGFPE when one isn't warranted) *is* a bug, no?
>

We support the code you listed, but we don't support configuring your
processor to make FP divide by zero trap.

I'm not making a value judgement on what LLVM does here, I'm just relaying
the facts.


> And it doesn't seem to be per se a dup of the bug you mention above
> (in which case I should report it separately) or is it?


This bug has been reported enough times that it's probably worth having one
just for speculation of FP divide. There might already be one there in the
list of dupes that we could split off.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151118/76733a18/attachment.html>


More information about the cfe-dev mailing list