]> granicus.if.org Git - clang/commitdiff
Don't add a symbolic region for 'this' if the member function is static.
authorAnders Carlsson <andersca@mac.com>
Sat, 26 Mar 2011 14:30:44 +0000 (14:30 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 26 Mar 2011 14:30:44 +0000 (14:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128340 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/BasicStore.cpp
test/Analysis/cxx-crashes.cpp

index 98365e7f4e6278cbd9f264a72d19ccea57fa0c47..4faa84ca2660ad8f80d741ace70e1067423089cc 100644 (file)
@@ -429,12 +429,15 @@ StoreRef BasicStoreManager::getInitialStore(const LocationContext *InitLoc) {
   }
 
   if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(InitLoc->getDecl())) {
-    // For C++ methods add symbolic region for 'this' in initial stack frame.
-    QualType ThisT = MD->getThisType(StateMgr.getContext());
-    MemRegionManager &RegMgr = svalBuilder.getRegionManager();
-    const CXXThisRegion *ThisR = RegMgr.getCXXThisRegion(ThisT, InitLoc);
-    SVal ThisV = svalBuilder.getRegionValueSymbolVal(ThisR);
-    St = Bind(St.getStore(), svalBuilder.makeLoc(ThisR), ThisV);
+    // For C++ non-static member variables, add a symbolic region for 'this' in
+    // the initial stack frame.
+    if (MD->isInstance()) {
+      QualType ThisT = MD->getThisType(StateMgr.getContext());
+      MemRegionManager &RegMgr = svalBuilder.getRegionManager();
+      const CXXThisRegion *ThisR = RegMgr.getCXXThisRegion(ThisT, InitLoc);
+      SVal ThisV = svalBuilder.getRegionValueSymbolVal(ThisR);
+      St = Bind(St.getStore(), svalBuilder.makeLoc(ThisR), ThisV);
+    }
   }
 
   return St;
index 17e7c6dc0c85fde2496cb8cede7a98cd81999ddb..17fc74d06f4611023f54a772b788b4120b1ccdb1 100644 (file)
@@ -43,3 +43,14 @@ void *f(S* w) {
 }
 
 }
+
+namespace {
+
+struct C { 
+  void *p;
+  static void f();
+};
+
+void C::f() { }
+
+}