[PATCH] D27713: [clang-move] Fix incorrect EndLoc for declarations in macros.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 13 07:46:19 PST 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289541: [clang-move] Fix incorrect EndLoc for declarations in macros. (authored by hokein).
Changed prior to commit:
https://reviews.llvm.org/D27713?vs=81231&id=81234#toc
Repository:
rL LLVM
https://reviews.llvm.org/D27713
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
@@ -219,7 +219,8 @@
getLocForEndOfDecl(const clang::Decl *D,
const LangOptions &LangOpts = clang::LangOptions()) {
const auto &SM = D->getASTContext().getSourceManager();
- std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(D->getLocEnd());
+ auto EndExpansionLoc = SM.getExpansionLoc(D->getLocEnd());
+ std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(EndExpansionLoc);
// Try to load the file buffer.
bool InvalidTemp = false;
llvm::StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
@@ -235,7 +236,7 @@
// FIXME: this is a bit hacky to get ReadToEndOfLine work.
Lex.setParsingPreprocessorDirective(true);
Lex.ReadToEndOfLine(&Line);
- SourceLocation EndLoc = D->getLocEnd().getLocWithOffset(Line.size());
+ SourceLocation EndLoc = EndExpansionLoc.getLocWithOffset(Line.size());
// If we already reach EOF, just return the EOF SourceLocation;
// otherwise, move 1 offset ahead to include the trailing newline character
// '\n'.
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
@@ -386,6 +386,24 @@
EXPECT_EQ(ExpectedNewCode, Results[Spec.NewCC]);
}
+TEST(ClangMove, DefinitionInMacro) {
+ const char TestHeader[] = "#define DEF(CLASS) void CLASS##_::f() {}\n"
+ "class A_ {\nvoid f();\n};\n"
+ "class B {};\n";
+ const char TestCode[] = "#include \"foo.h\"\n"
+ "DEF(A)\n";
+ const char ExpectedNewCode[] = "#include \"new_foo.h\"\n\n"
+ "DEF(A)\n";
+ move::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]);
+}
+
TEST(ClangMove, WellFormattedCode) {
const std::string CommonHeader =
"namespace a {\n"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27713.81234.patch
Type: text/x-patch
Size: 2418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161213/7973143c/attachment.bin>
More information about the cfe-commits
mailing list