[PATCH] D123685: [clang][ASTImporter] Add isNewDecl
Gabor Marton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 13 09:06:34 PDT 2022
martong created this revision.
martong added reviewers: balazske, steakhal.
Herald added subscribers: gamesh411, Szelethus, dkrupp, rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
martong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Add a new function with which we can query if a Decl had been newly
created during the import process. This feature is a must if we want to
have a different static analysis strategy for such newly created
declarations.
This is a dependent patch that is needed for the new CTU implementation
discribed at
https://discourse.llvm.org/t/rfc-much-faster-cross-translation-unit-ctu-analysis-implementation/61728
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D123685
Files:
clang/include/clang/AST/ASTImporterSharedState.h
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp
Index: clang/unittests/AST/ASTImporterTest.cpp
===================================================================
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -7527,6 +7527,38 @@
EXPECT_TRUE(ToA->isCompleteDefinition());
}
+TEST_P(ASTImporterOptionSpecificTestBase, isNewDecl) {
+ Decl *FromTU = getTuDecl(
+ R"(
+ int bar() {
+ return 0;
+ }
+ void other() {
+ bar();
+ }
+ )",
+ Lang_CXX11);
+ Decl *ToTU = getToTuDecl(
+ R"(
+ int bar() {
+ return 0;
+ }
+ )",
+ Lang_CXX11);
+ auto *FromOther = FirstDeclMatcher<FunctionDecl>().match(
+ FromTU, functionDecl(hasName("other")));
+ ASSERT_TRUE(FromOther);
+
+ auto *ToOther = Import(FromOther, Lang_CXX11);
+ ASSERT_TRUE(ToOther);
+
+ auto *ToBar = FirstDeclMatcher<FunctionDecl>().match(
+ ToTU, functionDecl(hasName("bar")));
+
+ EXPECT_TRUE(SharedStatePtr->isNewDecl(ToOther));
+ EXPECT_FALSE(SharedStatePtr->isNewDecl(ToBar));
+}
+
INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
DefaultTestValuesForRunOptions);
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -245,6 +245,7 @@
ToD = CreateFun(std::forward<Args>(args)...);
// Keep track of imported Decls.
Importer.RegisterImportedDecl(FromD, ToD);
+ Importer.SharedState->setNewDecl(ToD);
InitializeImportedDecl(FromD, ToD);
return false; // A new Decl is created.
}
Index: clang/include/clang/AST/ASTImporterSharedState.h
===================================================================
--- clang/include/clang/AST/ASTImporterSharedState.h
+++ clang/include/clang/AST/ASTImporterSharedState.h
@@ -39,6 +39,9 @@
/// never cleared (like ImportedFromDecls).
llvm::DenseMap<Decl *, ImportError> ImportErrors;
+ /// Set of the newly created declarations.
+ llvm::DenseSet<Decl *> NewDecls;
+
// FIXME put ImportedFromDecls here!
// And from that point we can better encapsulate the lookup table.
@@ -74,6 +77,10 @@
void setImportDeclError(Decl *To, ImportError Error) {
ImportErrors[To] = Error;
}
+
+ bool isNewDecl(const Decl *ToD) const { return NewDecls.count(ToD); }
+
+ void setNewDecl(Decl *ToD) { NewDecls.insert(ToD); }
};
} // namespace clang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123685.422533.patch
Type: text/x-patch
Size: 2475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220413/26c1a74a/attachment.bin>
More information about the cfe-commits
mailing list