This is an archive of the discontinued LLVM Phabricator instance.

[FileManager] getFile(open=true) after getFile(open=false) should open the file.
ClosedPublic

Authored by sammccall on Nov 19 2018, 1:11 AM.

Details

Summary

Old behavior is to just return the cached entry regardless of opened-ness.
That feels buggy (though I guess nobody ever actually needed this).

This came up in the context of clangd+clang-tidy integration: we're
going to getFile(open=false) to replay preprocessor actions obscured by
the preamble, but the compilation may subsequently getFile(open=true)
for non-preamble includes.

Diff Detail

Event Timeline

sammccall created this revision.Nov 19 2018, 1:11 AM

Overall LG. The only concerning bit is that the initialization of the UFE is now scattered across the function body.
Grouping File and DeferredOpen into a struct or adding a comment that those are initialized separately from the rest of the fields might make it more evident what's going on. WDYT?

include/clang/Basic/FileManager.h
72

NIT: not sure if it's actually that useful, but the fact that the comment mentioned that FileEntry could be uninitialized if IsValid is false was a hint that drew my attention to this.

lib/Basic/FileManager.cpp
263

Maybe add a comment that DeferredOpen might do an extra stat here that could technically be avoided?
No need to fix this, though, hopefully that won't matter.

306

Maybe add an assertion that DeferredOpen is false at this point?
To make it clear we'll never hit this branch twice.

sammccall marked 3 inline comments as done.Nov 19 2018, 2:41 AM

Overall LG. The only concerning bit is that the initialization of the UFE is now scattered across the function body.
Grouping File and DeferredOpen into a struct or adding a comment that those are initialized separately from the rest of the fields might make it more evident what's going on. WDYT?

I added a comment in getFile() where ~all the UFE fields are initialized that File and DeferredOpen are initialized above.
Added a redundant initialization in getVirtualFile() for clarity.

sammccall updated this revision to Diff 174577.Nov 19 2018, 2:41 AM

Address review comments.

ilya-biryukov accepted this revision.Nov 19 2018, 3:46 AM

Thanks! LGTM

This revision is now accepted and ready to land.Nov 19 2018, 3:46 AM
This revision was automatically updated to reflect the committed changes.