summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-21 23:28:41 +0000
committerChris Lattner <sabre@nondot.org>2009-04-21 23:28:41 +0000
commitca515ccb49dda9f09fe714fb336ec5119cd10851 (patch)
tree8c183723ce20c56324e20d550ba1038b46f6c42b /clang
parentc8e236278e60cee9a612d5a5c49625661025223b (diff)
downloadbcm5719-llvm-ca515ccb49dda9f09fe714fb336ec5119cd10851.tar.gz
bcm5719-llvm-ca515ccb49dda9f09fe714fb336ec5119cd10851.zip
apply Eli's patch to fix PR4008, with a testcase. Thanks Eli!
llvm-svn: 69750
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Lex/TokenConcatenation.cpp8
-rw-r--r--clang/test/Preprocessor/output_paste_avoid.c19
2 files changed, 20 insertions, 7 deletions
diff --git a/clang/lib/Lex/TokenConcatenation.cpp b/clang/lib/Lex/TokenConcatenation.cpp
index 92edca7be43..15637996b41 100644
--- a/clang/lib/Lex/TokenConcatenation.cpp
+++ b/clang/lib/Lex/TokenConcatenation.cpp
@@ -126,6 +126,14 @@ static char GetFirstChar(Preprocessor &PP, const Token &Tok) {
/// don't want to track enough to tell "x.." from "...".
bool TokenConcatenation::AvoidConcat(const Token &PrevTok,
const Token &Tok) const {
+ // First, check to see if the tokens were directly adjacent in the original
+ // source. If they were, it must be okay to stick them together: if there
+ // were an issue, the tokens would have been lexed differently.
+ if (PrevTok.getLocation().isFileID() && Tok.getLocation().isFileID() &&
+ PrevTok.getLocation().getFileLocWithOffset(PrevTok.getLength()) ==
+ Tok.getLocation())
+ return false;
+
tok::TokenKind PrevKind = PrevTok.getKind();
if (PrevTok.getIdentifierInfo()) // Language keyword or named operator.
PrevKind = tok::identifier;
diff --git a/clang/test/Preprocessor/output_paste_avoid.c b/clang/test/Preprocessor/output_paste_avoid.c
index b23d22a7963..ff8afc3e47a 100644
--- a/clang/test/Preprocessor/output_paste_avoid.c
+++ b/clang/test/Preprocessor/output_paste_avoid.c
@@ -1,18 +1,23 @@
-// RUN: clang-cc -E %s | grep '+ + - - + + = = =' &&
-// RUN: clang-cc -E %s | not grep -F '...' &&
-// RUN: clang-cc -E %s | not grep -F 'L"str"'
-
+// RUN: clang-cc -E %s -o %t &&
// This should print as ".. ." to avoid turning into ...
+// RUN: grep -F 'A: . . .' %t &&
#define y(a) ..a
-y(.)
+A: y(.)
+
+// RUN: grep -F 'C: .. .' %t &&
+#define DOT .
+C: ..DOT
+
+// RUN: grep -F 'D: + + - - + + = = =' %t &&
#define PLUS +
#define EMPTY
#define f(x) =x=
-+PLUS -EMPTY- PLUS+ f(=)
+D: +PLUS -EMPTY- PLUS+ f(=)
+// RUN: grep -F 'E: L "str"' %t
// Should expand to L "str" not L"str"
#define test(x) L#x
-test(str)
+E: test(str)
OpenPOWER on IntegriCloud