[cfe-commits] r67816 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Parse/ParseDecl.cpp lib/Parse/ParseExpr.cpp lib/Parse/ParseTentative.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/Sema/exprs.c

Chris Lattner sabre at nondot.org
Thu Mar 26 21:18:07 PDT 2009


Author: lattner
Date: Thu Mar 26 23:18:06 2009
New Revision: 67816

URL: http://llvm.org/viewvc/llvm-project?rev=67816&view=rev
Log:
Fix rdar://6719156 - clang should emit a better error when blocks are disabled but are used anyway
by changing blocks from being disabled in the parser to being disabled
in Sema.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/lib/Parse/ParseTentative.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/Sema/exprs.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=67816&r1=67815&r2=67816&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Mar 26 23:18:06 2009
@@ -1394,6 +1394,8 @@
 
 
 // Blocks
+def err_blocks_disable : Error<"blocks support disabled - compile with -fblocks"
+  " or pick a deployment target that supports them">;
 def err_expected_block_lbrace : Error<"expected '{' in block literal">;
 def err_goto_in_block : Error<
   "goto not allowed in block literal">;

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=67816&r1=67815&r2=67816&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Mar 26 23:18:06 2009
@@ -1682,11 +1682,10 @@
 
   tok::TokenKind Kind = Tok.getKind();
   // Not a pointer, C++ reference, or block.
-  if (Kind != tok::star &&
+  if (Kind != tok::star && Kind != tok::caret &&
       (Kind != tok::amp || !getLang().CPlusPlus) &&
       // We parse rvalue refs in C++03, because otherwise the errors are scary.
-      (Kind != tok::ampamp || !getLang().CPlusPlus) &&
-      (Kind != tok::caret || !getLang().Blocks)) {
+      (Kind != tok::ampamp || !getLang().CPlusPlus)) {
     if (DirectDeclParser)
       (this->*DirectDeclParser)(D);
     return;
@@ -1697,7 +1696,7 @@
   SourceLocation Loc = ConsumeToken();  // Eat the *, ^, & or &&.
   D.SetRangeEnd(Loc);
 
-  if (Kind == tok::star || (Kind == tok::caret && getLang().Blocks)) {
+  if (Kind == tok::star || Kind == tok::caret) {
     // Is a pointer.
     DeclSpec DS;
 

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=67816&r1=67815&r2=67816&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Thu Mar 26 23:18:06 2009
@@ -776,10 +776,7 @@
     return ParseObjCAtExpression(AtLoc);
   }
   case tok::caret:
-    if (getLang().Blocks)
-      return ParsePostfixExpressionSuffix(ParseBlockLiteralExpression());
-    Diag(Tok, diag::err_expected_expression);
-    return ExprError();
+    return ParsePostfixExpressionSuffix(ParseBlockLiteralExpression());
   case tok::l_square:
     // These can be followed by postfix-expr pieces.
     if (getLang().ObjC1)
@@ -1344,18 +1341,17 @@
 
 
   OwningExprResult Result(Actions, true);
-  if (Tok.is(tok::l_brace)) {
-    OwningStmtResult Stmt(ParseCompoundStatementBody());
-    if (!Stmt.isInvalid()) {
-      Result = Actions.ActOnBlockStmtExpr(CaretLoc, move(Stmt), CurScope);
-    } else {
-      Actions.ActOnBlockError(CaretLoc, CurScope);
-    }
-  } else {
+  if (!Tok.is(tok::l_brace)) {
     // Saw something like: ^expr
     Diag(Tok, diag::err_expected_expression);
     return ExprError();
   }
+  
+  OwningStmtResult Stmt(ParseCompoundStatementBody());
+  if (!Stmt.isInvalid())
+    Result = Actions.ActOnBlockStmtExpr(CaretLoc, move(Stmt), CurScope);
+  else
+    Actions.ActOnBlockError(CaretLoc, CurScope);
   return move(Result);
 }
 

Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=67816&r1=67815&r2=67816&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Thu Mar 26 23:18:06 2009
@@ -405,14 +405,13 @@
     if (Tok.is(tok::coloncolon) || Tok.is(tok::identifier))
       TryAnnotateCXXScopeToken();
 
-    if (Tok.is(tok::star) || Tok.is(tok::amp) ||
-        (Tok.is(tok::caret) && getLang().Blocks) ||
+    if (Tok.is(tok::star) || Tok.is(tok::amp) || Tok.is(tok::caret) ||
         (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::star))) {
       // ptr-operator
       ConsumeToken();
       while (Tok.is(tok::kw_const)    ||
              Tok.is(tok::kw_volatile) ||
-             Tok.is(tok::kw_restrict)   )
+             Tok.is(tok::kw_restrict))
         ConsumeToken();
     } else {
       break;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=67816&r1=67815&r2=67816&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Mar 26 23:18:06 2009
@@ -4589,6 +4589,10 @@
 /// literal was successfully completed.  ^(int x){...}
 Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc,
                                                 StmtArg body, Scope *CurScope) {
+  // If blocks are disabled, emit an error.
+  if (!LangOpts.Blocks)
+    Diag(CaretLoc, diag::err_blocks_disable);
+  
   // Ensure that CurBlock is deleted.
   llvm::OwningPtr<BlockSemaInfo> BSI(CurBlock);
 

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=67816&r1=67815&r2=67816&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Mar 26 23:18:06 2009
@@ -625,6 +625,10 @@
     switch (DeclType.Kind) {
     default: assert(0 && "Unknown decltype!");
     case DeclaratorChunk::BlockPointer:
+      // If blocks are disabled, emit an error.
+      if (!LangOpts.Blocks)
+        Diag(DeclType.Loc, diag::err_blocks_disable);
+        
       if (DeclType.Cls.TypeQuals)
         Diag(D.getIdentifierLoc(), diag::err_qualified_block_pointer_type);
       if (!T.getTypePtr()->isFunctionType())

Modified: cfe/trunk/test/Sema/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/exprs.c?rev=67816&r1=67815&r2=67816&view=diff

==============================================================================
--- cfe/trunk/test/Sema/exprs.c (original)
+++ cfe/trunk/test/Sema/exprs.c Thu Mar 26 23:18:06 2009
@@ -1,4 +1,4 @@
-// RUN: clang-cc %s -verify -pedantic -fsyntax-only
+// RUN: clang-cc %s -verify -pedantic -fsyntax-only -fno-blocks
 
 // PR1966
 _Complex double test1() {
@@ -85,3 +85,9 @@
   return X == "foo";  // expected-warning {{comparison against a string literal is unspecified}}
 }
 
+// rdar://6719156
+void test13(
+            void (^P)()) { // expected-error {{blocks support disabled - compile with -fblocks}}
+  P();
+  P = ^(){}; // expected-error {{blocks support disabled - compile with -fblocks}}
+}





More information about the cfe-commits mailing list