Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/Stmt.h
Line
Count
Source (jump to first uncovered line)
1
//===- Stmt.h - Classes for representing statements -------------*- 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 defines the Stmt interface and subclasses.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_AST_STMT_H
14
#define LLVM_CLANG_AST_STMT_H
15
16
#include "clang/AST/DeclGroup.h"
17
#include "clang/AST/DependenceFlags.h"
18
#include "clang/AST/StmtIterator.h"
19
#include "clang/Basic/CapturedStmt.h"
20
#include "clang/Basic/IdentifierTable.h"
21
#include "clang/Basic/LLVM.h"
22
#include "clang/Basic/SourceLocation.h"
23
#include "clang/Basic/Specifiers.h"
24
#include "llvm/ADT/ArrayRef.h"
25
#include "llvm/ADT/BitmaskEnum.h"
26
#include "llvm/ADT/PointerIntPair.h"
27
#include "llvm/ADT/StringRef.h"
28
#include "llvm/ADT/iterator.h"
29
#include "llvm/ADT/iterator_range.h"
30
#include "llvm/Support/Casting.h"
31
#include "llvm/Support/Compiler.h"
32
#include "llvm/Support/ErrorHandling.h"
33
#include <algorithm>
34
#include <cassert>
35
#include <cstddef>
36
#include <iterator>
37
#include <string>
38
39
namespace llvm {
40
41
class FoldingSetNodeID;
42
43
} // namespace llvm
44
45
namespace clang {
46
47
class ASTContext;
48
class Attr;
49
class CapturedDecl;
50
class Decl;
51
class Expr;
52
class AddrLabelExpr;
53
class LabelDecl;
54
class ODRHash;
55
class PrinterHelper;
56
struct PrintingPolicy;
57
class RecordDecl;
58
class SourceManager;
59
class StringLiteral;
60
class Token;
61
class VarDecl;
62
63
//===----------------------------------------------------------------------===//
64
// AST classes for statements.
65
//===----------------------------------------------------------------------===//
66
67
/// Stmt - This represents one statement.
68
///
69
class alignas(void *) Stmt {
70
public:
71
  enum StmtClass {
72
    NoStmtClass = 0,
73
#define STMT(CLASS, PARENT) CLASS##Class,
74
#define STMT_RANGE(BASE, FIRST, LAST) \
75
        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
76
#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
77
        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
78
#define ABSTRACT_STMT(STMT)
79
#include "clang/AST/StmtNodes.inc"
80
  };
81
82
  // Make vanilla 'new' and 'delete' illegal for Stmts.
83
protected:
84
  friend class ASTStmtReader;
85
  friend class ASTStmtWriter;
86
87
0
  void *operator new(size_t bytes) noexcept {
88
0
    llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
89
0
  }
90
91
0
  void operator delete(void *data) noexcept {
92
0
    llvm_unreachable("Stmts cannot be released with regular 'delete'.");
93
0
  }
94
95
  //===--- Statement bitfields classes ---===//
96
97
  class StmtBitfields {
98
    friend class ASTStmtReader;
99
    friend class ASTStmtWriter;
100
    friend class Stmt;
101
102
    /// The statement class.
103
    unsigned sClass : 8;
104
  };
105
  enum { NumStmtBits = 8 };
106
107
  class NullStmtBitfields {
108
    friend class ASTStmtReader;
109
    friend class ASTStmtWriter;
110
    friend class NullStmt;
111
112
    unsigned : NumStmtBits;
113
114
    /// True if the null statement was preceded by an empty macro, e.g:
115
    /// @code
116
    ///   #define CALL(x)
117
    ///   CALL(0);
118
    /// @endcode
119
    unsigned HasLeadingEmptyMacro : 1;
120
121
    /// The location of the semi-colon.
122
    SourceLocation SemiLoc;
123
  };
124
125
  class CompoundStmtBitfields {
126
    friend class ASTStmtReader;
127
    friend class CompoundStmt;
128
129
    unsigned : NumStmtBits;
130
131
    unsigned NumStmts : 32 - NumStmtBits;
132
133
    /// The location of the opening "{".
134
    SourceLocation LBraceLoc;
135
  };
136
137
  class LabelStmtBitfields {
138
    friend class LabelStmt;
139
140
    unsigned : NumStmtBits;
141
142
    SourceLocation IdentLoc;
143
  };
144
145
  class AttributedStmtBitfields {
146
    friend class ASTStmtReader;
147
    friend class AttributedStmt;
148
149
    unsigned : NumStmtBits;
150
151
    /// Number of attributes.
152
    unsigned NumAttrs : 32 - NumStmtBits;
153
154
    /// The location of the attribute.
155
    SourceLocation AttrLoc;
156
  };
157
158
  class IfStmtBitfields {
159
    friend class ASTStmtReader;
160
    friend class IfStmt;
161
162
    unsigned : NumStmtBits;
163
164
    /// Whether this is a constexpr if, or a consteval if, or neither.
165
    unsigned Kind : 3;
166
167
    /// True if this if statement has storage for an else statement.
168
    unsigned HasElse : 1;
169
170
    /// True if this if statement has storage for a variable declaration.
171
    unsigned HasVar : 1;
172
173
    /// True if this if statement has storage for an init statement.
174
    unsigned HasInit : 1;
175
176
    /// The location of the "if".
177
    SourceLocation IfLoc;
178
  };
179
180
  class SwitchStmtBitfields {
181
    friend class SwitchStmt;
182
183
    unsigned : NumStmtBits;
184
185
    /// True if the SwitchStmt has storage for an init statement.
186
    unsigned HasInit : 1;
187
188
    /// True if the SwitchStmt has storage for a condition variable.
189
    unsigned HasVar : 1;
190
191
    /// If the SwitchStmt is a switch on an enum value, records whether all
192
    /// the enum values were covered by CaseStmts.  The coverage information
193
    /// value is meant to be a hint for possible clients.
194
    unsigned AllEnumCasesCovered : 1;
195
196
    /// The location of the "switch".
197
    SourceLocation SwitchLoc;
198
  };
199
200
  class WhileStmtBitfields {
201
    friend class ASTStmtReader;
202
    friend class WhileStmt;
203
204
    unsigned : NumStmtBits;
205
206
    /// True if the WhileStmt has storage for a condition variable.
207
    unsigned HasVar : 1;
208
209
    /// The location of the "while".
210
    SourceLocation WhileLoc;
211
  };
212
213
  class DoStmtBitfields {
214
    friend class DoStmt;
215
216
    unsigned : NumStmtBits;
217
218
    /// The location of the "do".
219
    SourceLocation DoLoc;
220
  };
221
222
  class ForStmtBitfields {
223
    friend class ForStmt;
224
225
    unsigned : NumStmtBits;
226
227
    /// The location of the "for".
228
    SourceLocation ForLoc;
229
  };
230
231
  class GotoStmtBitfields {
232
    friend class GotoStmt;
233
    friend class IndirectGotoStmt;
234
235
    unsigned : NumStmtBits;
236
237
    /// The location of the "goto".
238
    SourceLocation GotoLoc;
239
  };
240
241
  class ContinueStmtBitfields {
242
    friend class ContinueStmt;
243
244
    unsigned : NumStmtBits;
245
246
    /// The location of the "continue".
247
    SourceLocation ContinueLoc;
248
  };
249
250
  class BreakStmtBitfields {
251
    friend class BreakStmt;
252
253
    unsigned : NumStmtBits;
254
255
    /// The location of the "break".
256
    SourceLocation BreakLoc;
257
  };
258
259
  class ReturnStmtBitfields {
260
    friend class ReturnStmt;
261
262
    unsigned : NumStmtBits;
263
264
    /// True if this ReturnStmt has storage for an NRVO candidate.
265
    unsigned HasNRVOCandidate : 1;
266
267
    /// The location of the "return".
268
    SourceLocation RetLoc;
269
  };
270
271
  class SwitchCaseBitfields {
272
    friend class SwitchCase;
273
    friend class CaseStmt;
274
275
    unsigned : NumStmtBits;
276
277
    /// Used by CaseStmt to store whether it is a case statement
278
    /// of the form case LHS ... RHS (a GNU extension).
279
    unsigned CaseStmtIsGNURange : 1;
280
281
    /// The location of the "case" or "default" keyword.
282
    SourceLocation KeywordLoc;
283
  };
284
285
  //===--- Expression bitfields classes ---===//
286
287
  class ExprBitfields {
288
    friend class ASTStmtReader; // deserialization
289
    friend class AtomicExpr; // ctor
290
    friend class BlockDeclRefExpr; // ctor
291
    friend class CallExpr; // ctor
292
    friend class CXXConstructExpr; // ctor
293
    friend class CXXDependentScopeMemberExpr; // ctor
294
    friend class CXXNewExpr; // ctor
295
    friend class CXXUnresolvedConstructExpr; // ctor
296
    friend class DeclRefExpr; // computeDependence
297
    friend class DependentScopeDeclRefExpr; // ctor
298
    friend class DesignatedInitExpr; // ctor
299
    friend class Expr;
300
    friend class InitListExpr; // ctor
301
    friend class ObjCArrayLiteral; // ctor
302
    friend class ObjCDictionaryLiteral; // ctor
303
    friend class ObjCMessageExpr; // ctor
304
    friend class OffsetOfExpr; // ctor
305
    friend class OpaqueValueExpr; // ctor
306
    friend class OverloadExpr; // ctor
307
    friend class ParenListExpr; // ctor
308
    friend class PseudoObjectExpr; // ctor
309
    friend class ShuffleVectorExpr; // ctor
310
311
    unsigned : NumStmtBits;
312
313
    unsigned ValueKind : 2;
314
    unsigned ObjectKind : 3;
315
    unsigned /*ExprDependence*/ Dependent : llvm::BitWidth<ExprDependence>;
316
  };
317
  enum { NumExprBits = NumStmtBits + 5 + llvm::BitWidth<ExprDependence> };
318
319
  class ConstantExprBitfields {
320
    friend class ASTStmtReader;
321
    friend class ASTStmtWriter;
322
    friend class ConstantExpr;
323
324
    unsigned : NumExprBits;
325
326
    /// The kind of result that is tail-allocated.
327
    unsigned ResultKind : 2;
328
329
    /// The kind of Result as defined by APValue::Kind.
330
    unsigned APValueKind : 4;
331
332
    /// When ResultKind == RSK_Int64, true if the tail-allocated integer is
333
    /// unsigned.
334
    unsigned IsUnsigned : 1;
335
336
    /// When ResultKind == RSK_Int64. the BitWidth of the tail-allocated
337
    /// integer. 7 bits because it is the minimal number of bits to represent a
338
    /// value from 0 to 64 (the size of the tail-allocated integer).
339
    unsigned BitWidth : 7;
340
341
    /// When ResultKind == RSK_APValue, true if the ASTContext will cleanup the
342
    /// tail-allocated APValue.
343
    unsigned HasCleanup : 1;
344
345
    /// True if this ConstantExpr was created for immediate invocation.
346
    unsigned IsImmediateInvocation : 1;
347
  };
348
349
  class PredefinedExprBitfields {
350
    friend class ASTStmtReader;
351
    friend class PredefinedExpr;
352
353
    unsigned : NumExprBits;
354
355
    /// The kind of this PredefinedExpr. One of the enumeration values
356
    /// in PredefinedExpr::IdentKind.
357
    unsigned Kind : 4;
358
359
    /// True if this PredefinedExpr has a trailing "StringLiteral *"
360
    /// for the predefined identifier.
361
    unsigned HasFunctionName : 1;
362
363
    /// The location of this PredefinedExpr.
364
    SourceLocation Loc;
365
  };
366
367
  class DeclRefExprBitfields {
368
    friend class ASTStmtReader; // deserialization
369
    friend class DeclRefExpr;
370
371
    unsigned : NumExprBits;
372
373
    unsigned HasQualifier : 1;
374
    unsigned HasTemplateKWAndArgsInfo : 1;
375
    unsigned HasFoundDecl : 1;
376
    unsigned HadMultipleCandidates : 1;
377
    unsigned RefersToEnclosingVariableOrCapture : 1;
378
    unsigned NonOdrUseReason : 2;
379
380
    /// The location of the declaration name itself.
381
    SourceLocation Loc;
382
  };
383
384
385
  class FloatingLiteralBitfields {
386
    friend class FloatingLiteral;
387
388
    unsigned : NumExprBits;
389
390
    unsigned Semantics : 3; // Provides semantics for APFloat construction
391
    unsigned IsExact : 1;
392
  };
393
394
  class StringLiteralBitfields {
395
    friend class ASTStmtReader;
396
    friend class StringLiteral;
397
398
    unsigned : NumExprBits;
399
400
    /// The kind of this string literal.
401
    /// One of the enumeration values of StringLiteral::StringKind.
402
    unsigned Kind : 3;
403
404
    /// The width of a single character in bytes. Only values of 1, 2,
405
    /// and 4 bytes are supported. StringLiteral::mapCharByteWidth maps
406
    /// the target + string kind to the appropriate CharByteWidth.
407
    unsigned CharByteWidth : 3;
408
409
    unsigned IsPascal : 1;
410
411
    /// The number of concatenated token this string is made of.
412
    /// This is the number of trailing SourceLocation.
413
    unsigned NumConcatenated;
414
  };
415
416
  class CharacterLiteralBitfields {
417
    friend class CharacterLiteral;
418
419
    unsigned : NumExprBits;
420
421
    unsigned Kind : 3;
422
  };
423
424
  class UnaryOperatorBitfields {
425
    friend class UnaryOperator;
426
427
    unsigned : NumExprBits;
428
429
    unsigned Opc : 5;
430
    unsigned CanOverflow : 1;
431
    //
432
    /// This is only meaningful for operations on floating point
433
    /// types when additional values need to be in trailing storage.
434
    /// It is 0 otherwise.
435
    unsigned HasFPFeatures : 1;
436
437
    SourceLocation Loc;
438
  };
439
440
  class UnaryExprOrTypeTraitExprBitfields {
441
    friend class UnaryExprOrTypeTraitExpr;
442
443
    unsigned : NumExprBits;
444
445
    unsigned Kind : 3;
446
    unsigned IsType : 1; // true if operand is a type, false if an expression.
447
  };
448
449
  class ArrayOrMatrixSubscriptExprBitfields {
450
    friend class ArraySubscriptExpr;
451
    friend class MatrixSubscriptExpr;
452
453
    unsigned : NumExprBits;
454
455
    SourceLocation RBracketLoc;
456
  };
457
458
  class CallExprBitfields {
459
    friend class CallExpr;
460
461
    unsigned : NumExprBits;
462
463
    unsigned NumPreArgs : 1;
464
465
    /// True if the callee of the call expression was found using ADL.
466
    unsigned UsesADL : 1;
467
468
    /// True if the call expression has some floating-point features.
469
    unsigned HasFPFeatures : 1;
470
471
    /// Padding used to align OffsetToTrailingObjects to a byte multiple.
472
    unsigned : 24 - 3 - NumExprBits;
473
474
    /// The offset in bytes from the this pointer to the start of the
475
    /// trailing objects belonging to CallExpr. Intentionally byte sized
476
    /// for faster access.
477
    unsigned OffsetToTrailingObjects : 8;
478
  };
479
  enum { NumCallExprBits = 32 };
480
481
  class MemberExprBitfields {
482
    friend class ASTStmtReader;
483
    friend class MemberExpr;
484
485
    unsigned : NumExprBits;
486
487
    /// IsArrow - True if this is "X->F", false if this is "X.F".
488
    unsigned IsArrow : 1;
489
490
    /// True if this member expression used a nested-name-specifier to
491
    /// refer to the member, e.g., "x->Base::f", or found its member via
492
    /// a using declaration.  When true, a MemberExprNameQualifier
493
    /// structure is allocated immediately after the MemberExpr.
494
    unsigned HasQualifierOrFoundDecl : 1;
495
496
    /// True if this member expression specified a template keyword
497
    /// and/or a template argument list explicitly, e.g., x->f<int>,
498
    /// x->template f, x->template f<int>.
499
    /// When true, an ASTTemplateKWAndArgsInfo structure and its
500
    /// TemplateArguments (if any) are present.
501
    unsigned HasTemplateKWAndArgsInfo : 1;
502
503
    /// True if this member expression refers to a method that
504
    /// was resolved from an overloaded set having size greater than 1.
505
    unsigned HadMultipleCandidates : 1;
506
507
    /// Value of type NonOdrUseReason indicating why this MemberExpr does
508
    /// not constitute an odr-use of the named declaration. Meaningful only
509
    /// when naming a static member.
510
    unsigned NonOdrUseReason : 2;
511
512
    /// This is the location of the -> or . in the expression.
513
    SourceLocation OperatorLoc;
514
  };
515
516
  class CastExprBitfields {
517
    friend class CastExpr;
518
    friend class ImplicitCastExpr;
519
520
    unsigned : NumExprBits;
521
522
    unsigned Kind : 7;
523
    unsigned PartOfExplicitCast : 1; // Only set for ImplicitCastExpr.
524
525
    /// True if the call expression has some floating-point features.
526
    unsigned HasFPFeatures : 1;
527
528
    /// The number of CXXBaseSpecifiers in the cast. 14 bits would be enough
529
    /// here. ([implimits] Direct and indirect base classes [16384]).
530
    unsigned BasePathSize;
531
  };
532
533
  class BinaryOperatorBitfields {
534
    friend class BinaryOperator;
535
536
    unsigned : NumExprBits;
537
538
    unsigned Opc : 6;
539
540
    /// This is only meaningful for operations on floating point
541
    /// types when additional values need to be in trailing storage.
542
    /// It is 0 otherwise.
543
    unsigned HasFPFeatures : 1;
544
545
    SourceLocation OpLoc;
546
  };
547
548
  class InitListExprBitfields {
549
    friend class InitListExpr;
550
551
    unsigned : NumExprBits;
552
553
    /// Whether this initializer list originally had a GNU array-range
554
    /// designator in it. This is a temporary marker used by CodeGen.
555
    unsigned HadArrayRangeDesignator : 1;
556
  };
557
558
  class ParenListExprBitfields {
559
    friend class ASTStmtReader;
560
    friend class ParenListExpr;
561
562
    unsigned : NumExprBits;
563
564
    /// The number of expressions in the paren list.
565
    unsigned NumExprs;
566
  };
567
568
  class GenericSelectionExprBitfields {
569
    friend class ASTStmtReader;
570
    friend class GenericSelectionExpr;
571
572
    unsigned : NumExprBits;
573
574
    /// The location of the "_Generic".
575
    SourceLocation GenericLoc;
576
  };
577
578
  class PseudoObjectExprBitfields {
579
    friend class ASTStmtReader; // deserialization
580
    friend class PseudoObjectExpr;
581
582
    unsigned : NumExprBits;
583
584
    // These don't need to be particularly wide, because they're
585
    // strictly limited by the forms of expressions we permit.
586
    unsigned NumSubExprs : 8;
587
    unsigned ResultIndex : 32 - 8 - NumExprBits;
588
  };
589
590
  class SourceLocExprBitfields {
591
    friend class ASTStmtReader;
592
    friend class SourceLocExpr;
593
594
    unsigned : NumExprBits;
595
596
    /// The kind of source location builtin represented by the SourceLocExpr.
597
    /// Ex. __builtin_LINE, __builtin_FUNCTION, ect.
598
    unsigned Kind : 2;
599
  };
600
601
  class StmtExprBitfields {
602
    friend class ASTStmtReader;
603
    friend class StmtExpr;
604
605
    unsigned : NumExprBits;
606
607
    /// The number of levels of template parameters enclosing this statement
608
    /// expression. Used to determine if a statement expression remains
609
    /// dependent after instantiation.
610
    unsigned TemplateDepth;
611
  };
612
613
  //===--- C++ Expression bitfields classes ---===//
614
615
  class CXXOperatorCallExprBitfields {
616
    friend class ASTStmtReader;
617
    friend class CXXOperatorCallExpr;
618
619
    unsigned : NumCallExprBits;
620
621
    /// The kind of this overloaded operator. One of the enumerator
622
    /// value of OverloadedOperatorKind.
623
    unsigned OperatorKind : 6;
624
  };
625
626
  class CXXRewrittenBinaryOperatorBitfields {
627
    friend class ASTStmtReader;
628
    friend class CXXRewrittenBinaryOperator;
629
630
    unsigned : NumCallExprBits;
631
632
    unsigned IsReversed : 1;
633
  };
634
635
  class CXXBoolLiteralExprBitfields {
636
    friend class CXXBoolLiteralExpr;
637
638
    unsigned : NumExprBits;
639
640
    /// The value of the boolean literal.
641
    unsigned Value : 1;
642
643
    /// The location of the boolean literal.
644
    SourceLocation Loc;
645
  };
646
647
  class CXXNullPtrLiteralExprBitfields {
648
    friend class CXXNullPtrLiteralExpr;
649
650
    unsigned : NumExprBits;
651
652
    /// The location of the null pointer literal.
653
    SourceLocation Loc;
654
  };
655
656
  class CXXThisExprBitfields {
657
    friend class CXXThisExpr;
658
659
    unsigned : NumExprBits;
660
661
    /// Whether this is an implicit "this".
662
    unsigned IsImplicit : 1;
663
664
    /// The location of the "this".
665
    SourceLocation Loc;
666
  };
667
668
  class CXXThrowExprBitfields {
669
    friend class ASTStmtReader;
670
    friend class CXXThrowExpr;
671
672
    unsigned : NumExprBits;
673
674
    /// Whether the thrown variable (if any) is in scope.
675
    unsigned IsThrownVariableInScope : 1;
676
677
    /// The location of the "throw".
678
    SourceLocation ThrowLoc;
679
  };
680
681
  class CXXDefaultArgExprBitfields {
682
    friend class ASTStmtReader;
683
    friend class CXXDefaultArgExpr;
684
685
    unsigned : NumExprBits;
686
687
    /// The location where the default argument expression was used.
688
    SourceLocation Loc;
689
  };
690
691
  class CXXDefaultInitExprBitfields {
692
    friend class ASTStmtReader;
693
    friend class CXXDefaultInitExpr;
694
695
    unsigned : NumExprBits;
696
697
    /// The location where the default initializer expression was used.
698
    SourceLocation Loc;
699
  };
700
701
  class CXXScalarValueInitExprBitfields {
702
    friend class ASTStmtReader;
703
    friend class CXXScalarValueInitExpr;
704
705
    unsigned : NumExprBits;
706
707
    SourceLocation RParenLoc;
708
  };
709
710
  class CXXNewExprBitfields {
711
    friend class ASTStmtReader;
712
    friend class ASTStmtWriter;
713
    friend class CXXNewExpr;
714
715
    unsigned : NumExprBits;
716
717
    /// Was the usage ::new, i.e. is the global new to be used?
718
    unsigned IsGlobalNew : 1;
719
720
    /// Do we allocate an array? If so, the first trailing "Stmt *" is the
721
    /// size expression.
722
    unsigned IsArray : 1;
723
724
    /// Should the alignment be passed to the allocation function?
725
    unsigned ShouldPassAlignment : 1;
726
727
    /// If this is an array allocation, does the usual deallocation
728
    /// function for the allocated type want to know the allocated size?
729
    unsigned UsualArrayDeleteWantsSize : 1;
730
731
    /// What kind of initializer do we have? Could be none, parens, or braces.
732
    /// In storage, we distinguish between "none, and no initializer expr", and
733
    /// "none, but an implicit initializer expr".
734
    unsigned StoredInitializationStyle : 2;
735
736
    /// True if the allocated type was expressed as a parenthesized type-id.
737
    unsigned IsParenTypeId : 1;
738
739
    /// The number of placement new arguments.
740
    unsigned NumPlacementArgs;
741
  };
742
743
  class CXXDeleteExprBitfields {
744
    friend class ASTStmtReader;
745
    friend class CXXDeleteExpr;
746
747
    unsigned : NumExprBits;
748
749
    /// Is this a forced global delete, i.e. "::delete"?
750
    unsigned GlobalDelete : 1;
751
752
    /// Is this the array form of delete, i.e. "delete[]"?
753
    unsigned ArrayForm : 1;
754
755
    /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is
756
    /// applied to pointer-to-array type (ArrayFormAsWritten will be false
757
    /// while ArrayForm will be true).
758
    unsigned ArrayFormAsWritten : 1;
759
760
    /// Does the usual deallocation function for the element type require
761
    /// a size_t argument?
762
    unsigned UsualArrayDeleteWantsSize : 1;
763
764
    /// Location of the expression.
765
    SourceLocation Loc;
766
  };
767
768
  class TypeTraitExprBitfields {
769
    friend class ASTStmtReader;
770
    friend class ASTStmtWriter;
771
    friend class TypeTraitExpr;
772
773
    unsigned : NumExprBits;
774
775
    /// The kind of type trait, which is a value of a TypeTrait enumerator.
776
    unsigned Kind : 8;
777
778
    /// If this expression is not value-dependent, this indicates whether
779
    /// the trait evaluated true or false.
780
    unsigned Value : 1;
781
782
    /// The number of arguments to this type trait. According to [implimits]
783
    /// 8 bits would be enough, but we require (and test for) at least 16 bits
784
    /// to mirror FunctionType.
785
    unsigned NumArgs;
786
  };
787
788
  class DependentScopeDeclRefExprBitfields {
789
    friend class ASTStmtReader;
790
    friend class ASTStmtWriter;
791
    friend class DependentScopeDeclRefExpr;
792
793
    unsigned : NumExprBits;
794
795
    /// Whether the name includes info for explicit template
796
    /// keyword and arguments.
797
    unsigned HasTemplateKWAndArgsInfo : 1;
798
  };
799
800
  class CXXConstructExprBitfields {
801
    friend class ASTStmtReader;
802
    friend class CXXConstructExpr;
803
804
    unsigned : NumExprBits;
805
806
    unsigned Elidable : 1;
807
    unsigned HadMultipleCandidates : 1;
808
    unsigned ListInitialization : 1;
809
    unsigned StdInitListInitialization : 1;
810
    unsigned ZeroInitialization : 1;
811
    unsigned ConstructionKind : 3;
812
813
    SourceLocation Loc;
814
  };
815
816
  class ExprWithCleanupsBitfields {
817
    friend class ASTStmtReader; // deserialization
818
    friend class ExprWithCleanups;
819
820
    unsigned : NumExprBits;
821
822
    // When false, it must not have side effects.
823
    unsigned CleanupsHaveSideEffects : 1;
824
825
    unsigned NumObjects : 32 - 1 - NumExprBits;
826
  };
827
828
  class CXXUnresolvedConstructExprBitfields {
829
    friend class ASTStmtReader;
830
    friend class CXXUnresolvedConstructExpr;
831
832
    unsigned : NumExprBits;
833
834
    /// The number of arguments used to construct the type.
835
    unsigned NumArgs;
836
  };
837
838
  class CXXDependentScopeMemberExprBitfields {
839
    friend class ASTStmtReader;
840
    friend class CXXDependentScopeMemberExpr;
841
842
    unsigned : NumExprBits;
843
844
    /// Whether this member expression used the '->' operator or
845
    /// the '.' operator.
846
    unsigned IsArrow : 1;
847
848
    /// Whether this member expression has info for explicit template
849
    /// keyword and arguments.
850
    unsigned HasTemplateKWAndArgsInfo : 1;
851
852
    /// See getFirstQualifierFoundInScope() and the comment listing
853
    /// the trailing objects.
854
    unsigned HasFirstQualifierFoundInScope : 1;
855
856
    /// The location of the '->' or '.' operator.
857
    SourceLocation OperatorLoc;
858
  };
859
860
  class OverloadExprBitfields {
861
    friend class ASTStmtReader;
862
    friend class OverloadExpr;
863
864
    unsigned : NumExprBits;
865
866
    /// Whether the name includes info for explicit template
867
    /// keyword and arguments.
868
    unsigned HasTemplateKWAndArgsInfo : 1;
869
870
    /// Padding used by the derived classes to store various bits. If you
871
    /// need to add some data here, shrink this padding and add your data
872
    /// above. NumOverloadExprBits also needs to be updated.
873
    unsigned : 32 - NumExprBits - 1;
874
875
    /// The number of results.
876
    unsigned NumResults;
877
  };
878
  enum { NumOverloadExprBits = NumExprBits + 1 };
879
880
  class UnresolvedLookupExprBitfields {
881
    friend class ASTStmtReader;
882
    friend class UnresolvedLookupExpr;
883
884
    unsigned : NumOverloadExprBits;
885
886
    /// True if these lookup results should be extended by
887
    /// argument-dependent lookup if this is the operand of a function call.
888
    unsigned RequiresADL : 1;
889
890
    /// True if these lookup results are overloaded.  This is pretty trivially
891
    /// rederivable if we urgently need to kill this field.
892
    unsigned Overloaded : 1;
893
  };
894
  static_assert(sizeof(UnresolvedLookupExprBitfields) <= 4,
895
                "UnresolvedLookupExprBitfields must be <= than 4 bytes to"
896
                "avoid trashing OverloadExprBitfields::NumResults!");
897
898
  class UnresolvedMemberExprBitfields {
899
    friend class ASTStmtReader;
900
    friend class UnresolvedMemberExpr;
901
902
    unsigned : NumOverloadExprBits;
903
904
    /// Whether this member expression used the '->' operator or
905
    /// the '.' operator.
906
    unsigned IsArrow : 1;
907
908
    /// Whether the lookup results contain an unresolved using declaration.
909
    unsigned HasUnresolvedUsing : 1;
910
  };
911
  static_assert(sizeof(UnresolvedMemberExprBitfields) <= 4,
912
                "UnresolvedMemberExprBitfields must be <= than 4 bytes to"
913
                "avoid trashing OverloadExprBitfields::NumResults!");
914
915
  class CXXNoexceptExprBitfields {
916
    friend class ASTStmtReader;
917
    friend class CXXNoexceptExpr;
918
919
    unsigned : NumExprBits;
920
921
    unsigned Value : 1;
922
  };
923
924
  class SubstNonTypeTemplateParmExprBitfields {
925
    friend class ASTStmtReader;
926
    friend class SubstNonTypeTemplateParmExpr;
927
928
    unsigned : NumExprBits;
929
930
    /// The location of the non-type template parameter reference.
931
    SourceLocation NameLoc;
932
  };
933
934
  class LambdaExprBitfields {
935
    friend class ASTStmtReader;
936
    friend class ASTStmtWriter;
937
    friend class LambdaExpr;
938
939
    unsigned : NumExprBits;
940
941
    /// The default capture kind, which is a value of type
942
    /// LambdaCaptureDefault.
943
    unsigned CaptureDefault : 2;
944
945
    /// Whether this lambda had an explicit parameter list vs. an
946
    /// implicit (and empty) parameter list.
947
    unsigned ExplicitParams : 1;
948
949
    /// Whether this lambda had the result type explicitly specified.
950
    unsigned ExplicitResultType : 1;
951
952
    /// The number of captures.
953
    unsigned NumCaptures : 16;
954
  };
955
956
  class RequiresExprBitfields {
957
    friend class ASTStmtReader;
958
    friend class ASTStmtWriter;
959
    friend class RequiresExpr;
960
961
    unsigned : NumExprBits;
962
963
    unsigned IsSatisfied : 1;
964
    SourceLocation RequiresKWLoc;
965
  };
966
967
  //===--- C++ Coroutines TS bitfields classes ---===//
968
969
  class CoawaitExprBitfields {
970
    friend class CoawaitExpr;
971
972
    unsigned : NumExprBits;
973
974
    unsigned IsImplicit : 1;
975
  };
976
977
  //===--- Obj-C Expression bitfields classes ---===//
978
979
  class ObjCIndirectCopyRestoreExprBitfields {
980
    friend class ObjCIndirectCopyRestoreExpr;
981
982
    unsigned : NumExprBits;
983
984
    unsigned ShouldCopy : 1;
985
  };
986
987
  //===--- Clang Extensions bitfields classes ---===//
988
989
  class OpaqueValueExprBitfields {
990
    friend class ASTStmtReader;
991
    friend class OpaqueValueExpr;
992
993
    unsigned : NumExprBits;
994
995
    /// The OVE is a unique semantic reference to its source expression if this
996
    /// bit is set to true.
997
    unsigned IsUnique : 1;
998
999
    SourceLocation Loc;
1000
  };
1001
1002
  union {
1003
    // Same order as in StmtNodes.td.
1004
    // Statements
1005
    StmtBitfields StmtBits;
1006
    NullStmtBitfields NullStmtBits;
1007
    CompoundStmtBitfields CompoundStmtBits;
1008
    LabelStmtBitfields LabelStmtBits;
1009
    AttributedStmtBitfields AttributedStmtBits;
1010
    IfStmtBitfields IfStmtBits;
1011
    SwitchStmtBitfields SwitchStmtBits;
1012
    WhileStmtBitfields WhileStmtBits;
1013
    DoStmtBitfields DoStmtBits;
1014
    ForStmtBitfields ForStmtBits;
1015
    GotoStmtBitfields GotoStmtBits;
1016
    ContinueStmtBitfields ContinueStmtBits;
1017
    BreakStmtBitfields BreakStmtBits;
1018
    ReturnStmtBitfields ReturnStmtBits;
1019
    SwitchCaseBitfields SwitchCaseBits;
1020
1021
    // Expressions
1022
    ExprBitfields ExprBits;
1023
    ConstantExprBitfields ConstantExprBits;
1024
    PredefinedExprBitfields PredefinedExprBits;
1025
    DeclRefExprBitfields DeclRefExprBits;
1026
    FloatingLiteralBitfields FloatingLiteralBits;
1027
    StringLiteralBitfields StringLiteralBits;
1028
    CharacterLiteralBitfields CharacterLiteralBits;
1029
    UnaryOperatorBitfields UnaryOperatorBits;
1030
    UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
1031
    ArrayOrMatrixSubscriptExprBitfields ArrayOrMatrixSubscriptExprBits;
1032
    CallExprBitfields CallExprBits;
1033
    MemberExprBitfields MemberExprBits;
1034
    CastExprBitfields CastExprBits;
1035
    BinaryOperatorBitfields BinaryOperatorBits;
1036
    InitListExprBitfields InitListExprBits;
1037
    ParenListExprBitfields ParenListExprBits;
1038
    GenericSelectionExprBitfields GenericSelectionExprBits;
1039
    PseudoObjectExprBitfields PseudoObjectExprBits;
1040
    SourceLocExprBitfields SourceLocExprBits;
1041
1042
    // GNU Extensions.
1043
    StmtExprBitfields StmtExprBits;
1044
1045
    // C++ Expressions
1046
    CXXOperatorCallExprBitfields CXXOperatorCallExprBits;
1047
    CXXRewrittenBinaryOperatorBitfields CXXRewrittenBinaryOperatorBits;
1048
    CXXBoolLiteralExprBitfields CXXBoolLiteralExprBits;
1049
    CXXNullPtrLiteralExprBitfields CXXNullPtrLiteralExprBits;
1050
    CXXThisExprBitfields CXXThisExprBits;
1051
    CXXThrowExprBitfields CXXThrowExprBits;
1052
    CXXDefaultArgExprBitfields CXXDefaultArgExprBits;
1053
    CXXDefaultInitExprBitfields CXXDefaultInitExprBits;
1054
    CXXScalarValueInitExprBitfields CXXScalarValueInitExprBits;
1055
    CXXNewExprBitfields CXXNewExprBits;
1056
    CXXDeleteExprBitfields CXXDeleteExprBits;
1057
    TypeTraitExprBitfields TypeTraitExprBits;
1058
    DependentScopeDeclRefExprBitfields DependentScopeDeclRefExprBits;
1059
    CXXConstructExprBitfields CXXConstructExprBits;
1060
    ExprWithCleanupsBitfields ExprWithCleanupsBits;
1061
    CXXUnresolvedConstructExprBitfields CXXUnresolvedConstructExprBits;
1062
    CXXDependentScopeMemberExprBitfields CXXDependentScopeMemberExprBits;
1063
    OverloadExprBitfields OverloadExprBits;
1064
    UnresolvedLookupExprBitfields UnresolvedLookupExprBits;
1065
    UnresolvedMemberExprBitfields UnresolvedMemberExprBits;
1066
    CXXNoexceptExprBitfields CXXNoexceptExprBits;
1067
    SubstNonTypeTemplateParmExprBitfields SubstNonTypeTemplateParmExprBits;
1068
    LambdaExprBitfields LambdaExprBits;
1069
    RequiresExprBitfields RequiresExprBits;
1070
1071
    // C++ Coroutines TS expressions
1072
    CoawaitExprBitfields CoawaitBits;
1073
1074
    // Obj-C Expressions
1075
    ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
1076
1077
    // Clang Extensions
1078
    OpaqueValueExprBitfields OpaqueValueExprBits;
1079
  };
1080
1081
public:
1082
  // Only allow allocation of Stmts using the allocator in ASTContext
1083
  // or by doing a placement new.
1084
  void* operator new(size_t bytes, const ASTContext& C,
1085
                     unsigned alignment = 8);
1086
1087
  void* operator new(size_t bytes, const ASTContext* C,
1088
11.9k
                     unsigned alignment = 8) {
1089
11.9k
    return operator new(bytes, *C, alignment);
1090
11.9k
  }
1091
1092
95.8M
  void *operator new(size_t bytes, void *mem) noexcept { return mem; }
1093
1094
0
  void operator delete(void *, const ASTContext &, unsigned) noexcept {}
1095
0
  void operator delete(void *, const ASTContext *, unsigned) noexcept {}
1096
0
  void operator delete(void *, size_t) noexcept {}
1097
0
  void operator delete(void *, void *) noexcept {}
1098
1099
public:
1100
  /// A placeholder type used to construct an empty shell of a
1101
  /// type, that will be filled in later (e.g., by some
1102
  /// de-serialization).
1103
  struct EmptyShell {};
1104
1105
  /// The likelihood of a branch being taken.
1106
  enum Likelihood {
1107
    LH_Unlikely = -1, ///< Branch has the [[unlikely]] attribute.
1108
    LH_None,          ///< No attribute set or branches of the IfStmt have
1109
                      ///< the same attribute.
1110
    LH_Likely         ///< Branch has the [[likely]] attribute.
1111
  };
1112
1113
protected:
1114
  /// Iterator for iterating over Stmt * arrays that contain only T *.
1115
  ///
1116
  /// This is needed because AST nodes use Stmt* arrays to store
1117
  /// references to children (to be compatible with StmtIterator).
1118
  template<typename T, typename TPtr = T *, typename StmtPtr = Stmt *>
1119
  struct CastIterator
1120
      : llvm::iterator_adaptor_base<CastIterator<T, TPtr, StmtPtr>, StmtPtr *,
1121
                                    std::random_access_iterator_tag, TPtr> {
1122
    using Base = typename CastIterator::iterator_adaptor_base;
1123
1124
    CastIterator() : Base(nullptr) {}
1125
15.8M
    CastIterator(StmtPtr *I) : Base(I) {}
clang::Stmt::CastIterator<clang::Expr, clang::Expr*, clang::Stmt*>::CastIterator(clang::Stmt**)
Line
Count
Source
1125
8.39M
    CastIterator(StmtPtr *I) : Base(I) {}
clang::Stmt::CastIterator<clang::Expr, clang::Expr const* const, clang::Stmt const* const>::CastIterator(clang::Stmt const* const*)
Line
Count
Source
1125
7.49M
    CastIterator(StmtPtr *I) : Base(I) {}
clang::Stmt::CastIterator<clang::ObjCAtCatchStmt, clang::ObjCAtCatchStmt*, clang::Stmt*>::CastIterator(clang::Stmt**)
Line
Count
Source
1125
336
    CastIterator(StmtPtr *I) : Base(I) {}
clang::Stmt::CastIterator<clang::AddrLabelExpr, clang::AddrLabelExpr const* const, clang::Stmt const* const>::CastIterator(clang::Stmt const* const*)
Line
Count
Source
1125
464
    CastIterator(StmtPtr *I) : Base(I) {}
clang::Stmt::CastIterator<clang::AddrLabelExpr, clang::AddrLabelExpr*, clang::Stmt*>::CastIterator(clang::Stmt**)
Line
Count
Source
1125
236
    CastIterator(StmtPtr *I) : Base(I) {}
clang::Stmt::CastIterator<clang::ObjCAtCatchStmt, clang::ObjCAtCatchStmt const* const, clang::Stmt const* const>::CastIterator(clang::Stmt const* const*)
Line
Count
Source
1125
424
    CastIterator(StmtPtr *I) : Base(I) {}
1126
1127
14.2M
    typename Base::value_type operator*() const {
1128
14.2M
      return cast_or_null<T>(*this->I);
1129
14.2M
    }
clang::Stmt::CastIterator<clang::Expr, clang::Expr*, clang::Stmt*>::operator*() const
Line
Count
Source
1127
6.33M
    typename Base::value_type operator*() const {
1128
6.33M
      return cast_or_null<T>(*this->I);
1129
6.33M
    }
clang::Stmt::CastIterator<clang::Expr, clang::Expr const* const, clang::Stmt const* const>::operator*() const
Line
Count
Source
1127
7.87M
    typename Base::value_type operator*() const {
1128
7.87M
      return cast_or_null<T>(*this->I);
1129
7.87M
    }
clang::Stmt::CastIterator<clang::ObjCAtCatchStmt, clang::ObjCAtCatchStmt*, clang::Stmt*>::operator*() const
Line
Count
Source
1127
223
    typename Base::value_type operator*() const {
1128
223
      return cast_or_null<T>(*this->I);
1129
223
    }
clang::Stmt::CastIterator<clang::AddrLabelExpr, clang::AddrLabelExpr const* const, clang::Stmt const* const>::operator*() const
Line
Count
Source
1127
233
    typename Base::value_type operator*() const {
1128
233
      return cast_or_null<T>(*this->I);
1129
233
    }
clang::Stmt::CastIterator<clang::AddrLabelExpr, clang::AddrLabelExpr*, clang::Stmt*>::operator*() const
Line
Count
Source
1127
24
    typename Base::value_type operator*() const {
1128
24
      return cast_or_null<T>(*this->I);
1129
24
    }
clang::Stmt::CastIterator<clang::ObjCAtCatchStmt, clang::ObjCAtCatchStmt const* const, clang::Stmt const* const>::operator*() const
Line
Count
Source
1127
259
    typename Base::value_type operator*() const {
1128
259
      return cast_or_null<T>(*this->I);
1129
259
    }
1130
  };
1131
1132
  /// Const iterator for iterating over Stmt * arrays that contain only T *.
1133
  template <typename T>
1134
  using ConstCastIterator = CastIterator<T, const T *const, const Stmt *const>;
1135
1136
  using ExprIterator = CastIterator<Expr>;
1137
  using ConstExprIterator = ConstCastIterator<Expr>;
1138
1139
private:
1140
  /// Whether statistic collection is enabled.
1141
  static bool StatisticsEnabled;
1142
1143
protected:
1144
  /// Construct an empty statement.
1145
683k
  explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {}
1146
1147
public:
1148
  Stmt() = delete;
1149
  Stmt(const Stmt &) = delete;
1150
  Stmt(Stmt &&) = delete;
1151
  Stmt &operator=(const Stmt &) = delete;
1152
  Stmt &operator=(Stmt &&) = delete;
1153
1154
120M
  Stmt(StmtClass SC) {
1155
120M
    static_assert(sizeof(*this) <= 8,
1156
120M
                  "changing bitfields changed sizeof(Stmt)");
1157
120M
    static_assert(sizeof(*this) % alignof(void *) == 0,
1158
120M
                  "Insufficient alignment!");
1159
120M
    StmtBits.sClass = SC;
1160
120M
    if (StatisticsEnabled) 
Stmt::addStmtClass(SC)14
;
1161
120M
  }
1162
1163
7.05G
  StmtClass getStmtClass() const {
1164
7.05G
    return static_cast<StmtClass>(StmtBits.sClass);
1165
7.05G
  }
1166
1167
  const char *getStmtClassName() const;
1168
1169
  /// SourceLocation tokens are not useful in isolation - they are low level
1170
  /// value objects created/interpreted by SourceManager. We assume AST
1171
  /// clients will have a pointer to the respective SourceManager.
1172
  SourceRange getSourceRange() const LLVM_READONLY;
1173
  SourceLocation getBeginLoc() const LLVM_READONLY;
1174
  SourceLocation getEndLoc() const LLVM_READONLY;
1175
1176
  // global temp stats (until we have a per-module visitor)
1177
  static void addStmtClass(const StmtClass s);
1178
  static void EnableStatistics();
1179
  static void PrintStats();
1180
1181
  /// \returns the likelihood of a set of attributes.
1182
  static Likelihood getLikelihood(ArrayRef<const Attr *> Attrs);
1183
1184
  /// \returns the likelihood of a statement.
1185
  static Likelihood getLikelihood(const Stmt *S);
1186
1187
  /// \returns the likelihood attribute of a statement.
1188
  static const Attr *getLikelihoodAttr(const Stmt *S);
1189
1190
  /// \returns the likelihood of the 'then' branch of an 'if' statement. The
1191
  /// 'else' branch is required to determine whether both branches specify the
1192
  /// same likelihood, which affects the result.
1193
  static Likelihood getLikelihood(const Stmt *Then, const Stmt *Else);
1194
1195
  /// \returns whether the likelihood of the branches of an if statement are
1196
  /// conflicting. When the first element is \c true there's a conflict and
1197
  /// the Attr's are the conflicting attributes of the Then and Else Stmt.
1198
  static std::tuple<bool, const Attr *, const Attr *>
1199
  determineLikelihoodConflict(const Stmt *Then, const Stmt *Else);
1200
1201
  /// Dumps the specified AST fragment and all subtrees to
1202
  /// \c llvm::errs().
1203
  void dump() const;
1204
  void dump(raw_ostream &OS, const ASTContext &Context) const;
1205
1206
  /// \return Unique reproducible object identifier
1207
  int64_t getID(const ASTContext &Context) const;
1208
1209
  /// dumpColor - same as dump(), but forces color highlighting.
1210
  void dumpColor() const;
1211
1212
  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
1213
  /// back to its original source language syntax.
1214
  void dumpPretty(const ASTContext &Context) const;
1215
  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
1216
                   const PrintingPolicy &Policy, unsigned Indentation = 0,
1217
                   StringRef NewlineSymbol = "\n",
1218
                   const ASTContext *Context = nullptr) const;
1219
  void printPrettyControlled(raw_ostream &OS, PrinterHelper *Helper,
1220
                             const PrintingPolicy &Policy,
1221
                             unsigned Indentation = 0,
1222
                             StringRef NewlineSymbol = "\n",
1223
                             const ASTContext *Context = nullptr) const;
1224
1225
  /// Pretty-prints in JSON format.
1226
  void printJson(raw_ostream &Out, PrinterHelper *Helper,
1227
                 const PrintingPolicy &Policy, bool AddQuotes) const;
1228
1229
  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
1230
  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
1231
  void viewAST() const;
1232
1233
  /// Skip no-op (attributed, compound) container stmts and skip captured
1234
  /// stmt at the top, if \a IgnoreCaptured is true.
1235
  Stmt *IgnoreContainers(bool IgnoreCaptured = false);
1236
70.0k
  const Stmt *IgnoreContainers(bool IgnoreCaptured = false) const {
1237
70.0k
    return const_cast<Stmt *>(this)->IgnoreContainers(IgnoreCaptured);
1238
70.0k
  }
1239
1240
  const Stmt *stripLabelLikeStatements() const;
1241
782k
  Stmt *stripLabelLikeStatements() {
1242
782k
    return const_cast<Stmt*>(
1243
782k
      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
1244
782k
  }
1245
1246
  /// Child Iterators: All subclasses must implement 'children'
1247
  /// to permit easy iteration over the substatements/subexpessions of an
1248
  /// AST node.  This permits easy iteration over all nodes in the AST.
1249
  using child_iterator = StmtIterator;
1250
  using const_child_iterator = ConstStmtIterator;
1251
1252
  using child_range = llvm::iterator_range<child_iterator>;
1253
  using const_child_range = llvm::iterator_range<const_child_iterator>;
1254
1255
  child_range children();
1256
1257
54.2M
  const_child_range children() const {
1258
54.2M
    auto Children = const_cast<Stmt *>(this)->children();
1259
54.2M
    return const_child_range(Children.begin(), Children.end());
1260
54.2M
  }
1261
1262
14.7k
  child_iterator child_begin() { return children().begin(); }
1263
18
  child_iterator child_end() { return children().end(); }
1264
1265
2.58k
  const_child_iterator child_begin() const { return children().begin(); }
1266
4.40k
  const_child_iterator child_end() const { return children().end(); }
1267
1268
  /// Produce a unique representation of the given statement.
1269
  ///
1270
  /// \param ID once the profiling operation is complete, will contain
1271
  /// the unique representation of the given statement.
1272
  ///
1273
  /// \param Context the AST context in which the statement resides
1274
  ///
1275
  /// \param Canonical whether the profile should be based on the canonical
1276
  /// representation of this statement (e.g., where non-type template
1277
  /// parameters are identified by index/level rather than their
1278
  /// declaration pointers) or the exact representation of the statement as
1279
  /// written in the source.
1280
  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
1281
               bool Canonical) const;
1282
1283
  /// Calculate a unique representation for a statement that is
1284
  /// stable across compiler invocations.
1285
  ///
1286
  /// \param ID profile information will be stored in ID.
1287
  ///
1288
  /// \param Hash an ODRHash object which will be called where pointers would
1289
  /// have been used in the Profile function.
1290
  void ProcessODRHash(llvm::FoldingSetNodeID &ID, ODRHash& Hash) const;
1291
};
1292
1293
/// DeclStmt - Adaptor class for mixing declarations with statements and
1294
/// expressions. For example, CompoundStmt mixes statements, expressions
1295
/// and declarations (variables, types). Another example is ForStmt, where
1296
/// the first statement can be an expression or a declaration.
1297
class DeclStmt : public Stmt {
1298
  DeclGroupRef DG;
1299
  SourceLocation StartLoc, EndLoc;
1300
1301
public:
1302
  DeclStmt(DeclGroupRef dg, SourceLocation startLoc, SourceLocation endLoc)
1303
1.71M
      : Stmt(DeclStmtClass), DG(dg), StartLoc(startLoc), EndLoc(endLoc) {}
1304
1305
  /// Build an empty declaration statement.
1306
135k
  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) {}
1307
1308
  /// isSingleDecl - This method returns true if this DeclStmt refers
1309
  /// to a single Decl.
1310
698k
  bool isSingleDecl() const { return DG.isSingleDecl(); }
1311
1312
86.2k
  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
1313
632k
  Decl *getSingleDecl() { return DG.getSingleDecl(); }
1314
1315
2.07k
  const DeclGroupRef getDeclGroup() const { return DG; }
1316
189k
  DeclGroupRef getDeclGroup() { return DG; }
1317
135k
  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
1318
1319
135k
  void setStartLoc(SourceLocation L) { StartLoc = L; }
1320
730k
  SourceLocation getEndLoc() const { return EndLoc; }
1321
135k
  void setEndLoc(SourceLocation L) { EndLoc = L; }
1322
1323
1.18M
  SourceLocation getBeginLoc() const LLVM_READONLY { return StartLoc; }
1324
1325
2.42M
  static bool classof(const Stmt *T) {
1326
2.42M
    return T->getStmtClass() == DeclStmtClass;
1327
2.42M
  }
1328
1329
  // Iterators over subexpressions.
1330
268k
  child_range children() {
1331
268k
    return child_range(child_iterator(DG.begin(), DG.end()),
1332
268k
                       child_iterator(DG.end(), DG.end()));
1333
268k
  }
1334
1335
0
  const_child_range children() const {
1336
0
    auto Children = const_cast<DeclStmt *>(this)->children();
1337
0
    return const_child_range(Children);
1338
0
  }
1339
1340
  using decl_iterator = DeclGroupRef::iterator;
1341
  using const_decl_iterator = DeclGroupRef::const_iterator;
1342
  using decl_range = llvm::iterator_range<decl_iterator>;
1343
  using decl_const_range = llvm::iterator_range<const_decl_iterator>;
1344
1345
501k
  decl_range decls() { return decl_range(decl_begin(), decl_end()); }
1346
1347
316k
  decl_const_range decls() const {
1348
316k
    return decl_const_range(decl_begin(), decl_end());
1349
316k
  }
1350
1351
685k
  decl_iterator decl_begin() { return DG.begin(); }
1352
505k
  decl_iterator decl_end() { return DG.end(); }
1353
383k
  const_decl_iterator decl_begin() const { return DG.begin(); }
1354
316k
  const_decl_iterator decl_end() const { return DG.end(); }
1355
1356
  using reverse_decl_iterator = std::reverse_iterator<decl_iterator>;
1357
1358
3.47k
  reverse_decl_iterator decl_rbegin() {
1359
3.47k
    return reverse_decl_iterator(decl_end());
1360
3.47k
  }
1361
1362
3.47k
  reverse_decl_iterator decl_rend() {
1363
3.47k
    return reverse_decl_iterator(decl_begin());
1364
3.47k
  }
1365
};
1366
1367
/// NullStmt - This is the null statement ";": C99 6.8.3p3.
1368
///
1369
class NullStmt : public Stmt {
1370
public:
1371
  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
1372
37.9k
      : Stmt(NullStmtClass) {
1373
37.9k
    NullStmtBits.HasLeadingEmptyMacro = hasLeadingEmptyMacro;
1374
37.9k
    setSemiLoc(L);
1375
37.9k
  }
1376
1377
  /// Build an empty null statement.
1378
1.00k
  explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) {}
1379
1380
13.7k
  SourceLocation getSemiLoc() const { return NullStmtBits.SemiLoc; }
1381
38.9k
  void setSemiLoc(SourceLocation L) { NullStmtBits.SemiLoc = L; }
1382
1383
1.64k
  bool hasLeadingEmptyMacro() const {
1384
1.64k
    return NullStmtBits.HasLeadingEmptyMacro;
1385
1.64k
  }
1386
1387
2.50k
  SourceLocation getBeginLoc() const { return getSemiLoc(); }
1388
5.09k
  SourceLocation getEndLoc() const { return getSemiLoc(); }
1389
1390
1.23M
  static bool classof(const Stmt *T) {
1391
1.23M
    return T->getStmtClass() == NullStmtClass;
1392
1.23M
  }
1393
1394
23.2k
  child_range children() {
1395
23.2k
    return child_range(child_iterator(), child_iterator());
1396
23.2k
  }
1397
1398
0
  const_child_range children() const {
1399
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1400
0
  }
1401
};
1402
1403
/// CompoundStmt - This represents a group of statements like { stmt stmt }.
1404
class CompoundStmt final : public Stmt,
1405
                           private llvm::TrailingObjects<CompoundStmt, Stmt *> {
1406
  friend class ASTStmtReader;
1407
  friend TrailingObjects;
1408
1409
  /// The location of the closing "}". LBraceLoc is stored in CompoundStmtBits.
1410
  SourceLocation RBraceLoc;
1411
1412
  CompoundStmt(ArrayRef<Stmt *> Stmts, SourceLocation LB, SourceLocation RB);
1413
268k
  explicit CompoundStmt(EmptyShell Empty) : Stmt(CompoundStmtClass, Empty) {}
1414
1415
  void setStmts(ArrayRef<Stmt *> Stmts);
1416
1417
public:
1418
  static CompoundStmt *Create(const ASTContext &C, ArrayRef<Stmt *> Stmts,
1419
                              SourceLocation LB, SourceLocation RB);
1420
1421
  // Build an empty compound statement with a location.
1422
  explicit CompoundStmt(SourceLocation Loc)
1423
34.0k
      : Stmt(CompoundStmtClass), RBraceLoc(Loc) {
1424
34.0k
    CompoundStmtBits.NumStmts = 0;
1425
34.0k
    CompoundStmtBits.LBraceLoc = Loc;
1426
34.0k
  }
1427
1428
  // Build an empty compound statement.
1429
  static CompoundStmt *CreateEmpty(const ASTContext &C, unsigned NumStmts);
1430
1431
428k
  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
1432
7.61M
  unsigned size() const { return CompoundStmtBits.NumStmts; }
1433
1434
  using body_iterator = Stmt **;
1435
  using body_range = llvm::iterator_range<body_iterator>;
1436
1437
1.82M
  body_range body() { return body_range(body_begin(), body_end()); }
1438
10.3M
  body_iterator body_begin() { return getTrailingObjects<Stmt *>(); }
1439
2.96M
  body_iterator body_end() { return body_begin() + size(); }
1440
1.01k
  Stmt *body_front() { return !body_empty() ? body_begin()[0] : 
nullptr0
; }
1441
1442
110k
  Stmt *body_back() {
1443
110k
    return !body_empty() ? 
body_begin()[size() - 1]30.9k
:
nullptr79.4k
;
1444
110k
  }
1445
1446
  using const_body_iterator = Stmt *const *;
1447
  using body_const_range = llvm::iterator_range<const_body_iterator>;
1448
1449
3.99M
  body_const_range body() const {
1450
3.99M
    return body_const_range(body_begin(), body_end());
1451
3.99M
  }
1452
1453
8.25M
  const_body_iterator body_begin() const {
1454
8.25M
    return getTrailingObjects<Stmt *>();
1455
8.25M
  }
1456
1457
4.12M
  const_body_iterator body_end() const { return body_begin() + size(); }
1458
1459
1
  const Stmt *body_front() const {
1460
1
    return !body_empty() ? body_begin()[0] : 
nullptr0
;
1461
1
  }
1462
1463
4.86k
  const Stmt *body_back() const {
1464
4.86k
    return !body_empty() ? body_begin()[size() - 1] : 
nullptr0
;
1465
4.86k
  }
1466
1467
  using reverse_body_iterator = std::reverse_iterator<body_iterator>;
1468
1469
258k
  reverse_body_iterator body_rbegin() {
1470
258k
    return reverse_body_iterator(body_end());
1471
258k
  }
1472
1473
0
  reverse_body_iterator body_rend() {
1474
0
    return reverse_body_iterator(body_begin());
1475
0
  }
1476
1477
  using const_reverse_body_iterator =
1478
      std::reverse_iterator<const_body_iterator>;
1479
1480
120k
  const_reverse_body_iterator body_rbegin() const {
1481
120k
    return const_reverse_body_iterator(body_end());
1482
120k
  }
1483
1484
120k
  const_reverse_body_iterator body_rend() const {
1485
120k
    return const_reverse_body_iterator(body_begin());
1486
120k
  }
1487
1488
  // Get the Stmt that StmtExpr would consider to be the result of this
1489
  // compound statement. This is used by StmtExpr to properly emulate the GCC
1490
  // compound expression extension, which ignores trailing NullStmts when
1491
  // getting the result of the expression.
1492
  // i.e. ({ 5;;; })
1493
  //           ^^ ignored
1494
  // If we don't find something that isn't a NullStmt, just return the last
1495
  // Stmt.
1496
576k
  Stmt *getStmtExprResult() {
1497
576k
    for (auto *B : llvm::reverse(body())) {
1498
496k
      if (!isa<NullStmt>(B))
1499
496k
        return B;
1500
496k
    }
1501
79.4k
    return body_back();
1502
576k
  }
1503
1504
322k
  const Stmt *getStmtExprResult() const {
1505
322k
    return const_cast<CompoundStmt *>(this)->getStmtExprResult();
1506
322k
  }
1507
1508
773k
  SourceLocation getBeginLoc() const { return CompoundStmtBits.LBraceLoc; }
1509
4.78M
  SourceLocation getEndLoc() const { return RBraceLoc; }
1510
1511
724k
  SourceLocation getLBracLoc() const { return CompoundStmtBits.LBraceLoc; }
1512
616k
  SourceLocation getRBracLoc() const { return RBraceLoc; }
1513
1514
6.91M
  static bool classof(const Stmt *T) {
1515
6.91M
    return T->getStmtClass() == CompoundStmtClass;
1516
6.91M
  }
1517
1518
  // Iterators
1519
862k
  child_range children() { return child_range(body_begin(), body_end()); }
1520
1521
104
  const_child_range children() const {
1522
104
    return const_child_range(body_begin(), body_end());
1523
104
  }
1524
};
1525
1526
// SwitchCase is the base class for CaseStmt and DefaultStmt,
1527
class SwitchCase : public Stmt {
1528
protected:
1529
  /// The location of the ":".
1530
  SourceLocation ColonLoc;
1531
1532
  // The location of the "case" or "default" keyword. Stored in SwitchCaseBits.
1533
  // SourceLocation KeywordLoc;
1534
1535
  /// A pointer to the following CaseStmt or DefaultStmt class,
1536
  /// used by SwitchStmt.
1537
  SwitchCase *NextSwitchCase = nullptr;
1538
1539
  SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
1540
27.2k
      : Stmt(SC), ColonLoc(ColonLoc) {
1541
27.2k
    setKeywordLoc(KWLoc);
1542
27.2k
  }
1543
1544
2.70k
  SwitchCase(StmtClass SC, EmptyShell) : Stmt(SC) {}
1545
1546
public:
1547
1.00k
  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
1548
62.8k
  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
1549
28.6k
  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
1550
1551
28.8k
  SourceLocation getKeywordLoc() const { return SwitchCaseBits.KeywordLoc; }
1552
29.9k
  void setKeywordLoc(SourceLocation L) { SwitchCaseBits.KeywordLoc = L; }
1553
6.68k
  SourceLocation getColonLoc() const { return ColonLoc; }
1554
2.70k
  void setColonLoc(SourceLocation L) { ColonLoc = L; }
1555
1556
  inline Stmt *getSubStmt();
1557
353k
  const Stmt *getSubStmt() const {
1558
353k
    return const_cast<SwitchCase *>(this)->getSubStmt();
1559
353k
  }
1560
1561
45
  SourceLocation getBeginLoc() const { return getKeywordLoc(); }
1562
  inline SourceLocation getEndLoc() const LLVM_READONLY;
1563
1564
8.32M
  static bool classof(const Stmt *T) {
1565
8.32M
    return T->getStmtClass() == CaseStmtClass ||
1566
8.32M
           
T->getStmtClass() == DefaultStmtClass7.93M
;
1567
8.32M
  }
1568
};
1569
1570
/// CaseStmt - Represent a case statement. It can optionally be a GNU case
1571
/// statement of the form LHS ... RHS representing a range of cases.
1572
class CaseStmt final
1573
    : public SwitchCase,
1574
      private llvm::TrailingObjects<CaseStmt, Stmt *, SourceLocation> {
1575
  friend TrailingObjects;
1576
1577
  // CaseStmt is followed by several trailing objects, some of which optional.
1578
  // Note that it would be more convenient to put the optional trailing objects
1579
  // at the end but this would impact children().
1580
  // The trailing objects are in order:
1581
  //
1582
  // * A "Stmt *" for the LHS of the case statement. Always present.
1583
  //
1584
  // * A "Stmt *" for the RHS of the case statement. This is a GNU extension
1585
  //   which allow ranges in cases statement of the form LHS ... RHS.
1586
  //   Present if and only if caseStmtIsGNURange() is true.
1587
  //
1588
  // * A "Stmt *" for the substatement of the case statement. Always present.
1589
  //
1590
  // * A SourceLocation for the location of the ... if this is a case statement
1591
  //   with a range. Present if and only if caseStmtIsGNURange() is true.
1592
  enum { LhsOffset = 0, SubStmtOffsetFromRhs = 1 };
1593
  enum { NumMandatoryStmtPtr = 2 };
1594
1595
9.38k
  unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
1596
9.38k
    return NumMandatoryStmtPtr + caseStmtIsGNURange();
1597
9.38k
  }
1598
1599
0
  unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1600
0
    return caseStmtIsGNURange();
1601
0
  }
1602
1603
49.0k
  unsigned lhsOffset() const { return LhsOffset; }
1604
437k
  unsigned rhsOffset() const { return LhsOffset + caseStmtIsGNURange(); }
1605
436k
  unsigned subStmtOffset() const { return rhsOffset() + SubStmtOffsetFromRhs; }
1606
1607
  /// Build a case statement assuming that the storage for the
1608
  /// trailing objects has been properly allocated.
1609
  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
1610
           SourceLocation ellipsisLoc, SourceLocation colonLoc)
1611
24.9k
      : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
1612
    // Handle GNU case statements of the form LHS ... RHS.
1613
24.9k
    bool IsGNURange = rhs != nullptr;
1614
24.9k
    SwitchCaseBits.CaseStmtIsGNURange = IsGNURange;
1615
24.9k
    setLHS(lhs);
1616
24.9k
    setSubStmt(nullptr);
1617
24.9k
    if (IsGNURange) {
1618
108
      setRHS(rhs);
1619
108
      setEllipsisLoc(ellipsisLoc);
1620
108
    }
1621
24.9k
  }
1622
1623
  /// Build an empty switch case statement.
1624
  explicit CaseStmt(EmptyShell Empty, bool CaseStmtIsGNURange)
1625
2.47k
      : SwitchCase(CaseStmtClass, Empty) {
1626
2.47k
    SwitchCaseBits.CaseStmtIsGNURange = CaseStmtIsGNURange;
1627
2.47k
  }
1628
1629
public:
1630
  /// Build a case statement.
1631
  static CaseStmt *Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs,
1632
                          SourceLocation caseLoc, SourceLocation ellipsisLoc,
1633
                          SourceLocation colonLoc);
1634
1635
  /// Build an empty case statement.
1636
  static CaseStmt *CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange);
1637
1638
  /// True if this case statement is of the form case LHS ... RHS, which
1639
  /// is a GNU extension. In this case the RHS can be obtained with getRHS()
1640
  /// and the location of the ellipsis can be obtained with getEllipsisLoc().
1641
472k
  bool caseStmtIsGNURange() const { return SwitchCaseBits.CaseStmtIsGNURange; }
1642
1643
3.99k
  SourceLocation getCaseLoc() const { return getKeywordLoc(); }
1644
0
  void setCaseLoc(SourceLocation L) { setKeywordLoc(L); }
1645
1646
  /// Get the location of the ... in a case statement of the form LHS ... RHS.
1647
2.91k
  SourceLocation getEllipsisLoc() const {
1648
2.91k
    return caseStmtIsGNURange() ? 
*getTrailingObjects<SourceLocation>()7
1649
2.91k
                                : 
SourceLocation()2.90k
;
1650
2.91k
  }
1651
1652
  /// Set the location of the ... in a case statement of the form LHS ... RHS.
1653
  /// Assert that this case statement is of this form.
1654
109
  void setEllipsisLoc(SourceLocation L) {
1655
109
    assert(
1656
109
        caseStmtIsGNURange() &&
1657
109
        "setEllipsisLoc but this is not a case stmt of the form LHS ... RHS!");
1658
0
    *getTrailingObjects<SourceLocation>() = L;
1659
109
  }
1660
1661
18.9k
  Expr *getLHS() {
1662
18.9k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]);
1663
18.9k
  }
1664
1665
2.68k
  const Expr *getLHS() const {
1666
2.68k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]);
1667
2.68k
  }
1668
1669
27.4k
  void setLHS(Expr *Val) {
1670
27.4k
    getTrailingObjects<Stmt *>()[lhsOffset()] = reinterpret_cast<Stmt *>(Val);
1671
27.4k
  }
1672
1673
13.8k
  Expr *getRHS() {
1674
13.8k
    return caseStmtIsGNURange() ? reinterpret_cast<Expr *>(
1675
364
                                      getTrailingObjects<Stmt *>()[rhsOffset()])
1676
13.8k
                                : 
nullptr13.4k
;
1677
13.8k
  }
1678
1679
2.69k
  const Expr *getRHS() const {
1680
2.69k
    return caseStmtIsGNURange() ? reinterpret_cast<Expr *>(
1681
175
                                      getTrailingObjects<Stmt *>()[rhsOffset()])
1682
2.69k
                                : 
nullptr2.52k
;
1683
2.69k
  }
1684
1685
109
  void setRHS(Expr *Val) {
1686
109
    assert(caseStmtIsGNURange() &&
1687
109
           "setRHS but this is not a case stmt of the form LHS ... RHS!");
1688
0
    getTrailingObjects<Stmt *>()[rhsOffset()] = reinterpret_cast<Stmt *>(Val);
1689
109
  }
1690
1691
379k
  Stmt *getSubStmt() { return getTrailingObjects<Stmt *>()[subStmtOffset()]; }
1692
4.68k
  const Stmt *getSubStmt() const {
1693
4.68k
    return getTrailingObjects<Stmt *>()[subStmtOffset()];
1694
4.68k
  }
1695
1696
52.3k
  void setSubStmt(Stmt *S) {
1697
52.3k
    getTrailingObjects<Stmt *>()[subStmtOffset()] = S;
1698
52.3k
  }
1699
1700
19.6k
  SourceLocation getBeginLoc() const { return getKeywordLoc(); }
1701
822
  SourceLocation getEndLoc() const LLVM_READONLY {
1702
    // Handle deeply nested case statements with iteration instead of recursion.
1703
822
    const CaseStmt *CS = this;
1704
834
    while (const auto *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
1705
12
      CS = CS2;
1706
1707
822
    return CS->getSubStmt()->getEndLoc();
1708
822
  }
1709
1710
825k
  static bool classof(const Stmt *T) {
1711
825k
    return T->getStmtClass() == CaseStmtClass;
1712
825k
  }
1713
1714
  // Iterators
1715
9.27k
  child_range children() {
1716
9.27k
    return child_range(getTrailingObjects<Stmt *>(),
1717
9.27k
                       getTrailingObjects<Stmt *>() +
1718
9.27k
                           numTrailingObjects(OverloadToken<Stmt *>()));
1719
9.27k
  }
1720
1721
0
  const_child_range children() const {
1722
0
    return const_child_range(getTrailingObjects<Stmt *>(),
1723
0
                             getTrailingObjects<Stmt *>() +
1724
0
                                 numTrailingObjects(OverloadToken<Stmt *>()));
1725
0
  }
1726
};
1727
1728
class DefaultStmt : public SwitchCase {
1729
  Stmt *SubStmt;
1730
1731
public:
1732
  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt)
1733
2.26k
      : SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
1734
1735
  /// Build an empty default statement.
1736
  explicit DefaultStmt(EmptyShell Empty)
1737
233
      : SwitchCase(DefaultStmtClass, Empty) {}
1738
1739
2.83k
  Stmt *getSubStmt() { return SubStmt; }
1740
182
  const Stmt *getSubStmt() const { return SubStmt; }
1741
233
  void setSubStmt(Stmt *S) { SubStmt = S; }
1742
1743
348
  SourceLocation getDefaultLoc() const { return getKeywordLoc(); }
1744
0
  void setDefaultLoc(SourceLocation L) { setKeywordLoc(L); }
1745
1746
1.35k
  SourceLocation getBeginLoc() const { return getKeywordLoc(); }
1747
194
  SourceLocation getEndLoc() const LLVM_READONLY {
1748
194
    return SubStmt->getEndLoc();
1749
194
  }
1750
1751
21.4k
  static bool classof(const Stmt *T) {
1752
21.4k
    return T->getStmtClass() == DefaultStmtClass;
1753
21.4k
  }
1754
1755
  // Iterators
1756
1.30k
  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
1757
1758
0
  const_child_range children() const {
1759
0
    return const_child_range(&SubStmt, &SubStmt + 1);
1760
0
  }
1761
};
1762
1763
0
SourceLocation SwitchCase::getEndLoc() const {
1764
0
  if (const auto *CS = dyn_cast<CaseStmt>(this))
1765
0
    return CS->getEndLoc();
1766
0
  else if (const auto *DS = dyn_cast<DefaultStmt>(this))
1767
0
    return DS->getEndLoc();
1768
0
  llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
1769
0
}
1770
1771
373k
Stmt *SwitchCase::getSubStmt() {
1772
373k
  if (auto *CS = dyn_cast<CaseStmt>(this))
1773
371k
    return CS->getSubStmt();
1774
1.55k
  else if (auto *DS = dyn_cast<DefaultStmt>(this))
1775
1.55k
    return DS->getSubStmt();
1776
0
  llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
1777
0
}
1778
1779
/// Represents a statement that could possibly have a value and type. This
1780
/// covers expression-statements, as well as labels and attributed statements.
1781
///
1782
/// Value statements have a special meaning when they are the last non-null
1783
/// statement in a GNU statement expression, where they determine the value
1784
/// of the statement expression.
1785
class ValueStmt : public Stmt {
1786
protected:
1787
  using Stmt::Stmt;
1788
1789
public:
1790
  const Expr *getExprStmt() const;
1791
0
  Expr *getExprStmt() {
1792
0
    const ValueStmt *ConstThis = this;
1793
0
    return const_cast<Expr*>(ConstThis->getExprStmt());
1794
0
  }
1795
1796
33.3k
  static bool classof(const Stmt *T) {
1797
33.3k
    return T->getStmtClass() >= firstValueStmtConstant &&
1798
33.3k
           
T->getStmtClass() <= lastValueStmtConstant30.9k
;
1799
33.3k
  }
1800
};
1801
1802
/// LabelStmt - Represents a label, which has a substatement.  For example:
1803
///    foo: return;
1804
class LabelStmt : public ValueStmt {
1805
  LabelDecl *TheDecl;
1806
  Stmt *SubStmt;
1807
  bool SideEntry = false;
1808
1809
public:
1810
  /// Build a label statement.
1811
  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
1812
3.22k
      : ValueStmt(LabelStmtClass), TheDecl(D), SubStmt(substmt) {
1813
3.22k
    setIdentLoc(IL);
1814
3.22k
  }
1815
1816
  /// Build an empty label statement.
1817
26
  explicit LabelStmt(EmptyShell Empty) : ValueStmt(LabelStmtClass, Empty) {}
1818
1819
667
  SourceLocation getIdentLoc() const { return LabelStmtBits.IdentLoc; }
1820
3.25k
  void setIdentLoc(SourceLocation L) { LabelStmtBits.IdentLoc = L; }
1821
1822
2.06k
  LabelDecl *getDecl() const { return TheDecl; }
1823
26
  void setDecl(LabelDecl *D) { TheDecl = D; }
1824
1825
  const char *getName() const;
1826
3.30k
  Stmt *getSubStmt() { return SubStmt; }
1827
1828
958
  const Stmt *getSubStmt() const { return SubStmt; }
1829
26
  void setSubStmt(Stmt *SS) { SubStmt = SS; }
1830
1831
443
  SourceLocation getBeginLoc() const { return getIdentLoc(); }
1832
342
  SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();}
1833
1834
1.00k
  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
1835
1836
0
  const_child_range children() const {
1837
0
    return const_child_range(&SubStmt, &SubStmt + 1);
1838
0
  }
1839
1840
10.4M
  static bool classof(const Stmt *T) {
1841
10.4M
    return T->getStmtClass() == LabelStmtClass;
1842
10.4M
  }
1843
115
  bool isSideEntry() const { return SideEntry; }
1844
41
  void setSideEntry(bool SE) { SideEntry = SE; }
1845
};
1846
1847
/// Represents an attribute applied to a statement.
1848
///
1849
/// Represents an attribute applied to a statement. For example:
1850
///   [[omp::for(...)]] for (...) { ... }
1851
class AttributedStmt final
1852
    : public ValueStmt,
1853
      private llvm::TrailingObjects<AttributedStmt, const Attr *> {
1854
  friend class ASTStmtReader;
1855
  friend TrailingObjects;
1856
1857
  Stmt *SubStmt;
1858
1859
  AttributedStmt(SourceLocation Loc, ArrayRef<const Attr *> Attrs,
1860
                 Stmt *SubStmt)
1861
1.55k
      : ValueStmt(AttributedStmtClass), SubStmt(SubStmt) {
1862
1.55k
    AttributedStmtBits.NumAttrs = Attrs.size();
1863
1.55k
    AttributedStmtBits.AttrLoc = Loc;
1864
1.55k
    std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr());
1865
1.55k
  }
1866
1867
  explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
1868
34
      : ValueStmt(AttributedStmtClass, Empty) {
1869
34
    AttributedStmtBits.NumAttrs = NumAttrs;
1870
34
    AttributedStmtBits.AttrLoc = SourceLocation{};
1871
34
    std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
1872
34
  }
1873
1874
2.19k
  const Attr *const *getAttrArrayPtr() const {
1875
2.19k
    return getTrailingObjects<const Attr *>();
1876
2.19k
  }
1877
1.62k
  const Attr **getAttrArrayPtr() { return getTrailingObjects<const Attr *>(); }
1878
1879
public:
1880
  static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
1881
                                ArrayRef<const Attr *> Attrs, Stmt *SubStmt);
1882
1883
  // Build an empty attributed statement.
1884
  static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs);
1885
1886
166
  SourceLocation getAttrLoc() const { return AttributedStmtBits.AttrLoc; }
1887
2.19k
  ArrayRef<const Attr *> getAttrs() const {
1888
2.19k
    return llvm::makeArrayRef(getAttrArrayPtr(), AttributedStmtBits.NumAttrs);
1889
2.19k
  }
1890
1891
226
  Stmt *getSubStmt() { return SubStmt; }
1892
540
  const Stmt *getSubStmt() const { return SubStmt; }
1893
1894
66
  SourceLocation getBeginLoc() const { return getAttrLoc(); }
1895
75
  SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();}
1896
1897
1.45k
  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
1898
1899
0
  const_child_range children() const {
1900
0
    return const_child_range(&SubStmt, &SubStmt + 1);
1901
0
  }
1902
1903
2.07M
  static bool classof(const Stmt *T) {
1904
2.07M
    return T->getStmtClass() == AttributedStmtClass;
1905
2.07M
  }
1906
};
1907
1908
/// IfStmt - This represents an if/then/else.
1909
class IfStmt final
1910
    : public Stmt,
1911
      private llvm::TrailingObjects<IfStmt, Stmt *, SourceLocation> {
1912
  friend TrailingObjects;
1913
1914
  // IfStmt is followed by several trailing objects, some of which optional.
1915
  // Note that it would be more convenient to put the optional trailing
1916
  // objects at then end but this would change the order of the children.
1917
  // The trailing objects are in order:
1918
  //
1919
  // * A "Stmt *" for the init statement.
1920
  //    Present if and only if hasInitStorage().
1921
  //
1922
  // * A "Stmt *" for the condition variable.
1923
  //    Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
1924
  //
1925
  // * A "Stmt *" for the condition.
1926
  //    Always present. This is in fact a "Expr *".
1927
  //
1928
  // * A "Stmt *" for the then statement.
1929
  //    Always present.
1930
  //
1931
  // * A "Stmt *" for the else statement.
1932
  //    Present if and only if hasElseStorage().
1933
  //
1934
  // * A "SourceLocation" for the location of the "else".
1935
  //    Present if and only if hasElseStorage().
1936
  enum { InitOffset = 0, ThenOffsetFromCond = 1, ElseOffsetFromCond = 2 };
1937
  enum { NumMandatoryStmtPtr = 2 };
1938
  SourceLocation LParenLoc;
1939
  SourceLocation RParenLoc;
1940
1941
287k
  unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
1942
287k
    return NumMandatoryStmtPtr + hasElseStorage() + hasVarStorage() +
1943
287k
           hasInitStorage();
1944
287k
  }
1945
1946
0
  unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1947
0
    return hasElseStorage();
1948
0
  }
1949
1950
818
  unsigned initOffset() const { return InitOffset; }
1951
1.28k
  unsigned varOffset() const { return InitOffset + hasInitStorage(); }
1952
2.96M
  unsigned condOffset() const {
1953
2.96M
    return InitOffset + hasInitStorage() + hasVarStorage();
1954
2.96M
  }
1955
1.14M
  unsigned thenOffset() const { return condOffset() + ThenOffsetFromCond; }
1956
223k
  unsigned elseOffset() const { return condOffset() + ElseOffsetFromCond; }
1957
1958
  /// Build an if/then/else statement.
1959
  IfStmt(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind,
1960
         Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc,
1961
         SourceLocation RParenLoc, Stmt *Then, SourceLocation EL, Stmt *Else);
1962
1963
  /// Build an empty if/then/else statement.
1964
  explicit IfStmt(EmptyShell Empty, bool HasElse, bool HasVar, bool HasInit);
1965
1966
public:
1967
  /// Create an IfStmt.
1968
  static IfStmt *Create(const ASTContext &Ctx, SourceLocation IL,
1969
                        IfStatementKind Kind, Stmt *Init, VarDecl *Var,
1970
                        Expr *Cond, SourceLocation LPL, SourceLocation RPL,
1971
                        Stmt *Then, SourceLocation EL = SourceLocation(),
1972
                        Stmt *Else = nullptr);
1973
1974
  /// Create an empty IfStmt optionally with storage for an else statement,
1975
  /// condition variable and init expression.
1976
  static IfStmt *CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar,
1977
                             bool HasInit);
1978
1979
  /// True if this IfStmt has the storage for an init statement.
1980
3.74M
  bool hasInitStorage() const { return IfStmtBits.HasInit; }
1981
1982
  /// True if this IfStmt has storage for a variable declaration.
1983
3.88M
  bool hasVarStorage() const { return IfStmtBits.HasVar; }
1984
1985
  /// True if this IfStmt has storage for an else statement.
1986
1.16M
  bool hasElseStorage() const { return IfStmtBits.HasElse; }
1987
1988
521k
  Expr *getCond() {
1989
521k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
1990
521k
  }
1991
1992
410k
  const Expr *getCond() const {
1993
410k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
1994
410k
  }
1995
1996
660k
  void setCond(Expr *Cond) {
1997
660k
    getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
1998
660k
  }
1999
2000
241k
  Stmt *getThen() { return getTrailingObjects<Stmt *>()[thenOffset()]; }
2001
242k
  const Stmt *getThen() const {
2002
242k
    return getTrailingObjects<Stmt *>()[thenOffset()];
2003
242k
  }
2004
2005
660k
  void setThen(Stmt *Then) {
2006
660k
    getTrailingObjects<Stmt *>()[thenOffset()] = Then;
2007
660k
  }
2008
2009
248k
  Stmt *getElse() {
2010
248k
    return hasElseStorage() ? 
getTrailingObjects<Stmt *>()[elseOffset()]52.3k
2011
248k
                            : 
nullptr196k
;
2012
248k
  }
2013
2014
249k
  const Stmt *getElse() const {
2015
249k
    return hasElseStorage() ? 
getTrailingObjects<Stmt *>()[elseOffset()]33.9k
2016
249k
                            : 
nullptr215k
;
2017
249k
  }
2018
2019
136k
  void setElse(Stmt *Else) {
2020
136k
    assert(hasElseStorage() &&
2021
136k
           "This if statement has no storage for an else statement!");
2022
0
    getTrailingObjects<Stmt *>()[elseOffset()] = Else;
2023
136k
  }
2024
2025
  /// Retrieve the variable declared in this "if" statement, if any.
2026
  ///
2027
  /// In the following example, "x" is the condition variable.
2028
  /// \code
2029
  /// if (int x = foo()) {
2030
  ///   printf("x is %d", x);
2031
  /// }
2032
  /// \endcode
2033
  VarDecl *getConditionVariable();
2034
147k
  const VarDecl *getConditionVariable() const {
2035
147k
    return const_cast<IfStmt *>(this)->getConditionVariable();
2036
147k
  }
2037
2038
  /// Set the condition variable for this if statement.
2039
  /// The if statement must have storage for the condition variable.
2040
  void setConditionVariable(const ASTContext &Ctx, VarDecl *V);
2041
2042
  /// If this IfStmt has a condition variable, return the faux DeclStmt
2043
  /// associated with the creation of that condition variable.
2044
631k
  DeclStmt *getConditionVariableDeclStmt() {
2045
631k
    return hasVarStorage() ? static_cast<DeclStmt *>(
2046
797
                                 getTrailingObjects<Stmt *>()[varOffset()])
2047
631k
                           : 
nullptr630k
;
2048
631k
  }
2049
2050
118
  const DeclStmt *getConditionVariableDeclStmt() const {
2051
118
    return hasVarStorage() ? static_cast<DeclStmt *>(
2052
3
                                 getTrailingObjects<Stmt *>()[varOffset()])
2053
118
                           : 
nullptr115
;
2054
118
  }
2055
2056
377k
  Stmt *getInit() {
2057
377k
    return hasInitStorage() ? 
getTrailingObjects<Stmt *>()[initOffset()]54
2058
377k
                            : 
nullptr377k
;
2059
377k
  }
2060
2061
121k
  const Stmt *getInit() const {
2062
121k
    return hasInitStorage() ? 
getTrailingObjects<Stmt *>()[initOffset()]520
2063
121k
                            : 
nullptr121k
;
2064
121k
  }
2065
2066
244
  void setInit(Stmt *Init) {
2067
244
    assert(hasInitStorage() &&
2068
244
           "This if statement has no storage for an init statement!");
2069
0
    getTrailingObjects<Stmt *>()[initOffset()] = Init;
2070
244
  }
2071
2072
278k
  SourceLocation getIfLoc() const { return IfStmtBits.IfLoc; }
2073
660k
  void setIfLoc(SourceLocation IfLoc) { IfStmtBits.IfLoc = IfLoc; }
2074
2075
101k
  SourceLocation getElseLoc() const {
2076
101k
    return hasElseStorage() ? 
*getTrailingObjects<SourceLocation>()32.1k
2077
101k
                            : 
SourceLocation()69.4k
;
2078
101k
  }
2079
2080
136k
  void setElseLoc(SourceLocation ElseLoc) {
2081
136k
    assert(hasElseStorage() &&
2082
136k
           "This if statement has no storage for an else statement!");
2083
0
    *getTrailingObjects<SourceLocation>() = ElseLoc;
2084
136k
  }
2085
2086
523k
  bool isConsteval() const {
2087
523k
    return getStatementKind() == IfStatementKind::ConstevalNonNegated ||
2088
523k
           
getStatementKind() == IfStatementKind::ConstevalNegated523k
;
2089
523k
  }
2090
2091
29
  bool isNonNegatedConsteval() const {
2092
29
    return getStatementKind() == IfStatementKind::ConstevalNonNegated;
2093
29
  }
2094
2095
30
  bool isNegatedConsteval() const {
2096
30
    return getStatementKind() == IfStatementKind::ConstevalNegated;
2097
30
  }
2098
2099
208k
  bool isConstexpr() const {
2100
208k
    return getStatementKind() == IfStatementKind::Constexpr;
2101
208k
  }
2102
2103
660k
  void setStatementKind(IfStatementKind Kind) {
2104
660k
    IfStmtBits.Kind = static_cast<unsigned>(Kind);
2105
660k
  }
2106
2107
1.37M
  IfStatementKind getStatementKind() const {
2108
1.37M
    return static_cast<IfStatementKind>(IfStmtBits.Kind);
2109
1.37M
  }
2110
2111
  /// If this is an 'if constexpr', determine which substatement will be taken.
2112
  /// Otherwise, or if the condition is value-dependent, returns None.
2113
  Optional<const Stmt*> getNondiscardedCase(const ASTContext &Ctx) const;
2114
  Optional<Stmt *> getNondiscardedCase(const ASTContext &Ctx);
2115
2116
  bool isObjCAvailabilityCheck() const;
2117
2118
127k
  SourceLocation getBeginLoc() const { return getIfLoc(); }
2119
8.77k
  SourceLocation getEndLoc() const LLVM_READONLY {
2120
8.77k
    if (getElse())
2121
1.79k
      return getElse()->getEndLoc();
2122
6.97k
    return getThen()->getEndLoc();
2123
8.77k
  }
2124
124k
  SourceLocation getLParenLoc() const { return LParenLoc; }
2125
69.6k
  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2126
124k
  SourceLocation getRParenLoc() const { return RParenLoc; }
2127
69.6k
  void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
2128
2129
  // Iterators over subexpressions.  The iterators will include iterating
2130
  // over the initialization expression referenced by the condition variable.
2131
118k
  child_range children() {
2132
    // We always store a condition, but there is none for consteval if
2133
    // statements, so skip it.
2134
118k
    return child_range(getTrailingObjects<Stmt *>() +
2135
118k
                           (isConsteval() ? 
thenOffset()18
:
0118k
),
2136
118k
                       getTrailingObjects<Stmt *>() +
2137
118k
                           numTrailingObjects(OverloadToken<Stmt *>()));
2138
118k
  }
2139
2140
0
  const_child_range children() const {
2141
0
    // We always store a condition, but there is none for consteval if
2142
0
    // statements, so skip it.
2143
0
    return const_child_range(getTrailingObjects<Stmt *>() +
2144
0
                                 (isConsteval() ? thenOffset() : 0),
2145
0
                             getTrailingObjects<Stmt *>() +
2146
0
                                 numTrailingObjects(OverloadToken<Stmt *>()));
2147
0
  }
2148
2149
369k
  static bool classof(const Stmt *T) {
2150
369k
    return T->getStmtClass() == IfStmtClass;
2151
369k
  }
2152
};
2153
2154
/// SwitchStmt - This represents a 'switch' stmt.
2155
class SwitchStmt final : public Stmt,
2156
                         private llvm::TrailingObjects<SwitchStmt, Stmt *> {
2157
  friend TrailingObjects;
2158
2159
  /// Points to a linked list of case and default statements.
2160
  SwitchCase *FirstCase = nullptr;
2161
2162
  // SwitchStmt is followed by several trailing objects,
2163
  // some of which optional. Note that it would be more convenient to
2164
  // put the optional trailing objects at the end but this would change
2165
  // the order in children().
2166
  // The trailing objects are in order:
2167
  //
2168
  // * A "Stmt *" for the init statement.
2169
  //    Present if and only if hasInitStorage().
2170
  //
2171
  // * A "Stmt *" for the condition variable.
2172
  //    Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
2173
  //
2174
  // * A "Stmt *" for the condition.
2175
  //    Always present. This is in fact an "Expr *".
2176
  //
2177
  // * A "Stmt *" for the body.
2178
  //    Always present.
2179
  enum { InitOffset = 0, BodyOffsetFromCond = 1 };
2180
  enum { NumMandatoryStmtPtr = 2 };
2181
  SourceLocation LParenLoc;
2182
  SourceLocation RParenLoc;
2183
2184
7.48k
  unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2185
7.48k
    return NumMandatoryStmtPtr + hasInitStorage() + hasVarStorage();
2186
7.48k
  }
2187
2188
253
  unsigned initOffset() const { return InitOffset; }
2189
226
  unsigned varOffset() const { return InitOffset + hasInitStorage(); }
2190
63.7k
  unsigned condOffset() const {
2191
63.7k
    return InitOffset + hasInitStorage() + hasVarStorage();
2192
63.7k
  }
2193
20.3k
  unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
2194
2195
  /// Build a switch statement.
2196
  SwitchStmt(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond,
2197
             SourceLocation LParenLoc, SourceLocation RParenLoc);
2198
2199
  /// Build a empty switch statement.
2200
  explicit SwitchStmt(EmptyShell Empty, bool HasInit, bool HasVar);
2201
2202
public:
2203
  /// Create a switch statement.
2204
  static SwitchStmt *Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var,
2205
                            Expr *Cond, SourceLocation LParenLoc,
2206
                            SourceLocation RParenLoc);
2207
2208
  /// Create an empty switch statement optionally with storage for
2209
  /// an init expression and a condition variable.
2210
  static SwitchStmt *CreateEmpty(const ASTContext &Ctx, bool HasInit,
2211
                                 bool HasVar);
2212
2213
  /// True if this SwitchStmt has storage for an init statement.
2214
80.1k
  bool hasInitStorage() const { return SwitchStmtBits.HasInit; }
2215
2216
  /// True if this SwitchStmt has storage for a condition variable.
2217
80.4k
  bool hasVarStorage() const { return SwitchStmtBits.HasVar; }
2218
2219
33.4k
  Expr *getCond() {
2220
33.4k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2221
33.4k
  }
2222
2223
2.37k
  const Expr *getCond() const {
2224
2.37k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2225
2.37k
  }
2226
2227
7.58k
  void setCond(Expr *Cond) {
2228
7.58k
    getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2229
7.58k
  }
2230
2231
3.87k
  Stmt *getBody() { return getTrailingObjects<Stmt *>()[bodyOffset()]; }
2232
1.96k
  const Stmt *getBody() const {
2233
1.96k
    return getTrailingObjects<Stmt *>()[bodyOffset()];
2234
1.96k
  }
2235
2236
14.5k
  void setBody(Stmt *Body) {
2237
14.5k
    getTrailingObjects<Stmt *>()[bodyOffset()] = Body;
2238
14.5k
  }
2239
2240
7.65k
  Stmt *getInit() {
2241
7.65k
    return hasInitStorage() ? 
getTrailingObjects<Stmt *>()[initOffset()]103
2242
7.65k
                            : 
nullptr7.55k
;
2243
7.65k
  }
2244
2245
887
  const Stmt *getInit() const {
2246
887
    return hasInitStorage() ? 
getTrailingObjects<Stmt *>()[initOffset()]60
2247
887
                            : 
nullptr827
;
2248
887
  }
2249
2250
90
  void setInit(Stmt *Init) {
2251
90
    assert(hasInitStorage() &&
2252
90
           "This switch statement has no storage for an init statement!");
2253
0
    getTrailingObjects<Stmt *>()[initOffset()] = Init;
2254
90
  }
2255
2256
  /// Retrieve the variable declared in this "switch" statement, if any.
2257
  ///
2258
  /// In the following example, "x" is the condition variable.
2259
  /// \code
2260
  /// switch (int x = foo()) {
2261
  ///   case 0: break;
2262
  ///   // ...
2263
  /// }
2264
  /// \endcode
2265
  VarDecl *getConditionVariable();
2266
1.42k
  const VarDecl *getConditionVariable() const {
2267
1.42k
    return const_cast<SwitchStmt *>(this)->getConditionVariable();
2268
1.42k
  }
2269
2270
  /// Set the condition variable in this switch statement.
2271
  /// The switch statement must have storage for it.
2272
  void setConditionVariable(const ASTContext &Ctx, VarDecl *VD);
2273
2274
  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
2275
  /// associated with the creation of that condition variable.
2276
9.11k
  DeclStmt *getConditionVariableDeclStmt() {
2277
9.11k
    return hasVarStorage() ? static_cast<DeclStmt *>(
2278
170
                                 getTrailingObjects<Stmt *>()[varOffset()])
2279
9.11k
                           : 
nullptr8.94k
;
2280
9.11k
  }
2281
2282
2
  const DeclStmt *getConditionVariableDeclStmt() const {
2283
2
    return hasVarStorage() ? static_cast<DeclStmt *>(
2284
0
                                 getTrailingObjects<Stmt *>()[varOffset()])
2285
2
                           : nullptr;
2286
2
  }
2287
2288
12.3k
  SwitchCase *getSwitchCaseList() { return FirstCase; }
2289
432
  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
2290
1.25k
  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
2291
2292
2.87k
  SourceLocation getSwitchLoc() const { return SwitchStmtBits.SwitchLoc; }
2293
14.5k
  void setSwitchLoc(SourceLocation L) { SwitchStmtBits.SwitchLoc = L; }
2294
1.39k
  SourceLocation getLParenLoc() const { return LParenLoc; }
2295
642
  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2296
1.39k
  SourceLocation getRParenLoc() const { return RParenLoc; }
2297
642
  void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
2298
2299
6.31k
  void setBody(Stmt *S, SourceLocation SL) {
2300
6.31k
    setBody(S);
2301
6.31k
    setSwitchLoc(SL);
2302
6.31k
  }
2303
2304
24.5k
  void addSwitchCase(SwitchCase *SC) {
2305
24.5k
    assert(!SC->getNextSwitchCase() &&
2306
24.5k
           "case/default already added to a switch");
2307
0
    SC->setNextSwitchCase(FirstCase);
2308
24.5k
    FirstCase = SC;
2309
24.5k
  }
2310
2311
  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
2312
  /// switch over an enum value then all cases have been explicitly covered.
2313
431
  void setAllEnumCasesCovered() { SwitchStmtBits.AllEnumCasesCovered = true; }
2314
2315
  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
2316
  /// have been explicitly covered.
2317
1.41k
  bool isAllEnumCasesCovered() const {
2318
1.41k
    return SwitchStmtBits.AllEnumCasesCovered;
2319
1.41k
  }
2320
2321
1.14k
  SourceLocation getBeginLoc() const { return getSwitchLoc(); }
2322
602
  SourceLocation getEndLoc() const LLVM_READONLY {
2323
602
    return getBody() ? getBody()->getEndLoc()
2324
602
                     : 
reinterpret_cast<const Stmt *>(getCond())->getEndLoc()0
;
2325
602
  }
2326
2327
  // Iterators
2328
7.48k
  child_range children() {
2329
7.48k
    return child_range(getTrailingObjects<Stmt *>(),
2330
7.48k
                       getTrailingObjects<Stmt *>() +
2331
7.48k
                           numTrailingObjects(OverloadToken<Stmt *>()));
2332
7.48k
  }
2333
2334
0
  const_child_range children() const {
2335
0
    return const_child_range(getTrailingObjects<Stmt *>(),
2336
0
                             getTrailingObjects<Stmt *>() +
2337
0
                                 numTrailingObjects(OverloadToken<Stmt *>()));
2338
0
  }
2339
2340
98.9k
  static bool classof(const Stmt *T) {
2341
98.9k
    return T->getStmtClass() == SwitchStmtClass;
2342
98.9k
  }
2343
};
2344
2345
/// WhileStmt - This represents a 'while' stmt.
2346
class WhileStmt final : public Stmt,
2347
                        private llvm::TrailingObjects<WhileStmt, Stmt *> {
2348
  friend TrailingObjects;
2349
2350
  // WhileStmt is followed by several trailing objects,
2351
  // some of which optional. Note that it would be more
2352
  // convenient to put the optional trailing object at the end
2353
  // but this would affect children().
2354
  // The trailing objects are in order:
2355
  //
2356
  // * A "Stmt *" for the condition variable.
2357
  //    Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
2358
  //
2359
  // * A "Stmt *" for the condition.
2360
  //    Always present. This is in fact an "Expr *".
2361
  //
2362
  // * A "Stmt *" for the body.
2363
  //    Always present.
2364
  //
2365
  enum { VarOffset = 0, BodyOffsetFromCond = 1 };
2366
  enum { NumMandatoryStmtPtr = 2 };
2367
2368
  SourceLocation LParenLoc, RParenLoc;
2369
2370
903
  unsigned varOffset() const { return VarOffset; }
2371
2.29M
  unsigned condOffset() const { return VarOffset + hasVarStorage(); }
2372
1.13M
  unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
2373
2374
17.7k
  unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2375
17.7k
    return NumMandatoryStmtPtr + hasVarStorage();
2376
17.7k
  }
2377
2378
  /// Build a while statement.
2379
  WhileStmt(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body,
2380
            SourceLocation WL, SourceLocation LParenLoc,
2381
            SourceLocation RParenLoc);
2382
2383
  /// Build an empty while statement.
2384
  explicit WhileStmt(EmptyShell Empty, bool HasVar);
2385
2386
public:
2387
  /// Create a while statement.
2388
  static WhileStmt *Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond,
2389
                           Stmt *Body, SourceLocation WL,
2390
                           SourceLocation LParenLoc, SourceLocation RParenLoc);
2391
2392
  /// Create an empty while statement optionally with storage for
2393
  /// a condition variable.
2394
  static WhileStmt *CreateEmpty(const ASTContext &Ctx, bool HasVar);
2395
2396
  /// True if this WhileStmt has storage for a condition variable.
2397
3.38M
  bool hasVarStorage() const { return WhileStmtBits.HasVar; }
2398
2399
29.3k
  Expr *getCond() {
2400
29.3k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2401
29.3k
  }
2402
2403
1.07M
  const Expr *getCond() const {
2404
1.07M
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2405
1.07M
  }
2406
2407
55.5k
  void setCond(Expr *Cond) {
2408
55.5k
    getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2409
55.5k
  }
2410
2411
12.5k
  Stmt *getBody() { return getTrailingObjects<Stmt *>()[bodyOffset()]; }
2412
1.06M
  const Stmt *getBody() const {
2413
1.06M
    return getTrailingObjects<Stmt *>()[bodyOffset()];
2414
1.06M
  }
2415
2416
55.5k
  void setBody(Stmt *Body) {
2417
55.5k
    getTrailingObjects<Stmt *>()[bodyOffset()] = Body;
2418
55.5k
  }
2419
2420
  /// Retrieve the variable declared in this "while" statement, if any.
2421
  ///
2422
  /// In the following example, "x" is the condition variable.
2423
  /// \code
2424
  /// while (int x = random()) {
2425
  ///   // ...
2426
  /// }
2427
  /// \endcode
2428
  VarDecl *getConditionVariable();
2429
1.05M
  const VarDecl *getConditionVariable() const {
2430
1.05M
    return const_cast<WhileStmt *>(this)->getConditionVariable();
2431
1.05M
  }
2432
2433
  /// Set the condition variable of this while statement.
2434
  /// The while statement must have storage for it.
2435
  void setConditionVariable(const ASTContext &Ctx, VarDecl *V);
2436
2437
  /// If this WhileStmt has a condition variable, return the faux DeclStmt
2438
  /// associated with the creation of that condition variable.
2439
1.07M
  DeclStmt *getConditionVariableDeclStmt() {
2440
1.07M
    return hasVarStorage() ? static_cast<DeclStmt *>(
2441
281
                                 getTrailingObjects<Stmt *>()[varOffset()])
2442
1.07M
                           : 
nullptr1.07M
;
2443
1.07M
  }
2444
2445
0
  const DeclStmt *getConditionVariableDeclStmt() const {
2446
0
    return hasVarStorage() ? static_cast<DeclStmt *>(
2447
0
                                 getTrailingObjects<Stmt *>()[varOffset()])
2448
0
                           : nullptr;
2449
0
  }
2450
2451
15.6k
  SourceLocation getWhileLoc() const { return WhileStmtBits.WhileLoc; }
2452
55.5k
  void setWhileLoc(SourceLocation L) { WhileStmtBits.WhileLoc = L; }
2453
2454
7.77k
  SourceLocation getLParenLoc() const { return LParenLoc; }
2455
55.5k
  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2456
7.81k
  SourceLocation getRParenLoc() const { return RParenLoc; }
2457
55.5k
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2458
2459
6.57k
  SourceLocation getBeginLoc() const { return getWhileLoc(); }
2460
2.44k
  SourceLocation getEndLoc() const LLVM_READONLY {
2461
2.44k
    return getBody()->getEndLoc();
2462
2.44k
  }
2463
2464
64.1k
  static bool classof(const Stmt *T) {
2465
64.1k
    return T->getStmtClass() == WhileStmtClass;
2466
64.1k
  }
2467
2468
  // Iterators
2469
17.7k
  child_range children() {
2470
17.7k
    return child_range(getTrailingObjects<Stmt *>(),
2471
17.7k
                       getTrailingObjects<Stmt *>() +
2472
17.7k
                           numTrailingObjects(OverloadToken<Stmt *>()));
2473
17.7k
  }
2474
2475
0
  const_child_range children() const {
2476
0
    return const_child_range(getTrailingObjects<Stmt *>(),
2477
0
                             getTrailingObjects<Stmt *>() +
2478
0
                                 numTrailingObjects(OverloadToken<Stmt *>()));
2479
0
  }
2480
};
2481
2482
/// DoStmt - This represents a 'do/while' stmt.
2483
class DoStmt : public Stmt {
2484
  enum { BODY, COND, END_EXPR };
2485
  Stmt *SubExprs[END_EXPR];
2486
  SourceLocation WhileLoc;
2487
  SourceLocation RParenLoc; // Location of final ')' in do stmt condition.
2488
2489
public:
2490
  DoStmt(Stmt *Body, Expr *Cond, SourceLocation DL, SourceLocation WL,
2491
         SourceLocation RP)
2492
11.4k
      : Stmt(DoStmtClass), WhileLoc(WL), RParenLoc(RP) {
2493
11.4k
    setCond(Cond);
2494
11.4k
    setBody(Body);
2495
11.4k
    setDoLoc(DL);
2496
11.4k
  }
2497
2498
  /// Build an empty do-while statement.
2499
432
  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) {}
2500
2501
4.35k
  Expr *getCond() { return reinterpret_cast<Expr *>(SubExprs[COND]); }
2502
1.61k
  const Expr *getCond() const {
2503
1.61k
    return reinterpret_cast<Expr *>(SubExprs[COND]);
2504
1.61k
  }
2505
2506
11.9k
  void setCond(Expr *Cond) { SubExprs[COND] = reinterpret_cast<Stmt *>(Cond); }
2507
2508
3.67k
  Stmt *getBody() { return SubExprs[BODY]; }
2509
1.27k
  const Stmt *getBody() const { return SubExprs[BODY]; }
2510
11.9k
  void setBody(Stmt *Body) { SubExprs[BODY] = Body; }
2511
2512
3.33k
  SourceLocation getDoLoc() const { return DoStmtBits.DoLoc; }
2513
11.9k
  void setDoLoc(SourceLocation L) { DoStmtBits.DoLoc = L; }
2514
2.37k
  SourceLocation getWhileLoc() const { return WhileLoc; }
2515
432
  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
2516
2.71k
  SourceLocation getRParenLoc() const { return RParenLoc; }
2517
432
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2518
2519
1.51k
  SourceLocation getBeginLoc() const { return getDoLoc(); }
2520
892
  SourceLocation getEndLoc() const { return getRParenLoc(); }
2521
2522
12.9k
  static bool classof(const Stmt *T) {
2523
12.9k
    return T->getStmtClass() == DoStmtClass;
2524
12.9k
  }
2525
2526
  // Iterators
2527
3.36k
  child_range children() {
2528
3.36k
    return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2529
3.36k
  }
2530
2531
0
  const_child_range children() const {
2532
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2533
0
  }
2534
};
2535
2536
/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
2537
/// the init/cond/inc parts of the ForStmt will be null if they were not
2538
/// specified in the source.
2539
class ForStmt : public Stmt {
2540
  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
2541
  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
2542
  SourceLocation LParenLoc, RParenLoc;
2543
2544
public:
2545
  ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
2546
          Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
2547
          SourceLocation RP);
2548
2549
  /// Build an empty for statement.
2550
19.3k
  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) {}
2551
2552
355k
  Stmt *getInit() { return SubExprs[INIT]; }
2553
2554
  /// Retrieve the variable declared in this "for" statement, if any.
2555
  ///
2556
  /// In the following example, "y" is the condition variable.
2557
  /// \code
2558
  /// for (int x = random(); int y = mangle(x); ++x) {
2559
  ///   // ...
2560
  /// }
2561
  /// \endcode
2562
  VarDecl *getConditionVariable() const;
2563
  void setConditionVariable(const ASTContext &C, VarDecl *V);
2564
2565
  /// If this ForStmt has a condition variable, return the faux DeclStmt
2566
  /// associated with the creation of that condition variable.
2567
40
  const DeclStmt *getConditionVariableDeclStmt() const {
2568
40
    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
2569
40
  }
2570
2571
392k
  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
2572
330k
  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
2573
486k
  Stmt *getBody() { return SubExprs[BODY]; }
2574
2575
34.4k
  const Stmt *getInit() const { return SubExprs[INIT]; }
2576
4.69M
  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
2577
4.62M
  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
2578
4.68M
  const Stmt *getBody() const { return SubExprs[BODY]; }
2579
2580
19.3k
  void setInit(Stmt *S) { SubExprs[INIT] = S; }
2581
19.3k
  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
2582
19.3k
  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
2583
19.3k
  void setBody(Stmt *S) { SubExprs[BODY] = S; }
2584
2585
809k
  SourceLocation getForLoc() const { return ForStmtBits.ForLoc; }
2586
19.3k
  void setForLoc(SourceLocation L) { ForStmtBits.ForLoc = L; }
2587
85.1k
  SourceLocation getLParenLoc() const { return LParenLoc; }
2588
19.3k
  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2589
85.7k
  SourceLocation getRParenLoc() const { return RParenLoc; }
2590
19.3k
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2591
2592
460k
  SourceLocation getBeginLoc() const { return getForLoc(); }
2593
68.9k
  SourceLocation getEndLoc() const { return getBody()->getEndLoc(); }
2594
2595
840k
  static bool classof(const Stmt *T) {
2596
840k
    return T->getStmtClass() == ForStmtClass;
2597
840k
  }
2598
2599
  // Iterators
2600
142k
  child_range children() {
2601
142k
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2602
142k
  }
2603
2604
0
  const_child_range children() const {
2605
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2606
0
  }
2607
};
2608
2609
/// GotoStmt - This represents a direct goto.
2610
class GotoStmt : public Stmt {
2611
  LabelDecl *Label;
2612
  SourceLocation LabelLoc;
2613
2614
public:
2615
  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
2616
6.03k
      : Stmt(GotoStmtClass), Label(label), LabelLoc(LL) {
2617
6.03k
    setGotoLoc(GL);
2618
6.03k
  }
2619
2620
  /// Build an empty goto statement.
2621
47
  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) {}
2622
2623
14.4k
  LabelDecl *getLabel() const { return Label; }
2624
47
  void setLabel(LabelDecl *D) { Label = D; }
2625
2626
2.79k
  SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; }
2627
6.08k
  void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; }
2628
349
  SourceLocation getLabelLoc() const { return LabelLoc; }
2629
47
  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
2630
2631
235
  SourceLocation getBeginLoc() const { return getGotoLoc(); }
2632
86
  SourceLocation getEndLoc() const { return getLabelLoc(); }
2633
2634
21.8k
  static bool classof(const Stmt *T) {
2635
21.8k
    return T->getStmtClass() == GotoStmtClass;
2636
21.8k
  }
2637
2638
  // Iterators
2639
6.45k
  child_range children() {
2640
6.45k
    return child_range(child_iterator(), child_iterator());
2641
6.45k
  }
2642
2643
0
  const_child_range children() const {
2644
0
    return const_child_range(const_child_iterator(), const_child_iterator());
2645
0
  }
2646
};
2647
2648
/// IndirectGotoStmt - This represents an indirect goto.
2649
class IndirectGotoStmt : public Stmt {
2650
  SourceLocation StarLoc;
2651
  Stmt *Target;
2652
2653
public:
2654
  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, Expr *target)
2655
132
      : Stmt(IndirectGotoStmtClass), StarLoc(starLoc) {
2656
132
    setTarget(target);
2657
132
    setGotoLoc(gotoLoc);
2658
132
  }
2659
2660
  /// Build an empty indirect goto statement.
2661
  explicit IndirectGotoStmt(EmptyShell Empty)
2662
2
      : Stmt(IndirectGotoStmtClass, Empty) {}
2663
2664
134
  void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; }
2665
67
  SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; }
2666
2
  void setStarLoc(SourceLocation L) { StarLoc = L; }
2667
6
  SourceLocation getStarLoc() const { return StarLoc; }
2668
2669
213
  Expr *getTarget() { return reinterpret_cast<Expr *>(Target); }
2670
30
  const Expr *getTarget() const {
2671
30
    return reinterpret_cast<const Expr *>(Target);
2672
30
  }
2673
134
  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt *>(E); }
2674
2675
  /// getConstantTarget - Returns the fixed target of this indirect
2676
  /// goto, if one exists.
2677
  LabelDecl *getConstantTarget();
2678
22
  const LabelDecl *getConstantTarget() const {
2679
22
    return const_cast<IndirectGotoStmt *>(this)->getConstantTarget();
2680
22
  }
2681
2682
51
  SourceLocation getBeginLoc() const { return getGotoLoc(); }
2683
10
  SourceLocation getEndLoc() const LLVM_READONLY { return Target->getEndLoc(); }
2684
2685
4.93k
  static bool classof(const Stmt *T) {
2686
4.93k
    return T->getStmtClass() == IndirectGotoStmtClass;
2687
4.93k
  }
2688
2689
  // Iterators
2690
163
  child_range children() { return child_range(&Target, &Target + 1); }
2691
2692
0
  const_child_range children() const {
2693
0
    return const_child_range(&Target, &Target + 1);
2694
0
  }
2695
};
2696
2697
/// ContinueStmt - This represents a continue.
2698
class ContinueStmt : public Stmt {
2699
public:
2700
12.8k
  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass) {
2701
12.8k
    setContinueLoc(CL);
2702
12.8k
  }
2703
2704
  /// Build an empty continue statement.
2705
110
  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) {}
2706
2707
11.1k
  SourceLocation getContinueLoc() const { return ContinueStmtBits.ContinueLoc; }
2708
12.9k
  void setContinueLoc(SourceLocation L) { ContinueStmtBits.ContinueLoc = L; }
2709
2710
10.8k
  SourceLocation getBeginLoc() const { return getContinueLoc(); }
2711
65
  SourceLocation getEndLoc() const { return getContinueLoc(); }
2712
2713
27.4k
  static bool classof(const Stmt *T) {
2714
27.4k
    return T->getStmtClass() == ContinueStmtClass;
2715
27.4k
  }
2716
2717
  // Iterators
2718
1.72k
  child_range children() {
2719
1.72k
    return child_range(child_iterator(), child_iterator());
2720
1.72k
  }
2721
2722
0
  const_child_range children() const {
2723
0
    return const_child_range(const_child_iterator(), const_child_iterator());
2724
0
  }
2725
};
2726
2727
/// BreakStmt - This represents a break.
2728
class BreakStmt : public Stmt {
2729
public:
2730
40.6k
  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass) {
2731
40.6k
    setBreakLoc(BL);
2732
40.6k
  }
2733
2734
  /// Build an empty break statement.
2735
4.04k
  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) {}
2736
2737
13.0k
  SourceLocation getBreakLoc() const { return BreakStmtBits.BreakLoc; }
2738
44.6k
  void setBreakLoc(SourceLocation L) { BreakStmtBits.BreakLoc = L; }
2739
2740
5.84k
  SourceLocation getBeginLoc() const { return getBreakLoc(); }
2741
401
  SourceLocation getEndLoc() const { return getBreakLoc(); }
2742
2743
17.3k
  static bool classof(const Stmt *T) {
2744
17.3k
    return T->getStmtClass() == BreakStmtClass;
2745
17.3k
  }
2746
2747
  // Iterators
2748
19.2k
  child_range children() {
2749
19.2k
    return child_range(child_iterator(), child_iterator());
2750
19.2k
  }
2751
2752
0
  const_child_range children() const {
2753
0
    return const_child_range(const_child_iterator(), const_child_iterator());
2754
0
  }
2755
};
2756
2757
/// ReturnStmt - This represents a return, optionally of an expression:
2758
///   return;
2759
///   return 4;
2760
///
2761
/// Note that GCC allows return with no argument in a function declared to
2762
/// return a value, and it allows returning a value in functions declared to
2763
/// return void.  We explicitly model this in the AST, which means you can't
2764
/// depend on the return type of the function and the presence of an argument.
2765
class ReturnStmt final
2766
    : public Stmt,
2767
      private llvm::TrailingObjects<ReturnStmt, const VarDecl *> {
2768
  friend TrailingObjects;
2769
2770
  /// The return expression.
2771
  Stmt *RetExpr;
2772
2773
  // ReturnStmt is followed optionally by a trailing "const VarDecl *"
2774
  // for the NRVO candidate. Present if and only if hasNRVOCandidate().
2775
2776
  /// True if this ReturnStmt has storage for an NRVO candidate.
2777
6.74M
  bool hasNRVOCandidate() const { return ReturnStmtBits.HasNRVOCandidate; }
2778
2779
0
  unsigned numTrailingObjects(OverloadToken<const VarDecl *>) const {
2780
0
    return hasNRVOCandidate();
2781
0
  }
2782
2783
  /// Build a return statement.
2784
  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate);
2785
2786
  /// Build an empty return statement.
2787
  explicit ReturnStmt(EmptyShell Empty, bool HasNRVOCandidate);
2788
2789
public:
2790
  /// Create a return statement.
2791
  static ReturnStmt *Create(const ASTContext &Ctx, SourceLocation RL, Expr *E,
2792
                            const VarDecl *NRVOCandidate);
2793
2794
  /// Create an empty return statement, optionally with
2795
  /// storage for an NRVO candidate.
2796
  static ReturnStmt *CreateEmpty(const ASTContext &Ctx, bool HasNRVOCandidate);
2797
2798
704k
  Expr *getRetValue() { return reinterpret_cast<Expr *>(RetExpr); }
2799
387k
  const Expr *getRetValue() const { return reinterpret_cast<Expr *>(RetExpr); }
2800
147k
  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt *>(E); }
2801
2802
  /// Retrieve the variable that might be used for the named return
2803
  /// value optimization.
2804
  ///
2805
  /// The optimization itself can only be performed if the variable is
2806
  /// also marked as an NRVO object.
2807
6.68M
  const VarDecl *getNRVOCandidate() const {
2808
6.68M
    return hasNRVOCandidate() ? 
*getTrailingObjects<const VarDecl *>()133k
2809
6.68M
                              : 
nullptr6.54M
;
2810
6.68M
  }
2811
2812
  /// Set the variable that might be used for the named return value
2813
  /// optimization. The return statement must have storage for it,
2814
  /// which is the case if and only if hasNRVOCandidate() is true.
2815
63.5k
  void setNRVOCandidate(const VarDecl *Var) {
2816
63.5k
    assert(hasNRVOCandidate() &&
2817
63.5k
           "This return statement has no storage for an NRVO candidate!");
2818
0
    *getTrailingObjects<const VarDecl *>() = Var;
2819
63.5k
  }
2820
2821
786k
  SourceLocation getReturnLoc() const { return ReturnStmtBits.RetLoc; }
2822
3.48M
  void setReturnLoc(SourceLocation L) { ReturnStmtBits.RetLoc = L; }
2823
2824
389k
  SourceLocation getBeginLoc() const { return getReturnLoc(); }
2825
153k
  SourceLocation getEndLoc() const LLVM_READONLY {
2826
153k
    return RetExpr ? 
RetExpr->getEndLoc()147k
:
getReturnLoc()5.95k
;
2827
153k
  }
2828
2829
10.6M
  static bool classof(const Stmt *T) {
2830
10.6M
    return T->getStmtClass() == ReturnStmtClass;
2831
10.6M
  }
2832
2833
  // Iterators
2834
367k
  child_range children() {
2835
367k
    if (RetExpr)
2836
346k
      return child_range(&RetExpr, &RetExpr + 1);
2837
20.9k
    return child_range(child_iterator(), child_iterator());
2838
367k
  }
2839
2840
0
  const_child_range children() const {
2841
0
    if (RetExpr)
2842
0
      return const_child_range(&RetExpr, &RetExpr + 1);
2843
0
    return const_child_range(const_child_iterator(), const_child_iterator());
2844
0
  }
2845
};
2846
2847
/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
2848
class AsmStmt : public Stmt {
2849
protected:
2850
  friend class ASTStmtReader;
2851
2852
  SourceLocation AsmLoc;
2853
2854
  /// True if the assembly statement does not have any input or output
2855
  /// operands.
2856
  bool IsSimple;
2857
2858
  /// If true, treat this inline assembly as having side effects.
2859
  /// This assembly statement should not be optimized, deleted or moved.
2860
  bool IsVolatile;
2861
2862
  unsigned NumOutputs;
2863
  unsigned NumInputs;
2864
  unsigned NumClobbers;
2865
2866
  Stmt **Exprs = nullptr;
2867
2868
  AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
2869
          unsigned numoutputs, unsigned numinputs, unsigned numclobbers)
2870
      : Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
2871
        NumOutputs(numoutputs), NumInputs(numinputs),
2872
5.18k
        NumClobbers(numclobbers) {}
2873
2874
public:
2875
  /// Build an empty inline-assembly statement.
2876
10
  explicit AsmStmt(StmtClass SC, EmptyShell Empty) : Stmt(SC, Empty) {}
2877
2878
278
  SourceLocation getAsmLoc() const { return AsmLoc; }
2879
10
  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
2880
2881
6.69k
  bool isSimple() const { return IsSimple; }
2882
10
  void setSimple(bool V) { IsSimple = V; }
2883
2884
2.02k
  bool isVolatile() const { return IsVolatile; }
2885
10
  void setVolatile(bool V) { IsVolatile = V; }
2886
2887
0
  SourceLocation getBeginLoc() const LLVM_READONLY { return {}; }
2888
0
  SourceLocation getEndLoc() const LLVM_READONLY { return {}; }
2889
2890
  //===--- Asm String Analysis ---===//
2891
2892
  /// Assemble final IR asm string.
2893
  std::string generateAsmString(const ASTContext &C) const;
2894
2895
  //===--- Output operands ---===//
2896
2897
28.7k
  unsigned getNumOutputs() const { return NumOutputs; }
2898
2899
  /// getOutputConstraint - Return the constraint string for the specified
2900
  /// output operand.  All output constraints are known to be non-empty (either
2901
  /// '=' or '+').
2902
  StringRef getOutputConstraint(unsigned i) const;
2903
2904
  /// isOutputPlusConstraint - Return true if the specified output constraint
2905
  /// is a "+" constraint (which is both an input and an output) or false if it
2906
  /// is an "=" constraint (just an output).
2907
8.31k
  bool isOutputPlusConstraint(unsigned i) const {
2908
8.31k
    return getOutputConstraint(i)[0] == '+';
2909
8.31k
  }
2910
2911
  const Expr *getOutputExpr(unsigned i) const;
2912
2913
  /// getNumPlusOperands - Return the number of output operands that have a "+"
2914
  /// constraint.
2915
  unsigned getNumPlusOperands() const;
2916
2917
  //===--- Input operands ---===//
2918
2919
19.1k
  unsigned getNumInputs() const { return NumInputs; }
2920
2921
  /// getInputConstraint - Return the specified input constraint.  Unlike output
2922
  /// constraints, these can be empty.
2923
  StringRef getInputConstraint(unsigned i) const;
2924
2925
  const Expr *getInputExpr(unsigned i) const;
2926
2927
  //===--- Other ---===//
2928
2929
2.42k
  unsigned getNumClobbers() const { return NumClobbers; }
2930
  StringRef getClobber(unsigned i) const;
2931
2932
6.30k
  static bool classof(const Stmt *T) {
2933
6.30k
    return T->getStmtClass() == GCCAsmStmtClass ||
2934
6.30k
      
T->getStmtClass() == MSAsmStmtClass4.66k
;
2935
6.30k
  }
2936
2937
  // Input expr iterators.
2938
2939
  using inputs_iterator = ExprIterator;
2940
  using const_inputs_iterator = ConstExprIterator;
2941
  using inputs_range = llvm::iterator_range<inputs_iterator>;
2942
  using inputs_const_range = llvm::iterator_range<const_inputs_iterator>;
2943
2944
3
  inputs_iterator begin_inputs() {
2945
3
    return &Exprs[0] + NumOutputs;
2946
3
  }
2947
2948
3
  inputs_iterator end_inputs() {
2949
3
    return &Exprs[0] + NumOutputs + NumInputs;
2950
3
  }
2951
2952
3
  inputs_range inputs() { return inputs_range(begin_inputs(), end_inputs()); }
2953
2954
0
  const_inputs_iterator begin_inputs() const {
2955
0
    return &Exprs[0] + NumOutputs;
2956
0
  }
2957
2958
0
  const_inputs_iterator end_inputs() const {
2959
0
    return &Exprs[0] + NumOutputs + NumInputs;
2960
0
  }
2961
2962
0
  inputs_const_range inputs() const {
2963
0
    return inputs_const_range(begin_inputs(), end_inputs());
2964
0
  }
2965
2966
  // Output expr iterators.
2967
2968
  using outputs_iterator = ExprIterator;
2969
  using const_outputs_iterator = ConstExprIterator;
2970
  using outputs_range = llvm::iterator_range<outputs_iterator>;
2971
  using outputs_const_range = llvm::iterator_range<const_outputs_iterator>;
2972
2973
12
  outputs_iterator begin_outputs() {
2974
12
    return &Exprs[0];
2975
12
  }
2976
2977
12
  outputs_iterator end_outputs() {
2978
12
    return &Exprs[0] + NumOutputs;
2979
12
  }
2980
2981
12
  outputs_range outputs() {
2982
12
    return outputs_range(begin_outputs(), end_outputs());
2983
12
  }
2984
2985
37
  const_outputs_iterator begin_outputs() const {
2986
37
    return &Exprs[0];
2987
37
  }
2988
2989
37
  const_outputs_iterator end_outputs() const {
2990
37
    return &Exprs[0] + NumOutputs;
2991
37
  }
2992
2993
37
  outputs_const_range outputs() const {
2994
37
    return outputs_const_range(begin_outputs(), end_outputs());
2995
37
  }
2996
2997
2.08k
  child_range children() {
2998
2.08k
    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
2999
2.08k
  }
3000
3001
0
  const_child_range children() const {
3002
0
    return const_child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
3003
0
  }
3004
};
3005
3006
/// This represents a GCC inline-assembly statement extension.
3007
class GCCAsmStmt : public AsmStmt {
3008
  friend class ASTStmtReader;
3009
3010
  SourceLocation RParenLoc;
3011
  StringLiteral *AsmStr;
3012
3013
  // FIXME: If we wanted to, we could allocate all of these in one big array.
3014
  StringLiteral **Constraints = nullptr;
3015
  StringLiteral **Clobbers = nullptr;
3016
  IdentifierInfo **Names = nullptr;
3017
  unsigned NumLabels = 0;
3018
3019
public:
3020
  GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
3021
             bool isvolatile, unsigned numoutputs, unsigned numinputs,
3022
             IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
3023
             StringLiteral *asmstr, unsigned numclobbers,
3024
             StringLiteral **clobbers, unsigned numlabels,
3025
             SourceLocation rparenloc);
3026
3027
  /// Build an empty inline-assembly statement.
3028
10
  explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {}
3029
3030
109
  SourceLocation getRParenLoc() const { return RParenLoc; }
3031
10
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3032
3033
  //===--- Asm String Analysis ---===//
3034
3035
25.9k
  const StringLiteral *getAsmString() const { return AsmStr; }
3036
292
  StringLiteral *getAsmString() { return AsmStr; }
3037
10
  void setAsmString(StringLiteral *E) { AsmStr = E; }
3038
3039
  /// AsmStringPiece - this is part of a decomposed asm string specification
3040
  /// (for use with the AnalyzeAsmString function below).  An asm string is
3041
  /// considered to be a concatenation of these parts.
3042
  class AsmStringPiece {
3043
  public:
3044
    enum Kind {
3045
      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
3046
      Operand  // Operand reference, with optional modifier %c4.
3047
    };
3048
3049
  private:
3050
    Kind MyKind;
3051
    std::string Str;
3052
    unsigned OperandNo;
3053
3054
    // Source range for operand references.
3055
    CharSourceRange Range;
3056
3057
  public:
3058
13.0k
    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
3059
    AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin,
3060
                   SourceLocation End)
3061
        : MyKind(Operand), Str(S), OperandNo(OpNo),
3062
8.84k
          Range(CharSourceRange::getCharRange(Begin, End)) {}
3063
3064
6.44k
    bool isString() const { return MyKind == String; }
3065
33.1k
    bool isOperand() const { return MyKind == Operand; }
3066
3067
3.69k
    const std::string &getString() const { return Str; }
3068
3069
8.84k
    unsigned getOperandNo() const {
3070
8.84k
      assert(isOperand());
3071
0
      return OperandNo;
3072
8.84k
    }
3073
3074
42
    CharSourceRange getRange() const {
3075
42
      assert(isOperand() && "Range is currently used only for Operands.");
3076
0
      return Range;
3077
42
    }
3078
3079
    /// getModifier - Get the modifier for this operand, if present.  This
3080
    /// returns '\0' if there was no modifier.
3081
    char getModifier() const;
3082
  };
3083
3084
  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
3085
  /// it into pieces.  If the asm string is erroneous, emit errors and return
3086
  /// true, otherwise return false.  This handles canonicalization and
3087
  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
3088
  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
3089
  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
3090
                            const ASTContext &C, unsigned &DiagOffs) const;
3091
3092
  /// Assemble final IR asm string.
3093
  std::string generateAsmString(const ASTContext &C) const;
3094
3095
  //===--- Output operands ---===//
3096
3097
2.23k
  IdentifierInfo *getOutputIdentifier(unsigned i) const { return Names[i]; }
3098
3099
1.96k
  StringRef getOutputName(unsigned i) const {
3100
1.96k
    if (IdentifierInfo *II = getOutputIdentifier(i))
3101
496
      return II->getName();
3102
3103
1.47k
    return {};
3104
1.96k
  }
3105
3106
  StringRef getOutputConstraint(unsigned i) const;
3107
3108
11.0k
  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
3109
11.0k
    return Constraints[i];
3110
11.0k
  }
3111
391
  StringLiteral *getOutputConstraintLiteral(unsigned i) {
3112
391
    return Constraints[i];
3113
391
  }
3114
3115
  Expr *getOutputExpr(unsigned i);
3116
3117
1.50k
  const Expr *getOutputExpr(unsigned i) const {
3118
1.50k
    return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
3119
1.50k
  }
3120
3121
  //===--- Input operands ---===//
3122
3123
2.32k
  IdentifierInfo *getInputIdentifier(unsigned i) const {
3124
2.32k
    return Names[i + NumOutputs];
3125
2.32k
  }
3126
3127
2.12k
  StringRef getInputName(unsigned i) const {
3128
2.12k
    if (IdentifierInfo *II = getInputIdentifier(i))
3129
344
      return II->getName();
3130
3131
1.77k
    return {};
3132
2.12k
  }
3133
3134
  StringRef getInputConstraint(unsigned i) const;
3135
3136
3.43k
  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
3137
3.43k
    return Constraints[i + NumOutputs];
3138
3.43k
  }
3139
311
  StringLiteral *getInputConstraintLiteral(unsigned i) {
3140
311
    return Constraints[i + NumOutputs];
3141
311
  }
3142
3143
  Expr *getInputExpr(unsigned i);
3144
  void setInputExpr(unsigned i, Expr *E);
3145
3146
1.67k
  const Expr *getInputExpr(unsigned i) const {
3147
1.67k
    return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
3148
1.67k
  }
3149
3150
  //===--- Labels ---===//
3151
3152
12.9k
  bool isAsmGoto() const {
3153
12.9k
    return NumLabels > 0;
3154
12.9k
  }
3155
3156
8.77k
  unsigned getNumLabels() const {
3157
8.77k
    return NumLabels;
3158
8.77k
  }
3159
3160
2
  IdentifierInfo *getLabelIdentifier(unsigned i) const {
3161
2
    return Names[i + NumOutputs + NumInputs];
3162
2
  }
3163
3164
  AddrLabelExpr *getLabelExpr(unsigned i) const;
3165
  StringRef getLabelName(unsigned i) const;
3166
  using labels_iterator = CastIterator<AddrLabelExpr>;
3167
  using const_labels_iterator = ConstCastIterator<AddrLabelExpr>;
3168
  using labels_range = llvm::iterator_range<labels_iterator>;
3169
  using labels_const_range = llvm::iterator_range<const_labels_iterator>;
3170
3171
118
  labels_iterator begin_labels() {
3172
118
    return &Exprs[0] + NumOutputs + NumInputs;
3173
118
  }
3174
3175
118
  labels_iterator end_labels() {
3176
118
    return &Exprs[0] + NumOutputs + NumInputs + NumLabels;
3177
118
  }
3178
3179
118
  labels_range labels() {
3180
118
    return labels_range(begin_labels(), end_labels());
3181
118
  }
3182
3183
232
  const_labels_iterator begin_labels() const {
3184
232
    return &Exprs[0] + NumOutputs + NumInputs;
3185
232
  }
3186
3187
232
  const_labels_iterator end_labels() const {
3188
232
    return &Exprs[0] + NumOutputs + NumInputs + NumLabels;
3189
232
  }
3190
3191
232
  labels_const_range labels() const {
3192
232
    return labels_const_range(begin_labels(), end_labels());
3193
232
  }
3194
3195
private:
3196
  void setOutputsAndInputsAndClobbers(const ASTContext &C,
3197
                                      IdentifierInfo **Names,
3198
                                      StringLiteral **Constraints,
3199
                                      Stmt **Exprs,
3200
                                      unsigned NumOutputs,
3201
                                      unsigned NumInputs,
3202
                                      unsigned NumLabels,
3203
                                      StringLiteral **Clobbers,
3204
                                      unsigned NumClobbers);
3205
3206
public:
3207
  //===--- Other ---===//
3208
3209
  /// getNamedOperand - Given a symbolic operand reference like %[foo],
3210
  /// translate this into a numeric value needed to reference the same operand.
3211
  /// This returns -1 if the operand name is invalid.
3212
  int getNamedOperand(StringRef SymbolicName) const;
3213
3214
  StringRef getClobber(unsigned i) const;
3215
3216
98
  StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
3217
1.17k
  const StringLiteral *getClobberStringLiteral(unsigned i) const {
3218
1.17k
    return Clobbers[i];
3219
1.17k
  }
3220
3221
160
  SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
3222
15
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3223
3224
57.8k
  static bool classof(const Stmt *T) {
3225
57.8k
    return T->getStmtClass() == GCCAsmStmtClass;
3226
57.8k
  }
3227
};
3228
3229
/// This represents a Microsoft inline-assembly statement extension.
3230
class MSAsmStmt : public AsmStmt {
3231
  friend class ASTStmtReader;
3232
3233
  SourceLocation LBraceLoc, EndLoc;
3234
  StringRef AsmStr;
3235
3236
  unsigned NumAsmToks = 0;
3237
3238
  Token *AsmToks = nullptr;
3239
  StringRef *Constraints = nullptr;
3240
  StringRef *Clobbers = nullptr;
3241
3242
public:
3243
  MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
3244
            SourceLocation lbraceloc, bool issimple, bool isvolatile,
3245
            ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs,
3246
            ArrayRef<StringRef> constraints,
3247
            ArrayRef<Expr*> exprs, StringRef asmstr,
3248
            ArrayRef<StringRef> clobbers, SourceLocation endloc);
3249
3250
  /// Build an empty MS-style inline-assembly statement.
3251
0
  explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty) {}
3252
3253
1
  SourceLocation getLBraceLoc() const { return LBraceLoc; }
3254
0
  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
3255
1
  SourceLocation getEndLoc() const { return EndLoc; }
3256
0
  void setEndLoc(SourceLocation L) { EndLoc = L; }
3257
3258
0
  bool hasBraces() const { return LBraceLoc.isValid(); }
3259
3260
1
  unsigned getNumAsmToks() { return NumAsmToks; }
3261
1
  Token *getAsmToks() { return AsmToks; }
3262
3263
  //===--- Asm String Analysis ---===//
3264
1
  StringRef getAsmString() const { return AsmStr; }
3265
3266
  /// Assemble final IR asm string.
3267
  std::string generateAsmString(const ASTContext &C) const;
3268
3269
  //===--- Output operands ---===//
3270
3271
54
  StringRef getOutputConstraint(unsigned i) const {
3272
54
    assert(i < NumOutputs);
3273
0
    return Constraints[i];
3274
54
  }
3275
3276
  Expr *getOutputExpr(unsigned i);
3277
3278
27
  const Expr *getOutputExpr(unsigned i) const {
3279
27
    return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
3280
27
  }
3281
3282
  //===--- Input operands ---===//
3283
3284
226
  StringRef getInputConstraint(unsigned i) const {
3285
226
    assert(i < NumInputs);
3286
0
    return Constraints[i + NumOutputs];
3287
226
  }
3288
3289
  Expr *getInputExpr(unsigned i);
3290
  void setInputExpr(unsigned i, Expr *E);
3291
3292
113
  const Expr *getInputExpr(unsigned i) const {
3293
113
    return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
3294
113
  }
3295
3296
  //===--- Other ---===//
3297
3298
1
  ArrayRef<StringRef> getAllConstraints() const {
3299
1
    return llvm::makeArrayRef(Constraints, NumInputs + NumOutputs);
3300
1
  }
3301
3302
195
  ArrayRef<StringRef> getClobbers() const {
3303
195
    return llvm::makeArrayRef(Clobbers, NumClobbers);
3304
195
  }
3305
3306
1
  ArrayRef<Expr*> getAllExprs() const {
3307
1
    return llvm::makeArrayRef(reinterpret_cast<Expr**>(Exprs),
3308
1
                              NumInputs + NumOutputs);
3309
1
  }
3310
3311
194
  StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
3312
3313
private:
3314
  void initialize(const ASTContext &C, StringRef AsmString,
3315
                  ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints,
3316
                  ArrayRef<Expr*> Exprs, ArrayRef<StringRef> Clobbers);
3317
3318
public:
3319
0
  SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
3320
3321
6.73k
  static bool classof(const Stmt *T) {
3322
6.73k
    return T->getStmtClass() == MSAsmStmtClass;
3323
6.73k
  }
3324
3325
40
  child_range children() {
3326
40
    return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
3327
40
  }
3328
3329
0
  const_child_range children() const {
3330
0
    return const_child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
3331
0
  }
3332
};
3333
3334
class SEHExceptStmt : public Stmt {
3335
  friend class ASTReader;
3336
  friend class ASTStmtReader;
3337
3338
  SourceLocation  Loc;
3339
  Stmt *Children[2];
3340
3341
  enum { FILTER_EXPR, BLOCK };
3342
3343
  SEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block);
3344
1
  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) {}
3345
3346
public:
3347
  static SEHExceptStmt* Create(const ASTContext &C,
3348
                               SourceLocation ExceptLoc,
3349
                               Expr *FilterExpr,
3350
                               Stmt *Block);
3351
3352
24
  SourceLocation getBeginLoc() const LLVM_READONLY { return getExceptLoc(); }
3353
3354
32
  SourceLocation getExceptLoc() const { return Loc; }
3355
48
  SourceLocation getEndLoc() const { return getBlock()->getEndLoc(); }
3356
3357
94
  Expr *getFilterExpr() const {
3358
94
    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
3359
94
  }
3360
3361
179
  CompoundStmt *getBlock() const {
3362
179
    return cast<CompoundStmt>(Children[BLOCK]);
3363
179
  }
3364
3365
11
  child_range children() {
3366
11
    return child_range(Children, Children+2);
3367
11
  }
3368
3369
0
  const_child_range children() const {
3370
0
    return const_child_range(Children, Children + 2);
3371
0
  }
3372
3373
425
  static bool classof(const Stmt *T) {
3374
425
    return T->getStmtClass() == SEHExceptStmtClass;
3375
425
  }
3376
};
3377
3378
class SEHFinallyStmt : public Stmt {
3379
  friend class ASTReader;
3380
  friend class ASTStmtReader;
3381
3382
  SourceLocation  Loc;
3383
  Stmt *Block;
3384
3385
  SEHFinallyStmt(SourceLocation Loc, Stmt *Block);
3386
0
  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) {}
3387
3388
public:
3389
  static SEHFinallyStmt* Create(const ASTContext &C,
3390
                                SourceLocation FinallyLoc,
3391
                                Stmt *Block);
3392
3393
54
  SourceLocation getBeginLoc() const LLVM_READONLY { return getFinallyLoc(); }
3394
3395
55
  SourceLocation getFinallyLoc() const { return Loc; }
3396
108
  SourceLocation getEndLoc() const { return Block->getEndLoc(); }
3397
3398
137
  CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
3399
3400
56
  child_range children() {
3401
56
    return child_range(&Block,&Block+1);
3402
56
  }
3403
3404
0
  const_child_range children() const {
3405
0
    return const_child_range(&Block, &Block + 1);
3406
0
  }
3407
3408
647
  static bool classof(const Stmt *T) {
3409
647
    return T->getStmtClass() == SEHFinallyStmtClass;
3410
647
  }
3411
};
3412
3413
class SEHTryStmt : public Stmt {
3414
  friend class ASTReader;
3415
  friend class ASTStmtReader;
3416
3417
  bool IsCXXTry;
3418
  SourceLocation  TryLoc;
3419
  Stmt *Children[2];
3420
3421
  enum { TRY = 0, HANDLER = 1 };
3422
3423
  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
3424
             SourceLocation TryLoc,
3425
             Stmt *TryBlock,
3426
             Stmt *Handler);
3427
3428
1
  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) {}
3429
3430
public:
3431
  static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry,
3432
                            SourceLocation TryLoc, Stmt *TryBlock,
3433
                            Stmt *Handler);
3434
3435
78
  SourceLocation getBeginLoc() const LLVM_READONLY { return getTryLoc(); }
3436
3437
85
  SourceLocation getTryLoc() const { return TryLoc; }
3438
78
  SourceLocation getEndLoc() const { return Children[HANDLER]->getEndLoc(); }
3439
3440
7
  bool getIsCXXTry() const { return IsCXXTry; }
3441
3442
326
  CompoundStmt* getTryBlock() const {
3443
326
    return cast<CompoundStmt>(Children[TRY]);
3444
326
  }
3445
3446
645
  Stmt *getHandler() const { return Children[HANDLER]; }
3447
3448
  /// Returns 0 if not defined
3449
  SEHExceptStmt  *getExceptHandler() const;
3450
  SEHFinallyStmt *getFinallyHandler() const;
3451
3452
68
  child_range children() {
3453
68
    return child_range(Children, Children+2);
3454
68
  }
3455
3456
0
  const_child_range children() const {
3457
0
    return const_child_range(Children, Children + 2);
3458
0
  }
3459
3460
293
  static bool classof(const Stmt *T) {
3461
293
    return T->getStmtClass() == SEHTryStmtClass;
3462
293
  }
3463
};
3464
3465
/// Represents a __leave statement.
3466
class SEHLeaveStmt : public Stmt {
3467
  SourceLocation LeaveLoc;
3468
3469
public:
3470
  explicit SEHLeaveStmt(SourceLocation LL)
3471
26
      : Stmt(SEHLeaveStmtClass), LeaveLoc(LL) {}
3472
3473
  /// Build an empty __leave statement.
3474
0
  explicit SEHLeaveStmt(EmptyShell Empty) : Stmt(SEHLeaveStmtClass, Empty) {}
3475
3476
0
  SourceLocation getLeaveLoc() const { return LeaveLoc; }
3477
0
  void setLeaveLoc(SourceLocation L) { LeaveLoc = L; }
3478
3479
2
  SourceLocation getBeginLoc() const LLVM_READONLY { return LeaveLoc; }
3480
2
  SourceLocation getEndLoc() const LLVM_READONLY { return LeaveLoc; }
3481
3482
20
  static bool classof(const Stmt *T) {
3483
20
    return T->getStmtClass() == SEHLeaveStmtClass;
3484
20
  }
3485
3486
  // Iterators
3487
11
  child_range children() {
3488
11
    return child_range(child_iterator(), child_iterator());
3489
11
  }
3490
3491
0
  const_child_range children() const {
3492
0
    return const_child_range(const_child_iterator(), const_child_iterator());
3493
0
  }
3494
};
3495
3496
/// This captures a statement into a function. For example, the following
3497
/// pragma annotated compound statement can be represented as a CapturedStmt,
3498
/// and this compound statement is the body of an anonymous outlined function.
3499
/// @code
3500
/// #pragma omp parallel
3501
/// {
3502
///   compute();
3503
/// }
3504
/// @endcode
3505
class CapturedStmt : public Stmt {
3506
public:
3507
  /// The different capture forms: by 'this', by reference, capture for
3508
  /// variable-length array type etc.
3509
  enum VariableCaptureKind {
3510
    VCK_This,
3511
    VCK_ByRef,
3512
    VCK_ByCopy,
3513
    VCK_VLAType,
3514
  };
3515
3516
  /// Describes the capture of either a variable, or 'this', or
3517
  /// variable-length array type.
3518
  class Capture {
3519
    llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind;
3520
    SourceLocation Loc;
3521
3522
  public:
3523
    friend class ASTStmtReader;
3524
3525
    /// Create a new capture.
3526
    ///
3527
    /// \param Loc The source location associated with this capture.
3528
    ///
3529
    /// \param Kind The kind of capture (this, ByRef, ...).
3530
    ///
3531
    /// \param Var The variable being captured, or null if capturing this.
3532
    Capture(SourceLocation Loc, VariableCaptureKind Kind,
3533
            VarDecl *Var = nullptr);
3534
3535
    /// Determine the kind of capture.
3536
    VariableCaptureKind getCaptureKind() const;
3537
3538
    /// Retrieve the source location at which the variable or 'this' was
3539
    /// first used.
3540
398k
    SourceLocation getLocation() const { return Loc; }
3541
3542
    /// Determine whether this capture handles the C++ 'this' pointer.
3543
170k
    bool capturesThis() const { return getCaptureKind() == VCK_This; }
3544
3545
    /// Determine whether this capture handles a variable (by reference).
3546
2.83M
    bool capturesVariable() const { return getCaptureKind() == VCK_ByRef; }
3547
3548
    /// Determine whether this capture handles a variable by copy.
3549
1.13M
    bool capturesVariableByCopy() const {
3550
1.13M
      return getCaptureKind() == VCK_ByCopy;
3551
1.13M
    }
3552
3553
    /// Determine whether this capture handles a variable-length array
3554
    /// type.
3555
84.3k
    bool capturesVariableArrayType() const {
3556
84.3k
      return getCaptureKind() == VCK_VLAType;
3557
84.3k
    }
3558
3559
    /// Retrieve the declaration of the variable being captured.
3560
    ///
3561
    /// This operation is only valid if this capture captures a variable.
3562
    VarDecl *getCapturedVar() const;
3563
  };
3564
3565
private:
3566
  /// The number of variable captured, including 'this'.
3567
  unsigned NumCaptures;
3568
3569
  /// The pointer part is the implicit the outlined function and the
3570
  /// int part is the captured region kind, 'CR_Default' etc.
3571
  llvm::PointerIntPair<CapturedDecl *, 2, CapturedRegionKind> CapDeclAndKind;
3572
3573
  /// The record for captured variables, a RecordDecl or CXXRecordDecl.
3574
  RecordDecl *TheRecordDecl = nullptr;
3575
3576
  /// Construct a captured statement.
3577
  CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures,
3578
               ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
3579
3580
  /// Construct an empty captured statement.
3581
  CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
3582
3583
2.76M
  Stmt **getStoredStmts() { return reinterpret_cast<Stmt **>(this + 1); }
3584
3585
685k
  Stmt *const *getStoredStmts() const {
3586
685k
    return reinterpret_cast<Stmt *const *>(this + 1);
3587
685k
  }
3588
3589
  Capture *getStoredCaptures() const;
3590
3591
31.5k
  void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
3592
3593
public:
3594
  friend class ASTStmtReader;
3595
3596
  static CapturedStmt *Create(const ASTContext &Context, Stmt *S,
3597
                              CapturedRegionKind Kind,
3598
                              ArrayRef<Capture> Captures,
3599
                              ArrayRef<Expr *> CaptureInits,
3600
                              CapturedDecl *CD, RecordDecl *RD);
3601
3602
  static CapturedStmt *CreateDeserialized(const ASTContext &Context,
3603
                                          unsigned NumCaptures);
3604
3605
  /// Retrieve the statement being captured.
3606
1.87M
  Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
3607
640k
  const Stmt *getCapturedStmt() const { return getStoredStmts()[NumCaptures]; }
3608
3609
  /// Retrieve the outlined function declaration.
3610
  CapturedDecl *getCapturedDecl();
3611
  const CapturedDecl *getCapturedDecl() const;
3612
3613
  /// Set the outlined function declaration.
3614
  void setCapturedDecl(CapturedDecl *D);
3615
3616
  /// Retrieve the captured region kind.
3617
  CapturedRegionKind getCapturedRegionKind() const;
3618
3619
  /// Set the captured region kind.
3620
  void setCapturedRegionKind(CapturedRegionKind Kind);
3621
3622
  /// Retrieve the record declaration for captured variables.
3623
114k
  const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
3624
3625
  /// Set the record declaration for captured variables.
3626
31.5k
  void setCapturedRecordDecl(RecordDecl *D) {
3627
31.5k
    assert(D && "null RecordDecl");
3628
0
    TheRecordDecl = D;
3629
31.5k
  }
3630
3631
  /// True if this variable has been captured.
3632
  bool capturesVariable(const VarDecl *Var) const;
3633
3634
  /// An iterator that walks over the captures.
3635
  using capture_iterator = Capture *;
3636
  using const_capture_iterator = const Capture *;
3637
  using capture_range = llvm::iterator_range<capture_iterator>;
3638
  using capture_const_range = llvm::iterator_range<const_capture_iterator>;
3639
3640
338k
  capture_range captures() {
3641
338k
    return capture_range(capture_begin(), capture_end());
3642
338k
  }
3643
802k
  capture_const_range captures() const {
3644
802k
    return capture_const_range(capture_begin(), capture_end());
3645
802k
  }
3646
3647
  /// Retrieve an iterator pointing to the first capture.
3648
370k
  capture_iterator capture_begin() { return getStoredCaptures(); }
3649
836k
  const_capture_iterator capture_begin() const { return getStoredCaptures(); }
3650
3651
  /// Retrieve an iterator pointing past the end of the sequence of
3652
  /// captures.
3653
1.20M
  capture_iterator capture_end() const {
3654
1.20M
    return getStoredCaptures() + NumCaptures;
3655
1.20M
  }
3656
3657
  /// Retrieve the number of captures, including 'this'.
3658
143
  unsigned capture_size() const { return NumCaptures; }
3659
3660
  /// Iterator that walks over the capture initialization arguments.
3661
  using capture_init_iterator = Expr **;
3662
  using capture_init_range = llvm::iterator_range<capture_init_iterator>;
3663
3664
  /// Const iterator that walks over the capture initialization
3665
  /// arguments.
3666
  using const_capture_init_iterator = Expr *const *;
3667
  using const_capture_init_range =
3668
      llvm::iterator_range<const_capture_init_iterator>;
3669
3670
32.2k
  capture_init_range capture_inits() {
3671
32.2k
    return capture_init_range(capture_init_begin(), capture_init_end());
3672
32.2k
  }
3673
3674
0
  const_capture_init_range capture_inits() const {
3675
0
    return const_capture_init_range(capture_init_begin(), capture_init_end());
3676
0
  }
3677
3678
  /// Retrieve the first initialization argument.
3679
127k
  capture_init_iterator capture_init_begin() {
3680
127k
    return reinterpret_cast<Expr **>(getStoredStmts());
3681
127k
  }
3682
3683
45.0k
  const_capture_init_iterator capture_init_begin() const {
3684
45.0k
    return reinterpret_cast<Expr *const *>(getStoredStmts());
3685
45.0k
  }
3686
3687
  /// Retrieve the iterator pointing one past the last initialization
3688
  /// argument.
3689
63.8k
  capture_init_iterator capture_init_end() {
3690
63.8k
    return capture_init_begin() + NumCaptures;
3691
63.8k
  }
3692
3693
22.5k
  const_capture_init_iterator capture_init_end() const {
3694
22.5k
    return capture_init_begin() + NumCaptures;
3695
22.5k
  }
3696
3697
447k
  SourceLocation getBeginLoc() const LLVM_READONLY {
3698
447k
    return getCapturedStmt()->getBeginLoc();
3699
447k
  }
3700
3701
7
  SourceLocation getEndLoc() const LLVM_READONLY {
3702
7
    return getCapturedStmt()->getEndLoc();
3703
7
  }
3704
3705
10.6k
  SourceRange getSourceRange() const LLVM_READONLY {
3706
10.6k
    return getCapturedStmt()->getSourceRange();
3707
10.6k
  }
3708
3709
3.21M
  static bool classof(const Stmt *T) {
3710
3.21M
    return T->getStmtClass() == CapturedStmtClass;
3711
3.21M
  }
3712
3713
  child_range children();
3714
3715
  const_child_range children() const;
3716
};
3717
3718
} // namespace clang
3719
3720
#endif // LLVM_CLANG_AST_STMT_H