Coverage Report

Created: 2020-09-22 08:39

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