[cfe-commits] r66896 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaExpr.cpp lib/Sema/SemaStmt.cpp test/Sema/block-labels.c

Steve Naroff snaroff at apple.com
Fri Mar 13 09:03:38 PDT 2009


Author: snaroff
Date: Fri Mar 13 11:03:38 2009
New Revision: 66896

URL: http://llvm.org/viewvc/llvm-project?rev=66896&view=rev
Log:
Reimplement fix for <rdar://problem/6451399> problems with labels and blocks.

This solution is much simpler (and doesn't add any per-scope overhead, which concerned Chris). 

The only downside is the LabelMap is now declared in two places (Sema and BlockSemaInfo). My original fix tried to unify the LabelMap in "Scope" (which would support nested functions in general). In any event, this fixes the bug given the current language definition. If/when we decide to support GCC style nested functions, this will need to be tweaked.


Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/Sema/block-labels.c

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=66896&r1=66895&r2=66896&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Mar 13 11:03:38 2009
@@ -2310,6 +2310,11 @@
   /// return types, if any, in the block body.
   Type *ReturnType;
   
+  /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
+  /// it (which acts like the label decl in some ways).  Forward referenced
+  /// labels have a LabelStmt created for them with a null location & SubStmt.
+  llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
+  
   /// PrevBlockInfo - If this is nested inside another block, this points
   /// to the outer block.
   BlockSemaInfo *PrevBlockInfo;

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Mar 13 11:03:38 2009
@@ -4336,7 +4336,8 @@
                                       SourceLocation LabLoc,
                                       IdentifierInfo *LabelII) {
   // Look up the record for this label identifier.
-  LabelStmt *&LabelDecl = LabelMap[LabelII];
+  LabelStmt *&LabelDecl = CurBlock ? CurBlock->LabelMap[LabelII] : 
+                                     LabelMap[LabelII];
 
   // If we haven't seen this label yet, create a forward reference. It
   // will be validated and/or cleaned up in ActOnFinishFunctionBody.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Fri Mar 13 11:03:38 2009
@@ -170,7 +170,7 @@
                      SourceLocation ColonLoc, StmtArg subStmt) {
   Stmt *SubStmt = static_cast<Stmt*>(subStmt.release());
   // Look up the record for this label identifier.
-  LabelStmt *&LabelDecl = LabelMap[II];
+  LabelStmt *&LabelDecl = CurBlock ? CurBlock->LabelMap[II] : LabelMap[II];
 
   // If not forward referenced or defined already, just create a new LabelStmt.
   if (LabelDecl == 0)
@@ -676,7 +676,8 @@
     return StmtError(Diag(GotoLoc, diag::err_goto_in_block));
 
   // Look up the record for this label identifier.
-  LabelStmt *&LabelDecl = LabelMap[LabelII];
+  LabelStmt *&LabelDecl = CurBlock ? CurBlock->LabelMap[LabelII] : 
+                                     LabelMap[LabelII];
 
   // If we haven't seen this label yet, create a forward reference.
   if (LabelDecl == 0)

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

==============================================================================
--- cfe/trunk/test/Sema/block-labels.c (original)
+++ cfe/trunk/test/Sema/block-labels.c Fri Mar 13 11:03:38 2009
@@ -0,0 +1,17 @@
+// RUN: clang %s -verify -fblocks -fsyntax-only
+
+int a() { 
+  A:if (1) xx();
+  return ^{A:return 1;}();
+}
+int b() { 
+  A: return ^{int a; A:return 1;}();
+}
+
+int d() { 
+  A: return ^{int a; A: a = ^{int a; A:return 1;}() + ^{int b; A:return 2;}(); return a; }();
+}
+
+int c() { 
+  goto A; return ^{ A:return 1;}(); // expected-error {{use of undeclared label 'A'}}
+}





More information about the cfe-commits mailing list