[LLVMbugs] [Bug 3935] Invalid addresses at compile time not diagnosed
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Jun 21 14:22:37 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=3935
Kaelyn Uhrain <rikka at google.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |rikka at google.com
Resolution| |FIXED
--- Comment #1 from Kaelyn Uhrain <rikka at google.com> 2012-06-21 16:22:37 CDT ---
Since at least the 3.1 release, clang will warn about the invalid array index
via -Warray-bounds, which is enabled by default:
$ cat tmp.cc
int x[2], *y = &x[3], *z = x + 3;
$ clang -fsyntax-only tmp.cc
tmp.cc:1:17: warning: array index 3 is past the end of the array (which
contains 2 elements)
[-Warray-bounds]
int x[2], *y = &x[3], *z = x + 3;
^ ~
tmp.cc:1:1: note: array 'x' declared here
int x[2], *y = &x[3], *z = x + 3;
^
1 warning generated.
Additionally, passing -Warray-bounds-pointer-arithmetic will also raise a
warning about the bad pointer arithmetic:
$ clang -fsyntax-only -Warray-bounds-pointer-arithmetic -Wno-array-bounds
tmp.cc
tmp.cc:1:28: warning: the pointer incremented by 3 refers past the end of the
array
(that contains 2 elements) [-Warray-bounds-pointer-arithmetic]
int x[2], *y = &x[3], *z = x + 3;
^ ~
tmp.cc:1:1: note: array 'x' declared here
int x[2], *y = &x[3], *z = x + 3;
^
1 warning generated.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list