r196961 - Parse: Avoid crashing on unterminated top-level asm strings

Justin Bogner mail at justinbogner.com
Tue Dec 10 13:29:48 PST 2013


Author: bogner
Date: Tue Dec 10 15:29:48 2013
New Revision: 196961

URL: http://llvm.org/viewvc/llvm-project?rev=196961&view=rev
Log:
Parse: Avoid crashing on unterminated top-level asm strings

When parsing invalid top-level asm statements, we were ignoring the
return code of the SkipUntil we used for recovery. This led to crashes
when we hit the end of file and tried to continue parsing anyway.

This fixes the crash and adds a couple of tests for parsing related
problems.

Modified:
    cfe/trunk/lib/Parse/Parser.cpp
    cfe/trunk/test/Parser/asm.c

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=196961&r1=196960&r2=196961&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Tue Dec 10 15:29:48 2013
@@ -1354,16 +1354,15 @@ Parser::ExprResult Parser::ParseSimpleAs
 
   ExprResult Result(ParseAsmStringLiteral());
 
-  if (Result.isInvalid()) {
-    SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
-    if (EndLoc)
-      *EndLoc = Tok.getLocation();
-    ConsumeAnyToken();
-  } else {
+  if (!Result.isInvalid()) {
     // Close the paren and get the location of the end bracket
     T.consumeClose();
     if (EndLoc)
       *EndLoc = T.getCloseLocation();
+  } else if (SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch)) {
+    if (EndLoc)
+      *EndLoc = Tok.getLocation();
+    ConsumeParen();
   }
 
   return Result;

Modified: cfe/trunk/test/Parser/asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/asm.c?rev=196961&r1=196960&r2=196961&view=diff
==============================================================================
--- cfe/trunk/test/Parser/asm.c (original)
+++ cfe/trunk/test/Parser/asm.c Tue Dec 10 15:29:48 2013
@@ -23,3 +23,16 @@ __asm ; // expected-error {{expected '('
 // <rdar://problem/10465079> - Don't crash on wide string literals in 'asm'.
 int foo asm (L"bar"); // expected-error {{cannot use wide string literal in 'asm'}}
 
+asm() // expected-error {{expected string literal in 'asm'}}
+// expected-error at -1 {{expected ';' after top-level asm block}}
+
+asm(; // expected-error {{expected string literal in 'asm'}}
+
+asm("") // expected-error {{expected ';' after top-level asm block}}
+
+// Unterminated asm strings at the end of the file were causing us to crash, so
+// this needs to be last. rdar://15624081
+// expected-warning at +3 {{missing terminating '"' character}}
+// expected-error at +2 {{expected string literal in 'asm'}}
+// expected-error at +1 {{expected ';' after top-level asm block}}
+asm("





More information about the cfe-commits mailing list