[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:15 PDT 2026
================
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-unknown \
+// RUN: -fmax-init-list-elements=4 %s
+
+int designated_at_limit[] = { [3] = 1 };
+_Static_assert(sizeof(designated_at_limit) / sizeof(int) == 4, "");
+
+int range_at_limit[] = { [1 ... 3] = 1 };
+_Static_assert(sizeof(range_at_limit) / sizeof(int) == 4, "");
+
+int designated_over_limit[] = {
+ [4] = 1, // expected-error {{array is too large (5 elements)}}
----------------
AaronBallman wrote:
Agreed, the diagnostic should help the user understand why the array is too large. Maybe something like:
`array is too large (5 elements, '-fmax-init-list-elements' is 4)` or similar?
And if nothing is specified on the command line, perhaps that's a different diagnostic along the lines of `array designated initializer too large to support` or something? It's not that we can't support it, it's that we choose not to?
https://github.com/llvm/llvm-project/pull/205503
More information about the cfe-commits
mailing list