Commit Graph

177 Commits

Author SHA1 Message Date
Ted Kremenek d331d09e2f Add a QualType to ConjuredSymbol to represent the type and size of the symbol.
Use this updated interface when invalidating arguments passed by reference; the type of symbol is of the object passed by reference, not the reference itself.

llvm-svn: 56894
2008-10-01 00:21:14 +00:00
Ted Kremenek 21c24f1785 Revert 56735. The old bug categories were more informative.
llvm-svn: 56755
2008-09-27 22:02:42 +00:00
Ted Kremenek 16a59fabec Change "leaks" to have the category "Performance".
llvm-svn: 56735
2008-09-27 00:45:27 +00:00
Ted Kremenek 76f79ba890 Change casing of bug type.
llvm-svn: 56405
2008-09-21 19:08:31 +00:00
Ted Kremenek de195e2100 Add "category" to BugTypes, allowing bugs to be grouped.
Changed casing of many bug names.  The convention will be to have bug names (mostly) lower cased, and categories use some capitalization.

llvm-svn: 56385
2008-09-20 04:23:38 +00:00
Ted Kremenek 1b9e10390b Store: (static analyzer)
- Change definition of store::Region and store::Binding (once again) to make
  them real classes that just wrap pointers. This makes them more strictly
  typed, and allows specific implementations of Regions/Bindings to just
  subclass them.
- minor renamings to RegionExtent and its subclasses
- added a bunch of doxygen comments

StoreManager: (static analyzer)
- added 'iterBindings', an iteration method for iterating over the bindings of a
  store. It that takes a callback object (acting like a poor man's closure).
- added 'getRVal' version for store::Binding. Will potentially phase the other
  versions of GetRVal in StoreManager out.
- reimplemented 'getBindings' to be non-virtual and to use 'iterBindings'

BasicStoreManager: (static analyzer)
- implemented 'iterBindings' for BasicStoreManager

llvm-svn: 55688
2008-09-03 03:06:11 +00:00
Zhongxing Xu c1bd3a5f8b Migrate the rest symbolic analysis stuff to BasicConstraintManager.
llvm-svn: 55536
2008-08-29 14:52:36 +00:00
Ted Kremenek c83e755d78 Added "getBindings" and "BindingAsString" to GRStateManager and StoreManager.
Migrated CFRefCount.cpp to use getBindings and BindingsAsString instead of
making assumptions about the Store (removed dependence on GRState::vb_iterator).

llvm-svn: 55522
2008-08-29 00:47:32 +00:00
Ted Kremenek 87aab6c771 Migrate the retain/release checker to not manage the RefBindings::Factory object
directly, but instead have GRStateManager manage it.

llvm-svn: 54862
2008-08-17 03:20:02 +00:00
Ted Kremenek ceba6ead45 GRState:
- Remove ConstNotEq from GRState/GRStateManager (!= tracking uses GDM instead).
- GRStateManager now can book-keep "contexts" (e.g., factory objects) for uses
  with data elements stored into the GDM.
- Refactor pretty-printing of states to use GRState::Printer objects
  exclusively. This removed a huge amount of pretty-printing logic from
  GRExprEngine.

CFRefCount
- Simplified some API calls based on refinements to the GDM api.

llvm-svn: 54835
2008-08-16 00:49:49 +00:00
Ted Kremenek db7dd9cd15 Migrated retain/release checker to use the Generic Data Map in GRState (instead
of using CheckerState).

Removed CheckerState from GRState.

Added class GRStateRef which wraps GRState* and GRStateManager*. This is handy
for generating new states with a single handle.

Added member template set/get functions to GRStateRef/GRState/GRStateManager for
accessing the Generic Data Map.

llvm-svn: 54788
2008-08-14 21:16:54 +00:00
Ted Kremenek 16306107cf Renamed GRState::CheckerStatePrinter to GRState::Printer.
Updated checker state printer interface to allow transfer functions to return an arbitrary number of GRState::Printers.

llvm-svn: 54762
2008-08-13 21:24:49 +00:00
Ted Kremenek 5ab5a1b578 Rename ValueState -> GRState.
Rename ValueStateManager -> GRStateManager.

llvm-svn: 54721
2008-08-13 04:27:00 +00:00
Ted Kremenek 9551ab6c8c More cleanups. Add missing #include.
llvm-svn: 54699
2008-08-12 20:41:56 +00:00
Ted Kremenek 3f13f598ce More summary generation refactoring.
llvm-svn: 54696
2008-08-12 18:48:50 +00:00
Ted Kremenek 050b91cd28 Add variadic addInstMethSummary() and refactored addPanicSummary() to use this method. (code reduction).
Misc. cleanups.

llvm-svn: 54694
2008-08-12 18:30:56 +00:00
Daniel Dunbar 6e8aa537f8 More #include cleaning
- Drop {Decl.h,DeclObjC.h,IdentifierTable.h} from Expr.h
 - Moved Sema::getCurMethodDecl() out of line (dependent on
   ObjCMethodDecl via dyn_cast).

llvm-svn: 54629
2008-08-11 05:35:13 +00:00
Chris Lattner 3f6cd0bc76 remove some unneeded calls to getCanonicalType
llvm-svn: 54106
2008-07-26 22:36:27 +00:00
Ted Kremenek 9e9afb552c Correctly handle NSAssertionHandle -handleFailureInMethod:object:file:lineNumber:description:
This fixes: http://llvm.org/bugs/show_bug.cgi?id=2593

llvm-svn: 53993
2008-07-24 18:47:16 +00:00
Ted Kremenek 1f352db96a Moved registration of basic path-sensitive checks from GRSimpleVals.cpp to GRExprEngineInternalChecks.cpp.
llvm-svn: 53909
2008-07-22 16:21:24 +00:00
Ted Kremenek f41b1c45fa "currentHandler" is a nullary selector
llvm-svn: 53763
2008-07-18 18:14:26 +00:00
Ted Kremenek f7faa42c6c Fix caching bug.
llvm-svn: 53759
2008-07-18 17:39:56 +00:00
Ted Kremenek 3b2294c7e6 Add panic support for NSAssertionHandler.
llvm-svn: 53758
2008-07-18 17:24:20 +00:00
Ted Kremenek e330aacbed Update signature of EvalAssume.
llvm-svn: 53745
2008-07-17 23:33:10 +00:00
Ted Kremenek 176e2c519d isRetain() and isRelease() now only returns true if "Retain"/"Release" appears in the suffix of a function's name.
llvm-svn: 53621
2008-07-15 17:43:41 +00:00
Ted Kremenek fa89e2f09c Support retain/release tracking for CoreGraphics (CGxxxRef) objects.
llvm-svn: 53617
2008-07-15 16:50:12 +00:00
Ted Kremenek a7b8ffb05b Refactored most of the "Store" piece of ValueState into a Store type. The
current store implementation is now encapsulated by BasicStore.

These changes prompted some long due constification of ValueState. Much of the
diffs in this patch include adding "const" qualifiers.

llvm-svn: 53423
2008-07-10 22:03:41 +00:00
Ted Kremenek ae529271e8 Fix PR2519: correctly handle CFDictionaryCreate.
llvm-svn: 53334
2008-07-09 18:11:16 +00:00
Ted Kremenek 4963d1144f Updated clients of ImmutableMap::SlimFind to use ImmutableMap::lookup instead.
llvm-svn: 53172
2008-07-07 16:21:19 +00:00
Ted Kremenek 4d85146e6d Use conjured symbols for variables whose values are invalidated when
passed-by-reference to a function. This allows us to build up constraints for
their new values and restore some lost path-sensitivity. This addresses a few
false positives since in Adium.

llvm-svn: 53125
2008-07-03 23:26:32 +00:00
Ted Kremenek b1d0118a1a Refactored some of the BugReporter interface so that data such as the ASTContext&, PathDiagnosticClient*, can be provided by an external source.
Split BugReporter into BugReporter and GRBugReporter so checkers not based on GRExprEngine can still use the BugReporter mechanism.

llvm-svn: 53048
2008-07-02 21:24:01 +00:00
Ted Kremenek ab54e51b38 Unlike NSWindow objects, NSPanel objects initially do not have self-ownership.
llvm-svn: 52963
2008-07-01 17:21:27 +00:00
Ted Kremenek bc6d850088 Temporarily treat "Autorelease" as "StopTracking". This is the original behavior.
llvm-svn: 52940
2008-07-01 00:01:02 +00:00
Ted Kremenek a0e071c861 Added "Autorelease" ArgEffect to better simulate "autorelease" messages. Right
now this does the same thing as "MayEscape", but more functionality will go in
here shortly.

llvm-svn: 52904
2008-06-30 16:57:41 +00:00
Ted Kremenek 3185c9c9cd CF ref checker:
Tracked objects now have their type information tracked with them.

Enhanced summaries for ObjC methods to include the type information of the receiver.

Used the enhanced summaries to support the idiom that NSWindow owns itself (it sends a release message to itself upon close).

Added some comments.

Did some cleanups with the checker logic using operator overloading (reduced redundant code which I was concerned about being the source of bugs).

llvm-svn: 52741
2008-06-25 21:21:56 +00:00
Ted Kremenek f890bfe0ff Remove unneeded method arguments.
llvm-svn: 52668
2008-06-24 03:56:45 +00:00
Ted Kremenek b1d1329ac7 Cache ObjC summaries by IdentifierInfo*, not by ObjCInterfaceDecl.
llvm-svn: 52667
2008-06-24 03:49:48 +00:00
Ted Kremenek 0cfc16100b Added ObjCSummaryCache, a new summary cache object to cache summaries for Objective-C methods. Instead of mapping from Selectors -> Summaries, we will now map from (ObjCInterfaceDecl*,Selectors) -> Summaries. This will allow more nuanced summary generation. This patch just swaps in the new data structure; the rest of the code works as before by allowing the ObjCInterfaceDecl* to be null.
llvm-svn: 52653
2008-06-23 23:30:29 +00:00
Ted Kremenek ea736c5d02 Rename summary methods for "instance methods" to "class methods" (the names got screwed up). No functionality change.
llvm-svn: 52650
2008-06-23 22:21:20 +00:00
Ted Kremenek ab4a8b5213 The CF retain/release checker now assumes that allocations do not fail. Eventually we will add a flag to the driver to enable allocation failures (documented as a FIXME).
llvm-svn: 52632
2008-06-23 18:02:52 +00:00
Ted Kremenek 08e171183f This patch is motivated by numerous strict-aliasing warnings when compiling
clang as a Release build.

The big change is that all AST nodes (subclasses of Stmt) whose children are
Expr* store their children as Stmt* or arrays of Stmt*. This is to remove
strict-aliasing warnings when using StmtIterator. None of the interfaces of any
of the classes have changed (except those with arg_iterators, see below), as the
accessor methods introduce the needed casts (via cast<>). While this extra
casting may seem cumbersome, it actually adds some important sanity checks
throughout the codebase, as clients using StmtIterator can potentially overwrite
children that are expected to be Expr* with Stmt* (that aren't Expr*). The casts
provide extra sanity checks that are operational in debug builds to catch
invariant violations such as these.

For classes that have arg_iterators (e.g., CallExpr), the definition of
arg_iterator has been replaced. Instead of it being Expr**, it is an actual
class (called ExprIterator) that wraps a Stmt**, and provides the necessary
operators for iteration. The nice thing about this class is that it also uses
cast<> to type-checking, which introduces extra sanity checks throughout the
codebase that are useful for debugging.

A few of the CodeGen functions that use arg_iterator (especially from
OverloadExpr) have been modified to take begin and end iterators instead of a
base Expr** and the number of arguments. This matches more with the abstraction
of iteration. This still needs to be cleaned up a little bit, as clients expect
that ExprIterator is a RandomAccessIterator (which we may or may not wish to
allow for efficiency of representation).

This is a fairly large patch. It passes the tests (except CodeGen/bitfield.c,
which was already broken) on both a Debug and Release build, but it should
obviously be reviewed.

llvm-svn: 52378
2008-06-17 02:43:46 +00:00
Ted Kremenek 0b6b0e7157 Teach the CF retain checker about "_init" methods. Fixes: <rdar://problem/5956379>
llvm-svn: 51872
2008-06-02 17:14:13 +00:00
Ted Kremenek b91ef1b62b Prototyped support in the BugReporter to emit diagnostics of the form "p now aliases q".
llvm-svn: 51453
2008-05-22 23:45:19 +00:00
Ted Kremenek 1df2f3a1f5 Expand retain/release checker to consider methods/function calls that cause a
tracked object to "escape": it's reference count might be incremented by the
called function, thus causing an object's lifetime to extend beyond when the
local reference count is decremented to 0.

This addresses: <rdar://problem/5933215>

llvm-svn: 51433
2008-05-22 17:31:13 +00:00
Ted Kremenek c812b23ce8 Cache leaks by the allocation site, not the leak location.
llvm-svn: 51198
2008-05-16 18:33:44 +00:00
Ted Kremenek acdde6f099 Rename IsPointerType to LVal::IsLValType, and update CFRefCount::EvalSummary to use IsLValType when conjuring symbols for return values (this fixes a bug with an assertion firing in the analyzer when two qualified objective-c types were compared).
llvm-svn: 50924
2008-05-09 23:45:33 +00:00
Ted Kremenek bcdb46830b Added support for "drain".
llvm-svn: 50831
2008-05-07 21:17:39 +00:00
Ted Kremenek f958ec50c0 Expand the CF retain checker to allow the Create/Get rule to apply to any
function that returns a CFxxxRef, not just functions whose name begins with
CF.  This implements <rdar://problem/5917879>.

Added test case for this feature.

Updated calls to CStrInCStrNoCase to swap their arguments, per compatibility
with strcasestr.

llvm-svn: 50829
2008-05-07 20:06:41 +00:00
Ted Kremenek fcf060fd2f Flip order of arguments to CStrInStrNoCase.
llvm-svn: 50824
2008-05-07 18:57:30 +00:00
Ted Kremenek b6cbf28d82 Use llvm::CStrInCStrNoCase instead of strcasestr, since the latter is not portable.
Correctly check if the result of CStrInCStrNoCase is NULL to generate summaries; before we were inverting the condition.

llvm-svn: 50822
2008-05-07 18:36:45 +00:00
Ted Kremenek 89bd0fc27d copy-paste: NS types are not typedefs.
llvm-svn: 50817
2008-05-07 17:35:41 +00:00
Ted Kremenek 7bf9dc773c Do not treat **instance** methods "copyWithZone:" and "mutableCopyWithZone:" from NSObject as allocators.
llvm-svn: 50802
2008-05-07 05:34:45 +00:00
Ted Kremenek 9930bd8c4f Be less promiscuous with generating summaries for "new", "copy", "create".
llvm-svn: 50798
2008-05-07 04:25:59 +00:00
Ted Kremenek 08eb30f193 Added auto-summary generation for createXXX, copyXXX, newXXX methods.
llvm-svn: 50795
2008-05-07 03:45:05 +00:00
Ted Kremenek aec1811c6c Don't report leaks for autoreleased objects.
llvm-svn: 50777
2008-05-06 23:07:13 +00:00
Ted Kremenek 767d0742c7 More comments.
"#if 0" out some assumptions when auto-generating method summaries.

llvm-svn: 50772
2008-05-06 21:26:51 +00:00
Ted Kremenek 10427bdbb9 Experiment with not converting bug names to lower case.
llvm-svn: 50753
2008-05-06 18:11:36 +00:00
Ted Kremenek cb2e636606 Generate "stop" summaries for selectors involving receivers whose type is not NSxxxx.
llvm-svn: 50721
2008-05-06 15:44:25 +00:00
Ted Kremenek 68f463b88e Use strncmp correctly.
llvm-svn: 50715
2008-05-06 06:17:42 +00:00
Ted Kremenek 5f478e9a0a Make string comparison legible and remove buffer overrun introduced by typo.
llvm-svn: 50714
2008-05-06 06:09:09 +00:00
Ted Kremenek 2f08fedec1 String comparison cleanups.
Added test case.

llvm-svn: 50711
2008-05-06 04:28:05 +00:00
Ted Kremenek 041d02201f Fix logic error in string processing.
llvm-svn: 50710
2008-05-06 04:21:38 +00:00
Ted Kremenek c9f4948bba Remove assertion.
llvm-svn: 50709
2008-05-06 04:21:10 +00:00
Ted Kremenek 015c3561ad Use EvalSummary to process message expressions, thereby unifying the checker
logic for function calls and message expressions.

Use the following heuristic to infer "allocating" instance methods:

  [ClassName classWithXXX]  allocates an object
  
Update testcase to reflect this heuristic.

llvm-svn: 50708
2008-05-06 04:20:12 +00:00
Ted Kremenek 821537ecdb Added receiver effects to EvalSummary.
llvm-svn: 50700
2008-05-06 02:41:27 +00:00
Ted Kremenek b0862dca6c Expand summaries to include "Receiver" effects.
llvm-svn: 50697
2008-05-06 02:26:56 +00:00
Ted Kremenek be7c56ed78 Added initialization code to generate initial set of ObjC method summaries (non-instance methods).
llvm-svn: 50690
2008-05-06 00:38:54 +00:00
Ted Kremenek 0806f910d4 Added code to generate initial set of summaries for instance methods.
llvm-svn: 50689
2008-05-06 00:30:21 +00:00
Ted Kremenek 3d1e972275 Add summary generation for "initXXX" methods.
llvm-svn: 50684
2008-05-05 23:55:01 +00:00
Ted Kremenek 046845e842 Make CF retain diagnostics more succinct.
In a leak's "name", indicate GC or non-GC bugs.

llvm-svn: 50680
2008-05-05 23:16:31 +00:00
Ted Kremenek 00daccdd2a Initial work on refactoring the CFRefCount checker so that it is more
generic and handles reference counts for NSObjects.

llvm-svn: 50674
2008-05-05 22:11:16 +00:00
Ted Kremenek 627c3074dd Improve leak diagnostics to not report a leak on the same line where
the object was last used.  This can be confusing to users.

For example:

 // 'y' is leaked
x = foo(y);

instead:

x = foo(y);
  // 'y' is leaked

llvm-svn: 50661
2008-05-05 18:50:19 +00:00
Ted Kremenek 3917b82e85 Improved leak diagnostics.
llvm-svn: 50657
2008-05-05 17:53:17 +00:00
Ted Kremenek 875db81301 Minor refactorings/cleanups in CF retain checker and added support for NSMakeCollectable.
Added test case for NSMakeCollectable.

llvm-svn: 50653
2008-05-05 16:51:50 +00:00
Ted Kremenek 983be7cee6 Improved diagnostics for leaks: now we report which variable was leaked.
llvm-svn: 50588
2008-05-02 20:53:50 +00:00
Ted Kremenek 789942cfda When running the reference count checker twice (GC and non-GC mode), only emit
basic warnings (dead stores, null dereferences) on the first pass.

llvm-svn: 50584
2008-05-02 18:01:49 +00:00
Ted Kremenek 63d76df236 Fix copy-paste bug.
llvm-svn: 50557
2008-05-01 23:38:35 +00:00
Ted Kremenek 2722f36465 Remove no longer valid assertion.
llvm-svn: 50556
2008-05-01 23:28:56 +00:00
Ted Kremenek 1097b4c61f Added line number diagnostics to indicate the allocation site of the leaked object.
llvm-svn: 50553
2008-05-01 23:13:35 +00:00
Ted Kremenek fabfb4677d Do not highlight bogus ranges for leaks.
llvm-svn: 50549
2008-05-01 22:50:36 +00:00
Ted Kremenek 8a56b06b5c Correctly invalidate reference count state when passing objects by reference in message expressions we don't understand.
llvm-svn: 50541
2008-05-01 21:31:50 +00:00
Ted Kremenek f0b0f2edfe Renamed static method.
llvm-svn: 50533
2008-05-01 18:31:44 +00:00
Ted Kremenek 9f696852c4 When processing "release", "retain", and "autorelease" messages return the
lval passed as an argument.

Fix: Inverted diagnostic messages.
llvm-svn: 50513
2008-05-01 04:02:04 +00:00
Ted Kremenek 4828aa3152 Added support for "autorelease" message in CF ref. count checker.
llvm-svn: 50512
2008-05-01 02:18:37 +00:00
Ted Kremenek b0f87c48cb added preliminary diagnostics in scan-build results to denote whether
a CF memory leak occurred with GC enabled, etc.

llvm-svn: 50507
2008-04-30 23:47:44 +00:00
Ted Kremenek 20d8006e93 Teach more of the static analyzer about ObjCQualifiedIdType.
llvm-svn: 50494
2008-04-30 20:17:27 +00:00
Ted Kremenek 0940b99e3b Teach the static analysis engine about ObjCQualifiedIdType.
llvm-svn: 50493
2008-04-30 20:01:29 +00:00
Ted Kremenek a374ea9a35 Update typestate logic to support GC-mode.
llvm-svn: 50396
2008-04-29 05:44:10 +00:00
Ted Kremenek 4b7ca776cf Implement semantics of CFMakeCollectable for the CF-reference count checker.
llvm-svn: 50395
2008-04-29 05:33:51 +00:00
Ted Kremenek 4d1f422c6f Provide the option to run the CF-retain checker in GC enabled mode.
The transfer functions for the checker don't do anything special yet in GC mode.

llvm-svn: 50394
2008-04-29 05:13:59 +00:00
Ted Kremenek ecbdf75049 Do a better job at computing dead symbols.
Implemented support for better localized leaks in the CF reference count checker.
Now leaks should be flagged close to where they occur.

This should implement the desired functionality in <rdar://problem/5879592>, although the diagnostics still need to be improved.

llvm-svn: 50241
2008-04-25 01:25:15 +00:00
Ted Kremenek b0daf2f6f5 Add preliminary support for flagging leaks around when they happen (doesn't work yet).
llvm-svn: 50237
2008-04-24 23:57:27 +00:00
Ted Kremenek f7141597e8 CF reference count checker: handle variadic functions that allocate CF objects.
This fixes <rdar://problem/5886141>.

Part of this change resulted in creating sparser summaries.  I also added
some more comments and did some minor code cleanups.

llvm-svn: 50214
2008-04-24 17:22:33 +00:00
Ted Kremenek dd43aeee54 Fixed: <rdar://problem/5881148>
Problem:

In the recently refactored VisitDeref (which processes dereferences), we
were incorrectly skipping the node just generated for the subexpression
of the dereference.  This was a horrible regression.

llvm-svn: 50176
2008-04-23 20:12:28 +00:00
Ted Kremenek c79c0591d6 Added lval type (and tracking) for StringLiterals.
llvm-svn: 50109
2008-04-22 21:39:21 +00:00
Ted Kremenek 31484b2477 Generalize caching mechanism for bugs reports. Now individual BugTypes
can decide the policy on how to cache related bugs.  This allows us to
properly to handle warning about multiple leaks in the same location in the
ref count checker (not yet done).

llvm-svn: 49918
2008-04-18 20:54:29 +00:00
Ted Kremenek 4d83728a57 Added "GetErrorNodes()" to BugType so that -trim-egraph can recognize errors
from registered BugTypes.  This helps with debugging.

Add detection of NULL values in ref count checker; this suppresses false positives.

llvm-svn: 49912
2008-04-18 19:23:43 +00:00
Ted Kremenek d004c418b6 Fixed bug in GREndPathNodeBuilder: only return a node if it wasn't in the node cache.
llvm-svn: 49907
2008-04-18 16:30:14 +00:00
Ted Kremenek f03e07c34d More grammar fixes.
llvm-svn: 49895
2008-04-18 05:32:44 +00:00
Ted Kremenek ca8892b456 Fix plurality debacle.
llvm-svn: 49894
2008-04-18 05:13:26 +00:00