Commit Graph

65 Commits

Author SHA1 Message Date
Ted Kremenek 198a8c5f95 Use SymbolicRegion instead of CodeTextRegion for symbolic function
pointers.  Most logic cares first about whether or not a region is
symbolic, and second if represents code.  This should fix a series of
silent corner case bugs (as well as simplify a bunch of code).

llvm-svn: 80335
2009-08-28 04:49:15 +00:00
Benjamin Kramer 89b422c118 Replace cerr with errs().
llvm-svn: 79854
2009-08-23 12:08:50 +00:00
Ted Kremenek fa41714d8d Implement lazy "copying" of structures and arrays in RegionStore. While
RegionStore already lazily abstracted the contents of arrays and structs, when
doing an assignment from one array/struct to another we did an explicit
element-wise copy, which resulted in a loss of laziness and huge performance
problem when analyzing many code bases.

Now RegionStoreManager handles such assignments using a new SVal could
'LazyCompoundSVal', which basically means the value of a given struct or array
(a MemRegion*) in a specific state (GRState). When we do a load from a field
whose encompassing struct binds to a LazyCompoundSVal, we essentially do a field
lookup in the original structure. This means we have essentially zero copying of
data for structs/arrays and everything stays lazy.

llvm-svn: 78268
2009-08-06 01:20:57 +00:00
Ted Kremenek 4301526e8d Remove 'StoreManager::OldCastRegion()', TypedViewRegion (which only
OldCastRegion used), and the associated command line option
'-analyzer-store=old-basic-cast'.

llvm-svn: 77509
2009-07-29 21:43:22 +00:00
Ted Kremenek ccf3335939 Add 'MemRegion::getBaseRegion()', a utility method to strip ElementRegions with
index 0.  This will be used for refinements to InvalidateRegion and CastRegion.

llvm-svn: 77481
2009-07-29 18:14:27 +00:00
Ted Kremenek e2fb3ce385 Tweak pretty-printing of CompoundVal to make it more useful for debugging.
llvm-svn: 75672
2009-07-14 20:21:36 +00:00
Ted Kremenek a6904ff7f9 Tidy pretty-printing for SVals, using 'dump()' instead of 'printStdErr()', and implementing operator<< support for llvm::raw_ostream.
llvm-svn: 75560
2009-07-13 23:53:06 +00:00
Zhongxing Xu d0a246fd08 add utility method.
llvm-svn: 74521
2009-06-30 11:52:40 +00:00
Ted Kremenek 1642bdaaa5 Introduce a new concept to the static analyzer: SValuator.
GRTransferFuncs had the conflated role of both constructing SVals (symbolic
expressions) as well as handling checker-specific logic. Now SValuator has the
role of constructing SVals from expressions and GRTransferFuncs just handles
checker-specific logic. The motivation is by separating these two concepts we
will be able to much more easily create richer constraint-generating logic
without coupling it to the main checker transfer function logic.

We now have one implementation of SValuator: SimpleSValuator.

SimpleSValuator is essentially the SVal-related logic that was in GRSimpleVals
(which is removed in this patch). This includes the logic for EvalBinOp,
EvalCast, etc. Because SValuator has a narrower role than the old
GRTransferFuncs, the interfaces are much simpler, and so is the implementation
of SimpleSValuator compared to GRSimpleVals. I also did a line-by-line review of
SVal-related logic in GRSimpleVals and cleaned it up while moving it over to
SimpleSValuator.

As a consequence of removing GRSimpleVals, there is no longer a
'-checker-simple' option. The '-checker-cfref' did everything that option did
but also ran the retain/release checker. Of course a user may not always wish to
run the retain/release checker, nor do we wish core analysis logic buried in the
checker-specific logic. The next step is to refactor the logic in CFRefCount.cpp
to separate out these pieces into the core analysis engine.

llvm-svn: 74229
2009-06-26 00:05:51 +00:00
Ted Kremenek 799bb6e178 Remove uses of std::ostream from libAnalysis.
llvm-svn: 74136
2009-06-24 23:06:47 +00:00
Zhongxing Xu 7718ae4701 Move all factory methods from SVal to ValueManager. API cleanup!
llvm-svn: 73954
2009-06-23 09:02:15 +00:00
Zhongxing Xu 0808f70912 Split ValueManager method definitions into its own source file.
No functionality change.

llvm-svn: 73952
2009-06-23 06:22:22 +00:00
Zhongxing Xu d09b5205ef ValueManager::makeNonLoc -> ValueManager::makeIntVal
Clean up code with ValueManager.

llvm-svn: 73951
2009-06-23 06:13:19 +00:00
Zhongxing Xu b7cf95957d Instead of setting the default value of the array region, bind the rest of the
array elements to 0 explicitly. Create 0 values with the element type.

llvm-svn: 73946
2009-06-23 05:23:38 +00:00
Zhongxing Xu 54fb536b5c A further step of r73690: associate the cast-to type with the created symbol,
because the type of the symbol is used to create the default range. We need the
sign to be consistent.

llvm-svn: 73756
2009-06-19 06:00:32 +00:00
Ted Kremenek 095f1a9848 Move clients over from using GRStateManager::BindXXX and friends to
GRState->bindXXX and friends (and constify some arguments along the way).

llvm-svn: 73740
2009-06-18 23:58:37 +00:00
Zhongxing Xu cea6578078 When casting region, if we do not create an element region, record the cast-to
type. 

When retrieving the region value, if we are going to create a symbol value, use
the cast-to type if possible.

llvm-svn: 73690
2009-06-18 06:29:10 +00:00
Zhongxing Xu 08a2ede018 Add logic for invalidating array region to CFRefCount.cpp. When invalidating
array region, set its default value to conjured symbol. When retrieving its
element, create new region value symbol for the element.

Also fix some 80 columns violations.

llvm-svn: 71548
2009-05-12 10:10:00 +00:00
Zhongxing Xu 91e2ab496f Rename:
SymbolRegionRValue => SymbolRegionValue
  SymExpr::RegionRValue => SymExpr::RegionValueKind

llvm-svn: 71322
2009-05-09 04:08:27 +00:00
Zhongxing Xu 34d04b3ca9 As discussed with Ted, rename TypedRegion::getObjectType() to
TypedRegion::getValueType().

llvm-svn: 71321
2009-05-09 03:57:34 +00:00
Zhongxing Xu 8038f7b30f rename: MemRegion:
RValueType => ObjectType
 LValueType => LocationType

No functionality change.

llvm-svn: 71304
2009-05-09 00:50:33 +00:00
Ted Kremenek d795b02be7 Rename 'makeZeroIndex' to 'makeZeroArrayIndex'.
llvm-svn: 70865
2009-05-04 15:17:38 +00:00
Zhongxing Xu 6ebde279ae array indexes are unsigned integers of the same width as pointer.
no-outofbounds.c still fails. Previously it passed because the array index
is mistakenly a loc::ConcreteInt.

llvm-svn: 70844
2009-05-04 08:52:47 +00:00
Ted Kremenek 30fb341f4f Use 'getAs<CodeTextRegion>' instead of 'dyn_cast<CodeTextRegion>' to handle any
layered regions.

llvm-svn: 69686
2009-04-21 17:37:26 +00:00
Zhongxing Xu 3070210377 Remove loc::FuncVal.
llvm-svn: 69577
2009-04-20 06:35:22 +00:00
Zhongxing Xu ac1294318d get a CodeTextRegion when visiting FunctionDecl reference.
get FunctionDecl with more general utility method.

llvm-svn: 69570
2009-04-20 05:24:46 +00:00
Zhongxing Xu 23e1f45664 As we now have ValueManager as the new value factory, we do not need factory
methods of SVal.

llvm-svn: 69565
2009-04-20 02:27:09 +00:00
Ted Kremenek df24000d24 Implement analyzer support for OSCompareAndSwap. This required pushing "tagged"
ProgramPoints all the way through to GRCoreEngine.

NSString.m now fails with RegionStoreManager because of the void** cast.
Disabling use of region store for that test for now.

llvm-svn: 68845
2009-04-11 00:11:10 +00:00
Ted Kremenek ffe4ad6795 Move a few more NonLoc static functions to ValueManager.
llvm-svn: 68800
2009-04-10 18:11:44 +00:00
Zhongxing Xu 1aced0c9d2 Add prototype for CodeTextRegion.
A CodeTextRegion wraps two kinds of data: FunctionDecl* or SymbolRef. 
The latter comes from the symbolic function pointer that are generated from
function calls or input data.

llvm-svn: 68777
2009-04-10 08:45:10 +00:00
Zhongxing Xu dadf250598 Finally nuke loc::SymbolVal.
llvm-svn: 68771
2009-04-10 06:06:13 +00:00
Ted Kremenek f2489ea043 - Move ownership of MemRegionManager into ValueManager.
- Pull SVal::GetConjuredSymbol() and friends into ValueManager. This greatly
simplifies the calling interface to clients.

llvm-svn: 68731
2009-04-09 22:22:44 +00:00
Ted Kremenek f8cb51c20e Remove SVal::MakeZero and replace it with ValueManager::makeZeroVal.
llvm-svn: 68711
2009-04-09 16:46:55 +00:00
Zhongxing Xu 7e9c193398 stop using loc::SymbolVal and clean up code with new API.
llvm-svn: 68703
2009-04-09 07:39:46 +00:00
Zhongxing Xu 9410d7ee97 Add a new method because sometimes the type of the conjured symbol is not the
type of the expression where we create the symbol.

llvm-svn: 68692
2009-04-09 06:30:17 +00:00
Zhongxing Xu cb5d3ced70 Create a symbolic region instead of a loc::SymbolVal. This is a continued step
to eliminate the use of loc::SymbolVal.

llvm-svn: 68685
2009-04-09 05:57:11 +00:00
Ted Kremenek 5451c60f5a Enhance analyzer reasoning about sending messages to nil. A nil receiver returns 0 for scalars of size <= sizeof(void*).
llvm-svn: 68629
2009-04-08 18:51:08 +00:00
Zhongxing Xu ec7e7dfe0a This is the first step to gradually remove the use of loc::SymbolVal. Now
when creating symbolic values, we distinguish between location and non-location
values. For location values, we create a symbolic region instead of a
loc::SymbolVal.

llvm-svn: 68373
2009-04-03 07:33:13 +00:00
Ted Kremenek 3cd88e5d99 Remove dead code.
llvm-svn: 68063
2009-03-30 21:27:41 +00:00
Ted Kremenek 3e31c26f81 analyzer infrastructure: make a bunch of changes to symbolic expressions that
Zhongxing and I discussed by email.

Main changes:
- Removed SymIntConstraintVal and SymIntConstraint
- Added SymExpr as a parent class to SymbolData, SymSymExpr, SymIntExpr
- Added nonloc::SymExprVal to wrap SymExpr
- SymbolRef is now just a typedef of 'const SymbolData*'
- Bunch of minor code cleanups in how some methods were invoked (no functionality change)

This changes are part of a long-term plan to have full symbolic expression
trees. This will be useful for lazily evaluating complicated expressions.

llvm-svn: 67731
2009-03-26 03:35:11 +00:00
Zhongxing Xu 24e7eade19 This patch adds two more SymbolData subclasses: SymIntExpr and SymSymExpr, for
representing symbolic expressions like 'x'+3 and 'x'+'y'. The design is
subjected to change later when we fix the class hierarchy of symbolic
expressions.

llvm-svn: 67678
2009-03-25 05:58:37 +00:00
Ted Kremenek 6b31533ad1 GRExprEngine:
- Conjure symbols at '--' and '++' unary operations
- Add utility method SVal::GetConjuredSymbolVal() and constify some arguments
  along the way.

llvm-svn: 67395
2009-03-20 20:10:45 +00:00
Ted Kremenek b36e01d87e Fix crash reported in <rdar://problem/6695527>. We now have
SVal::GetRValueSymbolVal do the checking if we can symbolicate a type instead of
having BasicStoreManager do it (which wasn't always doing the check
consistently). Having this check in SVal::GetRValueSymbolVal keeps the check in
one centralized place.

llvm-svn: 67245
2009-03-18 22:10:22 +00:00
Daniel Dunbar 4095d89532 Remove some now-unneeded calls to llvm::errs().flush().
llvm-svn: 66555
2009-03-10 18:00:19 +00:00
Ted Kremenek c9747dd60f Rework use of loc::SymbolVal in the retain/release checker to use the new method
SVal::getAsLocSymbol(). This simplifies the code and allows the retain/release
checker to (I believe) also correctly reason about location symbols wrapped in
SymbolicRegions.

Along the way I cleaned up SymbolRef a little, disallowing implicit casts to
'unsigned'.

llvm-svn: 65972
2009-03-03 22:06:47 +00:00
Ted Kremenek e3852bd252 Fix case where we should use dyn_cast instead of cast.
llvm-svn: 65956
2009-03-03 19:01:37 +00:00
Ted Kremenek 7594e2a59a Fix a couple bugs:
- NonLoc::MakeVal() would use sizeof(unsigned) (literally) instead of consulting
  ASTContext for the size (in bits) of 'int'. While it worked, it was a
  conflation of concepts and using ASTContext.IntTy is 100% correct.
- RegionStore::getSizeInElements() no longer assumes that a VarRegion has the
  type "ConstantArray", and handles the case when uses use ordinary variables
  as if they were arrays.
- Fixed ElementRegion::getRValueType() to just return the rvalue type of its
  "array region" in the case the array didn't have ArrayType.
- All of this fixes <rdar://problem/6541136>

llvm-svn: 63347
2009-01-30 00:08:43 +00:00
Ted Kremenek 74040833e4 Static analyzer: Remove a bunch of outdated SymbolData objects and
their associated APIs.  We no longer need separate SymbolData objects
for fields, variables, etc.  Instead, we now associated symbols with
the "rvalue" of a MemRegion (i.e., the value stored at that region).
Now we only have two kinds of SymbolData objects: SymbolRegionRValue
and SymbolConjured.

This cleanup also makes the distinction between a SymbolicRegion and a
symbolic value that is a location much clearer.  A SymbolicRegion
represents a chunk of symbolic memory, while a symbolic location is
just a "pointer" with different possible values.  Without any specific
knowledge, a symbolic location resolves (i.e., via a dereference) to a
SymbolicRegion.  In the future, when we do better alias reasoning, a
symbolic location can become an alias for another location, thus
merging the constraints on the referred SymbolicRegion with the other
region.

llvm-svn: 62769
2009-01-22 18:23:34 +00:00
Zhongxing Xu af7415ffb1 Lazy bingding for region-store manager.
* Now Bind() methods take and return GRState* because binding could
  also alter GDM.
* No variables are initialized except those declared with initial
  values.
* failed C test cases are due to bugs in RemoveDeadBindings(),
which removes constraints that is still alive. This will be fixed in later
patch.
* default value of array and struct regions will be implemented in later patch.

llvm-svn: 61274
2008-12-20 06:32:12 +00:00
Zhongxing Xu 2e8123e5bb Add utility method. Remove an unused method.
llvm-svn: 60758
2008-12-09 10:51:19 +00:00