https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97393
Bug ID: 97393
Summary: missing -Walloca-larger-than on an excessive range
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
The call to malloc with the excessively large argument in f2 is diagnosed but
the call to alloca fails to trigger the corresponding warning in f0.
$ cat z.c && gcc -O2 -S -Wall z.c
void f0 (void*);
void f1 (int n)
{
if (n >= 0) n = -1;
f0 (__builtin_alloca (n * sizeof (int))); // missing warning
}
void f2 (int n)
{
if (n >= 0) n = -1;
f0 (__builtin_malloc (n * sizeof (int))); // warning (good)
}
z.c: In function ‘f2’:
z.c:12:3: warning: argument 1 range [18446744065119617024,
18446744073709551612] exceeds maximum object size 9223372036854775807
[-Walloc-size-larger-than=]
12 | f0 (__builtin_malloc (n * sizeof (int))); // warning (good)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
z.c:12:3: note: in a call to built-in allocation function ‘__builtin_malloc’