[llvm-bugs] [Bug 26127] New: miscompilation with -O wrong branch taken

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 13 03:13:53 PST 2016


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

            Bug ID: 26127
           Summary: miscompilation with -O wrong branch taken
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: Vasilis.Vlachoudis at cern.ch
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

In my program that compiles and runs with gcc with clang++ 3.7 on Fedora 23 it
fails on the following fraction of the code.

        if (Abs(g) < Abs(f)) {
            c1 = 0.0;
            c4 = -c / (2.0*f);
        } else {
            c1 = -c / (2.0*g);
            c4 = 0.0;
        }

with g=-0.5, f=0.0  (doubles)
however it selects the upper branch and it makes a division by zero when
evaluating the c4.
When I switch off optimization it runs with no problem.
When I add a
    printf("g=%g f=%g\n",g,f);
it also runs with no problem.

The Abs() is declared as
/* --- Abs --- */
template <class T>
inline T Abs(const T& a) {
    return (a<0) ? -a : a;
}
#include <math.h>
// Partial specializations
template <>
inline double Abs(const double& a) {
    return fabs(a);
}
template <>
inline float Abs(const float& a) {
    return fabsf(a);
}

I've tried to extract only the portion of the code that crashes, but all my
attempts failed. I can only reproduce it with the whole code.

In case it is necessary I can provide you the svn to download the code and a
test example.

-- 
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/20160113/055298f2/attachment.html>


More information about the llvm-bugs mailing list