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

Richard Smith richard at metafoo.co.uk
Thu Aug 21 11:33:01 PDT 2014


Can you include both an EOD test and an EOF test? Otherwise, LGTM.


On Thu, Aug 21, 2014 at 12:10 AM, David Majnemer <david.majnemer at gmail.com>
wrote:

> Ping.
>
>
> On Fri, Aug 15, 2014 at 6:59 PM, David Majnemer <david.majnemer at gmail.com>
> wrote:
>
>> 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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140821/256727e5/attachment.html>


More information about the cfe-commits mailing list