Commit Graph

266 Commits

Author SHA1 Message Date
Lenny Maiorani 18470e3287 Use StringRef::substr() and unbounded StringRef::compare() instead of bounded version of StringRef::compare() because bounded version of StringRef::compare() is going to be removed.
llvm-svn: 130425
2011-04-28 19:31:12 +00:00
Lenny Maiorani ed2cc6ccbb Eliminates an assert in the strncpy/strncat checker caused by not validating a cast was successful. If the value of an argument was unknown, the cast would result in a NULL pointer which was later being dereferenced.
This fixes Bugzilla #9806.

llvm-svn: 130422
2011-04-28 18:59:43 +00:00
Lenny Maiorani 4af23c8159 Implements strcasecmp() checker in Static Analyzer.
llvm-svn: 130398
2011-04-28 15:09:11 +00:00
John Wiegley 1c0675e155 Parsing/AST support for Structured Exception Handling
Patch authored by Sohail Somani.

Provide parsing and AST support for Windows structured exception handling.

llvm-svn: 130366
2011-04-28 01:08:34 +00:00
John Wiegley 6242b6a688 Implementation of Embarcadero array type traits
Patch authored by John Wiegley.

These are array type traits used for parsing code that employs certain
features of the Embarcadero C++ compiler: __array_rank(T) and
__array_extent(T, Dim).

llvm-svn: 130351
2011-04-28 00:16:57 +00:00
Lenny Maiorani 005b5c1aee More accurately model realloc() when the size argument is 0. realloc() with a size of 0 is equivalent to free(). The memory region should be marked as free and not used again.
Unit tests f2_realloc_0(), f6_realloc(), and f7_realloc() contributed by Marshall Clow <mclow.lists@gmail.com>. Thanks! 

llvm-svn: 130303
2011-04-27 14:49:29 +00:00
Ted Kremenek 08b434f450 Allow 'Environment::getSVal()' to allow an optional way for checkers to do a direct lookup to values bound to expressions, without
resulting to lazy logic.  This is critical for the OSAtomicChecker that does a simulated load on any arbitrary expression.

llvm-svn: 130292
2011-04-27 05:34:09 +00:00
Lenny Maiorani e553e40467 Implements the strncmp() checker just like the strcmp() checker, but with bounds. Requires LLVM svn r129582.
llvm-svn: 130161
2011-04-25 22:21:00 +00:00
John Wiegley f9f6584e95 t/clang/expr-traits
Patch authored by David Abrahams.

These two expression traits (__is_lvalue_expr, __is_rvalue_expr) are used for
parsing code that employs certain features of the Embarcadero C++ compiler.

llvm-svn: 130122
2011-04-25 06:54:41 +00:00
Jay Foad 1a180156b6 Remove unused STL header includes.
llvm-svn: 130068
2011-04-23 19:53:52 +00:00
Ted Kremenek 11e5c8b31a Add static analyzer support for C++'0X nullptr. Patch by Jim Goodnow II.
llvm-svn: 130003
2011-04-22 18:01:30 +00:00
Anders Carlsson d1f65f61ee Make the VariadicMethodTypeChecker accept block pointers as Objective-C pointers. Fixes PR9746.
llvm-svn: 129741
2011-04-19 01:16:46 +00:00
Richard Smith dda56e4b4a Support for C++11 (non-template) alias declarations.
llvm-svn: 129567
2011-04-15 14:24:37 +00:00
Chris Lattner 57540c5be0 fix a bunch of comment typos found by codespell. Patch by
Luis Felipe Strano Moraes!

llvm-svn: 129559
2011-04-15 05:22:18 +00:00
Peter Collingbourne 9114759641 C1X: implement generic selections
As an extension, generic selection support has been added for all
supported languages.  The syntax is the same as for C1X.

llvm-svn: 129554
2011-04-15 00:35:48 +00:00
Richard Smith 02e85f3bc5 Add support for C++0x's range-based for loops, as specified by the C++11 draft standard (N3291).
llvm-svn: 129541
2011-04-14 22:09:26 +00:00
Ted Kremenek ced5feaec9 Teach VariadicMethodTypeChecker to not crash when processing methods declared in protocols.
llvm-svn: 129395
2011-04-12 21:47:05 +00:00
Ted Kremenek 905a602e0c Fix another IdempotentOperationsChecker corner case when determining if an active block on the worklist
impacts the results of the check.

llvm-svn: 129394
2011-04-12 21:47:02 +00:00
Ted Kremenek 8a4c760c20 ArrayBoundCheckerV2: don't arbitrarily warn about indexing before the 0-index of a symbolic region. In many cases that isn't really the base offset.
llvm-svn: 129366
2011-04-12 17:21:33 +00:00
Lenny Maiorani f3539ad5c7 This patch adds modeling of strcmp() to the CString checker. Validates inputs are not NULL and are real C strings, then does the comparison and binds the proper return value. Unit tests included.
llvm-svn: 129364
2011-04-12 17:08:43 +00:00
Ted Kremenek f52718899f static analyzer: invalidate by-ref arguments passed to constructors in a 'new' expression.
llvm-svn: 129349
2011-04-12 05:12:39 +00:00
Ted Kremenek 57a4a152b2 Fix bug in SimpleSValBuilder where '--' pointer arithmetic was treated like '++' pointer arithmetic.
llvm-svn: 129348
2011-04-12 03:49:37 +00:00
Ted Kremenek 4f939da02d RegionStoreManager::invalidateRegions: treat classes the same as structs.
llvm-svn: 129333
2011-04-12 00:44:31 +00:00
John McCall 2979fe01da After some discussion with Doug, we decided that it made a lot more sense
for __unknown_anytype resolution to destructively modify the AST.  So that's
what it does now, which significantly simplifies some of the implementation.
Normal member calls work pretty cleanly now, and I added support for
propagating unknown-ness through &.

llvm-svn: 129331
2011-04-12 00:42:48 +00:00
Ted Kremenek 8ef59e5c03 C++ static analysis: also invalidate fields of objects that are the callees in C++ method calls.
llvm-svn: 129308
2011-04-11 22:22:05 +00:00
John McCall 2d2e870745 More __unknown_anytype work.
llvm-svn: 129269
2011-04-11 07:02:50 +00:00
Anders Carlsson 8a01a751c9 Remove CK_DynamicToNull.
llvm-svn: 129265
2011-04-11 02:03:26 +00:00
Anders Carlsson c602006638 As a first step towards fixing PR9641, add a CK_DynamicToNull cast kind which
represents a dynamic cast where we know that the result is always null.

For example:

struct A {
  virtual ~A();
};
struct B final : A { };
struct C { };

bool f(B* b) {
  return dynamic_cast<C*>(b);
}

llvm-svn: 129256
2011-04-10 20:33:22 +00:00
Lenny Maiorani 467dbd5f13 strcat() and strncat() model additions to CStringChecker.
Validates inputs are not NULL, checks for overlapping strings, concatenates the strings checking for buffer overflow, sets the length of the destination string to the sum of the s1 length and the s2 length, binds the return value to the s1 value.

llvm-svn: 129215
2011-04-09 15:12:58 +00:00
Ted Kremenek f603f3afbd Start overhauling static analyzer support for C++ constructors. The inlining support isn't complete, and needs
to be reworked to model CallEnter/CallExit (just like all other calls).  For now, treat constructors mostly
like other function calls, making the analysis of C++ code just a little more useful.

llvm-svn: 129166
2011-04-08 22:42:35 +00:00
John McCall 319963434c Basic, untested implementation for an "unknown any" type requested by LLDB.
The idea is that you can create a VarDecl with an unknown type, or a
FunctionDecl with an unknown return type, and it will still be valid to
access that object as long as you explicitly cast it at every use.  I'm
still going back and forth about how I want to test this effectively, but
I wanted to go ahead and provide a skeletal implementation for the LLDB
folks' benefit and because it also improves some diagnostic goodness for
placeholder expressions.

llvm-svn: 129065
2011-04-07 08:22:57 +00:00
John McCall 3337ca5f95 When updating the retain summary based on {cf,ns}_consumed attributes,
be sure to consume the argument index that actually had the attribute
rather than always the first.  rdar://problem/9234108

llvm-svn: 128998
2011-04-06 09:02:12 +00:00
Lenny Maiorani de909e4946 Add security syntax checker for strcat() which causes the Static Analyzer to generate a warning any time the strcat() function is used with a note suggesting to use a function which provides bounded buffers. CWE-119.
Also, brings the security syntax checker more inline with coding standards.

llvm-svn: 128916
2011-04-05 20:18:46 +00:00
Ted Kremenek 378819342e Fix PR 9626 (duplicated self-init warnings under -Wuninitialized) with numerous CFG and UninitializedValues analysis changes:
1) Change the CFG to include the DeclStmt for conditional variables, instead of using the condition itself as a faux DeclStmt.
2) Update ExprEngine (the static analyzer) to understand (1), so not to regress.
3) Update UninitializedValues.cpp to initialize all tracked variables to Uninitialized at the start of the function/method.
4) Only use the SelfReferenceChecker (SemaDecl.cpp) on global variables, leaving the dataflow analysis to handle other cases.

The combination of (1) and (3) allows the dataflow-based -Wuninitialized to find self-init problems when the initializer
contained control-flow.

llvm-svn: 128858
2011-04-04 23:29:12 +00:00
Lenny Maiorani fca2e9618a Refactoring the security checker a little bit so that each CallExpr check doesn't get called for each CallExpr. Instead it does a switch and only runs the check for the proper identifier. Slight speed improvement (probably significant on very large ASTs), and should make it easier and more clear to add more checks for other CallExpr's later.
llvm-svn: 128785
2011-04-03 05:07:11 +00:00
Ted Kremenek a95594416e static analyzer: Add a new ProgramPoint PostCondition to represent the post position of a branch condition, and a new generateNode method to BranchNodeBuilder using PostCondition ProgramPoint. This method generates a new ExplodedNode but not a new block edge.
Patch by Lei Zhang!

llvm-svn: 128784
2011-04-03 04:34:49 +00:00
Ted Kremenek 850d35be16 Fix RegionStore bug when doing a field load whose parent is also a field assigned a LazyCompoundValue. Fixes <rdar://problem/9163742> and PR 9522.
llvm-svn: 128783
2011-04-03 04:09:15 +00:00
Zhongxing Xu af2371e368 Remove a redundant method. We have a const version.
llvm-svn: 128762
2011-04-02 03:20:45 +00:00
Ted Kremenek 8f89f7c893 Teach IdempotentOperationsChecker about paths aborted because ExprEngine didn't know how to handle a specific Expr type.
llvm-svn: 128761
2011-04-02 02:56:23 +00:00
Ted Kremenek c703a666f7 static analyzer: Rename 'BlocksAborted' to 'BlocksExhausted' to reflect that a given CFGBlock was analyzed too many times.
llvm-svn: 128760
2011-04-02 02:56:17 +00:00
Lenny Maiorani 6ffe738f24 Add security syntax checker for strcpy() which causes the Static Analyzer to generate a warning any time the strcpy() function is used with a note suggesting to use a function which provides bounded buffers.
llvm-svn: 128679
2011-03-31 22:09:14 +00:00
Lenny Maiorani 79d74141b1 Adding Static Analyzer checker for mempcpy().
Models mempcpy() so that if length is NULL the destination pointer is returned. Otherwise, the source and destination are confirmed not to be NULL and not overlapping. Finally the copy is validated to not cause a buffer overrun and the return value is bound to the address of the byte after the last byte copied.

llvm-svn: 128677
2011-03-31 21:36:53 +00:00
Lenny Maiorani 70568c2be7 Fix spelling in a comment. (test commit)
llvm-svn: 128670
2011-03-31 21:26:55 +00:00
Ted Kremenek 40d16c0e75 Static analyzer: fix bug in handling of dynamic_cast<>. The sink node wouldn't always be the final node, thus causing the state to continue propagating. Instead,
recover some path-sensitivity by conjuring a symbol.

llvm-svn: 128612
2011-03-31 04:46:53 +00:00
Ted Kremenek 61a4f6682a Teach static analyzer about the basics of handling new[]. We still don't simulate constructors, but at least the analyzer doesn't think the return value is uninitialized.
llvm-svn: 128611
2011-03-31 04:04:48 +00:00
Ted Kremenek 98a24e37c5 Begin reworking static analyzer support for C++ method calls. The current logic was divorced
from how we process ordinary function calls, had a tremendous about of redundancy, and relied
strictly on inlining behavior (which was incomplete) to provide semantics instead of falling
back to the conservative analysis we use for C functions.  This is a significant step into
making C++ analyzer support more useful.

llvm-svn: 128557
2011-03-30 17:41:19 +00:00
Argyrios Kyrtzidis 84d7907797 [analyzer] Allow all checkers of a group to be enabled.
llvm-svn: 128512
2011-03-29 23:57:41 +00:00
Argyrios Kyrtzidis 437758cbe6 [analyzer] For -analyzer-checker-help show all the info about groups, packages, and which packages/checkers are hidden.
llvm-svn: 128511
2011-03-29 23:57:38 +00:00
Argyrios Kyrtzidis 4ee039647a [analyzer] Checker Packages can now belong to a group. This requires llvm commit r128474.
llvm-svn: 128475
2011-03-29 18:54:02 +00:00
Anders Carlsson 642b03413f Don't add a symbolic region for 'this' if the member function is static.
llvm-svn: 128340
2011-03-26 14:30:44 +00:00