[PATCH] D26609: [clang-move] Fix an incorrect range for the functions whose returned value is a macro

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 14 06:56:36 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL286833: [clang-move] Fix an incorrect range for the functions whose returned value is a… (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D26609?vs=77806&id=77810#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26609

Files:
  clang-tools-extra/trunk/clang-move/ClangMove.cpp
  clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp


Index: clang-tools-extra/trunk/clang-move/ClangMove.cpp
===================================================================
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp
@@ -227,8 +227,8 @@
 clang::CharSourceRange
 GetFullRange(const clang::SourceManager *SM, const clang::Decl *D,
              const clang::LangOptions &options = clang::LangOptions()) {
-  clang::SourceRange Full = D->getSourceRange();
-  Full.setEnd(getLocForEndOfDecl(D, SM));
+  clang::SourceRange Full(SM->getExpansionLoc(D->getLocStart()),
+                          getLocForEndOfDecl(D, SM));
   // Expand to comments that are associated with the Decl.
   if (const auto *Comment = D->getASTContext().getRawCommentForDeclNoCache(D)) {
     if (SM->isBeforeInTranslationUnit(Full.getEnd(), Comment->getLocEnd()))
Index: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
===================================================================
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
@@ -337,6 +337,24 @@
   }
 }
 
+TEST(ClangMove, MacroInFunction) {
+  const char TestHeader[] = "#define INT int\n"
+                            "class A {\npublic:\n  int f();\n};\n"
+                            "class B {};\n";
+  const char TestCode[] = "#include \"foo.h\"\n"
+                          "INT A::f() { return 0; }\n";
+  const char ExpectedNewCode[] = "#include \"new_foo.h\"\n\n"
+                                 "INT A::f() { return 0; }\n";
+  move::ClangMoveTool::MoveDefinitionSpec Spec;
+  Spec.Names.push_back("A");
+  Spec.OldHeader = "foo.h";
+  Spec.OldCC = "foo.cc";
+  Spec.NewHeader = "new_foo.h";
+  Spec.NewCC = "new_foo.cc";
+  auto Results = runClangMoveOnCode(Spec, TestHeader, TestCode);
+  EXPECT_EQ(ExpectedNewCode, Results[Spec.NewCC]);
+}
+
 } // namespace
 } // namespce move
 } // namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26609.77810.patch
Type: text/x-patch
Size: 1966 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161114/dd11063b/attachment.bin>


More information about the cfe-commits mailing list