[cfe-commits] r48989 - in /cfe/trunk: Driver/ASTConsumers.cpp Driver/ASTConsumers.h Driver/clang.cpp include/clang/Analysis/Analyses/GRSimpleVals.h include/clang/Analysis/LocalCheckers.h lib/Analysis/CFRefCount.cpp lib/Analysis/GRSimpleVals.cpp
Ted Kremenek
kremenek at apple.com
Mon Mar 31 11:26:32 PDT 2008
Author: kremenek
Date: Mon Mar 31 13:26:32 2008
New Revision: 48989
URL: http://llvm.org/viewvc/llvm-project?rev=48989&view=rev
Log:
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.
Removed:
cfe/trunk/include/clang/Analysis/Analyses/GRSimpleVals.h
Modified:
cfe/trunk/Driver/ASTConsumers.cpp
cfe/trunk/Driver/ASTConsumers.h
cfe/trunk/Driver/clang.cpp
cfe/trunk/include/clang/Analysis/LocalCheckers.h
cfe/trunk/lib/Analysis/CFRefCount.cpp
cfe/trunk/lib/Analysis/GRSimpleVals.cpp
Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=48989&r1=48988&r2=48989&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Mon Mar 31 13:26:32 2008
@@ -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 @@
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 @@
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 @@
#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 @@
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 @@
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);
}
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/Driver/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.h?rev=48989&r1=48988&r2=48989&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.h (original)
+++ cfe/trunk/Driver/ASTConsumers.h Mon Mar 31 13:26:32 2008
@@ -44,10 +44,12 @@
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,
Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=48989&r1=48988&r2=48989&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Mon Mar 31 13:26:32 2008
@@ -1039,13 +1039,14 @@
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);
Removed: cfe/trunk/include/clang/Analysis/Analyses/GRSimpleVals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/GRSimpleVals.h?rev=48988&view=auto
==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/GRSimpleVals.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/GRSimpleVals.h (removed)
@@ -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
Modified: cfe/trunk/include/clang/Analysis/LocalCheckers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/LocalCheckers.h?rev=48989&r1=48988&r2=48989&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/LocalCheckers.h (original)
+++ cfe/trunk/include/clang/Analysis/LocalCheckers.h Mon Mar 31 13:26:32 2008
@@ -21,6 +21,7 @@
class Decl;
class Diagnostic;
class ASTContext;
+class PathDiagnosticClient;
void CheckDeadStores(CFG& cfg, ASTContext &Ctx, Diagnostic &Diags);
@@ -28,7 +29,11 @@
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
Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=48989&r1=48988&r2=48989&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Mon Mar 31 13:26:32 2008
@@ -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 @@
namespace clang {
void CheckCFRefCount(CFG& cfg, Decl& CD, ASTContext& Ctx,
- Diagnostic& Diag) {
+ Diagnostic& Diag, PathDiagnosticClient* PD) {
if (Diag.hasErrorOccurred())
return;
Modified: cfe/trunk/lib/Analysis/GRSimpleVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRSimpleVals.cpp?rev=48989&r1=48988&r2=48989&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRSimpleVals.cpp (original)
+++ cfe/trunk/lib/Analysis/GRSimpleVals.cpp Mon Mar 31 13:26:32 2008
@@ -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 @@
}
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 @@
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 @@
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.");
More information about the cfe-commits
mailing list