<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 CODE: bad integer conversion at -O1/-Og"
href="https://bugs.llvm.org/show_bug.cgi?id=51519">51519</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>WRONG CODE: bad integer conversion at -O1/-Og
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</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>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>paulsson@linux.vnet.ibm.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>This program involves a conversion from signed to unsigned and then back again,
which should be well-defined. I understand that llvm should follow gccs
bahaviour found here:
<a href="https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html#Integers-implementation">https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html#Integers-implementation</a>.
It seems to print '1' typically, except at -O1 (and -Og) for some reason:
gcc -march=z13 -O0 wrong0.i -o a.out -w; ./a.out
1
clang -march=arch13 -O2 wrong0.i -o a.out -w; ./a.out
1
clang -march=arch13 -O1 wrong0.i -o a.out -w; ./a.out
0
This was run on SystemZ, but it should probably run the same on other
architectures...
long a, e;
long *b = &a;
int c, d;
int main() {
int f = -1452951746;
long *g = &e;
h:
i:
if (((0 != 8) != (*g = (f >= (-(unsigned)f)))) || b)
;
else {
int j;
for (; 7;) {
char k;
d = 0;
for (; d; d--)
for (; c;)
f = 0;
for (; 0;)
goto h;
if (c)
goto i;
b = 0;
}
}
printf("%d\n", ((int) e));
}</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>