aboutsummaryrefslogtreecommitdiff
path: root/test/SemaCXX/array-bounds.cpp
AgeCommit message (Collapse)Author
2012-12-14Have Sema::ActOnStartOfFunctionDef return the declaration that was passed it.Argyrios Kyrtzidis
This fixes the missing warning here: struct S { template <typename T> void meth() { char arr[3]; arr[4] = 0; // warning: array index 4 is past the end of the array } }; template <typename T> void func() { char arr[3]; arr[4] = 0; // no warning } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170180 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-27Fix a couple bugs in the way we handle array indexes in array bounds ↵Eli Friedman
checking. Specifically, make sure we don't ignore explicit casts in indexes, and make sure we use unsigned extension/comparisons on indexes. Fixes <rdar://problem/10916006>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151569 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-24Revert various template unreachability code I committed accidentally.David Blaikie
r148774, r148775, r148776, r148777 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148780 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-24Simple hack to do unreachable code analysis on template patterns.David Blaikie
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148774 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-29Suppress -Warray-bounds for classes (not just structs) where the last field isMatt Beaumont-Gay
a 1-length character array. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145445 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-29Merge branch 'yo-dawg-i-herd-u-like-arrays'Matt Beaumont-Gay
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145421 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-24Wordsmith the -Warray-bounds diagnostic text a bitMatt Beaumont-Gay
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145116 91177308-0d34-0410-b5e6-96231b3b80d8
2011-09-26Fix regression of -Warray-bounds involving varargs functions [PR 11007].Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140584 91177308-0d34-0410-b5e6-96231b3b80d8
2011-09-17Let -Warray-bounds handle casted array types without false positives.Nico Weber
Fixes PR10771. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139990 91177308-0d34-0410-b5e6-96231b3b80d8
2011-08-05Perform array bounds checking in more situations and properly handle specialKaelyn Uhrain
case situations with the unary operators & and *. Also extend the array bounds checking to work with pointer arithmetic; the pointer arithemtic checking can be turned on using -Warray-bounds-pointer-arithmetic. The changes to where CheckArrayAccess gets called is based on some trial & error and a bunch of digging through source code and gdb backtraces in order to have the check performed under as many situations as possible (such as for variable initializers, arguments to function calls, and within conditional in addition to the simpler cases of the operands to binary and unary operator) while not being called--and triggering warnings--more than once for a given ArraySubscriptExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136997 91177308-0d34-0410-b5e6-96231b3b80d8
2011-08-05Flesh out the -Warray-bounds detection of C89 tail-padded one-elementChandler Carruth
arrays. This now suppresses the warning only in the case of a one-element array as the last field in a struct where the array size is a literal '1' rather than any macro expansion or template parameter. This doesn't distinguish between the language standard in use to allow code which dates from C89 era to compile without the warning even in C99 and C++ builds. We could add a separate warning (under a different flag) with fixit hints to switch to a flexible array, but its not clear that this would be desirable. Much of the code using this idiom is striving for maximum portability. Tests were also fleshed out a bit, and the diagnostic itself tweaked to be more pretty w.r.t. single elment arrays. This is more ugly than I would like due to APInt's not being supported by the diagnostic rendering engine. A pseudo-patch for this was proposed by Nicola Gigante, but I reworked it both for several correctness issues and for code style. Sorry this was so long in coming. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136965 91177308-0d34-0410-b5e6-96231b3b80d8
2011-08-02disable array bounds overflow warning for cases where an array Chris Lattner
has a single element. This disables the warning in cases where there is a clear bug, but this is really rare (who uses arrays with one element?) and it also silences a large class of false positive issues with C89 code that is using tail padding in structs. A better version of this patch would detect when an array is in a tail position in a struct, but at least patch fixes the huge false positives that are hitting postgres and other code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136724 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-26Revert r136046 while fixing handling of e.g. &foo[index_one_past_size]Kaelyn Uhrain
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136113 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-26Expand array bounds checking to work in the presence of unary & and *,Kaelyn Uhrain
and to work with pointer arithmetic in addition to array indexing. The new pointer arithmetic porition of the array bounds checking can be turned on by -Warray-bounds-pointer-arithmetic (and is off by default). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136046 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-16Teach CFGBuilder that the 'default' branch of a switch statement is dead if ↵Ted Kremenek
all enum values in a switch conditioned are handled. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127727 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-04Correctly handle nested switch statements in CFGBuilder when on switch ↵Ted Kremenek
statement has a condition that evaluates to a constant. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126977 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-01Teach CFGBuilder to prune trivially unreachable case statements.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126797 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-01For C++, enhance -Warray-bounds to recursively analyze array subscript ↵Ted Kremenek
accesses in ?: expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126766 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-23Fix bogus -Warray-bounds warning involving 'array[true]' reported in PR 9296.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126341 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-23Add test case for PR 9284, a false positive for -Warray-bounds that is now ↵Ted Kremenek
addressed using basic reachability analysis. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126291 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-23Enhance Sema::DiagRuntimeBehavior() to delay some diagnostics to see if the ↵Ted Kremenek
related code is reachable. This suppresses some diagnostics that occur in unreachable code (e.g., -Warray-bound). We only pay the cost of doing the reachability analysis when we issue one of these diagnostics. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126290 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-18Fix assertion failure on -Warray-bounds for 32-bit builds of Clang.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125821 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-17Add -Warray-bounds test showing how the warning currently interoperates with ↵Ted Kremenek
macros. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125781 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-17Enhance the array bounds checking to work for several other constructs,Chandler Carruth
especially C++ code, and generally expand the test coverage. Logic adapted from a patch by Kaelyn Uhrain <rikka@google.com> and another Googler. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125775 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-16Fix assertion failure in -Warray-bounds on template parameters used as arrays.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125693 91177308-0d34-0410-b5e6-96231b3b80d8