Commit Graph

2087 Commits

Author SHA1 Message Date
Tom Care b49ec6907b Bug 7377: Fixed several bad printf format string bugs.
- Added warning for undefined behavior when using field specifier
- Added warning for undefined behavior when using length modifier
- Fixed warnings for invalid flags
- Added warning for ignored flags
- Added fixits for the above warnings
- Fixed accuracy of detecting several undefined behavior conditions
- Receive normal warnings in addition to security warnings when using %n
- Fix bug where '+' flag would remain on unsigned conversion suggestions

Summary of changes:
- Added expanded tests
- Added/expanded warnings
- Added position info to OptionalAmounts for fixits
- Extracted optional flags to a wrapper class with position info for fixits
- Added several methods to validate a FormatSpecifier by component, each checking for undefined behavior
- Fixed conversion specifier checking to conform to C99 standard
- Added hooks to detect the invalid states in CheckPrintfHandler::HandleFormatSpecifier

Note: warnings involving the ' ' (space) flag are temporarily disabled until whitespace highlighting no longer triggers assertions. I will make a post about this on cfe-dev shortly.

M    test/Sema/format-strings.c
M    include/clang/Basic/DiagnosticSemaKinds.td
M    include/clang/Analysis/Analyses/PrintfFormatString.h
M    lib/Analysis/PrintfFormatString.cpp
M    lib/Sema/SemaChecking.cpp

llvm-svn: 106233
2010-06-17 19:00:27 +00:00
Alexis Hunt c675ec09f0 Update CMake build for new attribute changes.
llvm-svn: 106188
2010-06-17 00:37:02 +00:00
Ted Kremenek 64c235e4c6 Extend format string type-checking to include '%p'. Fixes remaining cases PR 4468.
llvm-svn: 106151
2010-06-16 21:23:04 +00:00
Tom Care 00554634db Small fixes regarding printf fix suggestions.
- Added some handling of flags that become invalid when changing the conversion specifier.
- Changed fixit behavior to remove unnecessary length modifiers.
- Separated some tests out and added some comments.

modified:
  lib/Analysis/PrintfFormatString.cpp
  test/Sema/format-strings-fixit.c

llvm-svn: 105807
2010-06-11 04:22:02 +00:00
Douglas Gregor b4e3533ce1 Fix a typo that breaks the GCC build. Turns out that Clang isn't
diagnosing this code as an error when it should, so I've filed
http://llvm.org/bugs/show_bug.cgi?id=7325. 

llvm-svn: 105683
2010-06-09 05:25:34 +00:00
Tom Care b704270779 Added FixIt support to printf format string checking.
- Refactored LengthModifier to be a class.
- Added toString methods in all member classes of FormatSpecifier.
- FixIt suggestions keep user specified flags unless incorrect.

Limitations:
- The suggestions are not conversion specifier sensitive. For example, if we have a 'pad with zeroes' flag, and the correction is a string conversion specifier, we do not remove the flag. Clang will warn us on the next compilation.

A    test/Sema/format-strings-fixit.c
M    include/clang/Analysis/Analyses/PrintfFormatString.h
M    lib/Analysis/PrintfFormatString.cpp
M    lib/Sema/SemaChecking.cpp

llvm-svn: 105680
2010-06-09 04:11:11 +00:00
Daniel Dunbar ee6b692551 Makefiles: Set Clang CPP compiler flags in a single location, instead of scattered throughout the project Makefiles.
llvm-svn: 105638
2010-06-08 20:44:43 +00:00
Daniel Dunbar e6c1daa8fd Makefile: Switch Clang Makefiles to always include the top-level Clang Makefile.
- This eliminates most dependencies on how Clang is installed relative to LLVM.

llvm-svn: 105637
2010-06-08 20:34:18 +00:00
Jordy Rose 2e22268904 Assignments to reference variables shouldn't kill the variable.
llvm-svn: 105452
2010-06-04 01:14:56 +00:00
Zhongxing Xu ea9fcffe03 Make addStmt always add stmt. Delegate other cases to Visit() directly.
llvm-svn: 105384
2010-06-03 06:43:23 +00:00
Zhongxing Xu 41cdf585c2 CFG: add all LHS of assingments as lvalue. This improves support for C++ reference. Patch by Jordy.
llvm-svn: 105383
2010-06-03 06:23:18 +00:00
Alexis Hunt ed05325dbe Convert DeclNodes to use TableGen.
The macros required for DeclNodes use have changed to match the use of
StmtNodes. The FooFirst enumerator constants have been named firstFoo
to match usage elsewhere.

llvm-svn: 105165
2010-05-30 07:21:58 +00:00
Ted Kremenek 304a9537e1 Fix crash in CFG construction for 'break' statements appearing in statement expressions
within the increment code of a for loop.

llvm-svn: 104375
2010-05-21 20:30:15 +00:00
Ted Kremenek ecc31c93c2 Don't add a null successor to a CFGBlock when the contents of an @synchronized statement is empty.
Fixes <rdar://problem/7979430>.

llvm-svn: 103717
2010-05-13 16:38:08 +00:00
Douglas Gregor ecc60b99f9 Unbreak CMake build.
llvm-svn: 103077
2010-05-05 05:41:05 +00:00
Ted Kremenek bc1416dcad Add null check in CFGBuilder::VisitStmt() to make CFG construction
more resilient to bad code.

llvm-svn: 102793
2010-04-30 22:25:53 +00:00
Ted Kremenek 989da5eeff Fix CFG crasher involving statement expressions reported in PR 6938.
llvm-svn: 102576
2010-04-29 01:10:26 +00:00
Zhongxing Xu b5e94ac97d Use direct assignment instead of user defined conversion.
llvm-svn: 101236
2010-04-14 05:50:04 +00:00
Zhongxing Xu 7e61217d86 CFGBuilder: always add C++ member call expr as block-level expr.
llvm-svn: 101127
2010-04-13 09:38:01 +00:00
Ted Kremenek 5868ec6e3d Fix CFG bug where bases of member expressions were not always evaluated in a lvalue context. Fixes <rdar://problem/7813989>.
llvm-svn: 100966
2010-04-11 17:02:10 +00:00
Ted Kremenek 66de60376c Fix bug in AddStmtChoice:asLValue() where 'AsLValueNotAlwaysAdd' would not be treated as indicating an lvalue.
llvm-svn: 100965
2010-04-11 17:02:04 +00:00
Ted Kremenek d2ba1f9ff0 Sort visitor methods. No functionality change.
llvm-svn: 100964
2010-04-11 17:01:59 +00:00
Rafael Espindola c50c27cca8 the big refactoring bits of PR3782.
This introduces FunctionType::ExtInfo to hold the calling convention and the
noreturn attribute. The next patch will extend it to include the regparm
attribute and fix the bug.

llvm-svn: 99920
2010-03-30 20:24:48 +00:00
Rafael Espindola 8756268ee5 Be a bit more consistent in using operator->
This patch moves some methods from QualType to Type and changes the users to
use -> instead of .

llvm-svn: 99805
2010-03-29 03:39:46 +00:00
Ted Kremenek 186508c7d6 Fix '+=' accumulation error when parsing numeric amounts in a format string.
llvm-svn: 99479
2010-03-25 03:59:09 +00:00
Ted Kremenek 0b40532b5e Only perform CFG-based warnings on 'static inline' functions that
are called (transitively) by regular functions/blocks within a
translation untion.

llvm-svn: 99233
2010-03-23 00:13:23 +00:00
Jeffrey Yasskin f6442f80cb Allow users to set CPPFLAGS and CXXFLAGS on the make command line.
Tested: make CPPFLAGS=-m64 CXXFLAGS=-m64 -j8 && (cd tools/clang;make test)
llvm-svn: 98399
2010-03-12 22:55:16 +00:00
Ted Kremenek 575398e29b When computing in AnalysisContext the variables referenced
by a block, also look at the contained blocks.

llvm-svn: 98111
2010-03-10 00:18:11 +00:00
Benjamin Kramer a3b13411fa Simplify code a bit and remove unneeded semicolons.
llvm-svn: 97654
2010-03-03 16:28:47 +00:00
Ted Kremenek 0f0883b918 Fix an algorithmic bug in LiveVariables pointed out by Zhongxing.
If an initializer in a DeclStmt references the declared variable, that
extends the liveness of that variable.

llvm-svn: 97624
2010-03-03 01:17:41 +00:00
Ted Kremenek 5d2bb1b9b3 [CFG]
After discussion with Zhongxing, don't force the initializer of DeclStmts to be
block-level expressions.

This led to some interesting fallout:

[UninitializedValues]

Always visit the initializer of DeclStmts (do not assume they are block-level expressions).

[BasicStore]

With initializers of DeclStmts no longer block-level expressions, this causes self-referencing initializers (e.g. 'int x = x') to no longer cause the initialized variable to be live before the DeclStmt.  While this is correct, it caused BasicStore::RemoveDeadBindings() to prune off the values of these variables from the initial store (where they are set to uninitialized).  The fix is to back-port some (and only some) of the lazy-binding logic from RegionStore to
BasicStore.  Now the default values of local variables are determined lazily as opposed
to explicitly initialized.

llvm-svn: 97591
2010-03-02 21:43:54 +00:00
Zhongxing Xu d497e126cb Register all parameters even if they didn't occur in the function body.
We may query their liveness because they are added to store when passing
argument values.

llvm-svn: 97562
2010-03-02 10:08:30 +00:00
Ted Kremenek 80263e5905 Allow a '0' precision in format strings (as the man page says it is okay).
Fixes <rdar://problem/7700339>.

llvm-svn: 97482
2010-03-01 19:22:33 +00:00
Ted Kremenek d166819c26 For printf format string checking, add support for positional format strings.
Along the way, coelesce some of the diagnostics.

llvm-svn: 97297
2010-02-27 01:41:03 +00:00
Ted Kremenek 4a49d9818b For printf format string checking, move the tracking of the data argument index out of
Sema and into analyze_printf::ParseFormatString().  Also use a bitvector to determine
what arguments have been covered (instead of just checking to see if the last argument consumed is the max argument).  This is prep. for support positional arguments (an IEEE extension).

llvm-svn: 97248
2010-02-26 19:18:41 +00:00
Zhongxing Xu a396e617b5 Always add CallExpr as block-level expression. Inline-based interprocedural
analysis needs this.

llvm-svn: 97014
2010-02-24 02:19:28 +00:00
Ted Kremenek 74a4ce7f1e Add support for '%C' and '%S' printf conversion specifiers.
llvm-svn: 97005
2010-02-24 00:05:54 +00:00
Ted Kremenek 552eeaa93e Move the rest of the unreachable code analysis from libSema
to libAnalysis (with only the error reporting in libSema).

llvm-svn: 96893
2010-02-23 05:59:20 +00:00
Ted Kremenek 7296de9ae3 Start moving some of the logic for the unreachable code analysis out of libSema
and into libAnalysis.

llvm-svn: 96872
2010-02-23 02:39:16 +00:00
Daniel Dunbar 260918ce5c Revert "Simplify code: Succ is guaranteed to be not NULL.", which turns out to
not be guaranteed.

llvm-svn: 96782
2010-02-22 05:58:59 +00:00
Zhongxing Xu d39620c451 Simplify code: Succ is guaranteed to be not NULL.
llvm-svn: 96772
2010-02-22 02:59:27 +00:00
Zhongxing Xu 86bab2cddd Add a utility method.
llvm-svn: 96471
2010-02-17 08:45:06 +00:00
Ted Kremenek c8b188d541 Refactor the logic for printf argument type-checking into analyze_printf::ArgTypeResult.
Implement printf argument type checking for '%s'.

Fixes <rdar://problem/3065808>.

llvm-svn: 96310
2010-02-16 01:46:59 +00:00
Ted Kremenek 2a0cd59f8e Convert tabs to spaces.
llvm-svn: 95621
2010-02-09 00:04:09 +00:00
Ted Kremenek 5abd69d946 Teach RegionStore::InvalidateRegions() to also invalidate static variables referenced by blocks.
llvm-svn: 95459
2010-02-06 00:30:00 +00:00
Ted Kremenek 1de1707bfc Move ParseFormatString() and FormatStringHandler back into the analyze_printf namespace.
llvm-svn: 95324
2010-02-04 20:46:58 +00:00
Ted Kremenek 016b605266 Add format string type checking support for 'long double'.
llvm-svn: 95026
2010-02-01 23:23:50 +00:00
Daniel Dunbar 19b70bd46c Recognize 'q' as a format length modifier (from BSD).
llvm-svn: 94894
2010-01-30 15:49:20 +00:00
Ted Kremenek 9ff02052dd Add format string checking of 'double' arguments. Fixes <rdar://problem/6931734>.
llvm-svn: 94867
2010-01-30 01:02:18 +00:00
Ted Kremenek ba775fe5c7 Fix spacing.
llvm-svn: 94852
2010-01-29 23:00:35 +00:00
Ted Kremenek 79db7b7b17 Per a suggestion from Cristian Draghici, add a method to FormatSpecifier that returns the expected type of the matching data argument. It isn't complete, but should handle several of the important cases.
llvm-svn: 94851
2010-01-29 22:59:32 +00:00
Ted Kremenek 23a71a1cdf Enhancements to the alternate (WIP) format string checking:
- Add ConversionSpecifier::consumesDataArgument() as a helper method
  to determine if a conversion specifier requires a matching argument.
- Add support for glibc-specific '%m' conversion
- Add an extra callback to HandleNull() for locations within the
  format specifier that have a null character

llvm-svn: 94834
2010-01-29 20:29:53 +00:00
Ted Kremenek c22f78ddfd Alternate format string checking: issue warnings for incomplete format specifiers.
In addition, move ParseFormatString() and FormatStringHandler() from
the clang::analyze_printf to the clang namespace.  Hopefully this will
resolve some link errors on Linux.

llvm-svn: 94794
2010-01-29 03:16:21 +00:00
Ted Kremenek 94af575e9c Alternate format string checking: issue a warning for invalid conversion specifiers.
llvm-svn: 94792
2010-01-29 02:40:24 +00:00
Ted Kremenek 176f7d6ef0 Yet another attempt to make the Linux buildbots happy. Apparently there are differences on how nested namespaces are handled...
llvm-svn: 94790
2010-01-29 02:13:53 +00:00
Ted Kremenek 559d89a02a Move definition of FormatStringHandler::~FormatStringHandler() within namespace directives. Hopefully this will make the Linux buildbots happy.
llvm-svn: 94784
2010-01-29 01:37:52 +00:00
Ted Kremenek 5739de77fa Add precision/field width checking to AlternateCheckPrintfString().
llvm-svn: 94774
2010-01-29 01:06:55 +00:00
Ted Kremenek b5c98ef61e Fix off-by-one error in ParseFormatSpecifier() when reporting the location of a null character.
llvm-svn: 94762
2010-01-28 23:56:52 +00:00
Ted Kremenek fee0e96c82 Add position of conversion specifier character to 'ConversionSpecifier'.
llvm-svn: 94739
2010-01-28 02:46:17 +00:00
Ted Kremenek 08ad1cceb3 Rename namespace clang::printf to clang::analyze_printf to avoid problems where the reference to 'printf' is ambiguous.
llvm-svn: 94733
2010-01-28 02:02:59 +00:00
Ted Kremenek bcbdaea703 Allow HandleFormatSpecifier() to indicate that no more processing of the format string is desired.
llvm-svn: 94715
2010-01-28 01:00:59 +00:00
Ted Kremenek c06ead62f0 Add '@' conversion specifier.
llvm-svn: 94713
2010-01-28 00:55:28 +00:00
Ted Kremenek fa784e88e8 Remove invalid conversion specifiers from format string checking.
llvm-svn: 94707
2010-01-28 00:17:51 +00:00
Ted Kremenek c8d9c01f04 Add a few more conversion specifiers to ParseFormatSpecifier (these appear in SemaChecking).
llvm-svn: 94704
2010-01-28 00:02:05 +00:00
Ted Kremenek a2e77b41f3 Add skeleton for a more structured way to analyzing pring format
strings than what we currently have in Sema.  This is both an
experiment and a WIP.

The idea is simple: parse the format string incrementally,
constructing a well-structure representation of each format specifier.
Each format specifier is then handed back one-by-one to a client via a
callback.  Malformed format strings are also handled with callbacks.
The idea is to separate the parsing of the format string from the
emission of diagnostics.  Currently what we have in Sema for handling
format strings is a mongrel of both that is hard to follow and
difficult to modify (I can apply this label since I'm the original
author of that code).

This is in libAnalysis as it is reasonable generic and can potentially
be used both by libSema and libChecker.

Comments welcome.

llvm-svn: 94702
2010-01-27 23:43:25 +00:00
Ted Kremenek d6b8708643 Split libAnalysis into two libraries: libAnalysis and libChecker.
(1) libAnalysis is a generic analysis library that can be used by
    Sema.  It defines the CFG, basic dataflow analysis primitives, and
    inexpensive flow-sensitive analyses (e.g. LiveVariables).

(2) libChecker contains the guts of the static analyzer, incuding the
    path-sensitive analysis engine and domain-specific checks.

Now any clients that want to use the frontend to build their own tools
don't need to link in the entire static analyzer.

This change exposes various obvious cleanups that can be made to the
layout of files and headers in libChecker.  More changes pending.  :)

This change also exposed a layering violation between AnalysisContext
and MemRegion.  BlockInvocationContext shouldn't explicitly know about
BlockDataRegions.  For now I've removed the BlockDataRegion* from
BlockInvocationContext (removing context-sensitivity; although this
wasn't used yet).  We need to have a better way to extend
BlockInvocationContext (and any LocationContext) to add
context-sensitivty.

llvm-svn: 94406
2010-01-25 04:41:41 +00:00
Chris Lattner 0bcc858a2b -fno-rtti is now the default.
llvm-svn: 94379
2010-01-24 20:43:31 +00:00
Zhongxing Xu a1293a67cd Process cast according to the cast kind. Prepare for more specific cast
handling (for C++). No functionality change for now.

llvm-svn: 94153
2010-01-22 04:30:00 +00:00
Mike Stump cc3a853df7 Improve unreachable code warnings with respect to dead binary and
unary operators.

llvm-svn: 94084
2010-01-21 17:21:23 +00:00
Mike Stump 04c6851cd6 Speed up compilation by avoiding generating exceptional edges from
CallExprs as those edges help cause a n^2 explosion in the number of
destructor calls.  Other consumers, such as static analysis, that
would like to have more a more complete CFG can select the inclusion
of those edges as CFG build time.

This also fixes up the two compilation users of CFGs to be tolerant of
having or not having those edges.  All catch code is assumed be to
live if we didn't generate the exceptional edges for CallExprs.

llvm-svn: 94074
2010-01-21 15:20:48 +00:00
Mike Stump 6bf1c08e99 Add infrastructure to add base initializers and member initializers to
the CFG.  WIP.

llvm-svn: 94062
2010-01-21 02:21:40 +00:00
Zhongxing Xu eb76a85af0 Correct comments.
llvm-svn: 93999
2010-01-20 07:57:45 +00:00
Mike Stump 845384a938 Wire up the EH context for the catch clauses to the outer EH context. WIP.
llvm-svn: 93963
2010-01-20 01:30:58 +00:00
Mike Stump 0bdba6cdd8 Add an exceptional edge from the try terminated block to the outer EH
context (try or the Exit block) when there isn't a catch (...).

Improve CFG printing for catch (...).

llvm-svn: 93962
2010-01-20 01:15:34 +00:00
Mike Stump 92244b00c7 Add CFG support for the start and end of scopes and infrastructure for
implicit destructor calls.  WIP.

llvm-svn: 93922
2010-01-19 22:00:14 +00:00
Ted Kremenek 60983dc3ad Tighten code and rework indentation of some if() branches (for readability). No functionality change.
llvm-svn: 93904
2010-01-19 20:52:05 +00:00
Ted Kremenek 1362b8bbe6 Remove extra space in uses of 'assert()'.
llvm-svn: 93903
2010-01-19 20:46:35 +00:00
Ted Kremenek b27378c82f Re-alphabetize cases in switch statement.
llvm-svn: 93902
2010-01-19 20:40:33 +00:00
Zhongxing Xu cd17954dbe Fix a serious bug: Tmp3 is the wrong destination set. We should create a new
intermediate destination set Tmp4.

llvm-svn: 93873
2010-01-19 09:25:53 +00:00
Mike Stump bbf5ba66a9 Add try/catch CFG support. Also improve throw CFG support. WIP.
llvm-svn: 93840
2010-01-19 02:20:09 +00:00
Zhongxing Xu 228b0d4def Add support for computing size in elements for symbolic regions obtained from
malloc().

llvm-svn: 93722
2010-01-18 08:54:31 +00:00
Zhongxing Xu e2bdb9a6e2 If the symbol has not been tracked, do not free it. This is possible when free
is called on a pointer that does not get its value directly from malloc.

llvm-svn: 93706
2010-01-18 03:27:34 +00:00
Ted Kremenek abf6ba1612 Don't suggest the developer use 'arc4random' instead of 'rand' when that function is not available. Fixes PR 6012.
llvm-svn: 93508
2010-01-15 08:20:31 +00:00
Ted Kremenek d74cc397c8 Teach BugReporter to "escape" the occurance of '%' characters in diagnostic messages when emitted results to the standard Diagnostics output. Fixes PR 6033.
llvm-svn: 93507
2010-01-15 07:56:51 +00:00
Ted Kremenek 959990b840 Convert a few more uses of std::string& to llvm::StringRef.
llvm-svn: 93506
2010-01-15 07:43:59 +00:00
Zhongxing Xu 803ade2532 Fix pr6035.
llvm-svn: 93422
2010-01-14 03:45:06 +00:00
Mike Stump 1bacb81d6f Add an unreachable code checker.
llvm-svn: 93287
2010-01-13 02:59:54 +00:00
Benjamin Kramer 378083101c Fix pasto.
llvm-svn: 93181
2010-01-11 20:15:06 +00:00
Benjamin Kramer 0129bd7432 Avoid use of deprecated functions (CStrInCStrNoCase and StringsEqualNoCase).
llvm-svn: 93175
2010-01-11 19:46:28 +00:00
Ken Dyck 40775003e6 Roll out ASTContext::getTypeSizeInChars(), replacing instances of
"ASTContext::getTypeSize() / 8". Replace [u]int64_t variables with CharUnits
ones as appropriate. 

Also rename RawType, fromRaw(), and getRaw() in CharUnits to QuantityType, 
fromQuantity(), and getQuantity() for clarity.

llvm-svn: 93153
2010-01-11 17:06:35 +00:00
Zhongxing Xu e47550e452 Enhance ScanReachableSymbols::scan(). Now another OSAtomic test case passes.
The old test case has a little mistake.

llvm-svn: 93148
2010-01-11 07:40:00 +00:00
Zhongxing Xu cbbf855432 Enhance SVals::getAsRegion: get the region that is converted to an integer.
This with previous patch fixes a OSAtomic test case.

llvm-svn: 93146
2010-01-11 06:52:53 +00:00
Ted Kremenek be909b5eff Switch RegionStore over to using <BaseRegion+raw offset> to store
value bindings.  Along with a small change to OSAtomicChecker, this
resolves <rdar://problem/7527292> and resolves some long-standing
issues with how values can be bound to the same physical address by
not have the same "key".  This change is only a beginning; logically
RegionStore needs to better handle loads from addresses where the
stored value is larger/smaller/different type than the loaded value.
We handle these cases in an approximate fashion now (via
CastRetrievedVal and help in SimpleSValuator), but it could be made
much smarter.

llvm-svn: 93137
2010-01-11 02:33:26 +00:00
Ted Kremenek 8e994a2808 Preliminary reworking of value-binding logic in RegionStore:
(1) Introduce a new 'BindingKey' class to match 'BindingValue'.  This
gives us the flexibility to change the current key value from 'const
MemRegion*' to something more interesting.

(2) Rework additions/removals/lookups from the store to use new
'Remove', 'Add', 'Lookup' utility methods.

No "real" functionality change; just prep work and abstraction.

llvm-svn: 93136
2010-01-11 00:07:44 +00:00
Ted Kremenek c6aa800eb3 Fix overzealous assertion in GRExprEngine::VisitLValue(). A
CallExpr/ObjCMessageExpr can be visited in an "lvalue" context if it
returns a struct temporary.  Currently the analyzer doesn't reason
about struct temporary returned by function calls, but we shouldn't
crash here either.

llvm-svn: 93081
2010-01-09 22:58:54 +00:00
Ted Kremenek 9aa01441c3 Fix broken diagnostic when returning the address of a stack-allocated array.
llvm-svn: 93071
2010-01-09 20:05:00 +00:00
Zhongxing Xu f1eeb78ffc When binding an rvalue to a reference, create a temporary object. Use
CXXObjectRegion to represent it. 

In Environment, lookup a literal expression before make up a value for it.

llvm-svn: 93047
2010-01-09 09:16:47 +00:00
Ted Kremenek b92304b42f Fix handling in GRExprEngine of 'default' branch in switch statements
when the default case is winnowed down to be infeasible.  When all
cases were ruled out (and the analysis state for the default case
would be infeasible) we would still consider the default case
possible.  This fixes PR 5969.

llvm-svn: 93017
2010-01-08 18:54:04 +00:00
Zhongxing Xu 662ba69a15 Revert r92318. Instead fix the analyzer: do not call
ASTContext::hasSameUnqualifiedType() when one of the type is VariableArrayType.

llvm-svn: 92723
2010-01-05 09:27:03 +00:00
Ted Kremenek acd71a4562 Make static analysis support for C++ 'this' expression context-sensitive. Essentially treat 'this' as a implicit parameter to the method call, and associate a region with it.
llvm-svn: 92675
2010-01-05 02:18:06 +00:00
Ted Kremenek de8e7447b6 Remove references to 'Checker' and 'GRTransferFuncs' from
GRStateManager.  Having these references was an abstraction violation,
as they really should only be known about GRExprEngine.

This change required adding a new 'ProcessAssume' callback in
GRSubEngine.  GRExprEngine implements this callback by calling
'EvalAssume' on all registered Checker objects as well as the
registered GRTransferFunc object.

llvm-svn: 92549
2010-01-05 00:15:18 +00:00
Zhongxing Xu b0e15df36b Let constraint manager inform checkers that some assumption logic has happend.
Add new states for symbolic regions tracked by malloc checker. This enables us
to do malloc checking more accurately. See test case.

Based on Lei Zhang's patch and discussion.

llvm-svn: 92342
2009-12-31 06:13:07 +00:00
Zhongxing Xu 7b8b4d70ef Simplify code by using an equivalent template class.
llvm-svn: 92305
2009-12-30 06:38:20 +00:00
Benjamin Kramer d20ef75b91 Remove some dead variables clang-analyzer found.
llvm-svn: 92162
2009-12-25 15:43:36 +00:00
Benjamin Kramer a713b5d9a8 Fix typo spotted by MSVC.
GRExprEngine.cpp(1348) : warning C4305: 'argument' : truncation from 'clang::ProgramPoint::Kind' to 'bool'

llvm-svn: 92154
2009-12-25 09:44:02 +00:00
Zhongxing Xu 51f1ca852f As Ted suggested, record the callsite information with the StackFrameContext.
llvm-svn: 92121
2009-12-24 03:34:38 +00:00
Ted Kremenek 9c951ab4f1 Enhance dataflow analyses to recognize branch statements in the CFG used as hooks for the initialization of condition variables.
llvm-svn: 92119
2009-12-24 02:40:30 +00:00
Zhongxing Xu 1704c4331b Inter-procedural analysis: now we can return from the callee.
llvm-svn: 92116
2009-12-24 02:25:21 +00:00
Ted Kremenek b135a13564 Teach GRExprEngine to handle the initialization of the condition variable of a ForStmt.
llvm-svn: 92114
2009-12-24 01:49:25 +00:00
Ted Kremenek ec92f9492b Add CFG support for the initializer of the condition variable of a ForStmt.
llvm-svn: 92113
2009-12-24 01:49:06 +00:00
Ted Kremenek 1ce53c4320 CFG tweak: in a WhileStmt, the condition variable initializer is evaluated every time the condition is checked.
llvm-svn: 92111
2009-12-24 01:34:10 +00:00
Ted Kremenek 09bc3b7df6 Teach GRExprEngine to handle the initialization of the condition variable of a WhileStmt.
llvm-svn: 92106
2009-12-24 00:54:56 +00:00
Ted Kremenek 1f07b4c439 Add CFG support for the initializer of the condition variable of a WhileStmt.
llvm-svn: 92105
2009-12-24 00:54:37 +00:00
Ted Kremenek 589493227b Teach GRExprEngine to handle the initialization of the condition variable of a SwitchStmt.
llvm-svn: 92102
2009-12-24 00:40:03 +00:00
Ted Kremenek 8b5dc12e52 Add CFG support for the initializer of the condition variable of a SwitchStmt.
llvm-svn: 92101
2009-12-24 00:39:26 +00:00
Ted Kremenek bff9844327 Tidy up FindSubExprAssignments to not deference the child_iterator multiple times.
llvm-svn: 92087
2009-12-23 23:37:10 +00:00
Nuno Lopes cfca1f0dc1 move a few more symbols to .rodata/.data.rel.ro
llvm-svn: 92012
2009-12-23 17:49:57 +00:00
Zhongxing Xu 2923046ec4 Migrate the call inliner to the Checker interface.
llvm-svn: 91991
2009-12-23 08:56:18 +00:00
Zhongxing Xu d2ab38e3f4 For inter-procedural analysis, predecessor node may be in another function.
So we should use the current program point.

llvm-svn: 91989
2009-12-23 08:54:57 +00:00
Ted Kremenek a7bcbde814 Add CFG support for the condition variable that can appear in IfStmts in C++ mode.
Add transfer function support in GRExprEngine for IfStmts with initialized condition variables.

llvm-svn: 91987
2009-12-23 04:49:01 +00:00
Ted Kremenek 857f41c650 Suppress dead store warnings involving objects initialized with CXXExprTemporaries.
llvm-svn: 91986
2009-12-23 04:11:44 +00:00
Ted Kremenek 76d5225271 Add stack trace pretty printing in GRExprEngine::VisitLValue().
llvm-svn: 91985
2009-12-23 04:09:43 +00:00
Ted Kremenek 9a05f20d41 Teach GRExprEngine::VisitLValue to ignore CXXExprWithTempories (for now).
llvm-svn: 91982
2009-12-23 03:14:23 +00:00
Ted Kremenek 25e280bf02 Fix PR 5857. When casting from a symbolic region to an integer back to a pointer value, we were not correctly layering the correct ElementRegion on the original SymbolicRegion.
llvm-svn: 91981
2009-12-23 02:52:14 +00:00
Ted Kremenek bb7a826844 Teach GRExprEngine::VisitLValue that we don't handle CXXZeroInitValueExprs yet.
llvm-svn: 91970
2009-12-23 01:25:13 +00:00
Ted Kremenek 343b51271d Also treat the type of the subexpression as a pointer in GRExprEngine::VisitCast when the expression is handled as an lvalue.
llvm-svn: 91969
2009-12-23 01:19:20 +00:00
Ted Kremenek 22cc1a8438 Add basic support for analyzing CastExprs as lvalues.
llvm-svn: 91952
2009-12-23 00:26:16 +00:00
Ted Kremenek e19711d223 Add transfer functions support for visiting an Objective-C message expression as an lvalue when the return type is a C++ reference.
llvm-svn: 91926
2009-12-22 22:13:46 +00:00
Zhongxing Xu fd62a33616 Add comments.
llvm-svn: 91818
2009-12-21 06:52:24 +00:00
Zhongxing Xu 4794801e27 Use the FunctionDecl's result type to know exactly if it returns a reference.
llvm-svn: 91751
2009-12-19 03:17:55 +00:00
Ted Kremenek af1bdd71af Enhance GRExprEngine::VisitCallExpr() to be used in an lvalue context. Uncovered a new failing test case along the way, but we're making progress on handling C++ references in the analyzer.
llvm-svn: 91710
2009-12-18 20:13:39 +00:00
Ted Kremenek 48af0e0a71 Tweak formatting and comments.
llvm-svn: 91615
2009-12-17 20:10:17 +00:00
Ted Kremenek 94cc33f33e Convert GRExprEngine::VisitCallExpr() to use a worklist instead of recursion to evaluate the arguments of a CallExpr. This simplifies the logic and makes it easier to read. (it also avoids any issues with blowing out the stack if the CallExpr had a ridiculous number of arguments)
llvm-svn: 91613
2009-12-17 20:06:29 +00:00
Ted Kremenek da7d55a4a8 Reduce nesting by using early exits. No functionality change.
llvm-svn: 91610
2009-12-17 19:17:27 +00:00
Ted Kremenek f907cee544 Sort switch statement. No functionality change.
llvm-svn: 91591
2009-12-17 07:38:34 +00:00
Ted Kremenek 2e2b258158 Fix check in GRExprEngine for the 'main' function to handle NULL IdentifierInfo*'s.
llvm-svn: 91577
2009-12-17 01:20:43 +00:00
Ted Kremenek d970acb60f Completely remove ObjCObjectRegion (tests pass this time).
llvm-svn: 91572
2009-12-16 23:53:37 +00:00
Ted Kremenek 3ab9e4cf87 Temporarily revert 91553.
llvm-svn: 91557
2009-12-16 19:46:44 +00:00
Ted Kremenek 023bceaf1b Remove use of ObjCObjectRegion from BasicStoreManager.
llvm-svn: 91553
2009-12-16 19:42:23 +00:00
Zhongxing Xu 6df9f54d6d Add a new kind of region: CXXObjectRegion. Currently it has only one
attribute: the object type. 
Add initial support for visiting CXXThisExpr.
Fix a bunch of 80-col violations.

llvm-svn: 91535
2009-12-16 11:27:52 +00:00
Ted Kremenek 9bcc264494 Teach RetainSummaryManager::getSummary(FunctionDecl* FD) that 'FD->getIdentifier()' will not always return a non-null IdentifierInfo*.
llvm-svn: 91512
2009-12-16 06:06:43 +00:00
Ted Kremenek 2d251557ef Teach OSAtomicChecker that a FunctionDecl's name isn't always a simple IdentifierInfo*.
llvm-svn: 91511
2009-12-16 06:03:24 +00:00
Ted Kremenek 85763180e7 Teach NoReturnFunctionChecker that FunctionDecl::getIdentifier() is not guaranteed to return a non-null IdentifierInfo*.
llvm-svn: 91510
2009-12-16 05:58:28 +00:00
Ted Kremenek 4cad5fc035 Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.

The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements.  Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue.  DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.

The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.

In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents.  EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).

Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).

Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references.  This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.

llvm-svn: 91501
2009-12-16 03:18:58 +00:00
Ted Kremenek 9158fb748c Remove ValueManager::getRegionValueSymbolValOrUnknown(). It was just extra veneer on top of getRegionValueSymbolVal().
llvm-svn: 91471
2009-12-15 23:23:27 +00:00
Chris Lattner 2f3da9b205 update to match LLVM API change:
Remove isPod() from DenseMapInfo, splitting it out to its own
isPodLike type trait.  This is a generally useful type trait for
more than just DenseMap, and we really care about whether something
acts like a pod, not whether it really is a pod.

llvm-svn: 91422
2009-12-15 07:26:51 +00:00
Ted Kremenek 29f3808667 Until we can make the dead stores checker smarter, dont' emit dead store warnings for C++ objects (whose constructors/destructors have possible side-effects).
llvm-svn: 91412
2009-12-15 04:12:12 +00:00
Ted Kremenek c98cdd175a Start the ball rolling on C++ support in the static analyzer. For
now, don't construct CFGs that contain C++ try/catch statements, and
have GRExprEngine abort a path if it encounters a C++ construct it
doesn't understand (which is mostly everything at this point).

llvm-svn: 91389
2009-12-15 01:38:04 +00:00
Ted Kremenek 814c416636 Fix: <rdar://problem/7468209> SymbolManager::isLive() should not crash on captured block variables that are passed by reference
llvm-svn: 91348
2009-12-14 22:15:06 +00:00
Zhongxing Xu cf86de4067 Use insert to avoid destroying existing nodes.
llvm-svn: 91258
2009-12-14 02:13:39 +00:00
Zhongxing Xu c0484fa611 Add initial support for realloc() in MallocChecker.
llvm-svn: 91216
2009-12-12 12:29:38 +00:00
Jeffrey Yasskin 1615d45daa Un-namespace-qualify llvm_unreachable. It's a macro, so the qualification gave
no extra safety anyway.

llvm-svn: 91207
2009-12-12 05:05:38 +00:00
Benjamin Kramer 4dab76a752 Switch PathDiagnostic to StringRef.
llvm-svn: 91155
2009-12-11 21:09:27 +00:00
Ted Kremenek f6d9cebafd Enhance understanding of VarRegions referenced by a block whose declarations are outside the current stack frame. Fixes <rdar://problem/7462324>.
llvm-svn: 91107
2009-12-11 06:43:27 +00:00
Zhongxing Xu 9cb53b86af Completely evaluate malloc/free in MallocChecker.cpp.
llvm-svn: 91100
2009-12-11 03:09:01 +00:00
Zhongxing Xu 1239de1592 Use 'class' instead of 'struct'.
llvm-svn: 91085
2009-12-11 00:55:44 +00:00
Ted Kremenek 8573913760 Fix null dereference in OSAtomicChecker and special case SymbolicRegions. We still aren't handling them correctly; I've added to failing test cases to test/Analysis/NSString-failed-cases.m that should pass and then be merged in to test/Analysis/NSString.m.
llvm-svn: 90993
2009-12-09 23:29:55 +00:00
Zhongxing Xu 1042bf4ae2 Refactor OSAtomic evaluation logic into OSAtomicChecker.
llvm-svn: 90968
2009-12-09 12:23:28 +00:00
Zhongxing Xu 8cca37fae0 Use a temporary destination set such that we can clear fake auto transitions.
Otherwise, even when real evaluation occurs, the previous fake auto 
transitions would still be in the destination set, causing fake state 
bifurcation.

llvm-svn: 90967
2009-12-09 12:16:07 +00:00
Zhongxing Xu 1d153328be OSAtomic simulation: use the original region as the location to load from,
instead of the ElementRegion obtained from casts.

Test cast: the leak cannot occur bacause the true branch cannot be taken.

llvm-svn: 90964
2009-12-09 08:32:57 +00:00
Zhongxing Xu f5448561ed remove dead code.
llvm-svn: 90953
2009-12-09 05:52:12 +00:00
Zhongxing Xu d1dee7e71a Insert instead of assign to the dest node set, since we use the dest node set
repeatedly.

llvm-svn: 90952
2009-12-09 05:48:53 +00:00
Ted Kremenek 32c32892f7 Fix a horrid bug in GRExprEngine::CheckerVisit() that was identified
by the test case in PR 5627.  Essentially we shouldn't clear the
ExplodedNodeSet where we deposit newly constructed nodes if that set
is the 'Dst' set passed in.  It is not okay to clear that set because
it may already contain nodes.

llvm-svn: 90931
2009-12-09 02:45:41 +00:00
Zhongxing Xu fe2f901269 Refactor builtin function evaluation into a checker.
llvm-svn: 90847
2009-12-08 09:07:59 +00:00
Ted Kremenek 04af9f20fb Add analysis support for blocks. This includes a few key changes:
- Refactor the MemRegion hierarchy to distinguish between different StackSpaceRegions for locals and parameters.
- VarRegions for "captured" variables now have the BlockDataRegion as their super region (except those passed by reference)
- Add transfer function support to GRExprEngine for BlockDeclRefExprs.

This change also supports analyzing blocks as an analysis entry point
(top-of-the-stack), which required pushing more context-sensitivity
around in the MemRegion hierarchy via the use of LocationContext
objects.  Functionally almost everything is the same, except we track
LocationContexts in a few more areas and StackSpaceRegions now refer
to a StackFrameContext object.  In the future we will need to modify
MemRegionManager to allow multiple StackSpaceRegions in flight at once
(for the analysis of multiple stack frames).

llvm-svn: 90809
2009-12-07 22:05:27 +00:00
Zhongxing Xu 175447f743 Add EvalCallExpr interface to checker, and migrate the no-return function
handler to this interface.
GRExprEngine::CheckerEvalCall() will return true if one of the checkers has
processed the node. In the future this might return void when we have some 
default checker.

llvm-svn: 90755
2009-12-07 09:17:35 +00:00
Ted Kremenek 45805b9a50 Teach AnalysisContext::getBody() about BlockDecls.
llvm-svn: 90585
2009-12-04 20:34:55 +00:00
Ted Kremenek ed2246aa2a Teach 'ExecutionContinues' (part of BugReporter's diagnostic generation) about BlockDecls.
llvm-svn: 90584
2009-12-04 20:34:31 +00:00
Ted Kremenek 75d6fa27bd Include BlockDeclRefExprs in constructed CFGs.
llvm-svn: 90583
2009-12-04 20:33:25 +00:00
Ted Kremenek c32f2c2e0f Replace SymbolReaper::isLive(VarDecl) with SymbolReaper::isLive(VarRegion).
llvm-svn: 90582
2009-12-04 20:32:20 +00:00
Ted Kremenek 6e8541ddd0 Rename instance variable to avoid name conflict with parameters, and modify addTransition() to compare the correct state values.
llvm-svn: 90552
2009-12-04 06:57:49 +00:00
Ted Kremenek c7916f9ff2 Allow BlockInvocationContext to wrap either a BlockDecl* or a BlockDataRegion*, giving us choice in our degree of context-sensitivity.
llvm-svn: 90516
2009-12-04 02:03:51 +00:00
Ted Kremenek 43d4a899c4 Refactor LocationContext creation logic into a single member template.
llvm-svn: 90509
2009-12-04 01:28:56 +00:00
Ted Kremenek 253882431e Refactor FoldingSet profiling code for LocationContexts, and add a new BlockInvocationContext to represent the invocation of a block.
llvm-svn: 90506
2009-12-04 00:50:10 +00:00
Ted Kremenek 721fcc007e constify MemRegion* returned by MemRegionManager::getXXXRegion() methods.
llvm-svn: 90503
2009-12-04 00:26:31 +00:00
Ted Kremenek 0ecd4c7d70 More template-logic for MemRegion construction out of MemRegion.h and into MemRegion.cpp.
llvm-svn: 90499
2009-12-04 00:05:57 +00:00
Ted Kremenek 4b349cc9c5 Tweak handling of BlockDataRegions in RegionStoreManager::RemoveDeadBindings(): only the VarRegions for variables marked with the '__block' annotation should have their lifetime extended by a BlockDataRegion.
llvm-svn: 90462
2009-12-03 17:48:05 +00:00
Zhongxing Xu 39bba629f3 Add security syntactic checker for mktemp.
Patch by Lei Zhang!

llvm-svn: 90444
2009-12-03 09:15:23 +00:00
Daniel Dunbar 98f2067ca4 Update CMake for CallGraph.cpp move.
llvm-svn: 90443
2009-12-03 09:14:19 +00:00
Ted Kremenek 5bee5c4ff0 Add value invalidation logic for block-captured variables. Conceptually invoking a block (without specific reasoning of what the block does) can invalidate any value to it by reference when the block was created.
llvm-svn: 90431
2009-12-03 08:25:47 +00:00
Ted Kremenek 4a815fc82e Make BlockDataRegion::referenced_vars_iterator an actual class that enforces that all MemRegions iterated over are VarRegions.
llvm-svn: 90430
2009-12-03 08:09:21 +00:00
Daniel Dunbar 19a30ca8c0 Fix layering violation by moving Analysis/CallGraph to Index
llvm-svn: 90424
2009-12-03 07:20:04 +00:00
Ted Kremenek e5716cbae7 Add batch version of 'StoreManager::InvalidateRegion()' for invalidating multiple regions as once. After adopting this in the CFRefCount::EvalCall(), we see a reduction in analysis time of 1.5% when analyzing all of SQLite3.
llvm-svn: 90405
2009-12-03 03:27:11 +00:00
Ted Kremenek f66b72094a Add a heuristic to the dead stores checker to prune dead stores for variables annotated with '__block'. This is overly conservative, but now the analyzer doesn't report dead stores for variables that can be updated by a block call.
llvm-svn: 90364
2009-12-03 00:46:16 +00:00
Zhongxing Xu af35329f71 Hard bifurcate the state into nil receiver and non-nil receiver, so that
we don't need to use the DoneEvaluation hack when check for 
ObjCMessageExpr.

PreVisitObjCMessageExpr() only checks for undefined receiver or arguments.

Add checker interface EvalNilReceiver(). This is a 'once-and-done' interface.

llvm-svn: 90296
2009-12-02 05:49:12 +00:00
Ted Kremenek 117e472b52 Provide the correct vector size for referenced variables.
llvm-svn: 90267
2009-12-01 22:12:34 +00:00
Ted Kremenek d3a241a9c6 Fix early-return logic in scanReachableSymbols() to match the rest of the recursive logic in the methods of ScanReachableSymbols.
llvm-svn: 90245
2009-12-01 17:50:25 +00:00
Douglas Gregor 693ba203a1 Eliminate another VISIBILITY_HIDDEN
llvm-svn: 90139
2009-11-30 16:08:24 +00:00
Tobias Grosser 9fc223a6b1 Adapt to the DOTGraphTraits changes in LLVM.
llvm-svn: 90137
2009-11-30 14:16:05 +00:00
Benjamin Kramer 6341553c93 Port BugReporter and BugType to StringRef.
llvm-svn: 90086
2009-11-29 18:27:55 +00:00
Benjamin Kramer ff3750f306 Kill some unnecessary calls to c_str().
llvm-svn: 90084
2009-11-29 18:03:28 +00:00
Ted Kremenek 33e88a7be7 Fix null dereference in UndefResultChecker identified by running the analyzer over Postgresql.
llvm-svn: 90060
2009-11-29 06:37:44 +00:00
Benjamin Kramer 4e75cd063f Cleanup includes and forward decls.
llvm-svn: 90034
2009-11-28 10:50:44 +00:00
Benjamin Kramer 435ef9b383 Remove unneeded includes.
llvm-svn: 90032
2009-11-28 09:41:31 +00:00
Kovarththanan Rajaratnam 65c6566b5b lib/Analysis: Remove VISIBILITY_HIDDEN from definitions in anonymous namespace
llvm-svn: 90028
2009-11-28 06:07:30 +00:00
Ted Kremenek 2350e0c3ba Improve diagnostics in ReturnStackAddressChecker for returning a stack-allocated block. Implements the rest of <rdar://problem/7387385>.
llvm-svn: 89940
2009-11-26 07:14:50 +00:00
Ted Kremenek f89dcdaf19 Add a PostVisitBlockExpr() method to RetainReleaseChecker to query for
the set of variables "captured" by a block.  Until the analysis gets
more sophisticated, for now we stop the retain count tracking of any
objects (transitively) referenced by these variables.

llvm-svn: 89929
2009-11-26 02:38:19 +00:00
Ted Kremenek 94f8c4a7d5 Teach RegionStoreManager::RemoveDeadBindings() about BlockDataRegions. Any VarRegion for a "captured" variable should also be considered live.
llvm-svn: 89928
2009-11-26 02:35:42 +00:00
Ted Kremenek 3378b610ae Add iterators to BlockDataRegion that allow clients to iterate over the VarRegions for "captured" variables for a block.
llvm-svn: 89927
2009-11-26 02:34:36 +00:00
Ted Kremenek 705fd953ef Added batch versions of GRState::scanReachableSymbols() so that clients can scan a collection of SVals or MemRegions all at once.
llvm-svn: 89926
2009-11-26 02:32:19 +00:00
Ted Kremenek 0f5e6f8805 Enhance LiveVariables to understand that blocks can extend the liveness of a variable by "capturing" them in a BlockExpr.
This required two changes:

1) Added 'getReferencedgetReferencedBlockVars()' to AnalysisContext so
that clients can iterate over the "captured" variables in a block.

2) Modified LiveVariables to take an AnalysisContext& in its
constructor and to call getReferencedgetReferencedBlockVars() when it
processes a BlockExpr*.

llvm-svn: 89924
2009-11-26 02:31:33 +00:00
Ted Kremenek 1646cf6d05 Add missing case in switch statement.
llvm-svn: 89903
2009-11-25 23:58:21 +00:00
Ted Kremenek b63ad7a6c1 Refine MemRegions for blocks. Add a new region called
'BlockDataRegion' to distinguish between the code associated with a
block (which is represented by 'BlockTextRegion') and an instance of a
block, which includes both code and data.  'BlockDataRegion' has an
associated LocationContext, which can be used to eventually model the
lifetime of a block object once LocationContexts can represent scopes
(and iterations around a loop, etc.).

llvm-svn: 89900
2009-11-25 23:53:07 +00:00
Ted Kremenek 80f70b54aa Remove recently added FIXME. The appropriate FIXME is already in MemRegionManager::getVarRegion().
llvm-svn: 89897
2009-11-25 23:30:34 +00:00
Ted Kremenek a3d6e62003 Add FIXME.
llvm-svn: 89892
2009-11-25 22:41:34 +00:00
Ted Kremenek e6929ffc21 Add post-visit Checker support in GRExprEngine for BlockExpr.
llvm-svn: 89890
2009-11-25 22:23:25 +00:00
Ted Kremenek 70a8788368 Add a new RetainReleaseChecker class (that subclasses CheckerVisitor) to extend the functionality of the retain/release checker using the new Checker interface. Pieces of CFRefCount will gradually be migrated to this new class over time.
llvm-svn: 89889
2009-11-25 22:17:44 +00:00
Ted Kremenek 945422794b Move RegisterChecks() to the end of the file. No functionality change.
llvm-svn: 89888
2009-11-25 22:08:49 +00:00
Ted Kremenek d0fe8047dd Make RegisterInternalChecks() part of GRExprEngine's private implementation by making it a static function within GRExprEngine.cpp.
llvm-svn: 89884
2009-11-25 21:51:20 +00:00
Ted Kremenek efb5003f95 Register internal checks with GRExprEngine when it is constructed, not manually in AnalysisConsumer.cpp.
llvm-svn: 89883
2009-11-25 21:45:48 +00:00
Ted Kremenek acdc817ed9 When dispatching to Checker objects in GRExprEngine::CheckerVisit(),
only stop processing the checkers after all the nodes for a current
check have been processed.  This (I believe) handles the case where
PredSet (the input nodes) contains more than one node due to state
bifurcation.  Zhongxing: can you review this?

llvm-svn: 89882
2009-11-25 21:40:22 +00:00
Ted Kremenek e6a2780c96 Add really basic support for blocks in the retain/release checker. For now, anytime we pass a tracked object to a block call we stop tracking it.
llvm-svn: 89831
2009-11-25 01:35:18 +00:00
Ted Kremenek 470bfa47db Allow building of CFGs for ASTs that contain BlockExprs.
llvm-svn: 89830
2009-11-25 01:34:30 +00:00
Ted Kremenek cfe223f637 Add transfer function support for BlockExpr.
llvm-svn: 89829
2009-11-25 01:33:13 +00:00
Ted Kremenek 10a50e7371 Split CodeTextRegion into FunctionTextRegion and BlockTextRegion. This a precursor to having basic static analysis support for blocks.
llvm-svn: 89828
2009-11-25 01:32:22 +00:00
Ted Kremenek 1fc1f20efd For the nil-receiver checker, take into account the behavioral changes that got introduced in Mac OS X 10.5 and later, notably return values of double, float, etc., will not be garbage. Fixes <rdar://problem/6829160>.
llvm-svn: 89809
2009-11-24 22:48:18 +00:00
Ted Kremenek 005e8a06f2 Cleanups and fixes to the nil-receiver checker, some of it fallout the
initial transition of the nil-receiver checker to the Checker
interface as done in r89745.  Some important changes include:

1) We consolidate the BugType object used for nil receiver bug
reports, and don't include the type of the returned value in the
BugType (which would be wrong if a nil receiver bug was reported more
than once)

2) Added a new (temporary) flag to CheckerContext: DoneEvauating.
This is used by GRExprEngine when evaluating message expressions to
not continue evaluating the message expression if this flag is set.
This flag is currently set by the nil receiver checker.  This is an
intermediate solution to allow the nil-receiver checker to properly
work as a plug-in outside of GRExprEngine.  Basically, this flag
indicates that the entire message expression has been evaluated, not
just a precondition (which is what the nil-receiver checker does).
This flag *should not* be repurposed for general use, but just to pull
more things out of GRExprEngine that already in there as we devise a
better interface in the Checker class.

3) Cleaned up the logic in the nil-receiver checker, making the
control-flow a lot easier to read.

llvm-svn: 89804
2009-11-24 21:41:28 +00:00
Zhongxing Xu c2998766f0 We can remove this file now.
llvm-svn: 89751
2009-11-24 08:28:49 +00:00
Zhongxing Xu c6123a1a3c Refactor undefined result checker. This is the last one.
llvm-svn: 89750
2009-11-24 08:24:26 +00:00
Zhongxing Xu 9e200798c2 Refactor NilReceiverStructRet and NilReceiverLargerThanVoidPtrRet into
CallAndMessageChecker.

llvm-svn: 89745
2009-11-24 07:06:39 +00:00
Zhongxing Xu 72269ec8cb rename UndefinedArgChecker to CallAndMessageChecker.
llvm-svn: 89735
2009-11-24 04:45:44 +00:00
Zhongxing Xu da32375115 Rename: UndefinedArgChecker.cpp => CallAndMessageChecker.cpp
llvm-svn: 89734
2009-11-24 04:08:01 +00:00
Ted Kremenek c0229557dd Enhance null dereference diagnostics by indicating what variable (if any) was dereferenced. Addresses <rdar://problem/7039161>.
llvm-svn: 89726
2009-11-24 01:33:10 +00:00
Ted Kremenek b0c0b08c71 After performing a bounds check in ArrayBoundChecker, record the fact that a bounds check succeeded by transitioning the ExplodedGraph.
llvm-svn: 89712
2009-11-23 23:23:26 +00:00
Ted Kremenek f57351570e Clean up the Checker API a little more, resolving some hidden bugs
along the way.  Important changes:

1) To generate a sink node, use GenerateSink(); GenerateNode() is for
generating regular transitions.  This makes the API clearer and also
allows us to use the 'bool' option to GenerateNode() for a different
purpose.

2) GenerateNode() now automatically adds the generated node to the
destination ExplodedNodeSet (autotransition) unless the client
specifies otherwise with a bool flag.  Several checkers did not call
'addTransition()' after calling 'GenerateNode()', causing the
simulation path to be prematurely culled when a non-fail stop bug was
encountered.

3) Add variants of GenerateNode()/GenerateSink() that take neither a
Stmt* or a GRState*; most callers of GenerateNode() just pass in the
same Stmt* as provided when the CheckerContext object is created; we
can just use that the majority of the time.  This cleanup also allows
us to potentially coelesce the APIs for evaluating branches and
end-of-paths (which currently directly use builders).

4) addTransition() no longer needs to be called except for a few
cases.  We now have a variant of addTransition() that takes a
GRState*; this allows one to propagate the updated state without
caring about generating a new node explicitly.  This nicely cleaned up
a bunch of cases that called autoTransition() with a bunch of
conditional logic surround the call (that common logic has now been
swallowed up by addTransition() itself).

llvm-svn: 89707
2009-11-23 22:22:01 +00:00
Ted Kremenek b43737387b Provide out-of-line definition for destructor of Checker.
llvm-svn: 89688
2009-11-23 18:53:03 +00:00
Ted Kremenek 02d6aca867 Tweak UndefBranchChecker to register the most nested "undefined" expression with bugreporter::registerTrackNullOrUndefValue instead of the condition itself.
llvm-svn: 89682
2009-11-23 18:12:03 +00:00
Ted Kremenek d4dca6fde6 Cleanup title/description of "undefined branch" BugType and add some test cases for this check.
llvm-svn: 89679
2009-11-23 17:58:48 +00:00
Douglas Gregor 1c3feb5b25 Fix CMake build
llvm-svn: 89650
2009-11-23 12:03:50 +00:00
Zhongxing Xu 5f76620b53 UndefBranchChecker: more bug reporter helper information emit.
llvm-svn: 89643
2009-11-23 03:29:59 +00:00
Zhongxing Xu 56dd5f0f70 Initial refactor of UndefBranchChecker. We still use GRBranchNodeBuilder
in the checker directly. But I don't have a better approach for now.

llvm-svn: 89640
2009-11-23 03:20:54 +00:00
Ted Kremenek 12b64959ce Change CheckDeadStores to use Expr::isNullPointerConstant, which will correctly determine whether an expression is a null pointer constant.
Patch by Kovarththanan Rajaratnam!

llvm-svn: 89621
2009-11-22 20:26:21 +00:00
Zhongxing Xu 014af28ce3 Undefined compound assignment result is checked in UndefinedAssignmentChecker. So this check is redundant.
llvm-svn: 89592
2009-11-22 13:36:20 +00:00
Zhongxing Xu 39638e133a Remove invalid comments. The result is undefined only when operands are undefined.
llvm-svn: 89591
2009-11-22 13:30:10 +00:00
Zhongxing Xu 7f83e97b00 Save and restore the HasGen flag in MallocChecker.
llvm-svn: 89590
2009-11-22 13:22:34 +00:00
Benjamin Kramer df58afae56 Don't include a dead header.
llvm-svn: 89587
2009-11-22 12:51:08 +00:00
Zhongxing Xu f0b7fc8890 Remove UndefinedAssignmentChecker's header.
llvm-svn: 89585
2009-11-22 12:29:52 +00:00
Ted Kremenek d354278b51 Make FixedAddressChecker and experimental check; it currently produces a ton of false positives when analyzing some projects (e.g., Wine).
llvm-svn: 89560
2009-11-21 17:55:24 +00:00
Ted Kremenek 9d6daf2cc4 Restructure DereferenceChecker slightly to handle caching out when we would report a null dereference more than once.
llvm-svn: 89526
2009-11-21 01:50:48 +00:00
Ted Kremenek caf2c51fad Pull BadCallChecker int UndefinedArgChecker, and have UndefinedArgChecker also handled undefined receivers in message expressions.
llvm-svn: 89524
2009-11-21 01:25:37 +00:00
Ted Kremenek f7adea43b4 More checker refactoring. Passing undefined values in a message expression is now handled by UndefinedArgChecker.
llvm-svn: 89519
2009-11-21 00:49:41 +00:00
Benjamin Kramer 7d875c7e7e Fix typo GCC 4.3 warned about.
llvm-svn: 89453
2009-11-20 10:03:00 +00:00
Ted Kremenek a4f7c180ae Add simple static analyzer checker to check for sending 'release', 'retain', etc. directly to a class. Fixes <rdar://problem/7252064>.
llvm-svn: 89449
2009-11-20 05:27:05 +00:00
Ted Kremenek c1f161c012 Unused ivar checker: ivars referenced by lexically nested functions should not be flagged as unused. Fixes <rdar://problem/7254495>.
llvm-svn: 89448
2009-11-20 04:31:57 +00:00
Zhongxing Xu ab0ae2139a Revert r89437 and add a comment.
llvm-svn: 89446
2009-11-20 03:50:46 +00:00
Zhongxing Xu 6d9a942174 It's unnecessary to check for unknown at this point.
llvm-svn: 89437
2009-11-20 01:56:48 +00:00
Ted Kremenek dd2b2b23c8 Fix null dereference in NSAutoreleasePoolChecker when analyzing messages sent to blocks.
llvm-svn: 89413
2009-11-20 00:12:36 +00:00
Ted Kremenek 439a6d146c Fix crash when using --analyzer-store=region when handling initializers with nested arrays/structs whose values are not explicitly specified. Fixes <rdar://problem/7403269>.
llvm-svn: 89384
2009-11-19 20:20:24 +00:00
Ted Kremenek 0c54d2da14 Remove printf statement.
llvm-svn: 89383
2009-11-19 20:01:53 +00:00
Ted Kremenek 4b35a2ed08 Only fetch the ASTContext object within the assertion.
llvm-svn: 89375
2009-11-19 19:04:08 +00:00