diff options
| author | John McCall <rjmccall@apple.com> | 2010-08-01 00:26:45 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-08-01 00:26:45 +0000 |
| commit | a95172baa0475d0045ddf493679f7611eb4efeb2 (patch) | |
| tree | aeb8e904db3978722bd97e11e48d98ac9a15ff06 /clang/lib/Sema/Sema.h | |
| parent | 82bef970cf218c3e99b1bb3d5be6b8bb6e1434b7 (diff) | |
| download | bcm5719-llvm-a95172baa0475d0045ddf493679f7611eb4efeb2.tar.gz bcm5719-llvm-a95172baa0475d0045ddf493679f7611eb4efeb2.zip | |
Only run the jump-checker if there's a branch-protected scope *and* there's
a switch or goto somewhere in the function. Indirect gotos trigger the
jump-checker regardless, because the conditions there are slightly more
elaborate and it's too marginal a case to be worth optimizing.
Turns off the jump-checker in a lot of cases in C++. rdar://problem/7702918
llvm-svn: 109962
Diffstat (limited to 'clang/lib/Sema/Sema.h')
| -rw-r--r-- | clang/lib/Sema/Sema.h | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index b0b777073c7..ecd167d9a07 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/lib/Sema/Sema.h @@ -116,11 +116,15 @@ struct FunctionScopeInfo { /// a block. bool IsBlockInfo; - /// \brief Set true when a function, method contains a VLA or ObjC try block, - /// which introduce scopes that need to be checked for goto conditions. If a - /// function does not contain this, then it need not have the jump checker run - /// on it. - bool NeedsScopeChecking; + /// \brief Whether this function contains a VLA, @try, try, C++ + /// initializer, or anything else that can't be jumped past. + bool HasBranchProtectedScope; + + /// \brief Whether this function contains any switches or direct gotos. + bool HasBranchIntoScope; + + /// \brief Whether this function contains any indirect gotos. + bool HasIndirectGoto; /// \brief The number of errors that had occurred before starting this /// function or block. @@ -139,9 +143,17 @@ struct FunctionScopeInfo { /// block, if there is any chance of applying the named return value /// optimization. llvm::SmallVector<ReturnStmt *, 4> Returns; + + bool NeedsScopeChecking() const { + return HasIndirectGoto || + (HasBranchProtectedScope && HasBranchIntoScope); + } FunctionScopeInfo(unsigned NumErrors) - : IsBlockInfo(false), NeedsScopeChecking(false), + : IsBlockInfo(false), + HasBranchProtectedScope(false), + HasBranchIntoScope(false), + HasIndirectGoto(false), NumErrorsAtStartOfFunction(NumErrors) { } virtual ~FunctionScopeInfo(); @@ -706,13 +718,28 @@ public: /// \brief Determine whether the current function or block needs scope /// checking. - bool &FunctionNeedsScopeChecking() { - if (FunctionScopes.empty()) - return TopFunctionScope.NeedsScopeChecking; + bool FunctionNeedsScopeChecking() { + if (!FunctionScopes.empty()) + return FunctionScopes.back()->NeedsScopeChecking(); + return false; + } - return FunctionScopes.back()->NeedsScopeChecking; + void setFunctionHasBranchIntoScope() { + if (!FunctionScopes.empty()) + FunctionScopes.back()->HasBranchIntoScope = true; } + void setFunctionHasBranchProtectedScope() { + if (!FunctionScopes.empty()) + FunctionScopes.back()->HasBranchProtectedScope = true; + } + + void setFunctionHasIndirectGoto() { + if (!FunctionScopes.empty()) + FunctionScopes.back()->HasIndirectGoto = true; + } + + bool hasAnyErrorsInThisFunction() const; /// \brief Retrieve the current block, if any. |

