[PATCH] D91296: Frontend: Clarify logic for using the preamble in ASTUnit::CodeComplete, almost NFC
Duncan P. N. Exon Smith via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 8 12:52:54 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG51f3432f4b52: Frontend: Clarify logic for using the preamble in ASTUnit::CodeComplete, almost… (authored by dexonsmith).
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91296/new/
https://reviews.llvm.org/D91296
Files:
clang/lib/Frontend/ASTUnit.cpp
Index: clang/lib/Frontend/ASTUnit.cpp
===================================================================
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -2237,28 +2237,30 @@
= new AugmentedCodeCompleteConsumer(*this, Consumer, CodeCompleteOpts);
Clang->setCodeCompletionConsumer(AugmentedConsumer);
+ auto getUniqueID =
+ [&FileMgr](StringRef Filename) -> Optional<llvm::sys::fs::UniqueID> {
+ if (auto Status = FileMgr.getVirtualFileSystem().status(Filename))
+ return Status->getUniqueID();
+ return None;
+ };
+
+ auto hasSameUniqueID = [getUniqueID](StringRef LHS, StringRef RHS) {
+ if (LHS == RHS)
+ return true;
+ if (auto LHSID = getUniqueID(LHS))
+ if (auto RHSID = getUniqueID(RHS))
+ return *LHSID == *RHSID;
+ return false;
+ };
+
// If we have a precompiled preamble, try to use it. We only allow
// the use of the precompiled preamble if we're if the completion
// point is within the main file, after the end of the precompiled
// preamble.
std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
- if (Preamble) {
- std::string CompleteFilePath(File);
-
- auto &VFS = FileMgr.getVirtualFileSystem();
- auto CompleteFileStatus = VFS.status(CompleteFilePath);
- if (CompleteFileStatus) {
- llvm::sys::fs::UniqueID CompleteFileID = CompleteFileStatus->getUniqueID();
-
- std::string MainPath(OriginalSourceFile);
- auto MainStatus = VFS.status(MainPath);
- if (MainStatus) {
- llvm::sys::fs::UniqueID MainID = MainStatus->getUniqueID();
- if (CompleteFileID == MainID && Line > 1)
- OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
- PCHContainerOps, Inv, &VFS, false, Line - 1);
- }
- }
+ if (Preamble && Line > 1 && hasSameUniqueID(File, OriginalSourceFile)) {
+ OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
+ PCHContainerOps, Inv, &FileMgr.getVirtualFileSystem(), false, Line - 1);
}
// If the main file has been overridden due to the use of a preamble,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91296.310324.patch
Type: text/x-patch
Size: 2087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201208/3028b818/attachment.bin>
More information about the cfe-commits
mailing list