[clang] 782c3e2 - [AST] Fix comparison to of SourceRanges in container

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 19 13:19:46 PDT 2021


Author: Stephen Kelly
Date: 2021-04-19T21:19:21+01:00
New Revision: 782c3e23ba09ca7b01034d0fbf0b34044c1c79a3

URL: https://github.com/llvm/llvm-project/commit/782c3e23ba09ca7b01034d0fbf0b34044c1c79a3
DIFF: https://github.com/llvm/llvm-project/commit/782c3e23ba09ca7b01034d0fbf0b34044c1c79a3.diff

LOG: [AST] Fix comparison to of SourceRanges in container

Differential Revision: https://reviews.llvm.org/D100723

Added: 
    

Modified: 
    clang/lib/Tooling/NodeIntrospection.cpp
    clang/unittests/Introspection/IntrospectionTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Tooling/NodeIntrospection.cpp b/clang/lib/Tooling/NodeIntrospection.cpp
index 6a8d7267f8ae4..8e2d446c3efec 100644
--- a/clang/lib/Tooling/NodeIntrospection.cpp
+++ b/clang/lib/Tooling/NodeIntrospection.cpp
@@ -44,9 +44,6 @@ namespace internal {
 bool RangeLessThan::operator()(
     std::pair<SourceRange, SharedLocationCall> const &LHS,
     std::pair<SourceRange, SharedLocationCall> const &RHS) const {
-  if (!LHS.first.isValid() || !RHS.first.isValid())
-    return false;
-
   if (LHS.first.getBegin() < RHS.first.getBegin())
     return true;
   else if (LHS.first.getBegin() != RHS.first.getBegin())

diff  --git a/clang/unittests/Introspection/IntrospectionTest.cpp b/clang/unittests/Introspection/IntrospectionTest.cpp
index 1db3e6a8e6d65..76b47b34a7916 100644
--- a/clang/unittests/Introspection/IntrospectionTest.cpp
+++ b/clang/unittests/Introspection/IntrospectionTest.cpp
@@ -91,6 +91,20 @@ TEST(Introspection, SourceLocations_CallContainer) {
   EXPECT_EQ(slm.size(), 2u);
 }
 
+TEST(Introspection, SourceLocations_CallContainer2) {
+  SourceRangeMap slm;
+  SharedLocationCall Prefix;
+  slm.insert(
+      std::make_pair(SourceRange(), llvm::makeIntrusiveRefCnt<LocationCall>(
+                                        Prefix, "getCXXOperatorNameRange")));
+  EXPECT_EQ(slm.size(), 1u);
+
+  slm.insert(std::make_pair(
+      SourceRange(),
+      llvm::makeIntrusiveRefCnt<LocationCall>(Prefix, "getSourceRange")));
+  EXPECT_EQ(slm.size(), 2u);
+}
+
 TEST(Introspection, SourceLocations_CallChainFormatting) {
   SharedLocationCall Prefix;
   auto chainedCall = llvm::makeIntrusiveRefCnt<LocationCall>(


        


More information about the cfe-commits mailing list