From 2c791bd122285e1212094147454ef996dee8ebaf Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 6 Nov 2009 00:44:32 +0000 Subject: [PATCH] Minor cleanup: use BuiltinBug (which will soon be renamed) for DeferenceChecker and friends so that they always report the same bug type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86208 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Analysis/PathSensitive/BugType.h | 14 ++++++++++---- lib/Analysis/DereferenceChecker.cpp | 5 ++--- lib/Analysis/DivZeroChecker.cpp | 2 +- lib/Analysis/UndefinedArgChecker.cpp | 4 ++-- lib/Analysis/UndefinedAssignmentChecker.cpp | 3 +-- lib/Analysis/VLASizeChecker.cpp | 4 ++-- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/include/clang/Analysis/PathSensitive/BugType.h b/include/clang/Analysis/PathSensitive/BugType.h index 242b8e9afe..1526fbb38c 100644 --- a/include/clang/Analysis/PathSensitive/BugType.h +++ b/include/clang/Analysis/PathSensitive/BugType.h @@ -59,21 +59,27 @@ public: }; class BuiltinBug : public BugType { - GRExprEngine &Eng; + GRExprEngine *Eng; protected: const std::string desc; public: + BuiltinBug(const char *name, const char *description) + : BugType(name, "Logic error"), Eng(0), desc(description) {} + + BuiltinBug(const char *name) + : BugType(name, "Logic error"), Eng(0), desc(name) {} + BuiltinBug(GRExprEngine *eng, const char* n, const char* d) - : BugType(n, "Logic error"), Eng(*eng), desc(d) {} + : BugType(n, "Logic error"), Eng(eng), desc(d) {} BuiltinBug(GRExprEngine *eng, const char* n) - : BugType(n, "Logic error"), Eng(*eng), desc(n) {} + : BugType(n, "Logic error"), Eng(eng), desc(n) {} const std::string &getDescription() const { return desc; } virtual void FlushReportsImpl(BugReporter& BR, GRExprEngine& Eng) {} - void FlushReports(BugReporter& BR) { FlushReportsImpl(BR, Eng); } + void FlushReports(BugReporter& BR) { FlushReportsImpl(BR, *Eng); } virtual void registerInitialVisitors(BugReporterContext& BRC, const ExplodedNode* N, diff --git a/lib/Analysis/DereferenceChecker.cpp b/lib/Analysis/DereferenceChecker.cpp index 33c85d5074..b7233419ef 100644 --- a/lib/Analysis/DereferenceChecker.cpp +++ b/lib/Analysis/DereferenceChecker.cpp @@ -51,12 +51,11 @@ ExplodedNode *NullDerefChecker::CheckLocation(const Stmt *S, ExplodedNode *Pred, if (!NotNullState) { // Explicit null case. if (!BT) - BT = new BuiltinBug(NULL, "Null dereference", - "Dereference of null pointer"); + BT = new BuiltinBug("Null dereference","Dereference of null pointer"); EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getDescription().c_str(), N); - + R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, bugreporter::GetDerefExpr(N)); diff --git a/lib/Analysis/DivZeroChecker.cpp b/lib/Analysis/DivZeroChecker.cpp index 9c2359f3b0..c90c0ab493 100644 --- a/lib/Analysis/DivZeroChecker.cpp +++ b/lib/Analysis/DivZeroChecker.cpp @@ -50,7 +50,7 @@ void DivZeroChecker::PreVisitBinaryOperator(CheckerContext &C, if (stateZero && !stateNotZero) { if (ExplodedNode *N = C.GenerateNode(B, stateZero, true)) { if (!BT) - BT = new BuiltinBug(0, "Division by zero"); + BT = new BuiltinBug("Division by zero"); EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getDescription().c_str(), N); diff --git a/lib/Analysis/UndefinedArgChecker.cpp b/lib/Analysis/UndefinedArgChecker.cpp index a229f55ff6..549c3b5fe9 100644 --- a/lib/Analysis/UndefinedArgChecker.cpp +++ b/lib/Analysis/UndefinedArgChecker.cpp @@ -29,8 +29,8 @@ void UndefinedArgChecker::PreVisitCallExpr(CheckerContext &C, if (C.getState()->getSVal(*I).isUndef()) { if (ExplodedNode *N = C.GenerateNode(CE, true)) { if (!BT) - BT = new BugType("Pass-by-value argument in function call is " - "undefined", "Logic error"); + BT = new BuiltinBug("Pass-by-value argument in function call is " + "undefined"); // Generate a report for this bug. EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName().c_str(), N); diff --git a/lib/Analysis/UndefinedAssignmentChecker.cpp b/lib/Analysis/UndefinedAssignmentChecker.cpp index 2e3ac34913..26f9ee30d4 100644 --- a/lib/Analysis/UndefinedAssignmentChecker.cpp +++ b/lib/Analysis/UndefinedAssignmentChecker.cpp @@ -36,8 +36,7 @@ void UndefinedAssignmentChecker::PreVisitBind(CheckerContext &C, return; if (!BT) - BT = new BugType("Assigned value is garbage or undefined", - "Logic error"); + BT = new BuiltinBug("Assigned value is garbage or undefined"); // Generate a report for this bug. EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName().c_str(), N); diff --git a/lib/Analysis/VLASizeChecker.cpp b/lib/Analysis/VLASizeChecker.cpp index 0e731902f4..6184a77cf3 100644 --- a/lib/Analysis/VLASizeChecker.cpp +++ b/lib/Analysis/VLASizeChecker.cpp @@ -38,8 +38,8 @@ ExplodedNode *UndefSizedVLAChecker::CheckType(QualType T, ExplodedNode *Pred, if (ExplodedNode* N = Builder.generateNode(S, state, Pred)) { N->markAsSink(); if (!BT) - BT = new BugType("Declared variable-length array (VLA) uses a garbage" - " value as its size", "Logic error"); + BT = new BuiltinBug("Declared variable-length array (VLA) uses a " + "garbage value as its size"); EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName().c_str(), N); -- 2.40.0