[Bug middle-end/94004] New: missing -Walloca on calls to alloca due to -Wno-system-headers
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Mar 2 17:07:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94004
Bug ID: 94004
Summary: missing -Walloca on calls to alloca due to
-Wno-system-headers
Product: gcc
Version: 10.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: ---
When alloca is a macro defined in a system header like <alloca.h> (for example
in Glibc), the -Walloca and -Walloca-larger-than= don't point out offending
calls to alloca unless -Wsystem-headers is also set.
$ cat t.c && gcc -S -O2 -Walloca-larger-than=8 t.c
#include <alloca.h>
void f (void*, ...);
void g (int n)
{
if (n < 88888)
n = 88888;
char *p = (char*) __builtin_alloca (n); // warning (good)
f (p, 0);
}
void h (int n)
{
if (n < 99999)
n = 99999;
char *p = (char*) alloca (n); // missing warning
f (p, 1);
}
t.c: In function ‘g’:
t.c:9:21: warning: argument to ‘alloca’ may be too large
[-Walloca-larger-than=]
9 | char *p = (char*) __builtin_alloca (n);
| ^~~~~~~~~~~~~~~~~~~~
t.c:9:21: note: limit is 8 bytes, but argument may be as large as 2147483647
When -Wsystem-headers is also set on the command line GCC diagnoses both calls
as expected:
t.c:9:21: warning: argument to ‘alloca’ may be too large
[-Walloca-larger-than=]
9 | char *p = (char*) __builtin_alloca (n);
| ^~~~~~~~~~~~~~~~~~~~
t.c:9:21: note: limit is 8 bytes, but argument may be as large as 2147483647
In file included from t.c:1:
t.c: In function ‘h’:
t.c:17:21: warning: argument to ‘alloca’ may be too large
[-Walloca-larger-than=]
17 | char *p = (char*) alloca (n);
| ^~~~~~
t.c:17:21: note: limit is 8 bytes, but argument may be as large as 2147483647
More information about the Gcc-bugs
mailing list