From: Stephen Kelly Date: Mon, 26 Apr 2021 17:28:50 +0000 (+0100) Subject: [AST] Fix DeclarationNameInfo introspection X-Git-Tag: llvmorg-14-init~8436 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=50b523cb2ceee4ca7279b4ce22ddb0d0b05df313;p=platform%2Fupstream%2Fllvm.git [AST] Fix DeclarationNameInfo introspection Some AST classes return `const DeclarationNameInfo &` instead of returning by value (eg CXXDependentScopeMemberExpr). --- diff --git a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp index 0aeb3a7..0a7fb9b 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("derivedFrom")) { diff --git a/clang/unittests/Introspection/IntrospectionTest.cpp b/clang/unittests/Introspection/IntrospectionTest.cpp index 521520c..d4f626b 100644 --- a/clang/unittests/Introspection/IntrospectionTest.cpp +++ b/clang/unittests/Introspection/IntrospectionTest.cpp @@ -1456,6 +1456,72 @@ getNamedTypeInfo()->getTypeLoc().getAs().getNameLoc()), STRING_LOCATION_PAIR((&NI), getSourceRange()))); } +TEST(Introspection, SourceLocations_DeclarationNameInfo_CRef) { + if (!NodeIntrospection::hasIntrospectionSupport()) + return; + + auto AST = buildASTFromCodeWithArgs( + R"cpp( +template +struct MyContainer +{ + template + void pushBack(); +}; + +template +void foo() +{ + MyContainer mc; + mc.template pushBack(); +} +)cpp", + {"-fno-delayed-template-parsing"}, "foo.cpp", "clang-tool", + std::make_shared()); + + 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("member"); + auto Result = NodeIntrospection::GetLocations(Member); + + auto ExpectedLocations = + FormatExpected(Result.LocationAccessors); + + llvm::sort(ExpectedLocations); + + EXPECT_EQ( + llvm::makeArrayRef(ExpectedLocations), + (ArrayRef>{ + 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(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;