https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71905
Bug ID: 71905 Summary: bogus -Wlarger-than=N and -Wframe-larger-than warnings on small objects with large N Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: driver Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- As discussed in the thread Re: RFA: new pass to warn on questionable uses of alloca() and VLAs (https://gcc.gnu.org/ml/gcc-patches/2016-07/msg00953.html), the -Wlarger-than=N and -Wframe-larger-than=N options accept arguments in excess of 32-bits but apparently store their arguments as an unsigned int and int, respectively, allowing slicing and conversion errors. Likewise, the checkers for the options interpret the arguments as 32-bit integers resulting in incorrect warnings when the N argument exceeds UINT_MAX or INT_MAX, respectively. If storing and correctly interpreting very large arguments isn't possible, the driver should detect such arguments, and either issue a warning and disable the corresponding option or issue an error. (As a data point, Clang treats option arguments as 32-bit unsigned int and issues the following warning when it's out of bounds: clang (LLVM option parsing): for the -warn-stack-size option: '4294967316' value invalid for uint argument!) $ cat x.c && /build/gcc-walloca/gcc/xgcc -B /build/gcc-walloca/gcc -S -Wall -Wextra -Wpedantic -Wlarger-than=$((256*256*256*256+20)) -Wframe-larger-than=$((256*256*256*129)) x.c void f (void*); char a [32]; void g (void) { char b [32]; f (b); } x.c:3:6: warning: size of ‘a’ is 32 bytes [-Wlarger-than=] char a [32]; ^ x.c: In function ‘g’: x.c:7:8: warning: size of ‘b’ is 32 bytes [-Wlarger-than=] char b [32]; ^ x.c:9:1: warning: the frame size of 32 bytes is larger than -2130706432 bytes [-Wframe-larger-than=] } ^