xref: /llvm-project/clang/lib/Frontend/CompilerInstance.cpp (revision 2083c32f7aa6dfc3af66562dd5903d3e0b9eb59e)
1 //===--- CompilerInstance.cpp ---------------------------------------------===//
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 #include "clang/Frontend/CompilerInstance.h"
11 #include "clang/Sema/Sema.h"
12 #include "clang/AST/ASTConsumer.h"
13 #include "clang/AST/ASTContext.h"
14 #include "clang/Basic/Diagnostic.h"
15 #include "clang/Basic/FileManager.h"
16 #include "clang/Basic/SourceManager.h"
17 #include "clang/Basic/TargetInfo.h"
18 #include "clang/Basic/Version.h"
19 #include "clang/Lex/HeaderSearch.h"
20 #include "clang/Lex/Preprocessor.h"
21 #include "clang/Lex/PTHManager.h"
22 #include "clang/Frontend/ChainedDiagnosticClient.h"
23 #include "clang/Frontend/FrontendAction.h"
24 #include "clang/Frontend/FrontendDiagnostic.h"
25 #include "clang/Frontend/LogDiagnosticPrinter.h"
26 #include "clang/Frontend/TextDiagnosticPrinter.h"
27 #include "clang/Frontend/VerifyDiagnosticsClient.h"
28 #include "clang/Frontend/Utils.h"
29 #include "clang/Serialization/ASTReader.h"
30 #include "clang/Sema/CodeCompleteConsumer.h"
31 #include "llvm/Support/FileSystem.h"
32 #include "llvm/Support/MemoryBuffer.h"
33 #include "llvm/Support/raw_ostream.h"
34 #include "llvm/ADT/Statistic.h"
35 #include "llvm/Support/Timer.h"
36 #include "llvm/Support/Host.h"
37 #include "llvm/Support/Path.h"
38 #include "llvm/Support/Program.h"
39 #include "llvm/Support/Signals.h"
40 #include "llvm/Support/system_error.h"
41 using namespace clang;
42 
43 CompilerInstance::CompilerInstance()
44   : Invocation(new CompilerInvocation()) {
45 }
46 
47 CompilerInstance::~CompilerInstance() {
48 }
49 
50 void CompilerInstance::setInvocation(CompilerInvocation *Value) {
51   Invocation = Value;
52 }
53 
54 void CompilerInstance::setDiagnostics(Diagnostic *Value) {
55   Diagnostics = Value;
56 }
57 
58 void CompilerInstance::setTarget(TargetInfo *Value) {
59   Target = Value;
60 }
61 
62 void CompilerInstance::setFileManager(FileManager *Value) {
63   FileMgr = Value;
64 }
65 
66 void CompilerInstance::setSourceManager(SourceManager *Value) {
67   SourceMgr = Value;
68 }
69 
70 void CompilerInstance::setPreprocessor(Preprocessor *Value) { PP = Value; }
71 
72 void CompilerInstance::setASTContext(ASTContext *Value) { Context = Value; }
73 
74 void CompilerInstance::setSema(Sema *S) {
75   TheSema.reset(S);
76 }
77 
78 void CompilerInstance::setASTConsumer(ASTConsumer *Value) {
79   Consumer.reset(Value);
80 }
81 
82 void CompilerInstance::setCodeCompletionConsumer(CodeCompleteConsumer *Value) {
83   CompletionConsumer.reset(Value);
84 }
85 
86 // Diagnostics
87 static void SetUpBuildDumpLog(const DiagnosticOptions &DiagOpts,
88                               unsigned argc, const char* const *argv,
89                               Diagnostic &Diags) {
90   std::string ErrorInfo;
91   llvm::OwningPtr<llvm::raw_ostream> OS(
92     new llvm::raw_fd_ostream(DiagOpts.DumpBuildInformation.c_str(), ErrorInfo));
93   if (!ErrorInfo.empty()) {
94     Diags.Report(diag::err_fe_unable_to_open_logfile)
95                  << DiagOpts.DumpBuildInformation << ErrorInfo;
96     return;
97   }
98 
99   (*OS) << "clang -cc1 command line arguments: ";
100   for (unsigned i = 0; i != argc; ++i)
101     (*OS) << argv[i] << ' ';
102   (*OS) << '\n';
103 
104   // Chain in a diagnostic client which will log the diagnostics.
105   DiagnosticClient *Logger =
106     new TextDiagnosticPrinter(*OS.take(), DiagOpts, /*OwnsOutputStream=*/true);
107   Diags.setClient(new ChainedDiagnosticClient(Diags.takeClient(), Logger));
108 }
109 
110 static void SetUpDiagnosticLog(const DiagnosticOptions &DiagOpts,
111                                Diagnostic &Diags) {
112   std::string ErrorInfo;
113   bool OwnsStream = false;
114   llvm::raw_ostream *OS = &llvm::errs();
115   if (DiagOpts.DiagnosticLogFile != "-") {
116     // Create the output stream.
117     llvm::raw_fd_ostream *FileOS(
118       new llvm::raw_fd_ostream(DiagOpts.DiagnosticLogFile.c_str(),
119                                ErrorInfo));
120     if (!ErrorInfo.empty()) {
121       Diags.Report(diag::warn_fe_cc_log_diagnostics_failure)
122         << DiagOpts.DumpBuildInformation << ErrorInfo;
123     } else {
124       FileOS->SetUnbuffered();
125       FileOS->SetUseAtomicWrites(true);
126       OS = FileOS;
127       OwnsStream = true;
128     }
129   }
130 
131   // Chain in the diagnostic client which will log the diagnostics.
132   DiagnosticClient *Logger = new LogDiagnosticPrinter(*OS, DiagOpts,
133                                                       OwnsStream);
134   Diags.setClient(new ChainedDiagnosticClient(Diags.takeClient(), Logger));
135 }
136 
137 void CompilerInstance::createDiagnostics(int Argc, const char* const *Argv,
138                                          DiagnosticClient *Client) {
139   Diagnostics = createDiagnostics(getDiagnosticOpts(), Argc, Argv, Client);
140 }
141 
142 llvm::IntrusiveRefCntPtr<Diagnostic>
143 CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts,
144                                     int Argc, const char* const *Argv,
145                                     DiagnosticClient *Client) {
146   llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
147   llvm::IntrusiveRefCntPtr<Diagnostic> Diags(new Diagnostic(DiagID));
148 
149   // Create the diagnostic client for reporting errors or for
150   // implementing -verify.
151   if (Client)
152     Diags->setClient(Client);
153   else
154     Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), Opts));
155 
156   // Chain in -verify checker, if requested.
157   if (Opts.VerifyDiagnostics)
158     Diags->setClient(new VerifyDiagnosticsClient(*Diags, Diags->takeClient()));
159 
160   // Chain in -diagnostic-log-file dumper, if requested.
161   if (!Opts.DiagnosticLogFile.empty())
162     SetUpDiagnosticLog(Opts, *Diags);
163 
164   if (!Opts.DumpBuildInformation.empty())
165     SetUpBuildDumpLog(Opts, Argc, Argv, *Diags);
166 
167   // Configure our handling of diagnostics.
168   ProcessWarningOptions(*Diags, Opts);
169 
170   return Diags;
171 }
172 
173 // File Manager
174 
175 void CompilerInstance::createFileManager() {
176   FileMgr = new FileManager(getFileSystemOpts());
177 }
178 
179 // Source Manager
180 
181 void CompilerInstance::createSourceManager(FileManager &FileMgr) {
182   SourceMgr = new SourceManager(getDiagnostics(), FileMgr);
183 }
184 
185 // Preprocessor
186 
187 void CompilerInstance::createPreprocessor() {
188   PP = createPreprocessor(getDiagnostics(), getLangOpts(),
189                           getPreprocessorOpts(), getHeaderSearchOpts(),
190                           getDependencyOutputOpts(), getTarget(),
191                           getFrontendOpts(), getSourceManager(),
192                           getFileManager());
193 }
194 
195 Preprocessor *
196 CompilerInstance::createPreprocessor(Diagnostic &Diags,
197                                      const LangOptions &LangInfo,
198                                      const PreprocessorOptions &PPOpts,
199                                      const HeaderSearchOptions &HSOpts,
200                                      const DependencyOutputOptions &DepOpts,
201                                      const TargetInfo &Target,
202                                      const FrontendOptions &FEOpts,
203                                      SourceManager &SourceMgr,
204                                      FileManager &FileMgr) {
205   // Create a PTH manager if we are using some form of a token cache.
206   PTHManager *PTHMgr = 0;
207   if (!PPOpts.TokenCache.empty())
208     PTHMgr = PTHManager::Create(PPOpts.TokenCache, Diags);
209 
210   // Create the Preprocessor.
211   HeaderSearch *HeaderInfo = new HeaderSearch(FileMgr);
212   Preprocessor *PP = new Preprocessor(Diags, LangInfo, Target,
213                                       SourceMgr, *HeaderInfo, PTHMgr,
214                                       /*OwnsHeaderSearch=*/true);
215 
216   // Note that this is different then passing PTHMgr to Preprocessor's ctor.
217   // That argument is used as the IdentifierInfoLookup argument to
218   // IdentifierTable's ctor.
219   if (PTHMgr) {
220     PTHMgr->setPreprocessor(PP);
221     PP->setPTHManager(PTHMgr);
222   }
223 
224   if (PPOpts.DetailedRecord)
225     PP->createPreprocessingRecord();
226 
227   InitializePreprocessor(*PP, PPOpts, HSOpts, FEOpts);
228 
229   // Handle generating dependencies, if requested.
230   if (!DepOpts.OutputFile.empty())
231     AttachDependencyFileGen(*PP, DepOpts);
232 
233   // Handle generating header include information, if requested.
234   if (DepOpts.ShowHeaderIncludes)
235     AttachHeaderIncludeGen(*PP);
236   if (!DepOpts.HeaderIncludeOutputFile.empty()) {
237     llvm::StringRef OutputPath = DepOpts.HeaderIncludeOutputFile;
238     if (OutputPath == "-")
239       OutputPath = "";
240     AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/true, OutputPath,
241                            /*ShowDepth=*/false);
242   }
243 
244   return PP;
245 }
246 
247 // ASTContext
248 
249 void CompilerInstance::createASTContext() {
250   Preprocessor &PP = getPreprocessor();
251   Context = new ASTContext(getLangOpts(), PP.getSourceManager(),
252                            getTarget(), PP.getIdentifierTable(),
253                            PP.getSelectorTable(), PP.getBuiltinInfo(),
254                            /*size_reserve=*/ 0);
255 }
256 
257 // ExternalASTSource
258 
259 void CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path,
260                                                   bool DisablePCHValidation,
261                                                   bool DisableStatCache,
262                                                  void *DeserializationListener){
263   llvm::OwningPtr<ExternalASTSource> Source;
264   bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
265   Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot,
266                                           DisablePCHValidation,
267                                           DisableStatCache,
268                                           getPreprocessor(), getASTContext(),
269                                           DeserializationListener,
270                                           Preamble));
271   getASTContext().setExternalSource(Source);
272 }
273 
274 ExternalASTSource *
275 CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path,
276                                              const std::string &Sysroot,
277                                              bool DisablePCHValidation,
278                                              bool DisableStatCache,
279                                              Preprocessor &PP,
280                                              ASTContext &Context,
281                                              void *DeserializationListener,
282                                              bool Preamble) {
283   llvm::OwningPtr<ASTReader> Reader;
284   Reader.reset(new ASTReader(PP, &Context,
285                              Sysroot.empty() ? 0 : Sysroot.c_str(),
286                              DisablePCHValidation, DisableStatCache));
287 
288   Reader->setDeserializationListener(
289             static_cast<ASTDeserializationListener *>(DeserializationListener));
290   switch (Reader->ReadAST(Path,
291                           Preamble ? ASTReader::Preamble : ASTReader::PCH)) {
292   case ASTReader::Success:
293     // Set the predefines buffer as suggested by the PCH reader. Typically, the
294     // predefines buffer will be empty.
295     PP.setPredefines(Reader->getSuggestedPredefines());
296     return Reader.take();
297 
298   case ASTReader::Failure:
299     // Unrecoverable failure: don't even try to process the input file.
300     break;
301 
302   case ASTReader::IgnorePCH:
303     // No suitable PCH file could be found. Return an error.
304     break;
305   }
306 
307   return 0;
308 }
309 
310 // Code Completion
311 
312 static bool EnableCodeCompletion(Preprocessor &PP,
313                                  const std::string &Filename,
314                                  unsigned Line,
315                                  unsigned Column) {
316   // Tell the source manager to chop off the given file at a specific
317   // line and column.
318   const FileEntry *Entry = PP.getFileManager().getFile(Filename);
319   if (!Entry) {
320     PP.getDiagnostics().Report(diag::err_fe_invalid_code_complete_file)
321       << Filename;
322     return true;
323   }
324 
325   // Truncate the named file at the given line/column.
326   PP.SetCodeCompletionPoint(Entry, Line, Column);
327   return false;
328 }
329 
330 void CompilerInstance::createCodeCompletionConsumer() {
331   const ParsedSourceLocation &Loc = getFrontendOpts().CodeCompletionAt;
332   if (!CompletionConsumer) {
333     CompletionConsumer.reset(
334       createCodeCompletionConsumer(getPreprocessor(),
335                                    Loc.FileName, Loc.Line, Loc.Column,
336                                    getFrontendOpts().ShowMacrosInCodeCompletion,
337                              getFrontendOpts().ShowCodePatternsInCodeCompletion,
338                            getFrontendOpts().ShowGlobalSymbolsInCodeCompletion,
339                                    llvm::outs()));
340     if (!CompletionConsumer)
341       return;
342   } else if (EnableCodeCompletion(getPreprocessor(), Loc.FileName,
343                                   Loc.Line, Loc.Column)) {
344     CompletionConsumer.reset();
345     return;
346   }
347 
348   if (CompletionConsumer->isOutputBinary() &&
349       llvm::sys::Program::ChangeStdoutToBinary()) {
350     getPreprocessor().getDiagnostics().Report(diag::err_fe_stdout_binary);
351     CompletionConsumer.reset();
352   }
353 }
354 
355 void CompilerInstance::createFrontendTimer() {
356   FrontendTimer.reset(new llvm::Timer("Clang front-end timer"));
357 }
358 
359 CodeCompleteConsumer *
360 CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
361                                                const std::string &Filename,
362                                                unsigned Line,
363                                                unsigned Column,
364                                                bool ShowMacros,
365                                                bool ShowCodePatterns,
366                                                bool ShowGlobals,
367                                                llvm::raw_ostream &OS) {
368   if (EnableCodeCompletion(PP, Filename, Line, Column))
369     return 0;
370 
371   // Set up the creation routine for code-completion.
372   return new PrintingCodeCompleteConsumer(ShowMacros, ShowCodePatterns,
373                                           ShowGlobals, OS);
374 }
375 
376 void CompilerInstance::createSema(bool CompleteTranslationUnit,
377                                   CodeCompleteConsumer *CompletionConsumer) {
378   TheSema.reset(new Sema(getPreprocessor(), getASTContext(), getASTConsumer(),
379                          CompleteTranslationUnit, CompletionConsumer));
380 }
381 
382 // Output Files
383 
384 void CompilerInstance::addOutputFile(const OutputFile &OutFile) {
385   assert(OutFile.OS && "Attempt to add empty stream to output list!");
386   OutputFiles.push_back(OutFile);
387 }
388 
389 void CompilerInstance::clearOutputFiles(bool EraseFiles) {
390   for (std::list<OutputFile>::iterator
391          it = OutputFiles.begin(), ie = OutputFiles.end(); it != ie; ++it) {
392     delete it->OS;
393     if (!it->TempFilename.empty()) {
394       if (EraseFiles) {
395         bool existed;
396         llvm::sys::fs::remove(it->TempFilename, existed);
397       } else {
398         llvm::SmallString<128> NewOutFile(it->Filename);
399 
400         // If '-working-directory' was passed, the output filename should be
401         // relative to that.
402         FileMgr->FixupRelativePath(NewOutFile);
403         if (llvm::error_code ec = llvm::sys::fs::rename(it->TempFilename,
404                                                         NewOutFile.str())) {
405           getDiagnostics().Report(diag::err_fe_unable_to_rename_temp)
406             << it->TempFilename << it->Filename << ec.message();
407 
408           bool existed;
409           llvm::sys::fs::remove(it->TempFilename, existed);
410         }
411       }
412     } else if (!it->Filename.empty() && EraseFiles)
413       llvm::sys::Path(it->Filename).eraseFromDisk();
414 
415   }
416   OutputFiles.clear();
417 }
418 
419 llvm::raw_fd_ostream *
420 CompilerInstance::createDefaultOutputFile(bool Binary,
421                                           llvm::StringRef InFile,
422                                           llvm::StringRef Extension) {
423   return createOutputFile(getFrontendOpts().OutputFile, Binary,
424                           /*RemoveFileOnSignal=*/true, InFile, Extension);
425 }
426 
427 llvm::raw_fd_ostream *
428 CompilerInstance::createOutputFile(llvm::StringRef OutputPath,
429                                    bool Binary, bool RemoveFileOnSignal,
430                                    llvm::StringRef InFile,
431                                    llvm::StringRef Extension) {
432   std::string Error, OutputPathName, TempPathName;
433   llvm::raw_fd_ostream *OS = createOutputFile(OutputPath, Error, Binary,
434                                               RemoveFileOnSignal,
435                                               InFile, Extension,
436                                               &OutputPathName,
437                                               &TempPathName);
438   if (!OS) {
439     getDiagnostics().Report(diag::err_fe_unable_to_open_output)
440       << OutputPath << Error;
441     return 0;
442   }
443 
444   // Add the output file -- but don't try to remove "-", since this means we are
445   // using stdin.
446   addOutputFile(OutputFile((OutputPathName != "-") ? OutputPathName : "",
447                 TempPathName, OS));
448 
449   return OS;
450 }
451 
452 llvm::raw_fd_ostream *
453 CompilerInstance::createOutputFile(llvm::StringRef OutputPath,
454                                    std::string &Error,
455                                    bool Binary,
456                                    bool RemoveFileOnSignal,
457                                    llvm::StringRef InFile,
458                                    llvm::StringRef Extension,
459                                    std::string *ResultPathName,
460                                    std::string *TempPathName) {
461   std::string OutFile, TempFile;
462   if (!OutputPath.empty()) {
463     OutFile = OutputPath;
464   } else if (InFile == "-") {
465     OutFile = "-";
466   } else if (!Extension.empty()) {
467     llvm::sys::Path Path(InFile);
468     Path.eraseSuffix();
469     Path.appendSuffix(Extension);
470     OutFile = Path.str();
471   } else {
472     OutFile = "-";
473   }
474 
475   if (OutFile != "-") {
476     llvm::sys::Path OutPath(OutFile);
477     // Only create the temporary if we can actually write to OutPath, otherwise
478     // we want to fail early.
479     bool Exists;
480     if ((llvm::sys::fs::exists(OutPath.str(), Exists) || !Exists) ||
481         (OutPath.isRegularFile() && OutPath.canWrite())) {
482       // Create a temporary file.
483       llvm::sys::Path TempPath(OutFile);
484       if (!TempPath.createTemporaryFileOnDisk())
485         TempFile = TempPath.str();
486     }
487   }
488 
489   std::string OSFile = OutFile;
490   if (!TempFile.empty())
491     OSFile = TempFile;
492 
493   llvm::OwningPtr<llvm::raw_fd_ostream> OS(
494     new llvm::raw_fd_ostream(OSFile.c_str(), Error,
495                              (Binary ? llvm::raw_fd_ostream::F_Binary : 0)));
496   if (!Error.empty())
497     return 0;
498 
499   // Make sure the out stream file gets removed if we crash.
500   if (RemoveFileOnSignal)
501     llvm::sys::RemoveFileOnSignal(llvm::sys::Path(OSFile));
502 
503   if (ResultPathName)
504     *ResultPathName = OutFile;
505   if (TempPathName)
506     *TempPathName = TempFile;
507 
508   return OS.take();
509 }
510 
511 // Initialization Utilities
512 
513 bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile) {
514   return InitializeSourceManager(InputFile, getDiagnostics(), getFileManager(),
515                                  getSourceManager(), getFrontendOpts());
516 }
517 
518 bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
519                                                Diagnostic &Diags,
520                                                FileManager &FileMgr,
521                                                SourceManager &SourceMgr,
522                                                const FrontendOptions &Opts) {
523   // Figure out where to get and map in the main file, unless it's already
524   // been created (e.g., by a precompiled preamble).
525   if (!SourceMgr.getMainFileID().isInvalid()) {
526     // Do nothing: the main file has already been set.
527   } else if (InputFile != "-") {
528     const FileEntry *File = FileMgr.getFile(InputFile);
529     if (!File) {
530       Diags.Report(diag::err_fe_error_reading) << InputFile;
531       return false;
532     }
533     SourceMgr.createMainFileID(File);
534   } else {
535     llvm::OwningPtr<llvm::MemoryBuffer> SB;
536     if (llvm::MemoryBuffer::getSTDIN(SB)) {
537       // FIXME: Give ec.message() in this diag.
538       Diags.Report(diag::err_fe_error_reading_stdin);
539       return false;
540     }
541     const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
542                                                    SB->getBufferSize(), 0);
543     SourceMgr.createMainFileID(File);
544     SourceMgr.overrideFileContents(File, SB.take());
545   }
546 
547   assert(!SourceMgr.getMainFileID().isInvalid() &&
548          "Couldn't establish MainFileID!");
549   return true;
550 }
551 
552 // High-Level Operations
553 
554 bool CompilerInstance::ExecuteAction(FrontendAction &Act) {
555   assert(hasDiagnostics() && "Diagnostics engine is not initialized!");
556   assert(!getFrontendOpts().ShowHelp && "Client must handle '-help'!");
557   assert(!getFrontendOpts().ShowVersion && "Client must handle '-version'!");
558 
559   // FIXME: Take this as an argument, once all the APIs we used have moved to
560   // taking it as an input instead of hard-coding llvm::errs.
561   llvm::raw_ostream &OS = llvm::errs();
562 
563   // Create the target instance.
564   setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), getTargetOpts()));
565   if (!hasTarget())
566     return false;
567 
568   // Inform the target of the language options.
569   //
570   // FIXME: We shouldn't need to do this, the target should be immutable once
571   // created. This complexity should be lifted elsewhere.
572   getTarget().setForcedLangOptions(getLangOpts());
573 
574   // Validate/process some options.
575   if (getHeaderSearchOpts().Verbose)
576     OS << "clang -cc1 version " CLANG_VERSION_STRING
577        << " based upon " << PACKAGE_STRING
578        << " hosted on " << llvm::sys::getHostTriple() << "\n";
579 
580   if (getFrontendOpts().ShowTimers)
581     createFrontendTimer();
582 
583   if (getFrontendOpts().ShowStats)
584     llvm::EnableStatistics();
585 
586   for (unsigned i = 0, e = getFrontendOpts().Inputs.size(); i != e; ++i) {
587     const std::string &InFile = getFrontendOpts().Inputs[i].second;
588 
589     // Reset the ID tables if we are reusing the SourceManager.
590     if (hasSourceManager())
591       getSourceManager().clearIDTables();
592 
593     if (Act.BeginSourceFile(*this, InFile, getFrontendOpts().Inputs[i].first)) {
594       Act.Execute();
595       Act.EndSourceFile();
596     }
597   }
598 
599   if (getDiagnosticOpts().ShowCarets) {
600     // We can have multiple diagnostics sharing one diagnostic client.
601     // Get the total number of warnings/errors from the client.
602     unsigned NumWarnings = getDiagnostics().getClient()->getNumWarnings();
603     unsigned NumErrors = getDiagnostics().getClient()->getNumErrors();
604 
605     if (NumWarnings)
606       OS << NumWarnings << " warning" << (NumWarnings == 1 ? "" : "s");
607     if (NumWarnings && NumErrors)
608       OS << " and ";
609     if (NumErrors)
610       OS << NumErrors << " error" << (NumErrors == 1 ? "" : "s");
611     if (NumWarnings || NumErrors)
612       OS << " generated.\n";
613   }
614 
615   if (getFrontendOpts().ShowStats && hasFileManager()) {
616     getFileManager().PrintStats();
617     OS << "\n";
618   }
619 
620   return !getDiagnostics().getClient()->getNumErrors();
621 }
622 
623 
624