From: Artem Dergachev Date: Sat, 20 Oct 2018 00:29:24 +0000 (+0000) Subject: [analyzer] Be more plugin-friendly by moving static locals into .cpp files. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3f9a2142b46f697d5ec2b911256470152a7097e7;p=clang [analyzer] Be more plugin-friendly by moving static locals into .cpp files. 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 --- diff --git a/include/clang/StaticAnalyzer/Core/Checker.h b/include/clang/StaticAnalyzer/Core/Checker.h index 8484cfe4c9..786465cee8 100644 --- a/include/clang/StaticAnalyzer/Core/Checker.h +++ b/include/clang/StaticAnalyzer/Core/Checker.h @@ -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. diff --git a/include/clang/StaticAnalyzer/Core/CheckerManager.h b/include/clang/StaticAnalyzer/Core/CheckerManager.h index 463c842ec5..538ed19f7e 100644 --- a/include/clang/StaticAnalyzer/Core/CheckerManager.h +++ b/include/clang/StaticAnalyzer/Core/CheckerManager.h @@ -532,19 +532,19 @@ public: template void _registerListenerForEvent(CheckEventFunc checkfn) { - EventInfo &info = Events[getTag()]; + EventInfo &info = Events[&EVENT::Tag]; info.Checkers.push_back(checkfn); } template void _registerDispatcherForEvent() { - EventInfo &info = Events[getTag()]; + EventInfo &info = Events[&EVENT::Tag]; info.HasDispatcher = true; } template void _dispatchEvent(const EVENT &event) const { - EventsTy::const_iterator I = Events.find(getTag()); + EventsTy::const_iterator I = Events.find(&EVENT::Tag); if (I == Events.end()) return; const EventInfo &info = I->second; diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h b/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h index 2f8ead0746..b0d514dc28 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h @@ -36,10 +36,7 @@ using DynamicTypeMapImpl = template <> struct ProgramStateTrait : public ProgramStatePartialTrait { - static void *GDMIndex() { - static int index = 0; - return &index; - } + static void *GDMIndex(); }; /// Get dynamic type information for a region. diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h index 91e47b37b7..86b776afb8 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h @@ -832,7 +832,7 @@ struct ReplayWithoutInlining{}; template <> struct ProgramStateTrait : public ProgramStatePartialTrait { - static void *GDMIndex() { static int index = 0; return &index; } + static void *GDMIndex(); }; } // namespace ento diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h b/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h index d2ba1f7c95..1b12a4edc2 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h @@ -131,7 +131,7 @@ using ConstraintRangeTy = llvm::ImmutableMap; template <> struct ProgramStateTrait : public ProgramStatePartialTrait { - static void *GDMIndex() { static int Index; return &Index; } + static void *GDMIndex(); }; diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h b/include/clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h index ce19b7131d..8218fb1eea 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h @@ -34,10 +34,7 @@ using TaintMapImpl = llvm::ImmutableMap; template<> struct ProgramStateTrait : public ProgramStatePartialTrait { - 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; template<> struct ProgramStateTrait : public ProgramStatePartialTrait { - static void *GDMIndex() { - static int index; - return &index; - } + static void *GDMIndex(); }; class TaintManager { diff --git a/lib/StaticAnalyzer/Core/CMakeLists.txt b/lib/StaticAnalyzer/Core/CMakeLists.txt index db06e4efd5..44310073a6 100644 --- a/lib/StaticAnalyzer/Core/CMakeLists.txt +++ b/lib/StaticAnalyzer/Core/CMakeLists.txt @@ -52,6 +52,7 @@ add_clang_library(clangStaticAnalyzerCore Store.cpp SubEngine.cpp SymbolManager.cpp + TaintManager.cpp WorkList.cpp Z3ConstraintManager.cpp diff --git a/lib/StaticAnalyzer/Core/Checker.cpp b/lib/StaticAnalyzer/Core/Checker.cpp index b422a88719..72bfd84b40 100644 --- a/lib/StaticAnalyzer/Core/Checker.cpp +++ b/lib/StaticAnalyzer/Core/Checker.cpp @@ -17,6 +17,8 @@ using namespace clang; using namespace ento; +int ImplicitNullDerefEvent::Tag; + StringRef CheckerBase::getTagDescription() const { return getCheckName().getName(); } diff --git a/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp b/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp index 5309339168..da7854df1d 100644 --- a/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp +++ b/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp @@ -77,5 +77,10 @@ void printDynamicTypeInfo(ProgramStateRef State, raw_ostream &Out, } } +void *ProgramStateTrait::GDMIndex() { + static int index = 0; + return &index; +} + } // namespace ento } // namespace clang diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp index c5edfad741..f30cf5a216 100644 --- a/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -3108,3 +3108,8 @@ std::string ExprEngine::DumpGraph(ArrayRef Nodes, llvm::errs() << "Warning: dumping graph requires assertions" << "\n"; return ""; } + +void *ProgramStateTrait::GDMIndex() { + static int index = 0; + return &index; +} diff --git a/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp b/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp index f99853f070..146dc20ad0 100644 --- a/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp +++ b/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp @@ -200,6 +200,11 @@ void RangedConstraintManager::computeAdjustment(SymbolRef &Sym, } } +void *ProgramStateTrait::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 index 0000000000..c34b0ca183 --- /dev/null +++ b/lib/StaticAnalyzer/Core/TaintManager.cpp @@ -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::GDMIndex() { + static int index = 0; + return &index; +} + +void *ProgramStateTrait::GDMIndex() { + static int index; + return &index; +}