1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-21 18:22:53 +01:00

[NFC] Reordering parameters in getFile and getFileOrSTDIN

In future patches I will be setting the IsText parameter frequently so I will refactor the args to be in the following order. I have removed the FileSize parameter because it is never used.

```
  static ErrorOr<std::unique_ptr<MemoryBuffer>>
  getFile(const Twine &Filename, bool IsText = false,
          bool RequiresNullTerminator = true, bool IsVolatile = false);

  static ErrorOr<std::unique_ptr<MemoryBuffer>>
  getFileOrSTDIN(const Twine &Filename, bool IsText = false,
                 bool RequiresNullTerminator = true);

 static ErrorOr<std::unique_ptr<MB>>
 getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
            bool IsText, bool RequiresNullTerminator, bool IsVolatile);

  static ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
  getFile(const Twine &Filename, bool IsVolatile = false);
```

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D99182
This commit is contained in:
Abhina Sreeskantharajan 2021-03-25 09:47:25 -04:00
parent 9c42655c14
commit d30f6cb8e4
22 changed files with 77 additions and 81 deletions

View File

@ -75,20 +75,17 @@ public:
virtual StringRef getBufferIdentifier() const { return "Unknown buffer"; } virtual StringRef getBufferIdentifier() const { return "Unknown buffer"; }
/// Open the specified file as a MemoryBuffer, returning a new MemoryBuffer /// Open the specified file as a MemoryBuffer, returning a new MemoryBuffer
/// if successful, otherwise returning null. If FileSize is specified, this /// if successful, otherwise returning null.
/// means that the client knows that the file exists and that it has the ///
/// specified size. /// \param IsText Set to true to indicate that the file should be read in
/// text mode.
/// ///
/// \param IsVolatile Set to true to indicate that the contents of the file /// \param IsVolatile Set to true to indicate that the contents of the file
/// can change outside the user's control, e.g. when libclang tries to parse /// can change outside the user's control, e.g. when libclang tries to parse
/// while the user is editing/updating the file or if the file is on an NFS. /// while the user is editing/updating the file or if the file is on an NFS.
///
/// \param IsText Set to true to indicate that the file should be read in
/// text mode.
static ErrorOr<std::unique_ptr<MemoryBuffer>> static ErrorOr<std::unique_ptr<MemoryBuffer>>
getFile(const Twine &Filename, int64_t FileSize = -1, getFile(const Twine &Filename, bool IsText = false,
bool RequiresNullTerminator = true, bool IsVolatile = false, bool RequiresNullTerminator = true, bool IsVolatile = false);
bool IsText = false);
/// Read all of the specified file into a MemoryBuffer as a stream /// Read all of the specified file into a MemoryBuffer as a stream
/// (i.e. until EOF reached). This is useful for special files that /// (i.e. until EOF reached). This is useful for special files that
@ -133,8 +130,8 @@ public:
/// Open the specified file as a MemoryBuffer, or open stdin if the Filename /// Open the specified file as a MemoryBuffer, or open stdin if the Filename
/// is "-". /// is "-".
static ErrorOr<std::unique_ptr<MemoryBuffer>> static ErrorOr<std::unique_ptr<MemoryBuffer>>
getFileOrSTDIN(const Twine &Filename, int64_t FileSize = -1, getFileOrSTDIN(const Twine &Filename, bool IsText = false,
bool RequiresNullTerminator = true, bool IsText = false); bool RequiresNullTerminator = true);
/// Map a subrange of the specified file as a MemoryBuffer. /// Map a subrange of the specified file as a MemoryBuffer.
static ErrorOr<std::unique_ptr<MemoryBuffer>> static ErrorOr<std::unique_ptr<MemoryBuffer>>
@ -184,8 +181,7 @@ public:
} }
static ErrorOr<std::unique_ptr<WritableMemoryBuffer>> static ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
getFile(const Twine &Filename, int64_t FileSize = -1, getFile(const Twine &Filename, bool IsVolatile = false);
bool IsVolatile = false);
/// Map a subrange of the specified file as a WritableMemoryBuffer. /// Map a subrange of the specified file as a WritableMemoryBuffer.
static ErrorOr<std::unique_ptr<WritableMemoryBuffer>> static ErrorOr<std::unique_ptr<WritableMemoryBuffer>>

View File

@ -223,7 +223,8 @@ file_magic llvm::identify_magic(StringRef Magic) {
} }
std::error_code llvm::identify_magic(const Twine &Path, file_magic &Result) { std::error_code llvm::identify_magic(const Twine &Path, file_magic &Result) {
auto FileOrError = MemoryBuffer::getFile(Path, -1LL, false); auto FileOrError = MemoryBuffer::getFile(Path, /*IsText=*/false,
/*RequiresNullTerminator=*/false);
if (!FileOrError) if (!FileOrError)
return FileOrError.getError(); return FileOrError.getError();

View File

@ -83,7 +83,7 @@ Error NativeSession::createFromPdb(std::unique_ptr<MemoryBuffer> Buffer,
static Expected<std::unique_ptr<PDBFile>> static Expected<std::unique_ptr<PDBFile>>
loadPdbFile(StringRef PdbPath, std::unique_ptr<BumpPtrAllocator> &Allocator) { loadPdbFile(StringRef PdbPath, std::unique_ptr<BumpPtrAllocator> &Allocator) {
ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer = ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
MemoryBuffer::getFile(PdbPath, /*FileSize=*/-1, MemoryBuffer::getFile(PdbPath, /*IsText=*/false,
/*RequiresNullTerminator=*/false); /*RequiresNullTerminator=*/false);
if (!ErrorOrBuffer) if (!ErrorOrBuffer)
return make_error<RawError>(ErrorOrBuffer.getError()); return make_error<RawError>(ErrorOrBuffer.getError());

View File

@ -153,7 +153,7 @@ int llvm::runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne,
continue; continue;
} }
auto BufOrErr = MemoryBuffer::getFile(Arg, /*FileSize-*/ -1, auto BufOrErr = MemoryBuffer::getFile(Arg, /*IsText=*/false,
/*RequiresNullTerminator=*/false); /*RequiresNullTerminator=*/false);
if (std::error_code EC = BufOrErr.getError()) { if (std::error_code EC = BufOrErr.getError()) {
errs() << "Error reading file: " << Arg << ": " << EC.message() << "\n"; errs() << "Error reading file: " << Arg << ": " << EC.message() << "\n";

View File

@ -92,9 +92,7 @@ std::unique_ptr<Module>
llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
DataLayoutCallbackTy DataLayoutCallback) { DataLayoutCallbackTy DataLayoutCallback) {
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr = ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
MemoryBuffer::getFileOrSTDIN(Filename, /*FileSize=*/-1, MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true);
/*RequiresNullTerminator=*/true,
/*IsText=*/true);
if (std::error_code EC = FileOrErr.getError()) { if (std::error_code EC = FileOrErr.getError()) {
Err = SMDiagnostic(Filename, SourceMgr::DK_Error, Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
"Could not open input file: " + EC.message()); "Could not open input file: " + EC.message());

View File

@ -285,8 +285,8 @@ LTOCodeGenerator::compileOptimized() {
return nullptr; return nullptr;
// read .o file into memory buffer // read .o file into memory buffer
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = MemoryBuffer::getFile(
MemoryBuffer::getFile(name, -1, false); name, /*IsText=*/false, /*RequiresNullTerminator=*/false);
if (std::error_code EC = BufferOrErr.getError()) { if (std::error_code EC = BufferOrErr.getError()) {
emitError(EC.message()); emitError(EC.message());
sys::fs::remove(NativeObjectPath); sys::fs::remove(NativeObjectPath);

View File

@ -97,7 +97,7 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
Expected<OwningBinary<Binary>> Expected<OwningBinary<Binary>>
object::createBinary(StringRef Path, LLVMContext *Context, bool InitContent) { object::createBinary(StringRef Path, LLVMContext *Context, bool InitContent) {
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr = ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1, MemoryBuffer::getFileOrSTDIN(Path, /*IsText=*/false,
/*RequiresNullTerminator=*/false); /*RequiresNullTerminator=*/false);
if (std::error_code EC = FileOrErr.getError()) if (std::error_code EC = FileOrErr.getError())
return errorCodeToError(EC); return errorCodeToError(EC);

View File

@ -564,7 +564,7 @@ public:
// Open source files without requiring a NUL terminator. The concurrent // Open source files without requiring a NUL terminator. The concurrent
// modification may nullify the NUL terminator condition. // modification may nullify the NUL terminator condition.
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getFileOrSTDIN(Filename, -1, MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/false,
/*RequiresNullTerminator=*/false); /*RequiresNullTerminator=*/false);
if (std::error_code EC = BufferOrErr.getError()) { if (std::error_code EC = BufferOrErr.getError()) {
errs() << Filename << ": " << EC.message() << "\n"; errs() << Filename << ": " << EC.message() << "\n";

View File

@ -105,9 +105,8 @@ public:
template <typename MB> template <typename MB>
static ErrorOr<std::unique_ptr<MB>> static ErrorOr<std::unique_ptr<MB>>
getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize, getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile, bool IsText, bool RequiresNullTerminator, bool IsVolatile);
bool IsText);
std::unique_ptr<MemoryBuffer> std::unique_ptr<MemoryBuffer>
MemoryBuffer::getMemBuffer(StringRef InputData, StringRef BufferName, MemoryBuffer::getMemBuffer(StringRef InputData, StringRef BufferName,
@ -141,21 +140,22 @@ MemoryBuffer::getMemBufferCopy(StringRef InputData, const Twine &BufferName) {
} }
ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOr<std::unique_ptr<MemoryBuffer>>
MemoryBuffer::getFileOrSTDIN(const Twine &Filename, int64_t FileSize, MemoryBuffer::getFileOrSTDIN(const Twine &Filename, bool IsText,
bool RequiresNullTerminator, bool IsText) { bool RequiresNullTerminator) {
SmallString<256> NameBuf; SmallString<256> NameBuf;
StringRef NameRef = Filename.toStringRef(NameBuf); StringRef NameRef = Filename.toStringRef(NameBuf);
if (NameRef == "-") if (NameRef == "-")
return getSTDIN(); return getSTDIN();
return getFile(Filename, FileSize, RequiresNullTerminator, false, IsText); return getFile(Filename, IsText, RequiresNullTerminator,
/*IsVolatile=*/false);
} }
ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOr<std::unique_ptr<MemoryBuffer>>
MemoryBuffer::getFileSlice(const Twine &FilePath, uint64_t MapSize, MemoryBuffer::getFileSlice(const Twine &FilePath, uint64_t MapSize,
uint64_t Offset, bool IsVolatile) { uint64_t Offset, bool IsVolatile) {
return getFileAux<MemoryBuffer>(FilePath, -1, MapSize, Offset, false, return getFileAux<MemoryBuffer>(FilePath, MapSize, Offset, /*IsText=*/false,
IsVolatile, false); /*RequiresNullTerminator=*/false, IsVolatile);
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -242,11 +242,10 @@ getMemoryBufferForStream(sys::fs::file_t FD, const Twine &BufferName) {
} }
ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOr<std::unique_ptr<MemoryBuffer>>
MemoryBuffer::getFile(const Twine &Filename, int64_t FileSize, MemoryBuffer::getFile(const Twine &Filename, bool IsText,
bool RequiresNullTerminator, bool IsVolatile, bool RequiresNullTerminator, bool IsVolatile) {
bool IsText) { return getFileAux<MemoryBuffer>(Filename, /*MapSize=*/-1, /*Offset=*/0,
return getFileAux<MemoryBuffer>(Filename, FileSize, FileSize, 0, IsText, RequiresNullTerminator, IsVolatile);
RequiresNullTerminator, IsVolatile, IsText);
} }
template <typename MB> template <typename MB>
@ -257,33 +256,32 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
template <typename MB> template <typename MB>
static ErrorOr<std::unique_ptr<MB>> static ErrorOr<std::unique_ptr<MB>>
getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize, getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile, bool IsText, bool RequiresNullTerminator, bool IsVolatile) {
bool IsText) {
Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForRead( Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForRead(
Filename, IsText ? sys::fs::OF_Text : sys::fs::OF_None); Filename, IsText ? sys::fs::OF_Text : sys::fs::OF_None);
if (!FDOrErr) if (!FDOrErr)
return errorToErrorCode(FDOrErr.takeError()); return errorToErrorCode(FDOrErr.takeError());
sys::fs::file_t FD = *FDOrErr; sys::fs::file_t FD = *FDOrErr;
auto Ret = getOpenFileImpl<MB>(FD, Filename, FileSize, MapSize, Offset, auto Ret = getOpenFileImpl<MB>(FD, Filename, /*FileSize=*/-1, MapSize, Offset,
RequiresNullTerminator, IsVolatile); RequiresNullTerminator, IsVolatile);
sys::fs::closeFile(FD); sys::fs::closeFile(FD);
return Ret; return Ret;
} }
ErrorOr<std::unique_ptr<WritableMemoryBuffer>> ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
WritableMemoryBuffer::getFile(const Twine &Filename, int64_t FileSize, WritableMemoryBuffer::getFile(const Twine &Filename, bool IsVolatile) {
bool IsVolatile) { return getFileAux<WritableMemoryBuffer>(
return getFileAux<WritableMemoryBuffer>(Filename, FileSize, FileSize, 0, Filename, /*MapSize=*/-1, /*Offset=*/0, /*IsText=*/false,
/*RequiresNullTerminator*/ false, /*RequiresNullTerminator=*/false, IsVolatile);
IsVolatile, false);
} }
ErrorOr<std::unique_ptr<WritableMemoryBuffer>> ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
WritableMemoryBuffer::getFileSlice(const Twine &Filename, uint64_t MapSize, WritableMemoryBuffer::getFileSlice(const Twine &Filename, uint64_t MapSize,
uint64_t Offset, bool IsVolatile) { uint64_t Offset, bool IsVolatile) {
return getFileAux<WritableMemoryBuffer>(Filename, -1, MapSize, Offset, false, return getFileAux<WritableMemoryBuffer>(
IsVolatile, false); Filename, MapSize, Offset, /*IsText=*/false,
/*RequiresNullTerminator=*/false, IsVolatile);
} }
std::unique_ptr<WritableMemoryBuffer> std::unique_ptr<WritableMemoryBuffer>

View File

@ -93,9 +93,7 @@ int llvm::TableGenMain(const char *argv0, TableGenMainFn *MainFn) {
Records.startTimer("Parse, build records"); Records.startTimer("Parse, build records");
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr = ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
MemoryBuffer::getFileOrSTDIN(InputFilename, /*FileSize=*/-1, MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true);
/*RequiresNullTerminator=*/true,
/*IsText=*/true);
if (std::error_code EC = FileOrErr.getError()) if (std::error_code EC = FileOrErr.getError())
return reportError(argv0, "Could not open input file '" + InputFilename + return reportError(argv0, "Could not open input file '" + InputFilename +
"': " + EC.message() + "\n"); "': " + EC.message() + "\n");
@ -139,9 +137,8 @@ int llvm::TableGenMain(const char *argv0, TableGenMainFn *MainFn) {
// Only updates the real output file if there are any differences. // Only updates the real output file if there are any differences.
// This prevents recompilation of all the files depending on it if there // This prevents recompilation of all the files depending on it if there
// aren't any. // aren't any.
if (auto ExistingOrErr = MemoryBuffer::getFile( if (auto ExistingOrErr =
OutputFilename, /*FileSize=*/-1, /*RequiresNullTerminator=*/true, MemoryBuffer::getFile(OutputFilename, /*IsText=*/true))
/*IsVolatile=*/false, /*IsText=*/true))
if (std::move(ExistingOrErr.get())->getBuffer() == Out.str()) if (std::move(ExistingOrErr.get())->getBuffer() == Out.str())
WriteFile = false; WriteFile = false;
} }

View File

@ -112,8 +112,8 @@ static void doList(opt::InputArgList& Args) {
std::unique_ptr<MemoryBuffer> B; std::unique_ptr<MemoryBuffer> B;
for (auto *Arg : Args.filtered(OPT_INPUT)) { for (auto *Arg : Args.filtered(OPT_INPUT)) {
// Create or open the archive object. // Create or open the archive object.
ErrorOr<std::unique_ptr<MemoryBuffer>> MaybeBuf = ErrorOr<std::unique_ptr<MemoryBuffer>> MaybeBuf = MemoryBuffer::getFile(
MemoryBuffer::getFile(Arg->getValue(), -1, false); Arg->getValue(), /*IsText=*/false, /*RequiresNullTerminator=*/false);
fatalOpenError(errorCodeToError(MaybeBuf.getError()), Arg->getValue()); fatalOpenError(errorCodeToError(MaybeBuf.getError()), Arg->getValue());
if (identify_magic(MaybeBuf.get()->getBuffer()) == file_magic::archive) { if (identify_magic(MaybeBuf.get()->getBuffer()) == file_magic::archive) {
@ -339,8 +339,8 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) {
continue; continue;
// Open a file. // Open a file.
ErrorOr<std::unique_ptr<MemoryBuffer>> MOrErr = ErrorOr<std::unique_ptr<MemoryBuffer>> MOrErr = MemoryBuffer::getFile(
MemoryBuffer::getFile(Path, -1, false); Path, /*IsText=*/false, /*RequiresNullTerminator=*/false);
fatalOpenError(errorCodeToError(MOrErr.getError()), Path); fatalOpenError(errorCodeToError(MOrErr.getError()), Path);
MemoryBufferRef MBRef = (*MOrErr)->getMemBufferRef(); MemoryBufferRef MBRef = (*MOrErr)->getMemBufferRef();

View File

@ -327,7 +327,8 @@ public:
return nullptr; return nullptr;
// Load the object from the cache filename // Load the object from the cache filename
ErrorOr<std::unique_ptr<MemoryBuffer>> IRObjectBuffer = ErrorOr<std::unique_ptr<MemoryBuffer>> IRObjectBuffer =
MemoryBuffer::getFile(CacheName, -1, false); MemoryBuffer::getFile(CacheName, /*IsText=*/false,
/*RequiresNullTerminator=*/false);
// If the file isn't there, that's OK. // If the file isn't there, that's OK.
if (!IRObjectBuffer) if (!IRObjectBuffer)
return nullptr; return nullptr;

View File

@ -270,7 +270,8 @@ static void getArchive() {
} }
static object::Archive &readLibrary(const Twine &Library) { static object::Archive &readLibrary(const Twine &Library) {
auto BufOrErr = MemoryBuffer::getFile(Library, -1, false); auto BufOrErr = MemoryBuffer::getFile(Library, /*IsText=*/false,
/*RequiresNullTerminator=*/false);
failIfError(BufOrErr.getError(), "could not open library " + Library); failIfError(BufOrErr.getError(), "could not open library " + Library);
ArchiveBuffers.push_back(std::move(*BufOrErr)); ArchiveBuffers.push_back(std::move(*BufOrErr));
auto LibOrErr = auto LibOrErr =
@ -995,8 +996,8 @@ static void performOperation(ArchiveOperation Operation,
static int performOperation(ArchiveOperation Operation, static int performOperation(ArchiveOperation Operation,
std::vector<NewArchiveMember> *NewMembers) { std::vector<NewArchiveMember> *NewMembers) {
// Create or open the archive object. // Create or open the archive object.
ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = MemoryBuffer::getFile(
MemoryBuffer::getFile(ArchiveName, -1, false); ArchiveName, /*IsText=*/false, /*RequiresNullTerminator=*/false);
std::error_code EC = Buf.getError(); std::error_code EC = Buf.getError();
if (EC && EC != errc::no_such_file_or_directory) if (EC && EC != errc::no_such_file_or_directory)
fail("unable to open '" + ArchiveName + "': " + EC.message()); fail("unable to open '" + ArchiveName + "': " + EC.message());

View File

@ -46,7 +46,8 @@ static void reportCoverage(StringRef SourceFile, StringRef ObjectDir,
// Open .gcda and .gcda without requiring a NUL terminator. The concurrent // Open .gcda and .gcda without requiring a NUL terminator. The concurrent
// modification may nullify the NUL terminator condition. // modification may nullify the NUL terminator condition.
ErrorOr<std::unique_ptr<MemoryBuffer>> GCNO_Buff = ErrorOr<std::unique_ptr<MemoryBuffer>> GCNO_Buff =
MemoryBuffer::getFileOrSTDIN(GCNO, -1, /*RequiresNullTerminator=*/false); MemoryBuffer::getFileOrSTDIN(GCNO, /*IsText=*/false,
/*RequiresNullTerminator=*/false);
if (std::error_code EC = GCNO_Buff.getError()) { if (std::error_code EC = GCNO_Buff.getError()) {
errs() << GCNO << ": " << EC.message() << "\n"; errs() << GCNO << ": " << EC.message() << "\n";
return; return;
@ -58,7 +59,8 @@ static void reportCoverage(StringRef SourceFile, StringRef ObjectDir,
} }
ErrorOr<std::unique_ptr<MemoryBuffer>> GCDA_Buff = ErrorOr<std::unique_ptr<MemoryBuffer>> GCDA_Buff =
MemoryBuffer::getFileOrSTDIN(GCDA, -1, /*RequiresNullTerminator=*/false); MemoryBuffer::getFileOrSTDIN(GCDA, /*IsText=*/false,
/*RequiresNullTerminator=*/false);
if (std::error_code EC = GCDA_Buff.getError()) { if (std::error_code EC = GCDA_Buff.getError()) {
if (EC != errc::no_such_file_or_directory) { if (EC != errc::no_such_file_or_directory) {
errs() << GCDA << ": " << EC.message() << "\n"; errs() << GCDA << ": " << EC.message() << "\n";

View File

@ -147,7 +147,7 @@ static Error processFileList() {
std::tie(FileName, DirName) = StringRef(FileList).rsplit(","); std::tie(FileName, DirName) = StringRef(FileList).rsplit(",");
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr = ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
MemoryBuffer::getFileOrSTDIN(FileName, /*FileSize=*/-1, MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/false,
/*RequiresNullTerminator=*/false); /*RequiresNullTerminator=*/false);
if (std::error_code EC = FileOrErr.getError()) if (std::error_code EC = FileOrErr.getError())
return createFileError(FileName, errorCodeToError(EC)); return createFileError(FileName, errorCodeToError(EC));

View File

@ -288,7 +288,8 @@ Expected<InputFile> InputFile::open(StringRef Path, bool AllowUnknownFile) {
formatv("File {0} is not a supported file type", Path), formatv("File {0} is not a supported file type", Path),
inconvertibleErrorCode()); inconvertibleErrorCode());
auto Result = MemoryBuffer::getFile(Path, -1LL, false); auto Result = MemoryBuffer::getFile(Path, /*IsText=*/false,
/*RequiresNullTerminator=*/false);
if (!Result) if (!Result)
return make_error<StringError>( return make_error<StringError>(
formatv("File {0} could not be opened", Path), Result.getError()); formatv("File {0} could not be opened", Path), Result.getError());

View File

@ -748,7 +748,7 @@ static ExitOnError ExitOnErr;
static void yamlToPdb(StringRef Path) { static void yamlToPdb(StringRef Path) {
BumpPtrAllocator Allocator; BumpPtrAllocator Allocator;
ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer = ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1, MemoryBuffer::getFileOrSTDIN(Path, /*IsText=*/false,
/*RequiresNullTerminator=*/false); /*RequiresNullTerminator=*/false);
if (ErrorOrBuffer.getError()) { if (ErrorOrBuffer.getError()) {

View File

@ -1524,14 +1524,16 @@ ResourceFileWriter::loadFile(StringRef File) const {
// properly though, so if using that to append paths below, this early // properly though, so if using that to append paths below, this early
// exception case could be removed.) // exception case could be removed.)
if (sys::path::has_root_directory(File)) if (sys::path::has_root_directory(File))
return errorOrToExpected(MemoryBuffer::getFile(File, -1, false)); return errorOrToExpected(MemoryBuffer::getFile(
File, /*IsText=*/false, /*RequiresNullTerminator=*/false));
// 1. The current working directory. // 1. The current working directory.
sys::fs::current_path(Cwd); sys::fs::current_path(Cwd);
Path.assign(Cwd.begin(), Cwd.end()); Path.assign(Cwd.begin(), Cwd.end());
sys::path::append(Path, File); sys::path::append(Path, File);
if (sys::fs::exists(Path)) if (sys::fs::exists(Path))
return errorOrToExpected(MemoryBuffer::getFile(Path, -1, false)); return errorOrToExpected(MemoryBuffer::getFile(
Path, /*IsText=*/false, /*RequiresNullTerminator=*/false));
// 2. The directory of the input resource file, if it is different from the // 2. The directory of the input resource file, if it is different from the
// current working directory. // current working directory.
@ -1539,19 +1541,22 @@ ResourceFileWriter::loadFile(StringRef File) const {
Path.assign(InputFileDir.begin(), InputFileDir.end()); Path.assign(InputFileDir.begin(), InputFileDir.end());
sys::path::append(Path, File); sys::path::append(Path, File);
if (sys::fs::exists(Path)) if (sys::fs::exists(Path))
return errorOrToExpected(MemoryBuffer::getFile(Path, -1, false)); return errorOrToExpected(MemoryBuffer::getFile(
Path, /*IsText=*/false, /*RequiresNullTerminator=*/false));
// 3. All of the include directories specified on the command line. // 3. All of the include directories specified on the command line.
for (StringRef ForceInclude : Params.Include) { for (StringRef ForceInclude : Params.Include) {
Path.assign(ForceInclude.begin(), ForceInclude.end()); Path.assign(ForceInclude.begin(), ForceInclude.end());
sys::path::append(Path, File); sys::path::append(Path, File);
if (sys::fs::exists(Path)) if (sys::fs::exists(Path))
return errorOrToExpected(MemoryBuffer::getFile(Path, -1, false)); return errorOrToExpected(MemoryBuffer::getFile(
Path, /*IsText=*/false, /*RequiresNullTerminator=*/false));
} }
if (auto Result = if (auto Result =
llvm::sys::Process::FindInEnvPath("INCLUDE", File, Params.NoInclude)) llvm::sys::Process::FindInEnvPath("INCLUDE", File, Params.NoInclude))
return errorOrToExpected(MemoryBuffer::getFile(*Result, -1, false)); return errorOrToExpected(MemoryBuffer::getFile(
*Result, /*IsText=*/false, /*RequiresNullTerminator=*/false));
return make_error<StringError>("error : file not found : " + Twine(File), return make_error<StringError>("error : file not found : " + Twine(File),
inconvertibleErrorCode()); inconvertibleErrorCode());

View File

@ -653,7 +653,7 @@ static void dumpWindowsResourceFile(WindowsResource *WinRes,
/// Opens \a File and dumps it. /// Opens \a File and dumps it.
static void dumpInput(StringRef File, ScopedPrinter &Writer) { static void dumpInput(StringRef File, ScopedPrinter &Writer) {
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr = ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
MemoryBuffer::getFileOrSTDIN(File, /*FileSize=*/-1, MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/false,
/*RequiresNullTerminator=*/false); /*RequiresNullTerminator=*/false);
if (std::error_code EC = FileOrErr.getError()) if (std::error_code EC = FileOrErr.getError())
return reportError(errorCodeToError(EC), File); return reportError(errorCodeToError(EC), File);

View File

@ -36,7 +36,7 @@ static Error dumpObject(const ObjectFile &Obj) {
static Error dumpInput(StringRef File) { static Error dumpInput(StringRef File) {
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr = ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
MemoryBuffer::getFileOrSTDIN(File, /*FileSize=*/-1, MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/false,
/*RequiresNullTerminator=*/false); /*RequiresNullTerminator=*/false);
if (std::error_code EC = FileOrErr.getError()) if (std::error_code EC = FileOrErr.getError())
return errorCodeToError(EC); return errorCodeToError(EC);

View File

@ -125,8 +125,8 @@ int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, cl::ParseCommandLineOptions(argc, argv,
"Sanitizer Statistics Processing Tool"); "Sanitizer Statistics Processing Tool");
ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = MemoryBuffer::getFile(
MemoryBuffer::getFile(ClInputFile, -1, false); ClInputFile, /*IsText=*/false, /*RequiresNullTerminator=*/false);
if (!MBOrErr) { if (!MBOrErr) {
errs() << argv[0] << ": " << ClInputFile << ": " errs() << argv[0] << ": " << ClInputFile << ": "
<< MBOrErr.getError().message() << '\n'; << MBOrErr.getError().message() << '\n';

View File

@ -821,9 +821,7 @@ int main(int argc, char **argv) {
// Read the expected strings from the check file. // Read the expected strings from the check file.
ErrorOr<std::unique_ptr<MemoryBuffer>> CheckFileOrErr = ErrorOr<std::unique_ptr<MemoryBuffer>> CheckFileOrErr =
MemoryBuffer::getFileOrSTDIN(CheckFilename, /*FileSize=*/-1, MemoryBuffer::getFileOrSTDIN(CheckFilename, /*IsText=*/true);
/*RequiresNullTerminator=*/true,
/*IsText=*/true);
if (std::error_code EC = CheckFileOrErr.getError()) { if (std::error_code EC = CheckFileOrErr.getError()) {
errs() << "Could not open check file '" << CheckFilename errs() << "Could not open check file '" << CheckFilename
<< "': " << EC.message() << '\n'; << "': " << EC.message() << '\n';
@ -845,9 +843,7 @@ int main(int argc, char **argv) {
// Open the file to check and add it to SourceMgr. // Open the file to check and add it to SourceMgr.
ErrorOr<std::unique_ptr<MemoryBuffer>> InputFileOrErr = ErrorOr<std::unique_ptr<MemoryBuffer>> InputFileOrErr =
MemoryBuffer::getFileOrSTDIN(InputFilename, /*FileSize=*/-1, MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true);
/*RequiresNullTerminator=*/true,
/*IsText=*/true);
if (InputFilename == "-") if (InputFilename == "-")
InputFilename = "<stdin>"; // Overwrite for improved diagnostic messages InputFilename = "<stdin>"; // Overwrite for improved diagnostic messages
if (std::error_code EC = InputFileOrErr.getError()) { if (std::error_code EC = InputFileOrErr.getError()) {