From d30f6cb8e49ec0a3a877a7695e72432133367f67 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Thu, 25 Mar 2021 09:47:25 -0400 Subject: [PATCH] [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> getFile(const Twine &Filename, bool IsText = false, bool RequiresNullTerminator = true, bool IsVolatile = false); static ErrorOr> getFileOrSTDIN(const Twine &Filename, bool IsText = false, bool RequiresNullTerminator = true); static ErrorOr> getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsText, bool RequiresNullTerminator, bool IsVolatile); static ErrorOr> getFile(const Twine &Filename, bool IsVolatile = false); ``` Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D99182 --- include/llvm/Support/MemoryBuffer.h | 22 ++++----- lib/BinaryFormat/Magic.cpp | 3 +- lib/DebugInfo/PDB/Native/NativeSession.cpp | 2 +- lib/FuzzMutate/FuzzerCLI.cpp | 2 +- lib/IRReader/IRReader.cpp | 4 +- lib/LTO/LTOCodeGenerator.cpp | 4 +- lib/Object/Binary.cpp | 2 +- lib/ProfileData/GCOV.cpp | 2 +- lib/Support/MemoryBuffer.cpp | 46 +++++++++---------- lib/TableGen/Main.cpp | 9 ++-- lib/ToolDrivers/llvm-lib/LibDriver.cpp | 8 ++-- tools/lli/lli.cpp | 3 +- tools/llvm-ar/llvm-ar.cpp | 7 +-- tools/llvm-cov/gcov.cpp | 6 ++- .../llvm-libtool-darwin.cpp | 2 +- tools/llvm-pdbutil/InputFile.cpp | 3 +- tools/llvm-pdbutil/llvm-pdbutil.cpp | 2 +- tools/llvm-rc/ResourceFileWriter.cpp | 15 ++++-- tools/llvm-readobj/llvm-readobj.cpp | 2 +- tools/obj2yaml/obj2yaml.cpp | 2 +- tools/sanstats/sanstats.cpp | 4 +- utils/FileCheck/FileCheck.cpp | 8 +--- 22 files changed, 77 insertions(+), 81 deletions(-) diff --git a/include/llvm/Support/MemoryBuffer.h b/include/llvm/Support/MemoryBuffer.h index eccb7ee01e6..c9ceeedbf3d 100644 --- a/include/llvm/Support/MemoryBuffer.h +++ b/include/llvm/Support/MemoryBuffer.h @@ -75,20 +75,17 @@ public: virtual StringRef getBufferIdentifier() const { return "Unknown buffer"; } /// Open the specified file as a MemoryBuffer, returning a new MemoryBuffer - /// if successful, otherwise returning null. If FileSize is specified, this - /// means that the client knows that the file exists and that it has the - /// specified size. + /// if successful, otherwise returning null. + /// + /// \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 /// 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. - /// - /// \param IsText Set to true to indicate that the file should be read in - /// text mode. static ErrorOr> - getFile(const Twine &Filename, int64_t FileSize = -1, - bool RequiresNullTerminator = true, bool IsVolatile = false, - bool IsText = false); + getFile(const Twine &Filename, bool IsText = false, + bool RequiresNullTerminator = true, bool IsVolatile = false); /// Read all of the specified file into a MemoryBuffer as a stream /// (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 /// is "-". static ErrorOr> - getFileOrSTDIN(const Twine &Filename, int64_t FileSize = -1, - bool RequiresNullTerminator = true, bool IsText = false); + getFileOrSTDIN(const Twine &Filename, bool IsText = false, + bool RequiresNullTerminator = true); /// Map a subrange of the specified file as a MemoryBuffer. static ErrorOr> @@ -184,8 +181,7 @@ public: } static ErrorOr> - getFile(const Twine &Filename, int64_t FileSize = -1, - bool IsVolatile = false); + getFile(const Twine &Filename, bool IsVolatile = false); /// Map a subrange of the specified file as a WritableMemoryBuffer. static ErrorOr> diff --git a/lib/BinaryFormat/Magic.cpp b/lib/BinaryFormat/Magic.cpp index 61b1504e59b..591da487747 100644 --- a/lib/BinaryFormat/Magic.cpp +++ b/lib/BinaryFormat/Magic.cpp @@ -223,7 +223,8 @@ file_magic llvm::identify_magic(StringRef Magic) { } 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) return FileOrError.getError(); diff --git a/lib/DebugInfo/PDB/Native/NativeSession.cpp b/lib/DebugInfo/PDB/Native/NativeSession.cpp index 5d7946cdc2f..7212a0e6503 100644 --- a/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ b/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -83,7 +83,7 @@ Error NativeSession::createFromPdb(std::unique_ptr Buffer, static Expected> loadPdbFile(StringRef PdbPath, std::unique_ptr &Allocator) { ErrorOr> ErrorOrBuffer = - MemoryBuffer::getFile(PdbPath, /*FileSize=*/-1, + MemoryBuffer::getFile(PdbPath, /*IsText=*/false, /*RequiresNullTerminator=*/false); if (!ErrorOrBuffer) return make_error(ErrorOrBuffer.getError()); diff --git a/lib/FuzzMutate/FuzzerCLI.cpp b/lib/FuzzMutate/FuzzerCLI.cpp index be0d5bfcab4..1527062cfd9 100644 --- a/lib/FuzzMutate/FuzzerCLI.cpp +++ b/lib/FuzzMutate/FuzzerCLI.cpp @@ -153,7 +153,7 @@ int llvm::runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne, continue; } - auto BufOrErr = MemoryBuffer::getFile(Arg, /*FileSize-*/ -1, + auto BufOrErr = MemoryBuffer::getFile(Arg, /*IsText=*/false, /*RequiresNullTerminator=*/false); if (std::error_code EC = BufOrErr.getError()) { errs() << "Error reading file: " << Arg << ": " << EC.message() << "\n"; diff --git a/lib/IRReader/IRReader.cpp b/lib/IRReader/IRReader.cpp index cc3b2068103..b645e0b766a 100644 --- a/lib/IRReader/IRReader.cpp +++ b/lib/IRReader/IRReader.cpp @@ -92,9 +92,7 @@ std::unique_ptr llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, DataLayoutCallbackTy DataLayoutCallback) { ErrorOr> FileOrErr = - MemoryBuffer::getFileOrSTDIN(Filename, /*FileSize=*/-1, - /*RequiresNullTerminator=*/true, - /*IsText=*/true); + MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true); if (std::error_code EC = FileOrErr.getError()) { Err = SMDiagnostic(Filename, SourceMgr::DK_Error, "Could not open input file: " + EC.message()); diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index 9634014dad6..8e5587051c2 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -285,8 +285,8 @@ LTOCodeGenerator::compileOptimized() { return nullptr; // read .o file into memory buffer - ErrorOr> BufferOrErr = - MemoryBuffer::getFile(name, -1, false); + ErrorOr> BufferOrErr = MemoryBuffer::getFile( + name, /*IsText=*/false, /*RequiresNullTerminator=*/false); if (std::error_code EC = BufferOrErr.getError()) { emitError(EC.message()); sys::fs::remove(NativeObjectPath); diff --git a/lib/Object/Binary.cpp b/lib/Object/Binary.cpp index e741cbba288..71c04463022 100644 --- a/lib/Object/Binary.cpp +++ b/lib/Object/Binary.cpp @@ -97,7 +97,7 @@ Expected> object::createBinary(MemoryBufferRef Buffer, Expected> object::createBinary(StringRef Path, LLVMContext *Context, bool InitContent) { ErrorOr> FileOrErr = - MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1, + MemoryBuffer::getFileOrSTDIN(Path, /*IsText=*/false, /*RequiresNullTerminator=*/false); if (std::error_code EC = FileOrErr.getError()) return errorCodeToError(EC); diff --git a/lib/ProfileData/GCOV.cpp b/lib/ProfileData/GCOV.cpp index 3332a898603..f24c4b0cf9b 100644 --- a/lib/ProfileData/GCOV.cpp +++ b/lib/ProfileData/GCOV.cpp @@ -564,7 +564,7 @@ public: // Open source files without requiring a NUL terminator. The concurrent // modification may nullify the NUL terminator condition. ErrorOr> BufferOrErr = - MemoryBuffer::getFileOrSTDIN(Filename, -1, + MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/false, /*RequiresNullTerminator=*/false); if (std::error_code EC = BufferOrErr.getError()) { errs() << Filename << ": " << EC.message() << "\n"; diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index 955bf113fd7..1d75f0be1ca 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -105,9 +105,8 @@ public: template static ErrorOr> -getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize, - uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile, - bool IsText); +getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset, + bool IsText, bool RequiresNullTerminator, bool IsVolatile); std::unique_ptr MemoryBuffer::getMemBuffer(StringRef InputData, StringRef BufferName, @@ -141,21 +140,22 @@ MemoryBuffer::getMemBufferCopy(StringRef InputData, const Twine &BufferName) { } ErrorOr> -MemoryBuffer::getFileOrSTDIN(const Twine &Filename, int64_t FileSize, - bool RequiresNullTerminator, bool IsText) { +MemoryBuffer::getFileOrSTDIN(const Twine &Filename, bool IsText, + bool RequiresNullTerminator) { SmallString<256> NameBuf; StringRef NameRef = Filename.toStringRef(NameBuf); if (NameRef == "-") return getSTDIN(); - return getFile(Filename, FileSize, RequiresNullTerminator, false, IsText); + return getFile(Filename, IsText, RequiresNullTerminator, + /*IsVolatile=*/false); } ErrorOr> MemoryBuffer::getFileSlice(const Twine &FilePath, uint64_t MapSize, uint64_t Offset, bool IsVolatile) { - return getFileAux(FilePath, -1, MapSize, Offset, false, - IsVolatile, false); + return getFileAux(FilePath, MapSize, Offset, /*IsText=*/false, + /*RequiresNullTerminator=*/false, IsVolatile); } //===----------------------------------------------------------------------===// @@ -242,11 +242,10 @@ getMemoryBufferForStream(sys::fs::file_t FD, const Twine &BufferName) { } ErrorOr> -MemoryBuffer::getFile(const Twine &Filename, int64_t FileSize, - bool RequiresNullTerminator, bool IsVolatile, - bool IsText) { - return getFileAux(Filename, FileSize, FileSize, 0, - RequiresNullTerminator, IsVolatile, IsText); +MemoryBuffer::getFile(const Twine &Filename, bool IsText, + bool RequiresNullTerminator, bool IsVolatile) { + return getFileAux(Filename, /*MapSize=*/-1, /*Offset=*/0, + IsText, RequiresNullTerminator, IsVolatile); } template @@ -257,33 +256,32 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize, template static ErrorOr> -getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize, - uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile, - bool IsText) { +getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset, + bool IsText, bool RequiresNullTerminator, bool IsVolatile) { Expected FDOrErr = sys::fs::openNativeFileForRead( Filename, IsText ? sys::fs::OF_Text : sys::fs::OF_None); if (!FDOrErr) return errorToErrorCode(FDOrErr.takeError()); sys::fs::file_t FD = *FDOrErr; - auto Ret = getOpenFileImpl(FD, Filename, FileSize, MapSize, Offset, + auto Ret = getOpenFileImpl(FD, Filename, /*FileSize=*/-1, MapSize, Offset, RequiresNullTerminator, IsVolatile); sys::fs::closeFile(FD); return Ret; } ErrorOr> -WritableMemoryBuffer::getFile(const Twine &Filename, int64_t FileSize, - bool IsVolatile) { - return getFileAux(Filename, FileSize, FileSize, 0, - /*RequiresNullTerminator*/ false, - IsVolatile, false); +WritableMemoryBuffer::getFile(const Twine &Filename, bool IsVolatile) { + return getFileAux( + Filename, /*MapSize=*/-1, /*Offset=*/0, /*IsText=*/false, + /*RequiresNullTerminator=*/false, IsVolatile); } ErrorOr> WritableMemoryBuffer::getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsVolatile) { - return getFileAux(Filename, -1, MapSize, Offset, false, - IsVolatile, false); + return getFileAux( + Filename, MapSize, Offset, /*IsText=*/false, + /*RequiresNullTerminator=*/false, IsVolatile); } std::unique_ptr diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp index 289af936cf6..0b1024648b6 100644 --- a/lib/TableGen/Main.cpp +++ b/lib/TableGen/Main.cpp @@ -93,9 +93,7 @@ int llvm::TableGenMain(const char *argv0, TableGenMainFn *MainFn) { Records.startTimer("Parse, build records"); ErrorOr> FileOrErr = - MemoryBuffer::getFileOrSTDIN(InputFilename, /*FileSize=*/-1, - /*RequiresNullTerminator=*/true, - /*IsText=*/true); + MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true); if (std::error_code EC = FileOrErr.getError()) return reportError(argv0, "Could not open input file '" + InputFilename + "': " + 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. // This prevents recompilation of all the files depending on it if there // aren't any. - if (auto ExistingOrErr = MemoryBuffer::getFile( - OutputFilename, /*FileSize=*/-1, /*RequiresNullTerminator=*/true, - /*IsVolatile=*/false, /*IsText=*/true)) + if (auto ExistingOrErr = + MemoryBuffer::getFile(OutputFilename, /*IsText=*/true)) if (std::move(ExistingOrErr.get())->getBuffer() == Out.str()) WriteFile = false; } diff --git a/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/lib/ToolDrivers/llvm-lib/LibDriver.cpp index f3904b921e6..80d3033244d 100644 --- a/lib/ToolDrivers/llvm-lib/LibDriver.cpp +++ b/lib/ToolDrivers/llvm-lib/LibDriver.cpp @@ -112,8 +112,8 @@ static void doList(opt::InputArgList& Args) { std::unique_ptr B; for (auto *Arg : Args.filtered(OPT_INPUT)) { // Create or open the archive object. - ErrorOr> MaybeBuf = - MemoryBuffer::getFile(Arg->getValue(), -1, false); + ErrorOr> MaybeBuf = MemoryBuffer::getFile( + Arg->getValue(), /*IsText=*/false, /*RequiresNullTerminator=*/false); fatalOpenError(errorCodeToError(MaybeBuf.getError()), Arg->getValue()); if (identify_magic(MaybeBuf.get()->getBuffer()) == file_magic::archive) { @@ -339,8 +339,8 @@ int llvm::libDriverMain(ArrayRef ArgsArr) { continue; // Open a file. - ErrorOr> MOrErr = - MemoryBuffer::getFile(Path, -1, false); + ErrorOr> MOrErr = MemoryBuffer::getFile( + Path, /*IsText=*/false, /*RequiresNullTerminator=*/false); fatalOpenError(errorCodeToError(MOrErr.getError()), Path); MemoryBufferRef MBRef = (*MOrErr)->getMemBufferRef(); diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index 1bfd4b82632..782bc745e4a 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -327,7 +327,8 @@ public: return nullptr; // Load the object from the cache filename ErrorOr> IRObjectBuffer = - MemoryBuffer::getFile(CacheName, -1, false); + MemoryBuffer::getFile(CacheName, /*IsText=*/false, + /*RequiresNullTerminator=*/false); // If the file isn't there, that's OK. if (!IRObjectBuffer) return nullptr; diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index 4c26c8cad3f..4991e51a0f7 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -270,7 +270,8 @@ static void getArchive() { } 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); ArchiveBuffers.push_back(std::move(*BufOrErr)); auto LibOrErr = @@ -995,8 +996,8 @@ static void performOperation(ArchiveOperation Operation, static int performOperation(ArchiveOperation Operation, std::vector *NewMembers) { // Create or open the archive object. - ErrorOr> Buf = - MemoryBuffer::getFile(ArchiveName, -1, false); + ErrorOr> Buf = MemoryBuffer::getFile( + ArchiveName, /*IsText=*/false, /*RequiresNullTerminator=*/false); std::error_code EC = Buf.getError(); if (EC && EC != errc::no_such_file_or_directory) fail("unable to open '" + ArchiveName + "': " + EC.message()); diff --git a/tools/llvm-cov/gcov.cpp b/tools/llvm-cov/gcov.cpp index d42e7cd3b55..9a1ebebc87f 100644 --- a/tools/llvm-cov/gcov.cpp +++ b/tools/llvm-cov/gcov.cpp @@ -46,7 +46,8 @@ static void reportCoverage(StringRef SourceFile, StringRef ObjectDir, // Open .gcda and .gcda without requiring a NUL terminator. The concurrent // modification may nullify the NUL terminator condition. ErrorOr> GCNO_Buff = - MemoryBuffer::getFileOrSTDIN(GCNO, -1, /*RequiresNullTerminator=*/false); + MemoryBuffer::getFileOrSTDIN(GCNO, /*IsText=*/false, + /*RequiresNullTerminator=*/false); if (std::error_code EC = GCNO_Buff.getError()) { errs() << GCNO << ": " << EC.message() << "\n"; return; @@ -58,7 +59,8 @@ static void reportCoverage(StringRef SourceFile, StringRef ObjectDir, } ErrorOr> GCDA_Buff = - MemoryBuffer::getFileOrSTDIN(GCDA, -1, /*RequiresNullTerminator=*/false); + MemoryBuffer::getFileOrSTDIN(GCDA, /*IsText=*/false, + /*RequiresNullTerminator=*/false); if (std::error_code EC = GCDA_Buff.getError()) { if (EC != errc::no_such_file_or_directory) { errs() << GCDA << ": " << EC.message() << "\n"; diff --git a/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp index 02173641841..f16b4a17105 100644 --- a/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp +++ b/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp @@ -147,7 +147,7 @@ static Error processFileList() { std::tie(FileName, DirName) = StringRef(FileList).rsplit(","); ErrorOr> FileOrErr = - MemoryBuffer::getFileOrSTDIN(FileName, /*FileSize=*/-1, + MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/false, /*RequiresNullTerminator=*/false); if (std::error_code EC = FileOrErr.getError()) return createFileError(FileName, errorCodeToError(EC)); diff --git a/tools/llvm-pdbutil/InputFile.cpp b/tools/llvm-pdbutil/InputFile.cpp index b316882de64..40b35625b6f 100644 --- a/tools/llvm-pdbutil/InputFile.cpp +++ b/tools/llvm-pdbutil/InputFile.cpp @@ -288,7 +288,8 @@ Expected InputFile::open(StringRef Path, bool AllowUnknownFile) { formatv("File {0} is not a supported file type", Path), inconvertibleErrorCode()); - auto Result = MemoryBuffer::getFile(Path, -1LL, false); + auto Result = MemoryBuffer::getFile(Path, /*IsText=*/false, + /*RequiresNullTerminator=*/false); if (!Result) return make_error( formatv("File {0} could not be opened", Path), Result.getError()); diff --git a/tools/llvm-pdbutil/llvm-pdbutil.cpp b/tools/llvm-pdbutil/llvm-pdbutil.cpp index 19f4880ab5e..f70558a5ab7 100644 --- a/tools/llvm-pdbutil/llvm-pdbutil.cpp +++ b/tools/llvm-pdbutil/llvm-pdbutil.cpp @@ -748,7 +748,7 @@ static ExitOnError ExitOnErr; static void yamlToPdb(StringRef Path) { BumpPtrAllocator Allocator; ErrorOr> ErrorOrBuffer = - MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1, + MemoryBuffer::getFileOrSTDIN(Path, /*IsText=*/false, /*RequiresNullTerminator=*/false); if (ErrorOrBuffer.getError()) { diff --git a/tools/llvm-rc/ResourceFileWriter.cpp b/tools/llvm-rc/ResourceFileWriter.cpp index 553bb754aea..2856fa8fe08 100644 --- a/tools/llvm-rc/ResourceFileWriter.cpp +++ b/tools/llvm-rc/ResourceFileWriter.cpp @@ -1524,14 +1524,16 @@ ResourceFileWriter::loadFile(StringRef File) const { // properly though, so if using that to append paths below, this early // exception case could be removed.) 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. sys::fs::current_path(Cwd); Path.assign(Cwd.begin(), Cwd.end()); sys::path::append(Path, File); 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 // current working directory. @@ -1539,19 +1541,22 @@ ResourceFileWriter::loadFile(StringRef File) const { Path.assign(InputFileDir.begin(), InputFileDir.end()); sys::path::append(Path, File); 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. for (StringRef ForceInclude : Params.Include) { Path.assign(ForceInclude.begin(), ForceInclude.end()); sys::path::append(Path, File); if (sys::fs::exists(Path)) - return errorOrToExpected(MemoryBuffer::getFile(Path, -1, false)); + return errorOrToExpected(MemoryBuffer::getFile( + Path, /*IsText=*/false, /*RequiresNullTerminator=*/false)); } if (auto Result = 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("error : file not found : " + Twine(File), inconvertibleErrorCode()); diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index 5d6ee25961f..7db52e63da4 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -653,7 +653,7 @@ static void dumpWindowsResourceFile(WindowsResource *WinRes, /// Opens \a File and dumps it. static void dumpInput(StringRef File, ScopedPrinter &Writer) { ErrorOr> FileOrErr = - MemoryBuffer::getFileOrSTDIN(File, /*FileSize=*/-1, + MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/false, /*RequiresNullTerminator=*/false); if (std::error_code EC = FileOrErr.getError()) return reportError(errorCodeToError(EC), File); diff --git a/tools/obj2yaml/obj2yaml.cpp b/tools/obj2yaml/obj2yaml.cpp index da70450503f..ff6b470f524 100644 --- a/tools/obj2yaml/obj2yaml.cpp +++ b/tools/obj2yaml/obj2yaml.cpp @@ -36,7 +36,7 @@ static Error dumpObject(const ObjectFile &Obj) { static Error dumpInput(StringRef File) { ErrorOr> FileOrErr = - MemoryBuffer::getFileOrSTDIN(File, /*FileSize=*/-1, + MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/false, /*RequiresNullTerminator=*/false); if (std::error_code EC = FileOrErr.getError()) return errorCodeToError(EC); diff --git a/tools/sanstats/sanstats.cpp b/tools/sanstats/sanstats.cpp index 1f154e08f24..54ad35b2ace 100644 --- a/tools/sanstats/sanstats.cpp +++ b/tools/sanstats/sanstats.cpp @@ -125,8 +125,8 @@ int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, "Sanitizer Statistics Processing Tool"); - ErrorOr> MBOrErr = - MemoryBuffer::getFile(ClInputFile, -1, false); + ErrorOr> MBOrErr = MemoryBuffer::getFile( + ClInputFile, /*IsText=*/false, /*RequiresNullTerminator=*/false); if (!MBOrErr) { errs() << argv[0] << ": " << ClInputFile << ": " << MBOrErr.getError().message() << '\n'; diff --git a/utils/FileCheck/FileCheck.cpp b/utils/FileCheck/FileCheck.cpp index 12365e03db5..c1bb97faac5 100644 --- a/utils/FileCheck/FileCheck.cpp +++ b/utils/FileCheck/FileCheck.cpp @@ -821,9 +821,7 @@ int main(int argc, char **argv) { // Read the expected strings from the check file. ErrorOr> CheckFileOrErr = - MemoryBuffer::getFileOrSTDIN(CheckFilename, /*FileSize=*/-1, - /*RequiresNullTerminator=*/true, - /*IsText=*/true); + MemoryBuffer::getFileOrSTDIN(CheckFilename, /*IsText=*/true); if (std::error_code EC = CheckFileOrErr.getError()) { errs() << "Could not open check file '" << CheckFilename << "': " << EC.message() << '\n'; @@ -845,9 +843,7 @@ int main(int argc, char **argv) { // Open the file to check and add it to SourceMgr. ErrorOr> InputFileOrErr = - MemoryBuffer::getFileOrSTDIN(InputFilename, /*FileSize=*/-1, - /*RequiresNullTerminator=*/true, - /*IsText=*/true); + MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true); if (InputFilename == "-") InputFilename = ""; // Overwrite for improved diagnostic messages if (std::error_code EC = InputFileOrErr.getError()) {