<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Wrong compilation bug - probably compiler assumes variables are independent"
href="https://bugs.llvm.org/show_bug.cgi?id=38532">38532</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Wrong compilation bug - probably compiler assumes variables are independent
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>6.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>smile.wave@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>During the C++ program development at work, I think I have discovered a bug in
compilation. I will describe it shortly, please tell me how to provide you more
information.
function main() {
float x[512] = 1.0;
uint32_t* x_uint = reinterpret_cast<uint32_t*>(x);
do_magic_1(x, x_uint);
do_magic_2(x, x_uint);
do_magic_3(x, x_uint);
}
/** This function does not work as expected */
function do_magic_1(float* x, uint32_t* x_uint) {
/* the rest of the code */
}
/** This function works as expected */
function do_magic_2(float* x, uint32_t* x_uint) {
x_uint = reinterpret_cast<uint32_t*>(x);
/* the rest of the code */
}
/** This function works as expected */
function do_magic_3(float* x, uint32_t* x_uint) {
/* the rest of the code */
std::cout << x_uint[0] << std::endl;
/* the rest of the code */
}
I use the same pointers for x and x_uint, because I developed a function with
the same trick as "Fast inverse square root", which assumes floating point in
IEEE 754 format, and performs boolean (not, xor) operations on it. I compile
with -O3 flag.</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>