[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:38:11 PST 2016
hokein created this revision.
hokein added a reviewer: ioeric.
hokein added a subscriber: cfe-commits.
Fix an incorrect range for the functions whose returned value is a macro
(e.g. `bool`). This incorrect range can lead to modifications of an unexpected
file where the macro is in.
We should use expansion location instead of spelling location.
https://reviews.llvm.org/D26609
Files:
clang-move/ClangMove.cpp
unittests/clang-move/ClangMoveTests.cpp
Index: unittests/clang-move/ClangMoveTests.cpp
===================================================================
--- unittests/clang-move/ClangMoveTests.cpp
+++ 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
Index: clang-move/ClangMove.cpp
===================================================================
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -227,8 +227,9 @@
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()))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26609.77806.patch
Type: text/x-patch
Size: 1810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161114/65b1708b/attachment.bin>
More information about the cfe-commits
mailing list