r173826 - [Preprocessor] When checking if we can concatenate two tokens, check
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Jan 29 12:28:24 PST 2013
Author: akirtzidis
Date: Tue Jan 29 14:28:24 2013
New Revision: 173826
URL: http://llvm.org/viewvc/llvm-project?rev=173826&view=rev
Log:
[Preprocessor] When checking if we can concatenate two tokens, check
if they were already concatenated in source using the spelling locations
even if they came from a macro expansion.
This fixes an issue where a GUID passed as macro argument ends up
malformed after preprocessing because we added spaces inside it.
rdar://13016645
Modified:
cfe/trunk/lib/Lex/TokenConcatenation.cpp
cfe/trunk/test/Preprocessor/output_paste_avoid.c
Modified: cfe/trunk/lib/Lex/TokenConcatenation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenConcatenation.cpp?rev=173826&r1=173825&r2=173826&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenConcatenation.cpp (original)
+++ cfe/trunk/lib/Lex/TokenConcatenation.cpp Tue Jan 29 14:28:24 2013
@@ -156,9 +156,10 @@ bool TokenConcatenation::AvoidConcat(con
// 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().getLocWithOffset(PrevTok.getLength()) ==
- Tok.getLocation())
+ SourceManager &SM = PP.getSourceManager();
+ SourceLocation PrevSpellLoc = SM.getSpellingLoc(PrevTok.getLocation());
+ SourceLocation SpellLoc = SM.getSpellingLoc(Tok.getLocation());
+ if (PrevSpellLoc.getLocWithOffset(PrevTok.getLength()) == SpellLoc)
return false;
tok::TokenKind PrevKind = PrevTok.getKind();
Modified: cfe/trunk/test/Preprocessor/output_paste_avoid.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/output_paste_avoid.c?rev=173826&r1=173825&r2=173826&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/output_paste_avoid.c (original)
+++ cfe/trunk/test/Preprocessor/output_paste_avoid.c Tue Jan 29 14:28:24 2013
@@ -31,3 +31,9 @@ E: test(str)
#define equal =
F: >>equal
// CHECK: F: >> =
+
+// Make sure we don't introduce spaces in the guid because we try to avoid
+// pasting '-' to a numeric constant.
+#define TYPEDEF(guid) typedef [uuid(guid)]
+TYPEDEF(66504301-BE0F-101A-8BBB-00AA00300CAB) long OLE_COLOR;
+// CHECK: typedef [uuid(66504301-BE0F-101A-8BBB-00AA00300CAB)] long OLE_COLOR;
More information about the cfe-commits
mailing list