[clang-tools-extra] r289541 - [clang-move] Fix incorrect EndLoc for declarations in macros.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 13 07:35:47 PST 2016
Author: hokein
Date: Tue Dec 13 09:35:47 2016
New Revision: 289541
URL: http://llvm.org/viewvc/llvm-project?rev=289541&view=rev
Log:
[clang-move] Fix incorrect EndLoc for declarations in macros.
Reviewers: ioeric
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D27713
Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=289541&r1=289540&r2=289541&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Tue Dec 13 09:35:47 2016
@@ -219,7 +219,8 @@ SourceLocation
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 @@ getLocForEndOfDecl(const clang::Decl *D,
// 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'.
Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=289541&r1=289540&r2=289541&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Tue Dec 13 09:35:47 2016
@@ -386,6 +386,24 @@ TEST(ClangMove, MacroInFunction) {
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"
More information about the cfe-commits
mailing list