<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 - Clang miscompiles with -O0."
href="https://bugs.llvm.org/show_bug.cgi?id=36629">36629</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang miscompiles with -O0.
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@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=20013" name="attach_20013" title="Reproducer.">attachment 20013</a> <a href="attachment.cgi?id=20013&action=edit" title="Reproducer.">[details]</a></span>
Reproducer.
Reduced reproducer (see full in attachment):
<span class="quote">>$ cat repr.cpp</span >
#include <stdio.h>
#include <vector>
struct struct_1 {
signed char member_1_0 : 23;
unsigned char : 16;
unsigned char member_1_1 : 25;
};
const unsigned char aa = 60;
const unsigned char bb = 246;
signed char cc = 36;
signed char dd = 97;
unsigned char ee = 178;
struct_1 struct_obj_1;
short a = 42;
void tf_0_foo() {
ee = a % (unsigned char)((bb && aa ? ~0 : 0) % struct_obj_1.member_1_0 ^ cc);
dd = struct_obj_1.member_1_1;
}
int main() {
struct_obj_1.member_1_0 = -122;
struct_obj_1.member_1_1 = 98;
tf_0_foo();
printf("%d\n", (int)ee);
}
Error:
<span class="quote">>$ clang++ -fsanitize=undefined -fno-sanitize-recover=undefined -Werror=uninitialized -Werror=implicitly-unsigned-literal -O0 -w repr.cpp ; ./a.out</span >
42
<span class="quote">>$ clang++ -w -O0 repr.cpp ; ./a.out</span >
5
LLVM version:
<span class="quote">>$ clang++ -v</span >
clang version 7.0.0 (trunk 326547)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /llvm/bin-trunk/bin
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.8.5
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>