[cfe-commits] r126627 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h lib/StaticAnalyzer/Core/SVals.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Sun Feb 27 17:28:18 PST 2011


Author: akirtzidis
Date: Sun Feb 27 19:28:18 2011
New Revision: 126627

URL: http://llvm.org/viewvc/llvm-project?rev=126627&view=rev
Log:
[analyzer] Introduce SVal::getAsVarDecl().

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
    cfe/trunk/lib/StaticAnalyzer/Core/SVals.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h?rev=126627&r1=126626&r2=126627&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h Sun Feb 27 19:28:18 2011
@@ -125,6 +125,10 @@
   /// 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;

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SVals.cpp?rev=126627&r1=126626&r2=126627&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/SVals.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SVals.cpp Sun Feb 27 19:28:18 2011
@@ -60,6 +60,16 @@
   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?





More information about the cfe-commits mailing list