[Bug c/79010] New: -Wlarger-than ineffective for VLAs, alloca, malloc
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jan 5 23:15:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79010
Bug ID: 79010
Summary: -Wlarger-than ineffective for VLAs, alloca, malloc
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
The -Wlarger-than is documented to "Warn whenever an object of larger than len
bytes is defined." Setting aside the typo ("object of larger than") the option
doesn't has the advertised effect: it fails to warn when either a VLA object of
excessive size is created, or when such an object is created by a call to
alloca or malloc. (The warning for the unnamed array is also duplicated.)
For alloca there is -Walloca-larger-than, and for malloc and other allocation
functions there is -Walloc-size-larger-than, so -Walrger-than should either be
documented to have a limited effect or the option should also enable the other
two.
Either way, the typo in the manual should be corrected and the duplicate
warning suppressed.
$ cat b.c && gcc -DN=123456 -S -Wall -Wextra -Wpedantic -Wlarger-than=123 b.c
void sink (void*);
char a[N];
void farray (void)
{
char a[N];
sink (a);
}
void funnamed_array (void)
{
sink ((char[N]){ 0 });
}
void fvla (void)
{
int n = N;
char a[n];
sink (a);
}
void falloca (void)
{
void *a = __builtin_alloca (N);
sink (a);
}
void fmalloc (void)
{
void *a = __builtin_malloc (N);
sink (a);
}
b.c:3:6: warning: size of ‘a’ is 123456 bytes [-Wlarger-than=]
char a[N];
^
b.c: In function ‘farray’:
b.c:7:8: warning: size of ‘a’ is 123456 bytes [-Wlarger-than=]
char a[N];
^
b.c: In function ‘funnamed_array’:
b.c:13:18: warning: size of ‘({anonymous})’ is 123456 bytes [-Wlarger-than=]
sink ((char[N]){ 0 });
^
b.c:13:18: warning: size of ‘({anonymous})’ is 123456 bytes [-Wlarger-than=]
More information about the Gcc-bugs
mailing list