diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-10-04 05:50:14 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-10-04 05:50:14 +0000 |
commit | 9e24049bef26b6289cce9ac9b483c5cbb096e3ae (patch) | |
tree | c9a70624d81f7d9f3cd72af08e9f2cda445db3a2 /lib/Analysis/RValues.cpp | |
parent | 924d9a8cb989b5702dd07e1b1d7e8be9084f24f0 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57042 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/RValues.cpp')
-rw-r--r-- | lib/Analysis/RValues.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/Analysis/RValues.cpp b/lib/Analysis/RValues.cpp index 5dc9cd5fbe..337d479255 100644 --- a/lib/Analysis/RValues.cpp +++ b/lib/Analysis/RValues.cpp @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Analysis/PathSensitive/RValues.h" +#include "clang/Analysis/PathSensitive/GRState.h" #include "clang/Basic/IdentifierTable.h" #include "llvm/Support/Streams.h" @@ -163,9 +163,9 @@ NonLVal LVal::EQ(BasicValueFactory& BasicVals, const LVal& R) const { break; } - case lval::DeclValKind: - if (isa<lval::DeclVal>(R)) { - bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(R); + case lval::MemRegionKind: + if (isa<lval::MemRegionVal>(R)) { + bool b = cast<lval::MemRegionVal>(*this) == cast<lval::MemRegionVal>(R); return NonLVal::MakeIntTruthVal(BasicVals, b); } @@ -216,9 +216,9 @@ NonLVal LVal::NE(BasicValueFactory& BasicVals, const LVal& R) const { break; } - case lval::DeclValKind: - if (isa<lval::DeclVal>(R)) { - bool b = cast<lval::DeclVal>(*this) == cast<lval::DeclVal>(R); + case lval::MemRegionKind: + if (isa<lval::MemRegionVal>(R)) { + bool b = cast<lval::MemRegionVal>(*this)==cast<lval::MemRegionVal>(R); return NonLVal::MakeIntTruthVal(BasicVals, b); } @@ -270,12 +270,12 @@ LVal LVal::MakeVal(StringLiteral* S) { // Utility methods for constructing RVals (both NonLVals and LVals). //===----------------------------------------------------------------------===// -RVal RVal::MakeVal(BasicValueFactory& BasicVals, DeclRefExpr* E) { +RVal RVal::MakeVal(GRStateManager& SMgr, DeclRefExpr* E) { ValueDecl* D = cast<DeclRefExpr>(E)->getDecl(); if (VarDecl* VD = dyn_cast<VarDecl>(D)) { - return lval::DeclVal(VD); + return SMgr.getLVal(VD); } else if (EnumConstantDecl* ED = dyn_cast<EnumConstantDecl>(D)) { @@ -283,7 +283,7 @@ RVal RVal::MakeVal(BasicValueFactory& BasicVals, DeclRefExpr* E) { // already has persistent storage? We do this because we // are comparing states using pointer equality. Perhaps there is // a better way, since APInts are fairly lightweight. - + BasicValueFactory& BasicVals = SMgr.getBasicVals(); return nonlval::ConcreteInt(BasicVals.getValue(ED->getInitVal())); } else if (FunctionDecl* FD = dyn_cast<FunctionDecl>(D)) { @@ -408,9 +408,8 @@ void LVal::print(std::ostream& Out) const { << cast<lval::GotoLabel>(this)->getLabel()->getID()->getName(); break; - case lval::DeclValKind: - Out << '&' - << cast<lval::DeclVal>(this)->getDecl()->getIdentifier()->getName(); + case lval::MemRegionKind: + Out << '&' << cast<lval::MemRegionVal>(this)->getRegion()->getString(); break; case lval::FuncValKind: |