Coverage Report

Created: 2019-03-22 08:08

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