[PATCH] D20446: clang-rename: fix renaming members when referenced as macro arguments
Miklos Vajna via cfe-commits
cfe-commits at lists.llvm.org
Thu May 19 12:52:22 PDT 2016
vmiklos created this revision.
vmiklos added reviewers: cfe-commits, klimek.
The second check failed, FOO(C.X) wasn't renamed to FOO(C.Y).
http://reviews.llvm.org/D20446
Files:
clang-rename/USRLocFinder.cpp
test/clang-rename/MemberExprMacro.cpp
Index: test/clang-rename/MemberExprMacro.cpp
===================================================================
--- /dev/null
+++ test/clang-rename/MemberExprMacro.cpp
@@ -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.
Index: clang-rename/USRLocFinder.cpp
===================================================================
--- clang-rename/USRLocFinder.cpp
+++ clang-rename/USRLocFinder.cpp
@@ -103,7 +103,14 @@
bool VisitMemberExpr(const MemberExpr *Expr) {
const auto *Decl = Expr->getFoundDecl().getDecl();
if (getUSRForDecl(Decl) == USR) {
- LocationsFound.push_back(Expr->getMemberLoc());
+ SourceLocation Location = Expr->getMemberLoc();
+ if (Location.isMacroID()) {
+ // The location is expanded from a macro, look up the original spelling
+ // location.
+ const ASTContext &Context = Decl->getASTContext();
+ Location = Context.getSourceManager().getSpellingLoc(Location);
+ }
+ LocationsFound.push_back(Location);
}
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20446.57838.patch
Type: text/x-patch
Size: 1418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160519/7520803b/attachment.bin>
More information about the cfe-commits
mailing list