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

Miklos Vajna via cfe-commits cfe-commits at lists.llvm.org
Fri May 20 04:44:02 PDT 2016


Author: vmiklos
Date: Fri May 20 06:43:59 2016
New Revision: 270204

URL: http://llvm.org/viewvc/llvm-project?rev=270204&view=rev
Log:
clang-rename: fix renaming members 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/D20446

Added:
    clang-tools-extra/trunk/test/clang-rename/MemberExprMacro.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=270204&r1=270203&r2=270204&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp (original)
+++ clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp Fri May 20 06:43:59 2016
@@ -103,7 +103,9 @@ public:
   bool VisitMemberExpr(const MemberExpr *Expr) {
     const auto *Decl = Expr->getFoundDecl().getDecl();
     if (getUSRForDecl(Decl) == USR) {
-      LocationsFound.push_back(Expr->getMemberLoc());
+      const SourceManager &Manager = Decl->getASTContext().getSourceManager();
+      SourceLocation Location = Manager.getSpellingLoc(Expr->getMemberLoc());
+      LocationsFound.push_back(Location);
     }
     return true;
   }

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




More information about the cfe-commits mailing list