From 4f6d69846747dd53a54a5de0da7eca38df52d5ca Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 15 Apr 2021 12:18:34 +0100 Subject: [PATCH] [AST] Fix location call storage with common last-invocation Differential Revision: https://reviews.llvm.org/D100548 --- clang/lib/Tooling/NodeIntrospection.cpp | 6 +++-- .../Introspection/IntrospectionTest.cpp | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/clang/lib/Tooling/NodeIntrospection.cpp b/clang/lib/Tooling/NodeIntrospection.cpp index 2ee0b1cae55b..0e3ef3c6a01e 100644 --- a/clang/lib/Tooling/NodeIntrospection.cpp +++ b/clang/lib/Tooling/NodeIntrospection.cpp @@ -66,13 +66,15 @@ bool RangeLessThan::operator()( else if (LHS.first.getEnd() != RHS.first.getEnd()) return false; - return LHS.second->name() < RHS.second->name(); + return LocationCallFormatterCpp::format(*LHS.second) < + LocationCallFormatterCpp::format(*RHS.second); } bool RangeLessThan::operator()( std::pair const &LHS, std::pair const &RHS) const { if (LHS.first == RHS.first) - return LHS.second->name() < RHS.second->name(); + return LocationCallFormatterCpp::format(*LHS.second) < + LocationCallFormatterCpp::format(*RHS.second); return LHS.first < RHS.first; } } // namespace internal diff --git a/clang/unittests/Introspection/IntrospectionTest.cpp b/clang/unittests/Introspection/IntrospectionTest.cpp index 880068c43b6e..2df401c8d813 100644 --- a/clang/unittests/Introspection/IntrospectionTest.cpp +++ b/clang/unittests/Introspection/IntrospectionTest.cpp @@ -45,6 +45,31 @@ FormatExpected(const MapType &Accessors) { #define STRING_LOCATION_PAIR(INSTANCE, LOC) Pair(#LOC, INSTANCE->LOC) +TEST(Introspection, SourceLocations_CallContainer) { + SourceLocationMap slm; + SharedLocationCall Prefix; + slm.insert(std::make_pair( + SourceLocation(), + llvm::makeIntrusiveRefCnt(Prefix, "getSourceRange"))); + EXPECT_EQ(slm.size(), 1u); + + auto callTypeLoc = + llvm::makeIntrusiveRefCnt(Prefix, "getTypeLoc"); + slm.insert(std::make_pair( + SourceLocation(), + llvm::makeIntrusiveRefCnt(callTypeLoc, "getSourceRange"))); + EXPECT_EQ(slm.size(), 2u); +} + +TEST(Introspection, SourceLocations_CallChainFormatting) { + SharedLocationCall Prefix; + auto chainedCall = llvm::makeIntrusiveRefCnt( + llvm::makeIntrusiveRefCnt(Prefix, "getTypeLoc"), + "getSourceRange"); + EXPECT_EQ(LocationCallFormatterCpp::format(*chainedCall), + "getTypeLoc().getSourceRange()"); +} + TEST(Introspection, SourceLocations_Stmt) { if (!NodeIntrospection::hasIntrospectionSupport()) return;