Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 97b51af

Browse files
committed
Update for llvm api change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216397 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 79adaa2 commit 97b51af

File tree

17 files changed

+94
-111
lines changed

17 files changed

+94
-111
lines changed

include/clang/Frontend/CompilerInstance.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ class CompilerInstance : public ModuleLoader {
641641
/// renamed to \p OutputPath in the end.
642642
///
643643
/// \param OutputPath - If given, the path to the output file.
644-
/// \param Error [out] - On failure, the error message.
644+
/// \param Error [out] - On failure, the error.
645645
/// \param BaseInput - If \p OutputPath is empty, the input path name to use
646646
/// for deriving the output path.
647647
/// \param Extension - The extension to use for derived output names.
@@ -658,13 +658,10 @@ class CompilerInstance : public ModuleLoader {
658658
/// \param TempPathName [out] - If given, the temporary file path name
659659
/// will be stored here on success.
660660
static llvm::raw_fd_ostream *
661-
createOutputFile(StringRef OutputPath, std::string &Error,
662-
bool Binary, bool RemoveFileOnSignal,
663-
StringRef BaseInput,
664-
StringRef Extension,
665-
bool UseTemporary,
666-
bool CreateMissingDirectories,
667-
std::string *ResultPathName,
661+
createOutputFile(StringRef OutputPath, std::error_code &Error, bool Binary,
662+
bool RemoveFileOnSignal, StringRef BaseInput,
663+
StringRef Extension, bool UseTemporary,
664+
bool CreateMissingDirectories, std::string *ResultPathName,
668665
std::string *TempPathName);
669666

670667
llvm::raw_null_ostream *createNullOutputFile();

lib/ARCMigrate/FileRemapper.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ bool FileRemapper::flushToDisk(StringRef outputDir, DiagnosticsEngine &Diag) {
122122
bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
123123
using namespace llvm::sys;
124124

125-
std::string errMsg;
125+
std::error_code EC;
126126
std::string infoFile = outputPath;
127-
llvm::raw_fd_ostream infoOut(infoFile.c_str(), errMsg, llvm::sys::fs::F_None);
128-
if (!errMsg.empty())
129-
return report(errMsg, Diag);
127+
llvm::raw_fd_ostream infoOut(infoFile, EC, llvm::sys::fs::F_None);
128+
if (EC)
129+
return report(EC.message(), Diag);
130130

131131
for (MappingsTy::iterator
132132
I = FromToMappings.begin(), E = FromToMappings.end(); I != E; ++I) {
@@ -179,10 +179,10 @@ bool FileRemapper::overwriteOriginal(DiagnosticsEngine &Diag,
179179
return report(StringRef("File does not exist: ") + origFE->getName(),
180180
Diag);
181181

182-
std::string errMsg;
183-
llvm::raw_fd_ostream Out(origFE->getName(), errMsg, llvm::sys::fs::F_None);
184-
if (!errMsg.empty())
185-
return report(errMsg, Diag);
182+
std::error_code EC;
183+
llvm::raw_fd_ostream Out(origFE->getName(), EC, llvm::sys::fs::F_None);
184+
if (EC)
185+
return report(EC.message(), Diag);
186186

187187
llvm::MemoryBuffer *mem = I->second.get<llvm::MemoryBuffer *>();
188188
Out.write(mem->getBufferStart(), mem->getBufferSize());

lib/ARCMigrate/ObjCMT.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,12 +1791,12 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
17911791
}
17921792

17931793
if (IsOutputFile) {
1794-
std::string Error;
1795-
llvm::raw_fd_ostream OS(MigrateDir.c_str(), Error, llvm::sys::fs::F_None);
1796-
if (!Error.empty()) {
1794+
std::error_code EC;
1795+
llvm::raw_fd_ostream OS(MigrateDir, EC, llvm::sys::fs::F_None);
1796+
if (EC) {
17971797
DiagnosticsEngine &Diags = Ctx.getDiagnostics();
17981798
Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0"))
1799-
<< Error;
1799+
<< EC.message();
18001800
return;
18011801
}
18021802

lib/ARCMigrate/PlistReporter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ void arcmt::writeARCDiagsToPlist(const std::string &outPath,
5656
}
5757
}
5858

59-
std::string errMsg;
60-
llvm::raw_fd_ostream o(outPath.c_str(), errMsg, llvm::sys::fs::F_Text);
61-
if (!errMsg.empty()) {
59+
std::error_code EC;
60+
llvm::raw_fd_ostream o(outPath, EC, llvm::sys::fs::F_Text);
61+
if (EC) {
6262
llvm::errs() << "error: could not create file: " << outPath << '\n';
6363
return;
6464
}

lib/Driver/Compilation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ int Compilation::ExecuteCommand(const Command &C,
131131
// Follow gcc implementation of CC_PRINT_OPTIONS; we could also cache the
132132
// output stream.
133133
if (getDriver().CCPrintOptions && getDriver().CCPrintOptionsFilename) {
134-
std::string Error;
135-
OS = new llvm::raw_fd_ostream(getDriver().CCPrintOptionsFilename, Error,
134+
std::error_code EC;
135+
OS = new llvm::raw_fd_ostream(getDriver().CCPrintOptionsFilename, EC,
136136
llvm::sys::fs::F_Append |
137137
llvm::sys::fs::F_Text);
138-
if (!Error.empty()) {
138+
if (EC) {
139139
getDriver().Diag(clang::diag::err_drv_cc_print_options_failure)
140-
<< Error;
140+
<< EC.message();
141141
FailingCommand = &C;
142142
delete OS;
143143
return 1;

lib/Driver/Driver.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,12 @@ void Driver::generateCompilationDiagnostics(Compilation &C,
533533
llvm::sys::path::append(VFS, "vfs", "vfs.yaml");
534534
}
535535

536-
std::string Err;
536+
std::error_code EC;
537537
Script += ".sh";
538-
llvm::raw_fd_ostream ScriptOS(Script.c_str(), Err, llvm::sys::fs::F_Excl);
539-
if (!Err.empty()) {
538+
llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::F_Excl);
539+
if (EC) {
540540
Diag(clang::diag::note_drv_command_failed_diag_msg)
541-
<< "Error generating run script: " + Script + " " + Err;
541+
<< "Error generating run script: " + Script + " " + EC.message();
542542
} else {
543543
// Replace the original filename with the preprocessed one.
544544
size_t I, E;

lib/Frontend/CompilerInstance.cpp

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,17 @@ void CompilerInstance::setModuleDepCollector(
134134
static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts,
135135
const CodeGenOptions *CodeGenOpts,
136136
DiagnosticsEngine &Diags) {
137-
std::string ErrorInfo;
137+
std::error_code EC;
138138
bool OwnsStream = false;
139139
raw_ostream *OS = &llvm::errs();
140140
if (DiagOpts->DiagnosticLogFile != "-") {
141141
// Create the output stream.
142142
llvm::raw_fd_ostream *FileOS(new llvm::raw_fd_ostream(
143-
DiagOpts->DiagnosticLogFile.c_str(), ErrorInfo,
143+
DiagOpts->DiagnosticLogFile, EC,
144144
llvm::sys::fs::F_Append | llvm::sys::fs::F_Text));
145-
if (!ErrorInfo.empty()) {
145+
if (EC) {
146146
Diags.Report(diag::warn_fe_cc_log_diagnostics_failure)
147-
<< DiagOpts->DiagnosticLogFile << ErrorInfo;
147+
<< DiagOpts->DiagnosticLogFile << EC.message();
148148
} else {
149149
FileOS->SetUnbuffered();
150150
FileOS->SetUseAtomicWrites(true);
@@ -164,14 +164,14 @@ static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts,
164164
static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts,
165165
DiagnosticsEngine &Diags,
166166
StringRef OutputFile) {
167-
std::string ErrorInfo;
167+
std::error_code EC;
168168
std::unique_ptr<llvm::raw_fd_ostream> OS;
169-
OS.reset(new llvm::raw_fd_ostream(OutputFile.str().c_str(), ErrorInfo,
170-
llvm::sys::fs::F_None));
169+
OS.reset(
170+
new llvm::raw_fd_ostream(OutputFile.str(), EC, llvm::sys::fs::F_None));
171171

172-
if (!ErrorInfo.empty()) {
173-
Diags.Report(diag::warn_fe_serialized_diag_failure)
174-
<< OutputFile << ErrorInfo;
172+
if (EC) {
173+
Diags.Report(diag::warn_fe_serialized_diag_failure) << OutputFile
174+
<< EC.message();
175175
return;
176176
}
177177

@@ -573,17 +573,14 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
573573
StringRef Extension,
574574
bool UseTemporary,
575575
bool CreateMissingDirectories) {
576-
std::string Error, OutputPathName, TempPathName;
577-
llvm::raw_fd_ostream *OS = createOutputFile(OutputPath, Error, Binary,
578-
RemoveFileOnSignal,
579-
InFile, Extension,
580-
UseTemporary,
581-
CreateMissingDirectories,
582-
&OutputPathName,
583-
&TempPathName);
576+
std::string OutputPathName, TempPathName;
577+
std::error_code EC;
578+
llvm::raw_fd_ostream *OS = createOutputFile(
579+
OutputPath, EC, Binary, RemoveFileOnSignal, InFile, Extension,
580+
UseTemporary, CreateMissingDirectories, &OutputPathName, &TempPathName);
584581
if (!OS) {
585-
getDiagnostics().Report(diag::err_fe_unable_to_open_output)
586-
<< OutputPath << Error;
582+
getDiagnostics().Report(diag::err_fe_unable_to_open_output) << OutputPath
583+
<< EC.message();
587584
return nullptr;
588585
}
589586

@@ -595,17 +592,11 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
595592
return OS;
596593
}
597594

598-
llvm::raw_fd_ostream *
599-
CompilerInstance::createOutputFile(StringRef OutputPath,
600-
std::string &Error,
601-
bool Binary,
602-
bool RemoveFileOnSignal,
603-
StringRef InFile,
604-
StringRef Extension,
605-
bool UseTemporary,
606-
bool CreateMissingDirectories,
607-
std::string *ResultPathName,
608-
std::string *TempPathName) {
595+
llvm::raw_fd_ostream *CompilerInstance::createOutputFile(
596+
StringRef OutputPath, std::error_code &Error, bool Binary,
597+
bool RemoveFileOnSignal, StringRef InFile, StringRef Extension,
598+
bool UseTemporary, bool CreateMissingDirectories,
599+
std::string *ResultPathName, std::string *TempPathName) {
609600
assert((!CreateMissingDirectories || UseTemporary) &&
610601
"CreateMissingDirectories is only allowed when using temporary files");
611602

@@ -674,9 +665,9 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
674665
if (!OS) {
675666
OSFile = OutFile;
676667
OS.reset(new llvm::raw_fd_ostream(
677-
OSFile.c_str(), Error,
668+
OSFile, Error,
678669
(Binary ? llvm::sys::fs::F_None : llvm::sys::fs::F_Text)));
679-
if (!Error.empty())
670+
if (Error)
680671
return nullptr;
681672
}
682673

@@ -1136,9 +1127,8 @@ static void checkConfigMacro(Preprocessor &PP, StringRef ConfigMacro,
11361127

11371128
/// \brief Write a new timestamp file with the given path.
11381129
static void writeTimestampFile(StringRef TimestampFile) {
1139-
std::string ErrorInfo;
1140-
llvm::raw_fd_ostream Out(TimestampFile.str().c_str(), ErrorInfo,
1141-
llvm::sys::fs::F_None);
1130+
std::error_code EC;
1131+
llvm::raw_fd_ostream Out(TimestampFile.str(), EC, llvm::sys::fs::F_None);
11421132
}
11431133

11441134
/// \brief Prune the module cache of modules that haven't been accessed in

lib/Frontend/DependencyFile.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@ void DFGImpl::OutputDependencyFile() {
297297
return;
298298
}
299299

300-
std::string Err;
301-
llvm::raw_fd_ostream OS(OutputFile.c_str(), Err, llvm::sys::fs::F_Text);
302-
if (!Err.empty()) {
303-
PP->getDiagnostics().Report(diag::err_fe_error_opening)
304-
<< OutputFile << Err;
300+
std::error_code EC;
301+
llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_Text);
302+
if (EC) {
303+
PP->getDiagnostics().Report(diag::err_fe_error_opening) << OutputFile
304+
<< EC.message();
305305
return;
306306
}
307307

lib/Frontend/DependencyGraph.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ DependencyGraphCallback::writeNodeReference(raw_ostream &OS,
9696
}
9797

9898
void DependencyGraphCallback::OutputGraphFile() {
99-
std::string Err;
100-
llvm::raw_fd_ostream OS(OutputFile.c_str(), Err, llvm::sys::fs::F_Text);
101-
if (!Err.empty()) {
102-
PP->getDiagnostics().Report(diag::err_fe_error_opening)
103-
<< OutputFile << Err;
99+
std::error_code EC;
100+
llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_Text);
101+
if (EC) {
102+
PP->getDiagnostics().Report(diag::err_fe_error_opening) << OutputFile
103+
<< EC.message();
104104
return;
105105
}
106106

lib/Frontend/FrontendActions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,9 @@ void DumpModuleInfoAction::ExecuteAction() {
534534
std::unique_ptr<llvm::raw_fd_ostream> OutFile;
535535
StringRef OutputFileName = getCompilerInstance().getFrontendOpts().OutputFile;
536536
if (!OutputFileName.empty() && OutputFileName != "-") {
537-
std::string ErrorInfo;
538-
OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str().c_str(),
539-
ErrorInfo, llvm::sys::fs::F_Text));
537+
std::error_code EC;
538+
OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
539+
llvm::sys::fs::F_Text));
540540
}
541541
llvm::raw_ostream &Out = OutFile.get()? *OutFile.get() : llvm::outs();
542542

lib/Frontend/HeaderIncludeGen.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ void clang::AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders,
5454

5555
// Open the output file, if used.
5656
if (!OutputPath.empty()) {
57-
std::string Error;
57+
std::error_code EC;
5858
llvm::raw_fd_ostream *OS = new llvm::raw_fd_ostream(
59-
OutputPath.str().c_str(), Error,
60-
llvm::sys::fs::F_Append | llvm::sys::fs::F_Text);
61-
if (!Error.empty()) {
62-
PP.getDiagnostics().Report(
63-
clang::diag::warn_fe_cc_print_header_failure) << Error;
59+
OutputPath.str(), EC, llvm::sys::fs::F_Append | llvm::sys::fs::F_Text);
60+
if (EC) {
61+
PP.getDiagnostics().Report(clang::diag::warn_fe_cc_print_header_failure)
62+
<< EC.message();
6463
delete OS;
6564
} else {
6665
OS->SetUnbuffered();

lib/Frontend/ModuleDependencyCollector.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ void ModuleDependencyCollector::writeFileMap() {
4848
SmallString<256> Dest = getDest();
4949
llvm::sys::path::append(Dest, "vfs.yaml");
5050

51-
std::string ErrorInfo;
52-
llvm::raw_fd_ostream OS(Dest.c_str(), ErrorInfo, llvm::sys::fs::F_Text);
53-
if (!ErrorInfo.empty()) {
51+
std::error_code EC;
52+
llvm::raw_fd_ostream OS(Dest, EC, llvm::sys::fs::F_Text);
53+
if (EC) {
5454
setHasErrors();
5555
return;
5656
}

lib/Frontend/Rewrite/FixItRewriter.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,16 @@ bool FixItRewriter::WriteFixedFiles(
8686
const FileEntry *Entry = Rewrite.getSourceMgr().getFileEntryForID(I->first);
8787
int fd;
8888
std::string Filename = FixItOpts->RewriteFilename(Entry->getName(), fd);
89-
std::string Err;
89+
std::error_code EC;
9090
std::unique_ptr<llvm::raw_fd_ostream> OS;
9191
if (fd != -1) {
9292
OS.reset(new llvm::raw_fd_ostream(fd, /*shouldClose=*/true));
9393
} else {
94-
OS.reset(new llvm::raw_fd_ostream(Filename.c_str(), Err,
95-
llvm::sys::fs::F_None));
94+
OS.reset(new llvm::raw_fd_ostream(Filename, EC, llvm::sys::fs::F_None));
9695
}
97-
if (!Err.empty()) {
98-
Diags.Report(clang::diag::err_fe_unable_to_open_output)
99-
<< Filename << Err;
96+
if (EC) {
97+
Diags.Report(clang::diag::err_fe_unable_to_open_output) << Filename
98+
<< EC.message();
10099
continue;
101100
}
102101
RewriteBuffer &RewriteBuf = I->second;

lib/Serialization/ASTReader.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3521,10 +3521,9 @@ bool ASTReader::isGlobalIndexUnavailable() const {
35213521
static void updateModuleTimestamp(ModuleFile &MF) {
35223522
// Overwrite the timestamp file contents so that file's mtime changes.
35233523
std::string TimestampFilename = MF.getTimestampFilename();
3524-
std::string ErrorInfo;
3525-
llvm::raw_fd_ostream OS(TimestampFilename.c_str(), ErrorInfo,
3526-
llvm::sys::fs::F_Text);
3527-
if (!ErrorInfo.empty())
3524+
std::error_code EC;
3525+
llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text);
3526+
if (EC)
35283527
return;
35293528
OS << "Timestamp file\n";
35303529
}

lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,10 @@ void PlistDiagnostics::FlushDiagnosticsImpl(
338338
}
339339

340340
// Open the file.
341-
std::string ErrMsg;
342-
llvm::raw_fd_ostream o(OutputFile.c_str(), ErrMsg, llvm::sys::fs::F_Text);
343-
if (!ErrMsg.empty()) {
344-
llvm::errs() << "warning: could not create file: " << OutputFile << '\n';
341+
std::error_code EC;
342+
llvm::raw_fd_ostream o(OutputFile, EC, llvm::sys::fs::F_Text);
343+
if (EC) {
344+
llvm::errs() << "warning: could not create file: " << EC.message() << '\n';
345345
return;
346346
}
347347

test/Frontend/output-failures.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// RUN: not %clang_cc1 -emit-llvm -o %S/doesnotexist/somename %s 2> %t
22
// RUN: FileCheck -check-prefix=OUTPUTFAIL -input-file=%t %s
33

4-
// OUTPUTFAIL: Error opening output file '{{.*}}doesnotexist{{.*}}'
4+
// OUTPUTFAIL: error: unable to open output file '{{.*}}/test/Frontend/doesnotexist/somename': 'No such file or directory'

tools/driver/cc1as_main.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,12 @@ static formatted_raw_ostream *GetOutputStream(AssemblerInvocation &Opts,
262262
if (Opts.OutputPath != "-")
263263
sys::RemoveFileOnSignal(Opts.OutputPath);
264264

265-
std::string Error;
266-
raw_fd_ostream *Out =
267-
new raw_fd_ostream(Opts.OutputPath.c_str(), Error,
268-
(Binary ? sys::fs::F_None : sys::fs::F_Text));
269-
if (!Error.empty()) {
270-
Diags.Report(diag::err_fe_unable_to_open_output)
271-
<< Opts.OutputPath << Error;
265+
std::error_code EC;
266+
raw_fd_ostream *Out = new raw_fd_ostream(
267+
Opts.OutputPath, EC, (Binary ? sys::fs::F_None : sys::fs::F_Text));
268+
if (EC) {
269+
Diags.Report(diag::err_fe_unable_to_open_output) << Opts.OutputPath
270+
<< EC.message();
272271
delete Out;
273272
return nullptr;
274273
}

0 commit comments

Comments
 (0)