Commit Graph

25 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis 26444c5243 Have Sema::ActOnStartOfFunctionDef return the declaration that was passed it.
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
}

llvm-svn: 170180
2012-12-14 06:54:03 +00:00
Eli Friedman 84e6e5cd1a Fix a couple bugs in the way we handle array indexes in array bounds 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>.
llvm-svn: 151569
2012-02-27 21:21:40 +00:00
David Blaikie 0f2ae78980 Revert various template unreachability code I committed accidentally.
r148774, r148775, r148776, r148777

llvm-svn: 148780
2012-01-24 04:51:48 +00:00
David Blaikie 7e625b67e5 Simple hack to do unreachable code analysis on template patterns.
llvm-svn: 148774
2012-01-24 04:29:18 +00:00
Matt Beaumont-Gay c93b489138 Suppress -Warray-bounds for classes (not just structs) where the last field is
a 1-length character array.

llvm-svn: 145445
2011-11-29 22:43:53 +00:00
Matt Beaumont-Gay b2339826e6 Merge branch 'yo-dawg-i-herd-u-like-arrays'
llvm-svn: 145421
2011-11-29 19:27:11 +00:00
Matt Beaumont-Gay 63be19122e Wordsmith the -Warray-bounds diagnostic text a bit
llvm-svn: 145116
2011-11-24 00:27:38 +00:00
Ted Kremenek d41f346875 Fix regression of -Warray-bounds involving varargs functions [PR 11007].
llvm-svn: 140584
2011-09-26 23:36:13 +00:00
Nico Weber 7c29980d20 Let -Warray-bounds handle casted array types without false positives.
Fixes PR10771.

llvm-svn: 139990
2011-09-17 22:59:41 +00:00
Kaelyn Uhrain 2e7aa5ae1f Perform array bounds checking in more situations and properly handle special
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.

llvm-svn: 136997
2011-08-05 23:18:04 +00:00
Chandler Carruth 28389f0cdf Flesh out the -Warray-bounds detection of C89 tail-padded one-element
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.

llvm-svn: 136965
2011-08-05 09:10:50 +00:00
Chris Lattner f51dae0378 disable array bounds overflow warning for cases where an array
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.

llvm-svn: 136724
2011-08-02 21:44:23 +00:00
Kaelyn Uhrain c45dcd2594 Revert r136046 while fixing handling of e.g. &foo[index_one_past_size]
llvm-svn: 136113
2011-07-26 18:36:36 +00:00
Kaelyn Uhrain 980bdb9dfb Expand array bounds checking to work in the presence of unary & and *,
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).

llvm-svn: 136046
2011-07-26 01:52:28 +00:00
Ted Kremenek 35c70f64db Teach CFGBuilder that the 'default' branch of a switch statement is dead if all enum values in a switch conditioned are handled.
llvm-svn: 127727
2011-03-16 04:32:01 +00:00
Ted Kremenek be52871b1a Correctly handle nested switch statements in CFGBuilder when on switch statement has a condition that evaluates to a constant.
llvm-svn: 126977
2011-03-04 01:03:41 +00:00
Ted Kremenek eff9a7ff91 Teach CFGBuilder to prune trivially unreachable case statements.
llvm-svn: 126797
2011-03-01 23:12:55 +00:00
Ted Kremenek df26df726e For C++, enhance -Warray-bounds to recursively analyze array subscript accesses in ?: expressions.
llvm-svn: 126766
2011-03-01 18:41:00 +00:00
Ted Kremenek e4b316c15c Fix bogus -Warray-bounds warning involving 'array[true]' reported in PR 9296.
llvm-svn: 126341
2011-02-23 23:06:04 +00:00
Ted Kremenek 477c8f5440 Add test case for PR 9284, a false positive for -Warray-bounds that is now addressed using basic reachability analysis.
llvm-svn: 126291
2011-02-23 01:52:07 +00:00
Ted Kremenek 3427fac7c8 Enhance Sema::DiagRuntimeBehavior() to delay some diagnostics to see if the 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.

llvm-svn: 126290
2011-02-23 01:52:04 +00:00
Ted Kremenek a7ced2cb4c Fix assertion failure on -Warray-bounds for 32-bit builds of Clang.
llvm-svn: 125821
2011-02-18 02:27:00 +00:00
Ted Kremenek 48d9626055 Add -Warray-bounds test showing how the warning currently interoperates with macros.
llvm-svn: 125781
2011-02-17 21:40:51 +00:00
Chandler Carruth 1af88f12a3 Enhance the array bounds checking to work for several other constructs,
especially C++ code, and generally expand the test coverage.

Logic adapted from a patch by Kaelyn Uhrain <rikka@google.com> and
another Googler.

llvm-svn: 125775
2011-02-17 21:10:52 +00:00
Ted Kremenek 197fcd4418 Fix assertion failure in -Warray-bounds on template parameters used as arrays.
llvm-svn: 125693
2011-02-16 23:39:09 +00:00