]> granicus.if.org Git - clang/commitdiff
[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@344823 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 8484cfe4c95607e52f7663773063aae23d069f2a..786465cee85592ebb6e4ddc15618643976e41fa7 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 463c842ec5b7ac05817e8e700528a1e46e72b471..538ed19f7eeffd9c5e203bf7281f3f40b54b0f80 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 2f8ead0746cac25c1a03f81620dd1da11a3acfb1..b0d514dc2863e5d9efbea05601c72e9bf6d460a8 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 91e47b37b7758b85fc8da29755ed210a3851912a..86b776afb82254bfacd4d77ee045dfba98051d46 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 d2ba1f7c9529a807448ed9eb72f633f44b90620f..1b12a4edc205bc0a31f51b4c03de7f3e6e4bed98 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 ce19b7131d42d76cb7b3975057f6b6b45f7c06ff..8218fb1eeafe85e441a7fffac6d75f802107dff0 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 db06e4efd5434f0d3490ee1c1e7698d7a55dbeac..44310073a61f18294517968780aee2bddd5a51d2 100644 (file)
@@ -52,6 +52,7 @@ add_clang_library(clangStaticAnalyzerCore
   Store.cpp
   SubEngine.cpp
   SymbolManager.cpp
+  TaintManager.cpp
   WorkList.cpp
   Z3ConstraintManager.cpp
 
index b422a8871983bc901e43541e25b89aa76a7d4ec0..72bfd84b40a33acef50634e2341b4183a5c5b252 100644 (file)
@@ -17,6 +17,8 @@
 using namespace clang;
 using namespace ento;
 
+int ImplicitNullDerefEvent::Tag;
+
 StringRef CheckerBase::getTagDescription() const {
   return getCheckName().getName();
 }
index 530933916889c88efb73a0d5faa8dc940900b5c5..da7854df1def00247fb1f6397411f5b644963e5c 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 c5edfad7413616ea866bd63eb163c6fb094ca4f3..f30cf5a2162a134bd5f89625323cf977f573f9b2 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 f99853f0707314d2b39b532932e701dc91b60820..146dc20ad0210347632f9c008fa60392798b77a1 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/lib/StaticAnalyzer/Core/TaintManager.cpp b/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;
+}