r197245 - Fix raw lex crash and -frewrite-includes noeol-at-eof failure
Alp Toker
alp at nuanti.com
Fri Dec 13 09:04:56 PST 2013
Author: alp
Date: Fri Dec 13 11:04:55 2013
New Revision: 197245
URL: http://llvm.org/viewvc/llvm-project?rev=197245&view=rev
Log:
Fix raw lex crash and -frewrite-includes noeol-at-eof failure
Raw lexers don't have a preprocessor so we need to null check.
Added:
cfe/trunk/test/Frontend/rewrite-includes-eof.c
Modified:
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=197245&r1=197244&r2=197245&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Fri Dec 13 11:04:55 2013
@@ -2460,7 +2460,8 @@ bool Lexer::LexEndOfFile(Token &Result,
FormTokenWithChars(Result, CurPtr, tok::eod);
// Restore comment saving mode, in case it was disabled for directive.
- resetExtendedTokenMode();
+ if (PP)
+ resetExtendedTokenMode();
return true; // Have a token.
}
Modified: cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp?rev=197245&r1=197244&r2=197245&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp Fri Dec 13 11:04:55 2013
@@ -77,7 +77,7 @@ private:
void OutputContentUpTo(const MemoryBuffer &FromFile,
unsigned &WriteFrom, unsigned WriteTo,
StringRef EOL, int &lines,
- bool EnsureNewline = false);
+ bool EnsureNewline);
void CommentOutDirective(Lexer &DirectivesLex, const Token &StartToken,
const MemoryBuffer &FromFile, StringRef EOL,
unsigned &NextToWrite, int &Lines);
@@ -250,7 +250,7 @@ void InclusionRewriter::CommentOutDirect
StringRef EOL,
unsigned &NextToWrite, int &Line) {
OutputContentUpTo(FromFile, NextToWrite,
- SM.getFileOffset(StartToken.getLocation()), EOL, Line);
+ SM.getFileOffset(StartToken.getLocation()), EOL, Line, false);
Token DirectiveToken;
do {
DirectiveLex.LexFromRawLexer(DirectiveToken);
@@ -258,7 +258,7 @@ void InclusionRewriter::CommentOutDirect
OS << "#if 0 /* expanded by -frewrite-includes */" << EOL;
OutputContentUpTo(FromFile, NextToWrite,
SM.getFileOffset(DirectiveToken.getLocation()) + DirectiveToken.getLength(),
- EOL, Line);
+ EOL, Line, true);
OS << "#endif /* expanded by -frewrite-includes */" << EOL;
}
@@ -462,12 +462,12 @@ bool InclusionRewriter::Process(FileID F
// Replace the macro with (0) or (1), followed by the commented
// out macro for reference.
OutputContentUpTo(FromFile, NextToWrite, SM.getFileOffset(Loc),
- EOL, Line);
+ EOL, Line, false);
OS << '(' << (int) HasFile << ")/*";
OutputContentUpTo(FromFile, NextToWrite,
SM.getFileOffset(RawToken.getLocation()) +
RawToken.getLength(),
- EOL, Line);
+ EOL, Line, false);
OS << "*/";
}
} while (RawToken.isNot(tok::eod));
Added: cfe/trunk/test/Frontend/rewrite-includes-eof.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/rewrite-includes-eof.c?rev=197245&view=auto
==============================================================================
--- cfe/trunk/test/Frontend/rewrite-includes-eof.c (added)
+++ cfe/trunk/test/Frontend/rewrite-includes-eof.c Fri Dec 13 11:04:55 2013
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -E -frewrite-includes -I %S/Inputs %s
+// expected-no-diagnostics
+// Note: there's no newline at the end of this C file.
+#include "rewrite-includes-bom.h"
\ No newline at end of file
More information about the cfe-commits
mailing list