From: Daniel Dunbar Date: Thu, 29 Oct 2009 21:05:18 +0000 (+0000) Subject: Move some clang-cc errors to use diagnostics, and simplify. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8cb6562f7b7e881342bfb228204545bfc9ee51c0;p=clang Move some clang-cc errors to use diagnostics, and simplify. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85527 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticFrontendKinds.td b/include/clang/Basic/DiagnosticFrontendKinds.td index e5c73270fd..ae8b923944 100644 --- a/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/include/clang/Basic/DiagnosticFrontendKinds.td @@ -12,6 +12,7 @@ let Component = "Frontend" in { def err_fe_unknown_triple : Error< "unknown target triple '%0', please use -triple or -arch">; def err_fe_unknown_target_abi : Error<"unknown target ABI '%0'">; +def err_fe_error_opening : Error<"error opening '%0': %1">; def err_fe_error_reading : Error<"error reading '%0'">; def err_fe_error_reading_stdin : Error<"error reading stdin">; def err_fe_error_backend : Error<"error in backend: %0">, DefaultFatal; @@ -19,6 +20,8 @@ def err_fe_invalid_ast_file : Error<"invalid AST file: '%0'">, DefaultFatal; def err_fe_invalid_ast_action : Error<"invalid action for AST input">, DefaultFatal; def err_fe_invalid_code_complete_file : Error<"cannot locate code-completion file %0">, DefaultFatal; +def err_fe_dependency_file_requires_MT : Error< + "-dependency-file requires at least one -MT option">; def note_fixit_applied : Note<"FIX-IT applied suggested code changes">; def note_fixit_in_macro : Note< diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 0dc95a4555..2d05859ebc 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -106,8 +106,6 @@ static bool ResolveParsedLocation(ParsedSourceLocation &ParsedLoc, /// anything. llvm::Timer *ClangFrontendTimer = 0; -static bool HadErrors = false; - static llvm::cl::opt Verbose("v", llvm::cl::desc("Enable verbose output")); static llvm::cl::opt @@ -1853,8 +1851,8 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, Features, Context)); if (!Consumer.get()) { - fprintf(stderr, "Unexpected program action!\n"); - HadErrors = true; + PP.getDiagnostics().Report(FullSourceLoc(), + diag::err_fe_invalid_ast_action); return; } @@ -2165,11 +2163,9 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, // handles. Also, we don't want to try to erase an open file. OS.reset(); - if ((HadErrors || (PP.getDiagnostics().getNumErrors() != 0)) && - !OutPath.isEmpty()) { - // If we had errors, try to erase the output file. + // If we had errors, try to erase the output file. + if (PP.getDiagnostics().getNumErrors() && !OutPath.isEmpty()) OutPath.eraseFromDisk(); - } } /// ProcessInputFile - Process a single AST input file with the specified state. @@ -2224,11 +2220,9 @@ static void ProcessASTInputFile(const std::string &InFile, ProgActions PA, // handles. Also, we don't want to try to erase an open file. OS.reset(); - if ((HadErrors || (PP.getDiagnostics().getNumErrors() != 0)) && - !OutPath.isEmpty()) { - // If we had errors, try to erase the output file. + // If we had errors, try to erase the output file. + if (PP.getDiagnostics().getNumErrors() && !OutPath.isEmpty()) OutPath.eraseFromDisk(); - } } static llvm::cl::list @@ -2290,9 +2284,9 @@ int main(int argc, char **argv) { if (MessageLength.getNumOccurrences() == 0) MessageLength.setValue(llvm::sys::Process::StandardErrColumns()); - if (!NoColorDiagnostic) { - NoColorDiagnostic.setValue(!llvm::sys::Process::StandardErrHasColors()); - } + // Disable color diagnostics if not supported on stderr. + if (!NoColorDiagnostic && !llvm::sys::Process::StandardErrHasColors()) + NoColorDiagnostic.setValue(true); DiagClient.reset(new TextDiagnosticPrinter(llvm::errs(), !NoShowColumn, @@ -2397,26 +2391,21 @@ int main(int argc, char **argv) { *SourceMgr.get(), HeaderInfo); llvm::OwningPtr PP(PPFactory.CreatePreprocessor()); - if (!PP) continue; - // Handle generating dependencies, if requested + // Handle generating dependencies, if requested. if (!DependencyFile.empty()) { - llvm::raw_ostream *DependencyOS; if (DependencyTargets.empty()) { - // FIXME: Use a proper diagnostic - llvm::errs() << "-dependency-file requires at least one -MT option\n"; - HadErrors = true; + Diags.Report(FullSourceLoc(), diag::err_fe_dependency_file_requires_MT); continue; } std::string ErrStr; - DependencyOS = + llvm::raw_ostream *DependencyOS = new llvm::raw_fd_ostream(DependencyFile.c_str(), ErrStr); if (!ErrStr.empty()) { - // FIXME: Use a proper diagnostic - llvm::errs() << "unable to open dependency file: " + ErrStr; - HadErrors = true; + Diags.Report(FullSourceLoc(), diag::err_fe_error_opening) + << DependencyFile << ErrStr; continue; } @@ -2465,5 +2454,5 @@ int main(int argc, char **argv) { // -time-passes usable. llvm::llvm_shutdown(); - return HadErrors || (Diags.getNumErrors() != 0); + return (Diags.getNumErrors() != 0); }