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

Shriramana Sharma via cfe-dev cfe-dev at lists.llvm.org
Wed Nov 18 19:04:28 PST 2015


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?

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?

-- 
Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा



More information about the cfe-dev mailing list