[llvm] r374024 - [Tools] Mark output of tools as text if it is text
Kai Nacke via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 8 01:21:21 PDT 2019
Author: redstar
Date: Tue Oct 8 01:21:20 2019
New Revision: 374024
URL: http://llvm.org/viewvc/llvm-project?rev=374024&view=rev
Log:
[Tools] Mark output of tools as text if it is text
Several LLVM tools write text files/streams without using OF_Text.
This can cause problems on platforms which distinguish between
text and binary output. This PR adds the OF_Text flag for the
following tools:
- llvm-dis
- llvm-dwarfdump
- llvm-mca
- llvm-mc (assembler files only)
- opt (assembler files only)
- RemarkStreamer (used e.g. by opt)
Reviewers: rnk, vivekvpandya, Bigcheese, andreadb
Differential Revision: https://reviews.llvm.org/D67696
Modified:
llvm/trunk/lib/IR/RemarkStreamer.cpp
llvm/trunk/tools/llvm-dis/llvm-dis.cpp
llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
llvm/trunk/tools/llvm-mc/llvm-mc.cpp
llvm/trunk/tools/llvm-mca/llvm-mca.cpp
llvm/trunk/tools/opt/opt.cpp
Modified: llvm/trunk/lib/IR/RemarkStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/RemarkStreamer.cpp?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- llvm/trunk/lib/IR/RemarkStreamer.cpp (original)
+++ llvm/trunk/lib/IR/RemarkStreamer.cpp Tue Oct 8 01:21:20 2019
@@ -122,18 +122,20 @@ llvm::setupOptimizationRemarks(LLVMConte
if (RemarksFilename.empty())
return nullptr;
+ Expected<remarks::Format> Format = remarks::parseFormat(RemarksFormat);
+ if (Error E = Format.takeError())
+ return make_error<RemarkSetupFormatError>(std::move(E));
+
std::error_code EC;
+ auto Flags = *Format == remarks::Format::YAML ? sys::fs::OF_Text
+ : sys::fs::OF_None;
auto RemarksFile =
- std::make_unique<ToolOutputFile>(RemarksFilename, EC, sys::fs::OF_None);
+ std::make_unique<ToolOutputFile>(RemarksFilename, EC, Flags);
// We don't use llvm::FileError here because some diagnostics want the file
// name separately.
if (EC)
return make_error<RemarkSetupFileError>(errorCodeToError(EC));
- Expected<remarks::Format> Format = remarks::parseFormat(RemarksFormat);
- if (Error E = Format.takeError())
- return make_error<RemarkSetupFormatError>(std::move(E));
-
Expected<std::unique_ptr<remarks::RemarkSerializer>> RemarkSerializer =
remarks::createRemarkSerializer(
*Format, remarks::SerializerMode::Separate, RemarksFile->os());
Modified: llvm/trunk/tools/llvm-dis/llvm-dis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dis/llvm-dis.cpp?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dis/llvm-dis.cpp (original)
+++ llvm/trunk/tools/llvm-dis/llvm-dis.cpp Tue Oct 8 01:21:20 2019
@@ -186,7 +186,7 @@ int main(int argc, char **argv) {
std::error_code EC;
std::unique_ptr<ToolOutputFile> Out(
- new ToolOutputFile(OutputFilename, EC, sys::fs::OF_None));
+ new ToolOutputFile(OutputFilename, EC, sys::fs::OF_Text));
if (EC) {
errs() << EC.message() << '\n';
return 1;
Modified: llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)
+++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Tue Oct 8 01:21:20 2019
@@ -584,7 +584,7 @@ int main(int argc, char **argv) {
}
std::error_code EC;
- ToolOutputFile OutputFile(OutputFilename, EC, sys::fs::OF_None);
+ ToolOutputFile OutputFile(OutputFilename, EC, sys::fs::OF_Text);
error("Unable to open output file" + OutputFilename, EC);
// Don't remove output file if we exit with an error.
OutputFile.keep();
Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Tue Oct 8 01:21:20 2019
@@ -209,9 +209,10 @@ static const Target *GetTarget(const cha
return TheTarget;
}
-static std::unique_ptr<ToolOutputFile> GetOutputStream(StringRef Path) {
+static std::unique_ptr<ToolOutputFile> GetOutputStream(StringRef Path,
+ sys::fs::OpenFlags Flags) {
std::error_code EC;
- auto Out = std::make_unique<ToolOutputFile>(Path, EC, sys::fs::OF_None);
+ auto Out = std::make_unique<ToolOutputFile>(Path, EC, Flags);
if (EC) {
WithColor::error() << EC.message() << '\n';
return nullptr;
@@ -413,7 +414,9 @@ int main(int argc, char **argv) {
FeaturesStr = Features.getString();
}
- std::unique_ptr<ToolOutputFile> Out = GetOutputStream(OutputFilename);
+ sys::fs::OpenFlags Flags = (FileType == OFT_AssemblyFile) ? sys::fs::OF_Text
+ : sys::fs::OF_None;
+ std::unique_ptr<ToolOutputFile> Out = GetOutputStream(OutputFilename, Flags);
if (!Out)
return 1;
@@ -423,7 +426,7 @@ int main(int argc, char **argv) {
WithColor::error() << "dwo output only supported with object files\n";
return 1;
}
- DwoOut = GetOutputStream(SplitDwarfFile);
+ DwoOut = GetOutputStream(SplitDwarfFile, sys::fs::OF_None);
if (!DwoOut)
return 1;
}
Modified: llvm/trunk/tools/llvm-mca/llvm-mca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/llvm-mca.cpp?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/llvm-mca.cpp (original)
+++ llvm/trunk/tools/llvm-mca/llvm-mca.cpp Tue Oct 8 01:21:20 2019
@@ -238,7 +238,7 @@ ErrorOr<std::unique_ptr<ToolOutputFile>>
OutputFilename = "-";
std::error_code EC;
auto Out =
- std::make_unique<ToolOutputFile>(OutputFilename, EC, sys::fs::OF_None);
+ std::make_unique<ToolOutputFile>(OutputFilename, EC, sys::fs::OF_Text);
if (!EC)
return std::move(Out);
return EC;
Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Tue Oct 8 01:21:20 2019
@@ -611,7 +611,9 @@ int main(int argc, char **argv) {
OutputFilename = "-";
std::error_code EC;
- Out.reset(new ToolOutputFile(OutputFilename, EC, sys::fs::OF_None));
+ sys::fs::OpenFlags Flags = OutputAssembly ? sys::fs::OF_Text
+ : sys::fs::OF_None;
+ Out.reset(new ToolOutputFile(OutputFilename, EC, Flags));
if (EC) {
errs() << EC.message() << '\n';
return 1;
More information about the llvm-commits
mailing list