Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
53.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
145k
#define CHECK_PERMISSIVE(x) (assert(Permissive || !(x)), (Permissive && 
(x)626
))
95
96
JumpScopeChecker::JumpScopeChecker(Stmt *Body, Sema &s)
97
8.83k
    : S(s), Permissive(s.hasAnyUnrecoverableErrorsInThisFunction()) {
98
8.83k
  // Add a scope entry for function scope.
99
8.83k
  Scopes.push_back(GotoScope(~0U, ~0U, ~0U, SourceLocation()));
100
8.83k
101
8.83k
  // Build information for the top level compound statement, so that we have a
102
8.83k
  // defined scope record for every "goto" and label.
103
8.83k
  unsigned BodyParentScope = 0;
104
8.83k
  BuildScopeInformation(Body, BodyParentScope);
105
8.83k
106
8.83k
  // Check that all jumps we saw are kosher.
107
8.83k
  VerifyJumps();
108
8.83k
  VerifyIndirectOrAsmJumps(false);
109
8.83k
  VerifyIndirectOrAsmJumps(true);
110
8.83k
}
111
112
/// GetDeepestCommonScope - Finds the innermost scope enclosing the
113
/// two scopes.
114
1.69k
unsigned JumpScopeChecker::GetDeepestCommonScope(unsigned A, unsigned B) {
115
6.81k
  while (A != B) {
116
5.12k
    // Inner scopes are created after outer scopes and therefore have
117
5.12k
    // higher indices.
118
5.12k
    if (A < B) {
119
241
      assert(Scopes[B].ParentScope < B);
120
241
      B = Scopes[B].ParentScope;
121
4.88k
    } else {
122
4.88k
      assert(Scopes[A].ParentScope < A);
123
4.88k
      A = Scopes[A].ParentScope;
124
4.88k
    }
125
5.12k
  }
126
1.69k
  return A;
127
1.69k
}
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
53.2k
static ScopePair GetDiagForGotoScopeDecl(Sema &S, const Decl *D) {
134
53.2k
  if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
135
49.7k
    unsigned InDiag = 0;
136
49.7k
    unsigned OutDiag = 0;
137
49.7k
138
49.7k
    if (VD->getType()->isVariablyModifiedType())
139
34
      InDiag = diag::note_protected_by_vla;
140
49.7k
141
49.7k
    if (VD->hasAttr<BlocksAttr>())
142
2
      return ScopePair(diag::note_protected_by___block,
143
2
                       diag::note_exits___block);
144
49.7k
145
49.7k
    if (VD->hasAttr<CleanupAttr>())
146
1
      return ScopePair(diag::note_protected_by_cleanup,
147
1
                       diag::note_exits_cleanup);
148
49.7k
149
49.7k
    if (VD->hasLocalStorage()) {
150
49.5k
      switch (VD->getType().isDestructedType()) {
151
49.5k
      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
49.5k
155
49.5k
      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
49.5k
159
49.5k
      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
49.5k
163
49.5k
      case QualType::DK_cxx_destructor:
164
1.47k
        OutDiag = diag::note_exits_dtor;
165
1.47k
        break;
166
49.5k
167
49.5k
      case QualType::DK_none:
168
48.0k
        break;
169
49.7k
      }
170
49.7k
    }
171
49.7k
172
49.7k
    const Expr *Init = VD->getInit();
173
49.7k
    if (S.Context.getLangOpts().CPlusPlus && 
VD->hasLocalStorage()49.5k
&&
Init49.3k
) {
174
44.1k
      // C++11 [stmt.dcl]p3:
175
44.1k
      //   A program that jumps from a point where a variable with automatic
176
44.1k
      //   storage duration is not in scope to a point where it is in scope
177
44.1k
      //   is ill-formed unless the variable has scalar type, class type with
178
44.1k
      //   a trivial default constructor and a trivial destructor, a
179
44.1k
      //   cv-qualified version of one of these types, or an array of one of
180
44.1k
      //   the preceding types and is declared without an initializer.
181
44.1k
182
44.1k
      // C++03 [stmt.dcl.p3:
183
44.1k
      //   A program that jumps from a point where a local variable
184
44.1k
      //   with automatic storage duration is not in scope to a point
185
44.1k
      //   where it is in scope is ill-formed unless the variable has
186
44.1k
      //   POD type and is declared without an initializer.
187
44.1k
188
44.1k
      InDiag = diag::note_protected_by_variable_init;
189
44.1k
190
44.1k
      // For a variable of (array of) class type declared without an
191
44.1k
      // initializer, we will have call-style initialization and the initializer
192
44.1k
      // will be the CXXConstructExpr with no intervening nodes.
193
44.1k
      if (const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(Init)) {
194
3.21k
        const CXXConstructorDecl *Ctor = CCE->getConstructor();
195
3.21k
        if (Ctor->isTrivial() && 
Ctor->isDefaultConstructor()544
&&
196
3.21k
            
VD->getInitStyle() == VarDecl::CallInit419
) {
197
408
          if (OutDiag)
198
76
            InDiag = diag::note_protected_by_variable_nontriv_destructor;
199
332
          else if (!Ctor->getParent()->isPOD())
200
18
            InDiag = diag::note_protected_by_variable_non_pod;
201
314
          else
202
314
            InDiag = 0;
203
408
        }
204
3.21k
      }
205
44.1k
    }
206
49.7k
207
49.7k
    return ScopePair(InDiag, OutDiag);
208
49.7k
  }
209
3.48k
210
3.48k
  if (const TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
211
3.44k
    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
3.47k
  }
217
3.47k
218
3.47k
  return ScopePair(0U, 0U);
219
3.47k
}
220
221
/// Build scope information for a declaration that is part of a DeclStmt.
222
53.2k
void JumpScopeChecker::BuildScopeInformation(Decl *D, unsigned &ParentScope) {
223
53.2k
  // If this decl causes a new scope, push and switch to it.
224
53.2k
  std::pair<unsigned,unsigned> Diags = GetDiagForGotoScopeDecl(S, D);
225
53.2k
  if (Diags.first || 
Diags.second9.37k
) {
226
43.8k
    Scopes.push_back(GotoScope(ParentScope, Diags.first, Diags.second,
227
43.8k
                               D->getLocation()));
228
43.8k
    ParentScope = Scopes.size()-1;
229
43.8k
  }
230
53.2k
231
53.2k
  // If the decl has an initializer, walk it with the potentially new
232
53.2k
  // scope we just installed.
233
53.2k
  if (VarDecl *VD = dyn_cast<VarDecl>(D))
234
49.7k
    if (Expr *Init = VD->getInit())
235
44.3k
      BuildScopeInformation(Init, ParentScope);
236
53.2k
}
237
238
/// Build scope information for a captured block literal variables.
239
void JumpScopeChecker::BuildScopeInformation(VarDecl *D,
240
                                             const BlockDecl *BDecl,
241
19
                                             unsigned &ParentScope) {
242
19
  // exclude captured __block variables; there's no destructor
243
19
  // associated with the block literal for them.
244
19
  if (D->hasAttr<BlocksAttr>())
245
2
    return;
246
17
  QualType T = D->getType();
247
17
  QualType::DestructionKind destructKind = T.isDestructedType();
248
17
  if (destructKind != QualType::DK_none) {
249
17
    std::pair<unsigned,unsigned> Diags;
250
17
    switch (destructKind) {
251
17
      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
17
      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
17
      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
17
      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
17
      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
17
}
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.80M
                                             unsigned &origParentScope) {
285
1.80M
  // If this is a statement, rather than an expression, scopes within it don't
286
1.80M
  // propagate out into the enclosing scope.  Otherwise we have to worry
287
1.80M
  // about block literals, which have the lifetime of their enclosing statement.
288
1.80M
  unsigned independentParentScope = origParentScope;
289
1.80M
  unsigned &ParentScope = ((isa<Expr>(S) && 
!isa<StmtExpr>(S)1.53M
)
290
1.80M
                            ? 
origParentScope1.53M
:
independentParentScope270k
);
291
1.80M
292
1.80M
  unsigned StmtsToSkip = 0u;
293
1.80M
294
1.80M
  // If we found a label, remember that it is in ParentScope scope.
295
1.80M
  switch (S->getStmtClass()) {
296
1.80M
  case Stmt::AddrLabelExprClass:
297
206
    IndirectJumpTargets.push_back(cast<AddrLabelExpr>(S)->getLabel());
298
206
    break;
299
1.80M
300
1.80M
  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
1.80M
  }
308
1.80M
309
1.80M
  case Stmt::IndirectGotoStmtClass:
310
143
    // "goto *&&lbl;" is a special case which we treat as equivalent
311
143
    // to a normal goto.  In addition, we don't calculate scope in the
312
143
    // operand (to avoid recording the address-of-label use), which
313
143
    // works only because of the restricted set of expressions which
314
143
    // we detect as constant targets.
315
143
    if (cast<IndirectGotoStmt>(S)->getConstantTarget()) {
316
7
      LabelAndGotoScopes[S] = ParentScope;
317
7
      Jumps.push_back(S);
318
7
      return;
319
7
    }
320
136
321
136
    LabelAndGotoScopes[S] = ParentScope;
322
136
    IndirectJumps.push_back(S);
323
136
    break;
324
136
325
7.72k
  case Stmt::SwitchStmtClass:
326
7.72k
    // Evaluate the C++17 init stmt and condition variable
327
7.72k
    // before entering the scope of the switch statement.
328
7.72k
    if (Stmt *Init = cast<SwitchStmt>(S)->getInit()) {
329
60
      BuildScopeInformation(Init, ParentScope);
330
60
      ++StmtsToSkip;
331
60
    }
332
7.72k
    if (VarDecl *Var = cast<SwitchStmt>(S)->getConditionVariable()) {
333
52
      BuildScopeInformation(Var, ParentScope);
334
52
      ++StmtsToSkip;
335
52
    }
336
7.72k
    LLVM_FALLTHROUGH;
337
7.72k
338
11.3k
  case Stmt::GotoStmtClass:
339
11.3k
    // Remember both what scope a goto is in as well as the fact that we have
340
11.3k
    // it.  This makes the second scan not have to walk the AST again.
341
11.3k
    LabelAndGotoScopes[S] = ParentScope;
342
11.3k
    Jumps.push_back(S);
343
11.3k
    break;
344
7.72k
345
7.72k
  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
7.72k
357
48.9k
  case Stmt::IfStmtClass: {
358
48.9k
    IfStmt *IS = cast<IfStmt>(S);
359
48.9k
    if (!(IS->isConstexpr() || 
IS->isObjCAvailabilityCheck()48.9k
))
360
48.9k
      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
217
  case Stmt::CXXTryStmtClass: {
386
217
    CXXTryStmt *TS = cast<CXXTryStmt>(S);
387
217
    {
388
217
      unsigned NewParentScope = Scopes.size();
389
217
      Scopes.push_back(GotoScope(ParentScope,
390
217
                                 diag::note_protected_by_cxx_try,
391
217
                                 diag::note_exits_cxx_try,
392
217
                                 TS->getSourceRange().getBegin()));
393
217
      if (Stmt *TryBlock = TS->getTryBlock())
394
217
        BuildScopeInformation(TryBlock, NewParentScope);
395
217
    }
396
217
397
217
    // Jump from the catch into the try is not allowed either.
398
456
    for (unsigned I = 0, E = TS->getNumHandlers(); I != E; 
++I239
) {
399
239
      CXXCatchStmt *CS = TS->getHandler(I);
400
239
      unsigned NewParentScope = Scopes.size();
401
239
      Scopes.push_back(GotoScope(ParentScope,
402
239
                                 diag::note_protected_by_cxx_catch,
403
239
                                 diag::note_exits_cxx_catch,
404
239
                                 CS->getSourceRange().getBegin()));
405
239
      BuildScopeInformation(CS->getHandlerBlock(), NewParentScope);
406
239
    }
407
217
    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
52.8k
  case Stmt::DeclStmtClass: {
443
52.8k
    // If this is a declstmt with a VLA definition, it defines a scope from here
444
52.8k
    // to the end of the containing context.
445
52.8k
    DeclStmt *DS = cast<DeclStmt>(S);
446
52.8k
    // The decl statement creates a scope if any of the decls in it are VLAs
447
52.8k
    // or have the cleanup attribute.
448
52.8k
    for (auto *I : DS->decls())
449
53.2k
      BuildScopeInformation(I, origParentScope);
450
52.8k
    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
4.56k
  case Stmt::ExprWithCleanupsClass: {
527
4.56k
    // Disallow jumps past full-expressions that use blocks with
528
4.56k
    // non-trivial cleanups of their captures.  This is theoretically
529
4.56k
    // implementable but a lot of work which we haven't felt up to doing.
530
4.56k
    ExprWithCleanups *EWC = cast<ExprWithCleanups>(S);
531
4.58k
    for (unsigned i = 0, e = EWC->getNumObjects(); i != e; 
++i19
) {
532
19
      const BlockDecl *BDecl = EWC->getObject(i);
533
19
      for (const auto &CI : BDecl->captures()) {
534
19
        VarDecl *variable = CI.getVariable();
535
19
        BuildScopeInformation(variable, BDecl, origParentScope);
536
19
      }
537
19
    }
538
4.56k
    break;
539
16
  }
540
16
541
5.00k
  case Stmt::MaterializeTemporaryExprClass: {
542
5.00k
    // Disallow jumps out of scopes containing temporaries lifetime-extended to
543
5.00k
    // automatic storage duration.
544
5.00k
    MaterializeTemporaryExpr *MTE = cast<MaterializeTemporaryExpr>(S);
545
5.00k
    if (MTE->getStorageDuration() == SD_Automatic) {
546
79
      SmallVector<const Expr *, 4> CommaLHS;
547
79
      SmallVector<SubobjectAdjustment, 4> Adjustments;
548
79
      const Expr *ExtendedObject =
549
79
          MTE->GetTemporaryExpr()->skipRValueSubobjectAdjustments(
550
79
              CommaLHS, Adjustments);
551
79
      if (ExtendedObject->getType().isDestructedType()) {
552
10
        Scopes.push_back(GotoScope(ParentScope, 0,
553
10
                                   diag::note_exits_temporary_dtor,
554
10
                                   ExtendedObject->getExprLoc()));
555
10
        origParentScope = Scopes.size()-1;
556
10
      }
557
79
    }
558
5.00k
    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.67M
  default:
568
1.67M
    break;
569
1.74M
  }
570
1.74M
571
1.75M
  
for (Stmt *SubStmt : S->children())1.74M
{
572
1.75M
    if (!SubStmt)
573
5.60k
        continue;
574
1.74M
    if (StmtsToSkip) {
575
112
      --StmtsToSkip;
576
112
      continue;
577
112
    }
578
1.74M
579
1.74M
    // Cases, labels, and defaults aren't "scope parents".  It's also
580
1.74M
    // important to handle these iteratively instead of recursively in
581
1.74M
    // order to avoid blowing out the stack.
582
1.79M
    
while (1.74M
true) {
583
1.79M
      Stmt *Next;
584
1.79M
      if (SwitchCase *SC = dyn_cast<SwitchCase>(SubStmt))
585
45.8k
        Next = SC->getSubStmt();
586
1.75M
      else if (LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt))
587
3.06k
        Next = LS->getSubStmt();
588
1.74M
      else
589
1.74M
        break;
590
48.9k
591
48.9k
      LabelAndGotoScopes[SubStmt] = ParentScope;
592
48.9k
      SubStmt = Next;
593
48.9k
    }
594
1.74M
595
1.74M
    // Recursively walk the AST.
596
1.74M
    BuildScopeInformation(SubStmt, ParentScope);
597
1.74M
  }
598
1.74M
}
599
600
/// VerifyJumps - Verify each element of the Jumps array to see if they are
601
/// valid, emitting diagnostics if not.
602
8.83k
void JumpScopeChecker::VerifyJumps() {
603
20.1k
  while (!Jumps.empty()) {
604
11.3k
    Stmt *Jump = Jumps.pop_back_val();
605
11.3k
606
11.3k
    // With a goto,
607
11.3k
    if (GotoStmt *GS = dyn_cast<GotoStmt>(Jump)) {
608
3.59k
      // The label may not have a statement if it's coming from inline MS ASM.
609
3.59k
      if (GS->getLabel()->getStmt()) {
610
3.49k
        CheckJump(GS, GS->getLabel()->getStmt(), GS->getGotoLoc(),
611
3.49k
                  diag::err_goto_into_protected_scope,
612
3.49k
                  diag::ext_goto_into_protected_scope,
613
3.49k
                  diag::warn_cxx98_compat_goto_into_protected_scope);
614
3.49k
      }
615
3.59k
      CheckGotoStmt(GS);
616
3.59k
      continue;
617
3.59k
    }
618
7.73k
619
7.73k
    // We only get indirect gotos here when they have a constant target.
620
7.73k
    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
7.72k
629
7.72k
    SwitchStmt *SS = cast<SwitchStmt>(Jump);
630
53.5k
    for (SwitchCase *SC = SS->getSwitchCaseList(); SC;
631
45.8k
         SC = SC->getNextSwitchCase()) {
632
45.8k
      if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(SC)))
633
45.8k
        
continue0
;
634
45.8k
      SourceLocation Loc;
635
45.8k
      if (CaseStmt *CS = dyn_cast<CaseStmt>(SC))
636
43.2k
        Loc = CS->getBeginLoc();
637
2.58k
      else if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC))
638
2.58k
        Loc = DS->getBeginLoc();
639
0
      else
640
0
        Loc = SC->getBeginLoc();
641
45.8k
      CheckJump(SS, SC, Loc, diag::err_switch_into_protected_scope, 0,
642
45.8k
                diag::warn_cxx98_compat_switch_into_protected_scope);
643
45.8k
    }
644
7.72k
  }
645
8.83k
}
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
17.6k
void JumpScopeChecker::VerifyIndirectOrAsmJumps(bool IsAsmGoto) {
666
17.6k
  SmallVector<Stmt*, 4> GotoJumps = IsAsmGoto ? 
AsmJumps8.83k
:
IndirectJumps8.83k
;
667
17.6k
  if (GotoJumps.empty())
668
17.5k
    return;
669
101
  SmallVector<LabelDecl *, 4> JumpTargets =
670
101
      IsAsmGoto ? 
AsmJumpTargets17
:
IndirectJumpTargets84
;
671
101
  // If there aren't any address-of-label expressions in this function,
672
101
  // complain about the first indirect goto.
673
101
  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
101
  // Collect a single representative of every scope containing an
680
101
  // indirect or asm goto.  For most code bases, this substantially cuts
681
101
  // down on the number of jump sites we'll have to consider later.
682
101
  typedef std::pair<unsigned, Stmt*> JumpScope;
683
101
  SmallVector<JumpScope, 32> JumpScopes;
684
101
  {
685
101
    llvm::DenseMap<unsigned, Stmt*> JumpScopesMap;
686
101
    for (SmallVectorImpl<Stmt *>::iterator I = GotoJumps.begin(),
687
101
                                           E = GotoJumps.end();
688
254
         I != E; 
++I153
) {
689
153
      Stmt *IG = *I;
690
153
      if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(IG)))
691
153
        
continue0
;
692
153
      unsigned IGScope = LabelAndGotoScopes[IG];
693
153
      Stmt *&Entry = JumpScopesMap[IGScope];
694
153
      if (!Entry) 
Entry = IG112
;
695
153
    }
696
101
    JumpScopes.reserve(JumpScopesMap.size());
697
101
    for (llvm::DenseMap<unsigned, Stmt *>::iterator I = JumpScopesMap.begin(),
698
101
                                                    E = JumpScopesMap.end();
699
213
         I != E; 
++I112
)
700
112
      JumpScopes.push_back(*I);
701
101
  }
702
101
703
101
  // Collect a single representative of every scope containing a
704
101
  // label whose address was taken somewhere in the function.
705
101
  // For most code bases, there will be only one such scope.
706
101
  llvm::DenseMap<unsigned, LabelDecl*> TargetScopes;
707
101
  for (SmallVectorImpl<LabelDecl *>::iterator I = JumpTargets.begin(),
708
101
                                              E = JumpTargets.end();
709
316
       I != E; 
++I215
) {
710
215
    LabelDecl *TheLabel = *I;
711
215
    if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(TheLabel->getStmt())))
712
215
      
continue0
;
713
215
    unsigned LabelScope = LabelAndGotoScopes[TheLabel->getStmt()];
714
215
    LabelDecl *&Target = TargetScopes[LabelScope];
715
215
    if (!Target) 
Target = TheLabel107
;
716
215
  }
717
101
718
101
  // For each target scope, make sure it's trivially reachable from
719
101
  // every scope containing a jump site.
720
101
  //
721
101
  // A path between scopes always consists of exitting zero or more
722
101
  // scopes, then entering zero or more scopes.  We build a set of
723
101
  // of scopes S from which the target scope can be trivially
724
101
  // entered, then verify that every jump scope can be trivially
725
101
  // exitted to reach a scope in S.
726
101
  llvm::BitVector Reachable(Scopes.size(), false);
727
101
  for (llvm::DenseMap<unsigned,LabelDecl*>::iterator
728
208
         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) 
break73
;
743
34
744
34
      // Stop if we can't trivially enter the current scope.
745
34
      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
138
      while (true) {
763
138
        if (Reachable.test(Scope)) {
764
79
          // If we find something reachable, mark all the scopes we just
765
79
          // walked through as reachable.
766
92
          for (unsigned S = I->first; S != Scope; 
S = Scopes[S].ParentScope13
)
767
13
            Reachable.set(S);
768
79
          IsReachable = true;
769
79
          break;
770
79
        }
771
59
772
59
        // Don't walk out if we've reached the top-level scope or we've
773
59
        // gotten shallower than the shallowest reachable scope.
774
59
        if (Scope == 0 || 
Scope < Min53
)
break12
;
775
47
776
47
        // Don't walk out through an out-diagnostic.
777
47
        if (Scopes[Scope].OutDiag) 
break28
;
778
19
779
19
        Scope = Scopes[Scope].ParentScope;
780
19
      }
781
119
782
119
      // Only diagnose if we didn't find something.
783
119
      if (IsReachable) 
continue79
;
784
40
785
40
      DiagnoseIndirectOrAsmJump(I->second, I->first, TargetLabel, TargetScope);
786
40
    }
787
107
  }
788
101
}
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
235
static bool IsCXX98CompatWarning(Sema &S, unsigned InDiagNote) {
801
235
  return S.getLangOpts().CPlusPlus11 &&
802
235
         
InDiagNote == diag::note_protected_by_variable_non_pod130
;
803
235
}
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
210
void JumpScopeChecker::NoteJumpIntoScopes(ArrayRef<unsigned> ToScopes) {
820
210
  if (CHECK_PERMISSIVE(ToScopes.empty()))
821
210
    
return0
;
822
441
  
for (unsigned I = 0, E = ToScopes.size(); 210
I != E;
++I231
)
823
231
    if (Scopes[ToScopes[I]].InDiag)
824
231
      S.Diag(Scopes[ToScopes[I]].Loc, Scopes[ToScopes[I]].InDiag);
825
210
}
826
827
/// Diagnose an indirect jump which is known to cross scopes.
828
void JumpScopeChecker::DiagnoseIndirectOrAsmJump(Stmt *Jump, unsigned JumpScope,
829
                                                 LabelDecl *Target,
830
40
                                                 unsigned TargetScope) {
831
40
  if (CHECK_PERMISSIVE(JumpScope == TargetScope))
832
40
    
return0
;
833
40
834
40
  unsigned Common = GetDeepestCommonScope(JumpScope, TargetScope);
835
40
  bool Diagnosed = false;
836
40
837
40
  // Walk out the scope chain until we reach the common ancestor.
838
85
  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
40
844
40
  SmallVector<unsigned, 10> ToScopesCXX98Compat;
845
40
846
40
  // Now walk into the scopes containing the label whose address was taken.
847
52
  for (unsigned I = TargetScope; I != Common; 
I = Scopes[I].ParentScope12
)
848
12
    if (IsCXX98CompatWarning(S, Scopes[I].InDiag))
849
2
      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
40
855
40
  // Diagnose this jump if it would be ill-formed in C++98.
856
40
  if (!Diagnosed && 
!ToScopesCXX98Compat.empty()2
) {
857
2
    bool IsAsmGoto = isa<GCCAsmStmt>(Jump);
858
2
    S.Diag(Jump->getBeginLoc(),
859
2
           diag::warn_cxx98_compat_indirect_goto_in_protected_scope)
860
2
        << IsAsmGoto;
861
2
    S.Diag(Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
862
2
        << IsAsmGoto;
863
2
    NoteJumpIntoScopes(ToScopesCXX98Compat);
864
2
  }
865
40
}
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
49.3k
                                 unsigned JumpDiagCXX98Compat) {
872
49.3k
  if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(From)))
873
49.3k
    
return0
;
874
49.3k
  if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(To)))
875
49.3k
    
return0
;
876
49.3k
877
49.3k
  unsigned FromScope = LabelAndGotoScopes[From];
878
49.3k
  unsigned ToScope = LabelAndGotoScopes[To];
879
49.3k
880
49.3k
  // Common case: exactly the same scope, which is fine.
881
49.3k
  if (FromScope == ToScope) 
return47.7k
;
882
1.65k
883
1.65k
  // Warn on gotos out of __finally blocks.
884
1.65k
  if (isa<GotoStmt>(From) || 
isa<IndirectGotoStmt>(From)50
) {
885
1.60k
    // If FromScope > ToScope, FromScope is more nested and the jump goes to a
886
1.60k
    // less nested scope.  Check if it crosses a __finally along the way.
887
6.41k
    for (unsigned I = FromScope; I > ToScope; 
I = Scopes[I].ParentScope4.80k
) {
888
4.81k
      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.81k
    }
893
1.60k
  }
894
1.65k
895
1.65k
  unsigned CommonScope = GetDeepestCommonScope(FromScope, ToScope);
896
1.65k
897
1.65k
  // It's okay to jump out from a nested scope.
898
1.65k
  if (CommonScope == ToScope) 
return1.44k
;
899
208
900
208
  // Pull out (and reverse) any scopes we might need to diagnose skipping.
901
208
  SmallVector<unsigned, 10> ToScopesCXX98Compat;
902
208
  SmallVector<unsigned, 10> ToScopesError;
903
208
  SmallVector<unsigned, 10> ToScopesWarning;
904
437
  for (unsigned I = ToScope; I != CommonScope; 
I = Scopes[I].ParentScope229
) {
905
229
    if (S.getLangOpts().MSVCCompat && 
JumpDiagWarning != 010
&&
906
229
        
IsMicrosoftJumpWarning(JumpDiagError, Scopes[I].InDiag)8
)
907
6
      ToScopesWarning.push_back(I);
908
223
    else if (IsCXX98CompatWarning(S, Scopes[I].InDiag))
909
10
      ToScopesCXX98Compat.push_back(I);
910
213
    else if (Scopes[I].InDiag)
911
213
      ToScopesError.push_back(I);
912
229
  }
913
208
914
208
  // Handle warnings.
915
208
  if (!ToScopesWarning.empty()) {
916
6
    S.Diag(DiagLoc, JumpDiagWarning);
917
6
    NoteJumpIntoScopes(ToScopesWarning);
918
6
  }
919
208
920
208
  // Handle errors.
921
208
  if (!ToScopesError.empty()) {
922
192
    S.Diag(DiagLoc, JumpDiagError);
923
192
    NoteJumpIntoScopes(ToScopesError);
924
192
  }
925
208
926
208
  // Handle -Wc++98-compat warnings if the jump is well-formed.
927
208
  if (ToScopesError.empty() && 
!ToScopesCXX98Compat.empty()16
) {
928
10
    S.Diag(DiagLoc, JumpDiagCXX98Compat);
929
10
    NoteJumpIntoScopes(ToScopesCXX98Compat);
930
10
  }
931
208
}
932
933
3.59k
void JumpScopeChecker::CheckGotoStmt(GotoStmt *GS) {
934
3.59k
  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.59k
}
941
942
8.83k
void Sema::DiagnoseInvalidJumps(Stmt *Body) {
943
8.83k
  (void)JumpScopeChecker(Body, *this);
944
8.83k
}