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 | 6d97e5e4b7abdae710c2548b51f4ed0298e86d80 (patch) | |
tree | 1bfd4ca64b65979839394efe939d3310598c81e9 /lib/Sema/SemaDecl.cpp | |
parent | 632c9d26925f9aa8179607956c83ee348930b6d7 (diff) |
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;
^
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97497 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 47c787b0c4..be4a591f29 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -850,7 +850,7 @@ void Sema::MergeTypeDefDecl(TypedefDecl *New, LookupResult &OldDecls) { // is normally mapped to an error, but can be controlled with // -Wtypedef-redefinition. If either the original or the redefinition is // in a system header, don't emit this for compatibility with GCC. - if (PP.getDiagnostics().getSuppressSystemWarnings() && + if (getDiagnostics().getSuppressSystemWarnings() && (Context.getSourceManager().isInSystemHeader(Old->getLocation()) || Context.getSourceManager().isInSystemHeader(New->getLocation()))) return; @@ -2500,7 +2500,12 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, bool isVM = T->isVariablyModifiedType(); if (isVM || NewVD->hasAttr<CleanupAttr>() || - NewVD->hasAttr<BlocksAttr>()) + NewVD->hasAttr<BlocksAttr>() || + // FIXME: We need to diagnose jumps passed initialized variables in C++. + // However, this turns on the scope checker for everything with a variable + // which may impact compile time. See if we can find a better solution + // to this, perhaps only checking functions that contain gotos in C++? + (LangOpts.CPlusPlus && NewVD->hasLocalStorage())) CurFunctionNeedsScopeChecking = true; if ((isVM && NewVD->hasLinkage()) || @@ -4079,6 +4084,7 @@ Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) { FD = cast<FunctionDecl>(D.getAs<Decl>()); CurFunctionNeedsScopeChecking = false; + NumErrorsAtStartOfFunction = getDiagnostics().getNumErrors(); // See if this is a redefinition. // But don't complain if we're in GNU89 mode and the previous definition @@ -4257,7 +4263,8 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg, CheckUnreachable(AC); // Verify that that gotos and switch cases don't jump into scopes illegally. - if (CurFunctionNeedsScopeChecking) + if (CurFunctionNeedsScopeChecking && + NumErrorsAtStartOfFunction == getDiagnostics().getNumErrors()) DiagnoseInvalidJumps(Body); // C++ constructors that have function-try-blocks can't have return @@ -4272,7 +4279,7 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg, // If any errors have occurred, clear out any temporaries that may have // been leftover. This ensures that these temporaries won't be picked up for // deletion in some later function. - if (PP.getDiagnostics().hasErrorOccurred()) + if (getDiagnostics().hasErrorOccurred()) ExprTemporaries.clear(); assert(ExprTemporaries.empty() && "Leftover temporaries in function"); |