<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 - 0-sized array has size 0 in generated assembly, has identical address to other objects"
href="https://bugs.llvm.org/show_bug.cgi?id=51848">51848</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>0-sized array has size 0 in generated assembly, has identical address to other objects
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>12.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>C
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>cuoq@trust-in-soft.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>GCC offers an ill thought-out extension allowing arrays of size zero. In their
defense it was necessary to offer something before C99 standardized Flexible
Array Members, but GCC does not apply the restrictions applicable to FAMs to
zero-sized arrays, so that the following program is accepted by GCC and by
Clang:
#include <stdint.h>
#include <stdio.h>
int t[0];
int u[0];
int main(void) {
printf("%llx %llx %d\n", (unsigned long long)u, (unsigned long long)t,
u==t);
}
Compiler Explorer link: <a href="https://godbolt.org/z/Yq855sqnz">https://godbolt.org/z/Yq855sqnz</a>
The assembly generated by GCC on x86-64 shows:
t:
.zero 1
u:
.zero 1
On the other hand the assembly generated by Clang 12.0.1 shows:
u:
t:
This has the unfortunate effect of making the generated binary print, for
instance, when you execute it:
404034 404034 1
Meanwhile Clang emits the following warning during the compilation:
<source>:8:77: warning: array comparison always evaluates to false
[-Wtautological-compare]
Since arrays of size 0 are an extension, Clang can be a standard compiler while
doing absolutely what it likes with them, but if Clang's behavior here is as
intended, then the emitted warning is spurious and misleading.</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>