Skip to content

Commit c83cd8f

Browse files
committed
[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
1 parent 0becc4d commit c83cd8f

File tree

30 files changed

+109
-108
lines changed

30 files changed

+109
-108
lines changed

clang/lib/Tooling/JSONCompilationDatabase.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ JSONCompilationDatabase::loadFromFile(StringRef FilePath,
198198
JSONCommandLineSyntax Syntax) {
199199
// Don't mmap: if we're a long-lived process, the build system may overwrite.
200200
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> DatabaseBuffer =
201-
llvm::MemoryBuffer::getFile(FilePath, /*FileSize=*/-1,
201+
llvm::MemoryBuffer::getFile(FilePath, /*IsText=*/false,
202202
/*RequiresNullTerminator=*/true,
203203
/*IsVolatile=*/true);
204204
if (std::error_code Result = DatabaseBuffer.getError()) {

clang/tools/arcmt-test/arcmt-test.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,13 @@ static bool performTransformations(StringRef resourcesPath,
207207
static bool filesCompareEqual(StringRef fname1, StringRef fname2) {
208208
using namespace llvm;
209209

210-
ErrorOr<std::unique_ptr<MemoryBuffer>> file1 = MemoryBuffer::getFile(
211-
fname1, /*FileSize=*/-1, /*RequiresNullTerminator=*/true,
212-
/*IsVolatile=*/false, /*IsText=*/true);
210+
ErrorOr<std::unique_ptr<MemoryBuffer>> file1 =
211+
MemoryBuffer::getFile(fname1, /*IsText=*/true);
213212
if (!file1)
214213
return false;
215214

216-
ErrorOr<std::unique_ptr<MemoryBuffer>> file2 = MemoryBuffer::getFile(
217-
fname2, /*FileSize=*/-1, /*RequiresNullTerminator=*/true,
218-
/*IsVolatile=*/false, /*IsText=*/true);
215+
ErrorOr<std::unique_ptr<MemoryBuffer>> file2 =
216+
MemoryBuffer::getFile(fname2, /*IsText=*/true);
219217
if (!file2)
220218
return false;
221219

@@ -244,9 +242,7 @@ static bool verifyTransformedFiles(ArrayRef<std::string> resultFiles) {
244242
if (RemappingsFile.empty())
245243
inputBuf = MemoryBuffer::getSTDIN();
246244
else
247-
inputBuf = MemoryBuffer::getFile(RemappingsFile, /*FileSize=*/-1,
248-
/*RequiresNullTerminator=*/true,
249-
/*IsVolatile=*/false, /*IsText=*/true);
245+
inputBuf = MemoryBuffer::getFile(RemappingsFile, /*IsText=*/true);
250246
if (!inputBuf) {
251247
errs() << "error: could not read remappings input\n";
252248
return true;

lld/COFF/Driver.cpp

+19-11
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@ static std::future<MBErrPair> createFutureForFile(std::string path) {
157157
auto strategy = std::launch::deferred;
158158
#endif
159159
return std::async(strategy, [=]() {
160-
auto mbOrErr = MemoryBuffer::getFile(path,
161-
/*FileSize*/ -1,
162-
/*RequiresNullTerminator*/ false);
160+
auto mbOrErr = MemoryBuffer::getFile(path, /*IsText=*/false,
161+
/*RequiresNullTerminator=*/false);
163162
if (!mbOrErr)
164163
return MBErrPair{nullptr, mbOrErr.getError()};
165164
return MBErrPair{std::move(*mbOrErr), std::error_code()};
@@ -829,7 +828,7 @@ static void createImportLibrary(bool asLib) {
829828
// If the import library already exists, replace it only if the contents
830829
// have changed.
831830
ErrorOr<std::unique_ptr<MemoryBuffer>> oldBuf = MemoryBuffer::getFile(
832-
path, /*FileSize*/ -1, /*RequiresNullTerminator*/ false);
831+
path, /*IsText=*/false, /*RequiresNullTerminator=*/false);
833832
if (!oldBuf) {
834833
handleError(writeImportLibrary(libName, path, exports, config->machine,
835834
config->mingw));
@@ -849,7 +848,7 @@ static void createImportLibrary(bool asLib) {
849848
}
850849

851850
std::unique_ptr<MemoryBuffer> newBuf = check(MemoryBuffer::getFile(
852-
tmpName, /*FileSize*/ -1, /*RequiresNullTerminator*/ false));
851+
tmpName, /*IsText=*/false, /*RequiresNullTerminator=*/false));
853852
if ((*oldBuf)->getBuffer() != newBuf->getBuffer()) {
854853
oldBuf->reset();
855854
handleError(errorCodeToError(sys::fs::rename(tmpName, path)));
@@ -859,8 +858,11 @@ static void createImportLibrary(bool asLib) {
859858
}
860859

861860
static void parseModuleDefs(StringRef path) {
862-
std::unique_ptr<MemoryBuffer> mb = CHECK(
863-
MemoryBuffer::getFile(path, -1, false, true), "could not open " + path);
861+
std::unique_ptr<MemoryBuffer> mb =
862+
CHECK(MemoryBuffer::getFile(path, /*IsText=*/false,
863+
/*RequiresNullTerminator=*/false,
864+
/*IsVolatile=*/true),
865+
"could not open " + path);
864866
COFFModuleDefinition m = check(parseCOFFModuleDefinition(
865867
mb->getMemBufferRef(), config->machine, config->mingw));
866868

@@ -948,8 +950,11 @@ static void parseOrderFile(StringRef arg) {
948950

949951
// Open a file.
950952
StringRef path = arg.substr(1);
951-
std::unique_ptr<MemoryBuffer> mb = CHECK(
952-
MemoryBuffer::getFile(path, -1, false, true), "could not open " + path);
953+
std::unique_ptr<MemoryBuffer> mb =
954+
CHECK(MemoryBuffer::getFile(path, /*IsText=*/false,
955+
/*RequiresNullTerminator=*/false,
956+
/*IsVolatile=*/true),
957+
"could not open " + path);
953958

954959
// Parse a file. An order file contains one symbol per line.
955960
// All symbols that were not present in a given order file are
@@ -973,8 +978,11 @@ static void parseOrderFile(StringRef arg) {
973978
}
974979

975980
static void parseCallGraphFile(StringRef path) {
976-
std::unique_ptr<MemoryBuffer> mb = CHECK(
977-
MemoryBuffer::getFile(path, -1, false, true), "could not open " + path);
981+
std::unique_ptr<MemoryBuffer> mb =
982+
CHECK(MemoryBuffer::getFile(path, /*IsText=*/false,
983+
/*RequiresNullTerminator=*/false,
984+
/*IsVolatile=*/true),
985+
"could not open " + path);
978986

979987
// Build a map from symbol name to section.
980988
DenseMap<StringRef, Symbol *> map;

lld/COFF/DriverUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ class TemporaryFile {
350350
// is called (you cannot remove an opened file on Windows.)
351351
std::unique_ptr<MemoryBuffer> getMemoryBuffer() {
352352
// IsVolatile=true forces MemoryBuffer to not use mmap().
353-
return CHECK(MemoryBuffer::getFile(path, /*FileSize=*/-1,
353+
return CHECK(MemoryBuffer::getFile(path, /*IsText=*/false,
354354
/*RequiresNullTerminator=*/false,
355355
/*IsVolatile=*/true),
356356
"could not open " + path);

lld/ELF/InputFiles.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ Optional<MemoryBufferRef> elf::readFile(StringRef path) {
115115
log(path);
116116
config->dependencyFiles.insert(llvm::CachedHashString(path));
117117

118-
auto mbOrErr = MemoryBuffer::getFile(path, -1, false);
118+
auto mbOrErr = MemoryBuffer::getFile(path, /*IsText=*/false,
119+
/*RequiresNullTerminator=*/false);
119120
if (auto ec = mbOrErr.getError()) {
120121
error("cannot open " + path + ": " + ec.message());
121122
return None;

lldb/source/Host/common/FileSystem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size,
307307
std::unique_ptr<llvm::WritableMemoryBuffer> buffer;
308308
if (size == 0) {
309309
auto buffer_or_error =
310-
llvm::WritableMemoryBuffer::getFile(*external_path, -1, is_volatile);
310+
llvm::WritableMemoryBuffer::getFile(*external_path, is_volatile);
311311
if (!buffer_or_error)
312312
return nullptr;
313313
buffer = std::move(*buffer_or_error);

lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ ObjectFilePDB::loadPDBFile(std::string PdbPath,
173173
if (ec || magic != llvm::file_magic::pdb)
174174
return nullptr;
175175
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ErrorOrBuffer =
176-
llvm::MemoryBuffer::getFile(PdbPath, /*FileSize=*/-1,
176+
llvm::MemoryBuffer::getFile(PdbPath, /*IsText=*/false,
177177
/*RequiresNullTerminator=*/false);
178178
if (!ErrorOrBuffer)
179179
return nullptr;

lldb/unittests/TestingSupport/TestUtilities.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ llvm::Expected<TestFile> TestFile::fromYaml(llvm::StringRef Yaml) {
3838

3939
llvm::Expected<TestFile> TestFile::fromYamlFile(const llvm::Twine &Name) {
4040
auto BufferOrError =
41-
llvm::MemoryBuffer::getFile(GetInputFilePath(Name), /*FileSize*/ -1,
42-
/*RequiresNullTerminator*/ false);
41+
llvm::MemoryBuffer::getFile(GetInputFilePath(Name), /*IsText=*/false,
42+
/*RequiresNullTerminator=*/false);
4343
if (!BufferOrError)
4444
return llvm::errorCodeToError(BufferOrError.getError());
4545
return fromYaml(BufferOrError.get()->getBuffer());

llvm/include/llvm/Support/MemoryBuffer.h

+9-13
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,17 @@ class MemoryBuffer {
7575
virtual StringRef getBufferIdentifier() const { return "Unknown buffer"; }
7676

7777
/// Open the specified file as a MemoryBuffer, returning a new MemoryBuffer
78-
/// if successful, otherwise returning null. If FileSize is specified, this
79-
/// means that the client knows that the file exists and that it has the
80-
/// specified size.
78+
/// if successful, otherwise returning null.
79+
///
80+
/// \param IsText Set to true to indicate that the file should be read in
81+
/// text mode.
8182
///
8283
/// \param IsVolatile Set to true to indicate that the contents of the file
8384
/// can change outside the user's control, e.g. when libclang tries to parse
8485
/// while the user is editing/updating the file or if the file is on an NFS.
85-
///
86-
/// \param IsText Set to true to indicate that the file should be read in
87-
/// text mode.
8886
static ErrorOr<std::unique_ptr<MemoryBuffer>>
89-
getFile(const Twine &Filename, int64_t FileSize = -1,
90-
bool RequiresNullTerminator = true, bool IsVolatile = false,
91-
bool IsText = false);
87+
getFile(const Twine &Filename, bool IsText = false,
88+
bool RequiresNullTerminator = true, bool IsVolatile = false);
9289

9390
/// Read all of the specified file into a MemoryBuffer as a stream
9491
/// (i.e. until EOF reached). This is useful for special files that
@@ -133,8 +130,8 @@ class MemoryBuffer {
133130
/// Open the specified file as a MemoryBuffer, or open stdin if the Filename
134131
/// is "-".
135132
static ErrorOr<std::unique_ptr<MemoryBuffer>>
136-
getFileOrSTDIN(const Twine &Filename, int64_t FileSize = -1,
137-
bool RequiresNullTerminator = true, bool IsText = false);
133+
getFileOrSTDIN(const Twine &Filename, bool IsText = false,
134+
bool RequiresNullTerminator = true);
138135

139136
/// Map a subrange of the specified file as a MemoryBuffer.
140137
static ErrorOr<std::unique_ptr<MemoryBuffer>>
@@ -184,8 +181,7 @@ class WritableMemoryBuffer : public MemoryBuffer {
184181
}
185182

186183
static ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
187-
getFile(const Twine &Filename, int64_t FileSize = -1,
188-
bool IsVolatile = false);
184+
getFile(const Twine &Filename, bool IsVolatile = false);
189185

190186
/// Map a subrange of the specified file as a WritableMemoryBuffer.
191187
static ErrorOr<std::unique_ptr<WritableMemoryBuffer>>

llvm/lib/BinaryFormat/Magic.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ file_magic llvm::identify_magic(StringRef Magic) {
223223
}
224224

225225
std::error_code llvm::identify_magic(const Twine &Path, file_magic &Result) {
226-
auto FileOrError = MemoryBuffer::getFile(Path, -1LL, false);
226+
auto FileOrError = MemoryBuffer::getFile(Path, /*IsText=*/false,
227+
/*RequiresNullTerminator=*/false);
227228
if (!FileOrError)
228229
return FileOrError.getError();
229230

llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Error NativeSession::createFromPdb(std::unique_ptr<MemoryBuffer> Buffer,
8383
static Expected<std::unique_ptr<PDBFile>>
8484
loadPdbFile(StringRef PdbPath, std::unique_ptr<BumpPtrAllocator> &Allocator) {
8585
ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
86-
MemoryBuffer::getFile(PdbPath, /*FileSize=*/-1,
86+
MemoryBuffer::getFile(PdbPath, /*IsText=*/false,
8787
/*RequiresNullTerminator=*/false);
8888
if (!ErrorOrBuffer)
8989
return make_error<RawError>(ErrorOrBuffer.getError());

llvm/lib/FuzzMutate/FuzzerCLI.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ int llvm::runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne,
153153
continue;
154154
}
155155

156-
auto BufOrErr = MemoryBuffer::getFile(Arg, /*FileSize-*/ -1,
156+
auto BufOrErr = MemoryBuffer::getFile(Arg, /*IsText=*/false,
157157
/*RequiresNullTerminator=*/false);
158158
if (std::error_code EC = BufOrErr.getError()) {
159159
errs() << "Error reading file: " << Arg << ": " << EC.message() << "\n";

llvm/lib/IRReader/IRReader.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ std::unique_ptr<Module>
9292
llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
9393
DataLayoutCallbackTy DataLayoutCallback) {
9494
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
95-
MemoryBuffer::getFileOrSTDIN(Filename, /*FileSize=*/-1,
96-
/*RequiresNullTerminator=*/true,
97-
/*IsText=*/true);
95+
MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true);
9896
if (std::error_code EC = FileOrErr.getError()) {
9997
Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
10098
"Could not open input file: " + EC.message());

llvm/lib/LTO/LTOCodeGenerator.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ LTOCodeGenerator::compileOptimized() {
285285
return nullptr;
286286

287287
// read .o file into memory buffer
288-
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
289-
MemoryBuffer::getFile(name, -1, false);
288+
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = MemoryBuffer::getFile(
289+
name, /*IsText=*/false, /*RequiresNullTerminator=*/false);
290290
if (std::error_code EC = BufferOrErr.getError()) {
291291
emitError(EC.message());
292292
sys::fs::remove(NativeObjectPath);

llvm/lib/Object/Binary.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
9797
Expected<OwningBinary<Binary>>
9898
object::createBinary(StringRef Path, LLVMContext *Context, bool InitContent) {
9999
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
100-
MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
100+
MemoryBuffer::getFileOrSTDIN(Path, /*IsText=*/false,
101101
/*RequiresNullTerminator=*/false);
102102
if (std::error_code EC = FileOrErr.getError())
103103
return errorCodeToError(EC);

llvm/lib/ProfileData/GCOV.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ class LineConsumer {
564564
// Open source files without requiring a NUL terminator. The concurrent
565565
// modification may nullify the NUL terminator condition.
566566
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
567-
MemoryBuffer::getFileOrSTDIN(Filename, -1,
567+
MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/false,
568568
/*RequiresNullTerminator=*/false);
569569
if (std::error_code EC = BufferOrErr.getError()) {
570570
errs() << Filename << ": " << EC.message() << "\n";

llvm/lib/Support/MemoryBuffer.cpp

+22-24
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ class MemoryBufferMem : public MB {
105105

106106
template <typename MB>
107107
static ErrorOr<std::unique_ptr<MB>>
108-
getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize,
109-
uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile,
110-
bool IsText);
108+
getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
109+
bool IsText, bool RequiresNullTerminator, bool IsVolatile);
111110

112111
std::unique_ptr<MemoryBuffer>
113112
MemoryBuffer::getMemBuffer(StringRef InputData, StringRef BufferName,
@@ -141,21 +140,22 @@ MemoryBuffer::getMemBufferCopy(StringRef InputData, const Twine &BufferName) {
141140
}
142141

143142
ErrorOr<std::unique_ptr<MemoryBuffer>>
144-
MemoryBuffer::getFileOrSTDIN(const Twine &Filename, int64_t FileSize,
145-
bool RequiresNullTerminator, bool IsText) {
143+
MemoryBuffer::getFileOrSTDIN(const Twine &Filename, bool IsText,
144+
bool RequiresNullTerminator) {
146145
SmallString<256> NameBuf;
147146
StringRef NameRef = Filename.toStringRef(NameBuf);
148147

149148
if (NameRef == "-")
150149
return getSTDIN();
151-
return getFile(Filename, FileSize, RequiresNullTerminator, false, IsText);
150+
return getFile(Filename, IsText, RequiresNullTerminator,
151+
/*IsVolatile=*/false);
152152
}
153153

154154
ErrorOr<std::unique_ptr<MemoryBuffer>>
155155
MemoryBuffer::getFileSlice(const Twine &FilePath, uint64_t MapSize,
156156
uint64_t Offset, bool IsVolatile) {
157-
return getFileAux<MemoryBuffer>(FilePath, -1, MapSize, Offset, false,
158-
IsVolatile, false);
157+
return getFileAux<MemoryBuffer>(FilePath, MapSize, Offset, /*IsText=*/false,
158+
/*RequiresNullTerminator=*/false, IsVolatile);
159159
}
160160

161161
//===----------------------------------------------------------------------===//
@@ -242,11 +242,10 @@ getMemoryBufferForStream(sys::fs::file_t FD, const Twine &BufferName) {
242242
}
243243

244244
ErrorOr<std::unique_ptr<MemoryBuffer>>
245-
MemoryBuffer::getFile(const Twine &Filename, int64_t FileSize,
246-
bool RequiresNullTerminator, bool IsVolatile,
247-
bool IsText) {
248-
return getFileAux<MemoryBuffer>(Filename, FileSize, FileSize, 0,
249-
RequiresNullTerminator, IsVolatile, IsText);
245+
MemoryBuffer::getFile(const Twine &Filename, bool IsText,
246+
bool RequiresNullTerminator, bool IsVolatile) {
247+
return getFileAux<MemoryBuffer>(Filename, /*MapSize=*/-1, /*Offset=*/0,
248+
IsText, RequiresNullTerminator, IsVolatile);
250249
}
251250

252251
template <typename MB>
@@ -257,33 +256,32 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
257256

258257
template <typename MB>
259258
static ErrorOr<std::unique_ptr<MB>>
260-
getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize,
261-
uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile,
262-
bool IsText) {
259+
getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
260+
bool IsText, bool RequiresNullTerminator, bool IsVolatile) {
263261
Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForRead(
264262
Filename, IsText ? sys::fs::OF_Text : sys::fs::OF_None);
265263
if (!FDOrErr)
266264
return errorToErrorCode(FDOrErr.takeError());
267265
sys::fs::file_t FD = *FDOrErr;
268-
auto Ret = getOpenFileImpl<MB>(FD, Filename, FileSize, MapSize, Offset,
266+
auto Ret = getOpenFileImpl<MB>(FD, Filename, /*FileSize=*/-1, MapSize, Offset,
269267
RequiresNullTerminator, IsVolatile);
270268
sys::fs::closeFile(FD);
271269
return Ret;
272270
}
273271

274272
ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
275-
WritableMemoryBuffer::getFile(const Twine &Filename, int64_t FileSize,
276-
bool IsVolatile) {
277-
return getFileAux<WritableMemoryBuffer>(Filename, FileSize, FileSize, 0,
278-
/*RequiresNullTerminator*/ false,
279-
IsVolatile, false);
273+
WritableMemoryBuffer::getFile(const Twine &Filename, bool IsVolatile) {
274+
return getFileAux<WritableMemoryBuffer>(
275+
Filename, /*MapSize=*/-1, /*Offset=*/0, /*IsText=*/false,
276+
/*RequiresNullTerminator=*/false, IsVolatile);
280277
}
281278

282279
ErrorOr<std::unique_ptr<WritableMemoryBuffer>>
283280
WritableMemoryBuffer::getFileSlice(const Twine &Filename, uint64_t MapSize,
284281
uint64_t Offset, bool IsVolatile) {
285-
return getFileAux<WritableMemoryBuffer>(Filename, -1, MapSize, Offset, false,
286-
IsVolatile, false);
282+
return getFileAux<WritableMemoryBuffer>(
283+
Filename, MapSize, Offset, /*IsText=*/false,
284+
/*RequiresNullTerminator=*/false, IsVolatile);
287285
}
288286

289287
std::unique_ptr<WritableMemoryBuffer>

llvm/lib/TableGen/Main.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ int llvm::TableGenMain(const char *argv0, TableGenMainFn *MainFn) {
9393

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

0 commit comments

Comments
 (0)