[llvm-bugs] [Bug 25572] New: SIGFPE received when a program is compiled with Clang but not with GCC

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 18 19:42:24 PST 2015


https://llvm.org/bugs/show_bug.cgi?id=25572

            Bug ID: 25572
           Summary: SIGFPE received when a program is compiled with Clang
                    but not with GCC
           Product: new-bugs
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: samjnaa at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 15314
  --> https://llvm.org/bugs/attachment.cgi?id=15314&action=edit
Script to download and build Asymptote on a Debian-based system

Refer discussion on cfe-dev:
http://lists.llvm.org/pipermail/cfe-dev/2015-November/046154.html

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: https://packages.debian.org/sid/asymptote

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:
https://llvm.org/bugs/show_bug.cgi?id=8100

--

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);
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151119/d9240f69/attachment.html>


More information about the llvm-bugs mailing list