Skip to content

Commit

Permalink
[analyzer] Be more plugin-friendly by moving static locals into .cpp …
Browse files Browse the repository at this point in the history
…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

llvm-svn: 344823
  • Loading branch information
haoNoQ committed Oct 20, 2018
1 parent 8d6ff4c commit 25dac79
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 17 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/StaticAnalyzer/Core/Checker.h
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
Expand Up @@ -532,19 +532,19 @@ class CheckerManager {

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;
Expand Down
Expand Up @@ -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.
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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();
};


Expand Down
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions clang/lib/StaticAnalyzer/Core/CMakeLists.txt
Expand Up @@ -52,6 +52,7 @@ add_clang_library(clangStaticAnalyzerCore
Store.cpp
SubEngine.cpp
SymbolManager.cpp
TaintManager.cpp
WorkList.cpp
Z3ConstraintManager.cpp

Expand Down
2 changes: 2 additions & 0 deletions clang/lib/StaticAnalyzer/Core/Checker.cpp
Expand Up @@ -17,6 +17,8 @@
using namespace clang;
using namespace ento;

int ImplicitNullDerefEvent::Tag;

StringRef CheckerBase::getTagDescription() const {
return getCheckName().getName();
}
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
Expand Up @@ -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
5 changes: 5 additions & 0 deletions clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
Expand Up @@ -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
23 changes: 23 additions & 0 deletions clang/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<TaintMap>::GDMIndex() {
static int index = 0;
return &index;
}

void *ProgramStateTrait<DerivedSymTaint>::GDMIndex() {
static int index;
return &index;
}

0 comments on commit 25dac79

Please sign in to comment.