Coverage Report

Created: 2020-02-15 09:57

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Sema/JumpDiagnostics.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- JumpDiagnostics.cpp - Protected scope jump analysis ------*- C++ -*-=//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements the JumpScopeChecker class, which is used to diagnose
10
// jumps that enter a protected scope in an invalid way.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/Sema/SemaInternal.h"
15
#include "clang/AST/DeclCXX.h"
16
#include "clang/AST/Expr.h"
17
#include "clang/AST/ExprCXX.h"
18
#include "clang/AST/StmtCXX.h"
19
#include "clang/AST/StmtObjC.h"
20
#include "llvm/ADT/BitVector.h"
21
using namespace clang;
22
23
namespace {
24
25
/// JumpScopeChecker - This object is used by Sema to diagnose invalid jumps
26
/// into VLA and other protected scopes.  For example, this rejects:
27
///    goto L;
28
///    int a[n];
29
///  L:
30
///
31
class JumpScopeChecker {
32
  Sema &S;
33
34
  /// Permissive - True when recovering from errors, in which case precautions
35
  /// are taken to handle incomplete scope information.
36
  const bool Permissive;
37
38
  /// GotoScope - This is a record that we use to keep track of all of the
39
  /// scopes that are introduced by VLAs and other things that scope jumps like
40
  /// gotos.  This scope tree has nothing to do with the source scope tree,
41
  /// because you can have multiple VLA scopes per compound statement, and most
42
  /// compound statements don't introduce any scopes.
43
  struct GotoScope {
44
    /// ParentScope - The index in ScopeMap of the parent scope.  This is 0 for
45
    /// the parent scope is the function body.
46
    unsigned ParentScope;
47
48
    /// InDiag - The note to emit if there is a jump into this scope.
49
    unsigned InDiag;
50
51
    /// OutDiag - The note to emit if there is an indirect jump out
52
    /// of this scope.  Direct jumps always clean up their current scope
53
    /// in an orderly way.
54
    unsigned OutDiag;
55
56
    /// Loc - Location to emit the diagnostic.
57
    SourceLocation Loc;
58
59
    GotoScope(unsigned parentScope, unsigned InDiag, unsigned OutDiag,
60
              SourceLocation L)
61
37.4k
      : ParentScope(parentScope), InDiag(InDiag), OutDiag(OutDiag), Loc(L) {}
62
  };
63
64
  SmallVector<GotoScope, 48> Scopes;
65
  llvm::DenseMap<Stmt*, unsigned> LabelAndGotoScopes;
66
  SmallVector<Stmt*, 16> Jumps;
67
68
  SmallVector<Stmt*, 4> IndirectJumps;
69
  SmallVector<Stmt*, 4> AsmJumps;
70
  SmallVector<LabelDecl*, 4> IndirectJumpTargets;
71
  SmallVector<LabelDecl*, 4> AsmJumpTargets;
72
public:
73
  JumpScopeChecker(Stmt *Body, Sema &S);
74
private:
75
  void BuildScopeInformation(Decl *D, unsigned &ParentScope);
76
  void BuildScopeInformation(VarDecl *D, const BlockDecl *BDecl,
77
                             unsigned &ParentScope);
78
  void BuildScopeInformation(Stmt *S, unsigned &origParentScope);
79
80
  void VerifyJumps();
81
  void VerifyIndirectOrAsmJumps(bool IsAsmGoto);
82
  void NoteJumpIntoScopes(ArrayRef<unsigned> ToScopes);
83
  void DiagnoseIndirectOrAsmJump(Stmt *IG, unsigned IGScope, LabelDecl *Target,
84
                                 unsigned TargetScope);
85
  void CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
86
                 unsigned JumpDiag, unsigned JumpDiagWarning,
87
                 unsigned JumpDiagCXX98Compat);
88
  void CheckGotoStmt(GotoStmt *GS);
89
90
  unsigned GetDeepestCommonScope(unsigned A, unsigned B);
91
};
92
} // end anonymous namespace
93
94
65.6k
#define CHECK_PERMISSIVE(x) (assert(Permissive || !(x)), (Permissive && 
(x)823
))
95
96
JumpScopeChecker::JumpScopeChecker(Stmt *Body, Sema &s)
97
5.57k
    : S(s), Permissive(s.hasAnyUnrecoverableErrorsInThisFunction()) {
98
5.57k
  // Add a scope entry for function scope.
99
5.57k
  Scopes.push_back(GotoScope(~0U, ~0U, ~0U, SourceLocation()));
100
5.57k
101
5.57k
  // Build information for the top level compound statement, so that we have a
102
5.57k
  // defined scope record for every "goto" and label.
103
5.57k
  unsigned BodyParentScope = 0;
104
5.57k
  BuildScopeInformation(Body, BodyParentScope);
105
5.57k
106
5.57k
  // Check that all jumps we saw are kosher.
107
5.57k
  VerifyJumps();
108
5.57k
  VerifyIndirectOrAsmJumps(false);
109
5.57k
  VerifyIndirectOrAsmJumps(true);
110
5.57k
}
111
112
/// GetDeepestCommonScope - Finds the innermost scope enclosing the
113
/// two scopes.
114
1.53k
unsigned JumpScopeChecker::GetDeepestCommonScope(unsigned A, unsigned B) {
115
6.67k
  while (A != B) {
116
5.14k
    // Inner scopes are created after outer scopes and therefore have
117
5.14k
    // higher indices.
118
5.14k
    if (A < B) {
119
244
      assert(Scopes[B].ParentScope < B);
120
244
      B = Scopes[B].ParentScope;
121
4.89k
    } else {
122
4.89k
      assert(Scopes[A].ParentScope < A);
123
4.89k
      A = Scopes[A].ParentScope;
124
4.89k
    }
125
5.14k
  }
126
1.53k
  return A;
127
1.53k
}
128
129
typedef std::pair<unsigned,unsigned> ScopePair;
130
131
/// GetDiagForGotoScopeDecl - If this decl induces a new goto scope, return a
132
/// diagnostic that should be emitted if control goes over it. If not, return 0.
133
39.6k
static ScopePair GetDiagForGotoScopeDecl(Sema &S, const Decl *D) {
134
39.6k
  if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
135
35.2k
    unsigned InDiag = 0;
136
35.2k
    unsigned OutDiag = 0;
137
35.2k
138
35.2k
    if (VD->getType()->isVariablyModifiedType())
139
32
      InDiag = diag::note_protected_by_vla;
140
35.2k
141
35.2k
    if (VD->hasAttr<BlocksAttr>())
142
2
      return ScopePair(diag::note_protected_by___block,
143
2
                       diag::note_exits___block);
144
35.2k
145
35.2k
    if (VD->hasAttr<CleanupAttr>())
146
1
      return ScopePair(diag::note_protected_by_cleanup,
147
1
                       diag::note_exits_cleanup);
148
35.2k
149
35.2k
    if (VD->hasLocalStorage()) {
150
34.8k
      switch (VD->getType().isDestructedType()) {
151
22
      case QualType::DK_objc_strong_lifetime:
152
22
        return ScopePair(diag::note_protected_by_objc_strong_init,
153
22
                         diag::note_exits_objc_strong);
154
0
155
5
      case QualType::DK_objc_weak_lifetime:
156
5
        return ScopePair(diag::note_protected_by_objc_weak_init,
157
5
                         diag::note_exits_objc_weak);
158
0
159
4
      case QualType::DK_nontrivial_c_struct:
160
4
        return ScopePair(diag::note_protected_by_non_trivial_c_struct_init,
161
4
                         diag::note_exits_dtor);
162
0
163
589
      case QualType::DK_cxx_destructor:
164
589
        OutDiag = diag::note_exits_dtor;
165
589
        break;
166
0
167
34.2k
      case QualType::DK_none:
168
34.2k
        break;
169
35.2k
      }
170
35.2k
    }
171
35.2k
172
35.2k
    const Expr *Init = VD->getInit();
173
35.2k
    if (S.Context.getLangOpts().CPlusPlus && 
VD->hasLocalStorage()35.0k
&&
Init34.5k
) {
174
31.4k
      // C++11 [stmt.dcl]p3:
175
31.4k
      //   A program that jumps from a point where a variable with automatic
176
31.4k
      //   storage duration is not in scope to a point where it is in scope
177
31.4k
      //   is ill-formed unless the variable has scalar type, class type with
178
31.4k
      //   a trivial default constructor and a trivial destructor, a
179
31.4k
      //   cv-qualified version of one of these types, or an array of one of
180
31.4k
      //   the preceding types and is declared without an initializer.
181
31.4k
182
31.4k
      // C++03 [stmt.dcl.p3:
183
31.4k
      //   A program that jumps from a point where a local variable
184
31.4k
      //   with automatic storage duration is not in scope to a point
185
31.4k
      //   where it is in scope is ill-formed unless the variable has
186
31.4k
      //   POD type and is declared without an initializer.
187
31.4k
188
31.4k
      InDiag = diag::note_protected_by_variable_init;
189
31.4k
190
31.4k
      // For a variable of (array of) class type declared without an
191
31.4k
      // initializer, we will have call-style initialization and the initializer
192
31.4k
      // will be the CXXConstructExpr with no intervening nodes.
193
31.4k
      if (const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(Init)) {
194
2.32k
        const CXXConstructorDecl *Ctor = CCE->getConstructor();
195
2.32k
        if (Ctor->isTrivial() && 
Ctor->isDefaultConstructor()360
&&
196
2.32k
            
VD->getInitStyle() == VarDecl::CallInit245
) {
197
234
          if (OutDiag)
198
79
            InDiag = diag::note_protected_by_variable_nontriv_destructor;
199
155
          else if (!Ctor->getParent()->isPOD())
200
21
            InDiag = diag::note_protected_by_variable_non_pod;
201
134
          else
202
134
            InDiag = 0;
203
234
        }
204
2.32k
      }
205
31.4k
    }
206
35.2k
207
35.2k
    return ScopePair(InDiag, OutDiag);
208
35.2k
  }
209
4.34k
210
4.34k
  if (const TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
211
3.94k
    if (TD->getUnderlyingType()->isVariablyModifiedType())
212
4
      return ScopePair(isa<TypedefDecl>(TD)
213
4
                           ? 
diag::note_protected_by_vla_typedef3
214
4
                           : 
diag::note_protected_by_vla_type_alias1
,
215
4
                       0);
216
4.34k
  }
217
4.34k
218
4.34k
  return ScopePair(0U, 0U);
219
4.34k
}
220
221
/// Build scope information for a declaration that is part of a DeclStmt.
222
39.6k
void JumpScopeChecker::BuildScopeInformation(Decl *D, unsigned &ParentScope) {
223
39.6k
  // If this decl causes a new scope, push and switch to it.
224
39.6k
  std::pair<unsigned,unsigned> Diags = GetDiagForGotoScopeDecl(S, D);
225
39.6k
  if (Diags.first || 
Diags.second8.24k
) {
226
31.3k
    Scopes.push_back(GotoScope(ParentScope, Diags.first, Diags.second,
227
31.3k
                               D->getLocation()));
228
31.3k
    ParentScope = Scopes.size()-1;
229
31.3k
  }
230
39.6k
231
39.6k
  // If the decl has an initializer, walk it with the potentially new
232
39.6k
  // scope we just installed.
233
39.6k
  if (VarDecl *VD = dyn_cast<VarDecl>(D))
234
35.2k
    if (Expr *Init = VD->getInit())
235
32.0k
      BuildScopeInformation(Init, ParentScope);
236
39.6k
}
237
238
/// Build scope information for a captured block literal variables.
239
void JumpScopeChecker::BuildScopeInformation(VarDecl *D,
240
                                             const BlockDecl *BDecl,
241
109
                                             unsigned &ParentScope) {
242
109
  // exclude captured __block variables; there's no destructor
243
109
  // associated with the block literal for them.
244
109
  if (D->hasAttr<BlocksAttr>())
245
2
    return;
246
107
  QualType T = D->getType();
247
107
  QualType::DestructionKind destructKind = T.isDestructedType();
248
107
  if (destructKind != QualType::DK_none) {
249
17
    std::pair<unsigned,unsigned> Diags;
250
17
    switch (destructKind) {
251
1
      case QualType::DK_cxx_destructor:
252
1
        Diags = ScopePair(diag::note_enters_block_captures_cxx_obj,
253
1
                          diag::note_exits_block_captures_cxx_obj);
254
1
        break;
255
14
      case QualType::DK_objc_strong_lifetime:
256
14
        Diags = ScopePair(diag::note_enters_block_captures_strong,
257
14
                          diag::note_exits_block_captures_strong);
258
14
        break;
259
0
      case QualType::DK_objc_weak_lifetime:
260
0
        Diags = ScopePair(diag::note_enters_block_captures_weak,
261
0
                          diag::note_exits_block_captures_weak);
262
0
        break;
263
2
      case QualType::DK_nontrivial_c_struct:
264
2
        Diags = ScopePair(diag::note_enters_block_captures_non_trivial_c_struct,
265
2
                          diag::note_exits_block_captures_non_trivial_c_struct);
266
2
        break;
267
0
      case QualType::DK_none:
268
0
        llvm_unreachable("non-lifetime captured variable");
269
17
    }
270
17
    SourceLocation Loc = D->getLocation();
271
17
    if (Loc.isInvalid())
272
9
      Loc = BDecl->getLocation();
273
17
    Scopes.push_back(GotoScope(ParentScope,
274
17
                               Diags.first, Diags.second, Loc));
275
17
    ParentScope = Scopes.size()-1;
276
17
  }
277
107
}
278
279
/// BuildScopeInformation - The statements from CI to CE are known to form a
280
/// coherent VLA scope with a specified parent node.  Walk through the
281
/// statements, adding any labels or gotos to LabelAndGotoScopes and recursively
282
/// walking the AST as needed.
283
void JumpScopeChecker::BuildScopeInformation(Stmt *S,
284
1.11M
                                             unsigned &origParentScope) {
285
1.11M
  // If this is a statement, rather than an expression, scopes within it don't
286
1.11M
  // propagate out into the enclosing scope.  Otherwise we have to worry
287
1.11M
  // about block literals, which have the lifetime of their enclosing statement.
288
1.11M
  unsigned independentParentScope = origParentScope;
289
1.11M
  unsigned &ParentScope = ((isa<Expr>(S) && 
!isa<StmtExpr>(S)927k
)
290
1.11M
                            ? 
origParentScope927k
:
independentParentScope185k
);
291
1.11M
292
1.11M
  unsigned StmtsToSkip = 0u;
293
1.11M
294
1.11M
  // If we found a label, remember that it is in ParentScope scope.
295
1.11M
  switch (S->getStmtClass()) {
296
172
  case Stmt::AddrLabelExprClass:
297
172
    IndirectJumpTargets.push_back(cast<AddrLabelExpr>(S)->getLabel());
298
172
    break;
299
0
300
4
  case Stmt::ObjCForCollectionStmtClass: {
301
4
    auto *CS = cast<ObjCForCollectionStmt>(S);
302
4
    unsigned Diag = diag::note_protected_by_objc_fast_enumeration;
303
4
    unsigned NewParentScope = Scopes.size();
304
4
    Scopes.push_back(GotoScope(ParentScope, Diag, 0, S->getBeginLoc()));
305
4
    BuildScopeInformation(CS->getBody(), NewParentScope);
306
4
    return;
307
0
  }
308
0
309
112
  case Stmt::IndirectGotoStmtClass:
310
112
    // "goto *&&lbl;" is a special case which we treat as equivalent
311
112
    // to a normal goto.  In addition, we don't calculate scope in the
312
112
    // operand (to avoid recording the address-of-label use), which
313
112
    // works only because of the restricted set of expressions which
314
112
    // we detect as constant targets.
315
112
    if (cast<IndirectGotoStmt>(S)->getConstantTarget()) {
316
7
      LabelAndGotoScopes[S] = ParentScope;
317
7
      Jumps.push_back(S);
318
7
      return;
319
7
    }
320
105
321
105
    LabelAndGotoScopes[S] = ParentScope;
322
105
    IndirectJumps.push_back(S);
323
105
    break;
324
105
325
4.43k
  case Stmt::SwitchStmtClass:
326
4.43k
    // Evaluate the C++17 init stmt and condition variable
327
4.43k
    // before entering the scope of the switch statement.
328
4.43k
    if (Stmt *Init = cast<SwitchStmt>(S)->getInit()) {
329
63
      BuildScopeInformation(Init, ParentScope);
330
63
      ++StmtsToSkip;
331
63
    }
332
4.43k
    if (VarDecl *Var = cast<SwitchStmt>(S)->getConditionVariable()) {
333
53
      BuildScopeInformation(Var, ParentScope);
334
53
      ++StmtsToSkip;
335
53
    }
336
4.43k
    LLVM_FALLTHROUGH;
337
4.43k
338
7.94k
  case Stmt::GotoStmtClass:
339
7.94k
    // Remember both what scope a goto is in as well as the fact that we have
340
7.94k
    // it.  This makes the second scan not have to walk the AST again.
341
7.94k
    LabelAndGotoScopes[S] = ParentScope;
342
7.94k
    Jumps.push_back(S);
343
7.94k
    break;
344
4.43k
345
4.43k
  case Stmt::GCCAsmStmtClass:
346
28
    if (auto *GS = dyn_cast<GCCAsmStmt>(S))
347
28
      if (GS->isAsmGoto()) {
348
17
        // Remember both what scope a goto is in as well as the fact that we
349
17
        // have it.  This makes the second scan not have to walk the AST again.
350
17
        LabelAndGotoScopes[S] = ParentScope;
351
17
        AsmJumps.push_back(GS);
352
17
        for (auto *E : GS->labels())
353
19
          AsmJumpTargets.push_back(E->getLabel());
354
17
      }
355
28
    break;
356
4.43k
357
35.8k
  case Stmt::IfStmtClass: {
358
35.8k
    IfStmt *IS = cast<IfStmt>(S);
359
35.8k
    if (!(IS->isConstexpr() || 
IS->isObjCAvailabilityCheck()35.8k
))
360
35.8k
      break;
361
16
362
16
    unsigned Diag = IS->isConstexpr() ? 
diag::note_protected_by_constexpr_if14
363
16
                                      : 
diag::note_protected_by_if_available2
;
364
16
365
16
    if (VarDecl *Var = IS->getConditionVariable())
366
0
      BuildScopeInformation(Var, ParentScope);
367
16
368
16
    // Cannot jump into the middle of the condition.
369
16
    unsigned NewParentScope = Scopes.size();
370
16
    Scopes.push_back(GotoScope(ParentScope, Diag, 0, IS->getBeginLoc()));
371
16
    BuildScopeInformation(IS->getCond(), NewParentScope);
372
16
373
16
    // Jumps into either arm of an 'if constexpr' are not allowed.
374
16
    NewParentScope = Scopes.size();
375
16
    Scopes.push_back(GotoScope(ParentScope, Diag, 0, IS->getBeginLoc()));
376
16
    BuildScopeInformation(IS->getThen(), NewParentScope);
377
16
    if (Stmt *Else = IS->getElse()) {
378
9
      NewParentScope = Scopes.size();
379
9
      Scopes.push_back(GotoScope(ParentScope, Diag, 0, IS->getBeginLoc()));
380
9
      BuildScopeInformation(Else, NewParentScope);
381
9
    }
382
16
    return;
383
16
  }
384
16
385
130
  case Stmt::CXXTryStmtClass: {
386
130
    CXXTryStmt *TS = cast<CXXTryStmt>(S);
387
130
    {
388
130
      unsigned NewParentScope = Scopes.size();
389
130
      Scopes.push_back(GotoScope(ParentScope,
390
130
                                 diag::note_protected_by_cxx_try,
391
130
                                 diag::note_exits_cxx_try,
392
130
                                 TS->getSourceRange().getBegin()));
393
130
      if (Stmt *TryBlock = TS->getTryBlock())
394
130
        BuildScopeInformation(TryBlock, NewParentScope);
395
130
    }
396
130
397
130
    // Jump from the catch into the try is not allowed either.
398
264
    for (unsigned I = 0, E = TS->getNumHandlers(); I != E; 
++I134
) {
399
134
      CXXCatchStmt *CS = TS->getHandler(I);
400
134
      unsigned NewParentScope = Scopes.size();
401
134
      Scopes.push_back(GotoScope(ParentScope,
402
134
                                 diag::note_protected_by_cxx_catch,
403
134
                                 diag::note_exits_cxx_catch,
404
134
                                 CS->getSourceRange().getBegin()));
405
134
      BuildScopeInformation(CS->getHandlerBlock(), NewParentScope);
406
134
    }
407
130
    return;
408
16
  }
409
16
410
77
  case Stmt::SEHTryStmtClass: {
411
77
    SEHTryStmt *TS = cast<SEHTryStmt>(S);
412
77
    {
413
77
      unsigned NewParentScope = Scopes.size();
414
77
      Scopes.push_back(GotoScope(ParentScope,
415
77
                                 diag::note_protected_by_seh_try,
416
77
                                 diag::note_exits_seh_try,
417
77
                                 TS->getSourceRange().getBegin()));
418
77
      if (Stmt *TryBlock = TS->getTryBlock())
419
77
        BuildScopeInformation(TryBlock, NewParentScope);
420
77
    }
421
77
422
77
    // Jump from __except or __finally into the __try are not allowed either.
423
77
    if (SEHExceptStmt *Except = TS->getExceptHandler()) {
424
24
      unsigned NewParentScope = Scopes.size();
425
24
      Scopes.push_back(GotoScope(ParentScope,
426
24
                                 diag::note_protected_by_seh_except,
427
24
                                 diag::note_exits_seh_except,
428
24
                                 Except->getSourceRange().getBegin()));
429
24
      BuildScopeInformation(Except->getBlock(), NewParentScope);
430
53
    } else if (SEHFinallyStmt *Finally = TS->getFinallyHandler()) {
431
53
      unsigned NewParentScope = Scopes.size();
432
53
      Scopes.push_back(GotoScope(ParentScope,
433
53
                                 diag::note_protected_by_seh_finally,
434
53
                                 diag::note_exits_seh_finally,
435
53
                                 Finally->getSourceRange().getBegin()));
436
53
      BuildScopeInformation(Finally->getBlock(), NewParentScope);
437
53
    }
438
77
439
77
    return;
440
16
  }
441
16
442
39.4k
  case Stmt::DeclStmtClass: {
443
39.4k
    // If this is a declstmt with a VLA definition, it defines a scope from here
444
39.4k
    // to the end of the containing context.
445
39.4k
    DeclStmt *DS = cast<DeclStmt>(S);
446
39.4k
    // The decl statement creates a scope if any of the decls in it are VLAs
447
39.4k
    // or have the cleanup attribute.
448
39.4k
    for (auto *I : DS->decls())
449
39.5k
      BuildScopeInformation(I, origParentScope);
450
39.4k
    return;
451
16
  }
452
16
453
16
  case Stmt::ObjCAtTryStmtClass: {
454
7
    // Disallow jumps into any part of an @try statement by pushing a scope and
455
7
    // walking all sub-stmts in that scope.
456
7
    ObjCAtTryStmt *AT = cast<ObjCAtTryStmt>(S);
457
7
    // Recursively walk the AST for the @try part.
458
7
    {
459
7
      unsigned NewParentScope = Scopes.size();
460
7
      Scopes.push_back(GotoScope(ParentScope,
461
7
                                 diag::note_protected_by_objc_try,
462
7
                                 diag::note_exits_objc_try,
463
7
                                 AT->getAtTryLoc()));
464
7
      if (Stmt *TryPart = AT->getTryBody())
465
7
        BuildScopeInformation(TryPart, NewParentScope);
466
7
    }
467
7
468
7
    // Jump from the catch to the finally or try is not valid.
469
18
    for (unsigned I = 0, N = AT->getNumCatchStmts(); I != N; 
++I11
) {
470
11
      ObjCAtCatchStmt *AC = AT->getCatchStmt(I);
471
11
      unsigned NewParentScope = Scopes.size();
472
11
      Scopes.push_back(GotoScope(ParentScope,
473
11
                                 diag::note_protected_by_objc_catch,
474
11
                                 diag::note_exits_objc_catch,
475
11
                                 AC->getAtCatchLoc()));
476
11
      // @catches are nested and it isn't
477
11
      BuildScopeInformation(AC->getCatchBody(), NewParentScope);
478
11
    }
479
7
480
7
    // Jump from the finally to the try or catch is not valid.
481
7
    if (ObjCAtFinallyStmt *AF = AT->getFinallyStmt()) {
482
4
      unsigned NewParentScope = Scopes.size();
483
4
      Scopes.push_back(GotoScope(ParentScope,
484
4
                                 diag::note_protected_by_objc_finally,
485
4
                                 diag::note_exits_objc_finally,
486
4
                                 AF->getAtFinallyLoc()));
487
4
      BuildScopeInformation(AF, NewParentScope);
488
4
    }
489
7
490
7
    return;
491
16
  }
492
16
493
16
  case Stmt::ObjCAtSynchronizedStmtClass: {
494
1
    // Disallow jumps into the protected statement of an @synchronized, but
495
1
    // allow jumps into the object expression it protects.
496
1
    ObjCAtSynchronizedStmt *AS = cast<ObjCAtSynchronizedStmt>(S);
497
1
    // Recursively walk the AST for the @synchronized object expr, it is
498
1
    // evaluated in the normal scope.
499
1
    BuildScopeInformation(AS->getSynchExpr(), ParentScope);
500
1
501
1
    // Recursively walk the AST for the @synchronized part, protected by a new
502
1
    // scope.
503
1
    unsigned NewParentScope = Scopes.size();
504
1
    Scopes.push_back(GotoScope(ParentScope,
505
1
                               diag::note_protected_by_objc_synchronized,
506
1
                               diag::note_exits_objc_synchronized,
507
1
                               AS->getAtSynchronizedLoc()));
508
1
    BuildScopeInformation(AS->getSynchBody(), NewParentScope);
509
1
    return;
510
16
  }
511
16
512
16
  case Stmt::ObjCAutoreleasePoolStmtClass: {
513
2
    // Disallow jumps into the protected statement of an @autoreleasepool.
514
2
    ObjCAutoreleasePoolStmt *AS = cast<ObjCAutoreleasePoolStmt>(S);
515
2
    // Recursively walk the AST for the @autoreleasepool part, protected by a
516
2
    // new scope.
517
2
    unsigned NewParentScope = Scopes.size();
518
2
    Scopes.push_back(GotoScope(ParentScope,
519
2
                               diag::note_protected_by_objc_autoreleasepool,
520
2
                               diag::note_exits_objc_autoreleasepool,
521
2
                               AS->getAtLoc()));
522
2
    BuildScopeInformation(AS->getSubStmt(), NewParentScope);
523
2
    return;
524
16
  }
525
16
526
1.49k
  case Stmt::ExprWithCleanupsClass: {
527
1.49k
    // Disallow jumps past full-expressions that use blocks with
528
1.49k
    // non-trivial cleanups of their captures.  This is theoretically
529
1.49k
    // implementable but a lot of work which we haven't felt up to doing.
530
1.49k
    ExprWithCleanups *EWC = cast<ExprWithCleanups>(S);
531
1.60k
    for (unsigned i = 0, e = EWC->getNumObjects(); i != e; 
++i109
) {
532
109
      const BlockDecl *BDecl = EWC->getObject(i);
533
109
      for (const auto &CI : BDecl->captures()) {
534
109
        VarDecl *variable = CI.getVariable();
535
109
        BuildScopeInformation(variable, BDecl, origParentScope);
536
109
      }
537
109
    }
538
1.49k
    break;
539
16
  }
540
16
541
1.09k
  case Stmt::MaterializeTemporaryExprClass: {
542
1.09k
    // Disallow jumps out of scopes containing temporaries lifetime-extended to
543
1.09k
    // automatic storage duration.
544
1.09k
    MaterializeTemporaryExpr *MTE = cast<MaterializeTemporaryExpr>(S);
545
1.09k
    if (MTE->getStorageDuration() == SD_Automatic) {
546
96
      SmallVector<const Expr *, 4> CommaLHS;
547
96
      SmallVector<SubobjectAdjustment, 4> Adjustments;
548
96
      const Expr *ExtendedObject =
549
96
          MTE->getSubExpr()->skipRValueSubobjectAdjustments(CommaLHS,
550
96
                                                            Adjustments);
551
96
      if (ExtendedObject->getType().isDestructedType()) {
552
11
        Scopes.push_back(GotoScope(ParentScope, 0,
553
11
                                   diag::note_exits_temporary_dtor,
554
11
                                   ExtendedObject->getExprLoc()));
555
11
        origParentScope = Scopes.size()-1;
556
11
      }
557
96
    }
558
1.09k
    break;
559
16
  }
560
16
561
16
  case Stmt::CaseStmtClass:
562
8
  case Stmt::DefaultStmtClass:
563
8
  case Stmt::LabelStmtClass:
564
8
    LabelAndGotoScopes[S] = ParentScope;
565
8
    break;
566
8
567
1.02M
  default:
568
1.02M
    break;
569
1.07M
  }
570
1.07M
571
1.07M
  
for (Stmt *SubStmt : S->children())1.07M
{
572
1.07M
    if (!SubStmt)
573
3.69k
        continue;
574
1.07M
    if (StmtsToSkip) {
575
116
      --StmtsToSkip;
576
116
      continue;
577
116
    }
578
1.07M
579
1.07M
    // Cases, labels, and defaults aren't "scope parents".  It's also
580
1.07M
    // important to handle these iteratively instead of recursively in
581
1.07M
    // order to avoid blowing out the stack.
582
1.09M
    
while (1.07M
true) {
583
1.09M
      Stmt *Next;
584
1.09M
      if (SwitchCase *SC = dyn_cast<SwitchCase>(SubStmt))
585
19.4k
        Next = SC->getSubStmt();
586
1.07M
      else if (LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt))
587
3.06k
        Next = LS->getSubStmt();
588
1.07M
      else
589
1.07M
        break;
590
22.5k
591
22.5k
      LabelAndGotoScopes[SubStmt] = ParentScope;
592
22.5k
      SubStmt = Next;
593
22.5k
    }
594
1.07M
595
1.07M
    // Recursively walk the AST.
596
1.07M
    BuildScopeInformation(SubStmt, ParentScope);
597
1.07M
  }
598
1.07M
}
599
600
/// VerifyJumps - Verify each element of the Jumps array to see if they are
601
/// valid, emitting diagnostics if not.
602
5.57k
void JumpScopeChecker::VerifyJumps() {
603
13.5k
  while (!Jumps.empty()) {
604
7.95k
    Stmt *Jump = Jumps.pop_back_val();
605
7.95k
606
7.95k
    // With a goto,
607
7.95k
    if (GotoStmt *GS = dyn_cast<GotoStmt>(Jump)) {
608
3.51k
      // The label may not have a statement if it's coming from inline MS ASM.
609
3.51k
      if (GS->getLabel()->getStmt()) {
610
3.35k
        CheckJump(GS, GS->getLabel()->getStmt(), GS->getGotoLoc(),
611
3.35k
                  diag::err_goto_into_protected_scope,
612
3.35k
                  diag::ext_goto_into_protected_scope,
613
3.35k
                  diag::warn_cxx98_compat_goto_into_protected_scope);
614
3.35k
      }
615
3.51k
      CheckGotoStmt(GS);
616
3.51k
      continue;
617
3.51k
    }
618
4.44k
619
4.44k
    // We only get indirect gotos here when they have a constant target.
620
4.44k
    if (IndirectGotoStmt *IGS = dyn_cast<IndirectGotoStmt>(Jump)) {
621
7
      LabelDecl *Target = IGS->getConstantTarget();
622
7
      CheckJump(IGS, Target->getStmt(), IGS->getGotoLoc(),
623
7
                diag::err_goto_into_protected_scope,
624
7
                diag::ext_goto_into_protected_scope,
625
7
                diag::warn_cxx98_compat_goto_into_protected_scope);
626
7
      continue;
627
7
    }
628
4.43k
629
4.43k
    SwitchStmt *SS = cast<SwitchStmt>(Jump);
630
23.9k
    for (SwitchCase *SC = SS->getSwitchCaseList(); SC;
631
19.4k
         SC = SC->getNextSwitchCase()) {
632
19.4k
      if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(SC)))
633
19.4k
        
continue0
;
634
19.4k
      SourceLocation Loc;
635
19.4k
      if (CaseStmt *CS = dyn_cast<CaseStmt>(SC))
636
18.2k
        Loc = CS->getBeginLoc();
637
1.23k
      else if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC))
638
1.23k
        Loc = DS->getBeginLoc();
639
0
      else
640
0
        Loc = SC->getBeginLoc();
641
19.4k
      CheckJump(SS, SC, Loc, diag::err_switch_into_protected_scope, 0,
642
19.4k
                diag::warn_cxx98_compat_switch_into_protected_scope);
643
19.4k
    }
644
4.43k
  }
645
5.57k
}
646
647
/// VerifyIndirectOrAsmJumps - Verify whether any possible indirect goto or
648
/// asm goto jump might cross a protection boundary.  Unlike direct jumps,
649
/// indirect or asm goto jumps count cleanups as protection boundaries:
650
/// since there's no way to know where the jump is going, we can't implicitly
651
/// run the right cleanups the way we can with direct jumps.
652
/// Thus, an indirect/asm jump is "trivial" if it bypasses no
653
/// initializations and no teardowns.  More formally, an indirect/asm jump
654
/// from A to B is trivial if the path out from A to DCA(A,B) is
655
/// trivial and the path in from DCA(A,B) to B is trivial, where
656
/// DCA(A,B) is the deepest common ancestor of A and B.
657
/// Jump-triviality is transitive but asymmetric.
658
///
659
/// A path in is trivial if none of the entered scopes have an InDiag.
660
/// A path out is trivial is none of the exited scopes have an OutDiag.
661
///
662
/// Under these definitions, this function checks that the indirect
663
/// jump between A and B is trivial for every indirect goto statement A
664
/// and every label B whose address was taken in the function.
665
11.1k
void JumpScopeChecker::VerifyIndirectOrAsmJumps(bool IsAsmGoto) {
666
11.1k
  SmallVector<Stmt*, 4> GotoJumps = IsAsmGoto ? 
AsmJumps5.57k
:
IndirectJumps5.57k
;
667
11.1k
  if (GotoJumps.empty())
668
11.0k
    return;
669
100
  SmallVector<LabelDecl *, 4> JumpTargets =
670
100
      IsAsmGoto ? 
AsmJumpTargets17
:
IndirectJumpTargets83
;
671
100
  // If there aren't any address-of-label expressions in this function,
672
100
  // complain about the first indirect goto.
673
100
  if (JumpTargets.empty()) {
674
0
    assert(!IsAsmGoto &&"only indirect goto can get here");
675
0
    S.Diag(GotoJumps[0]->getBeginLoc(),
676
0
           diag::err_indirect_goto_without_addrlabel);
677
0
    return;
678
0
  }
679
100
  // Collect a single representative of every scope containing an
680
100
  // indirect or asm goto.  For most code bases, this substantially cuts
681
100
  // down on the number of jump sites we'll have to consider later.
682
100
  typedef std::pair<unsigned, Stmt*> JumpScope;
683
100
  SmallVector<JumpScope, 32> JumpScopes;
684
100
  {
685
100
    llvm::DenseMap<unsigned, Stmt*> JumpScopesMap;
686
100
    for (SmallVectorImpl<Stmt *>::iterator I = GotoJumps.begin(),
687
100
                                           E = GotoJumps.end();
688
222
         I != E; 
++I122
) {
689
122
      Stmt *IG = *I;
690
122
      if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(IG)))
691
122
        
continue0
;
692
122
      unsigned IGScope = LabelAndGotoScopes[IG];
693
122
      Stmt *&Entry = JumpScopesMap[IGScope];
694
122
      if (!Entry) 
Entry = IG111
;
695
122
    }
696
100
    JumpScopes.reserve(JumpScopesMap.size());
697
100
    for (llvm::DenseMap<unsigned, Stmt *>::iterator I = JumpScopesMap.begin(),
698
100
                                                    E = JumpScopesMap.end();
699
211
         I != E; 
++I111
)
700
111
      JumpScopes.push_back(*I);
701
100
  }
702
100
703
100
  // Collect a single representative of every scope containing a
704
100
  // label whose address was taken somewhere in the function.
705
100
  // For most code bases, there will be only one such scope.
706
100
  llvm::DenseMap<unsigned, LabelDecl*> TargetScopes;
707
100
  for (SmallVectorImpl<LabelDecl *>::iterator I = JumpTargets.begin(),
708
100
                                              E = JumpTargets.end();
709
281
       I != E; 
++I181
) {
710
181
    LabelDecl *TheLabel = *I;
711
181
    if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(TheLabel->getStmt())))
712
181
      
continue0
;
713
181
    unsigned LabelScope = LabelAndGotoScopes[TheLabel->getStmt()];
714
181
    LabelDecl *&Target = TargetScopes[LabelScope];
715
181
    if (!Target) 
Target = TheLabel107
;
716
181
  }
717
100
718
100
  // For each target scope, make sure it's trivially reachable from
719
100
  // every scope containing a jump site.
720
100
  //
721
100
  // A path between scopes always consists of exitting zero or more
722
100
  // scopes, then entering zero or more scopes.  We build a set of
723
100
  // of scopes S from which the target scope can be trivially
724
100
  // entered, then verify that every jump scope can be trivially
725
100
  // exitted to reach a scope in S.
726
100
  llvm::BitVector Reachable(Scopes.size(), false);
727
100
  for (llvm::DenseMap<unsigned,LabelDecl*>::iterator
728
207
         TI = TargetScopes.begin(), TE = TargetScopes.end(); TI != TE; 
++TI107
) {
729
107
    unsigned TargetScope = TI->first;
730
107
    LabelDecl *TargetLabel = TI->second;
731
107
732
107
    Reachable.reset();
733
107
734
107
    // Mark all the enclosing scopes from which you can safely jump
735
107
    // into the target scope.  'Min' will end up being the index of
736
107
    // the shallowest such scope.
737
107
    unsigned Min = TargetScope;
738
107
    while (true) {
739
107
      Reachable.set(Min);
740
107
741
107
      // Don't go beyond the outermost scope.
742
107
      if (Min == 0) 
break71
;
743
36
744
36
      // Stop if we can't trivially enter the current scope.
745
36
      if (Scopes[Min].InDiag) break;
746
0
747
0
      Min = Scopes[Min].ParentScope;
748
0
    }
749
107
750
107
    // Walk through all the jump sites, checking that they can trivially
751
107
    // reach this label scope.
752
107
    for (SmallVectorImpl<JumpScope>::iterator
753
226
           I = JumpScopes.begin(), E = JumpScopes.end(); I != E; 
++I119
) {
754
119
      unsigned Scope = I->first;
755
119
756
119
      // Walk out the "scope chain" for this scope, looking for a scope
757
119
      // we've marked reachable.  For well-formed code this amortizes
758
119
      // to O(JumpScopes.size() / Scopes.size()):  we only iterate
759
119
      // when we see something unmarked, and in well-formed code we
760
119
      // mark everything we iterate past.
761
119
      bool IsReachable = false;
762
139
      while (true) {
763
139
        if (Reachable.test(Scope)) {
764
78
          // If we find something reachable, mark all the scopes we just
765
78
          // walked through as reachable.
766
92
          for (unsigned S = I->first; S != Scope; 
S = Scopes[S].ParentScope14
)
767
14
            Reachable.set(S);
768
78
          IsReachable = true;
769
78
          break;
770
78
        }
771
61
772
61
        // Don't walk out if we've reached the top-level scope or we've
773
61
        // gotten shallower than the shallowest reachable scope.
774
61
        if (Scope == 0 || 
Scope < Min55
)
break13
;
775
48
776
48
        // Don't walk out through an out-diagnostic.
777
48
        if (Scopes[Scope].OutDiag) 
break28
;
778
20
779
20
        Scope = Scopes[Scope].ParentScope;
780
20
      }
781
119
782
119
      // Only diagnose if we didn't find something.
783
119
      if (IsReachable) 
continue78
;
784
41
785
41
      DiagnoseIndirectOrAsmJump(I->second, I->first, TargetLabel, TargetScope);
786
41
    }
787
107
  }
788
100
}
789
790
/// Return true if a particular error+note combination must be downgraded to a
791
/// warning in Microsoft mode.
792
8
static bool IsMicrosoftJumpWarning(unsigned JumpDiag, unsigned InDiagNote) {
793
8
  return (JumpDiag == diag::err_goto_into_protected_scope &&
794
8
         (InDiagNote == diag::note_protected_by_variable_init ||
795
8
          
InDiagNote == diag::note_protected_by_variable_nontriv_destructor4
));
796
8
}
797
798
/// Return true if a particular note should be downgraded to a compatibility
799
/// warning in C++11 mode.
800
238
static bool IsCXX98CompatWarning(Sema &S, unsigned InDiagNote) {
801
238
  return S.getLangOpts().CPlusPlus11 &&
802
238
         
InDiagNote == diag::note_protected_by_variable_non_pod133
;
803
238
}
804
805
/// Produce primary diagnostic for an indirect jump statement.
806
static void DiagnoseIndirectOrAsmJumpStmt(Sema &S, Stmt *Jump,
807
39
                                          LabelDecl *Target, bool &Diagnosed) {
808
39
  if (Diagnosed)
809
1
    return;
810
38
  bool IsAsmGoto = isa<GCCAsmStmt>(Jump);
811
38
  S.Diag(Jump->getBeginLoc(), diag::err_indirect_goto_in_protected_scope)
812
38
      << IsAsmGoto;
813
38
  S.Diag(Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
814
38
      << IsAsmGoto;
815
38
  Diagnosed = true;
816
38
}
817
818
/// Produce note diagnostics for a jump into a protected scope.
819
213
void JumpScopeChecker::NoteJumpIntoScopes(ArrayRef<unsigned> ToScopes) {
820
213
  if (CHECK_PERMISSIVE(ToScopes.empty()))
821
213
    
return0
;
822
447
  
for (unsigned I = 0, E = ToScopes.size(); 213
I != E;
++I234
)
823
234
    if (Scopes[ToScopes[I]].InDiag)
824
234
      S.Diag(Scopes[ToScopes[I]].Loc, Scopes[ToScopes[I]].InDiag);
825
213
}
826
827
/// Diagnose an indirect jump which is known to cross scopes.
828
void JumpScopeChecker::DiagnoseIndirectOrAsmJump(Stmt *Jump, unsigned JumpScope,
829
                                                 LabelDecl *Target,
830
41
                                                 unsigned TargetScope) {
831
41
  if (CHECK_PERMISSIVE(JumpScope == TargetScope))
832
41
    
return0
;
833
41
834
41
  unsigned Common = GetDeepestCommonScope(JumpScope, TargetScope);
835
41
  bool Diagnosed = false;
836
41
837
41
  // Walk out the scope chain until we reach the common ancestor.
838
86
  for (unsigned I = JumpScope; I != Common; 
I = Scopes[I].ParentScope45
)
839
45
    if (Scopes[I].OutDiag) {
840
29
      DiagnoseIndirectOrAsmJumpStmt(S, Jump, Target, Diagnosed);
841
29
      S.Diag(Scopes[I].Loc, Scopes[I].OutDiag);
842
29
    }
843
41
844
41
  SmallVector<unsigned, 10> ToScopesCXX98Compat;
845
41
846
41
  // Now walk into the scopes containing the label whose address was taken.
847
54
  for (unsigned I = TargetScope; I != Common; 
I = Scopes[I].ParentScope13
)
848
13
    if (IsCXX98CompatWarning(S, Scopes[I].InDiag))
849
3
      ToScopesCXX98Compat.push_back(I);
850
10
    else if (Scopes[I].InDiag) {
851
10
      DiagnoseIndirectOrAsmJumpStmt(S, Jump, Target, Diagnosed);
852
10
      S.Diag(Scopes[I].Loc, Scopes[I].InDiag);
853
10
    }
854
41
855
41
  // Diagnose this jump if it would be ill-formed in C++98.
856
41
  if (!Diagnosed && 
!ToScopesCXX98Compat.empty()3
) {
857
3
    bool IsAsmGoto = isa<GCCAsmStmt>(Jump);
858
3
    S.Diag(Jump->getBeginLoc(),
859
3
           diag::warn_cxx98_compat_indirect_goto_in_protected_scope)
860
3
        << IsAsmGoto;
861
3
    S.Diag(Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
862
3
        << IsAsmGoto;
863
3
    NoteJumpIntoScopes(ToScopesCXX98Compat);
864
3
  }
865
41
}
866
867
/// CheckJump - Validate that the specified jump statement is valid: that it is
868
/// jumping within or out of its current scope, not into a deeper one.
869
void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
870
                               unsigned JumpDiagError, unsigned JumpDiagWarning,
871
22.8k
                                 unsigned JumpDiagCXX98Compat) {
872
22.8k
  if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(From)))
873
22.8k
    
return0
;
874
22.8k
  if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(To)))
875
22.8k
    
return0
;
876
22.8k
877
22.8k
  unsigned FromScope = LabelAndGotoScopes[From];
878
22.8k
  unsigned ToScope = LabelAndGotoScopes[To];
879
22.8k
880
22.8k
  // Common case: exactly the same scope, which is fine.
881
22.8k
  if (FromScope == ToScope) 
return21.3k
;
882
1.49k
883
1.49k
  // Warn on gotos out of __finally blocks.
884
1.49k
  if (isa<GotoStmt>(From) || 
isa<IndirectGotoStmt>(From)51
) {
885
1.44k
    // If FromScope > ToScope, FromScope is more nested and the jump goes to a
886
1.44k
    // less nested scope.  Check if it crosses a __finally along the way.
887
6.26k
    for (unsigned I = FromScope; I > ToScope; 
I = Scopes[I].ParentScope4.81k
) {
888
4.82k
      if (Scopes[I].InDiag == diag::note_protected_by_seh_finally) {
889
8
        S.Diag(From->getBeginLoc(), diag::warn_jump_out_of_seh_finally);
890
8
        break;
891
8
      }
892
4.82k
    }
893
1.44k
  }
894
1.49k
895
1.49k
  unsigned CommonScope = GetDeepestCommonScope(FromScope, ToScope);
896
1.49k
897
1.49k
  // It's okay to jump out from a nested scope.
898
1.49k
  if (CommonScope == ToScope) 
return1.28k
;
899
210
900
210
  // Pull out (and reverse) any scopes we might need to diagnose skipping.
901
210
  SmallVector<unsigned, 10> ToScopesCXX98Compat;
902
210
  SmallVector<unsigned, 10> ToScopesError;
903
210
  SmallVector<unsigned, 10> ToScopesWarning;
904
441
  for (unsigned I = ToScope; I != CommonScope; 
I = Scopes[I].ParentScope231
) {
905
231
    if (S.getLangOpts().MSVCCompat && 
JumpDiagWarning != 010
&&
906
231
        
IsMicrosoftJumpWarning(JumpDiagError, Scopes[I].InDiag)8
)
907
6
      ToScopesWarning.push_back(I);
908
225
    else if (IsCXX98CompatWarning(S, Scopes[I].InDiag))
909
12
      ToScopesCXX98Compat.push_back(I);
910
213
    else if (Scopes[I].InDiag)
911
213
      ToScopesError.push_back(I);
912
231
  }
913
210
914
210
  // Handle warnings.
915
210
  if (!ToScopesWarning.empty()) {
916
6
    S.Diag(DiagLoc, JumpDiagWarning);
917
6
    NoteJumpIntoScopes(ToScopesWarning);
918
6
  }
919
210
920
210
  // Handle errors.
921
210
  if (!ToScopesError.empty()) {
922
192
    S.Diag(DiagLoc, JumpDiagError);
923
192
    NoteJumpIntoScopes(ToScopesError);
924
192
  }
925
210
926
210
  // Handle -Wc++98-compat warnings if the jump is well-formed.
927
210
  if (ToScopesError.empty() && 
!ToScopesCXX98Compat.empty()18
) {
928
12
    S.Diag(DiagLoc, JumpDiagCXX98Compat);
929
12
    NoteJumpIntoScopes(ToScopesCXX98Compat);
930
12
  }
931
210
}
932
933
3.51k
void JumpScopeChecker::CheckGotoStmt(GotoStmt *GS) {
934
3.51k
  if (GS->getLabel()->isMSAsmLabel()) {
935
4
    S.Diag(GS->getGotoLoc(), diag::err_goto_ms_asm_label)
936
4
        << GS->getLabel()->getIdentifier();
937
4
    S.Diag(GS->getLabel()->getLocation(), diag::note_goto_ms_asm_label)
938
4
        << GS->getLabel()->getIdentifier();
939
4
  }
940
3.51k
}
941
942
5.57k
void Sema::DiagnoseInvalidJumps(Stmt *Body) {
943
5.57k
  (void)JumpScopeChecker(Body, *this);
944
5.57k
}