r230449 - Don't crash on missing '{' after __except or __finally, PR22687.

Nico Weber nicolasweber at gmx.de
Tue Feb 24 18:22:07 PST 2015


Author: nico
Date: Tue Feb 24 20:22:06 2015
New Revision: 230449

URL: http://llvm.org/viewvc/llvm-project?rev=230449&view=rev
Log:
Don't crash on missing '{' after __except or __finally, PR22687.

Also add some general test/Parser coverage for SEH blocks.

Added:
    cfe/trunk/test/Parser/ms-seh.c
Modified:
    cfe/trunk/lib/Parse/ParseStmt.cpp

Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=230449&r1=230448&r2=230449&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Tue Feb 24 20:22:06 2015
@@ -421,7 +421,7 @@ StmtResult Parser::ParseSEHTryBlock() {
   assert(Tok.is(tok::kw___try) && "Expected '__try'");
   SourceLocation TryLoc = ConsumeToken();
 
-  if(Tok.isNot(tok::l_brace))
+  if (Tok.isNot(tok::l_brace))
     return StmtError(Diag(Tok, diag::err_expected) << tok::l_brace);
 
   StmtResult TryBlock(ParseCompoundStatement(/*isStmtExpr=*/false,
@@ -438,7 +438,7 @@ StmtResult Parser::ParseSEHTryBlock() {
     SourceLocation Loc = ConsumeToken();
     Handler = ParseSEHFinallyBlock(Loc);
   } else {
-    return StmtError(Diag(Tok,diag::err_seh_expected_handler));
+    return StmtError(Diag(Tok, diag::err_seh_expected_handler));
   }
 
   if(Handler.isInvalid())
@@ -491,6 +491,9 @@ StmtResult Parser::ParseSEHExceptBlock(S
   if (ExpectAndConsume(tok::r_paren))
     return StmtError();
 
+  if (Tok.isNot(tok::l_brace))
+    return StmtError(Diag(Tok, diag::err_expected) << tok::l_brace);
+
   StmtResult Block(ParseCompoundStatement());
 
   if(Block.isInvalid())
@@ -509,6 +512,9 @@ StmtResult Parser::ParseSEHFinallyBlock(
     raii2(Ident___abnormal_termination, false),
     raii3(Ident_AbnormalTermination, false);
 
+  if (Tok.isNot(tok::l_brace))
+    return StmtError(Diag(Tok, diag::err_expected) << tok::l_brace);
+
   StmtResult Block(ParseCompoundStatement());
   if(Block.isInvalid())
     return Block;

Added: cfe/trunk/test/Parser/ms-seh.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/ms-seh.c?rev=230449&view=auto
==============================================================================
--- cfe/trunk/test/Parser/ms-seh.c (added)
+++ cfe/trunk/test/Parser/ms-seh.c Tue Feb 24 20:22:06 2015
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
+
+void f() {
+  int a;
+
+  __try a; // expected-error {{expected '{'}} expected-warning {{expression result unused}}
+
+  __try {
+  }
+} // expected-error {{expected '__except' or '__finally' block}}
+
+void g() {
+  int a;
+
+  __try {
+  } __except(1) a; // expected-error {{expected '{'}} expected-warning {{expression result unused}}
+}
+
+void h() {
+  int a;
+
+  __try {
+  } __finally a; // expected-error {{expected '{'}} expected-warning {{expression result unused}}
+}





More information about the cfe-commits mailing list