]> granicus.if.org Git - clang/commitdiff
[analyzer] Introduce SVal::getAsVarDecl().
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 28 Feb 2011 01:28:18 +0000 (01:28 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 28 Feb 2011 01:28:18 +0000 (01:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126627 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
lib/StaticAnalyzer/Core/SVals.cpp

index 0d430794e76cb4e924323ac79d435be0370c235e..35c7274f7d3f8226977877f9524647be8a584c45 100644 (file)
@@ -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;
index 4614e349dece4275a4668813a6e49dabca437e6c..76ad94e40d817959e1db558cecb05a9b39b5ad9e 100644 (file)
@@ -60,6 +60,16 @@ const FunctionDecl *SVal::getAsFunctionDecl() const {
   return NULL;
 }
 
+const VarDecl* SVal::getAsVarDecl() const {
+  if (const loc::MemRegionVal* X = dyn_cast<loc::MemRegionVal>(this)) {
+    const MemRegion* R = X->getRegion();
+    if (const VarRegion *VR = R->getAs<VarRegion>())
+      return cast<VarDecl>(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?