Hide away implementation details of the ThreadSafetyAnalysis in anonymous namespaces

NFC.

llvm-svn: 231653
This commit is contained in:
Benjamin Kramer 2015-03-09 14:19:54 +00:00
parent ed61e1fcd1
commit 66a97ee957
4 changed files with 43 additions and 69 deletions

View File

@ -216,6 +216,8 @@ void runThreadSafetyAnalysis(AnalysisDeclContext &AC,
ThreadSafetyHandler &Handler,
BeforeSet **Bset);
void threadSafetyCleanup(BeforeSet *Cache);
/// \brief Helper function that returns a LockKind required for the given level
/// of access.
LockKind getLockKindFromAccessKind(AccessKind AK);

View File

@ -44,14 +44,13 @@
#include <sstream>
#include <utility>
#include <vector>
namespace clang {
namespace threadSafety {
using namespace clang;
using namespace threadSafety;
// Key method definition
ThreadSafetyHandler::~ThreadSafetyHandler() {}
namespace {
class TILPrinter :
public til::PrettyPrinter<TILPrinter, llvm::raw_ostream> {};
@ -69,7 +68,6 @@ static void warnInvalidLock(ThreadSafetyHandler &Handler,
Handler.handleInvalidLockExp(Kind, Loc);
}
/// \brief A set of CapabilityInfo objects, which are compiled from the
/// requires attributes on a function.
class CapExprSet : public SmallVector<CapabilityExpr, 4> {
@ -250,10 +248,11 @@ public:
}
};
class ThreadSafetyAnalyzer;
} // namespace
namespace clang {
namespace threadSafety {
class BeforeSet {
private:
typedef SmallVector<const ValueDecl*, 4> BeforeVect;
@ -286,9 +285,10 @@ private:
BeforeMap BMap;
CycleMap CycMap;
};
} // end namespace threadSafety
} // end namespace clang
namespace {
typedef llvm::ImmutableMap<const NamedDecl*, unsigned> LocalVarContext;
class LocalVariableMap;
@ -903,7 +903,7 @@ public:
/// \brief Class which implements the core thread safety analysis routines.
class ThreadSafetyAnalyzer {
friend class BuildLockset;
friend class BeforeSet;
friend class threadSafety::BeforeSet;
llvm::BumpPtrAllocator Bpa;
threadSafety::til::MemRegionRef Arena;
@ -959,8 +959,7 @@ public:
void runAnalysis(AnalysisDeclContext &AC);
};
} // namespace
/// Process acquired_before and acquired_after attributes on Vd.
BeforeSet::BeforeInfo* BeforeSet::insertAttrExprs(const ValueDecl* Vd,
@ -1103,6 +1102,7 @@ static const ValueDecl *getValueDecl(const Expr *Exp) {
return nullptr;
}
namespace {
template <typename Ty>
class has_arg_iterator_range {
typedef char yes[1];
@ -1117,6 +1117,7 @@ class has_arg_iterator_range {
public:
static const bool value = sizeof(test<Ty>(nullptr)) == sizeof(yes);
};
} // namespace
static StringRef ClassifyDiagnostic(const CapabilityAttr *A) {
return A->getName();
@ -1307,8 +1308,7 @@ void ThreadSafetyAnalyzer::getMutexIDs(CapExprSet &Mtxs, AttrType *Attr,
}
}
bool getStaticBooleanValue(Expr* E, bool& TCond) {
static bool getStaticBooleanValue(Expr *E, bool &TCond) {
if (isa<CXXNullPtrLiteralExpr>(E) || isa<GNUNullExpr>(E)) {
TCond = false;
return true;
@ -1453,6 +1453,7 @@ void ThreadSafetyAnalyzer::getEdgeLockset(FactSet& Result,
CapDiagKind);
}
namespace {
/// \brief We use this class to visit different types of expressions in
/// CFGBlocks, and build up the lockset.
/// An expression may cause us to add or remove locks from the lockset, or else
@ -1496,7 +1497,7 @@ public:
void VisitCXXConstructExpr(CXXConstructExpr *Exp);
void VisitDeclStmt(DeclStmt *S);
};
} // namespace
/// \brief Warn if the LSet does not contain a lock sufficient to protect access
/// of at least the passed in AccessKind.
@ -2059,7 +2060,7 @@ void ThreadSafetyAnalyzer::intersectAndWarn(FactSet &FSet1,
// Return true if block B never continues to its successors.
inline bool neverReturns(const CFGBlock* B) {
static bool neverReturns(const CFGBlock *B) {
if (B->hasNoReturnElement())
return true;
if (B->empty())
@ -2376,24 +2377,20 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
/// We traverse the blocks in the CFG, compute the set of mutexes that are held
/// at the end of each block, and issue warnings for thread safety violations.
/// Each block in the CFG is traversed exactly once.
void runThreadSafetyAnalysis(AnalysisDeclContext &AC,
ThreadSafetyHandler &Handler,
BeforeSet **BSet) {
void threadSafety::runThreadSafetyAnalysis(AnalysisDeclContext &AC,
ThreadSafetyHandler &Handler,
BeforeSet **BSet) {
if (!*BSet)
*BSet = new BeforeSet;
ThreadSafetyAnalyzer Analyzer(Handler, *BSet);
Analyzer.runAnalysis(AC);
}
void threadSafetyCleanup(BeforeSet* Cache) {
delete Cache;
}
void threadSafety::threadSafetyCleanup(BeforeSet *Cache) { delete Cache; }
/// \brief Helper function that returns a LockKind required for the given level
/// of access.
LockKind getLockKindFromAccessKind(AccessKind AK) {
LockKind threadSafety::getLockKindFromAccessKind(AccessKind AK) {
switch (AK) {
case AK_Read :
return LK_Shared;
@ -2402,5 +2399,3 @@ LockKind getLockKindFromAccessKind(AccessKind AK) {
}
llvm_unreachable("Unknown AccessKind");
}
}} // end namespace clang::threadSafety

View File

@ -31,13 +31,11 @@
#include <algorithm>
#include <climits>
#include <vector>
namespace clang {
namespace threadSafety {
using namespace clang;
using namespace threadSafety;
// From ThreadSafetyUtil.h
std::string getSourceLiteralString(const clang::Expr *CE) {
std::string threadSafety::getSourceLiteralString(const clang::Expr *CE) {
switch (CE->getStmtClass()) {
case Stmt::IntegerLiteralClass:
return cast<IntegerLiteral>(CE)->getValue().toString(10, true);
@ -59,18 +57,13 @@ std::string getSourceLiteralString(const clang::Expr *CE) {
}
}
namespace til {
// Return true if E is a variable that points to an incomplete Phi node.
static bool isIncompletePhi(const SExpr *E) {
if (const auto *Ph = dyn_cast<Phi>(E))
return Ph->status() == Phi::PH_Incomplete;
static bool isIncompletePhi(const til::SExpr *E) {
if (const auto *Ph = dyn_cast<til::Phi>(E))
return Ph->status() == til::Phi::PH_Incomplete;
return false;
}
} // end namespace til
typedef SExprBuilder::CallingContext CallingContext;
@ -87,9 +80,7 @@ til::SCFG *SExprBuilder::buildCFG(CFGWalker &Walker) {
return Scfg;
}
inline bool isCalleeArrow(const Expr *E) {
static bool isCalleeArrow(const Expr *E) {
const MemberExpr *ME = dyn_cast<MemberExpr>(E->IgnoreParenCasts());
return ME ? ME->isArrow() : false;
}
@ -313,8 +304,7 @@ til::SExpr *SExprBuilder::translateCXXThisExpr(const CXXThisExpr *TE,
return SelfVar;
}
const ValueDecl *getValueDeclFromSExpr(const til::SExpr *E) {
static const ValueDecl *getValueDeclFromSExpr(const til::SExpr *E) {
if (auto *V = dyn_cast<til::Variable>(E))
return V->clangDecl();
if (auto *Ph = dyn_cast<til::Phi>(E))
@ -326,7 +316,7 @@ const ValueDecl *getValueDeclFromSExpr(const til::SExpr *E) {
return 0;
}
bool hasCppPointerType(const til::SExpr *E) {
static bool hasCppPointerType(const til::SExpr *E) {
auto *VD = getValueDeclFromSExpr(E);
if (VD && VD->getType()->isPointerType())
return true;
@ -336,9 +326,8 @@ bool hasCppPointerType(const til::SExpr *E) {
return false;
}
// Grab the very first declaration of virtual method D
const CXXMethodDecl* getFirstVirtualDecl(const CXXMethodDecl *D) {
static const CXXMethodDecl *getFirstVirtualDecl(const CXXMethodDecl *D) {
while (true) {
D = D->getCanonicalDecl();
CXXMethodDecl::method_iterator I = D->begin_overridden_methods(),
@ -663,7 +652,7 @@ til::SExpr *SExprBuilder::lookupVarDecl(const ValueDecl *VD) {
// if E is a til::Variable, update its clangDecl.
inline void maybeUpdateVD(til::SExpr *E, const ValueDecl *VD) {
static void maybeUpdateVD(til::SExpr *E, const ValueDecl *VD) {
if (!E)
return;
if (til::Variable *V = dyn_cast<til::Variable>(E)) {
@ -986,8 +975,3 @@ void printSCFG(CFGWalker &Walker) {
TILPrinter::print(Scfg, llvm::errs());
}
*/
} // end namespace threadSafety
} // end namespace clang

View File

@ -9,13 +9,11 @@
#include "clang/Analysis/Analyses/ThreadSafetyTIL.h"
#include "clang/Analysis/Analyses/ThreadSafetyTraverse.h"
using namespace clang;
using namespace threadSafety;
using namespace til;
namespace clang {
namespace threadSafety {
namespace til {
StringRef getUnaryOpcodeString(TIL_UnaryOpcode Op) {
StringRef til::getUnaryOpcodeString(TIL_UnaryOpcode Op) {
switch (Op) {
case UOP_Minus: return "-";
case UOP_BitNot: return "~";
@ -24,8 +22,7 @@ StringRef getUnaryOpcodeString(TIL_UnaryOpcode Op) {
return "";
}
StringRef getBinaryOpcodeString(TIL_BinaryOpcode Op) {
StringRef til::getBinaryOpcodeString(TIL_BinaryOpcode Op) {
switch (Op) {
case BOP_Mul: return "*";
case BOP_Div: return "/";
@ -82,7 +79,7 @@ void BasicBlock::reservePredecessors(unsigned NumPreds) {
// If E is a variable, then trace back through any aliases or redundant
// Phi nodes to find the canonical definition.
const SExpr *getCanonicalVal(const SExpr *E) {
const SExpr *til::getCanonicalVal(const SExpr *E) {
while (true) {
if (auto *V = dyn_cast<Variable>(E)) {
if (V->kind() == Variable::VK_Let) {
@ -105,7 +102,7 @@ const SExpr *getCanonicalVal(const SExpr *E) {
// If E is a variable, then trace back through any aliases or redundant
// Phi nodes to find the canonical definition.
// The non-const version will simplify incomplete Phi nodes.
SExpr *simplifyToCanonicalVal(SExpr *E) {
SExpr *til::simplifyToCanonicalVal(SExpr *E) {
while (true) {
if (auto *V = dyn_cast<Variable>(E)) {
if (V->kind() != Variable::VK_Let)
@ -135,7 +132,7 @@ SExpr *simplifyToCanonicalVal(SExpr *E) {
// Trace the arguments of an incomplete Phi node to see if they have the same
// canonical definition. If so, mark the Phi node as redundant.
// getCanonicalVal() will recursively call simplifyIncompletePhi().
void simplifyIncompleteArg(til::Phi *Ph) {
void til::simplifyIncompleteArg(til::Phi *Ph) {
assert(Ph && Ph->status() == Phi::PH_Incomplete);
// eliminate infinite recursion -- assume that this node is not redundant.
@ -337,7 +334,3 @@ void SCFG::computeNormalForm() {
computeNodeID(Block, &BasicBlock::PostDominatorNode);
}
}
} // end namespace til
} // end namespace threadSafety
} // end namespace clang