forked from OSchip/llvm-project
Inlined clang/Analysis/Analyses/GRSimpleVals.h into LocalCheckers.h and removed
GRSimpleVals.h Added a PathDiagnosticClient option to the driver functions for the CFRefCountChecker and the GRSimpleVals analysis. Both analyses now accept a "-o" argument from the driver that specifies where HTML reports should be dumped. llvm-svn: 48989
This commit is contained in:
parent
612d34641b
commit
c27815ca82
|
@ -12,18 +12,20 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ASTConsumers.h"
|
||||
#include "HTMLDiagnostics.h"
|
||||
#include "clang/AST/TranslationUnit.h"
|
||||
#include "clang/Basic/Diagnostic.h"
|
||||
#include "clang/Analysis/PathDiagnostic.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
#include "clang/Basic/FileManager.h"
|
||||
#include "clang/AST/AST.h"
|
||||
#include "clang/AST/ASTConsumer.h"
|
||||
#include "clang/AST/CFG.h"
|
||||
#include "clang/Analysis/Analyses/LiveVariables.h"
|
||||
#include "clang/Analysis/Analyses/GRSimpleVals.h"
|
||||
#include "clang/Analysis/LocalCheckers.h"
|
||||
#include "llvm/Support/Streams.h"
|
||||
#include "llvm/Support/Timer.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
|
||||
using namespace clang;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -630,12 +632,15 @@ namespace {
|
|||
class GRSimpleValsVisitor : public CFGVisitor {
|
||||
Diagnostic &Diags;
|
||||
ASTContext* Ctx;
|
||||
const std::string& HTMLDir;
|
||||
bool Visualize;
|
||||
bool TrimGraph;
|
||||
public:
|
||||
GRSimpleValsVisitor(Diagnostic &diags, const std::string& fname,
|
||||
const std::string& htmldir,
|
||||
bool visualize, bool trim)
|
||||
: CFGVisitor(fname), Diags(diags), Visualize(visualize), TrimGraph(trim){}
|
||||
: CFGVisitor(fname), Diags(diags), HTMLDir(htmldir),
|
||||
Visualize(visualize), TrimGraph(trim) {}
|
||||
|
||||
virtual void Initialize(ASTContext &Context) { Ctx = &Context; }
|
||||
virtual void VisitCFG(CFG& C, Decl&);
|
||||
|
@ -645,9 +650,11 @@ namespace {
|
|||
|
||||
ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags,
|
||||
const std::string& FunctionName,
|
||||
const std::string& HTMLDir,
|
||||
bool Visualize, bool TrimGraph) {
|
||||
|
||||
return new GRSimpleValsVisitor(Diags, FunctionName, Visualize, TrimGraph);
|
||||
return new GRSimpleValsVisitor(Diags, FunctionName, HTMLDir,
|
||||
Visualize, TrimGraph);
|
||||
}
|
||||
|
||||
void GRSimpleValsVisitor::VisitCFG(CFG& C, Decl& CD) {
|
||||
|
@ -678,16 +685,21 @@ void GRSimpleValsVisitor::VisitCFG(CFG& C, Decl& CD) {
|
|||
#if 0
|
||||
llvm::Timer T("GRSimpleVals");
|
||||
T.startTimer();
|
||||
unsigned size = RunGRSimpleVals(C, CD, *Ctx, Diags, false, false);
|
||||
unsigned size = RunGRSimpleVals(C, CD, *Ctx, Diags, NULL, false, false);
|
||||
T.stopTimer();
|
||||
llvm::cerr << size << ' ' << T.getWallTime() << '\n';
|
||||
#else
|
||||
RunGRSimpleVals(C, CD, *Ctx, Diags, false, false);
|
||||
llvm::OwningPtr<PathDiagnosticClient> PD;
|
||||
|
||||
if (!HTMLDir.empty())
|
||||
PD.reset(CreateHTMLDiagnosticClient(HTMLDir));
|
||||
|
||||
RunGRSimpleVals(C, CD, *Ctx, Diags, PD.get(), false, false);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
llvm::cerr << '\n';
|
||||
RunGRSimpleVals(C, CD, *Ctx, Diags, Visualize, TrimGraph);
|
||||
RunGRSimpleVals(C, CD, *Ctx, Diags, NULL, Visualize, TrimGraph);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -699,10 +711,12 @@ namespace {
|
|||
class CFRefCountCheckerVisitor : public CFGVisitor {
|
||||
Diagnostic &Diags;
|
||||
ASTContext* Ctx;
|
||||
const std::string& HTMLDir;
|
||||
|
||||
public:
|
||||
CFRefCountCheckerVisitor(Diagnostic &diags, const std::string& fname)
|
||||
: CFGVisitor(fname), Diags(diags) {}
|
||||
CFRefCountCheckerVisitor(Diagnostic &diags, const std::string& fname,
|
||||
const std::string& htmldir)
|
||||
: CFGVisitor(fname), Diags(diags), HTMLDir(htmldir) {}
|
||||
|
||||
virtual void Initialize(ASTContext &Context) { Ctx = &Context; }
|
||||
virtual void VisitCFG(CFG& C, Decl&);
|
||||
|
@ -712,20 +726,21 @@ namespace {
|
|||
|
||||
|
||||
ASTConsumer* clang::CreateCFRefChecker(Diagnostic &Diags,
|
||||
const std::string& FunctionName) {
|
||||
const std::string& FunctionName,
|
||||
const std::string& HTMLDir) {
|
||||
|
||||
return new CFRefCountCheckerVisitor(Diags, FunctionName);
|
||||
return new CFRefCountCheckerVisitor(Diags, FunctionName, HTMLDir);
|
||||
}
|
||||
|
||||
void CFRefCountCheckerVisitor::VisitCFG(CFG& C, Decl& CD) {
|
||||
|
||||
|
||||
SourceLocation Loc = CD.getLocation();
|
||||
|
||||
if (!Loc.isFileID() ||
|
||||
Loc.getFileID() != Ctx->getSourceManager().getMainFileID())
|
||||
return;
|
||||
|
||||
CheckCFRefCount(C, CD, *Ctx, Diags);
|
||||
CheckCFRefCount(C, CD, *Ctx, Diags, NULL);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -44,10 +44,12 @@ ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags);
|
|||
|
||||
ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags,
|
||||
const std::string& Function,
|
||||
const std::string& HTMLDir,
|
||||
bool Visualize = false, bool TrimGraph = false);
|
||||
|
||||
ASTConsumer* CreateCFRefChecker(Diagnostic &Diags,
|
||||
const std::string& FunctionName);
|
||||
const std::string& FunctionName,
|
||||
const std::string& HTMLDir);
|
||||
|
||||
ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
|
||||
const std::string& OutFile,
|
||||
|
|
|
@ -1039,13 +1039,14 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
|
|||
return CreateUnitValsChecker(Diag);
|
||||
|
||||
case AnalysisGRSimpleVals:
|
||||
return CreateGRSimpleVals(Diag, AnalyzeSpecificFunction);
|
||||
return CreateGRSimpleVals(Diag, AnalyzeSpecificFunction, OutputFile);
|
||||
|
||||
case AnalysisGRSimpleValsView:
|
||||
return CreateGRSimpleVals(Diag, AnalyzeSpecificFunction, true, TrimGraph);
|
||||
return CreateGRSimpleVals(Diag, AnalyzeSpecificFunction, OutputFile,
|
||||
true, TrimGraph);
|
||||
|
||||
case CheckerCFRef:
|
||||
return CreateCFRefChecker(Diag, AnalyzeSpecificFunction);
|
||||
return CreateCFRefChecker(Diag, AnalyzeSpecificFunction, OutputFile);
|
||||
|
||||
case TestSerialization:
|
||||
return CreateSerializationTest(Diag, FileMgr, LangOpts);
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
//===-- GRSimpleVals.h- Simple, Path-Sens. Constant Prop. ---------*- C++ -*-==//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Constant Propagation via Graph Reachability
|
||||
//
|
||||
// This file defines the interface to use the 'GRSimpleVals' path-sensitive
|
||||
// constant-propagation analysis.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CLANG_GRCONSTANTS
|
||||
#define LLVM_CLANG_GRCONSTANTS
|
||||
|
||||
namespace clang {
|
||||
class Diagnostic;
|
||||
|
||||
/// RunGRSimpleVals - This is a simple driver to run the GRSimpleVals analysis
|
||||
/// on a provided CFG. This interface will eventually be replaced with
|
||||
/// something more elaborate as the requirements on the interface become
|
||||
/// clearer. The value returned is the number of nodes in the ExplodedGraph.
|
||||
unsigned RunGRSimpleVals(CFG& cfg, Decl& CD, ASTContext& Ctx,
|
||||
Diagnostic& Diag, bool Visualize, bool TrimGraph);
|
||||
|
||||
} // end clang namespace
|
||||
|
||||
|
||||
#endif
|
|
@ -21,6 +21,7 @@ class CFG;
|
|||
class Decl;
|
||||
class Diagnostic;
|
||||
class ASTContext;
|
||||
class PathDiagnosticClient;
|
||||
|
||||
void CheckDeadStores(CFG& cfg, ASTContext &Ctx, Diagnostic &Diags);
|
||||
|
||||
|
@ -28,7 +29,11 @@ void CheckUninitializedValues(CFG& cfg, ASTContext& Ctx, Diagnostic& Diags,
|
|||
bool FullUninitTaint=false);
|
||||
|
||||
void CheckCFRefCount(CFG& cfg, Decl& CodeDecl, ASTContext& Ctx,
|
||||
Diagnostic& Diag);
|
||||
Diagnostic& Diag, PathDiagnosticClient* PD);
|
||||
|
||||
unsigned RunGRSimpleVals(CFG& cfg, Decl& CD, ASTContext& Ctx,
|
||||
Diagnostic& Diag, PathDiagnosticClient* PD,
|
||||
bool Visualize, bool TrimGraph);
|
||||
|
||||
} // end namespace clang
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include "GRSimpleVals.h"
|
||||
#include "clang/Analysis/PathSensitive/ValueState.h"
|
||||
#include "clang/Basic/Diagnostic.h"
|
||||
#include "clang/Analysis/PathDiagnostic.h"
|
||||
#include "clang/Analysis/LocalCheckers.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/FoldingSet.h"
|
||||
|
@ -778,7 +778,7 @@ CFRefCount::RefBindings CFRefCount::Update(RefBindings B, SymbolID sym,
|
|||
namespace clang {
|
||||
|
||||
void CheckCFRefCount(CFG& cfg, Decl& CD, ASTContext& Ctx,
|
||||
Diagnostic& Diag) {
|
||||
Diagnostic& Diag, PathDiagnosticClient* PD) {
|
||||
|
||||
if (Diag.hasErrorOccurred())
|
||||
return;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "GRSimpleVals.h"
|
||||
#include "BasicObjCFoundationChecks.h"
|
||||
#include "clang/Analysis/PathSensitive/ValueState.h"
|
||||
#include "clang/Basic/Diagnostic.h"
|
||||
#include "clang/Analysis/PathDiagnostic.h"
|
||||
#include <sstream>
|
||||
|
||||
using namespace clang;
|
||||
|
@ -46,28 +46,31 @@ static inline Stmt* GetStmt(const ProgramPoint& P) {
|
|||
}
|
||||
|
||||
template <typename ITERATOR>
|
||||
static void EmitDiag(Diagnostic& Diag, SourceManager& SrcMgr,
|
||||
unsigned ErrorDiag, ITERATOR I) {
|
||||
static void EmitDiag(Diagnostic& Diag, PathDiagnosticClient* PD,
|
||||
SourceManager& SrcMgr,
|
||||
unsigned ErrorDiag, ITERATOR I) {
|
||||
|
||||
Stmt* S = GetStmt(GetLocation(I));
|
||||
Diag.Report(FullSourceLoc(S->getLocStart(), SrcMgr), ErrorDiag);
|
||||
Diag.Report(PD, FullSourceLoc(S->getLocStart(), SrcMgr), ErrorDiag);
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
static void EmitDiag(Diagnostic& Diag, SourceManager& SrcMgr,
|
||||
unsigned ErrorDiag, GRExprEngine::undef_arg_iterator I) {
|
||||
static void EmitDiag(Diagnostic& Diag, PathDiagnosticClient* PD,
|
||||
SourceManager& SrcMgr, unsigned ErrorDiag,
|
||||
GRExprEngine::undef_arg_iterator I) {
|
||||
|
||||
Stmt* S1 = GetStmt(GetLocation(I));
|
||||
Expr* E2 = cast<Expr>(I->second);
|
||||
|
||||
SourceLocation Loc = S1->getLocStart();
|
||||
SourceRange R = E2->getSourceRange();
|
||||
Diag.Report(FullSourceLoc(Loc, SrcMgr), ErrorDiag, 0, 0, &R, 1);
|
||||
Diag.Report(PD, FullSourceLoc(Loc, SrcMgr), ErrorDiag, 0, 0, &R, 1);
|
||||
}
|
||||
|
||||
template <typename ITERATOR>
|
||||
void EmitWarning(Diagnostic& Diag, SourceManager& SrcMgr,
|
||||
void EmitWarning(Diagnostic& Diag, PathDiagnosticClient* PD,
|
||||
SourceManager& SrcMgr,
|
||||
ITERATOR I, ITERATOR E, const char* msg) {
|
||||
|
||||
std::ostringstream Out;
|
||||
|
@ -97,12 +100,13 @@ void EmitWarning(Diagnostic& Diag, SourceManager& SrcMgr,
|
|||
CachedErrors.insert(p);
|
||||
}
|
||||
|
||||
EmitDiag(Diag, SrcMgr, ErrorDiag, I);
|
||||
EmitDiag(Diag, PD, SrcMgr, ErrorDiag, I);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned RunGRSimpleVals(CFG& cfg, Decl& CD, ASTContext& Ctx,
|
||||
Diagnostic& Diag, bool Visualize, bool TrimGraph) {
|
||||
Diagnostic& Diag, PathDiagnosticClient* PD,
|
||||
bool Visualize, bool TrimGraph) {
|
||||
|
||||
GRCoreEngine<GRExprEngine> Eng(cfg, CD, Ctx);
|
||||
GRExprEngine* CheckerState = &Eng.getCheckerState();
|
||||
|
@ -118,56 +122,56 @@ unsigned RunGRSimpleVals(CFG& cfg, Decl& CD, ASTContext& Ctx,
|
|||
CheckerState->AddObjCMessageExprCheck(FoundationCheck.get());
|
||||
|
||||
// Execute the worklist algorithm.
|
||||
Eng.ExecuteWorkList(100000);
|
||||
Eng.ExecuteWorkList(120000);
|
||||
|
||||
SourceManager& SrcMgr = Ctx.getSourceManager();
|
||||
|
||||
EmitWarning(Diag, SrcMgr,
|
||||
EmitWarning(Diag, PD, SrcMgr,
|
||||
CheckerState->null_derefs_begin(),
|
||||
CheckerState->null_derefs_end(),
|
||||
"Dereference of NULL pointer.");
|
||||
|
||||
EmitWarning(Diag, SrcMgr,
|
||||
EmitWarning(Diag, PD, SrcMgr,
|
||||
CheckerState->undef_derefs_begin(),
|
||||
CheckerState->undef_derefs_end(),
|
||||
"Dereference of undefined value.");
|
||||
|
||||
EmitWarning(Diag, SrcMgr,
|
||||
EmitWarning(Diag, PD, SrcMgr,
|
||||
CheckerState->undef_branches_begin(),
|
||||
CheckerState->undef_branches_end(),
|
||||
"Branch condition evaluates to an uninitialized value.");
|
||||
|
||||
EmitWarning(Diag, SrcMgr,
|
||||
EmitWarning(Diag, PD, SrcMgr,
|
||||
CheckerState->explicit_bad_divides_begin(),
|
||||
CheckerState->explicit_bad_divides_end(),
|
||||
"Division by zero/undefined value.");
|
||||
|
||||
EmitWarning(Diag, SrcMgr,
|
||||
EmitWarning(Diag, PD, SrcMgr,
|
||||
CheckerState->undef_results_begin(),
|
||||
CheckerState->undef_results_end(),
|
||||
"Result of operation is undefined.");
|
||||
|
||||
EmitWarning(Diag, SrcMgr,
|
||||
EmitWarning(Diag, PD, SrcMgr,
|
||||
CheckerState->bad_calls_begin(),
|
||||
CheckerState->bad_calls_end(),
|
||||
"Call using a NULL or undefined function pointer value.");
|
||||
|
||||
EmitWarning(Diag, SrcMgr,
|
||||
EmitWarning(Diag, PD, SrcMgr,
|
||||
CheckerState->undef_arg_begin(),
|
||||
CheckerState->undef_arg_end(),
|
||||
"Pass-by-value argument in function is undefined.");
|
||||
|
||||
EmitWarning(Diag, SrcMgr,
|
||||
EmitWarning(Diag, PD, SrcMgr,
|
||||
CheckerState->msg_expr_undef_arg_begin(),
|
||||
CheckerState->msg_expr_undef_arg_end(),
|
||||
"Pass-by-value argument in message expression is undefined.");
|
||||
|
||||
EmitWarning(Diag, SrcMgr,
|
||||
EmitWarning(Diag, PD, SrcMgr,
|
||||
CheckerState->undef_receivers_begin(),
|
||||
CheckerState->undef_receivers_end(),
|
||||
"Receiver in message expression is an uninitialized value.");
|
||||
|
||||
EmitWarning(Diag, SrcMgr,
|
||||
EmitWarning(Diag, PD, SrcMgr,
|
||||
CheckerState->ret_stackaddr_begin(),
|
||||
CheckerState->ret_stackaddr_end(),
|
||||
"Address of stack-allocated variable returned.");
|
||||
|
|
Loading…
Reference in New Issue