https://bugs.llvm.org/show_bug.cgi?id=51848
Bug ID: 51848
Summary: 0-sized array has size 0 in generated assembly, has
identical address to other objects
Product: clang
Version: 12.0
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: C
Assignee: unassignedclangb...@nondot.org
Reporter: c...@trust-in-soft.com
CC: blitzrak...@gmail.com, dgre...@apple.com,
erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
richard-l...@metafoo.co.uk
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: https://godbolt.org/z/Yq855sqnz
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs