[analyzer] Be more plugin-friendly by moving static locals into .cpp files.
authorArtem Dergachev <artem.dergachev@gmail.com>
Sat, 20 Oct 2018 00:29:24 +0000 (00:29 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Sat, 20 Oct 2018 00:29:24 +0000 (00:29 +0000)
The GDMIndex functions return a pointer that's used as a key for looking up
data, but addresses of local statics defined in header files aren't the same
across shared library boundaries and the result is that analyzer plugins
can't access this data.

Event types are uniqued by using the addresses of a local static defined
in a header files, but it isn't the same across shared library boundaries
and plugins can't currently handle ImplicitNullDerefEvents.

Patches by Joe Ranieri!

Differential Revision: https://reviews.llvm.org/D52905
Differential Revision: https://reviews.llvm.org/D52906

llvm-svn: 344823

12 files changed:
clang/include/clang/StaticAnalyzer/Core/Checker.h
clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h
clang/lib/StaticAnalyzer/Core/CMakeLists.txt
clang/lib/StaticAnalyzer/Core/Checker.cpp
clang/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
clang/lib/StaticAnalyzer/Core/TaintManager.cpp [new file with mode: 0644]

index 8484cfe..786465c 100644 (file)
@@ -558,6 +558,8 @@ struct ImplicitNullDerefEvent {
   // dereference might happen later (for example pointer passed to a parameter
   // that is marked with nonnull attribute.)
   bool IsDirectDereference;
+
+  static int Tag;
 };
 
 /// A helper class which wraps a boolean value set to false by default.
index 463c842..538ed19 100644 (file)
@@ -532,19 +532,19 @@ public:
 
   template <typename EVENT>
   void _registerListenerForEvent(CheckEventFunc checkfn) {
-    EventInfo &info = Events[getTag<EVENT>()];
+    EventInfo &info = Events[&EVENT::Tag];
     info.Checkers.push_back(checkfn);
   }
 
   template <typename EVENT>
   void _registerDispatcherForEvent() {
-    EventInfo &info = Events[getTag<EVENT>()];
+    EventInfo &info = Events[&EVENT::Tag];
     info.HasDispatcher = true;
   }
 
   template <typename EVENT>
   void _dispatchEvent(const EVENT &event) const {
-    EventsTy::const_iterator I = Events.find(getTag<EVENT>());
+    EventsTy::const_iterator I = Events.find(&EVENT::Tag);
     if (I == Events.end())
       return;
     const EventInfo &info = I->second;
index 2f8ead0..b0d514d 100644 (file)
@@ -36,10 +36,7 @@ using DynamicTypeMapImpl =
 template <>
 struct ProgramStateTrait<DynamicTypeMap>
     : public ProgramStatePartialTrait<DynamicTypeMapImpl> {
-  static void *GDMIndex() {
-    static int index = 0;
-    return &index;
-  }
+  static void *GDMIndex();
 };
 
 /// Get dynamic type information for a region.
index 91e47b3..86b776a 100644 (file)
@@ -832,7 +832,7 @@ struct ReplayWithoutInlining{};
 template <>
 struct ProgramStateTrait<ReplayWithoutInlining> :
   public ProgramStatePartialTrait<const void*> {
-  static void *GDMIndex() { static int index = 0; return &index; }
+  static void *GDMIndex();
 };
 
 } // namespace ento
index d2ba1f7..1b12a4e 100644 (file)
@@ -131,7 +131,7 @@ using ConstraintRangeTy = llvm::ImmutableMap<SymbolRef, RangeSet>;
 template <>
 struct ProgramStateTrait<ConstraintRange>
   : public ProgramStatePartialTrait<ConstraintRangeTy> {
-  static void *GDMIndex() { static int Index; return &Index; }
+  static void *GDMIndex();
 };
 
 
index ce19b71..8218fb1 100644 (file)
@@ -34,10 +34,7 @@ using TaintMapImpl = llvm::ImmutableMap<SymbolRef, TaintTagType>;
 
 template<> struct ProgramStateTrait<TaintMap>
     :  public ProgramStatePartialTrait<TaintMapImpl> {
-  static void *GDMIndex() {
-    static int index = 0;
-    return &index;
-  }
+  static void *GDMIndex();
 };
 
 /// The GDM component mapping derived symbols' parent symbols to their
@@ -49,10 +46,7 @@ using DerivedSymTaintImpl = llvm::ImmutableMap<SymbolRef, TaintedSubRegions>;
 
 template<> struct ProgramStateTrait<DerivedSymTaint>
     :  public ProgramStatePartialTrait<DerivedSymTaintImpl> {
-  static void *GDMIndex() {
-    static int index;
-    return &index;
-  }
+  static void *GDMIndex();
 };
 
 class TaintManager {
index db06e4e..4431007 100644 (file)
@@ -52,6 +52,7 @@ add_clang_library(clangStaticAnalyzerCore
   Store.cpp
   SubEngine.cpp
   SymbolManager.cpp
+  TaintManager.cpp
   WorkList.cpp
   Z3ConstraintManager.cpp
 
index b422a88..72bfd84 100644 (file)
@@ -17,6 +17,8 @@
 using namespace clang;
 using namespace ento;
 
+int ImplicitNullDerefEvent::Tag;
+
 StringRef CheckerBase::getTagDescription() const {
   return getCheckName().getName();
 }
index 5309339..da7854d 100644 (file)
@@ -77,5 +77,10 @@ void printDynamicTypeInfo(ProgramStateRef State, raw_ostream &Out,
   }
 }
 
+void *ProgramStateTrait<DynamicTypeMap>::GDMIndex() {
+  static int index = 0;
+  return &index;
+}
+
 } // namespace ento
 } // namespace clang
index c5edfad..f30cf5a 100644 (file)
@@ -3108,3 +3108,8 @@ std::string ExprEngine::DumpGraph(ArrayRef<const ExplodedNode*> Nodes,
   llvm::errs() << "Warning: dumping graph requires assertions" << "\n";
   return "";
 }
+
+void *ProgramStateTrait<ReplayWithoutInlining>::GDMIndex() {
+  static int index = 0;
+  return &index;
+}
index f99853f..146dc20 100644 (file)
@@ -200,6 +200,11 @@ void RangedConstraintManager::computeAdjustment(SymbolRef &Sym,
   }
 }
 
+void *ProgramStateTrait<ConstraintRange>::GDMIndex() {
+  static int Index;
+  return &Index;
+}
+
 } // end of namespace ento
 
 } // end of namespace clang
diff --git a/clang/lib/StaticAnalyzer/Core/TaintManager.cpp b/clang/lib/StaticAnalyzer/Core/TaintManager.cpp
new file mode 100644 (file)
index 0000000..c34b0ca
--- /dev/null
@@ -0,0 +1,23 @@
+//== TaintManager.cpp ------------------------------------------ -*- C++ -*--=//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h"
+
+using namespace clang;
+using namespace ento;
+
+void *ProgramStateTrait<TaintMap>::GDMIndex() {
+  static int index = 0;
+  return &index;
+}
+
+void *ProgramStateTrait<DerivedSymTaint>::GDMIndex() {
+  static int index;
+  return &index;
+}