summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2009-02-28 16:48:43 +0000
committerSteve Naroff <snaroff@apple.com>2009-02-28 16:48:43 +0000
commitd123bd05cab62bb3c641d0c2343fd94e6a96235e (patch)
tree710a9706402f096e1bed6df64d28b5e65dccab2c /clang/lib/Sema/SemaStmt.cpp
parent638b836aab3e6df7a568913fad46fd70225a1d21 (diff)
downloadbcm5719-llvm-d123bd05cab62bb3c641d0c2343fd94e6a96235e.tar.gz
bcm5719-llvm-d123bd05cab62bb3c641d0c2343fd94e6a96235e.zip
Fix <rdar://problem/6451399> problems with labels and blocks.
- Move the 'LabelMap' from Sema to Scope. To avoid layering problems, the second element is now a 'StmtTy *', which makes the LabelMap a bit more verbose to deal with. - Add 'ActiveScope' to Sema. Managed by ActOnStartOfFunctionDef(), ObjCActOnStartOfMethodDef(), ActOnBlockStmtExpr(). - Changed ActOnLabelStmt(), ActOnGotoStmt(), ActOnAddrLabel(), and ActOnFinishFunctionBody() to use the new ActiveScope. - Added FIXME to workaround in ActOnFinishFunctionBody() (for dealing with C++ nested functions). llvm-svn: 65694
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 990e951c3b6..dfcb65a3532 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -165,12 +165,19 @@ Action::OwningStmtResult
Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
SourceLocation ColonLoc, StmtArg subStmt) {
Stmt *SubStmt = static_cast<Stmt*>(subStmt.release());
+
// Look up the record for this label identifier.
- LabelStmt *&LabelDecl = LabelMap[II];
+ Scope::LabelMapTy::iterator I = ActiveScope->LabelMap.find(II);
+ LabelStmt *LabelDecl;
+
// If not forward referenced or defined already, just create a new LabelStmt.
- if (LabelDecl == 0)
- return Owned(LabelDecl = new (Context) LabelStmt(IdentLoc, II, SubStmt));
+ if (I == ActiveScope->LabelMap.end()) {
+ LabelDecl = new (Context) LabelStmt(IdentLoc, II, SubStmt);
+ ActiveScope->LabelMap.insert(std::make_pair(II, LabelDecl));
+ return Owned(LabelDecl);
+ } else
+ LabelDecl = static_cast<LabelStmt *>(I->second);
assert(LabelDecl->getID() == II && "Label mismatch!");
@@ -672,11 +679,16 @@ Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
return StmtError(Diag(GotoLoc, diag::err_goto_in_block));
// Look up the record for this label identifier.
- LabelStmt *&LabelDecl = LabelMap[LabelII];
+ Scope::LabelMapTy::iterator I = ActiveScope->LabelMap.find(LabelII);
- // If we haven't seen this label yet, create a forward reference.
- if (LabelDecl == 0)
+ LabelStmt *LabelDecl;
+
+ // If not forward referenced or defined already, just create a new LabelStmt.
+ if (I == ActiveScope->LabelMap.end()) {
LabelDecl = new (Context) LabelStmt(LabelLoc, LabelII, 0);
+ ActiveScope->LabelMap.insert(std::make_pair(LabelII, LabelDecl));
+ } else
+ LabelDecl = static_cast<LabelStmt *>(I->second);
return Owned(new (Context) GotoStmt(LabelDecl, GotoLoc, LabelLoc));
}
OpenPOWER on IntegriCloud