Replace the F_Binary flag with a F_Text one.

After this I will set the default back to F_None. The advantage is that
before this patch forgetting to set F_Binary would corrupt a file on windows.
Forgetting to set F_Text produces one that cannot be read in notepad, which
is a better failure mode :-)

llvm-svn: 202052
This commit is contained in:
Rafael Espindola 2014-02-24 18:20:12 +00:00
parent 8cd1e62020
commit d89ca7eab7
35 changed files with 50 additions and 48 deletions

View File

@ -108,7 +108,7 @@ int main(int argc, char **argv) {
if (OutputFilename != "-") {
std::string ErrInfo;
out = new raw_fd_ostream(OutputFilename.c_str(), ErrInfo,
sys::fs::F_Binary);
sys::fs::F_None);
}
}

View File

@ -69,7 +69,7 @@ public:
errs() << "Writing '" << Filename << "'...";
raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_None);
raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
std::string GraphName = DOTGraphTraits<GraphT>::getGraphName(Graph);
std::string Title = GraphName + " for '" + F.getName().str() + "' function";
@ -132,7 +132,7 @@ public:
errs() << "Writing '" << Filename << "'...";
raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_None);
raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
std::string Title = DOTGraphTraits<GraphT>::getGraphName(Graph);
if (ErrorInfo.empty())

View File

@ -578,9 +578,9 @@ enum OpenFlags {
/// with F_Excl.
F_Append = 2,
/// F_Binary - The file should be opened in binary mode on platforms that
/// make this distinction.
F_Binary = 4,
/// The file should be opened in text mode on platforms that make this
/// distinction.
F_Text = 4,
/// Open the file for read and write.
F_RW = 8

View File

@ -80,7 +80,7 @@ namespace {
errs() << "Writing '" << Filename << "'...";
std::string ErrorInfo;
raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_None);
raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
if (ErrorInfo.empty())
WriteGraph(File, (const Function*)&F);
@ -114,7 +114,7 @@ namespace {
errs() << "Writing '" << Filename << "'...";
std::string ErrorInfo;
raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_None);
raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
if (ErrorInfo.empty())
WriteGraph(File, (const Function*)&F, true);

View File

@ -18,7 +18,7 @@ using namespace llvm;
int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
std::string ErrorInfo;
raw_fd_ostream OS(Path, ErrorInfo, sys::fs::F_Binary);
raw_fd_ostream OS(Path, ErrorInfo, sys::fs::F_None);
if (!ErrorInfo.empty())
return -1;

View File

@ -276,7 +276,8 @@ bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) {
raw_ostream *OutFile = 0;
if (OutFileName) {
std::string ErrorInfo;
OutFile = new raw_fd_ostream(OutFileName, ErrorInfo, sys::fs::F_Append);
OutFile = new raw_fd_ostream(OutFileName, ErrorInfo,
sys::fs::F_Append | sys::fs::F_Text);
if (!ErrorInfo.empty()) {
errs() << "Error opening '" << OutFileName << "': " << ErrorInfo << '\n';
exit(1);

View File

@ -595,7 +595,7 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
rs << round;
std::string graphFileName(fqn + "." + rs.str() + ".pbqpgraph");
std::string tmp;
raw_fd_ostream os(graphFileName.c_str(), tmp, sys::fs::F_None);
raw_fd_ostream os(graphFileName.c_str(), tmp, sys::fs::F_Text);
DEBUG(dbgs() << "Dumping graph for round " << round << " to \""
<< graphFileName << "\"\n");
problem->getGraph().dump(os);

View File

@ -130,7 +130,7 @@ 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_None);
raw_fd_ostream dest(Filename, error, sys::fs::F_Text);
if (!error.empty()) {
*ErrorMessage = strdup(error.c_str());
return true;

View File

@ -482,7 +482,7 @@ void FileInfo::print(StringRef GCNOFile, StringRef GCDAFile) {
std::string CoveragePath = mangleCoveragePath(Filename,
Options.PreservePaths);
std::string ErrorInfo;
raw_fd_ostream OS(CoveragePath.c_str(), ErrorInfo, sys::fs::F_None);
raw_fd_ostream OS(CoveragePath.c_str(), ErrorInfo, sys::fs::F_Text);
if (!ErrorInfo.empty())
errs() << ErrorInfo << "\n";

View File

@ -191,7 +191,7 @@ bool LTOCodeGenerator::writeMergedModules(const char *path,
// create output file
std::string ErrInfo;
tool_output_file Out(path, ErrInfo, sys::fs::F_Binary);
tool_output_file Out(path, ErrInfo, sys::fs::F_None);
if (!ErrInfo.empty()) {
errMsg = "could not open bitcode file for writing: ";
errMsg += path;

View File

@ -634,7 +634,8 @@ bool DarwinAsmParser::ParseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
raw_ostream *OS = getContext().getSecureLog();
if (OS == NULL) {
std::string Err;
OS = new raw_fd_ostream(SecureLogFile, Err, sys::fs::F_Append);
OS = new raw_fd_ostream(SecureLogFile, Err,
sys::fs::F_Append | sys::fs::F_Text);
if (!Err.empty()) {
delete OS;
return Error(IDLoc, Twine("can't open secure log file: ") +

View File

@ -201,9 +201,9 @@ retry_random_path:
// Try to open + create the file.
switch (Type) {
case FS_File: {
if (error_code EC = sys::fs::openFileForWrite(
Twine(ResultPath.begin()), ResultFD,
sys::fs::F_RW | sys::fs::F_Excl | sys::fs::F_Binary, Mode)) {
if (error_code EC =
sys::fs::openFileForWrite(Twine(ResultPath.begin()), ResultFD,
sys::fs::F_RW | sys::fs::F_Excl, Mode)) {
if (EC == errc::file_exists)
goto retry_random_path;
return EC;

View File

@ -66,8 +66,8 @@ raw_ostream *llvm::CreateInfoOutputFile() {
// 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);
raw_ostream *Result = new raw_fd_ostream(
OutputFilename.c_str(), Error, sys::fs::F_Append | sys::fs::F_Text);
if (Error.empty())
return Result;

View File

@ -876,7 +876,7 @@ error_code openFileForWrite(const Twine &Name, int &ResultFD,
if (Flags & F_Append)
OpenFlags |= _O_APPEND;
if (!(Flags & F_Binary))
if (Flags & F_Text)
OpenFlags |= _O_TEXT;
int FD = ::_open_osfhandle(intptr_t(H), OpenFlags);

View File

@ -443,7 +443,7 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
FD = STDOUT_FILENO;
// If user requested binary then put stdout into binary mode if
// possible.
if (Flags & sys::fs::F_Binary)
if (!(Flags & sys::fs::F_Text))
sys::ChangeStdoutToBinary();
// Close stdout when we're done, to detect any output errors.
ShouldClose = true;

View File

@ -57,7 +57,7 @@ static int createDependencyFile(const TGParser &Parser, const char *argv0) {
return 1;
}
std::string Error;
tool_output_file DepOut(DependFilename.c_str(), Error, sys::fs::F_None);
tool_output_file DepOut(DependFilename.c_str(), Error, sys::fs::F_Text);
if (!Error.empty()) {
errs() << argv0 << ": error opening " << DependFilename
<< ":" << Error << "\n";
@ -103,7 +103,7 @@ int TableGenMain(char *argv0, TableGenMainFn *MainFn) {
return 1;
std::string Error;
tool_output_file Out(OutputFilename.c_str(), Error, sys::fs::F_None);
tool_output_file Out(OutputFilename.c_str(), Error, sys::fs::F_Text);
if (!Error.empty()) {
errs() << argv0 << ": error opening " << OutputFilename
<< ":" << Error << "\n";

View File

@ -238,7 +238,7 @@ 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_Binary);
raw_fd_ostream dest(Filename, error, sys::fs::F_None);
if (!error.empty()) {
*ErrorMessage = strdup(error.c_str());
return true;

View File

@ -528,7 +528,7 @@ void DebugIR::writeDebugBitcode(const Module *M, int *fd) {
if (!fd) {
std::string Path = getPath();
Out.reset(new raw_fd_ostream(Path.c_str(), error, sys::fs::F_None));
Out.reset(new raw_fd_ostream(Path.c_str(), error, sys::fs::F_Text));
DEBUG(dbgs() << "WRITING debug bitcode from Module " << M << " to file "
<< Path << "\n");
} else {

View File

@ -466,7 +466,7 @@ void GCOVProfiler::emitProfileNotes() {
DICompileUnit CU(CU_Nodes->getOperand(i));
std::string ErrorInfo;
raw_fd_ostream out(mangleName(CU, "gcno").c_str(), ErrorInfo,
sys::fs::F_Binary);
sys::fs::F_None);
std::string EdgeDestinations;
DIArray SPs = CU.getSubprograms();

View File

@ -71,7 +71,7 @@ bool BugDriver::writeProgramToFile(const std::string &Filename, int FD,
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_Binary);
tool_output_file Out(Filename.c_str(), ErrInfo, sys::fs::F_None);
if (ErrInfo.empty())
return writeProgramToFileAux(Out, M);
return true;

View File

@ -150,8 +150,8 @@ static tool_output_file *GetOutputStream(const char *TargetName,
// Open the file.
std::string error;
sys::fs::OpenFlags OpenFlags = sys::fs::F_None;
if (Binary)
OpenFlags |= sys::fs::F_Binary;
if (!Binary)
OpenFlags |= sys::fs::F_Text;
tool_output_file *FDOut = new tool_output_file(OutputFilename.c_str(), error,
OpenFlags);
if (!error.empty()) {

View File

@ -273,7 +273,7 @@ public:
sys::path::remove_filename(dir);
sys::fs::create_directories(Twine(dir));
}
raw_fd_ostream outfile(CacheName.c_str(), errStr, sys::fs::F_Binary);
raw_fd_ostream outfile(CacheName.c_str(), errStr, sys::fs::F_None);
outfile.write(Obj->getBufferStart(), Obj->getBufferSize());
outfile.close();
}

View File

@ -322,7 +322,7 @@ static void doExtract(StringRef Name, object::Archive::child_iterator I) {
int FD;
failIfError(
sys::fs::openFileForWrite(Storage.c_str(), FD, sys::fs::F_Binary, Mode),
sys::fs::openFileForWrite(Storage.c_str(), FD, sys::fs::F_None, Mode),
Storage.c_str());
{

View File

@ -70,7 +70,7 @@ static void WriteOutputFile(const Module *M) {
std::string ErrorInfo;
OwningPtr<tool_output_file> Out(new tool_output_file(
OutputFilename.c_str(), ErrorInfo, sys::fs::F_Binary));
OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
exit(1);

View File

@ -172,7 +172,7 @@ int main(int argc, char **argv) {
std::string ErrorInfo;
OwningPtr<tool_output_file> Out(new tool_output_file(
OutputFilename.c_str(), ErrorInfo, sys::fs::F_Binary));
OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;

View File

@ -265,7 +265,7 @@ int main(int argc, char **argv) {
Passes.add(createStripDeadPrototypesPass()); // Remove dead func decls
std::string ErrorInfo;
tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_Binary);
tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None);
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;

View File

@ -110,7 +110,7 @@ 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_Binary);
tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None);
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;

View File

@ -142,7 +142,7 @@ int main(int argc, char **argv) {
}
raw_fd_ostream FileStream(OutputFilename.c_str(), ErrorInfo,
sys::fs::F_Binary);
sys::fs::F_None);
if (!ErrorInfo.empty()) {
errs() << argv[0] << ": error opening the file '" << OutputFilename
<< "': " << ErrorInfo << "\n";

View File

@ -211,7 +211,7 @@ static tool_output_file *GetOutputStream() {
std::string Err;
tool_output_file *Out =
new tool_output_file(OutputFilename.c_str(), Err, sys::fs::F_Binary);
new tool_output_file(OutputFilename.c_str(), Err, sys::fs::F_None);
if (!Err.empty()) {
errs() << Err << '\n';
delete Out;

View File

@ -192,7 +192,7 @@ 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_None);
raw_fd_ostream Out(FileName, Error, sys::fs::F_Text);
if (!Error.empty()) {
errs() << "llvm-objdump: warning: " << Error << '\n';
return;
@ -373,7 +373,7 @@ 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_None);
raw_fd_ostream YAMLOut(YAMLCFG.c_str(), Error, sys::fs::F_Text);
if (!Error.empty()) {
errs() << ToolName << ": warning: " << Error << '\n';
return;

View File

@ -112,7 +112,7 @@ int main(int argc, char **argv) {
OutputFilename = "-";
std::string ErrorInfo;
raw_fd_ostream Output(OutputFilename.data(), ErrorInfo, sys::fs::F_None);
raw_fd_ostream Output(OutputFilename.data(), ErrorInfo, sys::fs::F_Text);
if (!ErrorInfo.empty())
exitWithError(ErrorInfo, OutputFilename);

View File

@ -705,7 +705,7 @@ int main(int argc, char **argv) {
std::string ErrorInfo;
Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
sys::fs::F_Binary));
sys::fs::F_None));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;

View File

@ -381,7 +381,7 @@ int main(int argc, char **argv) {
std::string ErrorInfo;
Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
sys::fs::F_Binary));
sys::fs::F_None));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;
@ -467,7 +467,7 @@ int main(int argc, char **argv) {
std::string ErrorInfo;
Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
sys::fs::F_Binary));
sys::fs::F_None));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;

View File

@ -501,7 +501,7 @@ TEST_F(FileSystemTest, Magic) {
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_Binary);
raw_fd_ostream file(file_pathname.c_str(), ErrMsg, sys::fs::F_None);
ASSERT_FALSE(file.has_error());
StringRef magic(i->magic_str, i->magic_str_len);
file << magic;
@ -521,7 +521,7 @@ TEST_F(FileSystemTest, CarriageReturn) {
path::append(FilePathname, "test");
{
raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_None);
raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_Text);
EXPECT_EQ(ErrMsg, "");
File << '\n';
}
@ -532,7 +532,7 @@ TEST_F(FileSystemTest, CarriageReturn) {
}
{
raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_Binary);
raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_None);
EXPECT_EQ(ErrMsg, "");
File << '\n';
}

View File

@ -71,7 +71,7 @@ int main(int argc, char **argv) {
<< "', contents changed.\n";
std::string ErrorStr;
tool_output_file OutStream(OutputFilename.c_str(), ErrorStr,
sys::fs::F_Binary);
sys::fs::F_None);
if (!ErrorStr.empty()) {
errs() << argv[0] << ": Unable to write output '"
<< OutputFilename << "': " << ErrorStr << '\n';