forked from OSchip/llvm-project
[analyzer] Migrate ReturnUndefChecker to CheckerV2.
llvm-svn: 126619
This commit is contained in:
parent
da6c7568e2
commit
4dc7fb37cb
|
@ -75,6 +75,10 @@ def ObjCUnusedIvarsChecker : Checker<"UnusedIvars">,
|
|||
|
||||
let ParentPackage = Core in {
|
||||
|
||||
def ReturnUndefChecker : Checker<"UndefReturn">,
|
||||
HelpText<"Check for undefined or garbage values being returned to the caller">,
|
||||
DescFile<"ReturnUndefChecker.cpp">;
|
||||
|
||||
def UndefinedArraySubscriptChecker : Checker<"UndefArraySubscript">,
|
||||
HelpText<"Check for undefined array subscripts">,
|
||||
DescFile<"UndefinedArraySubscriptChecker.cpp">;
|
||||
|
|
|
@ -327,7 +327,6 @@ static void RegisterInternalChecks(ExprEngine &Eng) {
|
|||
RegisterDereferenceChecker(Eng);
|
||||
RegisterVLASizeChecker(Eng);
|
||||
RegisterDivZeroChecker(Eng);
|
||||
RegisterReturnUndefChecker(Eng);
|
||||
}
|
||||
|
||||
ExprEngine::ExprEngine(AnalysisManager &mgr, TransferFuncs *tf)
|
||||
|
|
|
@ -27,7 +27,6 @@ void RegisterAttrNonNullChecker(ExprEngine &Eng);
|
|||
void RegisterCallAndMessageChecker(ExprEngine &Eng);
|
||||
void RegisterDereferenceChecker(ExprEngine &Eng);
|
||||
void RegisterDivZeroChecker(ExprEngine &Eng);
|
||||
void RegisterReturnUndefChecker(ExprEngine &Eng);
|
||||
void RegisterVLASizeChecker(ExprEngine &Eng);
|
||||
|
||||
} // end GR namespace
|
||||
|
|
|
@ -13,35 +13,26 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "InternalChecks.h"
|
||||
#include "ClangSACheckers.h"
|
||||
#include "clang/StaticAnalyzer/Core/CheckerV2.h"
|
||||
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
||||
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerVisitor.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
|
||||
|
||||
using namespace clang;
|
||||
using namespace ento;
|
||||
|
||||
namespace {
|
||||
class ReturnUndefChecker :
|
||||
public CheckerVisitor<ReturnUndefChecker> {
|
||||
BuiltinBug *BT;
|
||||
public CheckerV2< check::PreStmt<ReturnStmt> > {
|
||||
mutable llvm::OwningPtr<BuiltinBug> BT;
|
||||
public:
|
||||
ReturnUndefChecker() : BT(0) {}
|
||||
static void *getTag();
|
||||
void PreVisitReturnStmt(CheckerContext &C, const ReturnStmt *RS);
|
||||
void checkPreStmt(const ReturnStmt *RS, CheckerContext &C) const;
|
||||
};
|
||||
}
|
||||
|
||||
void ento::RegisterReturnUndefChecker(ExprEngine &Eng) {
|
||||
Eng.registerCheck(new ReturnUndefChecker());
|
||||
}
|
||||
|
||||
void *ReturnUndefChecker::getTag() {
|
||||
static int x = 0; return &x;
|
||||
}
|
||||
|
||||
void ReturnUndefChecker::PreVisitReturnStmt(CheckerContext &C,
|
||||
const ReturnStmt *RS) {
|
||||
void ReturnUndefChecker::checkPreStmt(const ReturnStmt *RS,
|
||||
CheckerContext &C) const {
|
||||
|
||||
const Expr *RetE = RS->getRetValue();
|
||||
if (!RetE)
|
||||
|
@ -56,8 +47,8 @@ void ReturnUndefChecker::PreVisitReturnStmt(CheckerContext &C,
|
|||
return;
|
||||
|
||||
if (!BT)
|
||||
BT = new BuiltinBug("Garbage return value",
|
||||
"Undefined or garbage value returned to caller");
|
||||
BT.reset(new BuiltinBug("Garbage return value",
|
||||
"Undefined or garbage value returned to caller"));
|
||||
|
||||
EnhancedBugReport *report =
|
||||
new EnhancedBugReport(*BT, BT->getDescription(), N);
|
||||
|
@ -67,3 +58,7 @@ void ReturnUndefChecker::PreVisitReturnStmt(CheckerContext &C,
|
|||
|
||||
C.EmitReport(report);
|
||||
}
|
||||
|
||||
void ento::registerReturnUndefChecker(CheckerManager &mgr) {
|
||||
mgr.registerChecker<ReturnUndefChecker>();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -verify %s
|
||||
// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-check-objc-mem -analyzer-store region -verify %s
|
||||
char PR7218(char a) {
|
||||
char buf[2];
|
||||
buf[0] = a;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -fblocks %s
|
||||
// RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s
|
||||
// RUN: %clang_cc1 -analyze -analyzer-checker=core,core.experimental -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -fblocks %s
|
||||
// RUN: %clang_cc1 -analyze -analyzer-checker=core,core.experimental -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s
|
||||
|
||||
// <rdar://problem/6776949>
|
||||
// main's 'argc' argument is always > 0
|
||||
|
|
Loading…
Reference in New Issue