llvm.org GIT mirror llvm / 8c96862
Modernize raw_fd_ostream's constructor a bit. Take a StringRef instead of a "const char *". Take a "std::error_code &" instead of a "std::string &" for error. A create static method would be even better, but this patch is already a bit too big. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216393 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
36 changed file(s) with 181 addition(s) and 192 deletion(s). Raw diff Collapse all Expand all
106106 OutputFilename = base+".bc";
107107 }
108108 if (OutputFilename != "-") {
109 std::string ErrInfo;
110 out = new raw_fd_ostream(OutputFilename.c_str(), ErrInfo,
111 sys::fs::F_None);
109 std::error_code EC;
110 out = new raw_fd_ostream(OutputFilename, EC, sys::fs::F_None);
112111 }
113112 }
114113
6565 bool runOnFunction(Function &F) override {
6666 GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis());
6767 std::string Filename = Name + "." + F.getName().str() + ".dot";
68 std::string ErrorInfo;
68 std::error_code EC;
6969
7070 errs() << "Writing '" << Filename << "'...";
7171
72 raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
72 raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
7373 std::string GraphName = DOTGraphTraits::getGraphName(Graph);
7474 std::string Title = GraphName + " for '" + F.getName().str() + "' function";
7575
76 if (ErrorInfo.empty())
76 if (!EC)
7777 WriteGraph(File, Graph, IsSimple, Title);
7878 else
7979 errs() << " error opening file for writing!";
128128 bool runOnModule(Module &M) override {
129129 GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis());
130130 std::string Filename = Name + ".dot";
131 std::string ErrorInfo;
131 std::error_code EC;
132132
133133 errs() << "Writing '" << Filename << "'...";
134134
135 raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
135 raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
136136 std::string Title = DOTGraphTraits::getGraphName(Graph);
137137
138 if (ErrorInfo.empty())
138 if (!EC)
139139 WriteGraph(File, Graph, IsSimple, Title);
140140 else
141141 errs() << " error opening file for writing!";
2828 /// destructed after the raw_fd_ostream is destructed. It installs
2929 /// cleanups in its constructor and uninstalls them in its destructor.
3030 class CleanupInstaller {
31 /// Filename - The name of the file.
31 /// The name of the file.
3232 std::string Filename;
3333 public:
34 /// Keep - The flag which indicates whether we should not delete the file.
34 /// The flag which indicates whether we should not delete the file.
3535 bool Keep;
3636
37 explicit CleanupInstaller(const char *filename);
37 explicit CleanupInstaller(StringRef ilename);
3838 ~CleanupInstaller();
3939 } Installer;
4040
4343 raw_fd_ostream OS;
4444
4545 public:
46 /// tool_output_file - This constructor's arguments are passed to
47 /// to raw_fd_ostream's constructor.
48 tool_output_file(const char *filename, std::string &ErrorInfo,
46 /// This constructor's arguments are passed to to raw_fd_ostream's
47 /// constructor.
48 tool_output_file(StringRef Filename, std::error_code &EC,
4949 sys::fs::OpenFlags Flags);
5050
51 tool_output_file(const char *Filename, int FD);
51 tool_output_file(StringRef Filename, int FD);
5252
5353 /// os - Return the contained raw_fd_ostream.
5454 raw_fd_ostream &os() { return OS; }
1616 #include "llvm/ADT/StringRef.h"
1717 #include "llvm/Support/Compiler.h"
1818 #include "llvm/Support/DataTypes.h"
19 #include
1920
2021 namespace llvm {
2122 class format_object_base;
340341 void error_detected() { Error = true; }
341342
342343 public:
343 /// raw_fd_ostream - Open the specified file for writing. If an error occurs,
344 /// information about the error is put into ErrorInfo, and the stream should
345 /// be immediately destroyed; the string will be empty if no error occurred.
346 /// This allows optional flags to control how the file will be opened.
344 /// Open the specified file for writing. If an error occurs, information
345 /// about the error is put into EC, and the stream should be immediately
346 /// destroyed;
347 /// \p Flags allows optional flags to control how the file will be opened.
347348 ///
348349 /// As a special case, if Filename is "-", then the stream will use
349350 /// STDOUT_FILENO instead of opening a file. Note that it will still consider
350351 /// itself to own the file descriptor. In particular, it will close the
351352 /// file descriptor when it is done (this is necessary to detect
352353 /// output errors).
353 raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
354 raw_fd_ostream(StringRef Filename, std::error_code &EC,
354355 sys::fs::OpenFlags Flags);
355356
356357 /// raw_fd_ostream ctor - FD is the file descriptor that this writes to. If
7878 bool runOnFunction(Function &F) override {
7979 std::string Filename = "cfg." + F.getName().str() + ".dot";
8080 errs() << "Writing '" << Filename << "'...";
81
82 std::string ErrorInfo;
83 raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
8481
85 if (ErrorInfo.empty())
82 std::error_code EC;
83 raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
84
85 if (!EC)
8686 WriteGraph(File, (const Function*)&F);
8787 else
8888 errs() << " error opening file for writing!";
113113 std::string Filename = "cfg." + F.getName().str() + ".dot";
114114 errs() << "Writing '" << Filename << "'...";
115115
116 std::string ErrorInfo;
117 raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
118
119 if (ErrorInfo.empty())
116 std::error_code EC;
117 raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
118
119 if (!EC)
120120 WriteGraph(File, (const Function*)&F, true);
121121 else
122122 errs() << " error opening file for writing!";
1717 /*===-- Operations on modules ---------------------------------------------===*/
1818
1919 int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
20 std::string ErrorInfo;
21 raw_fd_ostream OS(Path, ErrorInfo, sys::fs::F_None);
20 std::error_code EC;
21 raw_fd_ostream OS(Path, EC, sys::fs::F_None);
2222
23 if (!ErrorInfo.empty())
23 if (EC)
2424 return -1;
2525
2626 WriteBitcodeToFile(unwrap(M), OS);
275275 bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) {
276276 raw_ostream *OutFile = nullptr;
277277 if (OutFileName) {
278 std::string ErrorInfo;
279 OutFile = new raw_fd_ostream(OutFileName, ErrorInfo,
278 std::error_code EC;
279 OutFile = new raw_fd_ostream(OutFileName, EC,
280280 sys::fs::F_Append | sys::fs::F_Text);
281 if (!ErrorInfo.empty()) {
282 errs() << "Error opening '" << OutFileName << "': " << ErrorInfo << '\n';
281 if (EC) {
282 errs() << "Error opening '" << OutFileName << "': " << EC.message()
283 << '\n';
283284 exit(1);
284285 }
285286
586586 std::ostringstream rs;
587587 rs << round;
588588 std::string graphFileName(fqn + "." + rs.str() + ".pbqpgraph");
589 std::string tmp;
590 raw_fd_ostream os(graphFileName.c_str(), tmp, sys::fs::F_Text);
589 std::error_code EC;
590 raw_fd_ostream os(graphFileName, EC, sys::fs::F_Text);
591591 DEBUG(dbgs() << "Dumping graph for round " << round << " to \""
592592 << graphFileName << "\"\n");
593593 problem->getGraph().dump(os);
182182
183183 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
184184 char **ErrorMessage) {
185 std::string error;
186 raw_fd_ostream dest(Filename, error, sys::fs::F_Text);
187 if (!error.empty()) {
188 *ErrorMessage = strdup(error.c_str());
185 std::error_code EC;
186 raw_fd_ostream dest(Filename, EC, sys::fs::F_Text);
187 if (EC) {
188 *ErrorMessage = strdup(EC.message().c_str());
189189 return true;
190190 }
191191
192192 unwrap(M)->print(dest, nullptr);
193193
194 if (!error.empty()) {
195 *ErrorMessage = strdup(error.c_str());
194 dest.close();
195
196 if (dest.has_error()) {
197 *ErrorMessage = strdup("Error printing to file");
196198 return true;
197199 }
198 dest.flush();
200
199201 return false;
200202 }
201203
516516 if (Options.NoOutput)
517517 return llvm::make_unique();
518518
519 std::string ErrorInfo;
520 auto OS = llvm::make_unique(CoveragePath.str().c_str(),
521 ErrorInfo, sys::fs::F_Text);
522 if (!ErrorInfo.empty()) {
523 errs() << ErrorInfo << "\n";
519 std::error_code EC;
520 auto OS = llvm::make_unique(CoveragePath.str(), EC,
521 sys::fs::F_Text);
522 if (EC) {
523 errs() << EC.message() << "\n";
524524 return llvm::make_unique();
525525 }
526526 return std::move(OS);
162162 applyScopeRestrictions();
163163
164164 // create output file
165 std::string ErrInfo;
166 tool_output_file Out(path, ErrInfo, sys::fs::F_None);
167 if (!ErrInfo.empty()) {
165 std::error_code EC;
166 tool_output_file Out(path, EC, sys::fs::F_None);
167 if (EC) {
168168 errMsg = "could not open bitcode file for writing: ";
169169 errMsg += path;
170170 return false;
637637 // Open the secure log file if we haven't already.
638638 raw_ostream *OS = getContext().getSecureLog();
639639 if (!OS) {
640 std::string Err;
641 OS = new raw_fd_ostream(SecureLogFile, Err,
640 std::error_code EC;
641 OS = new raw_fd_ostream(SecureLogFile, EC,
642642 sys::fs::F_Append | sys::fs::F_Text);
643 if (!Err.empty()) {
643 if (EC) {
644644 delete OS;
645645 return Error(IDLoc, Twine("can't open secure log file: ") +
646 SecureLogFile + " (" + Err + ")");
646 SecureLogFile + " (" + EC.message() + ")");
647647 }
648648 getContext().setSecureLog(OS);
649649 }
6565 // each time -stats or -time-passes wants to print output to it. To
6666 // compensate for this, the test-suite Makefiles have code to delete the
6767 // info output file before running commands which write to it.
68 std::string Error;
69 raw_ostream *Result = new raw_fd_ostream(
70 OutputFilename.c_str(), Error, sys::fs::F_Append | sys::fs::F_Text);
71 if (Error.empty())
68 std::error_code EC;
69 raw_ostream *Result = new raw_fd_ostream(OutputFilename, EC,
70 sys::fs::F_Append | sys::fs::F_Text);
71 if (!EC)
7272 return Result;
7373
7474 errs() << "Error opening info-output-file '"
1515 #include "llvm/Support/Signals.h"
1616 using namespace llvm;
1717
18 tool_output_file::CleanupInstaller::CleanupInstaller(const char *filename)
19 : Filename(filename), Keep(false) {
18 tool_output_file::CleanupInstaller::CleanupInstaller(StringRef Filename)
19 : Filename(Filename), Keep(false) {
2020 // Arrange for the file to be deleted if the process is killed.
2121 if (Filename != "-")
2222 sys::RemoveFileOnSignal(Filename);
3333 sys::DontRemoveFileOnSignal(Filename);
3434 }
3535
36 tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo,
36 tool_output_file::tool_output_file(StringRef Filename, std::error_code &EC,
3737 sys::fs::OpenFlags Flags)
38 : Installer(filename), OS(filename, ErrorInfo, Flags) {
38 : Installer(Filename), OS(Filename, EC, Flags) {
3939 // If open fails, no cleanup is needed.
40 if (!ErrorInfo.empty())
40 if (EC)
4141 Installer.Keep = true;
4242 }
4343
44 tool_output_file::tool_output_file(const char *Filename, int FD)
45 : Installer(Filename), OS(FD, true) {
46 }
44 tool_output_file::tool_output_file(StringRef Filename, int FD)
45 : Installer(Filename), OS(FD, true) {}
425425 // raw_fd_ostream
426426 //===----------------------------------------------------------------------===//
427427
428 /// raw_fd_ostream - Open the specified file for writing. If an error
429 /// occurs, information about the error is put into ErrorInfo, and the
430 /// stream should be immediately destroyed; the string will be empty
431 /// if no error occurred.
432 raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
428 raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC,
433429 sys::fs::OpenFlags Flags)
434430 : Error(false), UseAtomicWrites(false), pos(0) {
435 assert(Filename && "Filename is null");
436 ErrorInfo.clear();
437
431 EC = std::error_code();
438432 // Handle "-" as stdout. Note that when we do this, we consider ourself
439433 // the owner of stdout. This means that we can do things like close the
440434 // file descriptor when we're done and set the "binary" flag globally.
441 if (Filename[0] == '-' && Filename[1] == 0) {
435 if (Filename == "-") {
442436 FD = STDOUT_FILENO;
443437 // If user requested binary then put stdout into binary mode if
444438 // possible.
449443 return;
450444 }
451445
452 std::error_code EC = sys::fs::openFileForWrite(Filename, FD, Flags);
446 EC = sys::fs::openFileForWrite(Filename, FD, Flags);
453447
454448 if (EC) {
455 ErrorInfo = "Error opening output file '" + std::string(Filename) + "': " +
456 EC.message();
457449 ShouldClose = false;
458450 return;
459451 }
5555 errs() << argv0 << ": the option -d must be used together with -o\n";
5656 return 1;
5757 }
58 std::string Error;
59 tool_output_file DepOut(DependFilename.c_str(), Error, sys::fs::F_Text);
60 if (!Error.empty()) {
61 errs() << argv0 << ": error opening " << DependFilename
62 << ":" << Error << "\n";
58 std::error_code EC;
59 tool_output_file DepOut(DependFilename, EC, sys::fs::F_Text);
60 if (EC) {
61 errs() << argv0 << ": error opening " << DependFilename << ":"
62 << EC.message() << "\n";
6363 return 1;
6464 }
6565 DepOut.os() << OutputFilename << ":";
100100 if (Parser.ParseFile())
101101 return 1;
102102
103 std::string Error;
104 tool_output_file Out(OutputFilename.c_str(), Error, sys::fs::F_Text);
105 if (!Error.empty()) {
106 errs() << argv0 << ": error opening " << OutputFilename
107 << ":" << Error << "\n";
103 std::error_code EC;
104 tool_output_file Out(OutputFilename, EC, sys::fs::F_Text);
105 if (EC) {
106 errs() << argv0 << ": error opening " << OutputFilename << ":"
107 << EC.message() << "\n";
108108 return 1;
109109 }
110110 if (!DependFilename.empty()) {
222222
223223 LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
224224 char* Filename, LLVMCodeGenFileType codegen, char** ErrorMessage) {
225 std::string error;
226 raw_fd_ostream dest(Filename, error, sys::fs::F_None);
227 if (!error.empty()) {
228 *ErrorMessage = strdup(error.c_str());
225 std::error_code EC;
226 raw_fd_ostream dest(Filename, EC, sys::fs::F_None);
227 if (EC) {
228 *ErrorMessage = strdup(EC.message().c_str());
229229 return true;
230230 }
231231 formatted_raw_ostream destf(dest);
524524
525525 void DebugIR::writeDebugBitcode(const Module *M, int *fd) {
526526 std::unique_ptr Out;
527 std::string error;
527 std::error_code EC;
528528
529529 if (!fd) {
530530 std::string Path = getPath();
531 Out.reset(new raw_fd_ostream(Path.c_str(), error, sys::fs::F_Text));
531 Out.reset(new raw_fd_ostream(Path, EC, sys::fs::F_Text));
532532 DEBUG(dbgs() << "WRITING debug bitcode from Module " << M << " to file "
533533 << Path << "\n");
534534 } else {
479479 // LTO, we'll generate the same .gcno files.
480480
481481 DICompileUnit CU(CU_Nodes->getOperand(i));
482 std::string ErrorInfo;
483 raw_fd_ostream out(mangleName(CU, "gcno").c_str(), ErrorInfo,
484 sys::fs::F_None);
482 std::error_code EC;
483 raw_fd_ostream out(mangleName(CU, "gcno"), EC, sys::fs::F_None);
485484 std::string EdgeDestinations;
486485
487486 DIArray SPs = CU.getSubprograms();
6565
6666 bool BugDriver::writeProgramToFile(const std::string &Filename, int FD,
6767 const Module *M) const {
68 tool_output_file Out(Filename.c_str(), FD);
68 tool_output_file Out(Filename, FD);
6969 return writeProgramToFileAux(Out, M);
7070 }
7171
7272 bool BugDriver::writeProgramToFile(const std::string &Filename,
7373 const Module *M) const {
74 std::string ErrInfo;
75 tool_output_file Out(Filename.c_str(), ErrInfo, sys::fs::F_None);
76 if (ErrInfo.empty())
74 std::error_code EC;
75 tool_output_file Out(Filename, EC, sys::fs::F_None);
76 if (!EC)
7777 return writeProgramToFileAux(Out, M);
7878 return true;
7979 }
148148 return 1;
149149 }
150150
151 tool_output_file InFile(InputFilename.c_str(), InputFD);
151 tool_output_file InFile(InputFilename, InputFD);
152152
153153 WriteBitcodeToFile(Program, InFile.os());
154154 InFile.os().close();
774774 else
775775 path = output_name + ".bc";
776776 {
777 std::string Error;
778 raw_fd_ostream OS(path.c_str(), Error, sys::fs::OpenFlags::F_None);
779 if (!Error.empty())
777 std::error_code EC;
778 raw_fd_ostream OS(path, EC, sys::fs::OpenFlags::F_None);
779 if (EC)
780780 message(LDPL_FATAL, "Failed to write the output file.");
781781 WriteBitcodeToFile(L.getModule(), OS);
782782 }
798798 if (!options::generate_api_file) {
799799 Ret = allSymbolsReadHook(nullptr);
800800 } else {
801 std::string Error;
802 raw_fd_ostream ApiFile("apifile.txt", Error, sys::fs::F_None);
803 if (!Error.empty())
801 std::error_code EC;
802 raw_fd_ostream ApiFile("apifile.txt", EC, sys::fs::F_None);
803 if (EC)
804804 message(LDPL_FATAL, "Unable to open apifile.txt for writing: %s",
805 Error.c_str());
805 EC.message().c_str());
806806 Ret = allSymbolsReadHook(&ApiFile);
807807 }
808808
158158 }
159159
160160 // Open the file.
161 std::string error;
161 std::error_code EC;
162162 sys::fs::OpenFlags OpenFlags = sys::fs::F_None;
163163 if (!Binary)
164164 OpenFlags |= sys::fs::F_Text;
165 tool_output_file *FDOut = new tool_output_file(OutputFilename.c_str(), error,
166 OpenFlags);
167 if (!error.empty()) {
168 errs() << error << '\n';
165 tool_output_file *FDOut = new tool_output_file(OutputFilename, EC, OpenFlags);
166 if (EC) {
167 errs() << EC.message() << '\n';
169168 delete FDOut;
170169 return nullptr;
171170 }
267267 std::string CacheName;
268268 if (!getCacheFilename(ModuleID, CacheName))
269269 return;
270 std::string errStr;
271270 if (!CacheDir.empty()) { // Create user-defined cache dir.
272271 SmallString<128> dir(CacheName);
273272 sys::path::remove_filename(dir);
274273 sys::fs::create_directories(Twine(dir));
275274 }
276 raw_fd_ostream outfile(CacheName.c_str(), errStr, sys::fs::F_None);
275 std::error_code EC;
276 raw_fd_ostream outfile(CacheName, EC, sys::fs::F_None);
277277 outfile.write(Obj.getBufferStart(), Obj.getBufferSize());
278278 outfile.close();
279279 }
6868 }
6969 }
7070
71 std::string ErrorInfo;
71 std::error_code EC;
7272 std::unique_ptr Out(
73 new tool_output_file(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
74 if (!ErrorInfo.empty()) {
75 errs() << ErrorInfo << '\n';
73 new tool_output_file(OutputFilename, EC, sys::fs::F_None));
74 if (EC) {
75 errs() << EC.message() << '\n';
7676 exit(1);
7777 }
7878
170170 }
171171 }
172172
173 std::string ErrorInfo;
173 std::error_code EC;
174174 std::unique_ptr Out(
175 new tool_output_file(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
176 if (!ErrorInfo.empty()) {
177 errs() << ErrorInfo << '\n';
175 new tool_output_file(OutputFilename, EC, sys::fs::F_None));
176 if (EC) {
177 errs() << EC.message() << '\n';
178178 return 1;
179179 }
180180
260260 Passes.add(createStripDeadDebugInfoPass()); // Remove dead debug info
261261 Passes.add(createStripDeadPrototypesPass()); // Remove dead func decls
262262
263 std::string ErrorInfo;
264 tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None);
265 if (!ErrorInfo.empty()) {
266 errs() << ErrorInfo << '\n';
263 std::error_code EC;
264 tool_output_file Out(OutputFilename, EC, sys::fs::F_None);
265 if (EC) {
266 errs() << EC.message() << '\n';
267267 return 1;
268268 }
269269
109109
110110 if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
111111
112 std::string ErrorInfo;
113 tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None);
114 if (!ErrorInfo.empty()) {
115 errs() << ErrorInfo << '\n';
112 std::error_code EC;
113 tool_output_file Out(OutputFilename, EC, sys::fs::F_None);
114 if (EC) {
115 errs() << EC.message() << '\n';
116116 return 1;
117117 }
118118
164164 return 1;
165165 }
166166
167 raw_fd_ostream FileStream(OutputFilename.c_str(), ErrorInfo,
168 sys::fs::F_None);
169 if (!ErrorInfo.empty()) {
167 std::error_code EC;
168 raw_fd_ostream FileStream(OutputFilename, EC, sys::fs::F_None);
169 if (EC) {
170170 errs() << argv[0] << ": error opening the file '" << OutputFilename
171 << "': " << ErrorInfo << "\n";
171 << "': " << EC.message() << "\n";
172172 return 1;
173173 }
174174
207207 if (OutputFilename == "")
208208 OutputFilename = "-";
209209
210 std::string Err;
210 std::error_code EC;
211211 tool_output_file *Out =
212 new tool_output_file(OutputFilename.c_str(), Err, sys::fs::F_None);
213 if (!Err.empty()) {
214 errs() << Err << '\n';
212 new tool_output_file(OutputFilename, EC, sys::fs::F_None);
213 if (EC) {
214 errs() << EC.message() << '\n';
215215 delete Out;
216216 return nullptr;
217217 }
201201 static void emitDOTFile(const char *FileName, const MCFunction &f,
202202 MCInstPrinter *IP) {
203203 // Start a new dot file.
204 std::string Error;
205 raw_fd_ostream Out(FileName, Error, sys::fs::F_Text);
206 if (!Error.empty()) {
207 errs() << "llvm-objdump: warning: " << Error << '\n';
204 std::error_code EC;
205 raw_fd_ostream Out(FileName, EC, sys::fs::F_Text);
206 if (EC) {
207 errs() << "llvm-objdump: warning: " << EC.message() << '\n';
208208 return;
209209 }
210210
385385 }
386386 }
387387 if (!YAMLCFG.empty()) {
388 std::string Error;
389 raw_fd_ostream YAMLOut(YAMLCFG.c_str(), Error, sys::fs::F_Text);
390 if (!Error.empty()) {
391 errs() << ToolName << ": warning: " << Error << '\n';
388 std::error_code EC;
389 raw_fd_ostream YAMLOut(YAMLCFG, EC, sys::fs::F_Text);
390 if (EC) {
391 errs() << ToolName << ": warning: " << EC.message() << '\n';
392392 return;
393393 }
394394 mcmodule2yaml(YAMLOut, *Mod, *MII, *MRI);
4747 if (OutputFilename.compare("-") == 0)
4848 exitWithError("Cannot write indexed profdata format to stdout.");
4949
50 std::string ErrorInfo;
51 raw_fd_ostream Output(OutputFilename.data(), ErrorInfo, sys::fs::F_None);
52 if (!ErrorInfo.empty())
53 exitWithError(ErrorInfo, OutputFilename);
50 std::error_code EC;
51 raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::F_None);
52 if (EC)
53 exitWithError(EC.message(), OutputFilename);
5454
5555 InstrProfWriter Writer;
5656 for (const auto &Filename : Inputs) {
9696 if (OutputFilename.empty())
9797 OutputFilename = "-";
9898
99 std::string ErrorInfo;
100 raw_fd_ostream OS(OutputFilename.data(), ErrorInfo, sys::fs::F_Text);
101 if (!ErrorInfo.empty())
102 exitWithError(ErrorInfo, OutputFilename);
99 std::error_code EC;
100 raw_fd_ostream OS(OutputFilename.data(), EC, sys::fs::F_Text);
101 if (EC)
102 exitWithError(EC.message(), OutputFilename);
103103
104104 if (ShowAllFunctions && !ShowFunction.empty())
105105 errs() << "warning: -function argument ignored: showing all functions\n";
703703 if (OutputFilename.empty())
704704 OutputFilename = "-";
705705
706 std::string ErrorInfo;
707 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
708 sys::fs::F_None));
709 if (!ErrorInfo.empty()) {
710 errs() << ErrorInfo << '\n';
706 std::error_code EC;
707 Out.reset(new tool_output_file(OutputFilename, EC, sys::fs::F_None));
708 if (EC) {
709 errs() << EC.message() << '\n';
711710 return 1;
712711 }
713712
384384 if (OutputFilename.empty())
385385 OutputFilename = "-";
386386
387 std::string ErrorInfo;
388 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
389 sys::fs::F_None));
390 if (!ErrorInfo.empty()) {
391 errs() << ErrorInfo << '\n';
387 std::error_code EC;
388 Out.reset(new tool_output_file(OutputFilename, EC, sys::fs::F_None));
389 if (EC) {
390 errs() << EC.message() << '\n';
392391 return 1;
393392 }
394393 }
469468 if (OutputFilename.empty())
470469 OutputFilename = "-";
471470
472 std::string ErrorInfo;
473 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
474 sys::fs::F_None));
475 if (!ErrorInfo.empty()) {
476 errs() << ErrorInfo << '\n';
471 std::error_code EC;
472 Out.reset(new tool_output_file(OutputFilename, EC, sys::fs::F_None));
473 if (EC) {
474 errs() << EC.message() << '\n';
477475 return 1;
478476 }
479477 }
122122
123123 bool TempFile::writeBitcode(const Module &M) const {
124124 DEBUG(dbgs() << " - write bitcode\n");
125 std::string ErrorInfo;
126 raw_fd_ostream OS(Filename.c_str(), ErrorInfo, sys::fs::F_None);
127 if (!ErrorInfo.empty()) {
128 DEBUG(dbgs() << "error: " << ErrorInfo << "\n");
125 std::error_code EC;
126 raw_fd_ostream OS(Filename, EC, sys::fs::F_None);
127 if (EC) {
128 DEBUG(dbgs() << "error: " << EC.message() << "\n");
129129 return true;
130130 }
131131
135135
136136 bool TempFile::writeAssembly(const Module &M) const {
137137 DEBUG(dbgs() << " - write assembly\n");
138 std::string ErrorInfo;
139 raw_fd_ostream OS(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
140 if (!ErrorInfo.empty()) {
141 DEBUG(dbgs() << "error: " << ErrorInfo << "\n");
138 std::error_code EC;
139 raw_fd_ostream OS(Filename, EC, sys::fs::F_Text);
140 if (EC) {
141 DEBUG(dbgs() << "error: " << EC.message() << "\n");
142142 return true;
143143 }
144144
8282 if (OutputFilename.empty())
8383 OutputFilename = "-";
8484
85 std::string ErrorInfo;
85 std::error_code EC;
8686 std::unique_ptr Out(
87 new tool_output_file(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
88 if (!ErrorInfo.empty()) {
89 errs() << ErrorInfo << '\n';
87 new tool_output_file(OutputFilename, EC, sys::fs::F_None));
88 if (EC) {
89 errs() << EC.message() << '\n';
9090 return 1;
9191 }
9292
534534 ++i) {
535535 SmallString<128> file_pathname(TestDirectory);
536536 path::append(file_pathname, i->filename);
537 std::string ErrMsg;
538 raw_fd_ostream file(file_pathname.c_str(), ErrMsg, sys::fs::F_None);
537 std::error_code EC;
538 raw_fd_ostream file(file_pathname, EC, sys::fs::F_None);
539539 ASSERT_FALSE(file.has_error());
540540 StringRef magic(i->magic_str, i->magic_str_len);
541541 file << magic;
552552 path::append(FilePathname, "test");
553553
554554 {
555 raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_Text);
555 raw_fd_ostream File(FilePathname, ErrMsg, sys::fs::F_Text);
556556 EXPECT_EQ(ErrMsg, "");
557557 File << '\n';
558558 }
559559 {
560 auto Buf = MemoryBuffer::getFile(FilePathname.c_str());
560 auto Buf = MemoryBuffer::getFile(FilePathname);
561561 EXPECT_TRUE((bool)Buf);
562562 EXPECT_EQ(Buf.get()->getBuffer(), "\r\n");
563563 }
564564
565565 {
566 raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_None);
566 raw_fd_ostream File(FilePathname, ErrMsg, sys::fs::F_None);
567567 EXPECT_EQ(ErrMsg, "");
568568 File << '\n';
569569 }
570570 {
571 auto Buf = MemoryBuffer::getFile(FilePathname.c_str());
571 auto Buf = MemoryBuffer::getFile(FilePathname);
572572 EXPECT_TRUE((bool)Buf);
573573 EXPECT_EQ(Buf.get()->getBuffer(), "\n");
574574 }