[clang] [clang][Sema] Avoid out-of-memory crash on huge designated initializer indices (PR #205503)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 10 05:00:19 PDT 2026
AaronBallman wrote:
> LLVM can handle IR like the following without ever explicitly allocating memory for the array:
>
> ```
> @g = global {[1000000000000 x i32], i32} {[1000000000000 x i32] zeroinitializer, i32 3}
> ```
>
> Of course, you hit an out-of-disk-space error if you try to compile this to an object file.
Thanks! Yeah, this is the "kicking the can down the road" problem I was worried about. We'll avoid the OOM from Clang, but once LLVM is processing the IR into an object file, it'll just OOM again.
One thing I'm concerned by is why we should have this for designated initializers but not array declarations in general. I would expect all of these to have effectively the same behavior regarding being too big of an array to support:
```
int array1[0x80000000];
int array2[0x80000000] = { 0 };
int array3[] = { [0x80000000 - 1] = 0 };
```
So I'm basically worried that `-fmax-init-list-elements` is too narrow of an option and we should be thinking about a more general flag, if any. What do others think?
https://github.com/llvm/llvm-project/pull/205503
More information about the cfe-commits
mailing list