<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57353>57353</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect initialization of global arrays that are 2^32 bytes or larger
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nlsandler
</td>
</tr>
</table>
<pre>
C programs with partially initialized arrays that are larger than 2^32 bytes aren't compiled correctly:
* `char` arrays get initialized entirely to zero, even if they have a non-zero initializer in the original source code
* when initializing arrays of other types, LLVM emits a `.space` or `.zero` directive with a negative byte count, which is rejected by the assembler.
```C
char bad_char[4294967296] = {1};
char ok_char[4294967295u] = {1};
int bad_int[1073741824] = {1};
int ok_int[1073741823] = {1};
```
Compiling this with `clang -S -arch x86_64 bad_static_arrays.c` produces:
```asm
.section __TEXT,__text,regular,pure_instructions
.build_version macos, 10, 15 sdk_version 10, 15
.globl _bad_char ## @bad_char
.zerofill __DATA,__common,_bad_char,4294967296,4
.section __DATA,__data
.globl _ok_char ## @ok_char
.p2align 4
_ok_char:
.byte 1 ## 0x1
.space 4294967294
.globl _bad_int ## @bad_int
.p2align 4
_bad_int:
.long 1 ## 0x1
.space 4294967292
.space -4294967296
.globl _ok_int ## @ok_int
.p2align 4
_ok_int:
.long 1 ## 0x1
.space 4294967288
.subsections_via_symbols
```
That's from compiling with Clang 11.0, but it looks like the issue exists in the most recent version too: https://godbolt.org/z/eobvhbf7s
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVUuPozgQ_jXkYiUC8woHDun0jLTS7Glao7khGyrgbYMj26Q7_eun7ISEZDqzh92IgMt2VX315qo5lluy16rVrDfkTdiO7Jm2gkl5JGIQbiU-oCFMa3Y0xHbM4hqIZLoF7eiB0CD9ElPCjxaMOxwCmltSq34vJLLWSmuorTwG8SYIn4NwE9ANCbKw7pjGzyS7BXujEgYr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