summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/BrainF/BrainFDriver.cpp5
-rw-r--r--include/llvm/Analysis/DOTGraphTraitsPass.h12
-rw-r--r--include/llvm/Support/ToolOutputFile.h14
-rw-r--r--include/llvm/Support/raw_ostream.h11
-rw-r--r--lib/Analysis/CFGPrinter.cpp16
-rw-r--r--lib/Bitcode/Writer/BitWriter.cpp6
-rw-r--r--lib/CodeGen/MachineVerifier.cpp9
-rw-r--r--lib/CodeGen/RegAllocPBQP.cpp4
-rw-r--r--lib/IR/Core.cpp16
-rw-r--r--lib/IR/GCOV.cpp10
-rw-r--r--lib/LTO/LTOCodeGenerator.cpp6
-rw-r--r--lib/MC/MCParser/DarwinAsmParser.cpp8
-rw-r--r--lib/Support/Timer.cpp8
-rw-r--r--lib/Support/ToolOutputFile.cpp15
-rw-r--r--lib/Support/raw_ostream.cpp16
-rw-r--r--lib/TableGen/Main.cpp20
-rw-r--r--lib/Target/TargetMachineC.cpp8
-rw-r--r--lib/Transforms/Instrumentation/DebugIR.cpp4
-rw-r--r--lib/Transforms/Instrumentation/GCOVProfiling.cpp5
-rw-r--r--tools/bugpoint/OptimizerDriver.cpp10
-rw-r--r--tools/gold/gold-plugin.cpp14
-rw-r--r--tools/llc/llc.cpp9
-rw-r--r--tools/lli/lli.cpp4
-rw-r--r--tools/llvm-as/llvm-as.cpp8
-rw-r--r--tools/llvm-dis/llvm-dis.cpp8
-rw-r--r--tools/llvm-extract/llvm-extract.cpp8
-rw-r--r--tools/llvm-link/llvm-link.cpp8
-rw-r--r--tools/llvm-lto/llvm-lto.cpp8
-rw-r--r--tools/llvm-mc/llvm-mc.cpp8
-rw-r--r--tools/llvm-objdump/llvm-objdump.cpp16
-rw-r--r--tools/llvm-profdata/llvm-profdata.cpp16
-rw-r--r--tools/llvm-stress/llvm-stress.cpp9
-rw-r--r--tools/opt/opt.cpp18
-rw-r--r--tools/verify-uselistorder/verify-uselistorder.cpp16
-rw-r--r--tools/yaml2obj/yaml2obj.cpp8
-rw-r--r--unittests/Support/Path.cpp12
36 files changed, 181 insertions, 192 deletions
diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp
index 9b1f0d3f118..5820f1d0d09 100644
--- a/examples/BrainF/BrainFDriver.cpp
+++ b/examples/BrainF/BrainFDriver.cpp
@@ -107,9 +107,8 @@ int main(int argc, char **argv) {
OutputFilename = base+".bc";
}
if (OutputFilename != "-") {
- std::string ErrInfo;
- out = new raw_fd_ostream(OutputFilename.c_str(), ErrInfo,
- sys::fs::F_None);
+ std::error_code EC;
+ out = new raw_fd_ostream(OutputFilename, EC, sys::fs::F_None);
}
}
diff --git a/include/llvm/Analysis/DOTGraphTraitsPass.h b/include/llvm/Analysis/DOTGraphTraitsPass.h
index 53c832cbebe..cb74e9f32d3 100644
--- a/include/llvm/Analysis/DOTGraphTraitsPass.h
+++ b/include/llvm/Analysis/DOTGraphTraitsPass.h
@@ -66,15 +66,15 @@ public:
bool runOnFunction(Function &F) override {
GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>());
std::string Filename = Name + "." + F.getName().str() + ".dot";
- std::string ErrorInfo;
+ std::error_code EC;
errs() << "Writing '" << Filename << "'...";
- raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
+ raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
std::string GraphName = DOTGraphTraits<GraphT>::getGraphName(Graph);
std::string Title = GraphName + " for '" + F.getName().str() + "' function";
- if (ErrorInfo.empty())
+ if (!EC)
WriteGraph(File, Graph, IsSimple, Title);
else
errs() << " error opening file for writing!";
@@ -129,14 +129,14 @@ public:
bool runOnModule(Module &M) override {
GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>());
std::string Filename = Name + ".dot";
- std::string ErrorInfo;
+ std::error_code EC;
errs() << "Writing '" << Filename << "'...";
- raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
+ raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
std::string Title = DOTGraphTraits<GraphT>::getGraphName(Graph);
- if (ErrorInfo.empty())
+ if (!EC)
WriteGraph(File, Graph, IsSimple, Title);
else
errs() << " error opening file for writing!";
diff --git a/include/llvm/Support/ToolOutputFile.h b/include/llvm/Support/ToolOutputFile.h
index 88f8ccc292d..d98e7bbd51d 100644
--- a/include/llvm/Support/ToolOutputFile.h
+++ b/include/llvm/Support/ToolOutputFile.h
@@ -29,13 +29,13 @@ class tool_output_file {
/// destructed after the raw_fd_ostream is destructed. It installs
/// cleanups in its constructor and uninstalls them in its destructor.
class CleanupInstaller {
- /// Filename - The name of the file.
+ /// The name of the file.
std::string Filename;
public:
- /// Keep - The flag which indicates whether we should not delete the file.
+ /// The flag which indicates whether we should not delete the file.
bool Keep;
- explicit CleanupInstaller(const char *filename);
+ explicit CleanupInstaller(StringRef ilename);
~CleanupInstaller();
} Installer;
@@ -44,12 +44,12 @@ class tool_output_file {
raw_fd_ostream OS;
public:
- /// tool_output_file - This constructor's arguments are passed to
- /// to raw_fd_ostream's constructor.
- tool_output_file(const char *filename, std::string &ErrorInfo,
+ /// This constructor's arguments are passed to to raw_fd_ostream's
+ /// constructor.
+ tool_output_file(StringRef Filename, std::error_code &EC,
sys::fs::OpenFlags Flags);
- tool_output_file(const char *Filename, int FD);
+ tool_output_file(StringRef Filename, int FD);
/// os - Return the contained raw_fd_ostream.
raw_fd_ostream &os() { return OS; }
diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h
index 34fbe082cda..6966e9a10d4 100644
--- a/include/llvm/Support/raw_ostream.h
+++ b/include/llvm/Support/raw_ostream.h
@@ -17,6 +17,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"
+#include <system_error>
namespace llvm {
class format_object_base;
@@ -341,17 +342,17 @@ class raw_fd_ostream : public raw_ostream {
void error_detected() { Error = true; }
public:
- /// raw_fd_ostream - Open the specified file for writing. If an error occurs,
- /// information about the error is put into ErrorInfo, and the stream should
- /// be immediately destroyed; the string will be empty if no error occurred.
- /// This allows optional flags to control how the file will be opened.
+ /// Open the specified file for writing. If an error occurs, information
+ /// about the error is put into EC, and the stream should be immediately
+ /// destroyed;
+ /// \p Flags allows optional flags to control how the file will be opened.
///
/// As a special case, if Filename is "-", then the stream will use
/// STDOUT_FILENO instead of opening a file. Note that it will still consider
/// itself to own the file descriptor. In particular, it will close the
/// file descriptor when it is done (this is necessary to detect
/// output errors).
- raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
+ raw_fd_ostream(StringRef Filename, std::error_code &EC,
sys::fs::OpenFlags Flags);
/// raw_fd_ostream ctor - FD is the file descriptor that this writes to. If
diff --git a/lib/Analysis/CFGPrinter.cpp b/lib/Analysis/CFGPrinter.cpp
index c2c19d6a69e..89787f826be 100644
--- a/lib/Analysis/CFGPrinter.cpp
+++ b/lib/Analysis/CFGPrinter.cpp
@@ -79,11 +79,11 @@ namespace {
bool runOnFunction(Function &F) override {
std::string Filename = "cfg." + F.getName().str() + ".dot";
errs() << "Writing '" << Filename << "'...";
-
- std::string ErrorInfo;
- raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
- if (ErrorInfo.empty())
+ std::error_code EC;
+ raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
+
+ if (!EC)
WriteGraph(File, (const Function*)&F);
else
errs() << " error opening file for writing!";
@@ -114,10 +114,10 @@ namespace {
std::string Filename = "cfg." + F.getName().str() + ".dot";
errs() << "Writing '" << Filename << "'...";
- std::string ErrorInfo;
- raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
-
- if (ErrorInfo.empty())
+ std::error_code EC;
+ raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
+
+ if (!EC)
WriteGraph(File, (const Function*)&F, true);
else
errs() << " error opening file for writing!";
diff --git a/lib/Bitcode/Writer/BitWriter.cpp b/lib/Bitcode/Writer/BitWriter.cpp
index 3747122fc98..6c9f7b3276f 100644
--- a/lib/Bitcode/Writer/BitWriter.cpp
+++ b/lib/Bitcode/Writer/BitWriter.cpp
@@ -18,10 +18,10 @@ using namespace llvm;
/*===-- Operations on modules ---------------------------------------------===*/
int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
- std::string ErrorInfo;
- raw_fd_ostream OS(Path, ErrorInfo, sys::fs::F_None);
+ std::error_code EC;
+ raw_fd_ostream OS(Path, EC, sys::fs::F_None);
- if (!ErrorInfo.empty())
+ if (EC)
return -1;
WriteBitcodeToFile(unwrap(M), OS);
diff --git a/lib/CodeGen/MachineVerifier.cpp b/lib/CodeGen/MachineVerifier.cpp
index e08766d292f..a1d83320089 100644
--- a/lib/CodeGen/MachineVerifier.cpp
+++ b/lib/CodeGen/MachineVerifier.cpp
@@ -276,11 +276,12 @@ void MachineFunction::verify(Pass *p, const char *Banner) const {
bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) {
raw_ostream *OutFile = nullptr;
if (OutFileName) {
- std::string ErrorInfo;
- OutFile = new raw_fd_ostream(OutFileName, ErrorInfo,
+ std::error_code EC;
+ OutFile = new raw_fd_ostream(OutFileName, EC,
sys::fs::F_Append | sys::fs::F_Text);
- if (!ErrorInfo.empty()) {
- errs() << "Error opening '" << OutFileName << "': " << ErrorInfo << '\n';
+ if (EC) {
+ errs() << "Error opening '" << OutFileName << "': " << EC.message()
+ << '\n';
exit(1);
}
diff --git a/lib/CodeGen/RegAllocPBQP.cpp b/lib/CodeGen/RegAllocPBQP.cpp
index 3e6988e2149..80f129f46e8 100644
--- a/lib/CodeGen/RegAllocPBQP.cpp
+++ b/lib/CodeGen/RegAllocPBQP.cpp
@@ -587,8 +587,8 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
std::ostringstream rs;
rs << round;
std::string graphFileName(fqn + "." + rs.str() + ".pbqpgraph");
- std::string tmp;
- raw_fd_ostream os(graphFileName.c_str(), tmp, sys::fs::F_Text);
+ std::error_code EC;
+ raw_fd_ostream os(graphFileName, EC, sys::fs::F_Text);
DEBUG(dbgs() << "Dumping graph for round " << round << " to \""
<< graphFileName << "\"\n");
problem->getGraph().dump(os);
diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp
index 2b2ccb96cc2..d81533b20c2 100644
--- a/lib/IR/Core.cpp
+++ b/lib/IR/Core.cpp
@@ -183,20 +183,22 @@ void LLVMDumpModule(LLVMModuleRef M) {
LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
char **ErrorMessage) {
- std::string error;
- raw_fd_ostream dest(Filename, error, sys::fs::F_Text);
- if (!error.empty()) {
- *ErrorMessage = strdup(error.c_str());
+ std::error_code EC;
+ raw_fd_ostream dest(Filename, EC, sys::fs::F_Text);
+ if (EC) {
+ *ErrorMessage = strdup(EC.message().c_str());
return true;
}
unwrap(M)->print(dest, nullptr);
- if (!error.empty()) {
- *ErrorMessage = strdup(error.c_str());
+ dest.close();
+
+ if (dest.has_error()) {
+ *ErrorMessage = strdup("Error printing to file");
return true;
}
- dest.flush();
+
return false;
}
diff --git a/lib/IR/GCOV.cpp b/lib/IR/GCOV.cpp
index 1667401f88d..566c5b9d59d 100644
--- a/lib/IR/GCOV.cpp
+++ b/lib/IR/GCOV.cpp
@@ -517,11 +517,11 @@ FileInfo::openCoveragePath(StringRef CoveragePath) {
if (Options.NoOutput)
return llvm::make_unique<raw_null_ostream>();
- std::string ErrorInfo;
- auto OS = llvm::make_unique<raw_fd_ostream>(CoveragePath.str().c_str(),
- ErrorInfo, sys::fs::F_Text);
- if (!ErrorInfo.empty()) {
- errs() << ErrorInfo << "\n";
+ std::error_code EC;
+ auto OS = llvm::make_unique<raw_fd_ostream>(CoveragePath.str(), EC,
+ sys::fs::F_Text);
+ if (EC) {
+ errs() << EC.message() << "\n";
return llvm::make_unique<raw_null_ostream>();
}
return std::move(OS);
diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp
index 34cd79c2a6e..54f5a6b4c50 100644
--- a/lib/LTO/LTOCodeGenerator.cpp
+++ b/lib/LTO/LTOCodeGenerator.cpp
@@ -163,9 +163,9 @@ bool LTOCodeGenerator::writeMergedModules(const char *path,
applyScopeRestrictions();
// create output file
- std::string ErrInfo;
- tool_output_file Out(path, ErrInfo, sys::fs::F_None);
- if (!ErrInfo.empty()) {
+ std::error_code EC;
+ tool_output_file Out(path, EC, sys::fs::F_None);
+ if (EC) {
errMsg = "could not open bitcode file for writing: ";
errMsg += path;
return false;
diff --git a/lib/MC/MCParser/DarwinAsmParser.cpp b/lib/MC/MCParser/DarwinAsmParser.cpp
index b2a67856da0..3ea745eba57 100644
--- a/lib/MC/MCParser/DarwinAsmParser.cpp
+++ b/lib/MC/MCParser/DarwinAsmParser.cpp
@@ -638,13 +638,13 @@ bool DarwinAsmParser::parseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
// Open the secure log file if we haven't already.
raw_ostream *OS = getContext().getSecureLog();
if (!OS) {
- std::string Err;
- OS = new raw_fd_ostream(SecureLogFile, Err,
+ std::error_code EC;
+ OS = new raw_fd_ostream(SecureLogFile, EC,
sys::fs::F_Append | sys::fs::F_Text);
- if (!Err.empty()) {
+ if (EC) {
delete OS;
return Error(IDLoc, Twine("can't open secure log file: ") +
- SecureLogFile + " (" + Err + ")");
+ SecureLogFile + " (" + EC.message() + ")");
}
getContext().setSecureLog(OS);
}
diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp
index 210bda754e7..e1a531a0af2 100644
--- a/lib/Support/Timer.cpp
+++ b/lib/Support/Timer.cpp
@@ -66,10 +66,10 @@ raw_ostream *llvm::CreateInfoOutputFile() {
// each time -stats or -time-passes wants to print output to it. To
// compensate for this, the test-suite Makefiles have code to delete the
// info output file before running commands which write to it.
- std::string Error;
- raw_ostream *Result = new raw_fd_ostream(
- OutputFilename.c_str(), Error, sys::fs::F_Append | sys::fs::F_Text);
- if (Error.empty())
+ std::error_code EC;
+ raw_ostream *Result = new raw_fd_ostream(OutputFilename, EC,
+ sys::fs::F_Append | sys::fs::F_Text);
+ if (!EC)
return Result;
errs() << "Error opening info-output-file '"
diff --git a/lib/Support/ToolOutputFile.cpp b/lib/Support/ToolOutputFile.cpp
index b5fb20f4b20..8ae977db6a1 100644
--- a/lib/Support/ToolOutputFile.cpp
+++ b/lib/Support/ToolOutputFile.cpp
@@ -16,8 +16,8 @@
#include "llvm/Support/Signals.h"
using namespace llvm;
-tool_output_file::CleanupInstaller::CleanupInstaller(const char *filename)
- : Filename(filename), Keep(false) {
+tool_output_file::CleanupInstaller::CleanupInstaller(StringRef Filename)
+ : Filename(Filename), Keep(false) {
// Arrange for the file to be deleted if the process is killed.
if (Filename != "-")
sys::RemoveFileOnSignal(Filename);
@@ -34,14 +34,13 @@ tool_output_file::CleanupInstaller::~CleanupInstaller() {
sys::DontRemoveFileOnSignal(Filename);
}
-tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo,
+tool_output_file::tool_output_file(StringRef Filename, std::error_code &EC,
sys::fs::OpenFlags Flags)
- : Installer(filename), OS(filename, ErrorInfo, Flags) {
+ : Installer(Filename), OS(Filename, EC, Flags) {
// If open fails, no cleanup is needed.
- if (!ErrorInfo.empty())
+ if (EC)
Installer.Keep = true;
}
-tool_output_file::tool_output_file(const char *Filename, int FD)
- : Installer(Filename), OS(FD, true) {
-}
+tool_output_file::tool_output_file(StringRef Filename, int FD)
+ : Installer(Filename), OS(FD, true) {}
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 0790be5305e..c2be517a6ad 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -426,20 +426,14 @@ void format_object_base::home() {
// raw_fd_ostream
//===----------------------------------------------------------------------===//
-/// raw_fd_ostream - Open the specified file for writing. If an error
-/// occurs, information about the error is put into ErrorInfo, and the
-/// stream should be immediately destroyed; the string will be empty
-/// if no error occurred.
-raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
+raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC,
sys::fs::OpenFlags Flags)
: Error(false), UseAtomicWrites(false), pos(0) {
- assert(Filename && "Filename is null");
- ErrorInfo.clear();
-
+ EC = std::error_code();
// Handle "-" as stdout. Note that when we do this, we consider ourself
// the owner of stdout. This means that we can do things like close the
// file descriptor when we're done and set the "binary" flag globally.
- if (Filename[0] == '-' && Filename[1] == 0) {
+ if (Filename == "-") {
FD = STDOUT_FILENO;
// If user requested binary then put stdout into binary mode if
// possible.
@@ -450,11 +444,9 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
return;
}
- std::error_code EC = sys::fs::openFileForWrite(Filename, FD, Flags);
+ EC = sys::fs::openFileForWrite(Filename, FD, Flags);
if (EC) {
- ErrorInfo = "Error opening output file '" + std::string(Filename) + "': " +
- EC.message();
ShouldClose = false;
return;
}
diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp
index d9c5601a5da..2578cc20357 100644
--- a/lib/TableGen/Main.cpp
+++ b/lib/TableGen/Main.cpp
@@ -56,11 +56,11 @@ static int createDependencyFile(const TGParser &Parser, const char *argv0) {
errs() << argv0 << ": the option -d must be used together with -o\n";
return 1;
}
- std::string Error;
- tool_output_file DepOut(DependFilename.c_str(), Error, sys::fs::F_Text);
- if (!Error.empty()) {
- errs() << argv0 << ": error opening " << DependFilename
- << ":" << Error << "\n";
+ std::error_code EC;
+ tool_output_file DepOut(DependFilename, EC, sys::fs::F_Text);
+ if (EC) {
+ errs() << argv0 << ": error opening " << DependFilename << ":"
+ << EC.message() << "\n";
return 1;
}
DepOut.os() << OutputFilename << ":";
@@ -101,11 +101,11 @@ int TableGenMain(char *argv0, TableGenMainFn *MainFn) {
if (Parser.ParseFile())
return 1;
- std::string Error;
- tool_output_file Out(OutputFilename.c_str(), Error, sys::fs::F_Text);
- if (!Error.empty()) {
- errs() << argv0 << ": error opening " << OutputFilename
- << ":" << Error << "\n";
+ std::error_code EC;
+ tool_output_file Out(OutputFilename, EC, sys::fs::F_Text);
+ if (EC) {
+ errs() << argv0 << ": error opening " << OutputFilename << ":"
+ << EC.message() << "\n";
return 1;
}
if (!DependFilename.empty()) {
diff --git a/lib/Target/TargetMachineC.cpp b/lib/Target/TargetMachineC.cpp
index 702b915c6cd..598783b1be1 100644
--- a/lib/Target/TargetMachineC.cpp
+++ b/lib/Target/TargetMachineC.cpp
@@ -223,10 +223,10 @@ static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M,
LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
char* Filename, LLVMCodeGenFileType codegen, char** ErrorMessage) {
- std::string error;
- raw_fd_ostream dest(Filename, error, sys::fs::F_None);
- if (!error.empty()) {
- *ErrorMessage = strdup(error.c_str());
+ std::error_code EC;
+ raw_fd_ostream dest(Filename, EC, sys::fs::F_None);
+ if (EC) {
+ *ErrorMessage = strdup(EC.message().c_str());
return true;
}
formatted_raw_ostream destf(dest);
diff --git a/lib/Transforms/Instrumentation/DebugIR.cpp b/lib/Transforms/Instrumentation/DebugIR.cpp
index f416339c6ad..5234341b32e 100644
--- a/lib/Transforms/Instrumentation/DebugIR.cpp
+++ b/lib/Transforms/Instrumentation/DebugIR.cpp
@@ -525,11 +525,11 @@ std::string DebugIR::getPath() {
void DebugIR::writeDebugBitcode(const Module *M, int *fd) {
std::unique_ptr<raw_fd_ostream> Out;
- std::string error;
+ std::error_code EC;
if (!fd) {
std::string Path = getPath();
- Out.reset(new raw_fd_ostream(Path.c_str(), error, sys::fs::F_Text));
+ Out.reset(new raw_fd_ostream(Path, EC, sys::fs::F_Text));
DEBUG(dbgs() << "WRITING debug bitcode from Module " << M << " to file "
<< Path << "\n");
} else {
diff --git a/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index cfeb62eb1f9..a1f42a8c3a4 100644
--- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -480,9 +480,8 @@ void GCOVProfiler::emitProfileNotes() {
// LTO, we'll generate the same .gcno files.
DICompileUnit CU(CU_Nodes->getOperand(i));
- std::string ErrorInfo;
- raw_fd_ostream out(mangleName(CU, "gcno").c_str(), ErrorInfo,
- sys::fs::F_None);
+ std::error_code EC;
+ raw_fd_ostream out(mangleName(CU, "gcno"), EC, sys::fs::F_None);
std::string EdgeDestinations;
DIArray SPs = CU.getSubprograms();
diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp
index d452fd94c06..c75f82f17dc 100644
--- a/tools/bugpoint/OptimizerDriver.cpp
+++ b/tools/bugpoint/OptimizerDriver.cpp
@@ -66,15 +66,15 @@ static bool writeProgramToFileAux(tool_output_file &Out, const Module *M) {
bool BugDriver::writeProgramToFile(const std::string &Filename, int FD,
const Module *M) const {
- tool_output_file Out(Filename.c_str(), FD);
+ tool_output_file Out(Filename, FD);
return writeProgramToFileAux(Out, M);
}
bool BugDriver::writeProgramToFile(const std::string &Filename,
const Module *M) const {
- std::string ErrInfo;
- tool_output_file Out(Filename.c_str(), ErrInfo, sys::fs::F_None);
- if (ErrInfo.empty())
+ std::error_code EC;
+ tool_output_file Out(Filename, EC, sys::fs::F_None);
+ if (!EC)
return writeProgramToFileAux(Out, M);
return true;
}
@@ -149,7 +149,7 @@ bool BugDriver::runPasses(Module *Program,
return 1;
}
- tool_output_file InFile(InputFilename.c_str(), InputFD);
+ tool_output_file InFile(InputFilename, InputFD);
WriteBitcodeToFile(Program, InFile.os());
InFile.os().close();
diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp
index 8ca2628e85a..55151e0352b 100644
--- a/tools/gold/gold-plugin.cpp
+++ b/tools/gold/gold-plugin.cpp
@@ -775,9 +775,9 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) {
else
path = output_name + ".bc";
{
- std::string Error;
- raw_fd_ostream OS(path.c_str(), Error, sys::fs::OpenFlags::F_None);
- if (!Error.empty())
+ std::error_code EC;
+ raw_fd_ostream OS(path, EC, sys::fs::OpenFlags::F_None);
+ if (EC)
message(LDPL_FATAL, "Failed to write the output file.");
WriteBitcodeToFile(L.getModule(), OS);
}
@@ -799,11 +799,11 @@ static ld_plugin_status all_symbols_read_hook(void) {
if (!options::generate_api_file) {
Ret = allSymbolsReadHook(nullptr);
} else {
- std::string Error;
- raw_fd_ostream ApiFile("apifile.txt", Error, sys::fs::F_None);
- if (!Error.empty())
+ std::error_code EC;
+ raw_fd_ostream ApiFile("apifile.txt", EC, sys::fs::F_None);
+ if (EC)
message(LDPL_FATAL, "Unable to open apifile.txt for writing: %s",
- Error.c_str());
+ EC.message().c_str());
Ret = allSymbolsReadHook(&ApiFile);
}
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index 01196d5c819..aef86b22ce0 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -159,14 +159,13 @@ static tool_output_file *GetOutputStream(const char *TargetName,
}
// Open the file.
- std::string error;
+ std::error_code EC;
sys::fs::OpenFlags OpenFlags = sys::fs::F_None;
if (!Binary)
OpenFlags |= sys::fs::F_Text;
- tool_output_file *FDOut = new tool_output_file(OutputFilename.c_str(), error,
- OpenFlags);
- if (!error.empty()) {
- errs() << error << '\n';
+ tool_output_file *FDOut = new tool_output_file(OutputFilename, EC, OpenFlags);
+ if (EC) {
+ errs() << EC.message() << '\n';
delete FDOut;
return nullptr;
}
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
index 3cf81cafe2f..993d1fafb82 100644
--- a/tools/lli/lli.cpp
+++ b/tools/lli/lli.cpp
@@ -268,13 +268,13 @@ public:
std::string CacheName;
if (!getCacheFilename(ModuleID, CacheName))
return;
- std::string errStr;
if (!CacheDir.empty()) { // Create user-defined cache dir.
SmallString<128> dir(CacheName);
sys::path::remove_filename(dir);
sys::fs::create_directories(Twine(dir));
}
- raw_fd_ostream outfile(CacheName.c_str(), errStr, sys::fs::F_None);
+ std::error_code EC;
+ raw_fd_ostream outfile(CacheName, EC, sys::fs::F_None);
outfile.write(Obj.getBufferStart(), Obj.getBufferSize());
outfile.close();
}
diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp
index ef4f7ba272a..5ccf505923f 100644
--- a/tools/llvm-as/llvm-as.cpp
+++ b/tools/llvm-as/llvm-as.cpp
@@ -69,11 +69,11 @@ static void WriteOutputFile(const Module *M) {
}
}
- std::string ErrorInfo;
+ std::error_code EC;
std::unique_ptr<tool_output_file> Out(
- new tool_output_file(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
- if (!ErrorInfo.empty()) {
- errs() << ErrorInfo << '\n';
+ new tool_output_file(OutputFilename, EC, sys::fs::F_None));
+ if (EC) {
+ errs() << EC.message() << '\n';
exit(1);
}
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index 3b0f838f1d7..fb737173761 100644
--- a/tools/llvm-dis/llvm-dis.cpp
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -171,11 +171,11 @@ int main(int argc, char **argv) {
}
}
- std::string ErrorInfo;
+ std::error_code EC;
std::unique_ptr<tool_output_file> Out(
- new tool_output_file(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
- if (!ErrorInfo.empty()) {
- errs() << ErrorInfo << '\n';
+ new tool_output_file(OutputFilename, EC, sys::fs::F_None));
+ if (EC) {
+ errs() << EC.message() << '\n';
return 1;
}
diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp
index 0f7086802a4..e36945641a4 100644
--- a/tools/llvm-extract/llvm-extract.cpp
+++ b/tools/llvm-extract/llvm-extract.cpp
@@ -261,10 +261,10 @@ int main(int argc, char **argv) {
Passes.add(createStripDeadDebugInfoPass()); // Remove dead debug info
Passes.add(createStripDeadPrototypesPass()); // Remove dead func decls
- std::string ErrorInfo;
- tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None);
- if (!ErrorInfo.empty()) {
- errs() << ErrorInfo << '\n';
+ std::error_code EC;
+ tool_output_file Out(OutputFilename, EC, sys::fs::F_None);
+ if (EC) {
+ errs() << EC.message() << '\n';
return 1;
}
diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp
index ed8c06e7984..9e217201a72 100644
--- a/tools/llvm-link/llvm-link.cpp
+++ b/tools/llvm-link/llvm-link.cpp
@@ -110,10 +110,10 @@ int main(int argc, char **argv) {
if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
- std::string ErrorInfo;
- tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None);
- if (!ErrorInfo.empty()) {
- errs() << ErrorInfo << '\n';
+ std::error_code EC;
+ tool_output_file Out(OutputFilename, EC, sys::fs::F_None);
+ if (EC) {
+ errs() << EC.message() << '\n';
return 1;
}
diff --git a/tools/llvm-lto/llvm-lto.cpp b/tools/llvm-lto/llvm-lto.cpp
index 8b39f1285f5..2f19090dfc9 100644
--- a/tools/llvm-lto/llvm-lto.cpp
+++ b/tools/llvm-lto/llvm-lto.cpp
@@ -165,11 +165,11 @@ int main(int argc, char **argv) {
return 1;
}
- raw_fd_ostream FileStream(OutputFilename.c_str(), ErrorInfo,
- sys::fs::F_None);
- if (!ErrorInfo.empty()) {
+ std::error_code EC;
+ raw_fd_ostream FileStream(OutputFilename, EC, sys::fs::F_None);
+ if (EC) {
errs() << argv[0] << ": error opening the file '" << OutputFilename
- << "': " << ErrorInfo << "\n";
+ << "': " << EC.message() << "\n";
return 1;
}
diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp
index 42cde6e16f4..61d1d9960d0 100644
--- a/tools/llvm-mc/llvm-mc.cpp
+++ b/tools/llvm-mc/llvm-mc.cpp
@@ -208,11 +208,11 @@ static tool_output_file *GetOutputStream() {
if (OutputFilename == "")
OutputFilename = "-";
- std::string Err;
+ std::error_code EC;
tool_output_file *Out =
- new tool_output_file(OutputFilename.c_str(), Err, sys::fs::F_None);
- if (!Err.empty()) {
- errs() << Err << '\n';
+ new tool_output_file(OutputFilename, EC, sys::fs::F_None);
+ if (EC) {
+ errs() << EC.message() << '\n';
delete Out;
return nullptr;
}
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index 259d00118a3..d23bfec54ca 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -202,10 +202,10 @@ static const Target *getTarget(const ObjectFile *Obj = nullptr) {
static void emitDOTFile(const char *FileName, const MCFunction &f,
MCInstPrinter *IP) {
// Start a new dot file.
- std::string Error;
- raw_fd_ostream Out(FileName, Error, sys::fs::F_Text);
- if (!Error.empty()) {
- errs() << "llvm-objdump: warning: " << Error << '\n';
+ std::error_code EC;
+ raw_fd_ostream Out(FileName, EC, sys::fs::F_Text);
+ if (EC) {
+ errs() << "llvm-objdump: warning: " << EC.message() << '\n';
return;
}
@@ -386,10 +386,10 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
}
}
if (!YAMLCFG.empty()) {
- std::string Error;
- raw_fd_ostream YAMLOut(YAMLCFG.c_str(), Error, sys::fs::F_Text);
- if (!Error.empty()) {
- errs() << ToolName << ": warning: " << Error << '\n';
+ std::error_code EC;
+ raw_fd_ostream YAMLOut(YAMLCFG, EC, sys::fs::F_Text);
+ if (EC) {
+ errs() << ToolName << ": warning: " << EC.message() << '\n';
return;
}
mcmodule2yaml(YAMLOut, *Mod, *MII, *MRI);
diff --git a/tools/llvm-profdata/llvm-profdata.cpp b/tools/llvm-profdata/llvm-profdata.cpp
index 49ad37eeed3..3229d4da5d6 100644
--- a/tools/llvm-profdata/llvm-profdata.cpp
+++ b/tools/llvm-profdata/llvm-profdata.cpp
@@ -48,10 +48,10 @@ int merge_main(int argc, const char *argv[]) {
if (OutputFilename.compare("-") == 0)
exitWithError("Cannot write indexed profdata format to stdout.");
- std::string ErrorInfo;
- raw_fd_ostream Output(OutputFilename.data(), ErrorInfo, sys::fs::F_None);
- if (!ErrorInfo.empty())
- exitWithError(ErrorInfo, OutputFilename);
+ std::error_code EC;
+ raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::F_None);
+ if (EC)
+ exitWithError(EC.message(), OutputFilename);
InstrProfWriter Writer;
for (const auto &Filename : Inputs) {
@@ -97,10 +97,10 @@ int show_main(int argc, const char *argv[]) {
if (OutputFilename.empty())
OutputFilename = "-";
- std::string ErrorInfo;
- raw_fd_ostream OS(OutputFilename.data(), ErrorInfo, sys::fs::F_Text);
- if (!ErrorInfo.empty())
- exitWithError(ErrorInfo, OutputFilename);
+ std::error_code EC;
+ raw_fd_ostream OS(OutputFilename.data(), EC, sys::fs::F_Text);
+ if (EC)
+ exitWithError(EC.message(), OutputFilename);
if (ShowAllFunctions && !ShowFunction.empty())
errs() << "warning: -function argument ignored: showing all functions\n";
diff --git a/tools/llvm-stress/llvm-stress.cpp b/tools/llvm-stress/llvm-stress.cpp
index 23d3b636b19..21a79e3294a 100644
--- a/tools/llvm-stress/llvm-stress.cpp
+++ b/tools/llvm-stress/llvm-stress.cpp
@@ -704,11 +704,10 @@ int main(int argc, char **argv) {
if (OutputFilename.empty())
OutputFilename = "-";
- std::string ErrorInfo;
- Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
- sys::fs::F_None));
- if (!ErrorInfo.empty()) {
- errs() << ErrorInfo << '\n';
+ std::error_code EC;
+ Out.reset(new tool_output_file(OutputFilename, EC, sys::fs::F_None));
+ if (EC) {
+ errs() << EC.message() << '\n';
return 1;
}
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index abcf6910b28..d6b450d03ed 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -385,11 +385,10 @@ int main(int argc, char **argv) {
if (OutputFilename.empty())
OutputFilename = "-";
- std::string ErrorInfo;
- Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
- sys::fs::F_None));
- if (!ErrorInfo.empty()) {
- errs() << ErrorInfo << '\n';
+ std::error_code EC;
+ Out.reset(new tool_output_file(OutputFilename, EC, sys::fs::F_None));
+ if (EC) {
+ errs() << EC.message() << '\n';
return 1;
}
}
@@ -470,11 +469,10 @@ int main(int argc, char **argv) {
if (OutputFilename.empty())
OutputFilename = "-";
- std::string ErrorInfo;
- Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
- sys::fs::F_None));
- if (!ErrorInfo.empty()) {
- errs() << ErrorInfo << '\n';
+ std::error_code EC;
+ Out.reset(new tool_output_file(OutputFilename, EC, sys::fs::F_None));
+ if (EC) {
+ errs() << EC.message() << '\n';
return 1;
}
}
diff --git a/tools/verify-uselistorder/verify-uselistorder.cpp b/tools/verify-uselistorder/verify-uselistorder.cpp
index 76d3e04266f..dd14a407c1d 100644
--- a/tools/verify-uselistorder/verify-uselistorder.cpp
+++ b/tools/verify-uselistorder/verify-uselistorder.cpp
@@ -123,10 +123,10 @@ bool TempFile::init(const std::string &Ext) {
bool TempFile::writeBitcode(const Module &M) const {
DEBUG(dbgs() << " - write bitcode\n");
- std::string ErrorInfo;
- raw_fd_ostream OS(Filename.c_str(), ErrorInfo, sys::fs::F_None);
- if (!ErrorInfo.empty()) {
- DEBUG(dbgs() << "error: " << ErrorInfo << "\n");
+ std::error_code EC;
+ raw_fd_ostream OS(Filename, EC, sys::fs::F_None);
+ if (EC) {
+ DEBUG(dbgs() << "error: " << EC.message() << "\n");
return true;
}
@@ -136,10 +136,10 @@ bool TempFile::writeBitcode(const Module &M) const {
bool TempFile::writeAssembly(const Module &M) const {
DEBUG(dbgs() << " - write assembly\n");
- std::string ErrorInfo;
- raw_fd_ostream OS(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
- if (!ErrorInfo.empty()) {
- DEBUG(dbgs() << "error: " << ErrorInfo << "\n");
+ std::error_code EC;
+ raw_fd_ostream OS(Filename, EC, sys::fs::F_Text);
+ if (EC) {
+ DEBUG(dbgs() << "error: " << EC.message() << "\n");
return true;
}
diff --git a/tools/yaml2obj/yaml2obj.cpp b/tools/yaml2obj/yaml2obj.cpp
index 945fad1384a..375cd89849c 100644
--- a/tools/yaml2obj/yaml2obj.cpp
+++ b/tools/yaml2obj/yaml2obj.cpp
@@ -83,11 +83,11 @@ int main(int argc, char **argv) {
if (OutputFilename.empty())
OutputFilename = "-";
- std::string ErrorInfo;
+ std::error_code EC;
std::unique_ptr<tool_output_file> Out(
- new tool_output_file(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
- if (!ErrorInfo.empty()) {
- errs() << ErrorInfo << '\n';
+ new tool_output_file(OutputFilename, EC, sys::fs::F_None));
+ if (EC) {
+ errs() << EC.message() << '\n';
return 1;
}
diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp
index 7bf66e0534a..22bf35d9cbe 100644
--- a/unittests/Support/Path.cpp
+++ b/unittests/Support/Path.cpp
@@ -535,8 +535,8 @@ TEST_F(FileSystemTest, Magic) {
++i) {
SmallString<128> file_pathname(TestDirectory);
path::append(file_pathname, i->filename);
- std::string ErrMsg;
- raw_fd_ostream file(file_pathname.c_str(), ErrMsg, sys::fs::F_None);
+ std::error_code EC;
+ raw_fd_ostream file(file_pathname, EC, sys::fs::F_None);
ASSERT_FALSE(file.has_error());
StringRef magic(i->magic_str, i->magic_str_len);
file << magic;
@@ -553,23 +553,23 @@ TEST_F(FileSystemTest, CarriageReturn) {
path::append(FilePathname, "test");
{
- raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_Text);
+ raw_fd_ostream File(FilePathname, ErrMsg, sys::fs::F_Text);
EXPECT_EQ(ErrMsg, "");
File << '\n';
}
{
- auto Buf = MemoryBuffer::getFile(FilePathname.c_str());
+ auto Buf = MemoryBuffer::getFile(FilePathname);
EXPECT_TRUE((bool)Buf);
EXPECT_EQ(Buf.get()->getBuffer(), "\r\n");
}
{
- raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_None);
+ raw_fd_ostream File(FilePathname, ErrMsg, sys::fs::F_None);
EXPECT_EQ(ErrMsg, "");
File << '\n';
}
{
- auto Buf = MemoryBuffer::getFile(FilePathname.c_str());
+ auto Buf = MemoryBuffer::getFile(FilePathname);
EXPECT_TRUE((bool)Buf);
EXPECT_EQ(Buf.get()->getBuffer(), "\n");
}