[Bug middle-end/66031] Spurious array bounds warning
slash.tmp at free dot fr
gcc-bugzilla@gcc.gnu.org
Wed Oct 18 11:46:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66031
Mason <slash.tmp at free dot fr> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |slash.tmp at free dot fr
--- Comment #2 from Mason <slash.tmp at free dot fr> ---
FWIW, the following code looks somewhat fishy to me:
unsigned char f = 10;
extern unsigned char p[1];
char check(unsigned int n)
{
if (n - 1 >= f) return p[n];
return 1;
}
p[n] is well-defined iff n = 0
If n = 0, n - 1 = UINT_MAX, thus the test is true for any f
No other value of n is allowed as an index into p.
Thus I would expect gcc to turn the code into
return (n == 0) ? p[0] : 1;
More information about the Gcc-bugs
mailing list