Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 1 | //===--- JumpDiagnostics.cpp - Analyze Jump Targets for VLA issues --------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the JumpScopeChecker class, which is used to diagnose |
| 11 | // jumps that enter a VLA scope in an invalid way. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
John McCall | 2d88708 | 2010-08-25 22:03:47 +0000 | [diff] [blame] | 15 | #include "clang/Sema/SemaInternal.h" |
John McCall | 384aff8 | 2010-08-25 07:42:41 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 17 | #include "clang/AST/Expr.h" |
Douglas Gregor | e413516 | 2011-05-27 16:05:29 +0000 | [diff] [blame] | 18 | #include "clang/AST/ExprCXX.h" |
Chris Lattner | 16f0049 | 2009-04-26 01:32:48 +0000 | [diff] [blame] | 19 | #include "clang/AST/StmtObjC.h" |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 20 | #include "clang/AST/StmtCXX.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/BitVector.h" |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 22 | using namespace clang; |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | /// JumpScopeChecker - This object is used by Sema to diagnose invalid jumps |
| 27 | /// into VLA and other protected scopes. For example, this rejects: |
| 28 | /// goto L; |
| 29 | /// int a[n]; |
| 30 | /// L: |
| 31 | /// |
| 32 | class JumpScopeChecker { |
| 33 | Sema &S; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 35 | /// GotoScope - This is a record that we use to keep track of all of the |
| 36 | /// scopes that are introduced by VLAs and other things that scope jumps like |
| 37 | /// gotos. This scope tree has nothing to do with the source scope tree, |
| 38 | /// because you can have multiple VLA scopes per compound statement, and most |
| 39 | /// compound statements don't introduce any scopes. |
| 40 | struct GotoScope { |
| 41 | /// ParentScope - The index in ScopeMap of the parent scope. This is 0 for |
| 42 | /// the parent scope is the function body. |
| 43 | unsigned ParentScope; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 44 | |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 45 | /// InDiag - The diagnostic to emit if there is a jump into this scope. |
| 46 | unsigned InDiag; |
| 47 | |
| 48 | /// OutDiag - The diagnostic to emit if there is an indirect jump out |
| 49 | /// of this scope. Direct jumps always clean up their current scope |
| 50 | /// in an orderly way. |
| 51 | unsigned OutDiag; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 52 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 53 | /// Loc - Location to emit the diagnostic. |
| 54 | SourceLocation Loc; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 56 | GotoScope(unsigned parentScope, unsigned InDiag, unsigned OutDiag, |
| 57 | SourceLocation L) |
| 58 | : ParentScope(parentScope), InDiag(InDiag), OutDiag(OutDiag), Loc(L) {} |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 59 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 60 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 61 | llvm::SmallVector<GotoScope, 48> Scopes; |
| 62 | llvm::DenseMap<Stmt*, unsigned> LabelAndGotoScopes; |
| 63 | llvm::SmallVector<Stmt*, 16> Jumps; |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 64 | |
| 65 | llvm::SmallVector<IndirectGotoStmt*, 4> IndirectJumps; |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 66 | llvm::SmallVector<LabelDecl*, 4> IndirectJumpTargets; |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 67 | public: |
| 68 | JumpScopeChecker(Stmt *Body, Sema &S); |
| 69 | private: |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 70 | void BuildScopeInformation(Decl *D, unsigned &ParentScope); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 71 | void BuildScopeInformation(Stmt *S, unsigned ParentScope); |
| 72 | void VerifyJumps(); |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 73 | void VerifyIndirectJumps(); |
| 74 | void DiagnoseIndirectJump(IndirectGotoStmt *IG, unsigned IGScope, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 75 | LabelDecl *Target, unsigned TargetScope); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 76 | void CheckJump(Stmt *From, Stmt *To, |
| 77 | SourceLocation DiagLoc, unsigned JumpDiag); |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 78 | |
| 79 | unsigned GetDeepestCommonScope(unsigned A, unsigned B); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 80 | }; |
| 81 | } // end anonymous namespace |
| 82 | |
| 83 | |
| 84 | JumpScopeChecker::JumpScopeChecker(Stmt *Body, Sema &s) : S(s) { |
| 85 | // Add a scope entry for function scope. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 86 | Scopes.push_back(GotoScope(~0U, ~0U, ~0U, SourceLocation())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 87 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 88 | // Build information for the top level compound statement, so that we have a |
| 89 | // defined scope record for every "goto" and label. |
| 90 | BuildScopeInformation(Body, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 91 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 92 | // Check that all jumps we saw are kosher. |
| 93 | VerifyJumps(); |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 94 | VerifyIndirectJumps(); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 95 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 96 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 97 | /// GetDeepestCommonScope - Finds the innermost scope enclosing the |
| 98 | /// two scopes. |
| 99 | unsigned JumpScopeChecker::GetDeepestCommonScope(unsigned A, unsigned B) { |
| 100 | while (A != B) { |
| 101 | // Inner scopes are created after outer scopes and therefore have |
| 102 | // higher indices. |
| 103 | if (A < B) { |
| 104 | assert(Scopes[B].ParentScope < B); |
| 105 | B = Scopes[B].ParentScope; |
| 106 | } else { |
| 107 | assert(Scopes[A].ParentScope < A); |
| 108 | A = Scopes[A].ParentScope; |
| 109 | } |
| 110 | } |
| 111 | return A; |
| 112 | } |
| 113 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 114 | /// GetDiagForGotoScopeDecl - If this decl induces a new goto scope, return a |
| 115 | /// diagnostic that should be emitted if control goes over it. If not, return 0. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 116 | static std::pair<unsigned,unsigned> |
| 117 | GetDiagForGotoScopeDecl(const Decl *D, bool isCPlusPlus) { |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 118 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 119 | unsigned InDiag = 0, OutDiag = 0; |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 120 | if (VD->getType()->isVariablyModifiedType()) |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 121 | InDiag = diag::note_protected_by_vla; |
| 122 | |
| 123 | if (VD->hasAttr<BlocksAttr>()) { |
| 124 | InDiag = diag::note_protected_by___block; |
| 125 | OutDiag = diag::note_exits___block; |
| 126 | } else if (VD->hasAttr<CleanupAttr>()) { |
| 127 | InDiag = diag::note_protected_by_cleanup; |
| 128 | OutDiag = diag::note_exits_cleanup; |
| 129 | } else if (isCPlusPlus) { |
Douglas Gregor | e413516 | 2011-05-27 16:05:29 +0000 | [diff] [blame] | 130 | if (!VD->hasLocalStorage()) |
| 131 | return std::make_pair(InDiag, OutDiag); |
| 132 | |
| 133 | ASTContext &Context = D->getASTContext(); |
| 134 | QualType T = Context.getBaseElementType(VD->getType()); |
Douglas Gregor | 025291b | 2010-07-01 00:21:21 +0000 | [diff] [blame] | 135 | if (!T->isDependentType()) { |
Douglas Gregor | e413516 | 2011-05-27 16:05:29 +0000 | [diff] [blame] | 136 | // C++0x [stmt.dcl]p3: |
| 137 | // A program that jumps from a point where a variable with automatic |
| 138 | // storage duration is not in scope to a point where it is in scope |
| 139 | // is ill-formed unless the variable has scalar type, class type with |
| 140 | // a trivial default constructor and a trivial destructor, a |
| 141 | // cv-qualified version of one of these types, or an array of one of |
| 142 | // the preceding types and is declared without an initializer (8.5). |
Douglas Gregor | f61103e | 2011-05-27 21:28:00 +0000 | [diff] [blame^] | 143 | // Check whether this is a C++ class. |
| 144 | CXXRecordDecl *Record = T->getAsCXXRecordDecl(); |
| 145 | |
| 146 | if (const Expr *Init = VD->getInit()) { |
| 147 | bool CallsTrivialConstructor = false; |
| 148 | if (Record) { |
| 149 | // FIXME: With generalized initializer lists, this may |
| 150 | // classify "X x{};" as having no initializer. |
| 151 | if (const CXXConstructExpr *Construct |
| 152 | = dyn_cast<CXXConstructExpr>(Init)) |
| 153 | if (const CXXConstructorDecl *Constructor |
| 154 | = Construct->getConstructor()) |
| 155 | if (Constructor->isDefaultConstructor() && |
| 156 | ((Context.getLangOptions().CPlusPlus0x && |
| 157 | Record->hasTrivialDefaultConstructor()) || |
| 158 | (!Context.getLangOptions().CPlusPlus0x && |
| 159 | Record->isPOD()))) |
| 160 | CallsTrivialConstructor = true; |
Douglas Gregor | e413516 | 2011-05-27 16:05:29 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Douglas Gregor | f61103e | 2011-05-27 21:28:00 +0000 | [diff] [blame^] | 163 | if (!CallsTrivialConstructor) |
| 164 | InDiag = diag::note_protected_by_variable_init; |
Douglas Gregor | e413516 | 2011-05-27 16:05:29 +0000 | [diff] [blame] | 165 | } |
Douglas Gregor | f61103e | 2011-05-27 21:28:00 +0000 | [diff] [blame^] | 166 | |
| 167 | // Note whether we have a class with a non-trivial destructor. |
| 168 | if (Record && !Record->hasTrivialDestructor()) |
| 169 | OutDiag = diag::note_exits_dtor; |
Douglas Gregor | 025291b | 2010-07-01 00:21:21 +0000 | [diff] [blame] | 170 | } |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 171 | } |
Chris Lattner | 6d97e5e | 2010-03-01 20:59:53 +0000 | [diff] [blame] | 172 | |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 173 | return std::make_pair(InDiag, OutDiag); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 174 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 | |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 176 | if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) { |
| 177 | if (TD->getUnderlyingType()->isVariablyModifiedType()) |
| 178 | return std::make_pair((unsigned) diag::note_protected_by_vla_typedef, 0); |
| 179 | } |
| 180 | |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 181 | if (const TypeAliasDecl *TD = dyn_cast<TypeAliasDecl>(D)) { |
| 182 | if (TD->getUnderlyingType()->isVariablyModifiedType()) |
| 183 | return std::make_pair((unsigned) diag::note_protected_by_vla_type_alias, 0); |
| 184 | } |
| 185 | |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 186 | return std::make_pair(0U, 0U); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 189 | /// \brief Build scope information for a declaration that is part of a DeclStmt. |
| 190 | void JumpScopeChecker::BuildScopeInformation(Decl *D, unsigned &ParentScope) { |
| 191 | bool isCPlusPlus = this->S.getLangOptions().CPlusPlus; |
| 192 | |
| 193 | // If this decl causes a new scope, push and switch to it. |
| 194 | std::pair<unsigned,unsigned> Diags |
| 195 | = GetDiagForGotoScopeDecl(D, isCPlusPlus); |
| 196 | if (Diags.first || Diags.second) { |
| 197 | Scopes.push_back(GotoScope(ParentScope, Diags.first, Diags.second, |
| 198 | D->getLocation())); |
| 199 | ParentScope = Scopes.size()-1; |
| 200 | } |
| 201 | |
| 202 | // If the decl has an initializer, walk it with the potentially new |
| 203 | // scope we just installed. |
| 204 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) |
| 205 | if (Expr *Init = VD->getInit()) |
| 206 | BuildScopeInformation(Init, ParentScope); |
| 207 | } |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 208 | |
| 209 | /// BuildScopeInformation - The statements from CI to CE are known to form a |
| 210 | /// coherent VLA scope with a specified parent node. Walk through the |
| 211 | /// statements, adding any labels or gotos to LabelAndGotoScopes and recursively |
| 212 | /// walking the AST as needed. |
| 213 | void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned ParentScope) { |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 214 | bool SkipFirstSubStmt = false; |
| 215 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 216 | // If we found a label, remember that it is in ParentScope scope. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 217 | switch (S->getStmtClass()) { |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 218 | case Stmt::AddrLabelExprClass: |
| 219 | IndirectJumpTargets.push_back(cast<AddrLabelExpr>(S)->getLabel()); |
| 220 | break; |
| 221 | |
| 222 | case Stmt::IndirectGotoStmtClass: |
John McCall | 95c225d | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 223 | // "goto *&&lbl;" is a special case which we treat as equivalent |
| 224 | // to a normal goto. In addition, we don't calculate scope in the |
| 225 | // operand (to avoid recording the address-of-label use), which |
| 226 | // works only because of the restricted set of expressions which |
| 227 | // we detect as constant targets. |
| 228 | if (cast<IndirectGotoStmt>(S)->getConstantTarget()) { |
| 229 | LabelAndGotoScopes[S] = ParentScope; |
| 230 | Jumps.push_back(S); |
| 231 | return; |
| 232 | } |
| 233 | |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 234 | LabelAndGotoScopes[S] = ParentScope; |
| 235 | IndirectJumps.push_back(cast<IndirectGotoStmt>(S)); |
| 236 | break; |
| 237 | |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 238 | case Stmt::SwitchStmtClass: |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 239 | // Evaluate the condition variable before entering the scope of the switch |
| 240 | // statement. |
| 241 | if (VarDecl *Var = cast<SwitchStmt>(S)->getConditionVariable()) { |
| 242 | BuildScopeInformation(Var, ParentScope); |
| 243 | SkipFirstSubStmt = true; |
| 244 | } |
| 245 | // Fall through |
| 246 | |
| 247 | case Stmt::GotoStmtClass: |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 248 | // Remember both what scope a goto is in as well as the fact that we have |
| 249 | // it. This makes the second scan not have to walk the AST again. |
| 250 | LabelAndGotoScopes[S] = ParentScope; |
| 251 | Jumps.push_back(S); |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 252 | break; |
| 253 | |
| 254 | default: |
| 255 | break; |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 256 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 257 | |
John McCall | 7502c1d | 2011-02-13 04:07:26 +0000 | [diff] [blame] | 258 | for (Stmt::child_range CI = S->children(); CI; ++CI) { |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 259 | if (SkipFirstSubStmt) { |
| 260 | SkipFirstSubStmt = false; |
| 261 | continue; |
| 262 | } |
| 263 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 264 | Stmt *SubStmt = *CI; |
| 265 | if (SubStmt == 0) continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 266 | |
John McCall | 97ba481 | 2010-08-02 23:33:14 +0000 | [diff] [blame] | 267 | // Cases, labels, and defaults aren't "scope parents". It's also |
| 268 | // important to handle these iteratively instead of recursively in |
| 269 | // order to avoid blowing out the stack. |
| 270 | while (true) { |
| 271 | Stmt *Next; |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 272 | if (CaseStmt *CS = dyn_cast<CaseStmt>(SubStmt)) |
| 273 | Next = CS->getSubStmt(); |
| 274 | else if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SubStmt)) |
| 275 | Next = DS->getSubStmt(); |
| 276 | else if (LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt)) |
| 277 | Next = LS->getSubStmt(); |
John McCall | 97ba481 | 2010-08-02 23:33:14 +0000 | [diff] [blame] | 278 | else |
| 279 | break; |
| 280 | |
| 281 | LabelAndGotoScopes[SubStmt] = ParentScope; |
| 282 | SubStmt = Next; |
| 283 | } |
| 284 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 285 | // If this is a declstmt with a VLA definition, it defines a scope from here |
| 286 | // to the end of the containing context. |
| 287 | if (DeclStmt *DS = dyn_cast<DeclStmt>(SubStmt)) { |
Chris Lattner | 6d97e5e | 2010-03-01 20:59:53 +0000 | [diff] [blame] | 288 | // The decl statement creates a scope if any of the decls in it are VLAs |
| 289 | // or have the cleanup attribute. |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 290 | for (DeclStmt::decl_iterator I = DS->decl_begin(), E = DS->decl_end(); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 291 | I != E; ++I) |
| 292 | BuildScopeInformation(*I, ParentScope); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 293 | continue; |
| 294 | } |
| 295 | |
| 296 | // Disallow jumps into any part of an @try statement by pushing a scope and |
| 297 | // walking all sub-stmts in that scope. |
| 298 | if (ObjCAtTryStmt *AT = dyn_cast<ObjCAtTryStmt>(SubStmt)) { |
| 299 | // Recursively walk the AST for the @try part. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 300 | Scopes.push_back(GotoScope(ParentScope, |
| 301 | diag::note_protected_by_objc_try, |
| 302 | diag::note_exits_objc_try, |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 303 | AT->getAtTryLoc())); |
| 304 | if (Stmt *TryPart = AT->getTryBody()) |
| 305 | BuildScopeInformation(TryPart, Scopes.size()-1); |
| 306 | |
| 307 | // Jump from the catch to the finally or try is not valid. |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 308 | for (unsigned I = 0, N = AT->getNumCatchStmts(); I != N; ++I) { |
| 309 | ObjCAtCatchStmt *AC = AT->getCatchStmt(I); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 310 | Scopes.push_back(GotoScope(ParentScope, |
| 311 | diag::note_protected_by_objc_catch, |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 312 | diag::note_exits_objc_catch, |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 313 | AC->getAtCatchLoc())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 314 | // @catches are nested and it isn't |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 315 | BuildScopeInformation(AC->getCatchBody(), Scopes.size()-1); |
| 316 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 317 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 318 | // Jump from the finally to the try or catch is not valid. |
| 319 | if (ObjCAtFinallyStmt *AF = AT->getFinallyStmt()) { |
| 320 | Scopes.push_back(GotoScope(ParentScope, |
| 321 | diag::note_protected_by_objc_finally, |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 322 | diag::note_exits_objc_finally, |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 323 | AF->getAtFinallyLoc())); |
| 324 | BuildScopeInformation(AF, Scopes.size()-1); |
| 325 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 326 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 327 | continue; |
| 328 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 329 | |
Chris Lattner | 46c3c4b | 2009-04-21 06:01:00 +0000 | [diff] [blame] | 330 | // Disallow jumps into the protected statement of an @synchronized, but |
| 331 | // allow jumps into the object expression it protects. |
| 332 | if (ObjCAtSynchronizedStmt *AS = dyn_cast<ObjCAtSynchronizedStmt>(SubStmt)){ |
| 333 | // Recursively walk the AST for the @synchronized object expr, it is |
| 334 | // evaluated in the normal scope. |
| 335 | BuildScopeInformation(AS->getSynchExpr(), ParentScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 336 | |
Chris Lattner | 46c3c4b | 2009-04-21 06:01:00 +0000 | [diff] [blame] | 337 | // Recursively walk the AST for the @synchronized part, protected by a new |
| 338 | // scope. |
| 339 | Scopes.push_back(GotoScope(ParentScope, |
| 340 | diag::note_protected_by_objc_synchronized, |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 341 | diag::note_exits_objc_synchronized, |
Chris Lattner | 46c3c4b | 2009-04-21 06:01:00 +0000 | [diff] [blame] | 342 | AS->getAtSynchronizedLoc())); |
| 343 | BuildScopeInformation(AS->getSynchBody(), Scopes.size()-1); |
| 344 | continue; |
| 345 | } |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 346 | |
| 347 | // Disallow jumps into any part of a C++ try statement. This is pretty |
| 348 | // much the same as for Obj-C. |
| 349 | if (CXXTryStmt *TS = dyn_cast<CXXTryStmt>(SubStmt)) { |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 350 | Scopes.push_back(GotoScope(ParentScope, |
| 351 | diag::note_protected_by_cxx_try, |
| 352 | diag::note_exits_cxx_try, |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 353 | TS->getSourceRange().getBegin())); |
| 354 | if (Stmt *TryBlock = TS->getTryBlock()) |
| 355 | BuildScopeInformation(TryBlock, Scopes.size()-1); |
| 356 | |
| 357 | // Jump from the catch into the try is not allowed either. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | for (unsigned I = 0, E = TS->getNumHandlers(); I != E; ++I) { |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 359 | CXXCatchStmt *CS = TS->getHandler(I); |
| 360 | Scopes.push_back(GotoScope(ParentScope, |
| 361 | diag::note_protected_by_cxx_catch, |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 362 | diag::note_exits_cxx_catch, |
Sebastian Redl | 972041f | 2009-04-27 20:27:31 +0000 | [diff] [blame] | 363 | CS->getSourceRange().getBegin())); |
| 364 | BuildScopeInformation(CS->getHandlerBlock(), Scopes.size()-1); |
| 365 | } |
| 366 | |
| 367 | continue; |
| 368 | } |
| 369 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 370 | // Recursively walk the AST. |
| 371 | BuildScopeInformation(SubStmt, ParentScope); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | /// VerifyJumps - Verify each element of the Jumps array to see if they are |
| 376 | /// valid, emitting diagnostics if not. |
| 377 | void JumpScopeChecker::VerifyJumps() { |
| 378 | while (!Jumps.empty()) { |
| 379 | Stmt *Jump = Jumps.pop_back_val(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 380 | |
| 381 | // With a goto, |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 382 | if (GotoStmt *GS = dyn_cast<GotoStmt>(Jump)) { |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 383 | CheckJump(GS, GS->getLabel()->getStmt(), GS->getGotoLoc(), |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 384 | diag::err_goto_into_protected_scope); |
| 385 | continue; |
| 386 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 387 | |
John McCall | 95c225d | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 388 | // We only get indirect gotos here when they have a constant target. |
| 389 | if (IndirectGotoStmt *IGS = dyn_cast<IndirectGotoStmt>(Jump)) { |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 390 | LabelDecl *Target = IGS->getConstantTarget(); |
| 391 | CheckJump(IGS, Target->getStmt(), IGS->getGotoLoc(), |
John McCall | 95c225d | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 392 | diag::err_goto_into_protected_scope); |
| 393 | continue; |
| 394 | } |
| 395 | |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 396 | SwitchStmt *SS = cast<SwitchStmt>(Jump); |
| 397 | for (SwitchCase *SC = SS->getSwitchCaseList(); SC; |
| 398 | SC = SC->getNextSwitchCase()) { |
| 399 | assert(LabelAndGotoScopes.count(SC) && "Case not visited?"); |
| 400 | CheckJump(SS, SC, SC->getLocStart(), |
| 401 | diag::err_switch_into_protected_scope); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | } |
| 405 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 406 | /// VerifyIndirectJumps - Verify whether any possible indirect jump |
| 407 | /// might cross a protection boundary. Unlike direct jumps, indirect |
| 408 | /// jumps count cleanups as protection boundaries: since there's no |
| 409 | /// way to know where the jump is going, we can't implicitly run the |
| 410 | /// right cleanups the way we can with direct jumps. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 411 | /// |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 412 | /// Thus, an indirect jump is "trivial" if it bypasses no |
| 413 | /// initializations and no teardowns. More formally, an indirect jump |
| 414 | /// from A to B is trivial if the path out from A to DCA(A,B) is |
| 415 | /// trivial and the path in from DCA(A,B) to B is trivial, where |
| 416 | /// DCA(A,B) is the deepest common ancestor of A and B. |
| 417 | /// Jump-triviality is transitive but asymmetric. |
| 418 | /// |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 419 | /// A path in is trivial if none of the entered scopes have an InDiag. |
| 420 | /// A path out is trivial is none of the exited scopes have an OutDiag. |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 421 | /// |
| 422 | /// Under these definitions, this function checks that the indirect |
| 423 | /// jump between A and B is trivial for every indirect goto statement A |
| 424 | /// and every label B whose address was taken in the function. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 425 | void JumpScopeChecker::VerifyIndirectJumps() { |
| 426 | if (IndirectJumps.empty()) return; |
| 427 | |
| 428 | // If there aren't any address-of-label expressions in this function, |
| 429 | // complain about the first indirect goto. |
| 430 | if (IndirectJumpTargets.empty()) { |
| 431 | S.Diag(IndirectJumps[0]->getGotoLoc(), |
| 432 | diag::err_indirect_goto_without_addrlabel); |
| 433 | return; |
| 434 | } |
| 435 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 436 | // Collect a single representative of every scope containing an |
| 437 | // indirect goto. For most code bases, this substantially cuts |
| 438 | // down on the number of jump sites we'll have to consider later. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 439 | typedef std::pair<unsigned, IndirectGotoStmt*> JumpScope; |
| 440 | llvm::SmallVector<JumpScope, 32> JumpScopes; |
| 441 | { |
| 442 | llvm::DenseMap<unsigned, IndirectGotoStmt*> JumpScopesMap; |
| 443 | for (llvm::SmallVectorImpl<IndirectGotoStmt*>::iterator |
| 444 | I = IndirectJumps.begin(), E = IndirectJumps.end(); I != E; ++I) { |
| 445 | IndirectGotoStmt *IG = *I; |
| 446 | assert(LabelAndGotoScopes.count(IG) && |
| 447 | "indirect jump didn't get added to scopes?"); |
| 448 | unsigned IGScope = LabelAndGotoScopes[IG]; |
| 449 | IndirectGotoStmt *&Entry = JumpScopesMap[IGScope]; |
| 450 | if (!Entry) Entry = IG; |
| 451 | } |
| 452 | JumpScopes.reserve(JumpScopesMap.size()); |
| 453 | for (llvm::DenseMap<unsigned, IndirectGotoStmt*>::iterator |
| 454 | I = JumpScopesMap.begin(), E = JumpScopesMap.end(); I != E; ++I) |
| 455 | JumpScopes.push_back(*I); |
| 456 | } |
| 457 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 458 | // Collect a single representative of every scope containing a |
| 459 | // label whose address was taken somewhere in the function. |
| 460 | // For most code bases, there will be only one such scope. |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 461 | llvm::DenseMap<unsigned, LabelDecl*> TargetScopes; |
| 462 | for (llvm::SmallVectorImpl<LabelDecl*>::iterator |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 463 | I = IndirectJumpTargets.begin(), E = IndirectJumpTargets.end(); |
| 464 | I != E; ++I) { |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 465 | LabelDecl *TheLabel = *I; |
| 466 | assert(LabelAndGotoScopes.count(TheLabel->getStmt()) && |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 467 | "Referenced label didn't get added to scopes?"); |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 468 | unsigned LabelScope = LabelAndGotoScopes[TheLabel->getStmt()]; |
| 469 | LabelDecl *&Target = TargetScopes[LabelScope]; |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 470 | if (!Target) Target = TheLabel; |
| 471 | } |
| 472 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 473 | // For each target scope, make sure it's trivially reachable from |
| 474 | // every scope containing a jump site. |
| 475 | // |
| 476 | // A path between scopes always consists of exitting zero or more |
| 477 | // scopes, then entering zero or more scopes. We build a set of |
| 478 | // of scopes S from which the target scope can be trivially |
| 479 | // entered, then verify that every jump scope can be trivially |
| 480 | // exitted to reach a scope in S. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 481 | llvm::BitVector Reachable(Scopes.size(), false); |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 482 | for (llvm::DenseMap<unsigned,LabelDecl*>::iterator |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 483 | TI = TargetScopes.begin(), TE = TargetScopes.end(); TI != TE; ++TI) { |
| 484 | unsigned TargetScope = TI->first; |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 485 | LabelDecl *TargetLabel = TI->second; |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 486 | |
| 487 | Reachable.reset(); |
| 488 | |
| 489 | // Mark all the enclosing scopes from which you can safely jump |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 490 | // into the target scope. 'Min' will end up being the index of |
| 491 | // the shallowest such scope. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 492 | unsigned Min = TargetScope; |
| 493 | while (true) { |
| 494 | Reachable.set(Min); |
| 495 | |
| 496 | // Don't go beyond the outermost scope. |
| 497 | if (Min == 0) break; |
| 498 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 499 | // Stop if we can't trivially enter the current scope. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 500 | if (Scopes[Min].InDiag) break; |
| 501 | |
| 502 | Min = Scopes[Min].ParentScope; |
| 503 | } |
| 504 | |
| 505 | // Walk through all the jump sites, checking that they can trivially |
| 506 | // reach this label scope. |
| 507 | for (llvm::SmallVectorImpl<JumpScope>::iterator |
| 508 | I = JumpScopes.begin(), E = JumpScopes.end(); I != E; ++I) { |
| 509 | unsigned Scope = I->first; |
| 510 | |
| 511 | // Walk out the "scope chain" for this scope, looking for a scope |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 512 | // we've marked reachable. For well-formed code this amortizes |
| 513 | // to O(JumpScopes.size() / Scopes.size()): we only iterate |
| 514 | // when we see something unmarked, and in well-formed code we |
| 515 | // mark everything we iterate past. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 516 | bool IsReachable = false; |
| 517 | while (true) { |
| 518 | if (Reachable.test(Scope)) { |
| 519 | // If we find something reachable, mark all the scopes we just |
| 520 | // walked through as reachable. |
| 521 | for (unsigned S = I->first; S != Scope; S = Scopes[S].ParentScope) |
| 522 | Reachable.set(S); |
| 523 | IsReachable = true; |
| 524 | break; |
| 525 | } |
| 526 | |
| 527 | // Don't walk out if we've reached the top-level scope or we've |
| 528 | // gotten shallower than the shallowest reachable scope. |
| 529 | if (Scope == 0 || Scope < Min) break; |
| 530 | |
| 531 | // Don't walk out through an out-diagnostic. |
| 532 | if (Scopes[Scope].OutDiag) break; |
| 533 | |
| 534 | Scope = Scopes[Scope].ParentScope; |
| 535 | } |
| 536 | |
| 537 | // Only diagnose if we didn't find something. |
| 538 | if (IsReachable) continue; |
| 539 | |
| 540 | DiagnoseIndirectJump(I->second, I->first, TargetLabel, TargetScope); |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 545 | /// Diagnose an indirect jump which is known to cross scopes. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 546 | void JumpScopeChecker::DiagnoseIndirectJump(IndirectGotoStmt *Jump, |
| 547 | unsigned JumpScope, |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 548 | LabelDecl *Target, |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 549 | unsigned TargetScope) { |
| 550 | assert(JumpScope != TargetScope); |
| 551 | |
John McCall | 95c225d | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 552 | S.Diag(Jump->getGotoLoc(), diag::err_indirect_goto_in_protected_scope); |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 553 | S.Diag(Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target); |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 554 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 555 | unsigned Common = GetDeepestCommonScope(JumpScope, TargetScope); |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 556 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 557 | // Walk out the scope chain until we reach the common ancestor. |
| 558 | for (unsigned I = JumpScope; I != Common; I = Scopes[I].ParentScope) |
| 559 | if (Scopes[I].OutDiag) |
| 560 | S.Diag(Scopes[I].Loc, Scopes[I].OutDiag); |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 561 | |
| 562 | // Now walk into the scopes containing the label whose address was taken. |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 563 | for (unsigned I = TargetScope; I != Common; I = Scopes[I].ParentScope) |
| 564 | if (Scopes[I].InDiag) |
| 565 | S.Diag(Scopes[I].Loc, Scopes[I].InDiag); |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 568 | /// CheckJump - Validate that the specified jump statement is valid: that it is |
| 569 | /// jumping within or out of its current scope, not into a deeper one. |
| 570 | void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, |
| 571 | SourceLocation DiagLoc, unsigned JumpDiag) { |
| 572 | assert(LabelAndGotoScopes.count(From) && "Jump didn't get added to scopes?"); |
| 573 | unsigned FromScope = LabelAndGotoScopes[From]; |
| 574 | |
| 575 | assert(LabelAndGotoScopes.count(To) && "Jump didn't get added to scopes?"); |
| 576 | unsigned ToScope = LabelAndGotoScopes[To]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 577 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 578 | // Common case: exactly the same scope, which is fine. |
| 579 | if (FromScope == ToScope) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 580 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 581 | unsigned CommonScope = GetDeepestCommonScope(FromScope, ToScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 582 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 583 | // It's okay to jump out from a nested scope. |
| 584 | if (CommonScope == ToScope) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 585 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 586 | // Pull out (and reverse) any scopes we might need to diagnose skipping. |
| 587 | llvm::SmallVector<unsigned, 10> ToScopes; |
| 588 | for (unsigned I = ToScope; I != CommonScope; I = Scopes[I].ParentScope) |
| 589 | if (Scopes[I].InDiag) |
| 590 | ToScopes.push_back(I); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 591 | |
John McCall | 5e2a7ac | 2010-05-12 02:37:54 +0000 | [diff] [blame] | 592 | // If the only scopes present are cleanup scopes, we're okay. |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 593 | if (ToScopes.empty()) return; |
| 594 | |
| 595 | S.Diag(DiagLoc, JumpDiag); |
| 596 | |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 597 | // Emit diagnostics for whatever is left in ToScopes. |
| 598 | for (unsigned i = 0, e = ToScopes.size(); i != e; ++i) |
John McCall | ddb0b4d | 2010-05-12 00:58:13 +0000 | [diff] [blame] | 599 | S.Diag(Scopes[ToScopes[i]].Loc, Scopes[ToScopes[i]].InDiag); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | void Sema::DiagnoseInvalidJumps(Stmt *Body) { |
Douglas Gregor | 6490ae5 | 2009-11-17 06:14:37 +0000 | [diff] [blame] | 603 | (void)JumpScopeChecker(Body, *this); |
Chris Lattner | 5af280c | 2009-04-19 04:46:21 +0000 | [diff] [blame] | 604 | } |