forked from OSchip/llvm-project
parent
b14bd53e6d
commit
dae941a6c8
|
@ -641,7 +641,7 @@ public:
|
|||
/// renamed to \p OutputPath in the end.
|
||||
///
|
||||
/// \param OutputPath - If given, the path to the output file.
|
||||
/// \param Error [out] - On failure, the error message.
|
||||
/// \param Error [out] - On failure, the error.
|
||||
/// \param BaseInput - If \p OutputPath is empty, the input path name to use
|
||||
/// for deriving the output path.
|
||||
/// \param Extension - The extension to use for derived output names.
|
||||
|
@ -658,13 +658,10 @@ public:
|
|||
/// \param TempPathName [out] - If given, the temporary file path name
|
||||
/// will be stored here on success.
|
||||
static llvm::raw_fd_ostream *
|
||||
createOutputFile(StringRef OutputPath, std::string &Error,
|
||||
bool Binary, bool RemoveFileOnSignal,
|
||||
StringRef BaseInput,
|
||||
StringRef Extension,
|
||||
bool UseTemporary,
|
||||
bool CreateMissingDirectories,
|
||||
std::string *ResultPathName,
|
||||
createOutputFile(StringRef OutputPath, std::error_code &Error, bool Binary,
|
||||
bool RemoveFileOnSignal, StringRef BaseInput,
|
||||
StringRef Extension, bool UseTemporary,
|
||||
bool CreateMissingDirectories, std::string *ResultPathName,
|
||||
std::string *TempPathName);
|
||||
|
||||
llvm::raw_null_ostream *createNullOutputFile();
|
||||
|
|
|
@ -122,11 +122,11 @@ bool FileRemapper::flushToDisk(StringRef outputDir, DiagnosticsEngine &Diag) {
|
|||
bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
|
||||
using namespace llvm::sys;
|
||||
|
||||
std::string errMsg;
|
||||
std::error_code EC;
|
||||
std::string infoFile = outputPath;
|
||||
llvm::raw_fd_ostream infoOut(infoFile.c_str(), errMsg, llvm::sys::fs::F_None);
|
||||
if (!errMsg.empty())
|
||||
return report(errMsg, Diag);
|
||||
llvm::raw_fd_ostream infoOut(infoFile, EC, llvm::sys::fs::F_None);
|
||||
if (EC)
|
||||
return report(EC.message(), Diag);
|
||||
|
||||
for (MappingsTy::iterator
|
||||
I = FromToMappings.begin(), E = FromToMappings.end(); I != E; ++I) {
|
||||
|
@ -179,10 +179,10 @@ bool FileRemapper::overwriteOriginal(DiagnosticsEngine &Diag,
|
|||
return report(StringRef("File does not exist: ") + origFE->getName(),
|
||||
Diag);
|
||||
|
||||
std::string errMsg;
|
||||
llvm::raw_fd_ostream Out(origFE->getName(), errMsg, llvm::sys::fs::F_None);
|
||||
if (!errMsg.empty())
|
||||
return report(errMsg, Diag);
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream Out(origFE->getName(), EC, llvm::sys::fs::F_None);
|
||||
if (EC)
|
||||
return report(EC.message(), Diag);
|
||||
|
||||
llvm::MemoryBuffer *mem = I->second.get<llvm::MemoryBuffer *>();
|
||||
Out.write(mem->getBufferStart(), mem->getBufferSize());
|
||||
|
|
|
@ -1791,12 +1791,12 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
|
|||
}
|
||||
|
||||
if (IsOutputFile) {
|
||||
std::string Error;
|
||||
llvm::raw_fd_ostream OS(MigrateDir.c_str(), Error, llvm::sys::fs::F_None);
|
||||
if (!Error.empty()) {
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream OS(MigrateDir, EC, llvm::sys::fs::F_None);
|
||||
if (EC) {
|
||||
DiagnosticsEngine &Diags = Ctx.getDiagnostics();
|
||||
Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0"))
|
||||
<< Error;
|
||||
<< EC.message();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,9 +56,9 @@ void arcmt::writeARCDiagsToPlist(const std::string &outPath,
|
|||
}
|
||||
}
|
||||
|
||||
std::string errMsg;
|
||||
llvm::raw_fd_ostream o(outPath.c_str(), errMsg, llvm::sys::fs::F_Text);
|
||||
if (!errMsg.empty()) {
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream o(outPath, EC, llvm::sys::fs::F_Text);
|
||||
if (EC) {
|
||||
llvm::errs() << "error: could not create file: " << outPath << '\n';
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -131,13 +131,13 @@ int Compilation::ExecuteCommand(const Command &C,
|
|||
// Follow gcc implementation of CC_PRINT_OPTIONS; we could also cache the
|
||||
// output stream.
|
||||
if (getDriver().CCPrintOptions && getDriver().CCPrintOptionsFilename) {
|
||||
std::string Error;
|
||||
OS = new llvm::raw_fd_ostream(getDriver().CCPrintOptionsFilename, Error,
|
||||
std::error_code EC;
|
||||
OS = new llvm::raw_fd_ostream(getDriver().CCPrintOptionsFilename, EC,
|
||||
llvm::sys::fs::F_Append |
|
||||
llvm::sys::fs::F_Text);
|
||||
if (!Error.empty()) {
|
||||
if (EC) {
|
||||
getDriver().Diag(clang::diag::err_drv_cc_print_options_failure)
|
||||
<< Error;
|
||||
<< EC.message();
|
||||
FailingCommand = &C;
|
||||
delete OS;
|
||||
return 1;
|
||||
|
|
|
@ -533,12 +533,12 @@ void Driver::generateCompilationDiagnostics(Compilation &C,
|
|||
llvm::sys::path::append(VFS, "vfs", "vfs.yaml");
|
||||
}
|
||||
|
||||
std::string Err;
|
||||
std::error_code EC;
|
||||
Script += ".sh";
|
||||
llvm::raw_fd_ostream ScriptOS(Script.c_str(), Err, llvm::sys::fs::F_Excl);
|
||||
if (!Err.empty()) {
|
||||
llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::F_Excl);
|
||||
if (EC) {
|
||||
Diag(clang::diag::note_drv_command_failed_diag_msg)
|
||||
<< "Error generating run script: " + Script + " " + Err;
|
||||
<< "Error generating run script: " + Script + " " + EC.message();
|
||||
} else {
|
||||
// Replace the original filename with the preprocessed one.
|
||||
size_t I, E;
|
||||
|
|
|
@ -134,17 +134,17 @@ void CompilerInstance::setModuleDepCollector(
|
|||
static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts,
|
||||
const CodeGenOptions *CodeGenOpts,
|
||||
DiagnosticsEngine &Diags) {
|
||||
std::string ErrorInfo;
|
||||
std::error_code EC;
|
||||
bool OwnsStream = false;
|
||||
raw_ostream *OS = &llvm::errs();
|
||||
if (DiagOpts->DiagnosticLogFile != "-") {
|
||||
// Create the output stream.
|
||||
llvm::raw_fd_ostream *FileOS(new llvm::raw_fd_ostream(
|
||||
DiagOpts->DiagnosticLogFile.c_str(), ErrorInfo,
|
||||
DiagOpts->DiagnosticLogFile, EC,
|
||||
llvm::sys::fs::F_Append | llvm::sys::fs::F_Text));
|
||||
if (!ErrorInfo.empty()) {
|
||||
if (EC) {
|
||||
Diags.Report(diag::warn_fe_cc_log_diagnostics_failure)
|
||||
<< DiagOpts->DiagnosticLogFile << ErrorInfo;
|
||||
<< DiagOpts->DiagnosticLogFile << EC.message();
|
||||
} else {
|
||||
FileOS->SetUnbuffered();
|
||||
FileOS->SetUseAtomicWrites(true);
|
||||
|
@ -164,14 +164,14 @@ static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts,
|
|||
static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts,
|
||||
DiagnosticsEngine &Diags,
|
||||
StringRef OutputFile) {
|
||||
std::string ErrorInfo;
|
||||
std::error_code EC;
|
||||
std::unique_ptr<llvm::raw_fd_ostream> OS;
|
||||
OS.reset(new llvm::raw_fd_ostream(OutputFile.str().c_str(), ErrorInfo,
|
||||
llvm::sys::fs::F_None));
|
||||
OS.reset(
|
||||
new llvm::raw_fd_ostream(OutputFile.str(), EC, llvm::sys::fs::F_None));
|
||||
|
||||
if (!ErrorInfo.empty()) {
|
||||
Diags.Report(diag::warn_fe_serialized_diag_failure)
|
||||
<< OutputFile << ErrorInfo;
|
||||
if (EC) {
|
||||
Diags.Report(diag::warn_fe_serialized_diag_failure) << OutputFile
|
||||
<< EC.message();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -573,17 +573,14 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
|
|||
StringRef Extension,
|
||||
bool UseTemporary,
|
||||
bool CreateMissingDirectories) {
|
||||
std::string Error, OutputPathName, TempPathName;
|
||||
llvm::raw_fd_ostream *OS = createOutputFile(OutputPath, Error, Binary,
|
||||
RemoveFileOnSignal,
|
||||
InFile, Extension,
|
||||
UseTemporary,
|
||||
CreateMissingDirectories,
|
||||
&OutputPathName,
|
||||
&TempPathName);
|
||||
std::string OutputPathName, TempPathName;
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream *OS = createOutputFile(
|
||||
OutputPath, EC, Binary, RemoveFileOnSignal, InFile, Extension,
|
||||
UseTemporary, CreateMissingDirectories, &OutputPathName, &TempPathName);
|
||||
if (!OS) {
|
||||
getDiagnostics().Report(diag::err_fe_unable_to_open_output)
|
||||
<< OutputPath << Error;
|
||||
getDiagnostics().Report(diag::err_fe_unable_to_open_output) << OutputPath
|
||||
<< EC.message();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -595,17 +592,11 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
|
|||
return OS;
|
||||
}
|
||||
|
||||
llvm::raw_fd_ostream *
|
||||
CompilerInstance::createOutputFile(StringRef OutputPath,
|
||||
std::string &Error,
|
||||
bool Binary,
|
||||
bool RemoveFileOnSignal,
|
||||
StringRef InFile,
|
||||
StringRef Extension,
|
||||
bool UseTemporary,
|
||||
bool CreateMissingDirectories,
|
||||
std::string *ResultPathName,
|
||||
std::string *TempPathName) {
|
||||
llvm::raw_fd_ostream *CompilerInstance::createOutputFile(
|
||||
StringRef OutputPath, std::error_code &Error, bool Binary,
|
||||
bool RemoveFileOnSignal, StringRef InFile, StringRef Extension,
|
||||
bool UseTemporary, bool CreateMissingDirectories,
|
||||
std::string *ResultPathName, std::string *TempPathName) {
|
||||
assert((!CreateMissingDirectories || UseTemporary) &&
|
||||
"CreateMissingDirectories is only allowed when using temporary files");
|
||||
|
||||
|
@ -674,9 +665,9 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
|
|||
if (!OS) {
|
||||
OSFile = OutFile;
|
||||
OS.reset(new llvm::raw_fd_ostream(
|
||||
OSFile.c_str(), Error,
|
||||
OSFile, Error,
|
||||
(Binary ? llvm::sys::fs::F_None : llvm::sys::fs::F_Text)));
|
||||
if (!Error.empty())
|
||||
if (Error)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -1136,9 +1127,8 @@ static void checkConfigMacro(Preprocessor &PP, StringRef ConfigMacro,
|
|||
|
||||
/// \brief Write a new timestamp file with the given path.
|
||||
static void writeTimestampFile(StringRef TimestampFile) {
|
||||
std::string ErrorInfo;
|
||||
llvm::raw_fd_ostream Out(TimestampFile.str().c_str(), ErrorInfo,
|
||||
llvm::sys::fs::F_None);
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream Out(TimestampFile.str(), EC, llvm::sys::fs::F_None);
|
||||
}
|
||||
|
||||
/// \brief Prune the module cache of modules that haven't been accessed in
|
||||
|
|
|
@ -297,11 +297,11 @@ void DFGImpl::OutputDependencyFile() {
|
|||
return;
|
||||
}
|
||||
|
||||
std::string Err;
|
||||
llvm::raw_fd_ostream OS(OutputFile.c_str(), Err, llvm::sys::fs::F_Text);
|
||||
if (!Err.empty()) {
|
||||
PP->getDiagnostics().Report(diag::err_fe_error_opening)
|
||||
<< OutputFile << Err;
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_Text);
|
||||
if (EC) {
|
||||
PP->getDiagnostics().Report(diag::err_fe_error_opening) << OutputFile
|
||||
<< EC.message();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,11 +96,11 @@ DependencyGraphCallback::writeNodeReference(raw_ostream &OS,
|
|||
}
|
||||
|
||||
void DependencyGraphCallback::OutputGraphFile() {
|
||||
std::string Err;
|
||||
llvm::raw_fd_ostream OS(OutputFile.c_str(), Err, llvm::sys::fs::F_Text);
|
||||
if (!Err.empty()) {
|
||||
PP->getDiagnostics().Report(diag::err_fe_error_opening)
|
||||
<< OutputFile << Err;
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_Text);
|
||||
if (EC) {
|
||||
PP->getDiagnostics().Report(diag::err_fe_error_opening) << OutputFile
|
||||
<< EC.message();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -534,9 +534,9 @@ void DumpModuleInfoAction::ExecuteAction() {
|
|||
std::unique_ptr<llvm::raw_fd_ostream> OutFile;
|
||||
StringRef OutputFileName = getCompilerInstance().getFrontendOpts().OutputFile;
|
||||
if (!OutputFileName.empty() && OutputFileName != "-") {
|
||||
std::string ErrorInfo;
|
||||
OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str().c_str(),
|
||||
ErrorInfo, llvm::sys::fs::F_Text));
|
||||
std::error_code EC;
|
||||
OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
|
||||
llvm::sys::fs::F_Text));
|
||||
}
|
||||
llvm::raw_ostream &Out = OutFile.get()? *OutFile.get() : llvm::outs();
|
||||
|
||||
|
|
|
@ -54,13 +54,12 @@ void clang::AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders,
|
|||
|
||||
// Open the output file, if used.
|
||||
if (!OutputPath.empty()) {
|
||||
std::string Error;
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream *OS = new llvm::raw_fd_ostream(
|
||||
OutputPath.str().c_str(), Error,
|
||||
llvm::sys::fs::F_Append | llvm::sys::fs::F_Text);
|
||||
if (!Error.empty()) {
|
||||
PP.getDiagnostics().Report(
|
||||
clang::diag::warn_fe_cc_print_header_failure) << Error;
|
||||
OutputPath.str(), EC, llvm::sys::fs::F_Append | llvm::sys::fs::F_Text);
|
||||
if (EC) {
|
||||
PP.getDiagnostics().Report(clang::diag::warn_fe_cc_print_header_failure)
|
||||
<< EC.message();
|
||||
delete OS;
|
||||
} else {
|
||||
OS->SetUnbuffered();
|
||||
|
|
|
@ -48,9 +48,9 @@ void ModuleDependencyCollector::writeFileMap() {
|
|||
SmallString<256> Dest = getDest();
|
||||
llvm::sys::path::append(Dest, "vfs.yaml");
|
||||
|
||||
std::string ErrorInfo;
|
||||
llvm::raw_fd_ostream OS(Dest.c_str(), ErrorInfo, llvm::sys::fs::F_Text);
|
||||
if (!ErrorInfo.empty()) {
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream OS(Dest, EC, llvm::sys::fs::F_Text);
|
||||
if (EC) {
|
||||
setHasErrors();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -86,17 +86,16 @@ bool FixItRewriter::WriteFixedFiles(
|
|||
const FileEntry *Entry = Rewrite.getSourceMgr().getFileEntryForID(I->first);
|
||||
int fd;
|
||||
std::string Filename = FixItOpts->RewriteFilename(Entry->getName(), fd);
|
||||
std::string Err;
|
||||
std::error_code EC;
|
||||
std::unique_ptr<llvm::raw_fd_ostream> OS;
|
||||
if (fd != -1) {
|
||||
OS.reset(new llvm::raw_fd_ostream(fd, /*shouldClose=*/true));
|
||||
} else {
|
||||
OS.reset(new llvm::raw_fd_ostream(Filename.c_str(), Err,
|
||||
llvm::sys::fs::F_None));
|
||||
OS.reset(new llvm::raw_fd_ostream(Filename, EC, llvm::sys::fs::F_None));
|
||||
}
|
||||
if (!Err.empty()) {
|
||||
Diags.Report(clang::diag::err_fe_unable_to_open_output)
|
||||
<< Filename << Err;
|
||||
if (EC) {
|
||||
Diags.Report(clang::diag::err_fe_unable_to_open_output) << Filename
|
||||
<< EC.message();
|
||||
continue;
|
||||
}
|
||||
RewriteBuffer &RewriteBuf = I->second;
|
||||
|
|
|
@ -3521,10 +3521,9 @@ bool ASTReader::isGlobalIndexUnavailable() const {
|
|||
static void updateModuleTimestamp(ModuleFile &MF) {
|
||||
// Overwrite the timestamp file contents so that file's mtime changes.
|
||||
std::string TimestampFilename = MF.getTimestampFilename();
|
||||
std::string ErrorInfo;
|
||||
llvm::raw_fd_ostream OS(TimestampFilename.c_str(), ErrorInfo,
|
||||
llvm::sys::fs::F_Text);
|
||||
if (!ErrorInfo.empty())
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text);
|
||||
if (EC)
|
||||
return;
|
||||
OS << "Timestamp file\n";
|
||||
}
|
||||
|
|
|
@ -338,10 +338,10 @@ void PlistDiagnostics::FlushDiagnosticsImpl(
|
|||
}
|
||||
|
||||
// Open the file.
|
||||
std::string ErrMsg;
|
||||
llvm::raw_fd_ostream o(OutputFile.c_str(), ErrMsg, llvm::sys::fs::F_Text);
|
||||
if (!ErrMsg.empty()) {
|
||||
llvm::errs() << "warning: could not create file: " << OutputFile << '\n';
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream o(OutputFile, EC, llvm::sys::fs::F_Text);
|
||||
if (EC) {
|
||||
llvm::errs() << "warning: could not create file: " << EC.message() << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// RUN: not %clang_cc1 -emit-llvm -o %S/doesnotexist/somename %s 2> %t
|
||||
// RUN: FileCheck -check-prefix=OUTPUTFAIL -input-file=%t %s
|
||||
|
||||
// OUTPUTFAIL: Error opening output file '{{.*}}doesnotexist{{.*}}'
|
||||
// OUTPUTFAIL: error: unable to open output file '{{.*}}/test/Frontend/doesnotexist/somename': 'No such file or directory'
|
||||
|
|
|
@ -262,13 +262,12 @@ static formatted_raw_ostream *GetOutputStream(AssemblerInvocation &Opts,
|
|||
if (Opts.OutputPath != "-")
|
||||
sys::RemoveFileOnSignal(Opts.OutputPath);
|
||||
|
||||
std::string Error;
|
||||
raw_fd_ostream *Out =
|
||||
new raw_fd_ostream(Opts.OutputPath.c_str(), Error,
|
||||
(Binary ? sys::fs::F_None : sys::fs::F_Text));
|
||||
if (!Error.empty()) {
|
||||
Diags.Report(diag::err_fe_unable_to_open_output)
|
||||
<< Opts.OutputPath << Error;
|
||||
std::error_code EC;
|
||||
raw_fd_ostream *Out = new raw_fd_ostream(
|
||||
Opts.OutputPath, EC, (Binary ? sys::fs::F_None : sys::fs::F_Text));
|
||||
if (EC) {
|
||||
Diags.Report(diag::err_fe_unable_to_open_output) << Opts.OutputPath
|
||||
<< EC.message();
|
||||
delete Out;
|
||||
return nullptr;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue