<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 - opt miscompiles with "opt -O3 -gvn-hoist""
href="https://bugs.llvm.org/show_bug.cgi?id=37791">37791</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>opt miscompiles with "opt -O3 -gvn-hoist"
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>Vsevolod.Livinskij@frtk.ru
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=20423" name="attach_20423" title="Reproducer.">attachment 20423</a> <a href="attachment.cgi?id=20423&action=edit" title="Reproducer.">[details]</a></span>
Reproducer.
Opt produces incorrect code that crashes with FPE at runtime.
Opt-bisect-limit points to " Early GVN Hoisting of Expressions"
Reproducer is relatively large, but I can't reduce it further.
Reproducer (also in attachement):
<span class="quote">>$ cat func.cpp</span >
#include "init.h"
void tf_0_foo() {
if (tf_0_var_20 + tf_0_array_1.at(5).member_2_4 % tf_0_array_2[3].member_2_1)
tf_0_var_106 = 0;
tf_0_var_1274 =
(tf_0_array_1.at(1).member_2_1 | tf_0_array_2[1].member_2_1 - 50874) /
unsigned(~tf_0_var_10 + 3 || tf_0_array_2[3].member_2_1 ||
tf_0_var_44) -
(~tf_0_var_10 + 3 || tf_0_array_2[3].member_2_1 || tf_0_var_44) -
tf_0_var_44 + tf_0_array_1.at(5).member_2_4;
tf_0_var_1276 =
((tf_0_array_1.at(1).member_2_1 | tf_0_array_2[1].member_2_1 - 50874) /
unsigned(~tf_0_var_10 + 3 || tf_0_array_2[3].member_2_1 ||
tf_0_var_44) -
(tf_0_array_1.at(1).member_2_1 |
tf_0_array_2[1].member_2_1 - 50874) /
unsigned(~tf_0_var_10 + 3 || tf_0_array_2[3].member_2_1 ||
tf_0_var_44) +
(tf_0_var_20 - 3) ==
50) /
(~tf_0_var_10 + 3 || tf_0_array_2[3].member_2_1 ||
tf_0_var_10 + tf_0_array_2[3].member_2_1);
}
<span class="quote">>$ cat driver.cpp</span >
#include <stdio.h>
#include "init.h"
const unsigned tf_0_var_10 = 6;
bool tf_0_var_20, tf_0_var_44, tf_0_var_106 ;
unsigned short tf_0_var_1274 ;
unsigned tf_0_var_1276 ;
std::vector<tf_0_struct_2> tf_0_array_1 {{} , {} , {} , {} , {} , {} };
std::vector<tf_0_struct_2> tf_0_array_2 {{} , {} , {} , {true} };
void tf_0_foo ();
int main () {
tf_0_foo ();
}
<span class="quote">>$ cat init.h</span >
#include <vector>
extern const unsigned tf_0_var_10;
extern bool tf_0_var_20;
extern bool tf_0_var_44;
extern bool tf_0_var_106;
extern unsigned short tf_0_var_1274;
extern unsigned tf_0_var_1276;
struct tf_0_struct_2 {
bool member_2_1;
int member_2_4;
};
extern std::vector<tf_0_struct_2> tf_0_array_1;
extern std::vector<tf_0_struct_2> tf_0_array_2;
Error:
<span class="quote">>$ clang++ -O3 -Xclang -disable-llvm-optzns -emit-llvm -c -o func.bc func.cpp
>$ opt -O3 -o func.ll func.bc -gvn-hoist
>$ clang++ -c -o func.o func.ll
>$ clang++ driver.cpp func.o
>$ ./a.out</span >
Floating point exception (core dumped)
LLVM version:
clang version 7.0.0 (trunk 334571) (llvm/trunk 334570)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /llvm/bin-trunk/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64</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>