<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - SIGFPE received when a program is compiled with Clang but not with GCC"
href="https://llvm.org/bugs/show_bug.cgi?id=25572">25572</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>SIGFPE received when a program is compiled with Clang but not with GCC
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>3.7
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>samjnaa@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=15314" name="attach_15314" title="Script to download and build Asymptote on a Debian-based system">attachment 15314</a> <a href="attachment.cgi?id=15314&action=edit" title="Script to download and build Asymptote on a Debian-based system">[details]</a></span>
Script to download and build Asymptote on a Debian-based system
Refer discussion on cfe-dev:
<a href="http://lists.llvm.org/pipermail/cfe-dev/2015-November/046154.html">http://lists.llvm.org/pipermail/cfe-dev/2015-November/046154.html</a>
I'm using Clang 3.7~svn251177-1~exp1 (from the Apt repo) on
Kubuntu Trusty 64 bit. I'm trying to backport Asymptote from Debian
Sid: <a href="https://packages.debian.org/sid/asymptote">https://packages.debian.org/sid/asymptote</a>
I find that the build fails with:
../asy -dir ../base -config "" -render=0 -f pdf -noprc filegraph.asy
../base/plain_Label.asy: 294.10: runtime: Floating point exception (core
dumped)
When I investigated this I found that there was no problem when
compiling with GCC.
Please note the attached script which should demonstrate the error.
Running the script with -g will compile using the "default" compiler
(gcc) and does not produce any error.
I used KDbg to debug the situation i.e. run the executable asy with
the given arguments which produced the error during the build and
found that at pair.h, line 148 reads:
if(scale != 0.0) scale=1.0/scale;
but it is at this point that despite the if() check, during one
particular invocation to pair unit(const pair&), somehow the program
is trying to do the division and getting the error.
Note that for some reason during debugging I keep getting SIGPWR,
SIGXCPU etc – I don't know why this is but it is perhaps because asy
implements a virtual machine which does not support debugging or such?
Anyhow, repeatedly trying to run the executable with the given
arguments produces the error in the end.
--
In reply to the above post, Reid Kleckner 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;
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:
<a class="bz_bug_link
bz_status_NEW "
title="NEW --- - clang/llvm don't support C99 FP rounding mode pragmas (FENV_ACCESS etc)"
href="show_bug.cgi?id=8100">https://llvm.org/bugs/show_bug.cgi?id=8100</a>
--
Note that I'm not able to reproduce the bug with minimal cases like the below,
so I'm not sure why it occurs only with the Asymptote sources, but the source
code in question is certainly valid and safely programmed C++ so it should not
cause any error/exception.
Minimal case:
#include <cmath>
#include <cstdio>
struct pair
{
pair(double x_, double y_) : x(x_), y(y_) {}
double x, y;
double length() const { return hypot(x, y); }
};
pair unit(const pair & z)
{
double scale = z.length();
if (scale != 0.0) scale = 1.0 / scale;
return pair(z.x * scale, z.y * scale);
}
int main()
{
pair o = unit(pair(0, 0));
printf("%f %f\n", o.x, o.y);
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>