Summary: | -Wvla-larger-than has no effect when compiling without optimizations | ||
---|---|---|---|
Product: | gcc | Reporter: | Jakub Łukasiewicz <jorengarenar> |
Component: | middle-end | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | UNCONFIRMED --- | ||
Severity: | enhancement | CC: | jorengarenar |
Priority: | P3 | Keywords: | diagnostic |
Version: | 12.2.1 | ||
Target Milestone: | --- | ||
See Also: |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98217 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85997 |
||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: |
Description
Jakub Łukasiewicz
2023-04-03 21:05:34 UTC
This is by designed and is even documented: https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Warning-Options.html#index-Wvla-larger-than_003d -Wvla-larger-than=‘PTRDIFF_MAX’ is enabled by default but is typically only effective when -ftree-vrp is active (default for -O2 and above). (In reply to Andrew Pinski from comment #1) > This is by designed and is even documented: > https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Warning-Options.html#index- > Wvla-larger-than_003d > > -Wvla-larger-than=‘PTRDIFF_MAX’ is enabled by default but is typically only > effective when -ftree-vrp is active (default for -O2 and above). Passing `-ftree-vrp` doesn't activate it either (In reply to Jakub Łukasiewicz from comment #2) > Passing `-ftree-vrp` doesn't activate it either Because of another part of the documentation: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options Most optimizations are completely disabled at -O0 or if an -O level is not set on the command line, even if individual optimization flags are specified. Similarly, -Og suppresses many optimization passes. (In reply to Andrew Pinski from comment #3) > (In reply to Jakub Łukasiewicz from comment #2) > > Passing `-ftree-vrp` doesn't activate it either > > Because of another part of the documentation: > https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options > > Most optimizations are completely disabled at -O0 or if an -O level is not > set on the command line, even if individual optimization flags are > specified. Similarly, -Og suppresses many optimization passes. So there is not way of detecting automatic VLA in "debug release"? (In reply to Jakub Łukasiewicz from comment #4) > So there is not way of detecting automatic VLA in "debug release"? -Wvla works. https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Warning-Options.html#index-Wvla (In reply to Andrew Pinski from comment #5) > (In reply to Jakub Łukasiewicz from comment #4) > > So there is not way of detecting automatic VLA in "debug release"? > > -Wvla works. > > https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Warning-Options.html#index-Wvla But also marks desired VLA (like in function parameters) $ gcc -std=c99 -Wvla -c foo.c foo.c:1:1: warning: ISO C90 forbids variable length array [-Wvla] 1 | int bar(int n, int[n]); | ^~~ foo.c: In function ‘foo’: foo.c:5:5: warning: ISO C90 forbids variable length array ‘arr’ [-Wvla] 5 | int arr[n]; | ^~~ Yes and that is still a VLA in terms of C99 definition ... Note GCC's C++ front-end even rejects VLA definitions like that for parameters so I don't know how useful they are really. (In reply to Andrew Pinski from comment #7) > Yes and that is still a VLA in terms of C99 definition ... Indeed, but we only want to prevent automatic VLA, all other instances of VM types are even encouraged. (In reply to Andrew Pinski from comment #8) > Note GCC's C++ front-end even rejects VLA definitions like that for > parameters so I don't know how useful they are really. The project is pure C and we really don't plan to convert it to C++ any time. At the same time, (recently added) diagnostics for size checking array parameter (https://godbolt.org/z/fdbheM8G9) could be really beneficial. Also, allocating on heap multidimensional arrays of unknown size is really convenient: int (*arr)[n][m] = malloc(sizeof *arr); |