[clang-tools-extra] r270599 - clang-rename: fix renaming non-members variables when referenced as macro arguments

Miklos Vajna via cfe-commits cfe-commits at lists.llvm.org
Tue May 24 12:08:53 PDT 2016


Author: vmiklos
Date: Tue May 24 14:08:53 2016
New Revision: 270599

URL: http://llvm.org/viewvc/llvm-project?rev=270599&view=rev
Log:
clang-rename: fix renaming non-members variables when referenced as macro arguments

The second check failed, FOO(C::X) wasn't renamed to FOO(C::Y).

Reviewers: klimek

Differential Revision: http://reviews.llvm.org/D20537

Added:
    clang-tools-extra/trunk/test/clang-rename/DeclRefExpr.cpp
Modified:
    clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp

Modified: clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp?rev=270599&r1=270598&r2=270599&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp (original)
+++ clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp Tue May 24 14:08:53 2016
@@ -94,7 +94,9 @@ public:
 
     checkNestedNameSpecifierLoc(Expr->getQualifierLoc());
     if (getUSRForDecl(Decl) == USR) {
-      LocationsFound.push_back(Expr->getLocation());
+      const SourceManager &Manager = Decl->getASTContext().getSourceManager();
+      SourceLocation Location = Manager.getSpellingLoc(Expr->getLocation());
+      LocationsFound.push_back(Location);
     }
 
     return true;

Added: clang-tools-extra/trunk/test/clang-rename/DeclRefExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/DeclRefExpr.cpp?rev=270599&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-rename/DeclRefExpr.cpp (added)
+++ clang-tools-extra/trunk/test/clang-rename/DeclRefExpr.cpp Tue May 24 14:08:53 2016
@@ -0,0 +1,24 @@
+// RUN: cat %s > %t.cpp
+// RUN: clang-rename -offset=158 -new-name=Y %t.cpp -i --
+// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
+class C
+{
+public:
+  static int X;
+};
+
+int foo(int x)
+{
+  return 0;
+}
+#define FOO(a) foo(a)
+
+int main()
+{
+  C::X = 1; // CHECK: C::Y
+  FOO(C::X); // CHECK: C::Y
+  int y = C::X; // CHECK: C::Y
+}
+
+// Use grep -FUbo 'X' <file> to get the correct offset of foo when changing
+// this file.




More information about the cfe-commits mailing list