Fix CompilerInstance::createOutputFile to use proper diagnostics, and (try to) update all clients to be able to handle failure.

llvm-svn: 90437
This commit is contained in:
Daniel Dunbar 2009-12-03 09:13:30 +00:00
parent 692bc47d25
commit 7554699afa
4 changed files with 48 additions and 15 deletions

View File

@ -53,6 +53,8 @@ def err_fe_pch_malformed_block : Error<
"malformed block record in PCH file: '%0'">;
def err_fe_pch_error_at_end_block : Error<
"error at end of module block in PCH file: '%0'">;
def err_fe_unable_to_open_output : Error<
"unable to to open output file '%0': '%1'">;
def err_verify_bogus_characters : Error<
"bogus characters before '{{' in expected string">;

View File

@ -482,12 +482,16 @@ public:
/// Create the default output file (from the invocation's options) and add it
/// to the list of tracked output files.
///
/// \return - Null on error.
llvm::raw_fd_ostream *
createDefaultOutputFile(bool Binary = true, llvm::StringRef BaseInput = "",
llvm::StringRef Extension = "");
/// Create a new output file and add it to the list of tracked output files,
/// optionally deriving the output path name.
///
/// \return - Null on error.
llvm::raw_fd_ostream *
createOutputFile(llvm::StringRef OutputPath, bool Binary = true,
llvm::StringRef BaseInput = "",

View File

@ -328,9 +328,9 @@ CompilerInstance::createOutputFile(llvm::StringRef OutputPath,
InFile, Extension,
&OutputPathName);
if (!OS) {
// FIXME: Don't fail this way.
llvm::errs() << "error: " << Error << "\n";
::exit(1);
getDiagnostics().Report(diag::err_fe_unable_to_open_output)
<< OutputPath << Error;
return 0;
}
// Add the output file -- but don't try to remove "-", since this means we are

View File

@ -35,13 +35,16 @@ ASTConsumer *AnalysisAction::CreateASTConsumer(CompilerInstance &CI,
ASTConsumer *ASTPrintAction::CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef InFile) {
return CreateASTPrinter(CI.createDefaultOutputFile(false, InFile));
if (llvm::raw_ostream *OS = CI.createDefaultOutputFile(false, InFile))
return CreateASTPrinter(OS);
return 0;
}
ASTConsumer *ASTPrintXMLAction::CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef InFile) {
return CreateASTPrinterXML(CI.createDefaultOutputFile(false, InFile,
"xml"));
if (llvm::raw_ostream *OS = CI.createDefaultOutputFile(false, InFile, "xml"))
return CreateASTPrinterXML(OS);
return 0;
}
ASTConsumer *ASTDumpAction::CreateASTConsumer(CompilerInstance &CI,
@ -74,6 +77,9 @@ ASTConsumer *GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI,
}
llvm::raw_ostream *OS = CI.createDefaultOutputFile(true, InFile);
if (!OS)
return 0;
if (CI.getFrontendOpts().RelocatablePCH)
return CreatePCHGenerator(CI.getPreprocessor(), OS, Sysroot.c_str());
@ -82,8 +88,9 @@ ASTConsumer *GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI,
ASTConsumer *HTMLPrintAction::CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef InFile) {
return CreateHTMLPrinter(CI.createDefaultOutputFile(false, InFile),
CI.getPreprocessor());
if (llvm::raw_ostream *OS = CI.createDefaultOutputFile(false, InFile))
return CreateHTMLPrinter(OS, CI.getPreprocessor());
return 0;
}
ASTConsumer *InheritanceViewAction::CreateASTConsumer(CompilerInstance &CI,
@ -140,10 +147,11 @@ void FixItAction::EndSourceFileAction() {
ASTConsumer *RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef InFile) {
return CreateObjCRewriter(InFile,
CI.createDefaultOutputFile(true, InFile, "cpp"),
CI.getDiagnostics(), CI.getLangOpts(),
CI.getDiagnosticOpts().NoRewriteMacros);
if (llvm::raw_ostream *OS = CI.createDefaultOutputFile(false, InFile, "cpp"))
return CreateObjCRewriter(InFile, OS,
CI.getDiagnostics(), CI.getLangOpts(),
CI.getDiagnosticOpts().NoRewriteMacros);
return 0;
}
ASTConsumer *RewriteBlocksAction::CreateASTConsumer(CompilerInstance &CI,
@ -162,12 +170,21 @@ ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef InFile) {
BackendAction BA = static_cast<BackendAction>(Act);
llvm::OwningPtr<llvm::raw_ostream> OS;
if (BA == Backend_EmitAssembly)
switch (BA) {
case Backend_EmitAssembly:
OS.reset(CI.createDefaultOutputFile(false, InFile, "s"));
else if (BA == Backend_EmitLL)
break;
case Backend_EmitLL:
OS.reset(CI.createDefaultOutputFile(false, InFile, "ll"));
else if (BA == Backend_EmitBC)
break;
case Backend_EmitBC:
OS.reset(CI.createDefaultOutputFile(true, InFile, "bc"));
break;
case Backend_EmitNothing:
break;
}
if (BA != Backend_EmitNothing && !OS)
return 0;
return CreateBackendConsumer(BA, CI.getDiagnostics(), CI.getLangOpts(),
CI.getCodeGenOpts(), CI.getTargetOpts(),
@ -228,6 +245,8 @@ void GeneratePTHAction::ExecuteAction() {
}
llvm::raw_fd_ostream *OS =
CI.createDefaultOutputFile(true, getCurrentFile());
if (!OS) return;
CacheTokens(CI.getPreprocessor(), OS);
}
@ -255,6 +274,8 @@ void PrintParseAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
Preprocessor &PP = getCompilerInstance().getPreprocessor();
llvm::raw_ostream *OS = CI.createDefaultOutputFile(false, getCurrentFile());
if (!OS) return;
llvm::OwningPtr<Action> PA(CreatePrintParserActionsAction(PP, OS));
Parser P(PP, *PA);
@ -265,6 +286,8 @@ void PrintParseAction::ExecuteAction() {
void PrintPreprocessedAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
llvm::raw_ostream *OS = CI.createDefaultOutputFile(false, getCurrentFile());
if (!OS) return;
DoPrintPreprocessedInput(CI.getPreprocessor(), OS,
CI.getPreprocessorOutputOpts());
}
@ -272,11 +295,15 @@ void PrintPreprocessedAction::ExecuteAction() {
void RewriteMacrosAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
llvm::raw_ostream *OS = CI.createDefaultOutputFile(true, getCurrentFile());
if (!OS) return;
RewriteMacrosInInput(CI.getPreprocessor(), OS);
}
void RewriteTestAction::ExecuteAction() {
CompilerInstance &CI = getCompilerInstance();
llvm::raw_ostream *OS = CI.createDefaultOutputFile(false, getCurrentFile());
if (!OS) return;
DoRewriteTest(CI.getPreprocessor(), OS);
}