diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp b/clang/lib/Tooling/JSONCompilationDatabase.cpp --- a/clang/lib/Tooling/JSONCompilationDatabase.cpp +++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp @@ -198,7 +198,7 @@ JSONCommandLineSyntax Syntax) { // Don't mmap: if we're a long-lived process, the build system may overwrite. llvm::ErrorOr> DatabaseBuffer = - llvm::MemoryBuffer::getFile(FilePath, /*FileSize=*/-1, + llvm::MemoryBuffer::getFile(FilePath, /*IsText=*/false, /*RequiresNullTerminator=*/true, /*IsVolatile=*/true); if (std::error_code Result = DatabaseBuffer.getError()) { diff --git a/clang/tools/arcmt-test/arcmt-test.cpp b/clang/tools/arcmt-test/arcmt-test.cpp --- a/clang/tools/arcmt-test/arcmt-test.cpp +++ b/clang/tools/arcmt-test/arcmt-test.cpp @@ -207,15 +207,13 @@ static bool filesCompareEqual(StringRef fname1, StringRef fname2) { using namespace llvm; - ErrorOr> file1 = MemoryBuffer::getFile( - fname1, /*FileSize=*/-1, /*RequiresNullTerminator=*/true, - /*IsVolatile=*/false, /*IsText=*/true); + ErrorOr> file1 = + MemoryBuffer::getFile(fname1, /*IsText=*/true); if (!file1) return false; - ErrorOr> file2 = MemoryBuffer::getFile( - fname2, /*FileSize=*/-1, /*RequiresNullTerminator=*/true, - /*IsVolatile=*/false, /*IsText=*/true); + ErrorOr> file2 = + MemoryBuffer::getFile(fname2, /*IsText=*/true); if (!file2) return false; @@ -244,9 +242,7 @@ if (RemappingsFile.empty()) inputBuf = MemoryBuffer::getSTDIN(); else - inputBuf = MemoryBuffer::getFile(RemappingsFile, /*FileSize=*/-1, - /*RequiresNullTerminator=*/true, - /*IsVolatile=*/false, /*IsText=*/true); + inputBuf = MemoryBuffer::getFile(RemappingsFile, /*IsText=*/true); if (!inputBuf) { errs() << "error: could not read remappings input\n"; return true; diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -157,9 +157,8 @@ auto strategy = std::launch::deferred; #endif return std::async(strategy, [=]() { - auto mbOrErr = MemoryBuffer::getFile(path, - /*FileSize*/ -1, - /*RequiresNullTerminator*/ false); + auto mbOrErr = MemoryBuffer::getFile(path, /*IsText=*/false, + /*RequiresNullTerminator=*/false); if (!mbOrErr) return MBErrPair{nullptr, mbOrErr.getError()}; return MBErrPair{std::move(*mbOrErr), std::error_code()}; @@ -829,7 +828,7 @@ // If the import library already exists, replace it only if the contents // have changed. ErrorOr> oldBuf = MemoryBuffer::getFile( - path, /*FileSize*/ -1, /*RequiresNullTerminator*/ false); + path, /*IsText=*/false, /*RequiresNullTerminator=*/false); if (!oldBuf) { handleError(writeImportLibrary(libName, path, exports, config->machine, config->mingw)); @@ -849,7 +848,7 @@ } std::unique_ptr newBuf = check(MemoryBuffer::getFile( - tmpName, /*FileSize*/ -1, /*RequiresNullTerminator*/ false)); + tmpName, /*IsText=*/false, /*RequiresNullTerminator=*/false)); if ((*oldBuf)->getBuffer() != newBuf->getBuffer()) { oldBuf->reset(); handleError(errorCodeToError(sys::fs::rename(tmpName, path))); @@ -859,8 +858,11 @@ } static void parseModuleDefs(StringRef path) { - std::unique_ptr mb = CHECK( - MemoryBuffer::getFile(path, -1, false, true), "could not open " + path); + std::unique_ptr mb = + CHECK(MemoryBuffer::getFile(path, /*IsText=*/false, + /*RequiresNullTerminator=*/false, + /*IsVolatile=*/true), + "could not open " + path); COFFModuleDefinition m = check(parseCOFFModuleDefinition( mb->getMemBufferRef(), config->machine, config->mingw)); @@ -948,8 +950,11 @@ // Open a file. StringRef path = arg.substr(1); - std::unique_ptr mb = CHECK( - MemoryBuffer::getFile(path, -1, false, true), "could not open " + path); + std::unique_ptr mb = + CHECK(MemoryBuffer::getFile(path, /*IsText=*/false, + /*RequiresNullTerminator=*/false, + /*IsVolatile=*/true), + "could not open " + path); // Parse a file. An order file contains one symbol per line. // All symbols that were not present in a given order file are @@ -973,8 +978,11 @@ } static void parseCallGraphFile(StringRef path) { - std::unique_ptr mb = CHECK( - MemoryBuffer::getFile(path, -1, false, true), "could not open " + path); + std::unique_ptr mb = + CHECK(MemoryBuffer::getFile(path, /*IsText=*/false, + /*RequiresNullTerminator=*/false, + /*IsVolatile=*/true), + "could not open " + path); // Build a map from symbol name to section. DenseMap map; diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp --- a/lld/COFF/DriverUtils.cpp +++ b/lld/COFF/DriverUtils.cpp @@ -350,7 +350,7 @@ // is called (you cannot remove an opened file on Windows.) std::unique_ptr getMemoryBuffer() { // IsVolatile=true forces MemoryBuffer to not use mmap(). - return CHECK(MemoryBuffer::getFile(path, /*FileSize=*/-1, + return CHECK(MemoryBuffer::getFile(path, /*IsText=*/false, /*RequiresNullTerminator=*/false, /*IsVolatile=*/true), "could not open " + path); diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -115,7 +115,8 @@ log(path); config->dependencyFiles.insert(llvm::CachedHashString(path)); - auto mbOrErr = MemoryBuffer::getFile(path, -1, false); + auto mbOrErr = MemoryBuffer::getFile(path, /*IsText=*/false, + /*RequiresNullTerminator=*/false); if (auto ec = mbOrErr.getError()) { error("cannot open " + path + ": " + ec.message()); return None; diff --git a/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp b/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp --- a/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp +++ b/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp @@ -173,7 +173,7 @@ if (ec || magic != llvm::file_magic::pdb) return nullptr; llvm::ErrorOr> ErrorOrBuffer = - llvm::MemoryBuffer::getFile(PdbPath, /*FileSize=*/-1, + llvm::MemoryBuffer::getFile(PdbPath, /*IsText=*/false, /*RequiresNullTerminator=*/false); if (!ErrorOrBuffer) return nullptr; diff --git a/lldb/unittests/TestingSupport/TestUtilities.cpp b/lldb/unittests/TestingSupport/TestUtilities.cpp --- a/lldb/unittests/TestingSupport/TestUtilities.cpp +++ b/lldb/unittests/TestingSupport/TestUtilities.cpp @@ -38,8 +38,8 @@ llvm::Expected TestFile::fromYamlFile(const llvm::Twine &Name) { auto BufferOrError = - llvm::MemoryBuffer::getFile(GetInputFilePath(Name), /*FileSize*/ -1, - /*RequiresNullTerminator*/ false); + llvm::MemoryBuffer::getFile(GetInputFilePath(Name), /*IsText=*/false, + /*RequiresNullTerminator=*/false); if (!BufferOrError) return llvm::errorCodeToError(BufferOrError.getError()); return fromYaml(BufferOrError.get()->getBuffer()); diff --git a/llvm/include/llvm/Support/MemoryBuffer.h b/llvm/include/llvm/Support/MemoryBuffer.h --- a/llvm/include/llvm/Support/MemoryBuffer.h +++ b/llvm/include/llvm/Support/MemoryBuffer.h @@ -79,16 +79,16 @@ /// 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 /// 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, + getFile(const Twine &Filename, bool IsText = false, bool RequiresNullTerminator = true, bool IsVolatile = false, - bool IsText = false); + int64_t FileSize = -1); /// 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 +133,8 @@ /// 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, int64_t FileSize = -1); /// Map a subrange of the specified file as a MemoryBuffer. static ErrorOr> diff --git a/llvm/lib/BinaryFormat/Magic.cpp b/llvm/lib/BinaryFormat/Magic.cpp --- a/llvm/lib/BinaryFormat/Magic.cpp +++ b/llvm/lib/BinaryFormat/Magic.cpp @@ -223,7 +223,8 @@ } 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/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp --- a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -83,7 +83,7 @@ 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/llvm/lib/FuzzMutate/FuzzerCLI.cpp b/llvm/lib/FuzzMutate/FuzzerCLI.cpp --- a/llvm/lib/FuzzMutate/FuzzerCLI.cpp +++ b/llvm/lib/FuzzMutate/FuzzerCLI.cpp @@ -153,7 +153,7 @@ 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/llvm/lib/IRReader/IRReader.cpp b/llvm/lib/IRReader/IRReader.cpp --- a/llvm/lib/IRReader/IRReader.cpp +++ b/llvm/lib/IRReader/IRReader.cpp @@ -92,9 +92,7 @@ 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/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -285,8 +285,8 @@ 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/llvm/lib/Object/Binary.cpp b/llvm/lib/Object/Binary.cpp --- a/llvm/lib/Object/Binary.cpp +++ b/llvm/lib/Object/Binary.cpp @@ -97,7 +97,7 @@ 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/llvm/lib/ProfileData/GCOV.cpp b/llvm/lib/ProfileData/GCOV.cpp --- a/llvm/lib/ProfileData/GCOV.cpp +++ b/llvm/lib/ProfileData/GCOV.cpp @@ -564,7 +564,7 @@ // 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/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp --- a/llvm/lib/Support/MemoryBuffer.cpp +++ b/llvm/lib/Support/MemoryBuffer.cpp @@ -106,8 +106,8 @@ template static ErrorOr> getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize, - uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile, - bool IsText); + uint64_t Offset, bool IsText, bool RequiresNullTerminator, + bool IsVolatile); std::unique_ptr MemoryBuffer::getMemBuffer(StringRef InputData, StringRef BufferName, @@ -141,21 +141,23 @@ } ErrorOr> -MemoryBuffer::getFileOrSTDIN(const Twine &Filename, int64_t FileSize, - bool RequiresNullTerminator, bool IsText) { +MemoryBuffer::getFileOrSTDIN(const Twine &Filename, bool IsText, + bool RequiresNullTerminator, int64_t FileSize) { 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, + FileSize); } 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, -1, MapSize, Offset, + /*IsText=*/false, + /*RequiresNullTerminator=*/false, IsVolatile); } //===----------------------------------------------------------------------===// @@ -242,11 +244,11 @@ } ErrorOr> -MemoryBuffer::getFile(const Twine &Filename, int64_t FileSize, +MemoryBuffer::getFile(const Twine &Filename, bool IsText, bool RequiresNullTerminator, bool IsVolatile, - bool IsText) { - return getFileAux(Filename, FileSize, FileSize, 0, - RequiresNullTerminator, IsVolatile, IsText); + int64_t FileSize) { + return getFileAux(Filename, FileSize, FileSize, 0, IsText, + RequiresNullTerminator, IsVolatile); } template @@ -258,8 +260,8 @@ template static ErrorOr> getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize, - uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile, - bool IsText) { + 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) @@ -274,16 +276,17 @@ ErrorOr> WritableMemoryBuffer::getFile(const Twine &Filename, int64_t FileSize, bool IsVolatile) { - return getFileAux(Filename, FileSize, FileSize, 0, - /*RequiresNullTerminator*/ false, - IsVolatile, false); + return getFileAux( + Filename, FileSize, FileSize, 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, -1, MapSize, Offset, /*IsText=*/false, + /*RequiresNullTerminator=*/false, IsVolatile); } std::unique_ptr diff --git a/llvm/lib/TableGen/Main.cpp b/llvm/lib/TableGen/Main.cpp --- a/llvm/lib/TableGen/Main.cpp +++ b/llvm/lib/TableGen/Main.cpp @@ -93,9 +93,7 @@ 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 @@ // 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/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp --- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp +++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp @@ -112,8 +112,8 @@ 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 @@ 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/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -327,7 +327,8 @@ 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/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -270,7 +270,8 @@ } 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 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/llvm/tools/llvm-cov/gcov.cpp b/llvm/tools/llvm-cov/gcov.cpp --- a/llvm/tools/llvm-cov/gcov.cpp +++ b/llvm/tools/llvm-cov/gcov.cpp @@ -46,7 +46,8 @@ // 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 @@ } 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/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp --- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp +++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp @@ -147,7 +147,7 @@ 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/llvm/tools/llvm-pdbutil/InputFile.cpp b/llvm/tools/llvm-pdbutil/InputFile.cpp --- a/llvm/tools/llvm-pdbutil/InputFile.cpp +++ b/llvm/tools/llvm-pdbutil/InputFile.cpp @@ -288,7 +288,8 @@ 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/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp --- a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp +++ b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp @@ -748,7 +748,7 @@ 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/llvm/tools/llvm-rc/ResourceFileWriter.cpp b/llvm/tools/llvm-rc/ResourceFileWriter.cpp --- a/llvm/tools/llvm-rc/ResourceFileWriter.cpp +++ b/llvm/tools/llvm-rc/ResourceFileWriter.cpp @@ -1524,14 +1524,16 @@ // 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 @@ 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/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp --- a/llvm/tools/llvm-readobj/llvm-readobj.cpp +++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -653,7 +653,7 @@ /// 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/llvm/tools/obj2yaml/obj2yaml.cpp b/llvm/tools/obj2yaml/obj2yaml.cpp --- a/llvm/tools/obj2yaml/obj2yaml.cpp +++ b/llvm/tools/obj2yaml/obj2yaml.cpp @@ -36,7 +36,7 @@ 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/llvm/tools/sanstats/sanstats.cpp b/llvm/tools/sanstats/sanstats.cpp --- a/llvm/tools/sanstats/sanstats.cpp +++ b/llvm/tools/sanstats/sanstats.cpp @@ -125,8 +125,8 @@ 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/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp --- a/llvm/utils/FileCheck/FileCheck.cpp +++ b/llvm/utils/FileCheck/FileCheck.cpp @@ -821,9 +821,7 @@ // 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 @@ // 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()) {