Commit Graph

177 Commits

Author SHA1 Message Date
Ted Kremenek 0ca23d3f73 Add 'AppendValue' to the list of magic CF function names that cause a tracked object to escape. Fixes <rdar://problem/6560661>.
llvm-svn: 63891
2009-02-05 22:34:53 +00:00
Ted Kremenek 400aae7fa4 Remove a bunch of obscene double-buffering of BugReports in the retain/release
checker. This was previously needed because BugReport objects were previously
allocated on the stack and not owned by BugReporter. Now we can just issue them
on the fly. This change was motivated because we were seeing some weird cases
where some really long paths would get issued for bugs (particularly leaks)
because of some double-caching.

llvm-svn: 63840
2009-02-05 06:50:21 +00:00
Ted Kremenek fb379b2660 Fix regression: Leak (BugType) object should have 'isLeak()' return true.
llvm-svn: 63803
2009-02-05 00:38:00 +00:00
Ted Kremenek fc5d067ea0 Overhaul BugReporter interface and implementation. The new interface cleans up
the ownership of BugTypes and BugReports. Now BugReports are owned by BugTypes,
and BugTypes are owned by the BugReporter object.

The major functionality change in this patch is that reports are not immediately
emitted by a call to BugReporter::EmitWarning (now called EmitReport), but
instead of queued up in report "equivalence classes". When
BugReporter::FlushReports() is called, it emits one diagnostic per report
equivalence class. This provides a nice cleanup with the caching of reports as
well as enables the BugReporter engine to select the "best" path for reporting a
path-sensitive bug based on all the locations in the ExplodedGraph that the same
bug could occur.

Along with this patch, Leaks are now coalesced into a common equivalence class
by their allocation site, and the "summary" diagnostic for leaks now reports the
allocation site as the location of the bug (this may later be augmented to also
provide an example location where the leak occurs).

llvm-svn: 63796
2009-02-04 23:49:09 +00:00
Ted Kremenek ed90de4caa retain/release checker: When generating summaries for CF/CG functions, allow arguments to "escape" if they are passed to a function containing the terms "InsertValue", "SetValue", or "AddValue". This fixes <rdar://problem/6539791>.
llvm-svn: 63341
2009-01-29 22:45:13 +00:00
Ted Kremenek b4dd3f8685 Remove '#if 0' code.
llvm-svn: 63250
2009-01-28 22:35:55 +00:00
Ted Kremenek 2e561dd491 Remove method 'AddNE' from the public interface of ConstraintManager.
llvm-svn: 63249
2009-01-28 22:27:59 +00:00
Ted Kremenek c783209605 retain/release checker: Always generate an "autorelease" summary for an "autorelease" message, and have the summary processing logic treat it as a no-op in GC mode. This change is motivated to encode more of the semantics in the summaries themselves for eventual better diagnostics.
llvm-svn: 63241
2009-01-28 21:44:40 +00:00
Ted Kremenek 4daeccf28f retain/release checker: Improve diagnostics to indicate that CF objects are not automatically garbage collected.
llvm-svn: 63187
2009-01-28 06:25:48 +00:00
Ted Kremenek f0ec316a04 retain/release checker: Indicate whether a tracked object is a Core Foundation or Objective-C object.
llvm-svn: 63186
2009-01-28 06:06:36 +00:00
Ted Kremenek bdaa384453 retain/release checker: More diagnostic refactoring.
llvm-svn: 63184
2009-01-28 06:01:42 +00:00
Ted Kremenek aeb115f93a retain/release checker: Embed an "object type" into the RetEffect/RetVal objects to help distinguish between Objective-C and Core Foundation objects (for better diagnostics).
llvm-svn: 63183
2009-01-28 05:56:51 +00:00
Ted Kremenek 21114f21c4 retain/release checker: More cleanups (no real functionality change).
llvm-svn: 63181
2009-01-28 05:29:13 +00:00
Ted Kremenek ff3c2bdfee Fix diagnostic truncated by my last patch.
llvm-svn: 63180
2009-01-28 05:18:08 +00:00
Ted Kremenek 758fda632b retain/release checker: More diagnostic refactoring.
llvm-svn: 63179
2009-01-28 05:15:02 +00:00
Ted Kremenek c4118ac79c retain/release checker: Output the name of the function that allocates an object.
llvm-svn: 63178
2009-01-28 05:06:46 +00:00
Ted Kremenek 424c61ff6d Refactor some diagnostic code to use raw_string_ostream. No functionality change.
llvm-svn: 63177
2009-01-28 04:47:13 +00:00
Ted Kremenek 99ae4120d6 Remove '#if 0' code.
llvm-svn: 63176
2009-01-28 04:37:52 +00:00
Ted Kremenek f08ac278ed More hacking on static analyzer diagnostics. When emitting summary diagnostics the code paths for diagnostics involving paths or single locations are now unified. This patch also constifies many arguments/methods that are touched by this logic, leading to a nice overall code cleanup.
llvm-svn: 62903
2009-01-24 00:55:43 +00:00
Ted Kremenek 16fbfe699e Static Analyzer: Replace LiveSymbols/DeadSymbols sets with a new object called "SymbolReaper". Right now it just consolidates the two and cleans up some client code, but shortly it will be used to enable "lazy computation" of live symbols for use with RegionStore.
llvm-svn: 62722
2009-01-21 22:26:05 +00:00
Ted Kremenek 86afde337d Fix PR 3337 [retain/release checker]: Handle FunctionDecl's declared using typedefs.
llvm-svn: 62331
2009-01-16 18:40:33 +00:00
Chris Lattner 8a42586c54 more SourceLocation lexicon change: instead of referring to the
"logical" location, refer to the "instantiation" location.

llvm-svn: 62316
2009-01-16 07:36:28 +00:00
Ted Kremenek 7e90422e95 retain/release checker:
- Refactor a bunch of logic in the retain/release checker, making it more
  condense and easier to read.
- Add support for "Create" methods in the DiskArbitration framework

retain/release tests:
- Rename CFDate.m to retain-release.m, and move test from CFString.c to
  retain-release.m
- Add DiskArbitration framework tests cases.
- Add/refine and few more retain/release GC test cases.

llvm-svn: 62106
2009-01-12 21:45:02 +00:00
Ted Kremenek 1d92d2c813 This commit reflects changes to the retain/release checker motivated by my
recent discussions with Thomas Clement and Ken Ferry concerning the "fundamental
rule" for Cocoa memory management
(http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html).

Here is the revised behavior of the checker concerning tracking retain/release
counts for objects returned from message expressions involving instance methods:

1) Track the returned object if the return type of the message expression is
id<..>, id, or a pointer to *any* object that subclasses NSObject. Such objects
are assumed to have a retain count. Previously the checker only tracked objects
when the receiver of the message expression was part of the standard Cocoa API
(i.e., had class names prefixed with 'NS'). This should significantly expand the
amount of checking performed.

2) Consider the object owned if the selector of the message expression contains
"alloc", "new", or "copy". Previously we also considered "create", but this
doesn't follow from the fundamental rule (discussions with the Cocoa folks
confirms this).

llvm-svn: 61837
2009-01-07 00:39:56 +00:00
Ted Kremenek 5b26c11f56 Fix regression when invalidating reference-counts for objects passed-by-reference to a function/method.
llvm-svn: 61224
2008-12-18 23:34:57 +00:00
Ted Kremenek 300c9cc8c6 Fix <rdar://problem/6451816>:
- Because of the introduction of AnonTypedRegions when reasoning about casts, we
  had a regression in the "symbolication" of variable values passed-by-reference
  to a function. This is now fixed in CFRefCount.cpp (-checker-cfref) by
  blasting through the layer of AnonTypedRegions when symbolicating the value of
  the variable. This logic may get moved elsewhere. Note that this change
  affects only -checker-cfref and not -checker-simple; eventually this logic
  should get pulled out of CFRefCount.cpp into a more common place. All users
  use -checker-cfref by default, and -checker-simple should probably just be
  removed.  
- Updated test 'Analysis/uninit-vals-ps.c' to only use -checker-cfref and added
  a test case for this regression.

llvm-svn: 61147
2008-12-17 19:42:34 +00:00
Ted Kremenek b5670fd555 MemRegion:
- Overhauled the notion of "types" for TypedRegions.  We now distinguish between the "lvalue" of a region (via getLValueRegion()) and the "rvalue" of a region (va getRValueRegion()).  Since a region represents a chunk of memory it has both, but we were conflating these concepts in some cases, leading to some insidious bugs.
- Removed AnonPointeeType, partially because it is unused and because it doesn't have a clear notion of lvalue vs rvalue type.  We can add it back once there is a need for it and we can resolve its role with these concepts.

StoreManager:
- Overhauled StoreManager::CastRegion.  It expects an *lvalue* type for a region.  This is actually what motivated the overhaul to the MemRegion type mechanism.  It also no longer returns an SVal; we can just return a MemRegion*.
- BasicStoreManager::CastRegion now overlays an "AnonTypedRegion" for pointer-pointer casts.  This matches with the MemRegion changes.
- Similar changes to RegionStore, except I've added a bunch of FIXMEs where it wasn't 100% clear where we should use TypedRegion::getRValueRegion() or TypedRegion::getLValueRegion().

AuditCFNumberCreate check:
- Now blasts through AnonTypedRegions that may layer the original memory region, thus checking if the actually memory block is of the appropriate type.  This change was needed to work with the changes to StoreManager::CastRegion.

GRExprEngine::VisitCast:
- Conform to the new interface of StoreManager::CastRegion.

Tests:
- None of the analysis tests fail now for using the "basic store".
- Disabled the tests 'array-struct.c' and 'rdar-6442306-1.m' pending further testing and bug fixing.

llvm-svn: 60995
2008-12-13 21:49:13 +00:00
Ted Kremenek d8242f19f7 Rename SymbolID to SymbolRef. This is a precursor to some overhauling of the representation of symbolic values.
llvm-svn: 60575
2008-12-05 02:27:51 +00:00
Ted Kremenek 817737a002 Add FIXME.
llvm-svn: 60390
2008-12-02 01:26:07 +00:00
Chris Lattner e4b95698df Rename Selector::getName() to Selector::getAsString(), and add
a new NamedDecl::getAsString() method.

Change uses of Selector::getName() to just pass in a Selector 
where possible (e.g. to diagnostics) instead of going through
an std::string.

This also adds new formatters for objcinstance and objcclass
as described in the dox.

llvm-svn: 59933
2008-11-24 03:33:13 +00:00
Ted Kremenek 16866d6fd8 GRExprEngine/CFRefCount/GRSimpleVals: We don't do any special handling (yet) of vector types. Add explicit checks that when we process integers that they really are scalars.
llvm-svn: 59225
2008-11-13 06:10:40 +00:00
Ted Kremenek 60d46414f4 Update method names involving GRStateRef. No functionality change.
llvm-svn: 59153
2008-11-12 19:22:09 +00:00
Ted Kremenek ab4782510b Fix regression with handling of CFMakeCollectable.
llvm-svn: 58771
2008-11-05 22:17:20 +00:00
Ted Kremenek 2855a93f07 initXXX methods can return owned objects
llvm-svn: 58758
2008-11-05 16:54:44 +00:00
Ted Kremenek 24b1d9f57e Handle prefix '_' that may appear in front of the name of 'Release' functions
llvm-svn: 58666
2008-11-04 00:36:12 +00:00
Sanjiv Gupta d79592448b Made the mechanism of defining preprocessor defs for maxint, ptrdiff_t, wchar
etc more generic. For some targets, long may not be equal to pointer size. For
example: PIC16 has int as i16, ptr as i16 but long as i32.

Also fixed a few build warnings in assert() functions in CFRefCount.cpp,
CGDecl.cpp, SemaDeclCXX.cpp and ParseDeclCXX.cpp.

llvm-svn: 58501
2008-10-31 09:52:39 +00:00
Ted Kremenek 4c276c736c Extend "followsFundamentalRule" to ignore prefix '_' characters.
llvm-svn: 58469
2008-10-30 23:14:58 +00:00
Ted Kremenek 3700b762ff IOServiceGetMatchingServices is a release function.
llvm-svn: 58362
2008-10-29 04:07:07 +00:00
Ted Kremenek 920406b5ca Use "followsFundamentalRule" to determine if an instance method allocates memory.
llvm-svn: 58114
2008-10-24 21:22:44 +00:00
Ted Kremenek 01acb6284e followsFundamentalRule() returns true if "alloc" or "new" appear at the beginning of the string, not anywhere within it.
llvm-svn: 58112
2008-10-24 21:18:08 +00:00
Ted Kremenek 03466c2273 Issue warnings about owned objects returned from a method that does not match the established Cocoa naming conventions.
llvm-svn: 58108
2008-10-24 20:32:50 +00:00
Ted Kremenek cc3d18877a Disable warning about potential leaks of returned values until we test it a little more (lots of noise).
llvm-svn: 58021
2008-10-23 01:56:15 +00:00
Ted Kremenek 631ff239fc Warn about potentially leaked objects that are returned from methods whose names do not follow the Cocoa Memory Management guidelines.
llvm-svn: 58012
2008-10-22 23:56:21 +00:00
Ted Kremenek 9a96bf22ec Enhance reference-count checker to correctly identify CG "release" functions. This fixes <rdar://problem/6303488>.
llvm-svn: 57997
2008-10-22 20:54:52 +00:00
Ted Kremenek 0747e7e025 Handle [NSAutoreleasePool addObject:] (an alternative way to add objects to the current autorelease pool).
Added initial code for tracking stack of autorelease pools.

llvm-svn: 57908
2008-10-21 15:53:15 +00:00
Ted Kremenek e86755e14f retain/release checker: Check if a tracked value escapes if we also try binding it to the store and the store doesn't support that binding (i.e., it cannot track it). This has the nice feature that the checker will automatically get more powerful if we use a more powerful store model.
llvm-svn: 57755
2008-10-18 03:49:51 +00:00
Ted Kremenek 213873232d When conjuring symbols to recover path-sensitivity, don't conjure symbols that represent an entire struct. We need to implement struct temporaries as an actual "region", and then bind symbols to the FieldRegion of those temporaries.
llvm-svn: 57739
2008-10-17 22:23:12 +00:00
Ted Kremenek 8b103c65c6 - constify some uses of MemRegion* (MemRegion should be immutable).
- Added new region "SymbolicRegion", which maps symbol values to the region domain.
- Enhanced BasicStore::getFieldLValue() to return a FieldRegion (using SymbolicRegion)
- Added some utility methods to GRState for fetch svals from the store.
- Fixed regression in CheckNSError (we weren't getting the value bound to the parameter)

llvm-svn: 57717
2008-10-17 20:28:54 +00:00
Zhongxing Xu 27f174214d This patch did the following renaming. There should be no functional changes.
RVal => SVal
LVal => Loc
NonLVal => NonLoc
lval => loc
nonlval => nonloc

llvm-svn: 57671
2008-10-17 05:57:07 +00:00
Ted Kremenek 5ca90a244f This is a big patch, but the functionality change is small and the rest of the patch consists of deltas due to API changes.
This patch overhauls the "memory region" abstraction that was prototyped (but never really used) as part of the Store.h.  This patch adds MemRegion.h and MemRegion.cpp, which defines the class MemRegion and its subclasses.  This classes serve to define an abstract representation of memory, with regions being layered on other regions to to capture the relationships between fields and variables, variables and the address space they are allocated in, and so on.  

The main motivation of this patch is that key parts of the analyzer assumed that all value bindings were to VarDecls.  In the future this won't be the case, and this patch removes lval::DeclVal and replaces it with lval::MemRegionVal.  Now all pieces of the analyzer must reason about abstract memory blocks instead of just variables.

There should be no functionality change from this patch, but it opens the door for significant improvements to the analyzer such as field-sensitivity and object-sensitivity, both which were on hold until the memory abstraction got generalized.

The memory region abstraction also allows type-information to literally be affixed to a memory region.  This will allow the some now redundant logic to be removed from the retain/release checker.

llvm-svn: 57042
2008-10-04 05:50:14 +00:00