From: Argyrios Kyrtzidis Date: Mon, 28 Feb 2011 01:28:18 +0000 (+0000) Subject: [analyzer] Introduce SVal::getAsVarDecl(). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d3bf3c0287a057eafe4b5d5588ebbb29f40ab6e1;p=clang [analyzer] Introduce SVal::getAsVarDecl(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126627 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h b/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h index 0d430794e7..35c7274f7d 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h @@ -125,6 +125,10 @@ public: /// Otherwise return 0. const FunctionDecl* getAsFunctionDecl() const; + /// \brief If this SVal is a MemRegionVal and wraps a VarDecl, + /// return that VarDecl. Otherwise return 0. + const VarDecl* getAsVarDecl() const; + /// getAsLocSymbol - If this SVal is a location (subclasses Loc) and /// wraps a symbol, return that SymbolRef. Otherwise return NULL. SymbolRef getAsLocSymbol() const; diff --git a/lib/StaticAnalyzer/Core/SVals.cpp b/lib/StaticAnalyzer/Core/SVals.cpp index 4614e349de..76ad94e40d 100644 --- a/lib/StaticAnalyzer/Core/SVals.cpp +++ b/lib/StaticAnalyzer/Core/SVals.cpp @@ -60,6 +60,16 @@ const FunctionDecl *SVal::getAsFunctionDecl() const { return NULL; } +const VarDecl* SVal::getAsVarDecl() const { + if (const loc::MemRegionVal* X = dyn_cast(this)) { + const MemRegion* R = X->getRegion(); + if (const VarRegion *VR = R->getAs()) + return cast(VR->getDecl()); + } + + return NULL; +} + /// getAsLocSymbol - If this SVal is a location (subclasses Loc) and /// wraps a symbol, return that SymbolRef. Otherwise return 0. // FIXME: should we consider SymbolRef wrapped in CodeTextRegion?