-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Cleanup IncludeLocMap #106241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang] Cleanup IncludeLocMap #106241
Conversation
@llvm/pr-subscribers-clang Author: kadir çetinkaya (kadircet) ChangesCompilerInstance can re-use same SourceManager across multiple It didn't reset IncludeLocMap, resulting in wrong include locations for Full diff: https://github.com/llvm/llvm-project/pull/106241.diff 1 Files Affected:
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index b0256a8ce9ed04..d6ec26af80aadd 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -350,6 +350,7 @@ void SourceManager::clearIDTables() {
LastLineNoContentCache = nullptr;
LastFileIDLookup = FileID();
+ IncludedLocMap.clear();
if (LineTable)
LineTable->clear();
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, but I wanted to explore if we could write a unit test for this...
ab986c7
to
f8fb043
Compare
You can test this locally with the following command:git-clang-format --diff b294951e3967730ffad14d51297694b1411d7af6 6f874afb3fac6a373c94897a5d17c4cd4d1653a6 --extensions cpp -- clang/lib/Basic/SourceManager.cpp clang/unittests/Basic/SourceManagerTest.cpp View the diff from clang-format here.diff --git a/clang/unittests/Basic/SourceManagerTest.cpp b/clang/unittests/Basic/SourceManagerTest.cpp
index c683bc2919..0f2476bd8b 100644
--- a/clang/unittests/Basic/SourceManagerTest.cpp
+++ b/clang/unittests/Basic/SourceManagerTest.cpp
@@ -474,13 +474,13 @@ TEST_F(SourceManagerTest, ResetsIncludeLocMap) {
};
auto Buf = llvm::MemoryBuffer::getMemBuffer("");
- FileEntryRef HeaderFile = FileMgr.getVirtualFileRef(
- "/foo.h", Buf->getBufferSize(), 0);
+ FileEntryRef HeaderFile =
+ FileMgr.getVirtualFileRef("/foo.h", Buf->getBufferSize(), 0);
SourceMgr.overrideFileContents(HeaderFile, std::move(Buf));
Buf = llvm::MemoryBuffer::getMemBuffer(R"cpp(#include "/foo.h")cpp");
- FileEntryRef BarFile = FileMgr.getVirtualFileRef(
- "/bar.h", Buf->getBufferSize(), 0);
+ FileEntryRef BarFile =
+ FileMgr.getVirtualFileRef("/bar.h", Buf->getBufferSize(), 0);
SourceMgr.overrideFileContents(BarFile, std::move(Buf));
SourceMgr.createFileID(BarFile, {}, clang::SrcMgr::C_User);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT with a small suggestion.
Thanks for getting the test in!
f8fb043
to
6f874af
Compare
CompilerInstance can re-use same SourceManager across multiple frontendactions. During this process it calls `SourceManager::clearIDTables` to reset any caches based on FileIDs. It didn't reset IncludeLocMap, resulting in wrong include locations for workflows that triggered multiple frontend-actions through same CompilerInstance.
6f874af
to
c8c29ea
Compare
CompilerInstance can re-use same SourceManager across multiple
frontendactions. During this process it calls
SourceManager::clearIDTables
to reset any caches based on FileIDs.It didn't reset IncludeLocMap, resulting in wrong include locations for
workflows that triggered multiple frontend-actions through same
CompilerInstance.