[PATCH] Lex: Don't try to recover as hard in malformed _Pragma

David Majnemer david.majnemer at gmail.com
Fri Aug 15 18:59:09 PDT 2014


Hi rsmith,

It's not particularly safe to lex a token if you don't know what it is.
_Pragma error recovery attempted to lex tokens without being sure what
they might be.

http://reviews.llvm.org/D4939

Files:
  lib/Lex/Pragma.cpp
  test/Preprocessor/_Pragma.c

Index: lib/Lex/Pragma.cpp
===================================================================
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -192,9 +192,7 @@
   Lex(Tok);
   if (!tok::isStringLiteral(Tok.getKind())) {
     Diag(PragmaLoc, diag::err__Pragma_malformed);
-    // Skip this token, and the ')', if present.
-    if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof))
-      Lex(Tok);
+    // Skip this token if it's a ')'.
     if (Tok.is(tok::r_paren))
       Lex(Tok);
     return _PragmaLexing.failed();
Index: test/Preprocessor/_Pragma.c
===================================================================
--- test/Preprocessor/_Pragma.c
+++ test/Preprocessor/_Pragma.c
@@ -12,4 +12,6 @@
 #error #define invalid
 #endif
 
-_Pragma( // expected-error{{_Pragma takes a parenthesized string literal}}
+// expected-error at +2{{unterminated conditional directive}}
+// expected-error at +1{{expected value in expression}}
+#if _Pragma( // expected-error{{_Pragma takes a parenthesized string literal}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4939.12577.patch
Type: text/x-patch
Size: 1007 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140816/49a563ad/attachment.bin>


More information about the cfe-commits mailing list