This is an archive of the discontinued LLVM Phabricator instance.

clang/Basic: Replace ContentCache::getBuffer with Optional semantics
ClosedPublic

Authored by dexonsmith on Oct 13 2020, 3:43 PM.

Details

Summary

Remove ContentCache::getBuffer, which always returned a
dereferenceable MemoryBuffer* and had a bool*Invalid out parameter,
and replace it with:

  • ContentCache::getBufferOrNone, which returns Optional<MemoryBufferRef>. This is the new API that consumers should use. Later it could be renamed to getBuffer, but intentionally using a different name to root out any unexpected callers.
  • ContentCache::getBufferPointer, which returns MemoryBuffer* with "optional" semantics. This is private to avoid growing callers and SourceManager has temporarily been made a friend to access it. Later paches will update the transitive callers to not need a raw pointer, and eventually this will be deleted.

No functionality change intended here.

Diff Detail

Event Timeline

dexonsmith created this revision.Oct 13 2020, 3:43 PM

Fixed a bug where Invalid was only set when it was true.

Fix a few more places where Invalid needs to be set to false.

Cleaned up the (fixed) Invalid logic to reduce the size of the diff and use a consistent pattern. Thanks for you patience with the false start; I think this is ready now.

Hah, and now I notice while working on a follow-up that SourceManager::getBufferOrNone was missing a const-qualifier (the use in this patch didn't need it). Fixed that too.

arphaman accepted this revision.Oct 14 2020, 10:53 AM
This revision is now accepted and ready to land.Oct 14 2020, 10:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2020, 12:56 PM