This is an archive of the discontinued LLVM Phabricator instance.

Basic: Return a reference from FileManager::getVirtualFileSystem, NFC
ClosedPublic

Authored by dexonsmith on Mar 14 2019, 2:49 PM.

Details

Summary

FileManager constructs a VFS in its constructor if it isn't passed one,
and there's no way to reset it. Make that contract clear by returning a
reference from its accessor.

Diff Detail

Event Timeline

dexonsmith created this revision.Mar 14 2019, 2:49 PM

Hi Duncan, thanks for working on better interfaces in clang!

I am just wondering - is it safe to have the lifetime of a single object on heap managed by two different IntrusiveRefCntPtr instances?

clang/lib/Frontend/ASTUnit.cpp
1693

Is this safe?

1800

Is this safe?

2236–2237

Is this safe?

clang/lib/Frontend/CompilerInstance.cpp
299

Is this safe?

clang/lib/Tooling/Tooling.cpp
304

The Driver constructor takes IntrusiveRefCntPtr< llvm::vfs::FileSystem > as an argument. Is this safe?

https://clang.llvm.org/doxygen/classclang_1_1driver_1_1Driver.html#a1930cae44e647c1983d11d6a61ce14ed

Hi Duncan, thanks for working on better interfaces in clang!

I am just wondering - is it safe to have the lifetime of a single object on heap managed by two different IntrusiveRefCntPtr instances?

Yes, it's safe. The reference count is "intrusive", meaning it's stored in the object itself (via inheritance from RefCountedBase). As a result, all the instances of IntrusiveRefCntPtr that reference at the same object will implicitly share their count.

martong resigned from this revision.Mar 19 2019, 3:58 AM
jkorous accepted this revision.Mar 19 2019, 11:28 AM

Yes, it's safe. The reference count is "intrusive", meaning it's stored in the object itself (via inheritance from RefCountedBase). As a result, all the instances of IntrusiveRefCntPtr that reference at the same object will implicitly share their count.

I missed that llvm::vfs::FileSystem inherits from ThreadSafeRefCountedBase.

LGTM.

This revision is now accepted and ready to land.Mar 19 2019, 11:28 AM
dexonsmith closed this revision.Mar 26 2019, 3:30 PM

Committed r357038.