<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 --- - miscompilation with -O wrong branch taken"
href="https://llvm.org/bugs/show_bug.cgi?id=26127">26127</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>miscompilation with -O wrong branch taken
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</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>release blocker
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>Vasilis.Vlachoudis@cern.ch
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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.</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>