[clang] 50b523c - [AST] Fix DeclarationNameInfo introspection
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 26 10:49:25 PDT 2021
Author: Stephen Kelly
Date: 2021-04-26T18:49:13+01:00
New Revision: 50b523cb2ceee4ca7279b4ce22ddb0d0b05df313
URL: https://github.com/llvm/llvm-project/commit/50b523cb2ceee4ca7279b4ce22ddb0d0b05df313
DIFF: https://github.com/llvm/llvm-project/commit/50b523cb2ceee4ca7279b4ce22ddb0d0b05df313.diff
LOG: [AST] Fix DeclarationNameInfo introspection
Some AST classes return `const DeclarationNameInfo &` instead of
returning by value (eg CXXDependentScopeMemberExpr).
Added:
Modified:
clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
clang/unittests/Introspection/IntrospectionTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
index 0aeb3a7703f7..0a7fb9b52f23 100644
--- a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
+++ b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
@@ -225,6 +225,9 @@ void ASTSrcLocProcessor::run(const MatchFinder::MatchResult &Result) {
CaptureMethods("class clang::NestedNameSpecifierLoc", ASTClass, Result);
CD.DeclNameInfos =
CaptureMethods("struct clang::DeclarationNameInfo", ASTClass, Result);
+ auto DI = CaptureMethods("const struct clang::DeclarationNameInfo &",
+ ASTClass, Result);
+ CD.DeclNameInfos.insert(CD.DeclNameInfos.end(), DI.begin(), DI.end());
if (const auto *DerivedFrom =
Result.Nodes.getNodeAs<clang::CXXRecordDecl>("derivedFrom")) {
diff --git a/clang/unittests/Introspection/IntrospectionTest.cpp b/clang/unittests/Introspection/IntrospectionTest.cpp
index 521520c9a7c7..d4f626bfeb74 100644
--- a/clang/unittests/Introspection/IntrospectionTest.cpp
+++ b/clang/unittests/Introspection/IntrospectionTest.cpp
@@ -1456,6 +1456,72 @@ getNamedTypeInfo()->getTypeLoc().getAs<clang::TypeSpecTypeLoc>().getNameLoc()),
STRING_LOCATION_PAIR((&NI), getSourceRange())));
}
+TEST(Introspection, SourceLocations_DeclarationNameInfo_CRef) {
+ if (!NodeIntrospection::hasIntrospectionSupport())
+ return;
+
+ auto AST = buildASTFromCodeWithArgs(
+ R"cpp(
+template<typename T>
+struct MyContainer
+{
+ template <typename U>
+ void pushBack();
+};
+
+template<typename T>
+void foo()
+{
+ MyContainer<T> mc;
+ mc.template pushBack<int>();
+}
+)cpp",
+ {"-fno-delayed-template-parsing"}, "foo.cpp", "clang-tool",
+ std::make_shared<PCHContainerOperations>());
+
+ auto &Ctx = AST->getASTContext();
+ auto &TU = *Ctx.getTranslationUnitDecl();
+
+ auto BoundNodes = ast_matchers::match(
+ decl(hasDescendant(cxxDependentScopeMemberExpr(hasMemberName("pushBack")).bind("member"))), TU,
+ Ctx);
+
+ EXPECT_EQ(BoundNodes.size(), 1u);
+
+ const auto *Member = BoundNodes[0].getNodeAs<CXXDependentScopeMemberExpr>("member");
+ auto Result = NodeIntrospection::GetLocations(Member);
+
+ auto ExpectedLocations =
+ FormatExpected<SourceLocation>(Result.LocationAccessors);
+
+ llvm::sort(ExpectedLocations);
+
+ EXPECT_EQ(
+ llvm::makeArrayRef(ExpectedLocations),
+ (ArrayRef<std::pair<std::string, SourceLocation>>{
+ STRING_LOCATION_STDPAIR(Member, getBeginLoc()),
+ STRING_LOCATION_STDPAIR(Member, getEndLoc()),
+ STRING_LOCATION_STDPAIR(Member, getExprLoc()),
+ STRING_LOCATION_STDPAIR(Member, getLAngleLoc()),
+ STRING_LOCATION_STDPAIR(Member, getMemberLoc()),
+ STRING_LOCATION_STDPAIR(Member, getMemberNameInfo().getBeginLoc()),
+ STRING_LOCATION_STDPAIR(Member, getMemberNameInfo().getEndLoc()),
+ STRING_LOCATION_STDPAIR(Member, getMemberNameInfo().getLoc()),
+ STRING_LOCATION_STDPAIR(Member, getOperatorLoc()),
+ STRING_LOCATION_STDPAIR(Member, getRAngleLoc()),
+ STRING_LOCATION_STDPAIR(Member, getTemplateKeywordLoc())
+ }));
+
+ auto ExpectedRanges = FormatExpected<SourceRange>(Result.RangeAccessors);
+
+ EXPECT_THAT(
+ ExpectedRanges,
+ UnorderedElementsAre(
+ STRING_LOCATION_PAIR(Member, getMemberNameInfo().getSourceRange()),
+ STRING_LOCATION_PAIR(Member, getSourceRange())
+ ));
+}
+
TEST(Introspection, SourceLocations_DeclarationNameInfo_ConvOp) {
if (!NodeIntrospection::hasIntrospectionSupport())
return;
More information about the cfe-commits
mailing list