Skip to content

Commit cdb3994

Browse files
committed
address comments
1 parent c1676e4 commit cdb3994

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

clang/include/clang/Basic/FileManager.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,19 @@ class FileManager : public RefCountedBase<FileManager> {
290290

291291
/// Open the specified file as a MemoryBuffer, returning a new
292292
/// MemoryBuffer if successful, otherwise returning null.
293+
/// The IsText parameter controls whether the file should be opened as a text
294+
/// or binary file, and should be set to false if the file contents should be
295+
/// treated as binary.
293296
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
294297
getBufferForFile(FileEntryRef Entry, bool isVolatile = false,
295-
bool RequiresNullTerminator = true, bool IsText = true,
296-
std::optional<int64_t> MaybeLimit = std::nullopt);
298+
bool RequiresNullTerminator = true,
299+
std::optional<int64_t> MaybeLimit = std::nullopt,
300+
bool IsText = true);
297301
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
298302
getBufferForFile(StringRef Filename, bool isVolatile = false,
299-
bool RequiresNullTerminator = true, bool IsText = true,
300-
std::optional<int64_t> MaybeLimit = std::nullopt) const {
303+
bool RequiresNullTerminator = true,
304+
std::optional<int64_t> MaybeLimit = std::nullopt,
305+
bool IsText = true) const {
301306
return getBufferForFileImpl(Filename,
302307
/*FileSize=*/MaybeLimit.value_or(-1),
303308
isVolatile, RequiresNullTerminator, IsText);

clang/lib/Basic/FileManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) {
530530

531531
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
532532
FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile,
533-
bool RequiresNullTerminator, bool IsText,
534-
std::optional<int64_t> MaybeLimit) {
533+
bool RequiresNullTerminator,
534+
std::optional<int64_t> MaybeLimit, bool IsText) {
535535
const FileEntry *Entry = &FE.getFileEntry();
536536
// If the content is living on the file entry, return a reference to it.
537537
if (Entry->Content)

clang/lib/Lex/HeaderMap.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ std::unique_ptr<HeaderMap> HeaderMap::Create(FileEntryRef FE, FileManager &FM) {
5656

5757
auto FileBuffer =
5858
FM.getBufferForFile(FE, /*IsVolatile=*/false,
59-
/*RequiresNullTerminator=*/true, /*IsText=*/false);
59+
/*RequiresNullTerminator=*/true,
60+
/*MaybeList=*/std::nullopt, /*IsText=*/false);
6061
if (!FileBuffer || !*FileBuffer)
6162
return nullptr;
6263
bool NeedsByteSwap;

clang/lib/Serialization/ASTReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5334,6 +5334,7 @@ std::string ASTReader::getOriginalSourceFile(
53345334
// Open the AST file.
53355335
auto Buffer = FileMgr.getBufferForFile(ASTFileName, /*IsVolatile=*/false,
53365336
/*RequiresNullTerminator=*/false,
5337+
/*MaybeLimit=*/std::nullopt,
53375338
/*IsText=*/false);
53385339
if (!Buffer) {
53395340
Diags.Report(diag::err_fe_unable_to_read_pch_file)

llvm/include/llvm/Support/VirtualFileSystem.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,20 @@ class FileSystem : public llvm::ThreadSafeRefCountedBase<FileSystem>,
275275
virtual llvm::ErrorOr<std::unique_ptr<File>>
276276
openFileForRead(const Twine &Path) = 0;
277277

278-
/// Get a \p File objct for the binary file at \p Path, if one exists.
279-
/// This function should be called instead of openFileForRead if the file
280-
/// should be opened as a binary file.
278+
/// Get a \p File object for the binary file at \p Path, if one exists.
279+
/// Some non-ascii based file systems perform encoding conversions
280+
/// when reading as a text file, and this function should be used if
281+
/// a file's bytes should be read as-is. On most filesystems, this
282+
/// is the same behaviour as openFileForRead.
281283
virtual llvm::ErrorOr<std::unique_ptr<File>>
282284
openFileForReadBinary(const Twine &Path) {
283285
return openFileForRead(Path);
284286
}
285287

286288
/// This is a convenience method that opens a file, gets its content and then
287289
/// closes the file.
290+
/// The IsText parameter is used to distinguish whether the file should be
291+
/// opened as a binary or text file.
288292
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
289293
getBufferForFile(const Twine &Name, int64_t FileSize = -1,
290294
bool RequiresNullTerminator = true, bool IsVolatile = false,

llvm/lib/Support/VirtualFileSystem.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ class RealFileSystem : public FileSystem {
305305
return Storage;
306306
}
307307

308-
ErrorOr<std::unique_ptr<File>> openFileForRead(const Twine &Name,
309-
sys::fs::OpenFlags Flags) {
308+
ErrorOr<std::unique_ptr<File>>
309+
openFileForReadWithFlags(const Twine &Name, sys::fs::OpenFlags Flags) {
310310
SmallString<256> RealName, Storage;
311311
Expected<file_t> FDOrErr = sys::fs::openNativeFileForRead(
312312
adjustPath(Name, Storage), Flags, &RealName);
@@ -338,12 +338,12 @@ ErrorOr<Status> RealFileSystem::status(const Twine &Path) {
338338

339339
ErrorOr<std::unique_ptr<File>>
340340
RealFileSystem::openFileForRead(const Twine &Name) {
341-
return openFileForRead(Name, sys::fs::OF_Text);
341+
return openFileForReadWithFlags(Name, sys::fs::OF_Text);
342342
}
343343

344344
ErrorOr<std::unique_ptr<File>>
345345
RealFileSystem::openFileForReadBinary(const Twine &Name) {
346-
return openFileForRead(Name, sys::fs::OF_None);
346+
return openFileForReadWithFlags(Name, sys::fs::OF_None);
347347
}
348348

349349
llvm::ErrorOr<std::string> RealFileSystem::getCurrentWorkingDirectory() const {

0 commit comments

Comments
 (0)