[cfe-commits] r93945 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp lib/Sema/SemaStmt.cpp test/Sema/block-literal.c test/Sema/block-misc.c test/Sema/scope-check.c

Mike Stump mrs at apple.com
Tue Jan 19 15:08:02 PST 2010


Author: mrs
Date: Tue Jan 19 17:08:01 2010
New Revision: 93945

URL: http://llvm.org/viewvc/llvm-project?rev=93945&view=rev
Log:
Implement goto inside of blocks.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/Sema/block-literal.c
    cfe/trunk/test/Sema/block-misc.c
    cfe/trunk/test/Sema/scope-check.c

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jan 19 17:08:01 2010
@@ -2458,8 +2458,6 @@
 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">;
 def err_return_in_block_expression : Error<
   "return not allowed in block expression literal">;
 def err_block_returns_array : Error<

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jan 19 17:08:01 2010
@@ -6884,6 +6884,26 @@
   CurFunctionNeedsScopeChecking = BSI->SavedFunctionNeedsScopeChecking;
 
   BSI->TheDecl->setBody(body.takeAs<CompoundStmt>());
+
+  bool Good = true;
+  // Check goto/label use.
+  for (llvm::DenseMap<IdentifierInfo*, LabelStmt*>::iterator
+         I = BSI->LabelMap.begin(), E = BSI->LabelMap.end(); I != E; ++I) {
+    LabelStmt *L = I->second;
+
+    // Verify that we have no forward references left.  If so, there was a goto
+    // or address of a label taken, but no definition of it.
+    if (L->getSubStmt() != 0)
+      continue;
+
+    // Emit error.
+    Diag(L->getIdentLoc(), diag::err_undeclared_label_use) << L->getName();
+    Good = false;
+  }
+  BSI->LabelMap.clear();
+  if (!Good)
+    return ExprError();
+
   AnalysisContext AC(BSI->TheDecl);
   CheckFallThroughForBlock(BlockTy, BSI->TheDecl->getBody(), AC);
   CheckUnreachable(AC);

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Jan 19 17:08:01 2010
@@ -879,10 +879,6 @@
 Action::OwningStmtResult
 Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
                     IdentifierInfo *LabelII) {
-  // If we are in a block, reject all gotos for now.
-  if (CurBlock)
-    return StmtError(Diag(GotoLoc, diag::err_goto_in_block));
-
   // Look up the record for this label identifier.
   LabelStmt *&LabelDecl = getLabelMap()[LabelII];
 

Modified: cfe/trunk/test/Sema/block-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-literal.c?rev=93945&r1=93944&r2=93945&view=diff

==============================================================================
--- cfe/trunk/test/Sema/block-literal.c (original)
+++ cfe/trunk/test/Sema/block-literal.c Tue Jan 19 17:08:01 2010
@@ -33,7 +33,8 @@
         break;  // expected-error {{'break' statement not in loop or switch statement}}
         continue; // expected-error {{'continue' statement not in loop statement}}
         while(1) break;  // ok
-        goto foo; // expected-error {{goto not allowed}}
+        goto foo; // expected-error {{use of undeclared label 'foo'}}
+        a: goto a;       // ok
       });
     break;
   }

Modified: cfe/trunk/test/Sema/block-misc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-misc.c?rev=93945&r1=93944&r2=93945&view=diff

==============================================================================
--- cfe/trunk/test/Sema/block-misc.c (original)
+++ cfe/trunk/test/Sema/block-misc.c Tue Jan 19 17:08:01 2010
@@ -87,8 +87,7 @@
 
 void test8() {
 somelabel:
- // FIXME: This should say "jump out of block not legal" when gotos are allowed.
-  ^{ goto somelabel; }();   // expected-error {{goto not allowed in block literal}}
+  ^{ goto somelabel; }();   // expected-error {{use of undeclared label 'somelabel'}}
 }
 
 void test9() {

Modified: cfe/trunk/test/Sema/scope-check.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/scope-check.c?rev=93945&r1=93944&r2=93945&view=diff

==============================================================================
--- cfe/trunk/test/Sema/scope-check.c (original)
+++ cfe/trunk/test/Sema/scope-check.c Tue Jan 19 17:08:01 2010
@@ -181,15 +181,14 @@
 // TODO: When and if gotos are allowed in blocks, this should work.
 void test12(int n) {
   void *P = ^{
-    goto L1;  // expected-error {{goto not allowed in block literal}}
+    goto L1;
   L1:
-    goto L2;  // expected-error {{goto not allowed in block literal}}
+    goto L2;
   L2:
-    goto L3;    // expected-error {{goto not allowed in block literal}}
-      // todo-error {{illegal goto into protected scope}}
-    int Arr[n]; // todo-note {{jump bypasses initialization of variable length array}}
+    goto L3;    // expected-error {{illegal goto into protected scope}}
+    int Arr[n]; // expected-note {{jump bypasses initialization of variable length array}}
   L3:
-    goto L4;  // expected-error {{goto not allowed in block literal}}
+    goto L4;
   L4: return;
   };
 }





More information about the cfe-commits mailing list