https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121257
Bug ID: 121257
Summary: vla-larger-than warns for negative sizes
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: uecker at gcc dot gnu.org
Target Milestone: ---
In code like this, I get a warning with -O2 -Wvla-larger-than=1024
int g(void*);
int f(int n)
{
if (n > 100) return -1;
int a[n];
return g(a);
}
This is not wrong and goes away with
if (n < 0 || n > 100) return -1;
by using unsigned int, or by using "-fsanitize=bounds
-fsanitize-undefined-trap-on-error",
but is confusing and not the ideal user experience.
Probably, the warning should be split into "-Wvla-size-maybe-negative" and
"-Wvla-larger-than="