summaryrefslogtreecommitdiff
path: root/unittests/Lex/LexerTest.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-07-23 20:44:14 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-07-23 20:44:14 +0000
commit2b6b257f4e5503a7a2675bdb8735693db769f75c (patch)
treee85e046ae7003fe3bcc8b5454cd0fa3f7407b470 /unittests/Lex/LexerTest.cpp
parentb4348ed0b7e90c0831b925fbee00b5f179a99796 (diff)
Notes
Diffstat (limited to 'unittests/Lex/LexerTest.cpp')
-rw-r--r--unittests/Lex/LexerTest.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/unittests/Lex/LexerTest.cpp b/unittests/Lex/LexerTest.cpp
index 42f8eb5a5c7f8..204601818152a 100644
--- a/unittests/Lex/LexerTest.cpp
+++ b/unittests/Lex/LexerTest.cpp
@@ -22,7 +22,6 @@
#include "clang/Lex/PreprocessorOptions.h"
#include "gtest/gtest.h"
-using namespace llvm;
using namespace clang;
namespace {
@@ -59,9 +58,9 @@ protected:
Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
}
- std::vector<Token> CheckLex(StringRef Source,
- ArrayRef<tok::TokenKind> ExpectedTokens) {
- std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Source);
+ std::vector<Token> Lex(StringRef Source) {
+ std::unique_ptr<llvm::MemoryBuffer> Buf =
+ llvm::MemoryBuffer::getMemBuffer(Source);
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
VoidModuleLoader ModLoader;
@@ -82,6 +81,12 @@ protected:
toks.push_back(tok);
}
+ return toks;
+ }
+
+ std::vector<Token> CheckLex(StringRef Source,
+ ArrayRef<tok::TokenKind> ExpectedTokens) {
+ auto toks = Lex(Source);
EXPECT_EQ(ExpectedTokens.size(), toks.size());
for (unsigned i = 0, e = ExpectedTokens.size(); i != e; ++i) {
EXPECT_EQ(ExpectedTokens[i], toks[i].getKind());
@@ -358,4 +363,21 @@ TEST_F(LexerTest, LexAPI) {
EXPECT_EQ("N", Lexer::getImmediateMacroName(idLoc4, SourceMgr, LangOpts));
}
+TEST_F(LexerTest, DontMergeMacroArgsFromDifferentMacroFiles) {
+ std::vector<Token> toks =
+ Lex("#define helper1 0\n"
+ "void helper2(const char *, ...);\n"
+ "#define M1(a, ...) helper2(a, ##__VA_ARGS__)\n"
+ "#define M2(a, ...) M1(a, helper1, ##__VA_ARGS__)\n"
+ "void f1() { M2(\"a\", \"b\"); }");
+
+ // Check the file corresponding to the "helper1" macro arg in M2.
+ //
+ // The lexer used to report its size as 31, meaning that the end of the
+ // expansion would be on the *next line* (just past `M2("a", "b")`). Make
+ // sure that we get the correct end location (the comma after "helper1").
+ SourceLocation helper1ArgLoc = toks[20].getLocation();
+ EXPECT_EQ(SourceMgr.getFileIDSize(SourceMgr.getFileID(helper1ArgLoc)), 8U);
+}
+
} // anonymous namespace