[cfe-commits] r56818 - in /cfe/trunk/lib/Lex: LiteralSupport.cpp PPMacroExpansion.cpp
Chris Lattner
sabre at nondot.org
Mon Sep 29 16:12:31 PDT 2008
Author: lattner
Date: Mon Sep 29 18:12:31 2008
New Revision: 56818
URL: http://llvm.org/viewvc/llvm-project?rev=56818&view=rev
Log:
Fix the root cause of PR2750 instead of the side effect.
NumericLiteral parser is not careful about overrun because
it should never be possible. It implicitly expects that its
input matched the regex for pp-constant. Because of this, it
knows it can't be pointing to a prefix of something that
looks like a number. This is all fine, except that __LINE__
does not prevent implicit concatenation from happening. Fix
__LINE__ to not do this.
Modified:
cfe/trunk/lib/Lex/LiteralSupport.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=56818&r1=56817&r2=56818&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Mon Sep 29 18:12:31 2008
@@ -224,7 +224,7 @@
saw_period = true;
s = SkipDigits(s);
}
- if (s != ThisTokEnd && (*s == 'e' || *s == 'E')) { // exponent
+ if ((*s == 'e' || *s == 'E')) { // exponent
const char *Exponent = s;
s++;
saw_exponent = true;
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=56818&r1=56817&r2=56818&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Mon Sep 29 18:12:31 2008
@@ -445,12 +445,15 @@
Tok.clearFlag(Token::NeedsCleaning);
if (II == Ident__LINE__) {
- // __LINE__ expands to a simple numeric value.
- sprintf(TmpBuffer, "%u", SourceMgr.getLogicalLineNumber(Tok.getLocation()));
- unsigned Length = strlen(TmpBuffer);
+ // __LINE__ expands to a simple numeric value. Add a space after it so that
+ // it will tokenize as a number (and not run into stuff after it in the temp
+ // buffer).
+ sprintf(TmpBuffer, "%u ",
+ SourceMgr.getLogicalLineNumber(Tok.getLocation()));
+ unsigned Length = strlen(TmpBuffer)-1;
Tok.setKind(tok::numeric_constant);
Tok.setLength(Length);
- Tok.setLocation(CreateString(TmpBuffer, Length, Tok.getLocation()));
+ Tok.setLocation(CreateString(TmpBuffer, Length+1, Tok.getLocation()));
} else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
SourceLocation Loc = Tok.getLocation();
if (II == Ident__BASE_FILE__) {
@@ -489,9 +492,11 @@
for (; Loc.isValid(); ++Depth)
Loc = SourceMgr.getIncludeLoc(Loc);
- // __INCLUDE_LEVEL__ expands to a simple numeric value.
- sprintf(TmpBuffer, "%u", Depth);
- unsigned Length = strlen(TmpBuffer);
+ // __INCLUDE_LEVEL__ expands to a simple numeric value. Add a space after
+ // it so that it will tokenize as a number (and not run into stuff after it
+ // in the temp buffer).
+ sprintf(TmpBuffer, "%u ", Depth);
+ unsigned Length = strlen(TmpBuffer)-1;
Tok.setKind(tok::numeric_constant);
Tok.setLength(Length);
Tok.setLocation(CreateString(TmpBuffer, Length, Tok.getLocation()));
@@ -523,7 +528,7 @@
TmpBuffer[Len-1] = '"'; // Replace the newline with a quote.
Tok.setKind(tok::string_literal);
Tok.setLength(Len);
- Tok.setLocation(CreateString(TmpBuffer, Len, Tok.getLocation()));
+ Tok.setLocation(CreateString(TmpBuffer, Len+1, Tok.getLocation()));
} else {
assert(0 && "Unknown identifier!");
}
More information about the cfe-commits
mailing list