From: Ted Kremenek Date: Fri, 15 Feb 2008 00:35:38 +0000 (+0000) Subject: Added --grsimple-view option to clang driver; this is the same as X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d55fe520e79960afa796bda53cb4273fb1be4811;p=clang Added --grsimple-view option to clang driver; this is the same as --grsimple except that it visualizes the ExplodedGraph using dot and outputs the current function being analyzed. --grsimple is now silent except when it emits diagnostics. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47146 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/GRSimpleVals.cpp b/Analysis/GRSimpleVals.cpp index 1e438ee5b3..e856c3e5d0 100644 --- a/Analysis/GRSimpleVals.cpp +++ b/Analysis/GRSimpleVals.cpp @@ -20,7 +20,7 @@ using namespace clang; namespace clang { void RunGRSimpleVals(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx, - Diagnostic& Diag) { + Diagnostic& Diag, bool Visualize) { if (Diag.hasErrorOccurred()) return; @@ -45,7 +45,7 @@ namespace clang { } #ifndef NDEBUG - CheckerState->ViewGraph(); + if (Visualize) CheckerState->ViewGraph(); #endif } } // end clang namespace diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index 08e2238a66..73f843f27a 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -580,20 +580,23 @@ namespace { class GRSimpleValsVisitor : public CFGVisitor { Diagnostic &Diags; ASTContext* Ctx; + bool Visualize; public: - GRSimpleValsVisitor(Diagnostic &diags) : Diags(diags) {} + GRSimpleValsVisitor(Diagnostic &diags, bool visualize) + : Diags(diags), Visualize(visualize) {} virtual void Initialize(ASTContext &Context) { Ctx = &Context; } virtual void VisitCFG(CFG& C, FunctionDecl&); + virtual bool printFuncDeclStart() { return Visualize; } }; } // end anonymous namespace -ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags) { - return new GRSimpleValsVisitor(Diags); +ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags, bool Visualize) { + return new GRSimpleValsVisitor(Diags, Visualize); } void GRSimpleValsVisitor::VisitCFG(CFG& C, FunctionDecl& FD) { - RunGRSimpleVals(C, FD, *Ctx, Diags); + RunGRSimpleVals(C, FD, *Ctx, Diags, Visualize); } //===----------------------------------------------------------------------===// diff --git a/Driver/ASTConsumers.h b/Driver/ASTConsumers.h index 8a14ff2b9e..08d2268162 100644 --- a/Driver/ASTConsumers.h +++ b/Driver/ASTConsumers.h @@ -41,7 +41,7 @@ ASTConsumer *CreateDeadStoreChecker(Diagnostic &Diags); ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags); -ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags); +ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags, bool Visualize = false); ASTConsumer *CreateCodeRewriterTest(const std::string& InFile, Diagnostic &Diags); diff --git a/Driver/clang.cpp b/Driver/clang.cpp index c29730397f..71291ae0a2 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -68,7 +68,8 @@ enum ProgActions { ParseCFGDump, // Parse ASTS. Build CFGs. Print CFGs. ParseCFGView, // Parse ASTS. Build CFGs. View CFGs. AnalysisLiveVariables, // Print results of live-variable analysis. - AnalysisGRSimpleVals, // Perform graph-reachability constant prop. + AnalysisGRSimpleVals, // Perform graph-reachability constant prop. + AnalysisGRSimpleValsView, // Visualize results of path-sens. analysis. WarnDeadStores, // Run DeadStores checker on parsed ASTs. WarnDeadStoresCheck, // Check diagnostics for "DeadStores". WarnUninitVals, // Run UnitializedVariables checker. @@ -115,6 +116,8 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore, "Flag warnings of uses of unitialized variables."), clEnumValN(AnalysisGRSimpleVals, "grsimple", "Perform path-sensitive constant propagation."), + clEnumValN(AnalysisGRSimpleValsView, "grsimple-view", + "View results of path-sensitive constant propagation."), clEnumValN(TestSerialization, "test-pickling", "Run prototype serializtion code."), clEnumValN(EmitLLVM, "emit-llvm", @@ -974,6 +977,9 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile, case AnalysisGRSimpleVals: return CreateGRSimpleVals(Diag); + case AnalysisGRSimpleValsView: + return CreateGRSimpleVals(Diag, true); + case TestSerialization: return CreateSerializationTest(Diag, FileMgr, LangOpts); diff --git a/include/clang/Analysis/Analyses/GRSimpleVals.h b/include/clang/Analysis/Analyses/GRSimpleVals.h index 4da6d258db..83b647360a 100644 --- a/include/clang/Analysis/Analyses/GRSimpleVals.h +++ b/include/clang/Analysis/Analyses/GRSimpleVals.h @@ -25,7 +25,7 @@ namespace clang { /// something more elaborate as the requirements on the interface become /// clearer. void RunGRSimpleVals(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx, - Diagnostic& Diag); + Diagnostic& Diag, bool Visualize); } // end clang namespace