Skip to content

Conversation

@yuhaouy
Copy link
Contributor

@yuhaouy yuhaouy commented Nov 12, 2025

Previously, e.g. for TypeLoc "MyNamespace::MyClass", node() selects only "MyClass" without the qualifier. With this change, it now selects "MyNamespace::MyClass".

yuhaouy and others added 4 commits October 24, 2025 12:57
…nstead of an invalid range.

Previously, when the text in selected range was different from the decl's name, `name` returned an invalid range, which could cause crashes if `name` was nested in other range selectors that  assumed always valid ranges. With this change, `name` returns an `Error` if it can't get the range.
…ualifiers of type locs.

Previously, e.g. for TypeLoc "MyNamespace::MyClass", `node()` selects only "MyClass" without the qualifier. With this change, it now selects "MyNamespace::MyClass".
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Nov 12, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 12, 2025

@llvm/pr-subscribers-clang

Author: Yu Hao (yuhaouy)

Changes

Previously, e.g. for TypeLoc "MyNamespace::MyClass", node() selects only "MyClass" without the qualifier. With this change, it now selects "MyNamespace::MyClass".


Full diff: https://github.com/llvm/llvm-project/pull/167619.diff

2 Files Affected:

  • (modified) clang/lib/Tooling/Transformer/RangeSelector.cpp (+1-1)
  • (modified) clang/unittests/Tooling/RangeSelectorTest.cpp (+7)
diff --git a/clang/lib/Tooling/Transformer/RangeSelector.cpp b/clang/lib/Tooling/Transformer/RangeSelector.cpp
index b4bdec1fcdd69..d669be2ca0409 100644
--- a/clang/lib/Tooling/Transformer/RangeSelector.cpp
+++ b/clang/lib/Tooling/Transformer/RangeSelector.cpp
@@ -139,7 +139,7 @@ RangeSelector transformer::node(std::string ID) {
             (Node->get<Stmt>() != nullptr && Node->get<Expr>() == nullptr))
                ? tooling::getExtendedRange(*Node, tok::TokenKind::semi,
                                            *Result.Context)
-               : CharSourceRange::getTokenRange(Node->getSourceRange());
+               : CharSourceRange::getTokenRange(Node->getSourceRange(true));
   };
 }
 
diff --git a/clang/unittests/Tooling/RangeSelectorTest.cpp b/clang/unittests/Tooling/RangeSelectorTest.cpp
index a1fcbb023832f..d441da165b09b 100644
--- a/clang/unittests/Tooling/RangeSelectorTest.cpp
+++ b/clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -339,6 +339,13 @@ TEST(RangeSelectorTest, NodeOpExpression) {
   EXPECT_THAT_EXPECTED(select(node("id"), Match), HasValue("3"));
 }
 
+TEST(RangeSelectorTest, NodeOpTypeLoc) {
+  StringRef Code = "namespace ns {struct Foo{};} ns::Foo a;";
+  TestMatch Match =
+      matchCode(Code, varDecl(hasTypeLoc(typeLoc().bind("typeloc"))));
+  EXPECT_THAT_EXPECTED(select(node("typeloc"), Match), HasValue("ns::Foo"));
+}
+
 TEST(RangeSelectorTest, StatementOp) {
   StringRef Code = "int f() { return 3; }";
   TestMatch Match = matchCode(Code, expr().bind("id"));

@fmayer fmayer requested a review from ymand November 12, 2025 02:06
Copy link
Collaborator

@ymand ymand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, but see my request for clarification.

@github-actions
Copy link

🐧 Linux x64 Test Results

  • 111318 tests passed
  • 4420 tests skipped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants