summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Lex/LexerTest.cpp
diff options
context:
space:
mode:
authorArtem Dergachev <artem.dergachev@gmail.com>2019-04-05 21:48:52 +0000
committerArtem Dergachev <artem.dergachev@gmail.com>2019-04-05 21:48:52 +0000
commit1dfd74ac4a16a9b18b1c34ec427f5545e1645c13 (patch)
treea03b07200c0edeaf88dcd603f9af27c5f1c8d7e9 /clang/unittests/Lex/LexerTest.cpp
parentc76b6215302f42c1ebdc5dfff3a875403f6abb67 (diff)
downloadbcm5719-llvm-1dfd74ac4a16a9b18b1c34ec427f5545e1645c13.tar.gz
bcm5719-llvm-1dfd74ac4a16a9b18b1c34ec427f5545e1645c13.zip
[Lexer] NFC: Fix an off-by-one bug in getAsCharRange().
As the unit test demonstrates, subtracting 1 from the offset was unnecessary. The only user of this function was the plist file emitter (in Static Analyzer and ARCMigrator). It means that a lot of Static Analyzer's plist arrows are in fact off by one character. The patch carefully preserves this completely incorrect behavior and causes no functional change, i.e. no plist format breakage. Differential Revision: https://reviews.llvm.org/D59977 llvm-svn: 357823
Diffstat (limited to 'clang/unittests/Lex/LexerTest.cpp')
-rw-r--r--clang/unittests/Lex/LexerTest.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang/unittests/Lex/LexerTest.cpp
index 320b60ea639..7b14f56201e 100644
--- a/clang/unittests/Lex/LexerTest.cpp
+++ b/clang/unittests/Lex/LexerTest.cpp
@@ -513,4 +513,23 @@ TEST_F(LexerTest, StringizingRasString) {
EXPECT_EQ(String6, R"(a\\\n\n\n \\\\b)");
}
+TEST_F(LexerTest, CharRangeOffByOne) {
+ std::vector<Token> toks = Lex(R"(#define MOO 1
+ void foo() { MOO; })");
+ const Token &moo = toks[5];
+
+ EXPECT_EQ(getSourceText(moo, moo), "MOO");
+
+ SourceRange R{moo.getLocation(), moo.getLocation()};
+
+ EXPECT_TRUE(
+ Lexer::isAtStartOfMacroExpansion(R.getBegin(), SourceMgr, LangOpts));
+ EXPECT_TRUE(
+ Lexer::isAtEndOfMacroExpansion(R.getEnd(), SourceMgr, LangOpts));
+
+ CharSourceRange CR = Lexer::getAsCharRange(R, SourceMgr, LangOpts);
+
+ EXPECT_EQ(Lexer::getSourceText(CR, SourceMgr, LangOpts), "MOO"); // Was "MO".
+}
+
} // anonymous namespace
OpenPOWER on IntegriCloud