aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Basic/DiagnosticFrontendKinds.td2
-rw-r--r--include/clang/Frontend/CompilerInstance.h4
-rw-r--r--lib/Frontend/CompilerInstance.cpp6
-rw-r--r--lib/Frontend/FrontendActions.cpp51
4 files changed, 48 insertions, 15 deletions
diff --git a/include/clang/Basic/DiagnosticFrontendKinds.td b/include/clang/Basic/DiagnosticFrontendKinds.td
index 835f57b13b..c7033561c1 100644
--- a/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -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">;
diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h
index 007006d493..27153b63c8 100644
--- a/include/clang/Frontend/CompilerInstance.h
+++ b/include/clang/Frontend/CompilerInstance.h
@@ -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 = "",
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp
index b6c79fb7bc..f36a56032b 100644
--- a/lib/Frontend/CompilerInstance.cpp
+++ b/lib/Frontend/CompilerInstance.cpp
@@ -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
diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp
index 27e194e6f1..e3c313a422 100644
--- a/lib/Frontend/FrontendActions.cpp
+++ b/lib/Frontend/FrontendActions.cpp
@@ -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);
}