[Bug c/79010] -Wlarger-than ineffective for VLAs, alloca, malloc

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jul 30 17:13:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79010

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
There was a change to how some of the larger-than warnings are controlled (bug
82063) but it hasn't affected this report.  The top of GCC 9 trunk still issues
the same warnings:

$ gcc -O2 -S -Wall -DN=123456 -S -Wall -Wextra -Wpedantic  -Wlarger-than=123
e.c
e.c:3:6: warning: size of ‘a’ 123456 bytes exceeds maximum object size 123
[-Wlarger-than=]
 char a[N];
      ^
e.c: In function ‘farray’:
e.c:7:8: warning: size of ‘a’ 123456 bytes exceeds maximum object size 123
[-Wlarger-than=]
   char a[N];
        ^
e.c: In function ‘funnamed_array’:
e.c:13:18: warning: size of ‘({anonymous})’ 123456 bytes exceeds maximum object
size 123 [-Wlarger-than=]
   sink ((char[N]){ 0 });
                  ^
e.c:13:18: warning: size of ‘({anonymous})’ 123456 bytes exceeds maximum object
size 123 [-Wlarger-than=]


Alloca and VLA sizes are controlled by the -Walloca-larger-than= and
-Wvla-larger-than= options (new in GCC 7).  If it's thought to be useful to
exclude them from -Wlarger-than= the manual should be updated to make that
clear.

gcc -O2 -S -Wall -DN=123456 -S -Wall -Wextra -Wpedantic  -Wlarger-than=123
-Walloca-larger-than=123 -Wvla-larger-than=123 e.c
e.c:3:6: warning: size of ‘a’ 123456 bytes exceeds maximum object size 123
[-Wlarger-than=]
 char a[N];
      ^
e.c: In function ‘farray’:
e.c:7:8: warning: size of ‘a’ 123456 bytes exceeds maximum object size 123
[-Wlarger-than=]
   char a[N];
        ^
e.c: In function ‘funnamed_array’:
e.c:13:18: warning: size of ‘({anonymous})’ 123456 bytes exceeds maximum object
size 123 [-Wlarger-than=]
   sink ((char[N]){ 0 });
                  ^
e.c:13:18: warning: size of ‘({anonymous})’ 123456 bytes exceeds maximum object
size 123 [-Wlarger-than=]
e.c: In function ‘fvla’:
e.c:19:8: warning: argument to variable-length array is too large
[-Wvla-larger-than=]
   char a[n];
        ^
e.c:19:8: note: limit is 123 bytes, but argument is 123456
e.c: In function ‘falloca’:
e.c:25:13: warning: argument to ‘alloca’ is too large [-Walloca-larger-than=]
   void *a = __builtin_alloca (N);
             ^~~~~~~~~~~~~~~~~~~~
e.c:25:13: note: limit is 123 bytes, but argument is 123456


More information about the Gcc-bugs mailing list