As discussed in " [PATCH] PR14795 : -frewrite-includes sometimes results in incorrect line number", the following leads to a crash:
$ echo -ne '#if 0\n#endif' >a.cpp $ clang++ -frewrite-includes -E a.cpp The attached patch adds a trivial fix avoiding the problem. I'm not quite sure why the problem happens, but presumably it has something to do with the lexing not being driven by the preprocessor instance (so maybe that one gets deleted when reaching EOF?). -- Lubos Lunak
From 2a79412f4c07af65cc5ff6f187e15da46173e7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= <[email protected]> Date: Wed, 27 Nov 2013 18:34:05 +0100 Subject: [PATCH] fix Lexer::LexEndOfFile() crash with -frewrite-includes --- lib/Lex/Lexer.cpp | 3 ++- test/Frontend/rewrite-includes-eof.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/Frontend/rewrite-includes-eof.c diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index c071455..009f18a 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -2460,7 +2460,8 @@ bool Lexer::LexEndOfFile(Token &Result, const char *CurPtr) { 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. } diff --git a/test/Frontend/rewrite-includes-eof.c b/test/Frontend/rewrite-includes-eof.c new file mode 100644 index 0000000..d8ec4e9 --- /dev/null +++ b/test/Frontend/rewrite-includes-eof.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -verify -Wall -E -frewrite-includes %s +// expected-no-diagnostics + +#if 0 +// intentionally no \n at the end of this line +#endif \ No newline at end of file -- 1.8.1.4
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
