Coverage Report

Created: 2019-07-24 05:18

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