[llvm-bugs] [Bug 51848] New: 0-sized array has size 0 in generated assembly, has identical address to other objects

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 14 07:54:37 PDT 2021


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: unassignedclangbugs at nondot.org
          Reporter: cuoq at trust-in-soft.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210914/96da253b/attachment.html>


More information about the llvm-bugs mailing list