AnalysisConsumer.cpp revision 1f5171edc9fb9b0698a75fa981c29a750b0a6082
1//===--- AnalysisConsumer.cpp - ASTConsumer for running Analyses ----------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// "Meta" ASTConsumer for running different source analyses.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "AnalysisConsumer"
15
16#include "AnalysisConsumer.h"
17#include "clang/AST/ASTConsumer.h"
18#include "clang/AST/Decl.h"
19#include "clang/AST/DeclCXX.h"
20#include "clang/AST/DeclObjC.h"
21#include "clang/AST/ParentMap.h"
22#include "clang/AST/RecursiveASTVisitor.h"
23#include "clang/Analysis/CFG.h"
24#include "clang/Analysis/CallGraph.h"
25#include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h"
26#include "clang/StaticAnalyzer/Core/CheckerManager.h"
27#include "clang/StaticAnalyzer/Checkers/LocalCheckers.h"
28#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
29#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
30#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
31#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
32#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
33
34#include "clang/Basic/FileManager.h"
35#include "clang/Basic/SourceManager.h"
36#include "clang/Frontend/AnalyzerOptions.h"
37#include "clang/Lex/Preprocessor.h"
38#include "llvm/Support/raw_ostream.h"
39#include "llvm/Support/Path.h"
40#include "llvm/Support/Program.h"
41#include "llvm/Support/Timer.h"
42#include "llvm/ADT/DepthFirstIterator.h"
43#include "llvm/ADT/OwningPtr.h"
44#include "llvm/ADT/Statistic.h"
45
46#include <queue>
47
48using namespace clang;
49using namespace ento;
50using llvm::SmallPtrSet;
51
52static ExplodedNode::Auditor* CreateUbiViz();
53
54STATISTIC(NumFunctionTopLevel, "The # of functions at top level.");
55STATISTIC(NumFunctionsAnalyzed, "The # of functions analysed (as top level).");
56
57//===----------------------------------------------------------------------===//
58// Special PathDiagnosticConsumers.
59//===----------------------------------------------------------------------===//
60
61static PathDiagnosticConsumer*
62createPlistHTMLDiagnosticConsumer(const std::string& prefix,
63                                const Preprocessor &PP) {
64  PathDiagnosticConsumer *PD =
65    createHTMLDiagnosticConsumer(llvm::sys::path::parent_path(prefix), PP);
66  return createPlistDiagnosticConsumer(prefix, PP, PD);
67}
68
69//===----------------------------------------------------------------------===//
70// AnalysisConsumer declaration.
71//===----------------------------------------------------------------------===//
72
73namespace {
74
75class AnalysisConsumer : public ASTConsumer,
76                         public RecursiveASTVisitor<AnalysisConsumer> {
77  enum AnalysisMode {
78    ANALYSIS_SYNTAX,
79    ANALYSIS_PATH,
80    ANALYSIS_ALL
81  };
82
83  /// Mode of the analyzes while recursively visiting Decls.
84  AnalysisMode RecVisitorMode;
85  /// Bug Reporter to use while recursively visiting Decls.
86  BugReporter *RecVisitorBR;
87
88public:
89  ASTContext *Ctx;
90  const Preprocessor &PP;
91  const std::string OutDir;
92  AnalyzerOptions Opts;
93  ArrayRef<std::string> Plugins;
94
95  // PD is owned by AnalysisManager.
96  PathDiagnosticConsumer *PD;
97
98  StoreManagerCreator CreateStoreMgr;
99  ConstraintManagerCreator CreateConstraintMgr;
100
101  OwningPtr<CheckerManager> checkerMgr;
102  OwningPtr<AnalysisManager> Mgr;
103
104  /// Time the analyzes time of each translation unit.
105  static llvm::Timer* TUTotalTimer;
106
107  AnalysisConsumer(const Preprocessor& pp,
108                   const std::string& outdir,
109                   const AnalyzerOptions& opts,
110                   ArrayRef<std::string> plugins)
111    : RecVisitorMode(ANALYSIS_ALL), RecVisitorBR(0),
112      Ctx(0), PP(pp), OutDir(outdir), Opts(opts), Plugins(plugins), PD(0) {
113    DigestAnalyzerOptions();
114    if (Opts.PrintStats) {
115      llvm::EnableStatistics();
116      TUTotalTimer = new llvm::Timer("Analyzer Total Time");
117    }
118  }
119
120  ~AnalysisConsumer() {
121    if (Opts.PrintStats)
122      delete TUTotalTimer;
123  }
124
125  void DigestAnalyzerOptions() {
126    // Create the PathDiagnosticConsumer.
127    if (!OutDir.empty()) {
128      switch (Opts.AnalysisDiagOpt) {
129      default:
130#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN, AUTOCREATE) \
131        case PD_##NAME: PD = CREATEFN(OutDir, PP); break;
132#include "clang/Frontend/Analyses.def"
133      }
134    } else if (Opts.AnalysisDiagOpt == PD_TEXT) {
135      // Create the text client even without a specified output file since
136      // it just uses diagnostic notes.
137      PD = createTextPathDiagnosticConsumer("", PP);
138    }
139
140    // Create the analyzer component creators.
141    switch (Opts.AnalysisStoreOpt) {
142    default:
143      llvm_unreachable("Unknown store manager.");
144#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATEFN)           \
145      case NAME##Model: CreateStoreMgr = CREATEFN; break;
146#include "clang/Frontend/Analyses.def"
147    }
148
149    switch (Opts.AnalysisConstraintsOpt) {
150    default:
151      llvm_unreachable("Unknown store manager.");
152#define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATEFN)     \
153      case NAME##Model: CreateConstraintMgr = CREATEFN; break;
154#include "clang/Frontend/Analyses.def"
155    }
156  }
157
158  void DisplayFunction(const Decl *D, AnalysisMode Mode) {
159    if (!Opts.AnalyzerDisplayProgress)
160      return;
161
162    SourceManager &SM = Mgr->getASTContext().getSourceManager();
163    PresumedLoc Loc = SM.getPresumedLoc(D->getLocation());
164    if (Loc.isValid()) {
165      llvm::errs() << "ANALYZE";
166      switch (Mode) {
167        case ANALYSIS_SYNTAX: llvm::errs() << "(Syntax)"; break;
168        case ANALYSIS_PATH: llvm::errs() << "(Path Sensitive)"; break;
169        case ANALYSIS_ALL: break;
170      };
171      llvm::errs() << ": " << Loc.getFilename();
172      if (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)) {
173        const NamedDecl *ND = cast<NamedDecl>(D);
174        llvm::errs() << ' ' << *ND << '\n';
175      }
176      else if (isa<BlockDecl>(D)) {
177        llvm::errs() << ' ' << "block(line:" << Loc.getLine() << ",col:"
178                     << Loc.getColumn() << '\n';
179      }
180      else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
181        Selector S = MD->getSelector();
182        llvm::errs() << ' ' << S.getAsString();
183      }
184    }
185  }
186
187  virtual void Initialize(ASTContext &Context) {
188    Ctx = &Context;
189    checkerMgr.reset(createCheckerManager(Opts, PP.getLangOpts(), Plugins,
190                                          PP.getDiagnostics()));
191    Mgr.reset(new AnalysisManager(*Ctx, PP.getDiagnostics(),
192                                  PP.getLangOpts(), PD,
193                                  CreateStoreMgr, CreateConstraintMgr,
194                                  checkerMgr.get(),
195                                  /* Indexer */ 0,
196                                  Opts.MaxNodes, Opts.MaxLoop,
197                                  Opts.VisualizeEGDot, Opts.VisualizeEGUbi,
198                                  Opts.AnalysisPurgeOpt, Opts.EagerlyAssume,
199                                  Opts.TrimGraph,
200                                  Opts.UnoptimizedCFG, Opts.CFGAddImplicitDtors,
201                                  Opts.CFGAddInitializers,
202                                  Opts.EagerlyTrimEGraph,
203                                  Opts.IPAMode,
204                                  Opts.InlineMaxStackDepth,
205                                  Opts.InlineMaxFunctionSize,
206                                  Opts.InliningMode));
207  }
208
209  virtual void HandleTranslationUnit(ASTContext &C);
210
211  /// \brief Build the call graph for the TU and use it to define the order
212  /// in which the functions should be visited.
213  void HandleDeclsGallGraph(TranslationUnitDecl *TU);
214
215  /// \brief Run analyzes(syntax or path sensitive) on the given function.
216  /// \param Mode - determines if we are requesting syntax only or path
217  /// sensitive only analysis.
218  /// \param VisitedCallees - The output parameter, which is populated with the
219  /// set of functions which should be considered analyzed after analyzing the
220  /// given root function.
221  void HandleCode(Decl *D, AnalysisMode Mode, SetOfDecls *VisitedCallees = 0);
222
223  /// \brief Check if we should skip (not analyze) the given function.
224  bool skipFunction(Decl *D);
225
226  void RunPathSensitiveChecks(Decl *D, SetOfDecls *VisitedCallees);
227  void ActionExprEngine(Decl *D, bool ObjCGCEnabled, SetOfDecls *VisitedCallees);
228
229  /// Visitors for the RecursiveASTVisitor.
230
231  /// Handle callbacks for arbitrary Decls.
232  bool VisitDecl(Decl *D) {
233    checkerMgr->runCheckersOnASTDecl(D, *Mgr, *RecVisitorBR);
234    return true;
235  }
236
237  bool VisitFunctionDecl(FunctionDecl *FD) {
238    IdentifierInfo *II = FD->getIdentifier();
239    if (II && II->getName().startswith("__inline"))
240      return true;
241
242    // We skip function template definitions, as their semantics is
243    // only determined when they are instantiated.
244    if (FD->isThisDeclarationADefinition() &&
245        !FD->isDependentContext()) {
246      HandleCode(FD, RecVisitorMode);
247    }
248    return true;
249  }
250
251  bool VisitObjCMethodDecl(ObjCMethodDecl *MD) {
252    checkerMgr->runCheckersOnASTDecl(MD, *Mgr, *RecVisitorBR);
253    if (MD->isThisDeclarationADefinition())
254      HandleCode(MD, RecVisitorMode);
255    return true;
256  }
257};
258} // end anonymous namespace
259
260
261//===----------------------------------------------------------------------===//
262// AnalysisConsumer implementation.
263//===----------------------------------------------------------------------===//
264llvm::Timer* AnalysisConsumer::TUTotalTimer = 0;
265
266void AnalysisConsumer::HandleDeclsGallGraph(TranslationUnitDecl *TU) {
267  // Otherwise, use the Callgraph to derive the order.
268  // Build the Call Graph.
269  CallGraph CG;
270  CG.addToCallGraph(TU);
271
272  // Find the top level nodes - children of root + the unreachable (parentless)
273  // nodes.
274  llvm::SmallVector<CallGraphNode*, 24> TopLevelFunctions;
275  for (CallGraph::nodes_iterator TI = CG.parentless_begin(),
276                                 TE = CG.parentless_end(); TI != TE; ++TI) {
277    TopLevelFunctions.push_back(*TI);
278    NumFunctionTopLevel++;
279  }
280  CallGraphNode *Entry = CG.getRoot();
281  for (CallGraphNode::iterator I = Entry->begin(),
282                               E = Entry->end(); I != E; ++I) {
283    TopLevelFunctions.push_back(*I);
284    NumFunctionTopLevel++;
285  }
286
287  // Make sure the nodes are sorted in order reverse of their definition in the
288  // translation unit. This step is very important for performance. It ensures
289  // that we analyze the root functions before the externally available
290  // subroutines.
291  std::queue<CallGraphNode*> BFSQueue;
292  for (llvm::SmallVector<CallGraphNode*, 24>::reverse_iterator
293         TI = TopLevelFunctions.rbegin(), TE = TopLevelFunctions.rend();
294         TI != TE; ++TI)
295    BFSQueue.push(*TI);
296
297  // BFS over all of the functions, while skipping the ones inlined into
298  // the previously processed functions. Use external Visited set, which is
299  // also modified when we inline a function.
300  SmallPtrSet<CallGraphNode*,24> Visited;
301  while(!BFSQueue.empty()) {
302    CallGraphNode *N = BFSQueue.front();
303    BFSQueue.pop();
304
305    // Skip the functions which have been processed already or previously
306    // inlined.
307    if (Visited.count(N))
308      continue;
309
310    // Analyze the function.
311    SetOfDecls VisitedCallees;
312    Decl *D = N->getDecl();
313    assert(D);
314    HandleCode(D, ANALYSIS_PATH,
315               (Mgr->InliningMode == All ? 0 : &VisitedCallees));
316
317    // Add the visited callees to the global visited set.
318    for (SetOfDecls::const_iterator I = VisitedCallees.begin(),
319                                    E = VisitedCallees.end(); I != E; ++I) {
320      CallGraphNode *VN = CG.getNode(*I);
321      if (VN)
322        Visited.insert(VN);
323    }
324    Visited.insert(N);
325
326    // Push the children into the queue.
327    for (CallGraphNode::const_iterator CI = N->begin(),
328                                       CE = N->end(); CI != CE; ++CI) {
329      BFSQueue.push(*CI);
330    }
331  }
332}
333
334void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
335  // Don't run the actions if an error has occurred with parsing the file.
336  DiagnosticsEngine &Diags = PP.getDiagnostics();
337  if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred())
338    return;
339
340  {
341    if (TUTotalTimer) TUTotalTimer->startTimer();
342
343    // Introduce a scope to destroy BR before Mgr.
344    BugReporter BR(*Mgr);
345    TranslationUnitDecl *TU = C.getTranslationUnitDecl();
346    checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
347
348    // Run the AST-only checks using the order in which functions are defined.
349    // If inlining is not turned on, use the simplest function order for path
350    // sensitive analyzes as well.
351    RecVisitorMode = (Mgr->shouldInlineCall() ? ANALYSIS_SYNTAX : ANALYSIS_ALL);
352    RecVisitorBR = &BR;
353    TraverseDecl(TU);
354
355    if (Mgr->shouldInlineCall())
356      HandleDeclsGallGraph(TU);
357
358    // After all decls handled, run checkers on the entire TranslationUnit.
359    checkerMgr->runCheckersOnEndOfTranslationUnit(TU, *Mgr, BR);
360
361    RecVisitorBR = 0;
362  }
363
364  // Explicitly destroy the PathDiagnosticConsumer.  This will flush its output.
365  // FIXME: This should be replaced with something that doesn't rely on
366  // side-effects in PathDiagnosticConsumer's destructor. This is required when
367  // used with option -disable-free.
368  Mgr.reset(NULL);
369
370  if (TUTotalTimer) TUTotalTimer->stopTimer();
371}
372
373static void FindBlocks(DeclContext *D, SmallVectorImpl<Decl*> &WL) {
374  if (BlockDecl *BD = dyn_cast<BlockDecl>(D))
375    WL.push_back(BD);
376
377  for (DeclContext::decl_iterator I = D->decls_begin(), E = D->decls_end();
378       I!=E; ++I)
379    if (DeclContext *DC = dyn_cast<DeclContext>(*I))
380      FindBlocks(DC, WL);
381}
382
383static std::string getFunctionName(const Decl *D) {
384  if (const ObjCMethodDecl *ID = dyn_cast<ObjCMethodDecl>(D)) {
385    return ID->getSelector().getAsString();
386  }
387  if (const FunctionDecl *ND = dyn_cast<FunctionDecl>(D)) {
388    IdentifierInfo *II = ND->getIdentifier();
389    if (II)
390      return II->getName();
391  }
392  return "";
393}
394
395bool AnalysisConsumer::skipFunction(Decl *D) {
396  if (!Opts.AnalyzeSpecificFunction.empty() &&
397      getFunctionName(D) != Opts.AnalyzeSpecificFunction)
398    return true;
399
400  // Don't run the actions on declarations in header files unless
401  // otherwise specified.
402  SourceManager &SM = Ctx->getSourceManager();
403  SourceLocation SL = SM.getExpansionLoc(D->getLocation());
404  if (!Opts.AnalyzeAll && !SM.isFromMainFile(SL))
405    return true;
406
407  return false;
408}
409
410void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
411                                  SetOfDecls *VisitedCallees) {
412  if (skipFunction(D))
413    return;
414
415  DisplayFunction(D, Mode);
416
417  // Clear the AnalysisManager of old AnalysisDeclContexts.
418  Mgr->ClearContexts();
419
420  // Dispatch on the actions.
421  SmallVector<Decl*, 10> WL;
422  WL.push_back(D);
423
424  if (D->hasBody() && Opts.AnalyzeNestedBlocks)
425    FindBlocks(cast<DeclContext>(D), WL);
426
427  BugReporter BR(*Mgr);
428  for (SmallVectorImpl<Decl*>::iterator WI=WL.begin(), WE=WL.end();
429       WI != WE; ++WI)
430    if ((*WI)->hasBody()) {
431      if (Mode != ANALYSIS_PATH)
432        checkerMgr->runCheckersOnASTBody(*WI, *Mgr, BR);
433      if (Mode != ANALYSIS_SYNTAX && checkerMgr->hasPathSensitiveCheckers()) {
434        RunPathSensitiveChecks(*WI, VisitedCallees);
435        NumFunctionsAnalyzed++;
436      }
437    }
438}
439
440//===----------------------------------------------------------------------===//
441// Path-sensitive checking.
442//===----------------------------------------------------------------------===//
443
444void AnalysisConsumer::ActionExprEngine(Decl *D, bool ObjCGCEnabled,
445                                        SetOfDecls *VisitedCallees) {
446  // Construct the analysis engine.  First check if the CFG is valid.
447  // FIXME: Inter-procedural analysis will need to handle invalid CFGs.
448  if (!Mgr->getCFG(D))
449    return;
450
451  ExprEngine Eng(*Mgr, ObjCGCEnabled, VisitedCallees);
452
453  // Set the graph auditor.
454  OwningPtr<ExplodedNode::Auditor> Auditor;
455  if (Mgr->shouldVisualizeUbigraph()) {
456    Auditor.reset(CreateUbiViz());
457    ExplodedNode::SetAuditor(Auditor.get());
458  }
459
460  // Execute the worklist algorithm.
461  Eng.ExecuteWorkList(Mgr->getAnalysisDeclContextManager().getStackFrame(D, 0),
462                      Mgr->getMaxNodes());
463
464  // Release the auditor (if any) so that it doesn't monitor the graph
465  // created BugReporter.
466  ExplodedNode::SetAuditor(0);
467
468  // Visualize the exploded graph.
469  if (Mgr->shouldVisualizeGraphviz())
470    Eng.ViewGraph(Mgr->shouldTrimGraph());
471
472  // Display warnings.
473  Eng.getBugReporter().FlushReports();
474}
475
476void AnalysisConsumer::RunPathSensitiveChecks(Decl *D, SetOfDecls *Visited) {
477
478  switch (Mgr->getLangOpts().getGC()) {
479  case LangOptions::NonGC:
480    ActionExprEngine(D, false, Visited);
481    break;
482
483  case LangOptions::GCOnly:
484    ActionExprEngine(D, true, Visited);
485    break;
486
487  case LangOptions::HybridGC:
488    ActionExprEngine(D, false, Visited);
489    ActionExprEngine(D, true, Visited);
490    break;
491  }
492}
493
494//===----------------------------------------------------------------------===//
495// AnalysisConsumer creation.
496//===----------------------------------------------------------------------===//
497
498ASTConsumer* ento::CreateAnalysisConsumer(const Preprocessor& pp,
499                                          const std::string& outDir,
500                                          const AnalyzerOptions& opts,
501                                          ArrayRef<std::string> plugins) {
502  // Disable the effects of '-Werror' when using the AnalysisConsumer.
503  pp.getDiagnostics().setWarningsAsErrors(false);
504
505  return new AnalysisConsumer(pp, outDir, opts, plugins);
506}
507
508//===----------------------------------------------------------------------===//
509// Ubigraph Visualization.  FIXME: Move to separate file.
510//===----------------------------------------------------------------------===//
511
512namespace {
513
514class UbigraphViz : public ExplodedNode::Auditor {
515  OwningPtr<raw_ostream> Out;
516  llvm::sys::Path Dir, Filename;
517  unsigned Cntr;
518
519  typedef llvm::DenseMap<void*,unsigned> VMap;
520  VMap M;
521
522public:
523  UbigraphViz(raw_ostream *out, llvm::sys::Path& dir,
524              llvm::sys::Path& filename);
525
526  ~UbigraphViz();
527
528  virtual void AddEdge(ExplodedNode *Src, ExplodedNode *Dst);
529};
530
531} // end anonymous namespace
532
533static ExplodedNode::Auditor* CreateUbiViz() {
534  std::string ErrMsg;
535
536  llvm::sys::Path Dir = llvm::sys::Path::GetTemporaryDirectory(&ErrMsg);
537  if (!ErrMsg.empty())
538    return 0;
539
540  llvm::sys::Path Filename = Dir;
541  Filename.appendComponent("llvm_ubi");
542  Filename.makeUnique(true,&ErrMsg);
543
544  if (!ErrMsg.empty())
545    return 0;
546
547  llvm::errs() << "Writing '" << Filename.str() << "'.\n";
548
549  OwningPtr<llvm::raw_fd_ostream> Stream;
550  Stream.reset(new llvm::raw_fd_ostream(Filename.c_str(), ErrMsg));
551
552  if (!ErrMsg.empty())
553    return 0;
554
555  return new UbigraphViz(Stream.take(), Dir, Filename);
556}
557
558void UbigraphViz::AddEdge(ExplodedNode *Src, ExplodedNode *Dst) {
559
560  assert (Src != Dst && "Self-edges are not allowed.");
561
562  // Lookup the Src.  If it is a new node, it's a root.
563  VMap::iterator SrcI= M.find(Src);
564  unsigned SrcID;
565
566  if (SrcI == M.end()) {
567    M[Src] = SrcID = Cntr++;
568    *Out << "('vertex', " << SrcID << ", ('color','#00ff00'))\n";
569  }
570  else
571    SrcID = SrcI->second;
572
573  // Lookup the Dst.
574  VMap::iterator DstI= M.find(Dst);
575  unsigned DstID;
576
577  if (DstI == M.end()) {
578    M[Dst] = DstID = Cntr++;
579    *Out << "('vertex', " << DstID << ")\n";
580  }
581  else {
582    // We have hit DstID before.  Change its style to reflect a cache hit.
583    DstID = DstI->second;
584    *Out << "('change_vertex_style', " << DstID << ", 1)\n";
585  }
586
587  // Add the edge.
588  *Out << "('edge', " << SrcID << ", " << DstID
589       << ", ('arrow','true'), ('oriented', 'true'))\n";
590}
591
592UbigraphViz::UbigraphViz(raw_ostream *out, llvm::sys::Path& dir,
593                         llvm::sys::Path& filename)
594  : Out(out), Dir(dir), Filename(filename), Cntr(0) {
595
596  *Out << "('vertex_style_attribute', 0, ('shape', 'icosahedron'))\n";
597  *Out << "('vertex_style', 1, 0, ('shape', 'sphere'), ('color', '#ffcc66'),"
598          " ('size', '1.5'))\n";
599}
600
601UbigraphViz::~UbigraphViz() {
602  Out.reset(0);
603  llvm::errs() << "Running 'ubiviz' program... ";
604  std::string ErrMsg;
605  llvm::sys::Path Ubiviz = llvm::sys::Program::FindProgramByName("ubiviz");
606  std::vector<const char*> args;
607  args.push_back(Ubiviz.c_str());
608  args.push_back(Filename.c_str());
609  args.push_back(0);
610
611  if (llvm::sys::Program::ExecuteAndWait(Ubiviz, &args[0],0,0,0,0,&ErrMsg)) {
612    llvm::errs() << "Error viewing graph: " << ErrMsg << "\n";
613  }
614
615  // Delete the directory.
616  Dir.eraseFromDisk(true);
617}
618