This is an archive of the discontinued LLVM Phabricator instance.

clang/Basic: Replace SourceManager::getMemoryBufferForFile, NFC
ClosedPublic

Authored by dexonsmith on Oct 14 2020, 3:12 PM.

Details

Summary

Replace SourceManager::getMemoryBufferForFile, which returned a
dereferenceable MemoryBuffer* and had a bool*Invalid out parameter,
with getMemoryBufferForFileOrNone (returning
Optional<MemoryBufferRef>) and getMemoryBufferForFileOrFake
(returning MemoryBufferRef).

Diff Detail

Event Timeline

dexonsmith created this revision.Oct 14 2020, 3:12 PM
JDevlieghere added inline comments.Oct 16 2020, 12:45 PM
clang/lib/Basic/SourceManager.cpp
705

Would it make sense to rename this to the slightly less verbose getMemoryBufferOrNone now that it takes just the File as an argument? Or maybe even getBufferOrNone like the method in ContentCache.

dexonsmith added inline comments.Oct 19 2020, 2:15 PM
clang/lib/Basic/SourceManager.cpp
121–127

[Highlighting this for the other comment.]

705

There's already a SourceManager::getBufferOrNone (see line 121 of this file, which I am highlighting). I'd rather keep the current weird naming to make it easy to grep for and eventually delete.

This function shouldn't really exist since it's at the wrong layer (FileEntry* -> MemoryBuffer is a FileManager concept). The problem is that the SourceManager owns the memory buffer so this is the only way to get access to it. Once I sink the content cache / MemoryBuffer ownership into the FileManager, we can delete this entirely.

arphaman accepted this revision.Oct 19 2020, 9:45 PM
This revision is now accepted and ready to land.Oct 19 2020, 9:45 PM
JDevlieghere accepted this revision.Oct 20 2020, 10:38 AM

Thanks for the explanation!

Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2020, 2:01 PM