https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78327
Bug ID: 78327 Summary: -Walloca-large-than false positives due to bad range info for signed integers in [-TYPE_MAX + N, N] Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The following is a test case for the problem brought up in the the thread Re: anti-ranges of signed variables (https://gcc.gnu.org/ml/gcc/2016-11/msg00029.html). In the test case below, n's range in function g is [-125, 2], making the largest value that (n + 128) can evaluate to and alloca be called with 130. Yet -Walloca-larger-than=200 emits a warning for the function with a note claiming that the computed value may be as large as 255. That's incorrect. Recompiling the same test case with -Walloca-larger-than=100 results in a warning for function h as well (as expected), and with a note correctly indicating the largest value alloca can be called with there given its range of [-125, 1]: 129. (The warning for g still says 255.) c.c:14:3: note: limit is 100 bytes, but argument may be as large as 129 The output of -fdump-tree-vrp confirms that the range GCC computes for n in g is [0, 255], while in h [3, 129]. The same problem seems to affect all signed integers. $ cat c.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -O2 -S -Wall -Wextra -Walloca-larger-than=200 c.c void f (void*); void g (signed char n) { if (n < -125 || 2 < n) n = 0; f (__builtin_alloca (n + 128)); } void h (signed char n) { if (n < -125 || 1 < n) n = 0; f (__builtin_alloca (n + 128)); } c.c: In function ‘g’: c.c:7:3: warning: argument to ‘alloca’ may be too large [-Walloca-larger-than=] f (__builtin_alloca (n + 128)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ c.c:7:3: note: limit is 200 bytes, but argument may be as large as 255