[analyzer][NFC] Remove dead code and modernize surroundings

Thanks @kazu for helping me clean these parts in D127799.

I'm leaving the dump methods, along with the unused visitor handlers and
the forwarding methods.

The dead parts actually helped to uncover two bugs, to which I'm going
to post separate patches.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D127836
This commit is contained in:
Balazs Benics 2022-06-15 16:50:12 +02:00
parent 575c9d6d4a
commit f1b18a79b7
15 changed files with 8 additions and 90 deletions

View File

@ -347,10 +347,6 @@ public:
CFNumberChecker() : ICreate(nullptr), IGetValue(nullptr) {}
void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
private:
void EmitError(const TypedRegion* R, const Expr *Ex,
uint64_t SourceSize, uint64_t TargetSize, uint64_t NumberKind);
};
} // end anonymous namespace

View File

@ -56,9 +56,6 @@ class DynamicTypePropagation:
check::PreObjCMessage,
check::PostObjCMessage > {
const ObjCObjectType *getObjectTypeForAllocAndNew(const ObjCMessageExpr *MsgE,
CheckerContext &C) const;
/// Return a better dynamic type if one can be derived from the cast.
const ObjCObjectPointerType *getBetterObjCType(const Expr *CastE,
CheckerContext &C) const;

View File

@ -254,9 +254,6 @@ static const ExplodedNode *getAcquireSite(const ExplodedNode *N, SymbolRef Sym,
namespace {
class FuchsiaHandleSymbolVisitor final : public SymbolVisitor {
public:
FuchsiaHandleSymbolVisitor(ProgramStateRef State) : State(std::move(State)) {}
ProgramStateRef getState() const { return State; }
bool VisitSymbol(SymbolRef S) override {
if (const auto *HandleType = S->getType()->getAs<TypedefType>())
if (HandleType->getDecl()->getName() == HandleTypeName)
@ -268,7 +265,6 @@ public:
private:
SmallVector<SymbolRef, 1024> Symbols;
ProgramStateRef State;
};
} // end anonymous namespace
@ -284,7 +280,7 @@ getFuchsiaHandleSymbols(QualType QT, SVal Arg, ProgramStateRef State) {
if (QT->isStructureType()) {
// If we see a structure, see if there is any handle referenced by the
// structure.
FuchsiaHandleSymbolVisitor Visitor(State);
FuchsiaHandleSymbolVisitor Visitor;
State->scanReachableSymbols(Arg, Visitor);
return Visitor.GetSymbols();
}

View File

@ -176,15 +176,6 @@ public:
bool isEmpty() const { return DiscreteArgs.empty() && !VariadicIndex; }
ArgVecTy ArgsUpTo(ArgIdxTy LastArgIdx) const {
ArgVecTy Args;
for (ArgIdxTy I = ReturnValueIndex; I <= LastArgIdx; ++I) {
if (contains(I))
Args.push_back(I);
}
return Args;
}
private:
ArgVecTy DiscreteArgs;
Optional<ArgIdxTy> VariadicIndex;
@ -340,11 +331,6 @@ private:
class GenericTaintChecker : public Checker<check::PreCall, check::PostCall> {
public:
static void *getTag() {
static int Tag;
return &Tag;
}
void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
void checkPostCall(const CallEvent &Call, CheckerContext &C) const;

View File

@ -63,9 +63,7 @@ public:
return Cont == X.Cont && Valid == X.Valid && Offset == X.Offset;
}
bool operator!=(const IteratorPosition &X) const {
return Cont != X.Cont || Valid != X.Valid || Offset != X.Offset;
}
bool operator!=(const IteratorPosition &X) const { return !(*this == X); }
void Profile(llvm::FoldingSetNodeID &ID) const {
ID.AddPointer(Cont);
@ -101,9 +99,7 @@ public:
return Begin == X.Begin && End == X.End;
}
bool operator!=(const ContainerData &X) const {
return Begin != X.Begin || End != X.End;
}
bool operator!=(const ContainerData &X) const { return !(*this == X); }
void Profile(llvm::FoldingSetNodeID &ID) const {
ID.Add(Begin);

View File

@ -151,8 +151,6 @@ public:
void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext &C) const;
void checkPostStmt(const UnaryOperator *UO, CheckerContext &C) const;
void checkPostStmt(const BinaryOperator *BO, CheckerContext &C) const;
void checkPostStmt(const CXXConstructExpr *CCE, CheckerContext &C) const;
void checkPostStmt(const DeclStmt *DS, CheckerContext &C) const;
void checkPostStmt(const MaterializeTemporaryExpr *MTE,
CheckerContext &C) const;
void checkLiveSymbols(ProgramStateRef State, SymbolReaper &SR) const;

View File

@ -927,11 +927,6 @@ public:
ID.AddPointer(&Tag);
ID.AddPointer(Sym);
}
void *getTag() const {
static int Tag = 0;
return static_cast<void *>(&Tag);
}
};
} // end anonymous namespace

View File

@ -49,7 +49,6 @@ class MoveChecker
: public Checker<check::PreCall, check::PostCall,
check::DeadSymbols, check::RegionChanges> {
public:
void checkEndFunction(const ReturnStmt *RS, CheckerContext &C) const;
void checkPreCall(const CallEvent &MC, CheckerContext &C) const;
void checkPostCall(const CallEvent &MC, CheckerContext &C) const;
void checkDeadSymbols(SymbolReaper &SR, CheckerContext &C) const;

View File

@ -47,9 +47,6 @@ class ObjCContainersChecker : public Checker< check::PreStmt<CallExpr>,
CheckerContext &C) const;
public:
/// A tag to id this checker.
static void *getTag() { static int Tag; return &Tag; }
void checkPostStmt(const CallExpr *CE, CheckerContext &C) const;
void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
ProgramStateRef checkPointerEscape(ProgramStateRef State,

View File

@ -89,20 +89,6 @@ public:
/// state. Let's store it in the ProgramState.
REGISTER_MAP_WITH_PROGRAMSTATE(StreamMap, SymbolRef, StreamState)
namespace {
class StopTrackingCallback final : public SymbolVisitor {
ProgramStateRef state;
public:
StopTrackingCallback(ProgramStateRef st) : state(std::move(st)) {}
ProgramStateRef getState() const { return state; }
bool VisitSymbol(SymbolRef sym) override {
state = state->remove<StreamMap>(sym);
return true;
}
};
} // end anonymous namespace
SimpleStreamChecker::SimpleStreamChecker()
: OpenFn("fopen"), CloseFn("fclose", 1) {
// Initialize the bug types.

View File

@ -50,7 +50,6 @@ public:
// Whether the checker should model for null dereferences of smart pointers.
bool ModelSmartPtrDereference = false;
bool evalCall(const CallEvent &Call, CheckerContext &C) const;
void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
ProgramStateRef
checkRegionChanges(ProgramStateRef State,

View File

@ -22,27 +22,15 @@ using namespace ento;
using namespace taint;
namespace {
class TaintTesterChecker : public Checker< check::PostStmt<Expr> > {
mutable std::unique_ptr<BugType> BT;
void initBugType() const;
/// Given a pointer argument, get the symbol of the value it contains
/// (points to).
SymbolRef getPointedToSymbol(CheckerContext &C,
const Expr* Arg,
bool IssueWarning = true) const;
class TaintTesterChecker : public Checker<check::PostStmt<Expr>> {
std::unique_ptr<BugType> BT =
std::make_unique<BugType>(this, "Tainted data", "General");
public:
void checkPostStmt(const Expr *E, CheckerContext &C) const;
};
}
inline void TaintTesterChecker::initBugType() const {
if (!BT)
BT.reset(new BugType(this, "Tainted data", "General"));
}
void TaintTesterChecker::checkPostStmt(const Expr *E,
CheckerContext &C) const {
ProgramStateRef State = C.getState();
@ -51,7 +39,6 @@ void TaintTesterChecker::checkPostStmt(const Expr *E,
if (isTainted(State, E, C.getLocationContext())) {
if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
initBugType();
auto report = std::make_unique<PathSensitiveBugReport>(*BT, "tainted", N);
report->addRange(E->getSourceRange());
C.emitReport(std::move(report));

View File

@ -527,11 +527,6 @@ public:
ID.AddPointer(RegionOfInterest);
}
void *getTag() const {
static int Tag = 0;
return static_cast<void *>(&Tag);
}
private:
/// \return Whether \c RegionOfInterest was modified at \p CurrN compared to
/// the value it holds in \p CallExitBeginN.

View File

@ -118,18 +118,10 @@ namespace {
/// the construction context was present and contained references to these
/// AST nodes.
class ConstructedObjectKey {
typedef std::pair<ConstructionContextItem, const LocationContext *>
ConstructedObjectKeyImpl;
using ConstructedObjectKeyImpl =
std::pair<ConstructionContextItem, const LocationContext *>;
const ConstructedObjectKeyImpl Impl;
const void *getAnyASTNodePtr() const {
if (const Stmt *S = getItem().getStmtOrNull())
return S;
else
return getItem().getCXXCtorInitializer();
}
public:
explicit ConstructedObjectKey(const ConstructionContextItem &Item,
const LocationContext *LC)

View File

@ -352,7 +352,6 @@ public:
private:
void storeTopLevelDecls(DeclGroupRef DG);
std::string getFunctionName(const Decl *D);
/// Check if we should skip (not analyze) the given function.
AnalysisMode getModeForDecl(Decl *D, AnalysisMode Mode);