<div dir="ltr">Mikael:<div><br></div><div>Building Erlang with --disable-fp-exceptions on 18.0-rc1 solved the problem.</div><div>Thanks for the pull request also.</div><div><br></div><div>Regards,</div><div>Kenji Rikitake</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, May 3, 2015 at 8:25 PM, Mikael Pettersson <span dir="ltr"><<a href="mailto:mikpelinux@gmail.com" target="_blank">mikpelinux@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Mikael Pettersson writes:<br>
> Mikael Pettersson writes:<br>
> > Kenji Rikitake writes:<br>
> > > Thanks Mikael for the confirmation.<br>
> > ><br>
> > > So can I conclude this as a bug or FPE handling<br>
> > > difference between gcc and clang?<br>
> ><br>
> > Yes. I have a reduced testcase in plain C99 which works with gcc<br>
> > but shows wrong behaviour when compiled by clang. It involves<br>
> > converting a double with value somewhere between INT64_MAX and<br>
> > UINT64_MAX to uint64_t: clang causes that to signal FP_INVALID.<br>
> ><br>
> > At the moment I'm trying to get confirmation about where the<br>
> > error lies: in the test case (i.e., the Erlang VM), or in clang.<br>
> > According to my reading of the C standard, clang is in error.<br>
><br>
> I've had a look in clang/llvm's bugzilla, and it's clear that clang/llvm<br>
> does not support FP exceptions in any way -- both due to backend bugs<br>
> and due to their middle-end being reckless. See e.g. PRs 17686, 22873,<br>
> and 8100.<br>
><br>
> I'll prepare a patch to force-disable FP exceptions if clang is detected.<br>
><br>
> /Mikael<br>
<br>
<a href="https://github.com/erlang/otp/pull/707" target="_blank">https://github.com/erlang/otp/pull/707</a><br>
<br>
<br>
><br>
> ><br>
> > For now, the workaround is to either compile with gcc, or to<br>
> > build with ./configure --disable-fp-exceptions.<br>
> ><br>
> > /Mikael<br>
> ><br>
> > > (I noticed on my OS X the *gcc-compiled* 18.0-rc1<br>
> > > didn't cause the problem either.)<br>
> > ><br>
> > > Regards,<br>
> > > Kenji Rikitake<br>
> > ><br>
> > > On Sat, May 2, 2015 at 3:04 AM, Mikael Pettersson <<a href="mailto:mikpelinux@gmail.com">mikpelinux@gmail.com</a>><br>
> > > wrote:<br>
> > ><br>
> > > > Kenji Rikitake writes:<br>
> > > > > Mikael:<br>
> > > > ><br>
> > > > > I managed to reduce the problem to a one-liner.<br>
> > > > > Executing<br>
> > > > > trunc(0.8 * (1 bsl 128))<br>
> > > > > will generate the SIGFPE.<br>
> > > ><br>
> > > > I can reproduce the SIGFPE on Linux/x86_64 by compiling OTP-18-rc1 with<br>
> > > > clang-3.6.0.<br>
> > > ><br>
> > > ><br>
> > > > ><br>
> > > > > I attached the gdb of FreeBSD 10.1-STABLE to the Erlang beam.smp and<br>
> > > > generated<br>
> > > > > the following output.<br>
> > > > > Regards,<br>
> > > > > Kenji Rikitake<br>
> > > > ><br>
> > > > > --- Erlang shell output:<br>
> > > > ><br>
> > > > > Erlang/OTP 18 [RELEASE CANDIDATE 1] [erts-7.0] [source-71bfef4]<br>
> > > > [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false] [dtrace]<br>
> > > > ><br>
> > > > > Eshell V7.0 (abort with ^G)<br>
> > > > > 1> trunc(0.8 * (1 bsl 128)).<br>
> > > > > %%% here FPE is issued and the gdb shows the value...<br>
> > > > > fpe_sig_action: FPE at 0x4ca1b7<br>
> > > > > 272225893536750785882272431128279252992<br>
> > > > > 2> trunc(0.8 * (1 bsl 128)).<br>
> > > > > ERTS_FP_CHECK_INIT at 0x571e60: detected unhandled FPE at<br>
> > > > 0x4cafpe_sig_action: FPE at 0x4ca1b7<br>
> > > > > 272225893536750785882272431128279252992<br>
> > > > > 3> q()<br>
> > > > > ok<br>
> > > > ><br>
> > > > > --- output of attached gdb:<br>
> > > > ><br>
> > > > > Continuing.<br>
> > > > ><br>
> > > > > Program received signal SIGFPE, Arithmetic exception.<br>
> > > > > [Switching to Thread 80240a000 (LWP 101243/beam.smp)]<br>
> > > > > double_to_integer (p=0x8031c0398, x=1.4757395258967642e+19) at<br>
> > > > beam/erl_bif_guard.c:302<br>
> > > > > 302 d = x; /* trunc */<br>
> > > > > Current language: auto; currently minimal<br>
> > > > > (gdb) print $mxcsr<br>
> > > > > $1 = 6401<br>
> > > > > (gdb) disassemble double_to_integer<br>
> > > > > Dump of assembler code for function double_to_integer:<br>
> > > > > [...]<br>
> > > > > 0x00000000004ca1b7 <double_to_integer+519>: cvttsd2siq %xmm1,%rcx<br>
> > > > > [...]<br>
> > > > > End of assembler dump.<br>
> > > > > (gdb) print $mxcsr<br>
> > > > > $3 = 6401<br>
> > > > > (gdb) print $xmm1<br>
> > > > > $4 = {f = {-1.58818684e-23, 467.199982, 0, 0}}<br>
> > > > > (gdb) print $rcx<br>
> > > > > $5 = -9223372036854775808<br>
> > > > ><br>
> > > > > [End of log]<br>
> > > > ><br>
> > > > > ++> Kenji Rikitake <<a href="mailto:kenji@k2r.org">kenji@k2r.org</a>> [2015-04-27 21:53:44 +0900]:<br>
> > > > > > Date: Mon, 27 Apr 2015 21:53:44 +0900<br>
> > > > > > From: Kenji Rikitake <<a href="mailto:kenji@k2r.org">kenji@k2r.org</a>><br>
> > > > > > To: Mikael Pettersson <<a href="mailto:mikpelinux@gmail.com">mikpelinux@gmail.com</a>><br>
> > > > > > Cc: <a href="mailto:erlang-bugs@erlang.org">erlang-bugs@erlang.org</a><br>
> > > > > > Subject: Re: [erlang-bugs] FreeBSD FPE issue on ERTS_FP_CHECK_INIT Re:<br>
> > > > > > ERTS_FP_CHECK_INIT error of HiPE in 18.0-rc1 running on FreeBSD<br>
> > > > > > 10.1-STABLE<br>
> > > > > ><br>
> > > > > > FYI:<br>
> > > > > > A reference on a similar issue on OS X:<br>
> > > > > > <a href="http://erlang.org/pipermail/erlang-bugs/2011-May/002383.html" target="_blank">http://erlang.org/pipermail/erlang-bugs/2011-May/002383.html</a><br>
> > > > > ><br>
> > > > > > The instruction caused the exception was "cvttsd2siq".<br>
> > > > > ><br>
> > > > > > Kenji Rikitake<br>
> > > > > ><br>
> > > > > > ++> Kenji Rikitake <<a href="mailto:kenji@k2r.org">kenji@k2r.org</a>> [2015-04-27 21:16:14 +0900]:<br>
> > > > > > > > Can you provide a disassembly of erts_gc_trunc_1 from this build?<br>
> > > > > > ><br>
> > > > > > > > Can you provide a disassembly of gc_double_to_integer from this<br>
> > > > build?<br>
> > > > > > ><br>
> > > > > > > I will send you personally (not on the list).<br>
> > > > > > _______________________________________________<br>
> > > > > > erlang-bugs mailing list<br>
> > > > > > <a href="mailto:erlang-bugs@erlang.org">erlang-bugs@erlang.org</a><br>
> > > > > > <a href="http://erlang.org/mailman/listinfo/erlang-bugs" target="_blank">http://erlang.org/mailman/listinfo/erlang-bugs</a><br>
> > > ><br>
> > > > --<br>
> > > ><br>
> ><br>
> > --<br>
><br>
> --<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
</font></span></blockquote></div><br></div>