On 27/02/2026 18:51, Martin Uecker via Gcc wrote:
Am Freitag, dem 27.02.2026 um 12:42 -0500 schrieb Yair Lenga via Gcc:
Greetings!
I'm happy to see discussion (including opposing/disagreeing opinions
!) on my proposal.
Wanted to cover one of the side-item in separate email - specifically
keeping -Wvla-larger-than not impacted by the proposed [[gnu::vla]]
In my projects, we use -Wvla and -Wvla-larger-than=512000 (~1MB, given
512000 bytes is about half a MB, surely?
each of our threads is configured for 5MB thread. This is the same
setting we for frame-larger-than.
Common scenario we have is:
// In header.h
#define MAX_POINTS 25000
// In code
int foo(void)
{
int n = MAX_POINTS ;
ALLOW_VLA(int v[n+1] ) ; // ALLOW_VLA uses Pragma to ignore -Wvla
}
The "ALLOW_VLA" indicate that the usage was reviewed - and approved.
Out of curiosity, what would are the criteria for this being allowed
or not? Or in other words, what is the actual use case you are
trying to address?
BTW: this code would always cause a warning with -Wvla-larger-than=, so
I assume it actually looks a bit different.
No, it does not trigger a warning with those values. (It will if
someone changes MAX_POINTS to 250000, but that's the point of the
-Wvla-larger-than=512000.)
<https://godbolt.org/z/xPo7ocWfr>
One thing I have noticed about all this is the weird error messages.
With the code "foo" above, but the -Wvla warning enabled, the error
message is :
"""
warning: ISO C90 forbids variable length array 'v' [-Wla]
"""
That is despite using -std=c23.
Even stranger, it changes when using "const int n = MAX_POINTS;" (in
code like this, "n" should be declared "const") :
"""
warning: ISO C90 forbids array 'v' whose size cannot be evaluated [-Wla]
"""
The same warning is given if "const int n = MAX_POINTS;" is moved to
file-scope - even though that requires that the initialiser for "n" can
not only be evaluated, but must be a constant expression and the
compiler knows the value of "n" can never be changed (without UB).
So there is scope for improvement on the wording of the warnings here!
With C23, it would (IMHO) be more natural to use "constexpr int" rather
than #define for MAX_POINTS and also for the "n", rendering the array
"v" a normal array rather than a VLA. Prior to C23, my preference for
these kinds of values is "enum { MAX_POINTS = 25000 };" and perhaps even
"enum { n = MAX_POINTS };" - again, that gives normal C arrays and not VLAs.
I am at a loss to understand why someone would want to make the VLA
stand out here and be covered by a warning, when slight changes to the
definition of "n" give the same effects but with a normal C array.
David
Martin
Common issue that we have is that the header.h is modified -> #define
MAX_POINTS 250000. The compiler does not warn on the VLA use - because
we tagged it safe. Keeping -Wvla-larger-than=500KB allow us to be
notified when of places where VLA usage is valid, but exceeds the
threshold.
Hope this use case is clean - and explain why I believe
-Wvla-larger-than should NOT be impacted with the proposed [[gnu::lva]
Regards,
Yair