<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 optimization of comparison of addresses of empty structs"
href="https://bugs.llvm.org/show_bug.cgi?id=44508">44508</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Wrong optimization of comparison of addresses of empty structs
</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>ch3root@openwall.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Wrong optimization of comparison of addresses of empty structs:
----------------------------------------------------------------------
#include <stdio.h>
int main()
{
struct {} x, y;
void *p = &x;
void *q = &y;
printf("eq1: %d\n", p == q);
unsigned long u = (unsigned long)p;
unsigned long v = (unsigned long)q;
printf("diff: %lu\n", u - v);
printf("eq2: %d\n", u == v);
}
----------------------------------------------------------------------
$ clang -std=c11 -Wall -O3 test.c && ./a.out
eq1: 0
diff: 0
eq2: 0
----------------------------------------------------------------------
clang x86-64 version: clang version 10.0.0
(<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
8647a72c4a52e0386c0397ce3fbd38121c18b873)
----------------------------------------------------------------------
Empty structs is a gcc extension (they are UB according to C11, 6.7.2.1p8) but,
nevertheless, I think zero `diff` should imply non-zero eq2 and eq1.</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>