diff options
author | Chris Lattner <sabre@nondot.org> | 2010-03-01 20:59:53 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-03-01 20:59:53 +0000 |
commit | 30d0cfda354ec7f271ff3fa006db02d10a9e9610 (patch) | |
tree | af0b01ca1669547c4585763ce944fc02e09b6464 /clang/lib/Sema/SemaExpr.cpp | |
parent | 115da88f01a9014bc6f56bbf8d13536c318e969e (diff) | |
download | bcm5719-llvm-30d0cfda354ec7f271ff3fa006db02d10a9e9610.tar.gz bcm5719-llvm-30d0cfda354ec7f271ff3fa006db02d10a9e9610.zip |
Implement jump checking for initialized c++ variables, implementing
a fixme and PR6451.
Only perform jump checking if the containing function has no errors,
and add the infrastructure needed to do this.
On the testcase in the PR, we produce:
t.cc:6:3: error: illegal goto into protected scope
goto later;
^
t.cc:7:5: note: jump bypasses variable initialization
X x;
^
llvm-svn: 97497
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 0d1614abe96..966cbc72a25 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -6734,8 +6734,10 @@ void Sema::ActOnBlockStart(SourceLocation CaretLoc, Scope *BlockScope) { BSI->hasBlockDeclRefExprs = false; BSI->hasPrototype = false; BSI->SavedFunctionNeedsScopeChecking = CurFunctionNeedsScopeChecking; + BSI->SavedNumErrorsAtStartOfFunction = NumErrorsAtStartOfFunction; CurFunctionNeedsScopeChecking = false; - + NumErrorsAtStartOfFunction = getDiagnostics().getNumErrors(); + BSI->TheDecl = BlockDecl::Create(Context, CurContext, CaretLoc); CurContext->addDecl(BSI->TheDecl); PushDeclContext(BlockScope, BSI->TheDecl); @@ -6849,6 +6851,7 @@ void Sema::ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope) { llvm::OwningPtr<BlockScopeInfo> CC(CurBlock); CurFunctionNeedsScopeChecking = CurBlock->SavedFunctionNeedsScopeChecking; + NumErrorsAtStartOfFunction = CurBlock->SavedNumErrorsAtStartOfFunction; // Pop off CurBlock, handle nested blocks. PopDeclContext(); @@ -6895,9 +6898,12 @@ Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, BlockTy = Context.getBlockPointerType(BlockTy); // If needed, diagnose invalid gotos and switches in the block. - if (CurFunctionNeedsScopeChecking) + if (CurFunctionNeedsScopeChecking && + NumErrorsAtStartOfFunction == getDiagnostics().getNumErrors()) DiagnoseInvalidJumps(static_cast<CompoundStmt*>(body.get())); + CurFunctionNeedsScopeChecking = BSI->SavedFunctionNeedsScopeChecking; + NumErrorsAtStartOfFunction = BSI->SavedNumErrorsAtStartOfFunction; BSI->TheDecl->setBody(body.takeAs<CompoundStmt>()); |