diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/Driver/ASTConsumers.cpp | 41 | ||||
-rw-r--r-- | clang/Driver/ASTConsumers.h | 4 | ||||
-rw-r--r-- | clang/Driver/clang.cpp | 7 | ||||
-rw-r--r-- | clang/include/clang/Analysis/Analyses/GRSimpleVals.h | 33 | ||||
-rw-r--r-- | clang/include/clang/Analysis/LocalCheckers.h | 7 | ||||
-rw-r--r-- | clang/lib/Analysis/CFRefCount.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Analysis/GRSimpleVals.cpp | 46 |
7 files changed, 68 insertions, 74 deletions
diff --git a/clang/Driver/ASTConsumers.cpp b/clang/Driver/ASTConsumers.cpp index 5868a28b70a..60246865e91 100644 --- a/clang/Driver/ASTConsumers.cpp +++ b/clang/Driver/ASTConsumers.cpp @@ -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); } //===----------------------------------------------------------------------===// diff --git a/clang/Driver/ASTConsumers.h b/clang/Driver/ASTConsumers.h index c72f95ec73f..a38d4279cbc 100644 --- a/clang/Driver/ASTConsumers.h +++ b/clang/Driver/ASTConsumers.h @@ -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, diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index 2bf99f8eafb..ba464147a1f 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -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); diff --git a/clang/include/clang/Analysis/Analyses/GRSimpleVals.h b/clang/include/clang/Analysis/Analyses/GRSimpleVals.h deleted file mode 100644 index 2e772ef5366..00000000000 --- a/clang/include/clang/Analysis/Analyses/GRSimpleVals.h +++ /dev/null @@ -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 diff --git a/clang/include/clang/Analysis/LocalCheckers.h b/clang/include/clang/Analysis/LocalCheckers.h index 0966ffc0394..00fb06efe57 100644 --- a/clang/include/clang/Analysis/LocalCheckers.h +++ b/clang/include/clang/Analysis/LocalCheckers.h @@ -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 diff --git a/clang/lib/Analysis/CFRefCount.cpp b/clang/lib/Analysis/CFRefCount.cpp index ead329936be..2e7b410065e 100644 --- a/clang/lib/Analysis/CFRefCount.cpp +++ b/clang/lib/Analysis/CFRefCount.cpp @@ -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; diff --git a/clang/lib/Analysis/GRSimpleVals.cpp b/clang/lib/Analysis/GRSimpleVals.cpp index 697d256119d..a6aba83db27 100644 --- a/clang/lib/Analysis/GRSimpleVals.cpp +++ b/clang/lib/Analysis/GRSimpleVals.cpp @@ -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."); |