r215672 - Don't Lex past EOF when lexing _Pragma

Reid Kleckner reid at kleckner.net
Thu Aug 14 12:47:06 PDT 2014


Author: rnk
Date: Thu Aug 14 14:47:06 2014
New Revision: 215672

URL: http://llvm.org/viewvc/llvm-project?rev=215672&view=rev
Log:
Don't Lex past EOF when lexing _Pragma

Fixes PR20662.

Modified:
    cfe/trunk/lib/Lex/Pragma.cpp
    cfe/trunk/test/Preprocessor/_Pragma.c

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=215672&r1=215671&r2=215672&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Thu Aug 14 14:47:06 2014
@@ -193,7 +193,7 @@ void Preprocessor::Handle_Pragma(Token &
   if (!tok::isStringLiteral(Tok.getKind())) {
     Diag(PragmaLoc, diag::err__Pragma_malformed);
     // Skip this token, and the ')', if present.
-    if (Tok.isNot(tok::r_paren))
+    if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof))
       Lex(Tok);
     if (Tok.is(tok::r_paren))
       Lex(Tok);

Modified: cfe/trunk/test/Preprocessor/_Pragma.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/_Pragma.c?rev=215672&r1=215671&r2=215672&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/_Pragma.c (original)
+++ cfe/trunk/test/Preprocessor/_Pragma.c Thu Aug 14 14:47:06 2014
@@ -11,3 +11,5 @@ _Pragma("message(\"foo \\\\\\\\ bar\")")
 #ifdef macro
 #error #define invalid
 #endif
+
+_Pragma( // expected-error{{_Pragma takes a parenthesized string literal}}





More information about the cfe-commits mailing list