AnalysisConsumer.cpp revision 5903a373db3d27794c90b25687e0dd6adb0e497d
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                                  Opts.RetryExhausted));
208  }
209
210  virtual void HandleTranslationUnit(ASTContext &C);
211
212  /// \brief Build the call graph for the TU and use it to define the order
213  /// in which the functions should be visited.
214  void HandleDeclsGallGraph(TranslationUnitDecl *TU);
215
216  /// \brief Run analyzes(syntax or path sensitive) on the given function.
217  /// \param Mode - determines if we are requesting syntax only or path
218  /// sensitive only analysis.
219  /// \param VisitedCallees - The output parameter, which is populated with the
220  /// set of functions which should be considered analyzed after analyzing the
221  /// given root function.
222  void HandleCode(Decl *D, AnalysisMode Mode, SetOfDecls *VisitedCallees = 0);
223
224  /// \brief Check if we should skip (not analyze) the given function.
225  bool skipFunction(Decl *D);
226
227  void RunPathSensitiveChecks(Decl *D, SetOfDecls *VisitedCallees);
228  void ActionExprEngine(Decl *D, bool ObjCGCEnabled, SetOfDecls *VisitedCallees);
229
230  /// Visitors for the RecursiveASTVisitor.
231
232  /// Handle callbacks for arbitrary Decls.
233  bool VisitDecl(Decl *D) {
234    checkerMgr->runCheckersOnASTDecl(D, *Mgr, *RecVisitorBR);
235    return true;
236  }
237
238  bool VisitFunctionDecl(FunctionDecl *FD) {
239    IdentifierInfo *II = FD->getIdentifier();
240    if (II && II->getName().startswith("__inline"))
241      return true;
242
243    // We skip function template definitions, as their semantics is
244    // only determined when they are instantiated.
245    if (FD->isThisDeclarationADefinition() &&
246        !FD->isDependentContext()) {
247      HandleCode(FD, RecVisitorMode);
248    }
249    return true;
250  }
251
252  bool VisitObjCMethodDecl(ObjCMethodDecl *MD) {
253    checkerMgr->runCheckersOnASTDecl(MD, *Mgr, *RecVisitorBR);
254    if (MD->isThisDeclarationADefinition())
255      HandleCode(MD, RecVisitorMode);
256    return true;
257  }
258};
259} // end anonymous namespace
260
261
262//===----------------------------------------------------------------------===//
263// AnalysisConsumer implementation.
264//===----------------------------------------------------------------------===//
265llvm::Timer* AnalysisConsumer::TUTotalTimer = 0;
266
267void AnalysisConsumer::HandleDeclsGallGraph(TranslationUnitDecl *TU) {
268  // Otherwise, use the Callgraph to derive the order.
269  // Build the Call Graph.
270  CallGraph CG;
271  CG.addToCallGraph(TU);
272
273  // Find the top level nodes - children of root + the unreachable (parentless)
274  // nodes.
275  llvm::SmallVector<CallGraphNode*, 24> TopLevelFunctions;
276  for (CallGraph::nodes_iterator TI = CG.parentless_begin(),
277                                 TE = CG.parentless_end(); TI != TE; ++TI) {
278    TopLevelFunctions.push_back(*TI);
279    NumFunctionTopLevel++;
280  }
281  CallGraphNode *Entry = CG.getRoot();
282  for (CallGraphNode::iterator I = Entry->begin(),
283                               E = Entry->end(); I != E; ++I) {
284    TopLevelFunctions.push_back(*I);
285    NumFunctionTopLevel++;
286  }
287
288  // Make sure the nodes are sorted in order reverse of their definition in the
289  // translation unit. This step is very important for performance. It ensures
290  // that we analyze the root functions before the externally available
291  // subroutines.
292  std::queue<CallGraphNode*> BFSQueue;
293  for (llvm::SmallVector<CallGraphNode*, 24>::reverse_iterator
294         TI = TopLevelFunctions.rbegin(), TE = TopLevelFunctions.rend();
295         TI != TE; ++TI)
296    BFSQueue.push(*TI);
297
298  // BFS over all of the functions, while skipping the ones inlined into
299  // the previously processed functions. Use external Visited set, which is
300  // also modified when we inline a function.
301  SmallPtrSet<CallGraphNode*,24> Visited;
302  while(!BFSQueue.empty()) {
303    CallGraphNode *N = BFSQueue.front();
304    BFSQueue.pop();
305
306    // Skip the functions which have been processed already or previously
307    // inlined.
308    if (Visited.count(N))
309      continue;
310
311    // Analyze the function.
312    SetOfDecls VisitedCallees;
313    Decl *D = N->getDecl();
314    assert(D);
315    HandleCode(D, ANALYSIS_PATH,
316               (Mgr->InliningMode == All ? 0 : &VisitedCallees));
317
318    // Add the visited callees to the global visited set.
319    for (SetOfDecls::const_iterator I = VisitedCallees.begin(),
320                                    E = VisitedCallees.end(); I != E; ++I) {
321      CallGraphNode *VN = CG.getNode(*I);
322      if (VN)
323        Visited.insert(VN);
324    }
325    Visited.insert(N);
326
327    // Push the children into the queue.
328    for (CallGraphNode::const_iterator CI = N->begin(),
329                                       CE = N->end(); CI != CE; ++CI) {
330      BFSQueue.push(*CI);
331    }
332  }
333}
334
335void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
336  // Don't run the actions if an error has occurred with parsing the file.
337  DiagnosticsEngine &Diags = PP.getDiagnostics();
338  if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred())
339    return;
340
341  {
342    if (TUTotalTimer) TUTotalTimer->startTimer();
343
344    // Introduce a scope to destroy BR before Mgr.
345    BugReporter BR(*Mgr);
346    TranslationUnitDecl *TU = C.getTranslationUnitDecl();
347    checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
348
349    // Run the AST-only checks using the order in which functions are defined.
350    // If inlining is not turned on, use the simplest function order for path
351    // sensitive analyzes as well.
352    RecVisitorMode = (Mgr->shouldInlineCall() ? ANALYSIS_SYNTAX : ANALYSIS_ALL);
353    RecVisitorBR = &BR;
354    TraverseDecl(TU);
355
356    if (Mgr->shouldInlineCall())
357      HandleDeclsGallGraph(TU);
358
359    // After all decls handled, run checkers on the entire TranslationUnit.
360    checkerMgr->runCheckersOnEndOfTranslationUnit(TU, *Mgr, BR);
361
362    RecVisitorBR = 0;
363  }
364
365  // Explicitly destroy the PathDiagnosticConsumer.  This will flush its output.
366  // FIXME: This should be replaced with something that doesn't rely on
367  // side-effects in PathDiagnosticConsumer's destructor. This is required when
368  // used with option -disable-free.
369  Mgr.reset(NULL);
370
371  if (TUTotalTimer) TUTotalTimer->stopTimer();
372}
373
374static void FindBlocks(DeclContext *D, SmallVectorImpl<Decl*> &WL) {
375  if (BlockDecl *BD = dyn_cast<BlockDecl>(D))
376    WL.push_back(BD);
377
378  for (DeclContext::decl_iterator I = D->decls_begin(), E = D->decls_end();
379       I!=E; ++I)
380    if (DeclContext *DC = dyn_cast<DeclContext>(*I))
381      FindBlocks(DC, WL);
382}
383
384static std::string getFunctionName(const Decl *D) {
385  if (const ObjCMethodDecl *ID = dyn_cast<ObjCMethodDecl>(D)) {
386    return ID->getSelector().getAsString();
387  }
388  if (const FunctionDecl *ND = dyn_cast<FunctionDecl>(D)) {
389    IdentifierInfo *II = ND->getIdentifier();
390    if (II)
391      return II->getName();
392  }
393  return "";
394}
395
396bool AnalysisConsumer::skipFunction(Decl *D) {
397  if (!Opts.AnalyzeSpecificFunction.empty() &&
398      getFunctionName(D) != Opts.AnalyzeSpecificFunction)
399    return true;
400
401  // Don't run the actions on declarations in header files unless
402  // otherwise specified.
403  SourceManager &SM = Ctx->getSourceManager();
404  SourceLocation SL = SM.getExpansionLoc(D->getLocation());
405  if (!Opts.AnalyzeAll && !SM.isFromMainFile(SL))
406    return true;
407
408  return false;
409}
410
411void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
412                                  SetOfDecls *VisitedCallees) {
413  if (skipFunction(D))
414    return;
415
416  DisplayFunction(D, Mode);
417
418  // Clear the AnalysisManager of old AnalysisDeclContexts.
419  Mgr->ClearContexts();
420
421  // Dispatch on the actions.
422  SmallVector<Decl*, 10> WL;
423  WL.push_back(D);
424
425  if (D->hasBody() && Opts.AnalyzeNestedBlocks)
426    FindBlocks(cast<DeclContext>(D), WL);
427
428  BugReporter BR(*Mgr);
429  for (SmallVectorImpl<Decl*>::iterator WI=WL.begin(), WE=WL.end();
430       WI != WE; ++WI)
431    if ((*WI)->hasBody()) {
432      if (Mode != ANALYSIS_PATH)
433        checkerMgr->runCheckersOnASTBody(*WI, *Mgr, BR);
434      if (Mode != ANALYSIS_SYNTAX && checkerMgr->hasPathSensitiveCheckers()) {
435        RunPathSensitiveChecks(*WI, VisitedCallees);
436        NumFunctionsAnalyzed++;
437      }
438    }
439}
440
441//===----------------------------------------------------------------------===//
442// Path-sensitive checking.
443//===----------------------------------------------------------------------===//
444
445void AnalysisConsumer::ActionExprEngine(Decl *D, bool ObjCGCEnabled,
446                                        SetOfDecls *VisitedCallees) {
447  // Construct the analysis engine.  First check if the CFG is valid.
448  // FIXME: Inter-procedural analysis will need to handle invalid CFGs.
449  if (!Mgr->getCFG(D))
450    return;
451
452  ExprEngine Eng(*Mgr, ObjCGCEnabled, VisitedCallees);
453
454  // Set the graph auditor.
455  OwningPtr<ExplodedNode::Auditor> Auditor;
456  if (Mgr->shouldVisualizeUbigraph()) {
457    Auditor.reset(CreateUbiViz());
458    ExplodedNode::SetAuditor(Auditor.get());
459  }
460
461  // Execute the worklist algorithm.
462  Eng.ExecuteWorkList(Mgr->getAnalysisDeclContextManager().getStackFrame(D, 0),
463                      Mgr->getMaxNodes());
464
465  // Release the auditor (if any) so that it doesn't monitor the graph
466  // created BugReporter.
467  ExplodedNode::SetAuditor(0);
468
469  // Visualize the exploded graph.
470  if (Mgr->shouldVisualizeGraphviz())
471    Eng.ViewGraph(Mgr->shouldTrimGraph());
472
473  // Display warnings.
474  Eng.getBugReporter().FlushReports();
475}
476
477void AnalysisConsumer::RunPathSensitiveChecks(Decl *D, SetOfDecls *Visited) {
478
479  switch (Mgr->getLangOpts().getGC()) {
480  case LangOptions::NonGC:
481    ActionExprEngine(D, false, Visited);
482    break;
483
484  case LangOptions::GCOnly:
485    ActionExprEngine(D, true, Visited);
486    break;
487
488  case LangOptions::HybridGC:
489    ActionExprEngine(D, false, Visited);
490    ActionExprEngine(D, true, Visited);
491    break;
492  }
493}
494
495//===----------------------------------------------------------------------===//
496// AnalysisConsumer creation.
497//===----------------------------------------------------------------------===//
498
499ASTConsumer* ento::CreateAnalysisConsumer(const Preprocessor& pp,
500                                          const std::string& outDir,
501                                          const AnalyzerOptions& opts,
502                                          ArrayRef<std::string> plugins) {
503  // Disable the effects of '-Werror' when using the AnalysisConsumer.
504  pp.getDiagnostics().setWarningsAsErrors(false);
505
506  return new AnalysisConsumer(pp, outDir, opts, plugins);
507}
508
509//===----------------------------------------------------------------------===//
510// Ubigraph Visualization.  FIXME: Move to separate file.
511//===----------------------------------------------------------------------===//
512
513namespace {
514
515class UbigraphViz : public ExplodedNode::Auditor {
516  OwningPtr<raw_ostream> Out;
517  llvm::sys::Path Dir, Filename;
518  unsigned Cntr;
519
520  typedef llvm::DenseMap<void*,unsigned> VMap;
521  VMap M;
522
523public:
524  UbigraphViz(raw_ostream *out, llvm::sys::Path& dir,
525              llvm::sys::Path& filename);
526
527  ~UbigraphViz();
528
529  virtual void AddEdge(ExplodedNode *Src, ExplodedNode *Dst);
530};
531
532} // end anonymous namespace
533
534static ExplodedNode::Auditor* CreateUbiViz() {
535  std::string ErrMsg;
536
537  llvm::sys::Path Dir = llvm::sys::Path::GetTemporaryDirectory(&ErrMsg);
538  if (!ErrMsg.empty())
539    return 0;
540
541  llvm::sys::Path Filename = Dir;
542  Filename.appendComponent("llvm_ubi");
543  Filename.makeUnique(true,&ErrMsg);
544
545  if (!ErrMsg.empty())
546    return 0;
547
548  llvm::errs() << "Writing '" << Filename.str() << "'.\n";
549
550  OwningPtr<llvm::raw_fd_ostream> Stream;
551  Stream.reset(new llvm::raw_fd_ostream(Filename.c_str(), ErrMsg));
552
553  if (!ErrMsg.empty())
554    return 0;
555
556  return new UbigraphViz(Stream.take(), Dir, Filename);
557}
558
559void UbigraphViz::AddEdge(ExplodedNode *Src, ExplodedNode *Dst) {
560
561  assert (Src != Dst && "Self-edges are not allowed.");
562
563  // Lookup the Src.  If it is a new node, it's a root.
564  VMap::iterator SrcI= M.find(Src);
565  unsigned SrcID;
566
567  if (SrcI == M.end()) {
568    M[Src] = SrcID = Cntr++;
569    *Out << "('vertex', " << SrcID << ", ('color','#00ff00'))\n";
570  }
571  else
572    SrcID = SrcI->second;
573
574  // Lookup the Dst.
575  VMap::iterator DstI= M.find(Dst);
576  unsigned DstID;
577
578  if (DstI == M.end()) {
579    M[Dst] = DstID = Cntr++;
580    *Out << "('vertex', " << DstID << ")\n";
581  }
582  else {
583    // We have hit DstID before.  Change its style to reflect a cache hit.
584    DstID = DstI->second;
585    *Out << "('change_vertex_style', " << DstID << ", 1)\n";
586  }
587
588  // Add the edge.
589  *Out << "('edge', " << SrcID << ", " << DstID
590       << ", ('arrow','true'), ('oriented', 'true'))\n";
591}
592
593UbigraphViz::UbigraphViz(raw_ostream *out, llvm::sys::Path& dir,
594                         llvm::sys::Path& filename)
595  : Out(out), Dir(dir), Filename(filename), Cntr(0) {
596
597  *Out << "('vertex_style_attribute', 0, ('shape', 'icosahedron'))\n";
598  *Out << "('vertex_style', 1, 0, ('shape', 'sphere'), ('color', '#ffcc66'),"
599          " ('size', '1.5'))\n";
600}
601
602UbigraphViz::~UbigraphViz() {
603  Out.reset(0);
604  llvm::errs() << "Running 'ubiviz' program... ";
605  std::string ErrMsg;
606  llvm::sys::Path Ubiviz = llvm::sys::Program::FindProgramByName("ubiviz");
607  std::vector<const char*> args;
608  args.push_back(Ubiviz.c_str());
609  args.push_back(Filename.c_str());
610  args.push_back(0);
611
612  if (llvm::sys::Program::ExecuteAndWait(Ubiviz, &args[0],0,0,0,0,&ErrMsg)) {
613    llvm::errs() << "Error viewing graph: " << ErrMsg << "\n";
614  }
615
616  // Delete the directory.
617  Dir.eraseFromDisk(true);
618}
619