summaryrefslogtreecommitdiff
path: root/test/SemaCXX/array-bounds.cpp
Commit message (Collapse)AuthorAge
* Have Sema::ActOnStartOfFunctionDef return the declaration that was passed it.Argyrios Kyrtzidis2012-12-14
| | | | | | | | | | | | | | | | | | | | 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
* Fix a couple bugs in the way we handle array indexes in array bounds ↵Eli Friedman2012-02-27
| | | | | | 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
* Revert various template unreachability code I committed accidentally.David Blaikie2012-01-24
| | | | | | r148774, r148775, r148776, r148777 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148780 91177308-0d34-0410-b5e6-96231b3b80d8
* Simple hack to do unreachable code analysis on template patterns.David Blaikie2012-01-24
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148774 91177308-0d34-0410-b5e6-96231b3b80d8
* Suppress -Warray-bounds for classes (not just structs) where the last field isMatt Beaumont-Gay2011-11-29
| | | | | | a 1-length character array. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145445 91177308-0d34-0410-b5e6-96231b3b80d8
* Merge branch 'yo-dawg-i-herd-u-like-arrays'Matt Beaumont-Gay2011-11-29
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145421 91177308-0d34-0410-b5e6-96231b3b80d8
* Wordsmith the -Warray-bounds diagnostic text a bitMatt Beaumont-Gay2011-11-24
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145116 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix regression of -Warray-bounds involving varargs functions [PR 11007].Ted Kremenek2011-09-26
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140584 91177308-0d34-0410-b5e6-96231b3b80d8
* Let -Warray-bounds handle casted array types without false positives.Nico Weber2011-09-17
| | | | | | | | Fixes PR10771. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139990 91177308-0d34-0410-b5e6-96231b3b80d8
* Perform array bounds checking in more situations and properly handle specialKaelyn Uhrain2011-08-05
| | | | | | | | | | | | | | | | | 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
* Flesh out the -Warray-bounds detection of C89 tail-padded one-elementChandler Carruth2011-08-05
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* disable array bounds overflow warning for cases where an array Chris Lattner2011-08-02
| | | | | | | | | | | | | | | 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
* Revert r136046 while fixing handling of e.g. &foo[index_one_past_size]Kaelyn Uhrain2011-07-26
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136113 91177308-0d34-0410-b5e6-96231b3b80d8
* Expand array bounds checking to work in the presence of unary & and *,Kaelyn Uhrain2011-07-26
| | | | | | | | | | 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
* Teach CFGBuilder that the 'default' branch of a switch statement is dead if ↵Ted Kremenek2011-03-16
| | | | | | 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
* Correctly handle nested switch statements in CFGBuilder when on switch ↵Ted Kremenek2011-03-04
| | | | | | 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
* Teach CFGBuilder to prune trivially unreachable case statements.Ted Kremenek2011-03-01
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126797 91177308-0d34-0410-b5e6-96231b3b80d8
* For C++, enhance -Warray-bounds to recursively analyze array subscript ↵Ted Kremenek2011-03-01
| | | | | | accesses in ?: expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126766 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix bogus -Warray-bounds warning involving 'array[true]' reported in PR 9296.Ted Kremenek2011-02-23
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126341 91177308-0d34-0410-b5e6-96231b3b80d8
* Add test case for PR 9284, a false positive for -Warray-bounds that is now ↵Ted Kremenek2011-02-23
| | | | | | addressed using basic reachability analysis. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126291 91177308-0d34-0410-b5e6-96231b3b80d8
* Enhance Sema::DiagRuntimeBehavior() to delay some diagnostics to see if the ↵Ted Kremenek2011-02-23
| | | | | | | | | | 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
* Fix assertion failure on -Warray-bounds for 32-bit builds of Clang.Ted Kremenek2011-02-18
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125821 91177308-0d34-0410-b5e6-96231b3b80d8
* Add -Warray-bounds test showing how the warning currently interoperates with ↵Ted Kremenek2011-02-17
| | | | | | macros. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125781 91177308-0d34-0410-b5e6-96231b3b80d8
* Enhance the array bounds checking to work for several other constructs,Chandler Carruth2011-02-17
| | | | | | | | | 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
* Fix assertion failure in -Warray-bounds on template parameters used as arrays.Ted Kremenek2011-02-16
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125693 91177308-0d34-0410-b5e6-96231b3b80d8