Coverage Report

Created: 2018-09-23 03:40

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/Expr.h
Line
Count
Source (jump to first uncovered line)
1
//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
//  This file defines the Expr interface and subclasses.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_EXPR_H
15
#define LLVM_CLANG_AST_EXPR_H
16
17
#include "clang/AST/APValue.h"
18
#include "clang/AST/ASTVector.h"
19
#include "clang/AST/Decl.h"
20
#include "clang/AST/DeclAccessPair.h"
21
#include "clang/AST/OperationKinds.h"
22
#include "clang/AST/Stmt.h"
23
#include "clang/AST/TemplateBase.h"
24
#include "clang/AST/Type.h"
25
#include "clang/Basic/CharInfo.h"
26
#include "clang/Basic/LangOptions.h"
27
#include "clang/Basic/SyncScope.h"
28
#include "clang/Basic/TypeTraits.h"
29
#include "llvm/ADT/APFloat.h"
30
#include "llvm/ADT/APSInt.h"
31
#include "llvm/ADT/SmallVector.h"
32
#include "llvm/ADT/StringRef.h"
33
#include "llvm/Support/AtomicOrdering.h"
34
#include "llvm/Support/Compiler.h"
35
36
namespace clang {
37
  class APValue;
38
  class ASTContext;
39
  class BlockDecl;
40
  class CXXBaseSpecifier;
41
  class CXXMemberCallExpr;
42
  class CXXOperatorCallExpr;
43
  class CastExpr;
44
  class Decl;
45
  class IdentifierInfo;
46
  class MaterializeTemporaryExpr;
47
  class NamedDecl;
48
  class ObjCPropertyRefExpr;
49
  class OpaqueValueExpr;
50
  class ParmVarDecl;
51
  class StringLiteral;
52
  class TargetInfo;
53
  class ValueDecl;
54
55
/// A simple array of base specifiers.
56
typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
57
58
/// An adjustment to be made to the temporary created when emitting a
59
/// reference binding, which accesses a particular subobject of that temporary.
60
struct SubobjectAdjustment {
61
  enum {
62
    DerivedToBaseAdjustment,
63
    FieldAdjustment,
64
    MemberPointerAdjustment
65
  } Kind;
66
67
  struct DTB {
68
    const CastExpr *BasePath;
69
    const CXXRecordDecl *DerivedClass;
70
  };
71
72
  struct P {
73
    const MemberPointerType *MPT;
74
    Expr *RHS;
75
  };
76
77
  union {
78
    struct DTB DerivedToBase;
79
    FieldDecl *Field;
80
    struct P Ptr;
81
  };
82
83
  SubobjectAdjustment(const CastExpr *BasePath,
84
                      const CXXRecordDecl *DerivedClass)
85
4.06k
    : Kind(DerivedToBaseAdjustment) {
86
4.06k
    DerivedToBase.BasePath = BasePath;
87
4.06k
    DerivedToBase.DerivedClass = DerivedClass;
88
4.06k
  }
89
90
  SubobjectAdjustment(FieldDecl *Field)
91
53.7k
    : Kind(FieldAdjustment) {
92
53.7k
    this->Field = Field;
93
53.7k
  }
94
95
  SubobjectAdjustment(const MemberPointerType *MPT, Expr *RHS)
96
88
    : Kind(MemberPointerAdjustment) {
97
88
    this->Ptr.MPT = MPT;
98
88
    this->Ptr.RHS = RHS;
99
88
  }
100
};
101
102
/// This represents one expression.  Note that Expr's are subclasses of Stmt.
103
/// This allows an expression to be transparently used any place a Stmt is
104
/// required.
105
class Expr : public Stmt {
106
  QualType TR;
107
108
protected:
109
  Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK,
110
       bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack)
111
    : Stmt(SC)
112
87.8M
  {
113
87.8M
    ExprBits.TypeDependent = TD;
114
87.8M
    ExprBits.ValueDependent = VD;
115
87.8M
    ExprBits.InstantiationDependent = ID;
116
87.8M
    ExprBits.ValueKind = VK;
117
87.8M
    ExprBits.ObjectKind = OK;
118
87.8M
    assert(ExprBits.ObjectKind == OK && "truncated kind");
119
87.8M
    ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
120
87.8M
    setType(T);
121
87.8M
  }
122
123
  /// Construct an empty expression.
124
462k
  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
125
126
public:
127
837M
  QualType getType() const { return TR; }
128
92.4M
  void setType(QualType t) {
129
92.4M
    // In C++, the type of an expression is always adjusted so that it
130
92.4M
    // will not have reference type (C++ [expr]p6). Use
131
92.4M
    // QualType::getNonReferenceType() to retrieve the non-reference
132
92.4M
    // type. Additionally, inspect Expr::isLvalue to determine whether
133
92.4M
    // an expression that is adjusted in this manner should be
134
92.4M
    // considered an lvalue.
135
92.4M
    assert((t.isNull() || !t->isReferenceType()) &&
136
92.4M
           "Expressions can't have reference type");
137
92.4M
138
92.4M
    TR = t;
139
92.4M
  }
140
141
  /// isValueDependent - Determines whether this expression is
142
  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
143
  /// array bound of "Chars" in the following example is
144
  /// value-dependent.
145
  /// @code
146
  /// template<int Size, char (&Chars)[Size]> struct meta_string;
147
  /// @endcode
148
162M
  bool isValueDependent() const { return ExprBits.ValueDependent; }
149
150
  /// Set whether this expression is value-dependent or not.
151
483k
  void setValueDependent(bool VD) {
152
483k
    ExprBits.ValueDependent = VD;
153
483k
  }
154
155
  /// isTypeDependent - Determines whether this expression is
156
  /// type-dependent (C++ [temp.dep.expr]), which means that its type
157
  /// could change from one template instantiation to the next. For
158
  /// example, the expressions "x" and "x + y" are type-dependent in
159
  /// the following code, but "y" is not type-dependent:
160
  /// @code
161
  /// template<typename T>
162
  /// void add(T x, int y) {
163
  ///   x + y;
164
  /// }
165
  /// @endcode
166
164M
  bool isTypeDependent() const { return ExprBits.TypeDependent; }
167
168
  /// Set whether this expression is type-dependent or not.
169
465k
  void setTypeDependent(bool TD) {
170
465k
    ExprBits.TypeDependent = TD;
171
465k
  }
172
173
  /// Whether this expression is instantiation-dependent, meaning that
174
  /// it depends in some way on a template parameter, even if neither its type
175
  /// nor (constant) value can change due to the template instantiation.
176
  ///
177
  /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
178
  /// instantiation-dependent (since it involves a template parameter \c T), but
179
  /// is neither type- nor value-dependent, since the type of the inner
180
  /// \c sizeof is known (\c std::size_t) and therefore the size of the outer
181
  /// \c sizeof is known.
182
  ///
183
  /// \code
184
  /// template<typename T>
185
  /// void f(T x, T y) {
186
  ///   sizeof(sizeof(T() + T());
187
  /// }
188
  /// \endcode
189
  ///
190
88.2M
  bool isInstantiationDependent() const {
191
88.2M
    return ExprBits.InstantiationDependent;
192
88.2M
  }
193
194
  /// Set whether this expression is instantiation-dependent or not.
195
483k
  void setInstantiationDependent(bool ID) {
196
483k
    ExprBits.InstantiationDependent = ID;
197
483k
  }
198
199
  /// Whether this expression contains an unexpanded parameter
200
  /// pack (for C++11 variadic templates).
201
  ///
202
  /// Given the following function template:
203
  ///
204
  /// \code
205
  /// template<typename F, typename ...Types>
206
  /// void forward(const F &f, Types &&...args) {
207
  ///   f(static_cast<Types&&>(args)...);
208
  /// }
209
  /// \endcode
210
  ///
211
  /// The expressions \c args and \c static_cast<Types&&>(args) both
212
  /// contain parameter packs.
213
92.1M
  bool containsUnexpandedParameterPack() const {
214
92.1M
    return ExprBits.ContainsUnexpandedParameterPack;
215
92.1M
  }
216
217
  /// Set the bit that describes whether this expression
218
  /// contains an unexpanded parameter pack.
219
2.09k
  void setContainsUnexpandedParameterPack(bool PP = true) {
220
2.09k
    ExprBits.ContainsUnexpandedParameterPack = PP;
221
2.09k
  }
222
223
  /// getExprLoc - Return the preferred location for the arrow when diagnosing
224
  /// a problem with a generic expression.
225
  SourceLocation getExprLoc() const LLVM_READONLY;
226
227
  /// isUnusedResultAWarning - Return true if this immediate expression should
228
  /// be warned about if the result is unused.  If so, fill in expr, location,
229
  /// and ranges with expr to warn on and source locations/ranges appropriate
230
  /// for a warning.
231
  bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc,
232
                              SourceRange &R1, SourceRange &R2,
233
                              ASTContext &Ctx) const;
234
235
  /// isLValue - True if this expression is an "l-value" according to
236
  /// the rules of the current language.  C and C++ give somewhat
237
  /// different rules for this concept, but in general, the result of
238
  /// an l-value expression identifies a specific object whereas the
239
  /// result of an r-value expression is a value detached from any
240
  /// specific storage.
241
  ///
242
  /// C++11 divides the concept of "r-value" into pure r-values
243
  /// ("pr-values") and so-called expiring values ("x-values"), which
244
  /// identify specific objects that can be safely cannibalized for
245
  /// their resources.  This is an unfortunate abuse of terminology on
246
  /// the part of the C++ committee.  In Clang, when we say "r-value",
247
  /// we generally mean a pr-value.
248
858k
  bool isLValue() const { return getValueKind() == VK_LValue; }
249
35.9M
  bool isRValue() const { return getValueKind() == VK_RValue; }
250
519
  bool isXValue() const { return getValueKind() == VK_XValue; }
251
97.4M
  bool isGLValue() const { return getValueKind() != VK_RValue; }
252
253
  enum LValueClassification {
254
    LV_Valid,
255
    LV_NotObjectType,
256
    LV_IncompleteVoidType,
257
    LV_DuplicateVectorComponents,
258
    LV_InvalidExpression,
259
    LV_InvalidMessageExpression,
260
    LV_MemberFunction,
261
    LV_SubObjCPropertySetting,
262
    LV_ClassTemporary,
263
    LV_ArrayTemporary
264
  };
265
  /// Reasons why an expression might not be an l-value.
266
  LValueClassification ClassifyLValue(ASTContext &Ctx) const;
267
268
  enum isModifiableLvalueResult {
269
    MLV_Valid,
270
    MLV_NotObjectType,
271
    MLV_IncompleteVoidType,
272
    MLV_DuplicateVectorComponents,
273
    MLV_InvalidExpression,
274
    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
275
    MLV_IncompleteType,
276
    MLV_ConstQualified,
277
    MLV_ConstQualifiedField,
278
    MLV_ConstAddrSpace,
279
    MLV_ArrayType,
280
    MLV_NoSetterProperty,
281
    MLV_MemberFunction,
282
    MLV_SubObjCPropertySetting,
283
    MLV_InvalidMessageExpression,
284
    MLV_ClassTemporary,
285
    MLV_ArrayTemporary
286
  };
287
  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
288
  /// does not have an incomplete type, does not have a const-qualified type,
289
  /// and if it is a structure or union, does not have any member (including,
290
  /// recursively, any member or element of all contained aggregates or unions)
291
  /// with a const-qualified type.
292
  ///
293
  /// \param Loc [in,out] - A source location which *may* be filled
294
  /// in with the location of the expression making this a
295
  /// non-modifiable lvalue, if specified.
296
  isModifiableLvalueResult
297
  isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc = nullptr) const;
298
299
  /// The return type of classify(). Represents the C++11 expression
300
  ///        taxonomy.
301
  class Classification {
302
  public:
303
    /// The various classification results. Most of these mean prvalue.
304
    enum Kinds {
305
      CL_LValue,
306
      CL_XValue,
307
      CL_Function, // Functions cannot be lvalues in C.
308
      CL_Void, // Void cannot be an lvalue in C.
309
      CL_AddressableVoid, // Void expression whose address can be taken in C.
310
      CL_DuplicateVectorComponents, // A vector shuffle with dupes.
311
      CL_MemberFunction, // An expression referring to a member function
312
      CL_SubObjCPropertySetting,
313
      CL_ClassTemporary, // A temporary of class type, or subobject thereof.
314
      CL_ArrayTemporary, // A temporary of array type.
315
      CL_ObjCMessageRValue, // ObjC message is an rvalue
316
      CL_PRValue // A prvalue for any other reason, of any other type
317
    };
318
    /// The results of modification testing.
319
    enum ModifiableType {
320
      CM_Untested, // testModifiable was false.
321
      CM_Modifiable,
322
      CM_RValue, // Not modifiable because it's an rvalue
323
      CM_Function, // Not modifiable because it's a function; C++ only
324
      CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
325
      CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
326
      CM_ConstQualified,
327
      CM_ConstQualifiedField,
328
      CM_ConstAddrSpace,
329
      CM_ArrayType,
330
      CM_IncompleteType
331
    };
332
333
  private:
334
    friend class Expr;
335
336
    unsigned short Kind;
337
    unsigned short Modifiable;
338
339
    explicit Classification(Kinds k, ModifiableType m)
340
      : Kind(k), Modifiable(m)
341
12.4M
    {}
342
343
  public:
344
1.31M
    Classification() {}
345
346
2.07M
    Kinds getKind() const { return static_cast<Kinds>(Kind); }
347
1.88M
    ModifiableType getModifiable() const {
348
1.88M
      assert(Modifiable != CM_Untested && "Did not test for modifiability.");
349
1.88M
      return static_cast<ModifiableType>(Modifiable);
350
1.88M
    }
351
7.02M
    bool isLValue() const { return Kind == CL_LValue; }
352
884k
    bool isXValue() const { return Kind == CL_XValue; }
353
0
    bool isGLValue() const { return Kind <= CL_XValue; }
354
956k
    bool isPRValue() const { return Kind >= CL_Function; }
355
2.77M
    bool isRValue() const { return Kind >= CL_XValue; }
356
0
    bool isModifiable() const { return getModifiable() == CM_Modifiable; }
357
358
    /// Create a simple, modifiably lvalue
359
410k
    static Classification makeSimpleLValue() {
360
410k
      return Classification(CL_LValue, CM_Modifiable);
361
410k
    }
362
363
  };
364
  /// Classify - Classify this expression according to the C++11
365
  ///        expression taxonomy.
366
  ///
367
  /// C++11 defines ([basic.lval]) a new taxonomy of expressions to replace the
368
  /// old lvalue vs rvalue. This function determines the type of expression this
369
  /// is. There are three expression types:
370
  /// - lvalues are classical lvalues as in C++03.
371
  /// - prvalues are equivalent to rvalues in C++03.
372
  /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
373
  ///   function returning an rvalue reference.
374
  /// lvalues and xvalues are collectively referred to as glvalues, while
375
  /// prvalues and xvalues together form rvalues.
376
10.1M
  Classification Classify(ASTContext &Ctx) const {
377
10.1M
    return ClassifyImpl(Ctx, nullptr);
378
10.1M
  }
379
380
  /// ClassifyModifiable - Classify this expression according to the
381
  ///        C++11 expression taxonomy, and see if it is valid on the left side
382
  ///        of an assignment.
383
  ///
384
  /// This function extends classify in that it also tests whether the
385
  /// expression is modifiable (C99 6.3.2.1p1).
386
  /// \param Loc A source location that might be filled with a relevant location
387
  ///            if the expression is not modifiable.
388
1.88M
  Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{
389
1.88M
    return ClassifyImpl(Ctx, &Loc);
390
1.88M
  }
391
392
  /// getValueKindForType - Given a formal return or parameter type,
393
  /// give its value kind.
394
7.98M
  static ExprValueKind getValueKindForType(QualType T) {
395
7.98M
    if (const ReferenceType *RT = T->getAs<ReferenceType>())
396
469k
      return (isa<LValueReferenceType>(RT)
397
469k
                ? 
VK_LValue352k
398
469k
                : (RT->getPointeeType()->isFunctionType()
399
117k
                     ? 
VK_LValue3
:
VK_XValue117k
));
400
7.51M
    return VK_RValue;
401
7.51M
  }
402
403
  /// getValueKind - The value kind that this expression produces.
404
142M
  ExprValueKind getValueKind() const {
405
142M
    return static_cast<ExprValueKind>(ExprBits.ValueKind);
406
142M
  }
407
408
  /// getObjectKind - The object kind that this expression produces.
409
  /// Object kinds are meaningful only for expressions that yield an
410
  /// l-value or x-value.
411
7.33M
  ExprObjectKind getObjectKind() const {
412
7.33M
    return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
413
7.33M
  }
414
415
18.6k
  bool isOrdinaryOrBitFieldObject() const {
416
18.6k
    ExprObjectKind OK = getObjectKind();
417
18.6k
    return (OK == OK_Ordinary || 
OK == OK_BitField46
);
418
18.6k
  }
419
420
  /// setValueKind - Set the value kind produced by this expression.
421
3.30M
  void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
422
423
  /// setObjectKind - Set the object kind produced by this expression.
424
466k
  void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; }
425
426
private:
427
  Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
428
429
public:
430
431
  /// Returns true if this expression is a gl-value that
432
  /// potentially refers to a bit-field.
433
  ///
434
  /// In C++, whether a gl-value refers to a bitfield is essentially
435
  /// an aspect of the value-kind type system.
436
545k
  bool refersToBitField() const { return getObjectKind() == OK_BitField; }
437
438
  /// If this expression refers to a bit-field, retrieve the
439
  /// declaration of that bit-field.
440
  ///
441
  /// Note that this returns a non-null pointer in subtly different
442
  /// places than refersToBitField returns true.  In particular, this can
443
  /// return a non-null pointer even for r-values loaded from
444
  /// bit-fields, but it will return null for a conditional bit-field.
445
  FieldDecl *getSourceBitField();
446
447
382k
  const FieldDecl *getSourceBitField() const {
448
382k
    return const_cast<Expr*>(this)->getSourceBitField();
449
382k
  }
450
451
  Decl *getReferencedDeclOfCallee();
452
4.87k
  const Decl *getReferencedDeclOfCallee() const {
453
4.87k
    return const_cast<Expr*>(this)->getReferencedDeclOfCallee();
454
4.87k
  }
455
456
  /// If this expression is an l-value for an Objective C
457
  /// property, find the underlying property reference expression.
458
  const ObjCPropertyRefExpr *getObjCProperty() const;
459
460
  /// Check if this expression is the ObjC 'self' implicit parameter.
461
  bool isObjCSelfExpr() const;
462
463
  /// Returns whether this expression refers to a vector element.
464
  bool refersToVectorElement() const;
465
466
  /// Returns whether this expression refers to a global register
467
  /// variable.
468
  bool refersToGlobalRegisterVar() const;
469
470
  /// Returns whether this expression has a placeholder type.
471
4.24M
  bool hasPlaceholderType() const {
472
4.24M
    return getType()->isPlaceholderType();
473
4.24M
  }
474
475
  /// Returns whether this expression has a specific placeholder type.
476
6.36k
  bool hasPlaceholderType(BuiltinType::Kind K) const {
477
6.36k
    assert(BuiltinType::isPlaceholderTypeKind(K));
478
6.36k
    if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType()))
479
3.30k
      return BT->getKind() == K;
480
3.05k
    return false;
481
3.05k
  }
482
483
  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
484
  /// that is known to return 0 or 1.  This happens for _Bool/bool expressions
485
  /// but also int expressions which are produced by things like comparisons in
486
  /// C.
487
  bool isKnownToHaveBooleanValue() const;
488
489
  /// isIntegerConstantExpr - Return true if this expression is a valid integer
490
  /// constant expression, and, if so, return its value in Result.  If not a
491
  /// valid i-c-e, return false and fill in Loc (if specified) with the location
492
  /// of the invalid expression.
493
  ///
494
  /// Note: This does not perform the implicit conversions required by C++11
495
  /// [expr.const]p5.
496
  bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx,
497
                             SourceLocation *Loc = nullptr,
498
                             bool isEvaluated = true) const;
499
  bool isIntegerConstantExpr(const ASTContext &Ctx,
500
                             SourceLocation *Loc = nullptr) const;
501
502
  /// isCXX98IntegralConstantExpr - Return true if this expression is an
503
  /// integral constant expression in C++98. Can only be used in C++.
504
  bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const;
505
506
  /// isCXX11ConstantExpr - Return true if this expression is a constant
507
  /// expression in C++11. Can only be used in C++.
508
  ///
509
  /// Note: This does not perform the implicit conversions required by C++11
510
  /// [expr.const]p5.
511
  bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = nullptr,
512
                           SourceLocation *Loc = nullptr) const;
513
514
  /// isPotentialConstantExpr - Return true if this function's definition
515
  /// might be usable in a constant expression in C++11, if it were marked
516
  /// constexpr. Return false if the function can never produce a constant
517
  /// expression, along with diagnostics describing why not.
518
  static bool isPotentialConstantExpr(const FunctionDecl *FD,
519
                                      SmallVectorImpl<
520
                                        PartialDiagnosticAt> &Diags);
521
522
  /// isPotentialConstantExprUnevaluted - Return true if this expression might
523
  /// be usable in a constant expression in C++11 in an unevaluated context, if
524
  /// it were in function FD marked constexpr. Return false if the function can
525
  /// never produce a constant expression, along with diagnostics describing
526
  /// why not.
527
  static bool isPotentialConstantExprUnevaluated(Expr *E,
528
                                                 const FunctionDecl *FD,
529
                                                 SmallVectorImpl<
530
                                                   PartialDiagnosticAt> &Diags);
531
532
  /// isConstantInitializer - Returns true if this expression can be emitted to
533
  /// IR as a constant, and thus can be used as a constant initializer in C.
534
  /// If this expression is not constant and Culprit is non-null,
535
  /// it is used to store the address of first non constant expr.
536
  bool isConstantInitializer(ASTContext &Ctx, bool ForRef,
537
                             const Expr **Culprit = nullptr) const;
538
539
  /// EvalStatus is a struct with detailed info about an evaluation in progress.
540
  struct EvalStatus {
541
    /// Whether the evaluated expression has side effects.
542
    /// For example, (f() && 0) can be folded, but it still has side effects.
543
    bool HasSideEffects;
544
545
    /// Whether the evaluation hit undefined behavior.
546
    /// For example, 1.0 / 0.0 can be folded to Inf, but has undefined behavior.
547
    /// Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB.
548
    bool HasUndefinedBehavior;
549
550
    /// Diag - If this is non-null, it will be filled in with a stack of notes
551
    /// indicating why evaluation failed (or why it failed to produce a constant
552
    /// expression).
553
    /// If the expression is unfoldable, the notes will indicate why it's not
554
    /// foldable. If the expression is foldable, but not a constant expression,
555
    /// the notes will describes why it isn't a constant expression. If the
556
    /// expression *is* a constant expression, no notes will be produced.
557
    SmallVectorImpl<PartialDiagnosticAt> *Diag;
558
559
    EvalStatus()
560
29.4M
        : HasSideEffects(false), HasUndefinedBehavior(false), Diag(nullptr) {}
561
562
    // hasSideEffects - Return true if the evaluated expression has
563
    // side effects.
564
1.79k
    bool hasSideEffects() const {
565
1.79k
      return HasSideEffects;
566
1.79k
    }
567
  };
568
569
  /// EvalResult is a struct with detailed info about an evaluated expression.
570
  struct EvalResult : EvalStatus {
571
    /// Val - This is the value the expression can be folded to.
572
    APValue Val;
573
574
    // isGlobalLValue - Return true if the evaluated lvalue expression
575
    // is global.
576
    bool isGlobalLValue() const;
577
  };
578
579
  /// EvaluateAsRValue - Return true if this is a constant which we can fold to
580
  /// an rvalue using any crazy technique (that has nothing to do with language
581
  /// standards) that we want to, even if the expression has side-effects. If
582
  /// this function returns true, it returns the folded constant in Result. If
583
  /// the expression is a glvalue, an lvalue-to-rvalue conversion will be
584
  /// applied.
585
  bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const;
586
587
  /// EvaluateAsBooleanCondition - Return true if this is a constant
588
  /// which we can fold and convert to a boolean condition using
589
  /// any crazy technique that we want to, even if the expression has
590
  /// side-effects.
591
  bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const;
592
593
  enum SideEffectsKind {
594
    SE_NoSideEffects,          ///< Strictly evaluate the expression.
595
    SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not
596
                               ///< arbitrary unmodeled side effects.
597
    SE_AllowSideEffects        ///< Allow any unmodeled side effect.
598
  };
599
600
  /// EvaluateAsInt - Return true if this is a constant which we can fold and
601
  /// convert to an integer, using any crazy technique that we want to.
602
  bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx,
603
                     SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
604
605
  /// EvaluateAsFloat - Return true if this is a constant which we can fold and
606
  /// convert to a floating point value, using any crazy technique that we
607
  /// want to.
608
  bool
609
  EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx,
610
                  SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
611
612
  /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
613
  /// constant folded without side-effects, but discard the result.
614
  bool isEvaluatable(const ASTContext &Ctx,
615
                     SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
616
617
  /// HasSideEffects - This routine returns true for all those expressions
618
  /// which have any effect other than producing a value. Example is a function
619
  /// call, volatile variable read, or throwing an exception. If
620
  /// IncludePossibleEffects is false, this call treats certain expressions with
621
  /// potential side effects (such as function call-like expressions,
622
  /// instantiation-dependent expressions, or invocations from a macro) as not
623
  /// having side effects.
624
  bool HasSideEffects(const ASTContext &Ctx,
625
                      bool IncludePossibleEffects = true) const;
626
627
  /// Determine whether this expression involves a call to any function
628
  /// that is not trivial.
629
  bool hasNonTrivialCall(const ASTContext &Ctx) const;
630
631
  /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
632
  /// integer. This must be called on an expression that constant folds to an
633
  /// integer.
634
  llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx,
635
                    SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr) const;
636
637
  void EvaluateForOverflow(const ASTContext &Ctx) const;
638
639
  /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
640
  /// lvalue with link time known address, with no side-effects.
641
  bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const;
642
643
  /// EvaluateAsInitializer - Evaluate an expression as if it were the
644
  /// initializer of the given declaration. Returns true if the initializer
645
  /// can be folded to a constant, and produces any relevant notes. In C++11,
646
  /// notes will be produced if the expression is not a constant expression.
647
  bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx,
648
                             const VarDecl *VD,
649
                             SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
650
651
  /// EvaluateWithSubstitution - Evaluate an expression as if from the context
652
  /// of a call to the given function with the given arguments, inside an
653
  /// unevaluated context. Returns true if the expression could be folded to a
654
  /// constant.
655
  bool EvaluateWithSubstitution(APValue &Value, ASTContext &Ctx,
656
                                const FunctionDecl *Callee,
657
                                ArrayRef<const Expr*> Args,
658
                                const Expr *This = nullptr) const;
659
660
  /// Indicates how the constant expression will be used.
661
  enum ConstExprUsage { EvaluateForCodeGen, EvaluateForMangling };
662
663
  /// Evaluate an expression that is required to be a constant expression.
664
  bool EvaluateAsConstantExpr(EvalResult &Result, ConstExprUsage Usage,
665
                              const ASTContext &Ctx) const;
666
667
  /// If the current Expr is a pointer, this will try to statically
668
  /// determine the number of bytes available where the pointer is pointing.
669
  /// Returns true if all of the above holds and we were able to figure out the
670
  /// size, false otherwise.
671
  ///
672
  /// \param Type - How to evaluate the size of the Expr, as defined by the
673
  /// "type" parameter of __builtin_object_size
674
  bool tryEvaluateObjectSize(uint64_t &Result, ASTContext &Ctx,
675
                             unsigned Type) const;
676
677
  /// Enumeration used to describe the kind of Null pointer constant
678
  /// returned from \c isNullPointerConstant().
679
  enum NullPointerConstantKind {
680
    /// Expression is not a Null pointer constant.
681
    NPCK_NotNull = 0,
682
683
    /// Expression is a Null pointer constant built from a zero integer
684
    /// expression that is not a simple, possibly parenthesized, zero literal.
685
    /// C++ Core Issue 903 will classify these expressions as "not pointers"
686
    /// once it is adopted.
687
    /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
688
    NPCK_ZeroExpression,
689
690
    /// Expression is a Null pointer constant built from a literal zero.
691
    NPCK_ZeroLiteral,
692
693
    /// Expression is a C++11 nullptr.
694
    NPCK_CXX11_nullptr,
695
696
    /// Expression is a GNU-style __null constant.
697
    NPCK_GNUNull
698
  };
699
700
  /// Enumeration used to describe how \c isNullPointerConstant()
701
  /// should cope with value-dependent expressions.
702
  enum NullPointerConstantValueDependence {
703
    /// Specifies that the expression should never be value-dependent.
704
    NPC_NeverValueDependent = 0,
705
706
    /// Specifies that a value-dependent expression of integral or
707
    /// dependent type should be considered a null pointer constant.
708
    NPC_ValueDependentIsNull,
709
710
    /// Specifies that a value-dependent expression should be considered
711
    /// to never be a null pointer constant.
712
    NPC_ValueDependentIsNotNull
713
  };
714
715
  /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
716
  /// a Null pointer constant. The return value can further distinguish the
717
  /// kind of NULL pointer constant that was detected.
718
  NullPointerConstantKind isNullPointerConstant(
719
      ASTContext &Ctx,
720
      NullPointerConstantValueDependence NPC) const;
721
722
  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
723
  /// write barrier.
724
  bool isOBJCGCCandidate(ASTContext &Ctx) const;
725
726
  /// Returns true if this expression is a bound member function.
727
  bool isBoundMemberFunction(ASTContext &Ctx) const;
728
729
  /// Given an expression of bound-member type, find the type
730
  /// of the member.  Returns null if this is an *overloaded* bound
731
  /// member expression.
732
  static QualType findBoundMemberType(const Expr *expr);
733
734
  /// IgnoreImpCasts - Skip past any implicit casts which might
735
  /// surround this expression.  Only skips ImplicitCastExprs.
736
  Expr *IgnoreImpCasts() LLVM_READONLY;
737
738
  /// IgnoreImplicit - Skip past any implicit AST nodes which might
739
  /// surround this expression.
740
411k
  Expr *IgnoreImplicit() LLVM_READONLY {
741
411k
    return cast<Expr>(Stmt::IgnoreImplicit());
742
411k
  }
743
744
28.6k
  const Expr *IgnoreImplicit() const LLVM_READONLY {
745
28.6k
    return const_cast<Expr*>(this)->IgnoreImplicit();
746
28.6k
  }
747
748
  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
749
  ///  its subexpression.  If that subexpression is also a ParenExpr,
750
  ///  then this method recursively returns its subexpression, and so forth.
751
  ///  Otherwise, the method returns the current Expr.
752
  Expr *IgnoreParens() LLVM_READONLY;
753
754
  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
755
  /// or CastExprs, returning their operand.
756
  Expr *IgnoreParenCasts() LLVM_READONLY;
757
758
  /// Ignore casts.  Strip off any CastExprs, returning their operand.
759
  Expr *IgnoreCasts() LLVM_READONLY;
760
761
  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off
762
  /// any ParenExpr or ImplicitCastExprs, returning their operand.
763
  Expr *IgnoreParenImpCasts() LLVM_READONLY;
764
765
  /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a
766
  /// call to a conversion operator, return the argument.
767
  Expr *IgnoreConversionOperator() LLVM_READONLY;
768
769
0
  const Expr *IgnoreConversionOperator() const LLVM_READONLY {
770
0
    return const_cast<Expr*>(this)->IgnoreConversionOperator();
771
0
  }
772
773
32.7M
  const Expr *IgnoreParenImpCasts() const LLVM_READONLY {
774
32.7M
    return const_cast<Expr*>(this)->IgnoreParenImpCasts();
775
32.7M
  }
776
777
  /// Ignore parentheses and lvalue casts.  Strip off any ParenExpr and
778
  /// CastExprs that represent lvalue casts, returning their operand.
779
  Expr *IgnoreParenLValueCasts() LLVM_READONLY;
780
781
1.28k
  const Expr *IgnoreParenLValueCasts() const LLVM_READONLY {
782
1.28k
    return const_cast<Expr*>(this)->IgnoreParenLValueCasts();
783
1.28k
  }
784
785
  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
786
  /// value (including ptr->int casts of the same size).  Strip off any
787
  /// ParenExpr or CastExprs, returning their operand.
788
  Expr *IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY;
789
790
  /// Ignore parentheses and derived-to-base casts.
791
  Expr *ignoreParenBaseCasts() LLVM_READONLY;
792
793
102k
  const Expr *ignoreParenBaseCasts() const LLVM_READONLY {
794
102k
    return const_cast<Expr*>(this)->ignoreParenBaseCasts();
795
102k
  }
796
797
  /// Determine whether this expression is a default function argument.
798
  ///
799
  /// Default arguments are implicitly generated in the abstract syntax tree
800
  /// by semantic analysis for function calls, object constructions, etc. in
801
  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
802
  /// this routine also looks through any implicit casts to determine whether
803
  /// the expression is a default argument.
804
  bool isDefaultArgument() const;
805
806
  /// Determine whether the result of this expression is a
807
  /// temporary object of the given class type.
808
  bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
809
810
  /// Whether this expression is an implicit reference to 'this' in C++.
811
  bool isImplicitCXXThis() const;
812
813
983k
  const Expr *IgnoreImpCasts() const LLVM_READONLY {
814
983k
    return const_cast<Expr*>(this)->IgnoreImpCasts();
815
983k
  }
816
37.8M
  const Expr *IgnoreParens() const LLVM_READONLY {
817
37.8M
    return const_cast<Expr*>(this)->IgnoreParens();
818
37.8M
  }
819
1.14M
  const Expr *IgnoreParenCasts() const LLVM_READONLY {
820
1.14M
    return const_cast<Expr*>(this)->IgnoreParenCasts();
821
1.14M
  }
822
  /// Strip off casts, but keep parentheses.
823
944
  const Expr *IgnoreCasts() const LLVM_READONLY {
824
944
    return const_cast<Expr*>(this)->IgnoreCasts();
825
944
  }
826
827
2.03M
  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const LLVM_READONLY {
828
2.03M
    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
829
2.03M
  }
830
831
  static bool hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs);
832
833
  /// For an expression of class type or pointer to class type,
834
  /// return the most derived class decl the expression is known to refer to.
835
  ///
836
  /// If this expression is a cast, this method looks through it to find the
837
  /// most derived decl that can be inferred from the expression.
838
  /// This is valid because derived-to-base conversions have undefined
839
  /// behavior if the object isn't dynamically of the derived type.
840
  const CXXRecordDecl *getBestDynamicClassType() const;
841
842
  /// Get the inner expression that determines the best dynamic class.
843
  /// If this is a prvalue, we guarantee that it is of the most-derived type
844
  /// for the object itself.
845
  const Expr *getBestDynamicClassTypeExpr() const;
846
847
  /// Walk outwards from an expression we want to bind a reference to and
848
  /// find the expression whose lifetime needs to be extended. Record
849
  /// the LHSs of comma expressions and adjustments needed along the path.
850
  const Expr *skipRValueSubobjectAdjustments(
851
      SmallVectorImpl<const Expr *> &CommaLHS,
852
      SmallVectorImpl<SubobjectAdjustment> &Adjustments) const;
853
8.45M
  const Expr *skipRValueSubobjectAdjustments() const {
854
8.45M
    SmallVector<const Expr *, 8> CommaLHSs;
855
8.45M
    SmallVector<SubobjectAdjustment, 8> Adjustments;
856
8.45M
    return skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
857
8.45M
  }
858
859
64.4M
  static bool classof(const Stmt *T) {
860
64.4M
    return T->getStmtClass() >= firstExprConstant &&
861
64.4M
           
T->getStmtClass() <= lastExprConstant58.9M
;
862
64.4M
  }
863
};
864
865
//===----------------------------------------------------------------------===//
866
// Primary Expressions.
867
//===----------------------------------------------------------------------===//
868
869
/// OpaqueValueExpr - An expression referring to an opaque object of a
870
/// fixed type and value class.  These don't correspond to concrete
871
/// syntax; instead they're used to express operations (usually copy
872
/// operations) on values whose source is generally obvious from
873
/// context.
874
class OpaqueValueExpr : public Expr {
875
  friend class ASTStmtReader;
876
  Expr *SourceExpr;
877
  SourceLocation Loc;
878
879
public:
880
  OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK,
881
                  ExprObjectKind OK = OK_Ordinary,
882
                  Expr *SourceExpr = nullptr)
883
    : Expr(OpaqueValueExprClass, T, VK, OK,
884
           T->isDependentType() ||
885
           (SourceExpr && SourceExpr->isTypeDependent()),
886
           T->isDependentType() ||
887
           (SourceExpr && SourceExpr->isValueDependent()),
888
           T->isInstantiationDependentType() ||
889
           (SourceExpr && SourceExpr->isInstantiationDependent()),
890
           false),
891
552k
      SourceExpr(SourceExpr), Loc(Loc) {
892
552k
    setIsUnique(false);
893
552k
  }
894
895
  /// Given an expression which invokes a copy constructor --- i.e.  a
896
  /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
897
  /// find the OpaqueValueExpr that's the source of the construction.
898
  static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
899
900
  explicit OpaqueValueExpr(EmptyShell Empty)
901
623
    : Expr(OpaqueValueExprClass, Empty) { }
902
903
  /// Retrieve the location of this expression.
904
623
  SourceLocation getLocation() const { return Loc; }
905
906
479k
  SourceLocation getBeginLoc() const LLVM_READONLY {
907
479k
    return SourceExpr ? 
SourceExpr->getBeginLoc()43.0k
:
Loc436k
;
908
479k
  }
909
8.38k
  SourceLocation getEndLoc() const LLVM_READONLY {
910
8.38k
    return SourceExpr ? 
SourceExpr->getEndLoc()6.30k
:
Loc2.07k
;
911
8.38k
  }
912
25.5k
  SourceLocation getExprLoc() const LLVM_READONLY {
913
25.5k
    if (SourceExpr) 
return SourceExpr->getExprLoc()16.1k
;
914
9.35k
    return Loc;
915
9.35k
  }
916
917
32.2k
  child_range children() {
918
32.2k
    return child_range(child_iterator(), child_iterator());
919
32.2k
  }
920
921
0
  const_child_range children() const {
922
0
    return const_child_range(const_child_iterator(), const_child_iterator());
923
0
  }
924
925
  /// The source expression of an opaque value expression is the
926
  /// expression which originally generated the value.  This is
927
  /// provided as a convenience for analyses that don't wish to
928
  /// precisely model the execution behavior of the program.
929
  ///
930
  /// The source expression is typically set when building the
931
  /// expression which binds the opaque value expression in the first
932
  /// place.
933
22.7k
  Expr *getSourceExpr() const { return SourceExpr; }
934
935
557k
  void setIsUnique(bool V) {
936
557k
    assert((!V || SourceExpr) &&
937
557k
           "unique OVEs are expected to have source expressions");
938
557k
    OpaqueValueExprBits.IsUnique = V;
939
557k
  }
940
941
1.30k
  bool isUnique() const { return OpaqueValueExprBits.IsUnique; }
942
943
7.18M
  static bool classof(const Stmt *T) {
944
7.18M
    return T->getStmtClass() == OpaqueValueExprClass;
945
7.18M
  }
946
};
947
948
/// A reference to a declared variable, function, enum, etc.
949
/// [C99 6.5.1p2]
950
///
951
/// This encodes all the information about how a declaration is referenced
952
/// within an expression.
953
///
954
/// There are several optional constructs attached to DeclRefExprs only when
955
/// they apply in order to conserve memory. These are laid out past the end of
956
/// the object, and flags in the DeclRefExprBitfield track whether they exist:
957
///
958
///   DeclRefExprBits.HasQualifier:
959
///       Specifies when this declaration reference expression has a C++
960
///       nested-name-specifier.
961
///   DeclRefExprBits.HasFoundDecl:
962
///       Specifies when this declaration reference expression has a record of
963
///       a NamedDecl (different from the referenced ValueDecl) which was found
964
///       during name lookup and/or overload resolution.
965
///   DeclRefExprBits.HasTemplateKWAndArgsInfo:
966
///       Specifies when this declaration reference expression has an explicit
967
///       C++ template keyword and/or template argument list.
968
///   DeclRefExprBits.RefersToEnclosingVariableOrCapture
969
///       Specifies when this declaration reference expression (validly)
970
///       refers to an enclosed local or a captured variable.
971
class DeclRefExpr final
972
    : public Expr,
973
      private llvm::TrailingObjects<DeclRefExpr, NestedNameSpecifierLoc,
974
                                    NamedDecl *, ASTTemplateKWAndArgsInfo,
975
                                    TemplateArgumentLoc> {
976
  /// The declaration that we are referencing.
977
  ValueDecl *D;
978
979
  /// The location of the declaration name itself.
980
  SourceLocation Loc;
981
982
  /// Provides source/type location info for the declaration name
983
  /// embedded in D.
984
  DeclarationNameLoc DNLoc;
985
986
1.18M
  size_t numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const {
987
1.18M
    return hasQualifier() ? 
1817k
:
0364k
;
988
1.18M
  }
989
990
856k
  size_t numTrailingObjects(OverloadToken<NamedDecl *>) const {
991
856k
    return hasFoundDecl() ? 
1853k
:
02.29k
;
992
856k
  }
993
994
210k
  size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
995
210k
    return hasTemplateKWAndArgsInfo() ? 1 : 
00
;
996
210k
  }
997
998
  /// Test whether there is a distinct FoundDecl attached to the end of
999
  /// this DRE.
1000
1.67M
  bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
1001
1002
  DeclRefExpr(const ASTContext &Ctx,
1003
              NestedNameSpecifierLoc QualifierLoc,
1004
              SourceLocation TemplateKWLoc,
1005
              ValueDecl *D, bool RefersToEnlosingVariableOrCapture,
1006
              const DeclarationNameInfo &NameInfo,
1007
              NamedDecl *FoundD,
1008
              const TemplateArgumentListInfo *TemplateArgs,
1009
              QualType T, ExprValueKind VK);
1010
1011
  /// Construct an empty declaration reference expression.
1012
  explicit DeclRefExpr(EmptyShell Empty)
1013
130k
    : Expr(DeclRefExprClass, Empty) { }
1014
1015
  /// Computes the type- and value-dependence flags for this
1016
  /// declaration reference expression.
1017
  void computeDependence(const ASTContext &C);
1018
1019
public:
1020
  DeclRefExpr(ValueDecl *D, bool RefersToEnclosingVariableOrCapture, QualType T,
1021
              ExprValueKind VK, SourceLocation L,
1022
              const DeclarationNameLoc &LocInfo = DeclarationNameLoc())
1023
    : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false),
1024
1.60M
      D(D), Loc(L), DNLoc(LocInfo) {
1025
1.60M
    DeclRefExprBits.HasQualifier = 0;
1026
1.60M
    DeclRefExprBits.HasTemplateKWAndArgsInfo = 0;
1027
1.60M
    DeclRefExprBits.HasFoundDecl = 0;
1028
1.60M
    DeclRefExprBits.HadMultipleCandidates = 0;
1029
1.60M
    DeclRefExprBits.RefersToEnclosingVariableOrCapture =
1030
1.60M
        RefersToEnclosingVariableOrCapture;
1031
1.60M
    computeDependence(D->getASTContext());
1032
1.60M
  }
1033
1034
  static DeclRefExpr *
1035
  Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1036
         SourceLocation TemplateKWLoc, ValueDecl *D,
1037
         bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc,
1038
         QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr,
1039
         const TemplateArgumentListInfo *TemplateArgs = nullptr);
1040
1041
  static DeclRefExpr *
1042
  Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1043
         SourceLocation TemplateKWLoc, ValueDecl *D,
1044
         bool RefersToEnclosingVariableOrCapture,
1045
         const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK,
1046
         NamedDecl *FoundD = nullptr,
1047
         const TemplateArgumentListInfo *TemplateArgs = nullptr);
1048
1049
  /// Construct an empty declaration reference expression.
1050
  static DeclRefExpr *CreateEmpty(const ASTContext &Context,
1051
                                  bool HasQualifier,
1052
                                  bool HasFoundDecl,
1053
                                  bool HasTemplateKWAndArgsInfo,
1054
                                  unsigned NumTemplateArgs);
1055
1056
118M
  ValueDecl *getDecl() { return D; }
1057
160M
  const ValueDecl *getDecl() const { return D; }
1058
130k
  void setDecl(ValueDecl *NewD) { D = NewD; }
1059
1060
112M
  DeclarationNameInfo getNameInfo() const {
1061
112M
    return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc);
1062
112M
  }
1063
1064
20.8M
  SourceLocation getLocation() const { return Loc; }
1065
130k
  void setLocation(SourceLocation L) { Loc = L; }
1066
  SourceLocation getBeginLoc() const LLVM_READONLY;
1067
  SourceLocation getEndLoc() const LLVM_READONLY;
1068
1069
  /// Determine whether this declaration reference was preceded by a
1070
  /// C++ nested-name-specifier, e.g., \c N::foo.
1071
126M
  bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
1072
1073
  /// If the name was qualified, retrieves the nested-name-specifier
1074
  /// that precedes the name, with source-location information.
1075
12.4M
  NestedNameSpecifierLoc getQualifierLoc() const {
1076
12.4M
    if (!hasQualifier())
1077
3.43M
      return NestedNameSpecifierLoc();
1078
8.99M
    return *getTrailingObjects<NestedNameSpecifierLoc>();
1079
8.99M
  }
1080
1081
  /// If the name was qualified, retrieves the nested-name-specifier
1082
  /// that precedes the name. Otherwise, returns NULL.
1083
566k
  NestedNameSpecifier *getQualifier() const {
1084
566k
    return getQualifierLoc().getNestedNameSpecifier();
1085
566k
  }
1086
1087
  /// Get the NamedDecl through which this reference occurred.
1088
  ///
1089
  /// This Decl may be different from the ValueDecl actually referred to in the
1090
  /// presence of using declarations, etc. It always returns non-NULL, and may
1091
  /// simple return the ValueDecl when appropriate.
1092
1093
684k
  NamedDecl *getFoundDecl() {
1094
684k
    return hasFoundDecl() ? 
*getTrailingObjects<NamedDecl *>()2.79k
:
D682k
;
1095
684k
  }
1096
1097
  /// Get the NamedDecl through which this reference occurred.
1098
  /// See non-const variant.
1099
1.58k
  const NamedDecl *getFoundDecl() const {
1100
1.58k
    return hasFoundDecl() ? 
*getTrailingObjects<NamedDecl *>()166
:
D1.41k
;
1101
1.58k
  }
1102
1103
12.5M
  bool hasTemplateKWAndArgsInfo() const {
1104
12.5M
    return DeclRefExprBits.HasTemplateKWAndArgsInfo;
1105
12.5M
  }
1106
1107
  /// Retrieve the location of the template keyword preceding
1108
  /// this name, if any.
1109
123k
  SourceLocation getTemplateKeywordLoc() const {
1110
123k
    if (!hasTemplateKWAndArgsInfo()) 
return SourceLocation()118k
;
1111
4.92k
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
1112
4.92k
  }
1113
1114
  /// Retrieve the location of the left angle bracket starting the
1115
  /// explicit template argument list following the name, if any.
1116
10.8M
  SourceLocation getLAngleLoc() const {
1117
10.8M
    if (!hasTemplateKWAndArgsInfo()) 
return SourceLocation()10.5M
;
1118
228k
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
1119
228k
  }
1120
1121
  /// Retrieve the location of the right angle bracket ending the
1122
  /// explicit template argument list following the name, if any.
1123
264k
  SourceLocation getRAngleLoc() const {
1124
264k
    if (!hasTemplateKWAndArgsInfo()) 
return SourceLocation()63.4k
;
1125
200k
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
1126
200k
  }
1127
1128
  /// Determines whether the name in this declaration reference
1129
  /// was preceded by the template keyword.
1130
122k
  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
1131
1132
  /// Determines whether this declaration reference was followed by an
1133
  /// explicit template argument list.
1134
10.7M
  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
1135
1136
  /// Copies the template arguments (if present) into the given
1137
  /// structure.
1138
0
  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1139
0
    if (hasExplicitTemplateArgs())
1140
0
      getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
1141
0
          getTrailingObjects<TemplateArgumentLoc>(), List);
1142
0
  }
1143
1144
  /// Retrieve the template arguments provided as part of this
1145
  /// template-id.
1146
160k
  const TemplateArgumentLoc *getTemplateArgs() const {
1147
160k
    if (!hasExplicitTemplateArgs())
1148
151k
      return nullptr;
1149
8.20k
1150
8.20k
    return getTrailingObjects<TemplateArgumentLoc>();
1151
8.20k
  }
1152
1153
  /// Retrieve the number of template arguments provided as part of this
1154
  /// template-id.
1155
160k
  unsigned getNumTemplateArgs() const {
1156
160k
    if (!hasExplicitTemplateArgs())
1157
151k
      return 0;
1158
8.95k
1159
8.95k
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
1160
8.95k
  }
1161
1162
4.92k
  ArrayRef<TemplateArgumentLoc> template_arguments() const {
1163
4.92k
    return {getTemplateArgs(), getNumTemplateArgs()};
1164
4.92k
  }
1165
1166
  /// Returns true if this expression refers to a function that
1167
  /// was resolved from an overloaded set having size greater than 1.
1168
221k
  bool hadMultipleCandidates() const {
1169
221k
    return DeclRefExprBits.HadMultipleCandidates;
1170
221k
  }
1171
  /// Sets the flag telling whether this expression refers to
1172
  /// a function that was resolved from an overloaded set having size
1173
  /// greater than 1.
1174
955k
  void setHadMultipleCandidates(bool V = true) {
1175
955k
    DeclRefExprBits.HadMultipleCandidates = V;
1176
955k
  }
1177
1178
  /// Does this DeclRefExpr refer to an enclosing local or a captured
1179
  /// variable?
1180
4.44M
  bool refersToEnclosingVariableOrCapture() const {
1181
4.44M
    return DeclRefExprBits.RefersToEnclosingVariableOrCapture;
1182
4.44M
  }
1183
1184
60.3M
  static bool classof(const Stmt *T) {
1185
60.3M
    return T->getStmtClass() == DeclRefExprClass;
1186
60.3M
  }
1187
1188
  // Iterators
1189
20.7M
  child_range children() {
1190
20.7M
    return child_range(child_iterator(), child_iterator());
1191
20.7M
  }
1192
1193
0
  const_child_range children() const {
1194
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1195
0
  }
1196
1197
  friend TrailingObjects;
1198
  friend class ASTStmtReader;
1199
  friend class ASTStmtWriter;
1200
};
1201
1202
/// [C99 6.4.2.2] - A predefined identifier such as __func__.
1203
class PredefinedExpr : public Expr {
1204
public:
1205
  enum IdentType {
1206
    Func,
1207
    Function,
1208
    LFunction, // Same as Function, but as wide string.
1209
    FuncDName,
1210
    FuncSig,
1211
    LFuncSig, // Same as FuncSig, but as as wide string
1212
    PrettyFunction,
1213
    /// The same as PrettyFunction, except that the
1214
    /// 'virtual' keyword is omitted for virtual member functions.
1215
    PrettyFunctionNoVirtual
1216
  };
1217
1218
private:
1219
  SourceLocation Loc;
1220
  IdentType Type;
1221
  Stmt *FnName;
1222
1223
public:
1224
  PredefinedExpr(SourceLocation L, QualType FNTy, IdentType IT,
1225
                 StringLiteral *SL);
1226
1227
  /// Construct an empty predefined expression.
1228
  explicit PredefinedExpr(EmptyShell Empty)
1229
16
      : Expr(PredefinedExprClass, Empty), Loc(), Type(Func), FnName(nullptr) {}
1230
1231
2.27k
  IdentType getIdentType() const { return Type; }
1232
1233
90
  SourceLocation getLocation() const { return Loc; }
1234
16
  void setLocation(SourceLocation L) { Loc = L; }
1235
1236
  StringLiteral *getFunctionName();
1237
2.13k
  const StringLiteral *getFunctionName() const {
1238
2.13k
    return const_cast<PredefinedExpr *>(this)->getFunctionName();
1239
2.13k
  }
1240
1241
  static StringRef getIdentTypeName(IdentType IT);
1242
  static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
1243
1244
25.2k
  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1245
127
  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1246
1247
104k
  static bool classof(const Stmt *T) {
1248
104k
    return T->getStmtClass() == PredefinedExprClass;
1249
104k
  }
1250
1251
  // Iterators
1252
9.97k
  child_range children() { return child_range(&FnName, &FnName + 1); }
1253
0
  const_child_range children() const {
1254
0
    return const_child_range(&FnName, &FnName + 1);
1255
0
  }
1256
1257
  friend class ASTStmtReader;
1258
};
1259
1260
/// Used by IntegerLiteral/FloatingLiteral to store the numeric without
1261
/// leaking memory.
1262
///
1263
/// For large floats/integers, APFloat/APInt will allocate memory from the heap
1264
/// to represent these numbers.  Unfortunately, when we use a BumpPtrAllocator
1265
/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
1266
/// the APFloat/APInt values will never get freed. APNumericStorage uses
1267
/// ASTContext's allocator for memory allocation.
1268
class APNumericStorage {
1269
  union {
1270
    uint64_t VAL;    ///< Used to store the <= 64 bits integer value.
1271
    uint64_t *pVal;  ///< Used to store the >64 bits integer value.
1272
  };
1273
  unsigned BitWidth;
1274
1275
6.63M
  bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
1276
1277
  APNumericStorage(const APNumericStorage &) = delete;
1278
  void operator=(const APNumericStorage &) = delete;
1279
1280
protected:
1281
6.63M
  APNumericStorage() : VAL(0), BitWidth(0) { }
1282
1283
12.9M
  llvm::APInt getIntValue() const {
1284
12.9M
    unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
1285
12.9M
    if (NumWords > 1)
1286
954
      return llvm::APInt(BitWidth, NumWords, pVal);
1287
12.9M
    else
1288
12.9M
      return llvm::APInt(BitWidth, VAL);
1289
12.9M
  }
1290
  void setIntValue(const ASTContext &C, const llvm::APInt &Val);
1291
};
1292
1293
class APIntStorage : private APNumericStorage {
1294
public:
1295
12.6M
  llvm::APInt getValue() const { return getIntValue(); }
1296
6.40M
  void setValue(const ASTContext &C, const llvm::APInt &Val) {
1297
6.40M
    setIntValue(C, Val);
1298
6.40M
  }
1299
};
1300
1301
class APFloatStorage : private APNumericStorage {
1302
public:
1303
297k
  llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const {
1304
297k
    return llvm::APFloat(Semantics, getIntValue());
1305
297k
  }
1306
235k
  void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1307
235k
    setIntValue(C, Val.bitcastToAPInt());
1308
235k
  }
1309
};
1310
1311
class IntegerLiteral : public Expr, public APIntStorage {
1312
  SourceLocation Loc;
1313
1314
  /// Construct an empty integer literal.
1315
  explicit IntegerLiteral(EmptyShell Empty)
1316
69.1k
    : Expr(IntegerLiteralClass, Empty) { }
1317
1318
public:
1319
  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
1320
  // or UnsignedLongLongTy
1321
  IntegerLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1322
                 SourceLocation l);
1323
1324
  /// Returns a new integer literal with value 'V' and type 'type'.
1325
  /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
1326
  /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
1327
  /// \param V - the value that the returned integer literal contains.
1328
  static IntegerLiteral *Create(const ASTContext &C, const llvm::APInt &V,
1329
                                QualType type, SourceLocation l);
1330
  /// Returns a new empty integer literal.
1331
  static IntegerLiteral *Create(const ASTContext &C, EmptyShell Empty);
1332
1333
23.5M
  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1334
752k
  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1335
1336
  /// Retrieve the location of the literal.
1337
87.1k
  SourceLocation getLocation() const { return Loc; }
1338
1339
69.1k
  void setLocation(SourceLocation Location) { Loc = Location; }
1340
1341
13.8M
  static bool classof(const Stmt *T) {
1342
13.8M
    return T->getStmtClass() == IntegerLiteralClass;
1343
13.8M
  }
1344
1345
  // Iterators
1346
13.5M
  child_range children() {
1347
13.5M
    return child_range(child_iterator(), child_iterator());
1348
13.5M
  }
1349
0
  const_child_range children() const {
1350
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1351
0
  }
1352
};
1353
1354
class FixedPointLiteral : public Expr, public APIntStorage {
1355
  SourceLocation Loc;
1356
  unsigned Scale;
1357
1358
  /// \brief Construct an empty integer literal.
1359
  explicit FixedPointLiteral(EmptyShell Empty)
1360
      : Expr(FixedPointLiteralClass, Empty) {}
1361
1362
 public:
1363
  FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1364
                    SourceLocation l, unsigned Scale);
1365
1366
  // Store the int as is without any bit shifting.
1367
  static FixedPointLiteral *CreateFromRawInt(const ASTContext &C,
1368
                                             const llvm::APInt &V,
1369
                                             QualType type, SourceLocation l,
1370
                                             unsigned Scale);
1371
1372
710
  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1373
107
  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1374
1375
  /// \brief Retrieve the location of the literal.
1376
0
  SourceLocation getLocation() const { return Loc; }
1377
1378
0
  void setLocation(SourceLocation Location) { Loc = Location; }
1379
1380
0
  static bool classof(const Stmt *T) {
1381
0
    return T->getStmtClass() == FixedPointLiteralClass;
1382
0
  }
1383
1384
  std::string getValueAsString(unsigned Radix) const;
1385
1386
  // Iterators
1387
527
  child_range children() {
1388
527
    return child_range(child_iterator(), child_iterator());
1389
527
  }
1390
0
  const_child_range children() const {
1391
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1392
0
  }
1393
};
1394
1395
class CharacterLiteral : public Expr {
1396
public:
1397
  enum CharacterKind {
1398
    Ascii,
1399
    Wide,
1400
    UTF8,
1401
    UTF16,
1402
    UTF32
1403
  };
1404
1405
private:
1406
  unsigned Value;
1407
  SourceLocation Loc;
1408
public:
1409
  // type should be IntTy
1410
  CharacterLiteral(unsigned value, CharacterKind kind, QualType type,
1411
                   SourceLocation l)
1412
    : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
1413
           false, false),
1414
79.0k
      Value(value), Loc(l) {
1415
79.0k
    CharacterLiteralBits.Kind = kind;
1416
79.0k
  }
1417
1418
  /// Construct an empty character literal.
1419
207
  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
1420
1421
221
  SourceLocation getLocation() const { return Loc; }
1422
542
  CharacterKind getKind() const {
1423
542
    return static_cast<CharacterKind>(CharacterLiteralBits.Kind);
1424
542
  }
1425
1426
444k
  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1427
15.7k
  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1428
1429
206k
  unsigned getValue() const { return Value; }
1430
1431
207
  void setLocation(SourceLocation Location) { Loc = Location; }
1432
207
  void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; }
1433
207
  void setValue(unsigned Val) { Value = Val; }
1434
1435
1.43M
  static bool classof(const Stmt *T) {
1436
1.43M
    return T->getStmtClass() == CharacterLiteralClass;
1437
1.43M
  }
1438
1439
  // Iterators
1440
205k
  child_range children() {
1441
205k
    return child_range(child_iterator(), child_iterator());
1442
205k
  }
1443
0
  const_child_range children() const {
1444
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1445
0
  }
1446
};
1447
1448
class FloatingLiteral : public Expr, private APFloatStorage {
1449
  SourceLocation Loc;
1450
1451
  FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact,
1452
                  QualType Type, SourceLocation L);
1453
1454
  /// Construct an empty floating-point literal.
1455
  explicit FloatingLiteral(const ASTContext &C, EmptyShell Empty);
1456
1457
public:
1458
  static FloatingLiteral *Create(const ASTContext &C, const llvm::APFloat &V,
1459
                                 bool isexact, QualType Type, SourceLocation L);
1460
  static FloatingLiteral *Create(const ASTContext &C, EmptyShell Empty);
1461
1462
297k
  llvm::APFloat getValue() const {
1463
297k
    return APFloatStorage::getValue(getSemantics());
1464
297k
  }
1465
235k
  void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1466
235k
    assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics");
1467
235k
    APFloatStorage::setValue(C, Val);
1468
235k
  }
1469
1470
  /// Get a raw enumeration value representing the floating-point semantics of
1471
  /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1472
1.03k
  APFloatSemantics getRawSemantics() const {
1473
1.03k
    return static_cast<APFloatSemantics>(FloatingLiteralBits.Semantics);
1474
1.03k
  }
1475
1476
  /// Set the raw enumeration value representing the floating-point semantics of
1477
  /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1478
1.86k
  void setRawSemantics(APFloatSemantics Sem) {
1479
1.86k
    FloatingLiteralBits.Semantics = Sem;
1480
1.86k
  }
1481
1482
  /// Return the APFloat semantics this literal uses.
1483
  const llvm::fltSemantics &getSemantics() const;
1484
1485
  /// Set the APFloat semantics this literal uses.
1486
  void setSemantics(const llvm::fltSemantics &Sem);
1487
1488
1.90k
  bool isExact() const { return FloatingLiteralBits.IsExact; }
1489
933
  void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
1490
1491
  /// getValueAsApproximateDouble - This returns the value as an inaccurate
1492
  /// double.  Note that this may cause loss of precision, but is useful for
1493
  /// debugging dumps, etc.
1494
  double getValueAsApproximateDouble() const;
1495
1496
1.08k
  SourceLocation getLocation() const { return Loc; }
1497
933
  void setLocation(SourceLocation L) { Loc = L; }
1498
1499
1.00M
  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1500
37.2k
  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1501
1502
145k
  static bool classof(const Stmt *T) {
1503
145k
    return T->getStmtClass() == FloatingLiteralClass;
1504
145k
  }
1505
1506
  // Iterators
1507
671k
  child_range children() {
1508
671k
    return child_range(child_iterator(), child_iterator());
1509
671k
  }
1510
0
  const_child_range children() const {
1511
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1512
0
  }
1513
};
1514
1515
/// ImaginaryLiteral - We support imaginary integer and floating point literals,
1516
/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
1517
/// IntegerLiteral classes.  Instances of this class always have a Complex type
1518
/// whose element type matches the subexpression.
1519
///
1520
class ImaginaryLiteral : public Expr {
1521
  Stmt *Val;
1522
public:
1523
  ImaginaryLiteral(Expr *val, QualType Ty)
1524
    : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false,
1525
           false, false),
1526
362
      Val(val) {}
1527
1528
  /// Build an empty imaginary literal.
1529
  explicit ImaginaryLiteral(EmptyShell Empty)
1530
1
    : Expr(ImaginaryLiteralClass, Empty) { }
1531
1532
463
  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1533
9
  Expr *getSubExpr() { return cast<Expr>(Val); }
1534
1
  void setSubExpr(Expr *E) { Val = E; }
1535
1536
949
  SourceLocation getBeginLoc() const LLVM_READONLY {
1537
949
    return Val->getBeginLoc();
1538
949
  }
1539
105
  SourceLocation getEndLoc() const LLVM_READONLY { return Val->getEndLoc(); }
1540
1541
  static bool classof(const Stmt *T) {
1542
    return T->getStmtClass() == ImaginaryLiteralClass;
1543
  }
1544
1545
  // Iterators
1546
895
  child_range children() { return child_range(&Val, &Val+1); }
1547
0
  const_child_range children() const {
1548
0
    return const_child_range(&Val, &Val + 1);
1549
0
  }
1550
};
1551
1552
/// StringLiteral - This represents a string literal expression, e.g. "foo"
1553
/// or L"bar" (wide strings).  The actual string is returned by getBytes()
1554
/// is NOT null-terminated, and the length of the string is determined by
1555
/// calling getByteLength().  The C type for a string is always a
1556
/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
1557
/// not.
1558
///
1559
/// Note that strings in C can be formed by concatenation of multiple string
1560
/// literal pptokens in translation phase #6.  This keeps track of the locations
1561
/// of each of these pieces.
1562
///
1563
/// Strings in C can also be truncated and extended by assigning into arrays,
1564
/// e.g. with constructs like:
1565
///   char X[2] = "foobar";
1566
/// In this case, getByteLength() will return 6, but the string literal will
1567
/// have type "char[2]".
1568
class StringLiteral : public Expr {
1569
public:
1570
  enum StringKind {
1571
    Ascii,
1572
    Wide,
1573
    UTF8,
1574
    UTF16,
1575
    UTF32
1576
  };
1577
1578
private:
1579
  friend class ASTStmtReader;
1580
1581
  union {
1582
    const char *asChar;
1583
    const uint16_t *asUInt16;
1584
    const uint32_t *asUInt32;
1585
  } StrData;
1586
  unsigned Length;
1587
  unsigned CharByteWidth : 4;
1588
  unsigned Kind : 3;
1589
  unsigned IsPascal : 1;
1590
  unsigned NumConcatenated;
1591
  SourceLocation TokLocs[1];
1592
1593
  StringLiteral(QualType Ty) :
1594
    Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false,
1595
2.60M
         false) {}
1596
1597
  static int mapCharByteWidth(TargetInfo const &target,StringKind k);
1598
1599
public:
1600
  /// This is the "fully general" constructor that allows representation of
1601
  /// strings formed from multiple concatenated tokens.
1602
  static StringLiteral *Create(const ASTContext &C, StringRef Str,
1603
                               StringKind Kind, bool Pascal, QualType Ty,
1604
                               const SourceLocation *Loc, unsigned NumStrs);
1605
1606
  /// Simple constructor for string literals made from one token.
1607
  static StringLiteral *Create(const ASTContext &C, StringRef Str,
1608
                               StringKind Kind, bool Pascal, QualType Ty,
1609
2.68k
                               SourceLocation Loc) {
1610
2.68k
    return Create(C, Str, Kind, Pascal, Ty, &Loc, 1);
1611
2.68k
  }
1612
1613
  /// Construct an empty string literal.
1614
  static StringLiteral *CreateEmpty(const ASTContext &C, unsigned NumStrs);
1615
1616
2.57M
  StringRef getString() const {
1617
2.57M
    assert(CharByteWidth==1
1618
2.57M
           && "This function is used in places that assume strings use char");
1619
2.57M
    return StringRef(StrData.asChar, getByteLength());
1620
2.57M
  }
1621
1622
  /// Allow access to clients that need the byte representation, such as
1623
  /// ASTWriterStmt::VisitStringLiteral().
1624
1.45k
  StringRef getBytes() const {
1625
1.45k
    // FIXME: StringRef may not be the right type to use as a result for this.
1626
1.45k
    if (CharByteWidth == 1)
1627
1.40k
      return StringRef(StrData.asChar, getByteLength());
1628
47
    if (CharByteWidth == 4)
1629
31
      return StringRef(reinterpret_cast<const char*>(StrData.asUInt32),
1630
31
                       getByteLength());
1631
16
    assert(CharByteWidth == 2 && "unsupported CharByteWidth");
1632
16
    return StringRef(reinterpret_cast<const char*>(StrData.asUInt16),
1633
16
                     getByteLength());
1634
16
  }
1635
1636
  void outputString(raw_ostream &OS) const;
1637
1638
19.8k
  uint32_t getCodeUnit(size_t i) const {
1639
19.8k
    assert(i < Length && "out of bounds access");
1640
19.8k
    if (CharByteWidth == 1)
1641
13.1k
      return static_cast<unsigned char>(StrData.asChar[i]);
1642
6.63k
    if (CharByteWidth == 4)
1643
4.21k
      return StrData.asUInt32[i];
1644
2.42k
    assert(CharByteWidth == 2 && "unsupported CharByteWidth");
1645
2.42k
    return StrData.asUInt16[i];
1646
2.42k
  }
1647
1648
2.58M
  unsigned getByteLength() const { return CharByteWidth*Length; }
1649
56.1k
  unsigned getLength() const { return Length; }
1650
213k
  unsigned getCharByteWidth() const { return CharByteWidth; }
1651
1652
  /// Sets the string data to the given string data.
1653
  void setString(const ASTContext &C, StringRef Str,
1654
                 StringKind Kind, bool IsPascal);
1655
1656
16.0k
  StringKind getKind() const { return static_cast<StringKind>(Kind); }
1657
1658
1659
2.14M
  bool isAscii() const { return Kind == Ascii; }
1660
4.67k
  bool isWide() const { return Kind == Wide; }
1661
6
  bool isUTF8() const { return Kind == UTF8; }
1662
0
  bool isUTF16() const { return Kind == UTF16; }
1663
0
  bool isUTF32() const { return Kind == UTF32; }
1664
805
  bool isPascal() const { return IsPascal; }
1665
1666
3
  bool containsNonAscii() const {
1667
3
    StringRef Str = getString();
1668
28
    for (unsigned i = 0, e = Str.size(); i != e; 
++i25
)
1669
25
      if (!isASCII(Str[i]))
1670
0
        return true;
1671
3
    return false;
1672
3
  }
1673
1674
1.75k
  bool containsNonAsciiOrNull() const {
1675
1.75k
    StringRef Str = getString();
1676
12.4k
    for (unsigned i = 0, e = Str.size(); i != e; 
++i10.6k
)
1677
10.7k
      if (!isASCII(Str[i]) || 
!Str[i]10.7k
)
1678
53
        return true;
1679
1.75k
    
return false1.70k
;
1680
1.75k
  }
1681
1682
  /// getNumConcatenated - Get the number of string literal tokens that were
1683
  /// concatenated in translation phase #6 to form this string literal.
1684
2.65k
  unsigned getNumConcatenated() const { return NumConcatenated; }
1685
1686
228k
  SourceLocation getStrTokenLoc(unsigned TokNum) const {
1687
228k
    assert(TokNum < NumConcatenated && "Invalid tok number");
1688
228k
    return TokLocs[TokNum];
1689
228k
  }
1690
203
  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
1691
203
    assert(TokNum < NumConcatenated && "Invalid tok number");
1692
203
    TokLocs[TokNum] = L;
1693
203
  }
1694
1695
  /// getLocationOfByte - Return a source location that points to the specified
1696
  /// byte of this string literal.
1697
  ///
1698
  /// Strings are amazingly complex.  They can be formed from multiple tokens
1699
  /// and can have escape sequences in them in addition to the usual trigraph
1700
  /// and escaped newline business.  This routine handles this complexity.
1701
  ///
1702
  SourceLocation
1703
  getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
1704
                    const LangOptions &Features, const TargetInfo &Target,
1705
                    unsigned *StartToken = nullptr,
1706
                    unsigned *StartTokenByteOffset = nullptr) const;
1707
1708
  typedef const SourceLocation *tokloc_iterator;
1709
65
  tokloc_iterator tokloc_begin() const { return TokLocs; }
1710
65
  tokloc_iterator tokloc_end() const { return TokLocs + NumConcatenated; }
1711
1712
6.31M
  SourceLocation getBeginLoc() const LLVM_READONLY { return TokLocs[0]; }
1713
18.0k
  SourceLocation getEndLoc() const LLVM_READONLY {
1714
18.0k
    return TokLocs[NumConcatenated - 1];
1715
18.0k
  }
1716
1717
6.21M
  static bool classof(const Stmt *T) {
1718
6.21M
    return T->getStmtClass() == StringLiteralClass;
1719
6.21M
  }
1720
1721
  // Iterators
1722
1.29M
  child_range children() {
1723
1.29M
    return child_range(child_iterator(), child_iterator());
1724
1.29M
  }
1725
0
  const_child_range children() const {
1726
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1727
0
  }
1728
};
1729
1730
/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
1731
/// AST node is only formed if full location information is requested.
1732
class ParenExpr : public Expr {
1733
  SourceLocation L, R;
1734
  Stmt *Val;
1735
public:
1736
  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
1737
    : Expr(ParenExprClass, val->getType(),
1738
           val->getValueKind(), val->getObjectKind(),
1739
           val->isTypeDependent(), val->isValueDependent(),
1740
           val->isInstantiationDependent(),
1741
           val->containsUnexpandedParameterPack()),
1742
2.48M
      L(l), R(r), Val(val) {}
1743
1744
  /// Construct an empty parenthesized expression.
1745
  explicit ParenExpr(EmptyShell Empty)
1746
11.8k
    : Expr(ParenExprClass, Empty) { }
1747
1748
2.20M
  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1749
13.7M
  Expr *getSubExpr() { return cast<Expr>(Val); }
1750
11.8k
  void setSubExpr(Expr *E) { Val = E; }
1751
1752
5.84M
  SourceLocation getBeginLoc() const LLVM_READONLY { return L; }
1753
1.26M
  SourceLocation getEndLoc() const LLVM_READONLY { return R; }
1754
1755
  /// Get the location of the left parentheses '('.
1756
280k
  SourceLocation getLParen() const { return L; }
1757
11.8k
  void setLParen(SourceLocation Loc) { L = Loc; }
1758
1759
  /// Get the location of the right parentheses ')'.
1760
280k
  SourceLocation getRParen() const { return R; }
1761
11.8k
  void setRParen(SourceLocation Loc) { R = Loc; }
1762
1763
386M
  static bool classof(const Stmt *T) {
1764
386M
    return T->getStmtClass() == ParenExprClass;
1765
386M
  }
1766
1767
  // Iterators
1768
2.92M
  child_range children() { return child_range(&Val, &Val+1); }
1769
0
  const_child_range children() const {
1770
0
    return const_child_range(&Val, &Val + 1);
1771
0
  }
1772
};
1773
1774
/// UnaryOperator - This represents the unary-expression's (except sizeof and
1775
/// alignof), the postinc/postdec operators from postfix-expression, and various
1776
/// extensions.
1777
///
1778
/// Notes on various nodes:
1779
///
1780
/// Real/Imag - These return the real/imag part of a complex operand.  If
1781
///   applied to a non-complex value, the former returns its operand and the
1782
///   later returns zero in the type of the operand.
1783
///
1784
class UnaryOperator : public Expr {
1785
public:
1786
  typedef UnaryOperatorKind Opcode;
1787
1788
private:
1789
  unsigned Opc : 5;
1790
  unsigned CanOverflow : 1;
1791
  SourceLocation Loc;
1792
  Stmt *Val;
1793
public:
1794
  UnaryOperator(Expr *input, Opcode opc, QualType type, ExprValueKind VK,
1795
                ExprObjectKind OK, SourceLocation l, bool CanOverflow)
1796
      : Expr(UnaryOperatorClass, type, VK, OK,
1797
             input->isTypeDependent() || type->isDependentType(),
1798
             input->isValueDependent(),
1799
             (input->isInstantiationDependent() ||
1800
              type->isInstantiationDependentType()),
1801
             input->containsUnexpandedParameterPack()),
1802
2.58M
        Opc(opc), CanOverflow(CanOverflow), Loc(l), Val(input) {}
1803
1804
  /// Build an empty unary operator.
1805
  explicit UnaryOperator(EmptyShell Empty)
1806
9.89k
    : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { }
1807
1808
28.6M
  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
1809
9.89k
  void setOpcode(Opcode O) { Opc = O; }
1810
1811
7.23M
  Expr *getSubExpr() const { return cast<Expr>(Val); }
1812
9.89k
  void setSubExpr(Expr *E) { Val = E; }
1813
1814
  /// getOperatorLoc - Return the location of the operator.
1815
410k
  SourceLocation getOperatorLoc() const { return Loc; }
1816
9.89k
  void setOperatorLoc(SourceLocation L) { Loc = L; }
1817
1818
  /// Returns true if the unary operator can cause an overflow. For instance,
1819
  ///   signed int i = INT_MAX; i++;
1820
  ///   signed char c = CHAR_MAX; c++;
1821
  /// Due to integer promotions, c++ is promoted to an int before the postfix
1822
  /// increment, and the result is an int that cannot overflow. However, i++
1823
  /// can overflow.
1824
76.9k
  bool canOverflow() const { return CanOverflow; }
1825
9.89k
  void setCanOverflow(bool C) { CanOverflow = C; }
1826
1827
  /// isPostfix - Return true if this is a postfix operation, like x++.
1828
5.35M
  static bool isPostfix(Opcode Op) {
1829
5.35M
    return Op == UO_PostInc || 
Op == UO_PostDec5.14M
;
1830
5.35M
  }
1831
1832
  /// isPrefix - Return true if this is a prefix operation, like --x.
1833
326k
  static bool isPrefix(Opcode Op) {
1834
326k
    return Op == UO_PreInc || 
Op == UO_PreDec325k
;
1835
326k
  }
1836
1837
326k
  bool isPrefix() const { return isPrefix(getOpcode()); }
1838
5.35M
  bool isPostfix() const { return isPostfix(getOpcode()); }
1839
1840
58.1k
  static bool isIncrementOp(Opcode Op) {
1841
58.1k
    return Op == UO_PreInc || 
Op == UO_PostInc21.2k
;
1842
58.1k
  }
1843
58.1k
  bool isIncrementOp() const {
1844
58.1k
    return isIncrementOp(getOpcode());
1845
58.1k
  }
1846
1847
72.5k
  static bool isDecrementOp(Opcode Op) {
1848
72.5k
    return Op == UO_PreDec || 
Op == UO_PostDec72.4k
;
1849
72.5k
  }
1850
72.5k
  bool isDecrementOp() const {
1851
72.5k
    return isDecrementOp(getOpcode());
1852
72.5k
  }
1853
1854
633k
  static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; }
1855
633k
  bool isIncrementDecrementOp() const {
1856
633k
    return isIncrementDecrementOp(getOpcode());
1857
633k
  }
1858
1859
  static bool isArithmeticOp(Opcode Op) {
1860
    return Op >= UO_Plus && Op <= UO_LNot;
1861
  }
1862
  bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
1863
1864
  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1865
  /// corresponds to, e.g. "sizeof" or "[pre]++"
1866
  static StringRef getOpcodeStr(Opcode Op);
1867
1868
  /// Retrieve the unary opcode that corresponds to the given
1869
  /// overloaded operator.
1870
  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
1871
1872
  /// Retrieve the overloaded operator kind that corresponds to
1873
  /// the given unary opcode.
1874
  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1875
1876
4.85M
  SourceLocation getBeginLoc() const LLVM_READONLY {
1877
4.85M
    return isPostfix() ? 
Val->getBeginLoc()185k
:
Loc4.67M
;
1878
4.85M
  }
1879
429k
  SourceLocation getEndLoc() const LLVM_READONLY {
1880
429k
    return isPostfix() ? 
Loc32.4k
:
Val->getEndLoc()397k
;
1881
429k
  }
1882
3.69M
  SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
1883
1884
563M
  static bool classof(const Stmt *T) {
1885
563M
    return T->getStmtClass() == UnaryOperatorClass;
1886
563M
  }
1887
1888
  // Iterators
1889
3.76M
  child_range children() { return child_range(&Val, &Val+1); }
1890
0
  const_child_range children() const {
1891
0
    return const_child_range(&Val, &Val + 1);
1892
0
  }
1893
};
1894
1895
/// Helper class for OffsetOfExpr.
1896
1897
// __builtin_offsetof(type, identifier(.identifier|[expr])*)
1898
0
class OffsetOfNode {
1899
public:
1900
  /// The kind of offsetof node we have.
1901
  enum Kind {
1902
    /// An index into an array.
1903
    Array = 0x00,
1904
    /// A field.
1905
    Field = 0x01,
1906
    /// A field in a dependent type, known only by its name.
1907
    Identifier = 0x02,
1908
    /// An implicit indirection through a C++ base class, when the
1909
    /// field found is in a base class.
1910
    Base = 0x03
1911
  };
1912
1913
private:
1914
  enum { MaskBits = 2, Mask = 0x03 };
1915
1916
  /// The source range that covers this part of the designator.
1917
  SourceRange Range;
1918
1919
  /// The data describing the designator, which comes in three
1920
  /// different forms, depending on the lower two bits.
1921
  ///   - An unsigned index into the array of Expr*'s stored after this node
1922
  ///     in memory, for [constant-expression] designators.
1923
  ///   - A FieldDecl*, for references to a known field.
1924
  ///   - An IdentifierInfo*, for references to a field with a given name
1925
  ///     when the class type is dependent.
1926
  ///   - A CXXBaseSpecifier*, for references that look at a field in a
1927
  ///     base class.
1928
  uintptr_t Data;
1929
1930
public:
1931
  /// Create an offsetof node that refers to an array element.
1932
  OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
1933
               SourceLocation RBracketLoc)
1934
43
      : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) {}
1935
1936
  /// Create an offsetof node that refers to a field.
1937
  OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, SourceLocation NameLoc)
1938
      : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
1939
4.28k
        Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) {}
1940
1941
  /// Create an offsetof node that refers to an identifier.
1942
  OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
1943
               SourceLocation NameLoc)
1944
      : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
1945
17
        Data(reinterpret_cast<uintptr_t>(Name) | Identifier) {}
1946
1947
  /// Create an offsetof node that refers into a C++ base class.
1948
  explicit OffsetOfNode(const CXXBaseSpecifier *Base)
1949
18
      : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
1950
1951
  /// Determine what kind of offsetof node this is.
1952
5.23k
  Kind getKind() const { return static_cast<Kind>(Data & Mask); }
1953
1954
  /// For an array element node, returns the index into the array
1955
  /// of expressions.
1956
45
  unsigned getArrayExprIndex() const {
1957
45
    assert(getKind() == Array);
1958
45
    return Data >> 2;
1959
45
  }
1960
1961
  /// For a field offsetof node, returns the field.
1962
5.07k
  FieldDecl *getField() const {
1963
5.07k
    assert(getKind() == Field);
1964
5.07k
    return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
1965
5.07k
  }
1966
1967
  /// For a field or identifier offsetof node, returns the name of
1968
  /// the field.
1969
  IdentifierInfo *getFieldName() const;
1970
1971
  /// For a base class node, returns the base specifier.
1972
35
  CXXBaseSpecifier *getBase() const {
1973
35
    assert(getKind() == Base);
1974
35
    return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
1975
35
  }
1976
1977
  /// Retrieve the source range that covers this offsetof node.
1978
  ///
1979
  /// For an array element node, the source range contains the locations of
1980
  /// the square brackets. For a field or identifier node, the source range
1981
  /// contains the location of the period (if there is one) and the
1982
  /// identifier.
1983
40
  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
1984
3
  SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
1985
33
  SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
1986
};
1987
1988
/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
1989
/// offsetof(record-type, member-designator). For example, given:
1990
/// @code
1991
/// struct S {
1992
///   float f;
1993
///   double d;
1994
/// };
1995
/// struct T {
1996
///   int i;
1997
///   struct S s[10];
1998
/// };
1999
/// @endcode
2000
/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
2001
2002
class OffsetOfExpr final
2003
    : public Expr,
2004
      private llvm::TrailingObjects<OffsetOfExpr, OffsetOfNode, Expr *> {
2005
  SourceLocation OperatorLoc, RParenLoc;
2006
  // Base type;
2007
  TypeSourceInfo *TSInfo;
2008
  // Number of sub-components (i.e. instances of OffsetOfNode).
2009
  unsigned NumComps;
2010
  // Number of sub-expressions (i.e. array subscript expressions).
2011
  unsigned NumExprs;
2012
2013
614
  size_t numTrailingObjects(OverloadToken<OffsetOfNode>) const {
2014
614
    return NumComps;
2015
614
  }
2016
2017
  OffsetOfExpr(const ASTContext &C, QualType type,
2018
               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2019
               ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs,
2020
               SourceLocation RParenLoc);
2021
2022
  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
2023
    : Expr(OffsetOfExprClass, EmptyShell()),
2024
3
      TSInfo(nullptr), NumComps(numComps), NumExprs(numExprs) {}
2025
2026
public:
2027
2028
  static OffsetOfExpr *Create(const ASTContext &C, QualType type,
2029
                              SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2030
                              ArrayRef<OffsetOfNode> comps,
2031
                              ArrayRef<Expr*> exprs, SourceLocation RParenLoc);
2032
2033
  static OffsetOfExpr *CreateEmpty(const ASTContext &C,
2034
                                   unsigned NumComps, unsigned NumExprs);
2035
2036
  /// getOperatorLoc - Return the location of the operator.
2037
8
  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2038
3
  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2039
2040
  /// Return the location of the right parentheses.
2041
8
  SourceLocation getRParenLoc() const { return RParenLoc; }
2042
3
  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
2043
2044
5.12k
  TypeSourceInfo *getTypeSourceInfo() const {
2045
5.12k
    return TSInfo;
2046
5.12k
  }
2047
3
  void setTypeSourceInfo(TypeSourceInfo *tsi) {
2048
3
    TSInfo = tsi;
2049
3
  }
2050
2051
5.19k
  const OffsetOfNode &getComponent(unsigned Idx) const {
2052
5.19k
    assert(Idx < NumComps && "Subscript out of range");
2053
5.19k
    return getTrailingObjects<OffsetOfNode>()[Idx];
2054
5.19k
  }
2055
2056
4.35k
  void setComponent(unsigned Idx, OffsetOfNode ON) {
2057
4.35k
    assert(Idx < NumComps && "Subscript out of range");
2058
4.35k
    getTrailingObjects<OffsetOfNode>()[Idx] = ON;
2059
4.35k
  }
2060
2061
5.05k
  unsigned getNumComponents() const {
2062
5.05k
    return NumComps;
2063
5.05k
  }
2064
2065
6
  Expr* getIndexExpr(unsigned Idx) {
2066
6
    assert(Idx < NumExprs && "Subscript out of range");
2067
6
    return getTrailingObjects<Expr *>()[Idx];
2068
6
  }
2069
2070
39
  const Expr *getIndexExpr(unsigned Idx) const {
2071
39
    assert(Idx < NumExprs && "Subscript out of range");
2072
39
    return getTrailingObjects<Expr *>()[Idx];
2073
39
  }
2074
2075
41
  void setIndexExpr(unsigned Idx, Expr* E) {
2076
41
    assert(Idx < NumComps && "Subscript out of range");
2077
41
    getTrailingObjects<Expr *>()[Idx] = E;
2078
41
  }
2079
2080
11
  unsigned getNumExpressions() const {
2081
11
    return NumExprs;
2082
11
  }
2083
2084
3.90k
  SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; }
2085
70
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2086
2087
110
  static bool classof(const Stmt *T) {
2088
110
    return T->getStmtClass() == OffsetOfExprClass;
2089
110
  }
2090
2091
  // Iterators
2092
528
  child_range children() {
2093
528
    Stmt **begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
2094
528
    return child_range(begin, begin + NumExprs);
2095
528
  }
2096
0
  const_child_range children() const {
2097
0
    Stmt *const *begin =
2098
0
        reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
2099
0
    return const_child_range(begin, begin + NumExprs);
2100
0
  }
2101
  friend TrailingObjects;
2102
};
2103
2104
/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
2105
/// expression operand.  Used for sizeof/alignof (C99 6.5.3.4) and
2106
/// vec_step (OpenCL 1.1 6.11.12).
2107
class UnaryExprOrTypeTraitExpr : public Expr {
2108
  union {
2109
    TypeSourceInfo *Ty;
2110
    Stmt *Ex;
2111
  } Argument;
2112
  SourceLocation OpLoc, RParenLoc;
2113
2114
public:
2115
  UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo,
2116
                           QualType resultType, SourceLocation op,
2117
                           SourceLocation rp) :
2118
      Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2119
           false, // Never type-dependent (C++ [temp.dep.expr]p3).
2120
           // Value-dependent if the argument is type-dependent.
2121
           TInfo->getType()->isDependentType(),
2122
           TInfo->getType()->isInstantiationDependentType(),
2123
           TInfo->getType()->containsUnexpandedParameterPack()),
2124
148k
      OpLoc(op), RParenLoc(rp) {
2125
148k
    UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
2126
148k
    UnaryExprOrTypeTraitExprBits.IsType = true;
2127
148k
    Argument.Ty = TInfo;
2128
148k
  }
2129
2130
  UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E,
2131
                           QualType resultType, SourceLocation op,
2132
                           SourceLocation rp);
2133
2134
  /// Construct an empty sizeof/alignof expression.
2135
  explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty)
2136
32
    : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
2137
2138
509k
  UnaryExprOrTypeTrait getKind() const {
2139
509k
    return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
2140
509k
  }
2141
32
  void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;}
2142
2143
709k
  bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
2144
463k
  QualType getArgumentType() const {
2145
463k
    return getArgumentTypeInfo()->getType();
2146
463k
  }
2147
528k
  TypeSourceInfo *getArgumentTypeInfo() const {
2148
528k
    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
2149
528k
    return Argument.Ty;
2150
528k
  }
2151
172k
  Expr *getArgumentExpr() {
2152
172k
    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
2153
172k
    return static_cast<Expr*>(Argument.Ex);
2154
172k
  }
2155
105k
  const Expr *getArgumentExpr() const {
2156
105k
    return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
2157
105k
  }
2158
2159
18
  void setArgument(Expr *E) {
2160
18
    Argument.Ex = E;
2161
18
    UnaryExprOrTypeTraitExprBits.IsType = false;
2162
18
  }
2163
14
  void setArgument(TypeSourceInfo *TInfo) {
2164
14
    Argument.Ty = TInfo;
2165
14
    UnaryExprOrTypeTraitExprBits.IsType = true;
2166
14
  }
2167
2168
  /// Gets the argument type, or the type of the argument expression, whichever
2169
  /// is appropriate.
2170
361k
  QualType getTypeOfArgument() const {
2171
361k
    return isArgumentType() ? 
getArgumentType()258k
:
getArgumentExpr()->getType()103k
;
2172
361k
  }
2173
2174
65.8k
  SourceLocation getOperatorLoc() const { return OpLoc; }
2175
32
  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2176
2177
50
  SourceLocation getRParenLoc() const { return RParenLoc; }
2178
32
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2179
2180
820k
  SourceLocation getBeginLoc() const LLVM_READONLY { return OpLoc; }
2181
52.9k
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2182
2183
29.4M
  static bool classof(const Stmt *T) {
2184
29.4M
    return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
2185
29.4M
  }
2186
2187
  // Iterators
2188
  child_range children();
2189
  const_child_range children() const;
2190
};
2191
2192
//===----------------------------------------------------------------------===//
2193
// Postfix Operators.
2194
//===----------------------------------------------------------------------===//
2195
2196
/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
2197
class ArraySubscriptExpr : public Expr {
2198
  enum { LHS, RHS, END_EXPR=2 };
2199
  Stmt* SubExprs[END_EXPR];
2200
  SourceLocation RBracketLoc;
2201
public:
2202
  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
2203
                     ExprValueKind VK, ExprObjectKind OK,
2204
                     SourceLocation rbracketloc)
2205
  : Expr(ArraySubscriptExprClass, t, VK, OK,
2206
         lhs->isTypeDependent() || rhs->isTypeDependent(),
2207
         lhs->isValueDependent() || rhs->isValueDependent(),
2208
         (lhs->isInstantiationDependent() ||
2209
          rhs->isInstantiationDependent()),
2210
         (lhs->containsUnexpandedParameterPack() ||
2211
          rhs->containsUnexpandedParameterPack())),
2212
694k
    RBracketLoc(rbracketloc) {
2213
694k
    SubExprs[LHS] = lhs;
2214
694k
    SubExprs[RHS] = rhs;
2215
694k
  }
2216
2217
  /// Create an empty array subscript expression.
2218
  explicit ArraySubscriptExpr(EmptyShell Shell)
2219
5.14k
    : Expr(ArraySubscriptExprClass, Shell) { }
2220
2221
  /// An array access can be written A[4] or 4[A] (both are equivalent).
2222
  /// - getBase() and getIdx() always present the normalized view: A[4].
2223
  ///    In this case getBase() returns "A" and getIdx() returns "4".
2224
  /// - getLHS() and getRHS() present the syntactic view. e.g. for
2225
  ///    4[A] getLHS() returns "4".
2226
  /// Note: Because vector element access is also written A[4] we must
2227
  /// predicate the format conversion in getBase and getIdx only on the
2228
  /// the type of the RHS, as it is possible for the LHS to be a vector of
2229
  /// integer type
2230
406k
  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
2231
8.57M
  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2232
5.14k
  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2233
2234
251k
  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
2235
9.24M
  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2236
5.14k
  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2237
2238
161k
  Expr *getBase() {
2239
161k
    return getRHS()->getType()->isIntegerType() ? 
getLHS()161k
:
getRHS()35
;
2240
161k
  }
2241
2242
5.87M
  const Expr *getBase() const {
2243
5.87M
    return getRHS()->getType()->isIntegerType() ? 
getLHS()5.86M
:
getRHS()6.18k
;
2244
5.87M
  }
2245
2246
1.62k
  Expr *getIdx() {
2247
1.62k
    return getRHS()->getType()->isIntegerType() ? getRHS() : 
getLHS()0
;
2248
1.62k
  }
2249
2250
1.68M
  const Expr *getIdx() const {
2251
1.68M
    return getRHS()->getType()->isIntegerType() ? 
getRHS()1.68M
:
getLHS()130
;
2252
1.68M
  }
2253
2254
2.26M
  SourceLocation getBeginLoc() const LLVM_READONLY {
2255
2.26M
    return getLHS()->getBeginLoc();
2256
2.26M
  }
2257
146k
  SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; }
2258
2259
95.1k
  SourceLocation getRBracketLoc() const { return RBracketLoc; }
2260
5.14k
  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
2261
2262
1.66M
  SourceLocation getExprLoc() const LLVM_READONLY {
2263
1.66M
    return getBase()->getExprLoc();
2264
1.66M
  }
2265
2266
3.19M
  static bool classof(const Stmt *T) {
2267
3.19M
    return T->getStmtClass() == ArraySubscriptExprClass;
2268
3.19M
  }
2269
2270
  // Iterators
2271
1.45M
  child_range children() {
2272
1.45M
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2273
1.45M
  }
2274
0
  const_child_range children() const {
2275
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2276
0
  }
2277
};
2278
2279
/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
2280
/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
2281
/// while its subclasses may represent alternative syntax that (semantically)
2282
/// results in a function call. For example, CXXOperatorCallExpr is
2283
/// a subclass for overloaded operator calls that use operator syntax, e.g.,
2284
/// "str1 + str2" to resolve to a function call.
2285
class CallExpr : public Expr {
2286
  enum { FN=0, PREARGS_START=1 };
2287
  Stmt **SubExprs;
2288
  unsigned NumArgs;
2289
  SourceLocation RParenLoc;
2290
2291
  void updateDependenciesFromArg(Expr *Arg);
2292
2293
protected:
2294
  // These versions of the constructor are for derived classes.
2295
  CallExpr(const ASTContext &C, StmtClass SC, Expr *fn,
2296
           ArrayRef<Expr *> preargs, ArrayRef<Expr *> args, QualType t,
2297
           ExprValueKind VK, SourceLocation rparenloc);
2298
  CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, ArrayRef<Expr *> args,
2299
           QualType t, ExprValueKind VK, SourceLocation rparenloc);
2300
  CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs,
2301
           EmptyShell Empty);
2302
2303
4
  Stmt *getPreArg(unsigned i) {
2304
4
    assert(i < getNumPreArgs() && "Prearg access out of range!");
2305
4
    return SubExprs[PREARGS_START+i];
2306
4
  }
2307
8
  const Stmt *getPreArg(unsigned i) const {
2308
8
    assert(i < getNumPreArgs() && "Prearg access out of range!");
2309
8
    return SubExprs[PREARGS_START+i];
2310
8
  }
2311
0
  void setPreArg(unsigned i, Stmt *PreArg) {
2312
0
    assert(i < getNumPreArgs() && "Prearg access out of range!");
2313
0
    SubExprs[PREARGS_START+i] = PreArg;
2314
0
  }
2315
2316
43.9M
  unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
2317
2318
public:
2319
  CallExpr(const ASTContext& C, Expr *fn, ArrayRef<Expr*> args, QualType t,
2320
           ExprValueKind VK, SourceLocation rparenloc);
2321
2322
  /// Build an empty call expression.
2323
  CallExpr(const ASTContext &C, StmtClass SC, EmptyShell Empty);
2324
2325
33.5M
  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
2326
16.9M
  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
2327
14.2k
  void setCallee(Expr *F) { SubExprs[FN] = F; }
2328
2329
  Decl *getCalleeDecl();
2330
1.86M
  const Decl *getCalleeDecl() const {
2331
1.86M
    return const_cast<CallExpr*>(this)->getCalleeDecl();
2332
1.86M
  }
2333
2334
  /// If the callee is a FunctionDecl, return it. Otherwise return 0.
2335
  FunctionDecl *getDirectCallee();
2336
2.58M
  const FunctionDecl *getDirectCallee() const {
2337
2.58M
    return const_cast<CallExpr*>(this)->getDirectCallee();
2338
2.58M
  }
2339
2340
  /// getNumArgs - Return the number of actual arguments to this call.
2341
  ///
2342
25.3M
  unsigned getNumArgs() const { return NumArgs; }
2343
2344
  /// Retrieve the call arguments.
2345
6.37M
  Expr **getArgs() {
2346
6.37M
    return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START);
2347
6.37M
  }
2348
922k
  const Expr *const *getArgs() const {
2349
922k
    return reinterpret_cast<Expr **>(SubExprs + getNumPreArgs() +
2350
922k
                                     PREARGS_START);
2351
922k
  }
2352
2353
  /// getArg - Return the specified argument.
2354
10.7M
  Expr *getArg(unsigned Arg) {
2355
10.7M
    assert(Arg < NumArgs && "Arg access out of range!");
2356
10.7M
    return cast_or_null<Expr>(SubExprs[Arg + getNumPreArgs() + PREARGS_START]);
2357
10.7M
  }
2358
2.52M
  const Expr *getArg(unsigned Arg) const {
2359
2.52M
    assert(Arg < NumArgs && "Arg access out of range!");
2360
2.52M
    return cast_or_null<Expr>(SubExprs[Arg + getNumPreArgs() + PREARGS_START]);
2361
2.52M
  }
2362
2363
  /// setArg - Set the specified argument.
2364
7.33M
  void setArg(unsigned Arg, Expr *ArgExpr) {
2365
7.33M
    assert(Arg < NumArgs && "Arg access out of range!");
2366
7.33M
    SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr;
2367
7.33M
  }
2368
2369
  /// setNumArgs - This changes the number of arguments present in this call.
2370
  /// Any orphaned expressions are deleted by this, and any new operands are set
2371
  /// to null.
2372
  void setNumArgs(const ASTContext& C, unsigned NumArgs);
2373
2374
  typedef ExprIterator arg_iterator;
2375
  typedef ConstExprIterator const_arg_iterator;
2376
  typedef llvm::iterator_range<arg_iterator> arg_range;
2377
  typedef llvm::iterator_range<const_arg_iterator> const_arg_range;
2378
2379
11.5k
  arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
2380
845k
  const_arg_range arguments() const {
2381
845k
    return const_arg_range(arg_begin(), arg_end());
2382
845k
  }
2383
2384
2.84M
  arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); }
2385
2.84M
  arg_iterator arg_end() {
2386
2.84M
    return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2387
2.84M
  }
2388
851k
  const_arg_iterator arg_begin() const {
2389
851k
    return SubExprs+PREARGS_START+getNumPreArgs();
2390
851k
  }
2391
846k
  const_arg_iterator arg_end() const {
2392
846k
    return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2393
846k
  }
2394
2395
  /// This method provides fast access to all the subexpressions of
2396
  /// a CallExpr without going through the slower virtual child_iterator
2397
  /// interface.  This provides efficient reverse iteration of the
2398
  /// subexpressions.  This is currently used for CFG construction.
2399
718k
  ArrayRef<Stmt*> getRawSubExprs() {
2400
718k
    return llvm::makeArrayRef(SubExprs,
2401
718k
                              getNumPreArgs() + PREARGS_START + getNumArgs());
2402
718k
  }
2403
2404
  /// getNumCommas - Return the number of commas that must have been present in
2405
  /// this function call.
2406
0
  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
2407
2408
  /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID
2409
  /// of the callee. If not, return 0.
2410
  unsigned getBuiltinCallee() const;
2411
2412
  /// Returns \c true if this is a call to a builtin which does not
2413
  /// evaluate side-effects within its arguments.
2414
  bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const;
2415
2416
  /// getCallReturnType - Get the return type of the call expr. This is not
2417
  /// always the type of the expr itself, if the return type is a reference
2418
  /// type.
2419
  QualType getCallReturnType(const ASTContext &Ctx) const;
2420
2421
6.83M
  SourceLocation getRParenLoc() const { return RParenLoc; }
2422
4.54k
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2423
2424
  SourceLocation getBeginLoc() const LLVM_READONLY;
2425
  SourceLocation getEndLoc() const LLVM_READONLY;
2426
2427
  /// Return true if this is a call to __assume() or __builtin_assume() with
2428
  /// a non-value-dependent constant parameter evaluating as false.
2429
  bool isBuiltinAssumeFalse(const ASTContext &Ctx) const;
2430
2431
533k
  bool isCallToStdMove() const {
2432
533k
    const FunctionDecl* FD = getDirectCallee();
2433
533k
    return getNumArgs() == 1 && 
FD137k
&&
FD->isInStdNamespace()124k
&&
2434
533k
           
FD->getIdentifier()1.87k
&&
FD->getIdentifier()->isStr("move")1.84k
;
2435
533k
  }
2436
2437
68.6M
  static bool classof(const Stmt *T) {
2438
68.6M
    return T->getStmtClass() >= firstCallExprConstant &&
2439
68.6M
           
T->getStmtClass() <= lastCallExprConstant57.2M
;
2440
68.6M
  }
2441
2442
  // Iterators
2443
7.98M
  child_range children() {
2444
7.98M
    return child_range(&SubExprs[0],
2445
7.98M
                       &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START);
2446
7.98M
  }
2447
2448
0
  const_child_range children() const {
2449
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + NumArgs +
2450
0
                                               getNumPreArgs() + PREARGS_START);
2451
0
  }
2452
};
2453
2454
/// Extra data stored in some MemberExpr objects.
2455
struct MemberExprNameQualifier {
2456
  /// The nested-name-specifier that qualifies the name, including
2457
  /// source-location information.
2458
  NestedNameSpecifierLoc QualifierLoc;
2459
2460
  /// The DeclAccessPair through which the MemberDecl was found due to
2461
  /// name qualifiers.
2462
  DeclAccessPair FoundDecl;
2463
};
2464
2465
/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
2466
///
2467
class MemberExpr final
2468
    : public Expr,
2469
      private llvm::TrailingObjects<MemberExpr, MemberExprNameQualifier,
2470
                                    ASTTemplateKWAndArgsInfo,
2471
                                    TemplateArgumentLoc> {
2472
  /// Base - the expression for the base pointer or structure references.  In
2473
  /// X.F, this is "X".
2474
  Stmt *Base;
2475
2476
  /// MemberDecl - This is the decl being referenced by the field/member name.
2477
  /// In X.F, this is the decl referenced by F.
2478
  ValueDecl *MemberDecl;
2479
2480
  /// MemberDNLoc - Provides source/type location info for the
2481
  /// declaration name embedded in MemberDecl.
2482
  DeclarationNameLoc MemberDNLoc;
2483
2484
  /// MemberLoc - This is the location of the member name.
2485
  SourceLocation MemberLoc;
2486
2487
  /// This is the location of the -> or . in the expression.
2488
  SourceLocation OperatorLoc;
2489
2490
  /// IsArrow - True if this is "X->F", false if this is "X.F".
2491
  bool IsArrow : 1;
2492
2493
  /// True if this member expression used a nested-name-specifier to
2494
  /// refer to the member, e.g., "x->Base::f", or found its member via a using
2495
  /// declaration.  When true, a MemberExprNameQualifier
2496
  /// structure is allocated immediately after the MemberExpr.
2497
  bool HasQualifierOrFoundDecl : 1;
2498
2499
  /// True if this member expression specified a template keyword
2500
  /// and/or a template argument list explicitly, e.g., x->f<int>,
2501
  /// x->template f, x->template f<int>.
2502
  /// When true, an ASTTemplateKWAndArgsInfo structure and its
2503
  /// TemplateArguments (if any) are present.
2504
  bool HasTemplateKWAndArgsInfo : 1;
2505
2506
  /// True if this member expression refers to a method that
2507
  /// was resolved from an overloaded set having size greater than 1.
2508
  bool HadMultipleCandidates : 1;
2509
2510
7.44k
  size_t numTrailingObjects(OverloadToken<MemberExprNameQualifier>) const {
2511
7.44k
    return HasQualifierOrFoundDecl ? 1 : 
00
;
2512
7.44k
  }
2513
2514
1.81k
  size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2515
1.81k
    return HasTemplateKWAndArgsInfo ? 1 : 
00
;
2516
1.81k
  }
2517
2518
public:
2519
  MemberExpr(Expr *base, bool isarrow, SourceLocation operatorloc,
2520
             ValueDecl *memberdecl, const DeclarationNameInfo &NameInfo,
2521
             QualType ty, ExprValueKind VK, ExprObjectKind OK)
2522
      : Expr(MemberExprClass, ty, VK, OK, base->isTypeDependent(),
2523
             base->isValueDependent(), base->isInstantiationDependent(),
2524
             base->containsUnexpandedParameterPack()),
2525
        Base(base), MemberDecl(memberdecl), MemberDNLoc(NameInfo.getInfo()),
2526
        MemberLoc(NameInfo.getLoc()), OperatorLoc(operatorloc),
2527
        IsArrow(isarrow), HasQualifierOrFoundDecl(false),
2528
2.81M
        HasTemplateKWAndArgsInfo(false), HadMultipleCandidates(false) {
2529
2.81M
    assert(memberdecl->getDeclName() == NameInfo.getName());
2530
2.81M
  }
2531
2532
  // NOTE: this constructor should be used only when it is known that
2533
  // the member name can not provide additional syntactic info
2534
  // (i.e., source locations for C++ operator names or type source info
2535
  // for constructors, destructors and conversion operators).
2536
  MemberExpr(Expr *base, bool isarrow, SourceLocation operatorloc,
2537
             ValueDecl *memberdecl, SourceLocation l, QualType ty,
2538
             ExprValueKind VK, ExprObjectKind OK)
2539
      : Expr(MemberExprClass, ty, VK, OK, base->isTypeDependent(),
2540
             base->isValueDependent(), base->isInstantiationDependent(),
2541
             base->containsUnexpandedParameterPack()),
2542
        Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l),
2543
        OperatorLoc(operatorloc), IsArrow(isarrow),
2544
        HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false),
2545
29.4k
        HadMultipleCandidates(false) {}
2546
2547
  static MemberExpr *Create(const ASTContext &C, Expr *base, bool isarrow,
2548
                            SourceLocation OperatorLoc,
2549
                            NestedNameSpecifierLoc QualifierLoc,
2550
                            SourceLocation TemplateKWLoc, ValueDecl *memberdecl,
2551
                            DeclAccessPair founddecl,
2552
                            DeclarationNameInfo MemberNameInfo,
2553
                            const TemplateArgumentListInfo *targs, QualType ty,
2554
                            ExprValueKind VK, ExprObjectKind OK);
2555
2556
513k
  void setBase(Expr *E) { Base = E; }
2557
41.9M
  Expr *getBase() const { return cast<Expr>(Base); }
2558
2559
  /// Retrieve the member declaration to which this expression refers.
2560
  ///
2561
  /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
2562
  /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
2563
20.6M
  ValueDecl *getMemberDecl() const { return MemberDecl; }
2564
  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
2565
2566
  /// Retrieves the declaration found by lookup.
2567
651k
  DeclAccessPair getFoundDecl() const {
2568
651k
    if (!HasQualifierOrFoundDecl)
2569
638k
      return DeclAccessPair::make(getMemberDecl(),
2570
638k
                                  getMemberDecl()->getAccess());
2571
13.1k
    return getTrailingObjects<MemberExprNameQualifier>()->FoundDecl;
2572
13.1k
  }
2573
2574
  /// Determines whether this member expression actually had
2575
  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2576
  /// x->Base::foo.
2577
8.58M
  bool hasQualifier() const { return getQualifier() != nullptr; }
2578
2579
  /// If the member name was qualified, retrieves the
2580
  /// nested-name-specifier that precedes the member name, with source-location
2581
  /// information.
2582
9.05M
  NestedNameSpecifierLoc getQualifierLoc() const {
2583
9.05M
    if (!HasQualifierOrFoundDecl)
2584
8.77M
      return NestedNameSpecifierLoc();
2585
283k
2586
283k
    return getTrailingObjects<MemberExprNameQualifier>()->QualifierLoc;
2587
283k
  }
2588
2589
  /// If the member name was qualified, retrieves the
2590
  /// nested-name-specifier that precedes the member name. Otherwise, returns
2591
  /// NULL.
2592
8.97M
  NestedNameSpecifier *getQualifier() const {
2593
8.97M
    return getQualifierLoc().getNestedNameSpecifier();
2594
8.97M
  }
2595
2596
  /// Retrieve the location of the template keyword preceding
2597
  /// the member name, if any.
2598
269k
  SourceLocation getTemplateKeywordLoc() const {
2599
269k
    if (!HasTemplateKWAndArgsInfo) 
return SourceLocation()269k
;
2600
31
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
2601
31
  }
2602
2603
  /// Retrieve the location of the left angle bracket starting the
2604
  /// explicit template argument list following the member name, if any.
2605
1.68M
  SourceLocation getLAngleLoc() const {
2606
1.68M
    if (!HasTemplateKWAndArgsInfo) 
return SourceLocation()1.68M
;
2607
1.96k
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
2608
1.96k
  }
2609
2610
  /// Retrieve the location of the right angle bracket ending the
2611
  /// explicit template argument list following the member name, if any.
2612
1.77k
  SourceLocation getRAngleLoc() const {
2613
1.77k
    if (!HasTemplateKWAndArgsInfo) 
return SourceLocation()0
;
2614
1.77k
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
2615
1.77k
  }
2616
2617
  /// Determines whether the member name was preceded by the template keyword.
2618
4.23k
  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2619
2620
  /// Determines whether the member name was followed by an
2621
  /// explicit template argument list.
2622
1.68M
  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2623
2624
  /// Copies the template arguments (if present) into the given
2625
  /// structure.
2626
  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2627
    if (hasExplicitTemplateArgs())
2628
      getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
2629
          getTrailingObjects<TemplateArgumentLoc>(), List);
2630
  }
2631
2632
  /// Retrieve the template arguments provided as part of this
2633
  /// template-id.
2634
17.6k
  const TemplateArgumentLoc *getTemplateArgs() const {
2635
17.6k
    if (!hasExplicitTemplateArgs())
2636
17.6k
      return nullptr;
2637
57
2638
57
    return getTrailingObjects<TemplateArgumentLoc>();
2639
57
  }
2640
2641
  /// Retrieve the number of template arguments provided as part of this
2642
  /// template-id.
2643
17.6k
  unsigned getNumTemplateArgs() const {
2644
17.6k
    if (!hasExplicitTemplateArgs())
2645
17.6k
      return 0;
2646
57
2647
57
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
2648
57
  }
2649
2650
9
  ArrayRef<TemplateArgumentLoc> template_arguments() const {
2651
9
    return {getTemplateArgs(), getNumTemplateArgs()};
2652
9
  }
2653
2654
  /// Retrieve the member declaration name info.
2655
1.40M
  DeclarationNameInfo getMemberNameInfo() const {
2656
1.40M
    return DeclarationNameInfo(MemberDecl->getDeclName(),
2657
1.40M
                               MemberLoc, MemberDNLoc);
2658
1.40M
  }
2659
2660
6.38k
  SourceLocation getOperatorLoc() const LLVM_READONLY { return OperatorLoc; }
2661
2662
4.41M
  bool isArrow() const { return IsArrow; }
2663
  void setArrow(bool A) { IsArrow = A; }
2664
2665
  /// getMemberLoc - Return the location of the "member", in X->F, it is the
2666
  /// location of 'F'.
2667
6.44M
  SourceLocation getMemberLoc() const { return MemberLoc; }
2668
  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
2669
2670
  SourceLocation getBeginLoc() const LLVM_READONLY;
2671
  SourceLocation getEndLoc() const LLVM_READONLY;
2672
2673
6.57M
  SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; }
2674
2675
  /// Determine whether the base of this explicit is implicit.
2676
11.6M
  bool isImplicitAccess() const {
2677
11.6M
    return getBase() && getBase()->isImplicitCXXThis();
2678
11.6M
  }
2679
2680
  /// Returns true if this member expression refers to a method that
2681
  /// was resolved from an overloaded set having size greater than 1.
2682
6.32k
  bool hadMultipleCandidates() const {
2683
6.32k
    return HadMultipleCandidates;
2684
6.32k
  }
2685
  /// Sets the flag telling whether this expression refers to
2686
  /// a method that was resolved from an overloaded set having size
2687
  /// greater than 1.
2688
160k
  void setHadMultipleCandidates(bool V = true) {
2689
160k
    HadMultipleCandidates = V;
2690
160k
  }
2691
2692
  /// Returns true if virtual dispatch is performed.
2693
  /// If the member access is fully qualified, (i.e. X::f()), virtual
2694
  /// dispatching is not performed. In -fapple-kext mode qualified
2695
  /// calls to virtual method will still go through the vtable.
2696
2.87M
  bool performsVirtualDispatch(const LangOptions &LO) const {
2697
2.87M
    return LO.AppleKext || 
!hasQualifier()2.87M
;
2698
2.87M
  }
2699
2700
47.5M
  static bool classof(const Stmt *T) {
2701
47.5M
    return T->getStmtClass() == MemberExprClass;
2702
47.5M
  }
2703
2704
  // Iterators
2705
2.68M
  child_range children() { return child_range(&Base, &Base+1); }
2706
0
  const_child_range children() const {
2707
0
    return const_child_range(&Base, &Base + 1);
2708
0
  }
2709
2710
  friend TrailingObjects;
2711
  friend class ASTReader;
2712
  friend class ASTStmtWriter;
2713
};
2714
2715
/// CompoundLiteralExpr - [C99 6.5.2.5]
2716
///
2717
class CompoundLiteralExpr : public Expr {
2718
  /// LParenLoc - If non-null, this is the location of the left paren in a
2719
  /// compound literal like "(int){4}".  This can be null if this is a
2720
  /// synthesized compound expression.
2721
  SourceLocation LParenLoc;
2722
2723
  /// The type as written.  This can be an incomplete array type, in
2724
  /// which case the actual expression type will be different.
2725
  /// The int part of the pair stores whether this expr is file scope.
2726
  llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope;
2727
  Stmt *Init;
2728
public:
2729
  CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
2730
                      QualType T, ExprValueKind VK, Expr *init, bool fileScope)
2731
    : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary,
2732
           tinfo->getType()->isDependentType(),
2733
           init->isValueDependent(),
2734
           (init->isInstantiationDependent() ||
2735
            tinfo->getType()->isInstantiationDependentType()),
2736
           init->containsUnexpandedParameterPack()),
2737
29.1k
      LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {}
2738
2739
  /// Construct an empty compound literal.
2740
  explicit CompoundLiteralExpr(EmptyShell Empty)
2741
4
    : Expr(CompoundLiteralExprClass, Empty) { }
2742
2743
3.82k
  const Expr *getInitializer() const { return cast<Expr>(Init); }
2744
670
  Expr *getInitializer() { return cast<Expr>(Init); }
2745
4
  void setInitializer(Expr *E) { Init = E; }
2746
2747
3.51k
  bool isFileScope() const { return TInfoAndScope.getInt(); }
2748
4
  void setFileScope(bool FS) { TInfoAndScope.setInt(FS); }
2749
2750
553
  SourceLocation getLParenLoc() const { return LParenLoc; }
2751
4
  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2752
2753
679
  TypeSourceInfo *getTypeSourceInfo() const {
2754
679
    return TInfoAndScope.getPointer();
2755
679
  }
2756
4
  void setTypeSourceInfo(TypeSourceInfo *tinfo) {
2757
4
    TInfoAndScope.setPointer(tinfo);
2758
4
  }
2759
2760
82.5k
  SourceLocation getBeginLoc() const LLVM_READONLY {
2761
82.5k
    // FIXME: Init should never be null.
2762
82.5k
    if (!Init)
2763
0
      return SourceLocation();
2764
82.5k
    if (LParenLoc.isInvalid())
2765
99
      return Init->getBeginLoc();
2766
82.4k
    return LParenLoc;
2767
82.4k
  }
2768
7.34k
  SourceLocation getEndLoc() const LLVM_READONLY {
2769
7.34k
    // FIXME: Init should never be null.
2770
7.34k
    if (!Init)
2771
0
      return SourceLocation();
2772
7.34k
    return Init->getEndLoc();
2773
7.34k
  }
2774
2775
6.23k
  static bool classof(const Stmt *T) {
2776
6.23k
    return T->getStmtClass() == CompoundLiteralExprClass;
2777
6.23k
  }
2778
2779
  // Iterators
2780
61.1k
  child_range children() { return child_range(&Init, &Init+1); }
2781
0
  const_child_range children() const {
2782
0
    return const_child_range(&Init, &Init + 1);
2783
0
  }
2784
};
2785
2786
/// CastExpr - Base class for type casts, including both implicit
2787
/// casts (ImplicitCastExpr) and explicit casts that have some
2788
/// representation in the source code (ExplicitCastExpr's derived
2789
/// classes).
2790
class CastExpr : public Expr {
2791
public:
2792
  using BasePathSizeTy = unsigned int;
2793
  static_assert(std::numeric_limits<BasePathSizeTy>::max() >= 16384,
2794
                "[implimits] Direct and indirect base classes [16384].");
2795
2796
private:
2797
  Stmt *Op;
2798
2799
  bool CastConsistency() const;
2800
2801
  BasePathSizeTy *BasePathSize();
2802
2803
178k
  const CXXBaseSpecifier * const *path_buffer() const {
2804
178k
    return const_cast<CastExpr*>(this)->path_buffer();
2805
178k
  }
2806
  CXXBaseSpecifier **path_buffer();
2807
2808
182k
  void setBasePathSize(BasePathSizeTy basePathSize) {
2809
182k
    assert(!path_empty() && basePathSize != 0);
2810
182k
    *(BasePathSize()) = basePathSize;
2811
182k
  }
2812
2813
protected:
2814
  CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, const CastKind kind,
2815
           Expr *op, unsigned BasePathSize)
2816
      : Expr(SC, ty, VK, OK_Ordinary,
2817
             // Cast expressions are type-dependent if the type is
2818
             // dependent (C++ [temp.dep.expr]p3).
2819
             ty->isDependentType(),
2820
             // Cast expressions are value-dependent if the type is
2821
             // dependent or if the subexpression is value-dependent.
2822
             ty->isDependentType() || (op && op->isValueDependent()),
2823
             (ty->isInstantiationDependentType() ||
2824
              (op && op->isInstantiationDependent())),
2825
             // An implicit cast expression doesn't (lexically) contain an
2826
             // unexpanded pack, even if its target type does.
2827
             ((SC != ImplicitCastExprClass &&
2828
               ty->containsUnexpandedParameterPack()) ||
2829
              (op && op->containsUnexpandedParameterPack()))),
2830
22.8M
        Op(op) {
2831
22.8M
    CastExprBits.Kind = kind;
2832
22.8M
    CastExprBits.PartOfExplicitCast = false;
2833
22.8M
    CastExprBits.BasePathIsEmpty = BasePathSize == 0;
2834
22.8M
    if (!path_empty())
2835
182k
      setBasePathSize(BasePathSize);
2836
22.8M
    assert(CastConsistency());
2837
22.8M
  }
2838
2839
  /// Construct an empty cast.
2840
  CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
2841
99.4k
    : Expr(SC, Empty) {
2842
99.4k
    CastExprBits.PartOfExplicitCast = false;
2843
99.4k
    CastExprBits.BasePathIsEmpty = BasePathSize == 0;
2844
99.4k
    if (!path_empty())
2845
579
      setBasePathSize(BasePathSize);
2846
99.4k
  }
2847
2848
public:
2849
85.8M
  CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
2850
99.4k
  void setCastKind(CastKind K) { CastExprBits.Kind = K; }
2851
2852
  static const char *getCastKindName(CastKind CK);
2853
2.59k
  const char *getCastKindName() const { return getCastKindName(getCastKind()); }
2854
2855
92.4M
  Expr *getSubExpr() { return cast<Expr>(Op); }
2856
100M
  const Expr *getSubExpr() const { return cast<Expr>(Op); }
2857
100k
  void setSubExpr(Expr *E) { Op = E; }
2858
2859
  /// Retrieve the cast subexpression as it was written in the source
2860
  /// code, looking through any implicit casts or other intermediate nodes
2861
  /// introduced by semantic analysis.
2862
  Expr *getSubExprAsWritten();
2863
287k
  const Expr *getSubExprAsWritten() const {
2864
287k
    return const_cast<CastExpr *>(this)->getSubExprAsWritten();
2865
287k
  }
2866
2867
  /// If this cast applies a user-defined conversion, retrieve the conversion
2868
  /// function that it invokes.
2869
  NamedDecl *getConversionFunction() const;
2870
2871
  typedef CXXBaseSpecifier **path_iterator;
2872
  typedef const CXXBaseSpecifier * const *path_const_iterator;
2873
24.6M
  bool path_empty() const { return CastExprBits.BasePathIsEmpty; }
2874
773k
  unsigned path_size() const {
2875
773k
    if (path_empty())
2876
680k
      return 0U;
2877
93.0k
    return *(const_cast<CastExpr *>(this)->BasePathSize());
2878
93.0k
  }
2879
348k
  path_iterator path_begin() { return path_buffer(); }
2880
249k
  path_iterator path_end() { return path_buffer() + path_size(); }
2881
89.1k
  path_const_iterator path_begin() const { return path_buffer(); }
2882
89.1k
  path_const_iterator path_end() const { return path_buffer() + path_size(); }
2883
2884
4
  const FieldDecl *getTargetUnionField() const {
2885
4
    assert(getCastKind() == CK_ToUnion);
2886
4
    return getTargetFieldForToUnionCast(getType(), getSubExpr()->getType());
2887
4
  }
2888
2889
  static const FieldDecl *getTargetFieldForToUnionCast(QualType unionType,
2890
                                                       QualType opType);
2891
  static const FieldDecl *getTargetFieldForToUnionCast(const RecordDecl *RD,
2892
                                                       QualType opType);
2893
2894
108M
  static bool classof(const Stmt *T) {
2895
108M
    return T->getStmtClass() >= firstCastExprConstant &&
2896
108M
           
T->getStmtClass() <= lastCastExprConstant94.8M
;
2897
108M
  }
2898
2899
  // Iterators
2900
26.9M
  child_range children() { return child_range(&Op, &Op+1); }
2901
0
  const_child_range children() const { return const_child_range(&Op, &Op + 1); }
2902
};
2903
2904
/// ImplicitCastExpr - Allows us to explicitly represent implicit type
2905
/// conversions, which have no direct representation in the original
2906
/// source code. For example: converting T[]->T*, void f()->void
2907
/// (*f)(), float->double, short->int, etc.
2908
///
2909
/// In C, implicit casts always produce rvalues. However, in C++, an
2910
/// implicit cast whose result is being bound to a reference will be
2911
/// an lvalue or xvalue. For example:
2912
///
2913
/// @code
2914
/// class Base { };
2915
/// class Derived : public Base { };
2916
/// Derived &&ref();
2917
/// void f(Derived d) {
2918
///   Base& b = d; // initializer is an ImplicitCastExpr
2919
///                // to an lvalue of type Base
2920
///   Base&& r = ref(); // initializer is an ImplicitCastExpr
2921
///                     // to an xvalue of type Base
2922
/// }
2923
/// @endcode
2924
class ImplicitCastExpr final
2925
    : public CastExpr,
2926
      private llvm::TrailingObjects<ImplicitCastExpr, CastExpr::BasePathSizeTy,
2927
                                    CXXBaseSpecifier *> {
2928
828k
  size_t numTrailingObjects(OverloadToken<CastExpr::BasePathSizeTy>) const {
2929
828k
    return path_empty() ? 
0472k
:
1355k
;
2930
828k
  }
2931
2932
private:
2933
  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
2934
                   unsigned BasePathLength, ExprValueKind VK)
2935
18.4M
    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) {
2936
18.4M
  }
2937
2938
  /// Construct an empty implicit cast.
2939
  explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize)
2940
98.4k
    : CastExpr(ImplicitCastExprClass, Shell, PathSize) { }
2941
2942
public:
2943
  enum OnStack_t { OnStack };
2944
  ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op,
2945
                   ExprValueKind VK)
2946
1.10M
    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) {
2947
1.10M
  }
2948
2949
188k
  bool isPartOfExplicitCast() const { return CastExprBits.PartOfExplicitCast; }
2950
1.98M
  void setIsPartOfExplicitCast(bool PartOfExplicitCast) {
2951
1.98M
    CastExprBits.PartOfExplicitCast = PartOfExplicitCast;
2952
1.98M
  }
2953
2954
  static ImplicitCastExpr *Create(const ASTContext &Context, QualType T,
2955
                                  CastKind Kind, Expr *Operand,
2956
                                  const CXXCastPath *BasePath,
2957
                                  ExprValueKind Cat);
2958
2959
  static ImplicitCastExpr *CreateEmpty(const ASTContext &Context,
2960
                                       unsigned PathSize);
2961
2962
52.6M
  SourceLocation getBeginLoc() const LLVM_READONLY {
2963
52.6M
    return getSubExpr()->getBeginLoc();
2964
52.6M
  }
2965
4.70M
  SourceLocation getEndLoc() const LLVM_READONLY {
2966
4.70M
    return getSubExpr()->getEndLoc();
2967
4.70M
  }
2968
2969
227M
  static bool classof(const Stmt *T) {
2970
227M
    return T->getStmtClass() == ImplicitCastExprClass;
2971
227M
  }
2972
2973
  friend TrailingObjects;
2974
  friend class CastExpr;
2975
};
2976
2977
6.44M
inline Expr *Expr::IgnoreImpCasts() {
2978
6.44M
  Expr *e = this;
2979
9.41M
  while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
2980
2.96M
    e = ice->getSubExpr();
2981
6.44M
  return e;
2982
6.44M
}
2983
2984
/// ExplicitCastExpr - An explicit cast written in the source
2985
/// code.
2986
///
2987
/// This class is effectively an abstract class, because it provides
2988
/// the basic representation of an explicitly-written cast without
2989
/// specifying which kind of cast (C cast, functional cast, static
2990
/// cast, etc.) was written; specific derived classes represent the
2991
/// particular style of cast and its location information.
2992
///
2993
/// Unlike implicit casts, explicit cast nodes have two different
2994
/// types: the type that was written into the source code, and the
2995
/// actual type of the expression as determined by semantic
2996
/// analysis. These types may differ slightly. For example, in C++ one
2997
/// can cast to a reference type, which indicates that the resulting
2998
/// expression will be an lvalue or xvalue. The reference type, however,
2999
/// will not be used as the type of the expression.
3000
class ExplicitCastExpr : public CastExpr {
3001
  /// TInfo - Source type info for the (written) type
3002
  /// this expression is casting to.
3003
  TypeSourceInfo *TInfo;
3004
3005
protected:
3006
  ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK,
3007
                   CastKind kind, Expr *op, unsigned PathSize,
3008
                   TypeSourceInfo *writtenTy)
3009
3.28M
    : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {}
3010
3011
  /// Construct an empty explicit cast.
3012
  ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
3013
1.03k
    : CastExpr(SC, Shell, PathSize) { }
3014
3015
public:
3016
  /// getTypeInfoAsWritten - Returns the type source info for the type
3017
  /// that this expression is casting to.
3018
709k
  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
3019
1.03k
  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
3020
3021
  /// getTypeAsWritten - Returns the type that this expression is
3022
  /// casting to, as written in the source code.
3023
284k
  QualType getTypeAsWritten() const { return TInfo->getType(); }
3024
3025
45.0M
  static bool classof(const Stmt *T) {
3026
45.0M
     return T->getStmtClass() >= firstExplicitCastExprConstant &&
3027
45.0M
            
T->getStmtClass() <= lastExplicitCastExprConstant34.4M
;
3028
45.0M
  }
3029
};
3030
3031
/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
3032
/// cast in C++ (C++ [expr.cast]), which uses the syntax
3033
/// (Type)expr. For example: @c (int)f.
3034
class CStyleCastExpr final
3035
    : public ExplicitCastExpr,
3036
      private llvm::TrailingObjects<CStyleCastExpr, CastExpr::BasePathSizeTy,
3037
                                    CXXBaseSpecifier *> {
3038
  SourceLocation LPLoc; // the location of the left paren
3039
  SourceLocation RPLoc; // the location of the right paren
3040
3041
  CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
3042
                 unsigned PathSize, TypeSourceInfo *writtenTy,
3043
                 SourceLocation l, SourceLocation r)
3044
    : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
3045
2.94M
                       writtenTy), LPLoc(l), RPLoc(r) {}
3046
3047
  /// Construct an empty C-style explicit cast.
3048
  explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize)
3049
950
    : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { }
3050
3051
120k
  size_t numTrailingObjects(OverloadToken<CastExpr::BasePathSizeTy>) const {
3052
120k
    return path_empty() ? 
0119k
:
1667
;
3053
120k
  }
3054
3055
public:
3056
  static CStyleCastExpr *Create(const ASTContext &Context, QualType T,
3057
                                ExprValueKind VK, CastKind K,
3058
                                Expr *Op, const CXXCastPath *BasePath,
3059
                                TypeSourceInfo *WrittenTy, SourceLocation L,
3060
                                SourceLocation R);
3061
3062
  static CStyleCastExpr *CreateEmpty(const ASTContext &Context,
3063
                                     unsigned PathSize);
3064
3065
133k
  SourceLocation getLParenLoc() const { return LPLoc; }
3066
950
  void setLParenLoc(SourceLocation L) { LPLoc = L; }
3067
3068
133k
  SourceLocation getRParenLoc() const { return RPLoc; }
3069
950
  void setRParenLoc(SourceLocation L) { RPLoc = L; }
3070
3071
12.1M
  SourceLocation getBeginLoc() const LLVM_READONLY { return LPLoc; }
3072
100k
  SourceLocation getEndLoc() const LLVM_READONLY {
3073
100k
    return getSubExpr()->getEndLoc();
3074
100k
  }
3075
3076
1.46M
  static bool classof(const Stmt *T) {
3077
1.46M
    return T->getStmtClass() == CStyleCastExprClass;
3078
1.46M
  }
3079
3080
  friend TrailingObjects;
3081
  friend class CastExpr;
3082
};
3083
3084
/// A builtin binary operation expression such as "x + y" or "x <= y".
3085
///
3086
/// This expression node kind describes a builtin binary operation,
3087
/// such as "x + y" for integer values "x" and "y". The operands will
3088
/// already have been converted to appropriate types (e.g., by
3089
/// performing promotions or conversions).
3090
///
3091
/// In C++, where operators may be overloaded, a different kind of
3092
/// expression node (CXXOperatorCallExpr) is used to express the
3093
/// invocation of an overloaded operator with operator syntax. Within
3094
/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
3095
/// used to store an expression "x + y" depends on the subexpressions
3096
/// for x and y. If neither x or y is type-dependent, and the "+"
3097
/// operator resolves to a built-in operation, BinaryOperator will be
3098
/// used to express the computation (x and y may still be
3099
/// value-dependent). If either x or y is type-dependent, or if the
3100
/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
3101
/// be used to express the computation.
3102
class BinaryOperator : public Expr {
3103
public:
3104
  typedef BinaryOperatorKind Opcode;
3105
3106
private:
3107
  unsigned Opc : 6;
3108
3109
  // This is only meaningful for operations on floating point types and 0
3110
  // otherwise.
3111
  unsigned FPFeatures : 3;
3112
  SourceLocation OpLoc;
3113
3114
  enum { LHS, RHS, END_EXPR };
3115
  Stmt* SubExprs[END_EXPR];
3116
public:
3117
3118
  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
3119
                 ExprValueKind VK, ExprObjectKind OK,
3120
                 SourceLocation opLoc, FPOptions FPFeatures)
3121
    : Expr(BinaryOperatorClass, ResTy, VK, OK,
3122
           lhs->isTypeDependent() || rhs->isTypeDependent(),
3123
           lhs->isValueDependent() || rhs->isValueDependent(),
3124
           (lhs->isInstantiationDependent() ||
3125
            rhs->isInstantiationDependent()),
3126
           (lhs->containsUnexpandedParameterPack() ||
3127
            rhs->containsUnexpandedParameterPack())),
3128
6.40M
      Opc(opc), FPFeatures(FPFeatures.getInt()), OpLoc(opLoc) {
3129
6.40M
    SubExprs[LHS] = lhs;
3130
6.40M
    SubExprs[RHS] = rhs;
3131
6.40M
    assert(!isCompoundAssignmentOp() &&
3132
6.40M
           "Use CompoundAssignOperator for compound assignments");
3133
6.40M
  }
3134
3135
  /// Construct an empty binary operator.
3136
  explicit BinaryOperator(EmptyShell Empty)
3137
102k
    : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { }
3138
3139
11.4M
  SourceLocation getExprLoc() const LLVM_READONLY { return OpLoc; }
3140
5.87M
  SourceLocation getOperatorLoc() const { return OpLoc; }
3141
106k
  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
3142
3143
110M
  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
3144
106k
  void setOpcode(Opcode O) { Opc = O; }
3145
3146
42.6M
  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3147
106k
  void setLHS(Expr *E) { SubExprs[LHS] = E; }
3148
29.1M
  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3149
106k
  void setRHS(Expr *E) { SubExprs[RHS] = E; }
3150
3151
6.56M
  SourceLocation getBeginLoc() const LLVM_READONLY {
3152
6.56M
    return getLHS()->getBeginLoc();
3153
6.56M
  }
3154
768k
  SourceLocation getEndLoc() const LLVM_READONLY {
3155
768k
    return getRHS()->getEndLoc();
3156
768k
  }
3157
3158
  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
3159
  /// corresponds to, e.g. "<<=".
3160
  static StringRef getOpcodeStr(Opcode Op);
3161
3162
1.28k
  StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
3163
3164
  /// Retrieve the binary opcode that corresponds to the given
3165
  /// overloaded operator.
3166
  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
3167
3168
  /// Retrieve the overloaded operator kind that corresponds to
3169
  /// the given binary opcode.
3170
  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
3171
3172
  /// predicates to categorize the respective opcodes.
3173
150k
  bool isPtrMemOp() const { return Opc == BO_PtrMemD || 
Opc == BO_PtrMemI150k
; }
3174
172k
  static bool isMultiplicativeOp(Opcode Opc) {
3175
172k
    return Opc >= BO_Mul && Opc <= BO_Rem;
3176
172k
  }
3177
2.05k
  bool isMultiplicativeOp() const { return isMultiplicativeOp(getOpcode()); }
3178
2.68M
  static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || 
Opc==BO_Sub2.27M
; }
3179
2.50M
  bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
3180
184k
  static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || 
Opc == BO_Shr183k
; }
3181
209
  bool isShiftOp() const { return isShiftOp(getOpcode()); }
3182
3183
4.93M
  static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && 
Opc <= BO_Or2.10M
; }
3184
17.2k
  bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
3185
3186
1.65M
  static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && 
Opc<=BO_GE1.64M
; }
3187
441k
  bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
3188
3189
544k
  static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || 
Opc == BO_NE359k
; }
3190
486k
  bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
3191
3192
10.0M
  static bool isComparisonOp(Opcode Opc) { return Opc >= BO_Cmp && 
Opc<=BO_NE6.58M
; }
3193
4.88M
  bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
3194
3195
74.0k
  static Opcode negateComparisonOp(Opcode Opc) {
3196
74.0k
    switch (Opc) {
3197
74.0k
    default:
3198
0
      llvm_unreachable("Not a comparison operator.");
3199
74.0k
    
case BO_LT: return BO_GE466
;
3200
74.0k
    
case BO_GT: return BO_LE804
;
3201
74.0k
    
case BO_LE: return BO_GT3.13k
;
3202
74.0k
    
case BO_GE: return BO_LT1.75k
;
3203
74.0k
    
case BO_EQ: return BO_NE2.73k
;
3204
74.0k
    
case BO_NE: return BO_EQ65.1k
;
3205
74.0k
    }
3206
74.0k
  }
3207
3208
1.19k
  static Opcode reverseComparisonOp(Opcode Opc) {
3209
1.19k
    switch (Opc) {
3210
1.19k
    default:
3211
0
      llvm_unreachable("Not a comparison operator.");
3212
1.19k
    
case BO_LT: return BO_GT470
;
3213
1.19k
    
case BO_GT: return BO_LT54
;
3214
1.19k
    
case BO_LE: return BO_GE31
;
3215
1.19k
    
case BO_GE: return BO_LE65
;
3216
1.19k
    case BO_EQ:
3217
574
    case BO_NE:
3218
574
      return Opc;
3219
1.19k
    }
3220
1.19k
  }
3221
3222
23.2M
  static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || 
Opc==BO_LOr21.8M
; }
3223
23.2M
  bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
3224
3225
12.0M
  static bool isAssignmentOp(Opcode Opc) {
3226
12.0M
    return Opc >= BO_Assign && 
Opc <= BO_OrAssign1.60M
;
3227
12.0M
  }
3228
12.0M
  bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
3229
3230
708k
  static bool isCompoundAssignmentOp(Opcode Opc) {
3231
708k
    return Opc > BO_Assign && 
Opc <= BO_OrAssign13.2k
;
3232
708k
  }
3233
708k
  bool isCompoundAssignmentOp() const {
3234
708k
    return isCompoundAssignmentOp(getOpcode());
3235
708k
  }
3236
20.2k
  static Opcode getOpForCompoundAssignment(Opcode Opc) {
3237
20.2k
    assert(isCompoundAssignmentOp(Opc));
3238
20.2k
    if (Opc >= BO_AndAssign)
3239
5.00k
      return Opcode(unsigned(Opc) - BO_AndAssign + BO_And);
3240
15.2k
    else
3241
15.2k
      return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul);
3242
20.2k
  }
3243
3244
  static bool isShiftAssignOp(Opcode Opc) {
3245
    return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
3246
  }
3247
  bool isShiftAssignOp() const {
3248
    return isShiftAssignOp(getOpcode());
3249
  }
3250
3251
  // Return true if a binary operator using the specified opcode and operands
3252
  // would match the 'p = (i8*)nullptr + n' idiom for casting a pointer-sized
3253
  // integer to a pointer.
3254
  static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc,
3255
                                               Expr *LHS, Expr *RHS);
3256
3257
265M
  static bool classof(const Stmt *S) {
3258
265M
    return S->getStmtClass() >= firstBinaryOperatorConstant &&
3259
265M
           
S->getStmtClass() <= lastBinaryOperatorConstant260M
;
3260
265M
  }
3261
3262
  // Iterators
3263
8.52M
  child_range children() {
3264
8.52M
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3265
8.52M
  }
3266
0
  const_child_range children() const {
3267
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
3268
0
  }
3269
3270
  // Set the FP contractability status of this operator. Only meaningful for
3271
  // operations on floating point types.
3272
106k
  void setFPFeatures(FPOptions F) { FPFeatures = F.getInt(); }
3273
3274
1.62M
  FPOptions getFPFeatures() const { return FPOptions(FPFeatures); }
3275
3276
  // Get the FP contractability status of this operator. Only meaningful for
3277
  // operations on floating point types.
3278
  bool isFPContractableWithinStatement() const {
3279
    return FPOptions(FPFeatures).allowFPContractWithinStatement();
3280
  }
3281
3282
  // Get the FENV_ACCESS status of this operator. Only meaningful for
3283
  // operations on floating point types.
3284
  bool isFEnvAccessOn() const {
3285
    return FPOptions(FPFeatures).allowFEnvAccess();
3286
  }
3287
3288
protected:
3289
  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
3290
                 ExprValueKind VK, ExprObjectKind OK,
3291
                 SourceLocation opLoc, FPOptions FPFeatures, bool dead2)
3292
    : Expr(CompoundAssignOperatorClass, ResTy, VK, OK,
3293
           lhs->isTypeDependent() || rhs->isTypeDependent(),
3294
           lhs->isValueDependent() || rhs->isValueDependent(),
3295
           (lhs->isInstantiationDependent() ||
3296
            rhs->isInstantiationDependent()),
3297
           (lhs->containsUnexpandedParameterPack() ||
3298
            rhs->containsUnexpandedParameterPack())),
3299
201k
      Opc(opc), FPFeatures(FPFeatures.getInt()), OpLoc(opLoc) {
3300
201k
    SubExprs[LHS] = lhs;
3301
201k
    SubExprs[RHS] = rhs;
3302
201k
  }
3303
3304
  BinaryOperator(StmtClass SC, EmptyShell Empty)
3305
4.24k
    : Expr(SC, Empty), Opc(BO_MulAssign) { }
3306
};
3307
3308
/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
3309
/// track of the type the operation is performed in.  Due to the semantics of
3310
/// these operators, the operands are promoted, the arithmetic performed, an
3311
/// implicit conversion back to the result type done, then the assignment takes
3312
/// place.  This captures the intermediate type which the computation is done
3313
/// in.
3314
class CompoundAssignOperator : public BinaryOperator {
3315
  QualType ComputationLHSType;
3316
  QualType ComputationResultType;
3317
public:
3318
  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType,
3319
                         ExprValueKind VK, ExprObjectKind OK,
3320
                         QualType CompLHSType, QualType CompResultType,
3321
                         SourceLocation OpLoc, FPOptions FPFeatures)
3322
    : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, FPFeatures,
3323
                     true),
3324
      ComputationLHSType(CompLHSType),
3325
201k
      ComputationResultType(CompResultType) {
3326
201k
    assert(isCompoundAssignmentOp() &&
3327
201k
           "Only should be used for compound assignments");
3328
201k
  }
3329
3330
  /// Build an empty compound assignment operator expression.
3331
  explicit CompoundAssignOperator(EmptyShell Empty)
3332
4.24k
    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
3333
3334
  // The two computation types are the type the LHS is converted
3335
  // to for the computation and the type of the result; the two are
3336
  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
3337
72.1k
  QualType getComputationLHSType() const { return ComputationLHSType; }
3338
4.24k
  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
3339
3340
238k
  QualType getComputationResultType() const { return ComputationResultType; }
3341
4.24k
  void setComputationResultType(QualType T) { ComputationResultType = T; }
3342
3343
2.26M
  static bool classof(const Stmt *S) {
3344
2.26M
    return S->getStmtClass() == CompoundAssignOperatorClass;
3345
2.26M
  }
3346
};
3347
3348
/// AbstractConditionalOperator - An abstract base class for
3349
/// ConditionalOperator and BinaryConditionalOperator.
3350
class AbstractConditionalOperator : public Expr {
3351
  SourceLocation QuestionLoc, ColonLoc;
3352
  friend class ASTStmtReader;
3353
3354
protected:
3355
  AbstractConditionalOperator(StmtClass SC, QualType T,
3356
                              ExprValueKind VK, ExprObjectKind OK,
3357
                              bool TD, bool VD, bool ID,
3358
                              bool ContainsUnexpandedParameterPack,
3359
                              SourceLocation qloc,
3360
                              SourceLocation cloc)
3361
    : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack),
3362
233k
      QuestionLoc(qloc), ColonLoc(cloc) {}
3363
3364
  AbstractConditionalOperator(StmtClass SC, EmptyShell Empty)
3365
4.22k
    : Expr(SC, Empty) { }
3366
3367
public:
3368
  // getCond - Return the expression representing the condition for
3369
  //   the ?: operator.
3370
  Expr *getCond() const;
3371
3372
  // getTrueExpr - Return the subexpression representing the value of
3373
  //   the expression if the condition evaluates to true.
3374
  Expr *getTrueExpr() const;
3375
3376
  // getFalseExpr - Return the subexpression representing the value of
3377
  //   the expression if the condition evaluates to false.  This is
3378
  //   the same as getRHS.
3379
  Expr *getFalseExpr() const;
3380
3381
207k
  SourceLocation getQuestionLoc() const { return QuestionLoc; }
3382
34.0k
  SourceLocation getColonLoc() const { return ColonLoc; }
3383
3384
1.77k
  static bool classof(const Stmt *T) {
3385
1.77k
    return T->getStmtClass() == ConditionalOperatorClass ||
3386
1.77k
           
T->getStmtClass() == BinaryConditionalOperatorClass1.75k
;
3387
1.77k
  }
3388
};
3389
3390
/// ConditionalOperator - The ?: ternary operator.  The GNU "missing
3391
/// middle" extension is a BinaryConditionalOperator.
3392
class ConditionalOperator : public AbstractConditionalOperator {
3393
  enum { COND, LHS, RHS, END_EXPR };
3394
  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
3395
3396
  friend class ASTStmtReader;
3397
public:
3398
  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
3399
                      SourceLocation CLoc, Expr *rhs,
3400
                      QualType t, ExprValueKind VK, ExprObjectKind OK)
3401
    : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK,
3402
           // FIXME: the type of the conditional operator doesn't
3403
           // depend on the type of the conditional, but the standard
3404
           // seems to imply that it could. File a bug!
3405
           (lhs->isTypeDependent() || rhs->isTypeDependent()),
3406
           (cond->isValueDependent() || lhs->isValueDependent() ||
3407
            rhs->isValueDependent()),
3408
           (cond->isInstantiationDependent() ||
3409
            lhs->isInstantiationDependent() ||
3410
            rhs->isInstantiationDependent()),
3411
           (cond->containsUnexpandedParameterPack() ||
3412
            lhs->containsUnexpandedParameterPack() ||
3413
            rhs->containsUnexpandedParameterPack()),
3414
233k
                                  QLoc, CLoc) {
3415
233k
    SubExprs[COND] = cond;
3416
233k
    SubExprs[LHS] = lhs;
3417
233k
    SubExprs[RHS] = rhs;
3418
233k
  }
3419
3420
  /// Build an empty conditional operator.
3421
  explicit ConditionalOperator(EmptyShell Empty)
3422
4.22k
    : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
3423
3424
  // getCond - Return the expression representing the condition for
3425
  //   the ?: operator.
3426
1.52M
  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3427
3428
  // getTrueExpr - Return the subexpression representing the value of
3429
  //   the expression if the condition evaluates to true.
3430
609k
  Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
3431
3432
  // getFalseExpr - Return the subexpression representing the value of
3433
  //   the expression if the condition evaluates to false.  This is
3434
  //   the same as getRHS.
3435
616k
  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
3436
3437
209k
  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3438
217k
  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3439
3440
530k
  SourceLocation getBeginLoc() const LLVM_READONLY {
3441
530k
    return getCond()->getBeginLoc();
3442
530k
  }
3443
7.14k
  SourceLocation getEndLoc() const LLVM_READONLY {
3444
7.14k
    return getRHS()->getEndLoc();
3445
7.14k
  }
3446
3447
38.9M
  static bool classof(const Stmt *T) {
3448
38.9M
    return T->getStmtClass() == ConditionalOperatorClass;
3449
38.9M
  }
3450
3451
  // Iterators
3452
102k
  child_range children() {
3453
102k
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3454
102k
  }
3455
0
  const_child_range children() const {
3456
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
3457
0
  }
3458
};
3459
3460
/// BinaryConditionalOperator - The GNU extension to the conditional
3461
/// operator which allows the middle operand to be omitted.
3462
///
3463
/// This is a different expression kind on the assumption that almost
3464
/// every client ends up needing to know that these are different.
3465
class BinaryConditionalOperator : public AbstractConditionalOperator {
3466
  enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
3467
3468
  /// - the common condition/left-hand-side expression, which will be
3469
  ///   evaluated as the opaque value
3470
  /// - the condition, expressed in terms of the opaque value
3471
  /// - the left-hand-side, expressed in terms of the opaque value
3472
  /// - the right-hand-side
3473
  Stmt *SubExprs[NUM_SUBEXPRS];
3474
  OpaqueValueExpr *OpaqueValue;
3475
3476
  friend class ASTStmtReader;
3477
public:
3478
  BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue,
3479
                            Expr *cond, Expr *lhs, Expr *rhs,
3480
                            SourceLocation qloc, SourceLocation cloc,
3481
                            QualType t, ExprValueKind VK, ExprObjectKind OK)
3482
    : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
3483
           (common->isTypeDependent() || rhs->isTypeDependent()),
3484
           (common->isValueDependent() || rhs->isValueDependent()),
3485
           (common->isInstantiationDependent() ||
3486
            rhs->isInstantiationDependent()),
3487
           (common->containsUnexpandedParameterPack() ||
3488
            rhs->containsUnexpandedParameterPack()),
3489
                                  qloc, cloc),
3490
208
      OpaqueValue(opaqueValue) {
3491
208
    SubExprs[COMMON] = common;
3492
208
    SubExprs[COND] = cond;
3493
208
    SubExprs[LHS] = lhs;
3494
208
    SubExprs[RHS] = rhs;
3495
208
    assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value");
3496
208
  }
3497
3498
  /// Build an empty conditional operator.
3499
  explicit BinaryConditionalOperator(EmptyShell Empty)
3500
1
    : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
3501
3502
  /// getCommon - Return the common expression, written to the
3503
  ///   left of the condition.  The opaque value will be bound to the
3504
  ///   result of this expression.
3505
2.06k
  Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
3506
3507
  /// getOpaqueValue - Return the opaque value placeholder.
3508
694
  OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
3509
3510
  /// getCond - Return the condition expression; this is defined
3511
  ///   in terms of the opaque value.
3512
1.51k
  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3513
3514
  /// getTrueExpr - Return the subexpression which will be
3515
  ///   evaluated if the condition evaluates to true;  this is defined
3516
  ///   in terms of the opaque value.
3517
1.27k
  Expr *getTrueExpr() const {
3518
1.27k
    return cast<Expr>(SubExprs[LHS]);
3519
1.27k
  }
3520
3521
  /// getFalseExpr - Return the subexpression which will be
3522
  ///   evaluated if the condnition evaluates to false; this is
3523
  ///   defined in terms of the opaque value.
3524
1.18k
  Expr *getFalseExpr() const {
3525
1.18k
    return cast<Expr>(SubExprs[RHS]);
3526
1.18k
  }
3527
3528
1.24k
  SourceLocation getBeginLoc() const LLVM_READONLY {
3529
1.24k
    return getCommon()->getBeginLoc();
3530
1.24k
  }
3531
208
  SourceLocation getEndLoc() const LLVM_READONLY {
3532
208
    return getFalseExpr()->getEndLoc();
3533
208
  }
3534
3535
1.55M
  static bool classof(const Stmt *T) {
3536
1.55M
    return T->getStmtClass() == BinaryConditionalOperatorClass;
3537
1.55M
  }
3538
3539
  // Iterators
3540
441
  child_range children() {
3541
441
    return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
3542
441
  }
3543
0
  const_child_range children() const {
3544
0
    return const_child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
3545
0
  }
3546
};
3547
3548
379k
inline Expr *AbstractConditionalOperator::getCond() const {
3549
379k
  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3550
378k
    return co->getCond();
3551
908
  return cast<BinaryConditionalOperator>(this)->getCond();
3552
908
}
3553
3554
298k
inline Expr *AbstractConditionalOperator::getTrueExpr() const {
3555
298k
  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3556
297k
    return co->getTrueExpr();
3557
712
  return cast<BinaryConditionalOperator>(this)->getTrueExpr();
3558
712
}
3559
3560
286k
inline Expr *AbstractConditionalOperator::getFalseExpr() const {
3561
286k
  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3562
286k
    return co->getFalseExpr();
3563
649
  return cast<BinaryConditionalOperator>(this)->getFalseExpr();
3564
649
}
3565
3566
/// AddrLabelExpr - The GNU address of label extension, representing &&label.
3567
class AddrLabelExpr : public Expr {
3568
  SourceLocation AmpAmpLoc, LabelLoc;
3569
  LabelDecl *Label;
3570
public:
3571
  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L,
3572
                QualType t)
3573
    : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false,
3574
           false),
3575
276
      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
3576
3577
  /// Build an empty address of a label expression.
3578
  explicit AddrLabelExpr(EmptyShell Empty)
3579
2
    : Expr(AddrLabelExprClass, Empty) { }
3580
3581
12
  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
3582
2
  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
3583
13
  SourceLocation getLabelLoc() const { return LabelLoc; }
3584
2
  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
3585
3586
1.71k
  SourceLocation getBeginLoc() const LLVM_READONLY { return AmpAmpLoc; }
3587
519
  SourceLocation getEndLoc() const LLVM_READONLY { return LabelLoc; }
3588
3589
741
  LabelDecl *getLabel() const { return Label; }
3590
2
  void setLabel(LabelDecl *L) { Label = L; }
3591
3592
313
  static bool classof(const Stmt *T) {
3593
313
    return T->getStmtClass() == AddrLabelExprClass;
3594
313
  }
3595
3596
  // Iterators
3597
1.15k
  child_range children() {
3598
1.15k
    return child_range(child_iterator(), child_iterator());
3599
1.15k
  }
3600
0
  const_child_range children() const {
3601
0
    return const_child_range(const_child_iterator(), const_child_iterator());
3602
0
  }
3603
};
3604
3605
/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
3606
/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
3607
/// takes the value of the last subexpression.
3608
///
3609
/// A StmtExpr is always an r-value; values "returned" out of a
3610
/// StmtExpr will be copied.
3611
class StmtExpr : public Expr {
3612
  Stmt *SubStmt;
3613
  SourceLocation LParenLoc, RParenLoc;
3614
public:
3615
  // FIXME: Does type-dependence need to be computed differently?
3616
  // FIXME: Do we need to compute instantiation instantiation-dependence for
3617
  // statements? (ugh!)
3618
  StmtExpr(CompoundStmt *substmt, QualType T,
3619
           SourceLocation lp, SourceLocation rp) :
3620
    Expr(StmtExprClass, T, VK_RValue, OK_Ordinary,
3621
         T->isDependentType(), false, false, false),
3622
10.9k
    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
3623
3624
  /// Build an empty statement expression.
3625
13
  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
3626
3627
2.68k
  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
3628
13.1k
  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
3629
13
  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
3630
3631
20.5k
  SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
3632
341
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3633
3634
29
  SourceLocation getLParenLoc() const { return LParenLoc; }
3635
13
  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3636
29
  SourceLocation getRParenLoc() const { return RParenLoc; }
3637
13
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3638
3639
43.4M
  static bool classof(const Stmt *T) {
3640
43.4M
    return T->getStmtClass() == StmtExprClass;
3641
43.4M
  }
3642
3643
  // Iterators
3644
18.4k
  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
3645
0
  const_child_range children() const {
3646
0
    return const_child_range(&SubStmt, &SubStmt + 1);
3647
0
  }
3648
};
3649
3650
/// ShuffleVectorExpr - clang-specific builtin-in function
3651
/// __builtin_shufflevector.
3652
/// This AST node represents a operator that does a constant
3653
/// shuffle, similar to LLVM's shufflevector instruction. It takes
3654
/// two vectors and a variable number of constant indices,
3655
/// and returns the appropriately shuffled vector.
3656
class ShuffleVectorExpr : public Expr {
3657
  SourceLocation BuiltinLoc, RParenLoc;
3658
3659
  // SubExprs - the list of values passed to the __builtin_shufflevector
3660
  // function. The first two are vectors, and the rest are constant
3661
  // indices.  The number of values in this list is always
3662
  // 2+the number of indices in the vector type.
3663
  Stmt **SubExprs;
3664
  unsigned NumExprs;
3665
3666
public:
3667
  ShuffleVectorExpr(const ASTContext &C, ArrayRef<Expr*> args, QualType Type,
3668
                    SourceLocation BLoc, SourceLocation RP);
3669
3670
  /// Build an empty vector-shuffle expression.
3671
  explicit ShuffleVectorExpr(EmptyShell Empty)
3672
2
    : Expr(ShuffleVectorExprClass, Empty), SubExprs(nullptr) { }
3673
3674
1.30k
  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3675
2
  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3676
3677
1.30k
  SourceLocation getRParenLoc() const { return RParenLoc; }
3678
2
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3679
3680
336k
  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
3681
19.7k
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3682
3683
0
  static bool classof(const Stmt *T) {
3684
0
    return T->getStmtClass() == ShuffleVectorExprClass;
3685
0
  }
3686
3687
  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
3688
  /// constant expression, the actual arguments passed in, and the function
3689
  /// pointers.
3690
16.0k
  unsigned getNumSubExprs() const { return NumExprs; }
3691
3692
  /// Retrieve the array of expressions.
3693
4
  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
3694
3695
  /// getExpr - Return the Expr at the specified index.
3696
15.5k
  Expr *getExpr(unsigned Index) {
3697
15.5k
    assert((Index < NumExprs) && "Arg access out of range!");
3698
15.5k
    return cast<Expr>(SubExprs[Index]);
3699
15.5k
  }
3700
9.99k
  const Expr *getExpr(unsigned Index) const {
3701
9.99k
    assert((Index < NumExprs) && "Arg access out of range!");
3702
9.99k
    return cast<Expr>(SubExprs[Index]);
3703
9.99k
  }
3704
3705
  void setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs);
3706
3707
9.99k
  llvm::APSInt getShuffleMaskIdx(const ASTContext &Ctx, unsigned N) const {
3708
9.99k
    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
3709
9.99k
    return getExpr(N+2)->EvaluateKnownConstInt(Ctx);
3710
9.99k
  }
3711
3712
  // Iterators
3713
212k
  child_range children() {
3714
212k
    return child_range(&SubExprs[0], &SubExprs[0]+NumExprs);
3715
212k
  }
3716
0
  const_child_range children() const {
3717
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + NumExprs);
3718
0
  }
3719
};
3720
3721
/// ConvertVectorExpr - Clang builtin function __builtin_convertvector
3722
/// This AST node provides support for converting a vector type to another
3723
/// vector type of the same arity.
3724
class ConvertVectorExpr : public Expr {
3725
private:
3726
  Stmt *SrcExpr;
3727
  TypeSourceInfo *TInfo;
3728
  SourceLocation BuiltinLoc, RParenLoc;
3729
3730
  friend class ASTReader;
3731
  friend class ASTStmtReader;
3732
0
  explicit ConvertVectorExpr(EmptyShell Empty) : Expr(ConvertVectorExprClass, Empty) {}
3733
3734
public:
3735
  ConvertVectorExpr(Expr* SrcExpr, TypeSourceInfo *TI, QualType DstType,
3736
             ExprValueKind VK, ExprObjectKind OK,
3737
             SourceLocation BuiltinLoc, SourceLocation RParenLoc)
3738
    : Expr(ConvertVectorExprClass, DstType, VK, OK,
3739
           DstType->isDependentType(),
3740
           DstType->isDependentType() || SrcExpr->isValueDependent(),
3741
           (DstType->isInstantiationDependentType() ||
3742
            SrcExpr->isInstantiationDependent()),
3743
           (DstType->containsUnexpandedParameterPack() ||
3744
            SrcExpr->containsUnexpandedParameterPack())),
3745
12.6k
  SrcExpr(SrcExpr), TInfo(TI), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {}
3746
3747
  /// getSrcExpr - Return the Expr to be converted.
3748
896
  Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
3749
3750
  /// getTypeSourceInfo - Return the destination type.
3751
351
  TypeSourceInfo *getTypeSourceInfo() const {
3752
351
    return TInfo;
3753
351
  }
3754
  void setTypeSourceInfo(TypeSourceInfo *ti) {
3755
    TInfo = ti;
3756
  }
3757
3758
  /// getBuiltinLoc - Return the location of the __builtin_convertvector token.
3759
350
  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3760
3761
  /// getRParenLoc - Return the location of final right parenthesis.
3762
350
  SourceLocation getRParenLoc() const { return RParenLoc; }
3763
3764
16.8k
  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
3765
10.2k
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3766
3767
  static bool classof(const Stmt *T) {
3768
    return T->getStmtClass() == ConvertVectorExprClass;
3769
  }
3770
3771
  // Iterators
3772
25.8k
  child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
3773
0
  const_child_range children() const {
3774
0
    return const_child_range(&SrcExpr, &SrcExpr + 1);
3775
0
  }
3776
};
3777
3778
/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
3779
/// This AST node is similar to the conditional operator (?:) in C, with
3780
/// the following exceptions:
3781
/// - the test expression must be a integer constant expression.
3782
/// - the expression returned acts like the chosen subexpression in every
3783
///   visible way: the type is the same as that of the chosen subexpression,
3784
///   and all predicates (whether it's an l-value, whether it's an integer
3785
///   constant expression, etc.) return the same result as for the chosen
3786
///   sub-expression.
3787
class ChooseExpr : public Expr {
3788
  enum { COND, LHS, RHS, END_EXPR };
3789
  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
3790
  SourceLocation BuiltinLoc, RParenLoc;
3791
  bool CondIsTrue;
3792
public:
3793
  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs,
3794
             QualType t, ExprValueKind VK, ExprObjectKind OK,
3795
             SourceLocation RP, bool condIsTrue,
3796
             bool TypeDependent, bool ValueDependent)
3797
    : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent,
3798
           (cond->isInstantiationDependent() ||
3799
            lhs->isInstantiationDependent() ||
3800
            rhs->isInstantiationDependent()),
3801
           (cond->containsUnexpandedParameterPack() ||
3802
            lhs->containsUnexpandedParameterPack() ||
3803
            rhs->containsUnexpandedParameterPack())),
3804
39
      BuiltinLoc(BLoc), RParenLoc(RP), CondIsTrue(condIsTrue) {
3805
39
      SubExprs[COND] = cond;
3806
39
      SubExprs[LHS] = lhs;
3807
39
      SubExprs[RHS] = rhs;
3808
39
    }
3809
3810
  /// Build an empty __builtin_choose_expr.
3811
1
  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
3812
3813
  /// isConditionTrue - Return whether the condition is true (i.e. not
3814
  /// equal to zero).
3815
220
  bool isConditionTrue() const {
3816
220
    assert(!isConditionDependent() &&
3817
220
           "Dependent condition isn't true or false");
3818
220
    return CondIsTrue;
3819
220
  }
3820
1
  void setIsConditionTrue(bool isTrue) { CondIsTrue = isTrue; }
3821
3822
174
  bool isConditionDependent() const {
3823
174
    return getCond()->isTypeDependent() || getCond()->isValueDependent();
3824
174
  }
3825
3826
  /// getChosenSubExpr - Return the subexpression chosen according to the
3827
  /// condition.
3828
217
  Expr *getChosenSubExpr() const {
3829
217
    return isConditionTrue() ? 
getLHS()99
:
getRHS()118
;
3830
217
  }
3831
3832
384
  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3833
1
  void setCond(Expr *E) { SubExprs[COND] = E; }
3834
108
  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3835
1
  void setLHS(Expr *E) { SubExprs[LHS] = E; }
3836
127
  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3837
1
  void setRHS(Expr *E) { SubExprs[RHS] = E; }
3838
3839
5
  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3840
1
  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3841
3842
5
  SourceLocation getRParenLoc() const { return RParenLoc; }
3843
1
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3844
3845
61
  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
3846
12
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3847
3848
348M
  static bool classof(const Stmt *T) {
3849
348M
    return T->getStmtClass() == ChooseExprClass;
3850
348M
  }
3851
3852
  // Iterators
3853
24
  child_range children() {
3854
24
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3855
24
  }
3856
0
  const_child_range children() const {
3857
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
3858
0
  }
3859
};
3860
3861
/// GNUNullExpr - Implements the GNU __null extension, which is a name
3862
/// for a null pointer constant that has integral type (e.g., int or
3863
/// long) and is the same size and alignment as a pointer. The __null
3864
/// extension is typically only used by system headers, which define
3865
/// NULL as __null in C++ rather than using 0 (which is an integer
3866
/// that may not match the size of a pointer).
3867
class GNUNullExpr : public Expr {
3868
  /// TokenLoc - The location of the __null keyword.
3869
  SourceLocation TokenLoc;
3870
3871
public:
3872
  GNUNullExpr(QualType Ty, SourceLocation Loc)
3873
    : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false,
3874
           false),
3875
7.44k
      TokenLoc(Loc) { }
3876
3877
  /// Build an empty GNU __null expression.
3878
0
  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
3879
3880
  /// getTokenLocation - The location of the __null token.
3881
0
  SourceLocation getTokenLocation() const { return TokenLoc; }
3882
0
  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
3883
3884
33.8k
  SourceLocation getBeginLoc() const LLVM_READONLY { return TokenLoc; }
3885
10.3k
  SourceLocation getEndLoc() const LLVM_READONLY { return TokenLoc; }
3886
3887
11.8M
  static bool classof(const Stmt *T) {
3888
11.8M
    return T->getStmtClass() == GNUNullExprClass;
3889
11.8M
  }
3890
3891
  // Iterators
3892
8.13k
  child_range children() {
3893
8.13k
    return child_range(child_iterator(), child_iterator());
3894
8.13k
  }
3895
0
  const_child_range children() const {
3896
0
    return const_child_range(const_child_iterator(), const_child_iterator());
3897
0
  }
3898
};
3899
3900
/// Represents a call to the builtin function \c __builtin_va_arg.
3901
class VAArgExpr : public Expr {
3902
  Stmt *Val;
3903
  llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfo;
3904
  SourceLocation BuiltinLoc, RParenLoc;
3905
public:
3906
  VAArgExpr(SourceLocation BLoc, Expr *e, TypeSourceInfo *TInfo,
3907
            SourceLocation RPLoc, QualType t, bool IsMS)
3908
      : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, t->isDependentType(),
3909
             false, (TInfo->getType()->isInstantiationDependentType() ||
3910
                     e->isInstantiationDependent()),
3911
             (TInfo->getType()->containsUnexpandedParameterPack() ||
3912
              e->containsUnexpandedParameterPack())),
3913
1.35k
        Val(e), TInfo(TInfo, IsMS), BuiltinLoc(BLoc), RParenLoc(RPLoc) {}
3914
3915
  /// Create an empty __builtin_va_arg expression.
3916
  explicit VAArgExpr(EmptyShell Empty)
3917
2
      : Expr(VAArgExprClass, Empty), Val(nullptr), TInfo(nullptr, false) {}
3918
3919
37
  const Expr *getSubExpr() const { return cast<Expr>(Val); }
3920
1.03k
  Expr *getSubExpr() { return cast<Expr>(Val); }
3921
2
  void setSubExpr(Expr *E) { Val = E; }
3922
3923
  /// Returns whether this is really a Win64 ABI va_arg expression.
3924
2.03k
  bool isMicrosoftABI() const { return TInfo.getInt(); }
3925
2
  void setIsMicrosoftABI(bool IsMS) { TInfo.setInt(IsMS); }
3926
3927
74
  TypeSourceInfo *getWrittenTypeInfo() const { return TInfo.getPointer(); }
3928
2
  void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo.setPointer(TI); }
3929
3930
14
  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3931
2
  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3932
3933
14
  SourceLocation getRParenLoc() const { return RParenLoc; }
3934
2
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3935
3936
7.19k
  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
3937
357
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3938
3939
44
  static bool classof(const Stmt *T) {
3940
44
    return T->getStmtClass() == VAArgExprClass;
3941
44
  }
3942
3943
  // Iterators
3944
5.61k
  child_range children() { return child_range(&Val, &Val+1); }
3945
0
  const_child_range children() const {
3946
0
    return const_child_range(&Val, &Val + 1);
3947
0
  }
3948
};
3949
3950
/// Describes an C or C++ initializer list.
3951
///
3952
/// InitListExpr describes an initializer list, which can be used to
3953
/// initialize objects of different types, including
3954
/// struct/class/union types, arrays, and vectors. For example:
3955
///
3956
/// @code
3957
/// struct foo x = { 1, { 2, 3 } };
3958
/// @endcode
3959
///
3960
/// Prior to semantic analysis, an initializer list will represent the
3961
/// initializer list as written by the user, but will have the
3962
/// placeholder type "void". This initializer list is called the
3963
/// syntactic form of the initializer, and may contain C99 designated
3964
/// initializers (represented as DesignatedInitExprs), initializations
3965
/// of subobject members without explicit braces, and so on. Clients
3966
/// interested in the original syntax of the initializer list should
3967
/// use the syntactic form of the initializer list.
3968
///
3969
/// After semantic analysis, the initializer list will represent the
3970
/// semantic form of the initializer, where the initializations of all
3971
/// subobjects are made explicit with nested InitListExpr nodes and
3972
/// C99 designators have been eliminated by placing the designated
3973
/// initializations into the subobject they initialize. Additionally,
3974
/// any "holes" in the initialization, where no initializer has been
3975
/// specified for a particular subobject, will be replaced with
3976
/// implicitly-generated ImplicitValueInitExpr expressions that
3977
/// value-initialize the subobjects. Note, however, that the
3978
/// initializer lists may still have fewer initializers than there are
3979
/// elements to initialize within the object.
3980
///
3981
/// After semantic analysis has completed, given an initializer list,
3982
/// method isSemanticForm() returns true if and only if this is the
3983
/// semantic form of the initializer list (note: the same AST node
3984
/// may at the same time be the syntactic form).
3985
/// Given the semantic form of the initializer list, one can retrieve
3986
/// the syntactic form of that initializer list (when different)
3987
/// using method getSyntacticForm(); the method returns null if applied
3988
/// to a initializer list which is already in syntactic form.
3989
/// Similarly, given the syntactic form (i.e., an initializer list such
3990
/// that isSemanticForm() returns false), one can retrieve the semantic
3991
/// form using method getSemanticForm().
3992
/// Since many initializer lists have the same syntactic and semantic forms,
3993
/// getSyntacticForm() may return NULL, indicating that the current
3994
/// semantic initializer list also serves as its syntactic form.
3995
class InitListExpr : public Expr {
3996
  // FIXME: Eliminate this vector in favor of ASTContext allocation
3997
  typedef ASTVector<Stmt *> InitExprsTy;
3998
  InitExprsTy InitExprs;
3999
  SourceLocation LBraceLoc, RBraceLoc;
4000
4001
  /// The alternative form of the initializer list (if it exists).
4002
  /// The int part of the pair stores whether this initializer list is
4003
  /// in semantic form. If not null, the pointer points to:
4004
  ///   - the syntactic form, if this is in semantic form;
4005
  ///   - the semantic form, if this is in syntactic form.
4006
  llvm::PointerIntPair<InitListExpr *, 1, bool> AltForm;
4007
4008
  /// Either:
4009
  ///  If this initializer list initializes an array with more elements than
4010
  ///  there are initializers in the list, specifies an expression to be used
4011
  ///  for value initialization of the rest of the elements.
4012
  /// Or
4013
  ///  If this initializer list initializes a union, specifies which
4014
  ///  field within the union will be initialized.
4015
  llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit;
4016
4017
public:
4018
  InitListExpr(const ASTContext &C, SourceLocation lbraceloc,
4019
               ArrayRef<Expr*> initExprs, SourceLocation rbraceloc);
4020
4021
  /// Build an empty initializer list.
4022
  explicit InitListExpr(EmptyShell Empty)
4023
1.73k
    : Expr(InitListExprClass, Empty), AltForm(nullptr, true) { }
4024
4025
5.37M
  unsigned getNumInits() const { return InitExprs.size(); }
4026
4027
  /// Retrieve the set of initializers.
4028
190k
  Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
4029
4030
  /// Retrieve the set of initializers.
4031
0
  Expr * const *getInits() const {
4032
0
    return reinterpret_cast<Expr * const *>(InitExprs.data());
4033
0
  }
4034
4035
149k
  ArrayRef<Expr *> inits() {
4036
149k
    return llvm::makeArrayRef(getInits(), getNumInits());
4037
149k
  }
4038
4039
0
  ArrayRef<Expr *> inits() const {
4040
0
    return llvm::makeArrayRef(getInits(), getNumInits());
4041
0
  }
4042
4043
713k
  const Expr *getInit(unsigned Init) const {
4044
713k
    assert(Init < getNumInits() && "Initializer access out of range!");
4045
713k
    return cast_or_null<Expr>(InitExprs[Init]);
4046
713k
  }
4047
4048
7.73M
  Expr *getInit(unsigned Init) {
4049
7.73M
    assert(Init < getNumInits() && "Initializer access out of range!");
4050
7.73M
    return cast_or_null<Expr>(InitExprs[Init]);
4051
7.73M
  }
4052
4053
1.69M
  void setInit(unsigned Init, Expr *expr) {
4054
1.69M
    assert(Init < getNumInits() && "Initializer access out of range!");
4055
1.69M
    InitExprs[Init] = expr;
4056
1.69M
4057
1.69M
    if (expr) {
4058
1.69M
      ExprBits.TypeDependent |= expr->isTypeDependent();
4059
1.69M
      ExprBits.ValueDependent |= expr->isValueDependent();
4060
1.69M
      ExprBits.InstantiationDependent |= expr->isInstantiationDependent();
4061
1.69M
      ExprBits.ContainsUnexpandedParameterPack |=
4062
1.69M
          expr->containsUnexpandedParameterPack();
4063
1.69M
    }
4064
1.69M
  }
4065
4066
  /// Reserve space for some number of initializers.
4067
  void reserveInits(const ASTContext &C, unsigned NumInits);
4068
4069
  /// Specify the number of initializers
4070
  ///
4071
  /// If there are more than @p NumInits initializers, the remaining
4072
  /// initializers will be destroyed. If there are fewer than @p
4073
  /// NumInits initializers, NULL expressions will be added for the
4074
  /// unknown initializers.
4075
  void resizeInits(const ASTContext &Context, unsigned NumInits);
4076
4077
  /// Updates the initializer at index @p Init with the new
4078
  /// expression @p expr, and returns the old expression at that
4079
  /// location.
4080
  ///
4081
  /// When @p Init is out of range for this initializer list, the
4082
  /// initializer list will be extended with NULL expressions to
4083
  /// accommodate the new entry.
4084
  Expr *updateInit(const ASTContext &C, unsigned Init, Expr *expr);
4085
4086
  /// If this initializer list initializes an array with more elements
4087
  /// than there are initializers in the list, specifies an expression to be
4088
  /// used for value initialization of the rest of the elements.
4089
158k
  Expr *getArrayFiller() {
4090
158k
    return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>();
4091
158k
  }
4092
134k
  const Expr *getArrayFiller() const {
4093
134k
    return const_cast<InitListExpr *>(this)->getArrayFiller();
4094
134k
  }
4095
  void setArrayFiller(Expr *filler);
4096
4097
  /// Return true if this is an array initializer and its array "filler"
4098
  /// has been set.
4099
39.1k
  bool hasArrayFiller() const { return getArrayFiller(); }
4100
4101
  /// If this initializes a union, specifies which field in the
4102
  /// union to initialize.
4103
  ///
4104
  /// Typically, this field is the first named field within the
4105
  /// union. However, a designated initializer can specify the
4106
  /// initialization of a different field within the union.
4107
18.2k
  FieldDecl *getInitializedFieldInUnion() {
4108
18.2k
    return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>();
4109
18.2k
  }
4110
3.68k
  const FieldDecl *getInitializedFieldInUnion() const {
4111
3.68k
    return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion();
4112
3.68k
  }
4113
2.90k
  void setInitializedFieldInUnion(FieldDecl *FD) {
4114
2.90k
    assert((FD == nullptr
4115
2.90k
            || getInitializedFieldInUnion() == nullptr
4116
2.90k
            || getInitializedFieldInUnion() == FD)
4117
2.90k
           && "Only one field of a union may be initialized at a time!");
4118
2.90k
    ArrayFillerOrUnionFieldInit = FD;
4119
2.90k
  }
4120
4121
  // Explicit InitListExpr's originate from source code (and have valid source
4122
  // locations). Implicit InitListExpr's are created by the semantic analyzer.
4123
0
  bool isExplicit() const {
4124
0
    return LBraceLoc.isValid() && RBraceLoc.isValid();
4125
0
  }
4126
4127
  // Is this an initializer for an array of characters, initialized by a string
4128
  // literal or an @encode?
4129
  bool isStringLiteralInit() const;
4130
4131
  /// Is this a transparent initializer list (that is, an InitListExpr that is
4132
  /// purely syntactic, and whose semantics are that of the sole contained
4133
  /// initializer)?
4134
  bool isTransparent() const;
4135
4136
  /// Is this the zero initializer {0} in a language which considers it
4137
  /// idiomatic?
4138
  bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const;
4139
4140
14.8k
  SourceLocation getLBraceLoc() const { return LBraceLoc; }
4141
1.73k
  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
4142
14.7k
  SourceLocation getRBraceLoc() const { return RBraceLoc; }
4143
2.94k
  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
4144
4145
1.38M
  bool isSemanticForm() const { return AltForm.getInt(); }
4146
396
  InitListExpr *getSemanticForm() const {
4147
396
    return isSemanticForm() ? 
nullptr0
: AltForm.getPointer();
4148
396
  }
4149
0
  bool isSyntacticForm() const {
4150
0
    return !AltForm.getInt() || !AltForm.getPointer();
4151
0
  }
4152
1.37M
  InitListExpr *getSyntacticForm() const {
4153
1.37M
    return isSemanticForm() ? 
AltForm.getPointer()1.04M
:
nullptr329k
;
4154
1.37M
  }
4155
4156
192k
  void setSyntacticForm(InitListExpr *Init) {
4157
192k
    AltForm.setPointer(Init);
4158
192k
    AltForm.setInt(true);
4159
192k
    Init->AltForm.setPointer(this);
4160
192k
    Init->AltForm.setInt(false);
4161
192k
  }
4162
4163
11.6k
  bool hadArrayRangeDesignator() const {
4164
11.6k
    return InitListExprBits.HadArrayRangeDesignator != 0;
4165
11.6k
  }
4166
259k
  void sawArrayRangeDesignator(bool ARD = true) {
4167
259k
    InitListExprBits.HadArrayRangeDesignator = ARD;
4168
259k
  }
4169
4170
  SourceLocation getBeginLoc() const LLVM_READONLY;
4171
  SourceLocation getEndLoc() const LLVM_READONLY;
4172
4173
104M
  static bool classof(const Stmt *T) {
4174
104M
    return T->getStmtClass() == InitListExprClass;
4175
104M
  }
4176
4177
  // Iterators
4178
370k
  child_range children() {
4179
370k
    const_child_range CCR = const_cast<const InitListExpr *>(this)->children();
4180
370k
    return child_range(cast_away_const(CCR.begin()),
4181
370k
                       cast_away_const(CCR.end()));
4182
370k
  }
4183
4184
370k
  const_child_range children() const {
4185
370k
    // FIXME: This does not include the array filler expression.
4186
370k
    if (InitExprs.empty())
4187
31.5k
      return const_child_range(const_child_iterator(), const_child_iterator());
4188
338k
    return const_child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size());
4189
338k
  }
4190
4191
  typedef InitExprsTy::iterator iterator;
4192
  typedef InitExprsTy::const_iterator const_iterator;
4193
  typedef InitExprsTy::reverse_iterator reverse_iterator;
4194
  typedef InitExprsTy::const_reverse_iterator const_reverse_iterator;
4195
4196
0
  iterator begin() { return InitExprs.begin(); }
4197
7
  const_iterator begin() const { return InitExprs.begin(); }
4198
0
  iterator end() { return InitExprs.end(); }
4199
0
  const_iterator end() const { return InitExprs.end(); }
4200
0
  reverse_iterator rbegin() { return InitExprs.rbegin(); }
4201
850
  const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
4202
0
  reverse_iterator rend() { return InitExprs.rend(); }
4203
850
  const_reverse_iterator rend() const { return InitExprs.rend(); }
4204
4205
  friend class ASTStmtReader;
4206
  friend class ASTStmtWriter;
4207
};
4208
4209
/// Represents a C99 designated initializer expression.
4210
///
4211
/// A designated initializer expression (C99 6.7.8) contains one or
4212
/// more designators (which can be field designators, array
4213
/// designators, or GNU array-range designators) followed by an
4214
/// expression that initializes the field or element(s) that the
4215
/// designators refer to. For example, given:
4216
///
4217
/// @code
4218
/// struct point {
4219
///   double x;
4220
///   double y;
4221
/// };
4222
/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
4223
/// @endcode
4224
///
4225
/// The InitListExpr contains three DesignatedInitExprs, the first of
4226
/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
4227
/// designators, one array designator for @c [2] followed by one field
4228
/// designator for @c .y. The initialization expression will be 1.0.
4229
class DesignatedInitExpr final
4230
    : public Expr,
4231
      private llvm::TrailingObjects<DesignatedInitExpr, Stmt *> {
4232
public:
4233
  /// Forward declaration of the Designator class.
4234
  class Designator;
4235
4236
private:
4237
  /// The location of the '=' or ':' prior to the actual initializer
4238
  /// expression.
4239
  SourceLocation EqualOrColonLoc;
4240
4241
  /// Whether this designated initializer used the GNU deprecated
4242
  /// syntax rather than the C99 '=' syntax.
4243
  unsigned GNUSyntax : 1;
4244
4245
  /// The number of designators in this initializer expression.
4246
  unsigned NumDesignators : 15;
4247
4248
  /// The number of subexpressions of this initializer expression,
4249
  /// which contains both the initializer and any additional
4250
  /// expressions used by array and array-range designators.
4251
  unsigned NumSubExprs : 16;
4252
4253
  /// The designators in this designated initialization
4254
  /// expression.
4255
  Designator *Designators;
4256
4257
  DesignatedInitExpr(const ASTContext &C, QualType Ty,
4258
                     llvm::ArrayRef<Designator> Designators,
4259
                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
4260
                     ArrayRef<Expr *> IndexExprs, Expr *Init);
4261
4262
  explicit DesignatedInitExpr(unsigned NumSubExprs)
4263
    : Expr(DesignatedInitExprClass, EmptyShell()),
4264
9
      NumDesignators(0), NumSubExprs(NumSubExprs), Designators(nullptr) { }
4265
4266
public:
4267
  /// A field designator, e.g., ".x".
4268
  struct FieldDesignator {
4269
    /// Refers to the field that is being initialized. The low bit
4270
    /// of this field determines whether this is actually a pointer
4271
    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
4272
    /// initially constructed, a field designator will store an
4273
    /// IdentifierInfo*. After semantic analysis has resolved that
4274
    /// name, the field designator will instead store a FieldDecl*.
4275
    uintptr_t NameOrField;
4276
4277
    /// The location of the '.' in the designated initializer.
4278
    unsigned DotLoc;
4279
4280
    /// The location of the field name in the designated initializer.
4281
    unsigned FieldLoc;
4282
  };
4283
4284
  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
4285
  struct ArrayOrRangeDesignator {
4286
    /// Location of the first index expression within the designated
4287
    /// initializer expression's list of subexpressions.
4288
    unsigned Index;
4289
    /// The location of the '[' starting the array range designator.
4290
    unsigned LBracketLoc;
4291
    /// The location of the ellipsis separating the start and end
4292
    /// indices. Only valid for GNU array-range designators.
4293
    unsigned EllipsisLoc;
4294
    /// The location of the ']' terminating the array range designator.
4295
    unsigned RBracketLoc;
4296
  };
4297
4298
  /// Represents a single C99 designator.
4299
  ///
4300
  /// @todo This class is infuriatingly similar to clang::Designator,
4301
  /// but minor differences (storing indices vs. storing pointers)
4302
  /// keep us from reusing it. Try harder, later, to rectify these
4303
  /// differences.
4304
  class Designator {
4305
    /// The kind of designator this describes.
4306
    enum {
4307
      FieldDesignator,
4308
      ArrayDesignator,
4309
      ArrayRangeDesignator
4310
    } Kind;
4311
4312
    union {
4313
      /// A field designator, e.g., ".x".
4314
      struct FieldDesignator Field;
4315
      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
4316
      struct ArrayOrRangeDesignator ArrayOrRange;
4317
    };
4318
    friend class DesignatedInitExpr;
4319
4320
  public:
4321
3.03k
    Designator() {}
4322
4323
    /// Initializes a field designator.
4324
    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
4325
               SourceLocation FieldLoc)
4326
2.65k
      : Kind(FieldDesignator) {
4327
2.65k
      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
4328
2.65k
      Field.DotLoc = DotLoc.getRawEncoding();
4329
2.65k
      Field.FieldLoc = FieldLoc.getRawEncoding();
4330
2.65k
    }
4331
4332
    /// Initializes an array designator.
4333
    Designator(unsigned Index, SourceLocation LBracketLoc,
4334
               SourceLocation RBracketLoc)
4335
302
      : Kind(ArrayDesignator) {
4336
302
      ArrayOrRange.Index = Index;
4337
302
      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
4338
302
      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
4339
302
      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
4340
302
    }
4341
4342
    /// Initializes a GNU array-range designator.
4343
    Designator(unsigned Index, SourceLocation LBracketLoc,
4344
               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
4345
26
      : Kind(ArrayRangeDesignator) {
4346
26
      ArrayOrRange.Index = Index;
4347
26
      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
4348
26
      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
4349
26
      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
4350
26
    }
4351
4352
11.5k
    bool isFieldDesignator() const { return Kind == FieldDesignator; }
4353
3.60k
    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
4354
2.62k
    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
4355
4356
    IdentifierInfo *getFieldName() const;
4357
4358
5.34k
    FieldDecl *getField() const {
4359
5.34k
      assert(Kind == FieldDesignator && "Only valid on a field designator");
4360
5.34k
      if (Field.NameOrField & 0x01)
4361
5.07k
        return nullptr;
4362
273
      else
4363
273
        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
4364
5.34k
    }
4365
4366
2.64k
    void setField(FieldDecl *FD) {
4367
2.64k
      assert(Kind == FieldDesignator && "Only valid on a field designator");
4368
2.64k
      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
4369
2.64k
    }
4370
4371
605
    SourceLocation getDotLoc() const {
4372
605
      assert(Kind == FieldDesignator && "Only valid on a field designator");
4373
605
      return SourceLocation::getFromRawEncoding(Field.DotLoc);
4374
605
    }
4375
4376
2.77k
    SourceLocation getFieldLoc() const {
4377
2.77k
      assert(Kind == FieldDesignator && "Only valid on a field designator");
4378
2.77k
      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
4379
2.77k
    }
4380
4381
161
    SourceLocation getLBracketLoc() const {
4382
161
      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4383
161
             "Only valid on an array or array-range designator");
4384
161
      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
4385
161
    }
4386
4387
52
    SourceLocation getRBracketLoc() const {
4388
52
      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4389
52
             "Only valid on an array or array-range designator");
4390
52
      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
4391
52
    }
4392
4393
8
    SourceLocation getEllipsisLoc() const {
4394
8
      assert(Kind == ArrayRangeDesignator &&
4395
8
             "Only valid on an array-range designator");
4396
8
      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
4397
8
    }
4398
4399
61
    unsigned getFirstExprIndex() const {
4400
61
      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4401
61
             "Only valid on an array or array-range designator");
4402
61
      return ArrayOrRange.Index;
4403
61
    }
4404
4405
301
    SourceLocation getBeginLoc() const LLVM_READONLY {
4406
301
      if (Kind == FieldDesignator)
4407
225
        return getDotLoc().isInvalid()? 
getFieldLoc()8
:
getDotLoc()217
;
4408
76
      else
4409
76
        return getLBracketLoc();
4410
301
    }
4411
18
    SourceLocation getEndLoc() const LLVM_READONLY {
4412
18
      return Kind == FieldDesignator ? getFieldLoc() : 
getRBracketLoc()0
;
4413
18
    }
4414
18
    SourceRange getSourceRange() const LLVM_READONLY {
4415
18
      return SourceRange(getBeginLoc(), getEndLoc());
4416
18
    }
4417
  };
4418
4419
  static DesignatedInitExpr *Create(const ASTContext &C,
4420
                                    llvm::ArrayRef<Designator> Designators,
4421
                                    ArrayRef<Expr*> IndexExprs,
4422
                                    SourceLocation EqualOrColonLoc,
4423
                                    bool GNUSyntax, Expr *Init);
4424
4425
  static DesignatedInitExpr *CreateEmpty(const ASTContext &C,
4426
                                         unsigned NumIndexExprs);
4427
4428
  /// Returns the number of designators in this initializer.
4429
11.0k
  unsigned size() const { return NumDesignators; }
4430
4431
  // Iterator access to the designators.
4432
11.4k
  llvm::MutableArrayRef<Designator> designators() {
4433
11.4k
    return {Designators, NumDesignators};
4434
11.4k
  }
4435
4436
32
  llvm::ArrayRef<Designator> designators() const {
4437
32
    return {Designators, NumDesignators};
4438
32
  }
4439
4440
11.2k
  Designator *getDesignator(unsigned Idx) { return &designators()[Idx]; }
4441
0
  const Designator *getDesignator(unsigned Idx) const {
4442
0
    return &designators()[Idx];
4443
0
  }
4444
4445
  void setDesignators(const ASTContext &C, const Designator *Desigs,
4446
                      unsigned NumDesigs);
4447
4448
  Expr *getArrayIndex(const Designator &D) const;
4449
  Expr *getArrayRangeStart(const Designator &D) const;
4450
  Expr *getArrayRangeEnd(const Designator &D) const;
4451
4452
  /// Retrieve the location of the '=' that precedes the
4453
  /// initializer value itself, if present.
4454
153
  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
4455
9
  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
4456
4457
  /// Determines whether this designated initializer used the
4458
  /// deprecated GNU syntax for designated initializers.
4459
170
  bool usesGNUSyntax() const { return GNUSyntax; }
4460
9
  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
4461
4462
  /// Retrieve the initializer value.
4463
11.2k
  Expr *getInit() const {
4464
11.2k
    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
4465
11.2k
  }
4466
4467
2.09k
  void setInit(Expr *init) {
4468
2.09k
    *child_begin() = init;
4469
2.09k
  }
4470
4471
  /// Retrieve the total number of subexpressions in this
4472
  /// designated initializer expression, including the actual
4473
  /// initialized value and any expressions that occur within array
4474
  /// and array-range designators.
4475
148
  unsigned getNumSubExprs() const { return NumSubExprs; }
4476
4477
831
  Expr *getSubExpr(unsigned Idx) const {
4478
831
    assert(Idx < NumSubExprs && "Subscript out of range");
4479
831
    return cast<Expr>(getTrailingObjects<Stmt *>()[Idx]);
4480
831
  }
4481
4482
14
  void setSubExpr(unsigned Idx, Expr *E) {
4483
14
    assert(Idx < NumSubExprs && "Subscript out of range");
4484
14
    getTrailingObjects<Stmt *>()[Idx] = E;
4485
14
  }
4486
4487
  /// Replaces the designator at index @p Idx with the series
4488
  /// of designators in [First, Last).
4489
  void ExpandDesignator(const ASTContext &C, unsigned Idx,
4490
                        const Designator *First, const Designator *Last);
4491
4492
  SourceRange getDesignatorsSourceRange() const;
4493
4494
  SourceLocation getBeginLoc() const LLVM_READONLY;
4495
  SourceLocation getEndLoc() const LLVM_READONLY;
4496
4497
2.93M
  static bool classof(const Stmt *T) {
4498
2.93M
    return T->getStmtClass() == DesignatedInitExprClass;
4499
2.93M
  }
4500
4501
  // Iterators
4502
16.3k
  child_range children() {
4503
16.3k
    Stmt **begin = getTrailingObjects<Stmt *>();
4504
16.3k
    return child_range(begin, begin + NumSubExprs);
4505
16.3k
  }
4506
0
  const_child_range children() const {
4507
0
    Stmt * const *begin = getTrailingObjects<Stmt *>();
4508
0
    return const_child_range(begin, begin + NumSubExprs);
4509
0
  }
4510
4511
  friend TrailingObjects;
4512
};
4513
4514
/// Represents a place-holder for an object not to be initialized by
4515
/// anything.
4516
///
4517
/// This only makes sense when it appears as part of an updater of a
4518
/// DesignatedInitUpdateExpr (see below). The base expression of a DIUE
4519
/// initializes a big object, and the NoInitExpr's mark the spots within the
4520
/// big object not to be overwritten by the updater.
4521
///
4522
/// \see DesignatedInitUpdateExpr
4523
class NoInitExpr : public Expr {
4524
public:
4525
  explicit NoInitExpr(QualType ty)
4526
    : Expr(NoInitExprClass, ty, VK_RValue, OK_Ordinary,
4527
39
           false, false, ty->isInstantiationDependentType(), false) { }
4528
4529
  explicit NoInitExpr(EmptyShell Empty)
4530
1
    : Expr(NoInitExprClass, Empty) { }
4531
4532
13.6k
  static bool classof(const Stmt *T) {
4533
13.6k
    return T->getStmtClass() == NoInitExprClass;
4534
13.6k
  }
4535
4536
51
  SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
4537
0
  SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
4538
4539
  // Iterators
4540
166
  child_range children() {
4541
166
    return child_range(child_iterator(), child_iterator());
4542
166
  }
4543
0
  const_child_range children() const {
4544
0
    return const_child_range(const_child_iterator(), const_child_iterator());
4545
0
  }
4546
};
4547
4548
// In cases like:
4549
//   struct Q { int a, b, c; };
4550
//   Q *getQ();
4551
//   void foo() {
4552
//     struct A { Q q; } a = { *getQ(), .q.b = 3 };
4553
//   }
4554
//
4555
// We will have an InitListExpr for a, with type A, and then a
4556
// DesignatedInitUpdateExpr for "a.q" with type Q. The "base" for this DIUE
4557
// is the call expression *getQ(); the "updater" for the DIUE is ".q.b = 3"
4558
//
4559
class DesignatedInitUpdateExpr : public Expr {
4560
  // BaseAndUpdaterExprs[0] is the base expression;
4561
  // BaseAndUpdaterExprs[1] is an InitListExpr overwriting part of the base.
4562
  Stmt *BaseAndUpdaterExprs[2];
4563
4564
public:
4565
  DesignatedInitUpdateExpr(const ASTContext &C, SourceLocation lBraceLoc,
4566
                           Expr *baseExprs, SourceLocation rBraceLoc);
4567
4568
  explicit DesignatedInitUpdateExpr(EmptyShell Empty)
4569
1
    : Expr(DesignatedInitUpdateExprClass, Empty) { }
4570
4571
  SourceLocation getBeginLoc() const LLVM_READONLY;
4572
  SourceLocation getEndLoc() const LLVM_READONLY;
4573
4574
1.17M
  static bool classof(const Stmt *T) {
4575
1.17M
    return T->getStmtClass() == DesignatedInitUpdateExprClass;
4576
1.17M
  }
4577
4578
135
  Expr *getBase() const { return cast<Expr>(BaseAndUpdaterExprs[0]); }
4579
1
  void setBase(Expr *Base) { BaseAndUpdaterExprs[0] = Base; }
4580
4581
119
  InitListExpr *getUpdater() const {
4582
119
    return cast<InitListExpr>(BaseAndUpdaterExprs[1]);
4583
119
  }
4584
1
  void setUpdater(Expr *Updater) { BaseAndUpdaterExprs[1] = Updater; }
4585
4586
  // Iterators
4587
  // children = the base and the updater
4588
97
  child_range children() {
4589
97
    return child_range(&BaseAndUpdaterExprs[0], &BaseAndUpdaterExprs[0] + 2);
4590
97
  }
4591
0
  const_child_range children() const {
4592
0
    return const_child_range(&BaseAndUpdaterExprs[0],
4593
0
                             &BaseAndUpdaterExprs[0] + 2);
4594
0
  }
4595
};
4596
4597
/// Represents a loop initializing the elements of an array.
4598
///
4599
/// The need to initialize the elements of an array occurs in a number of
4600
/// contexts:
4601
///
4602
///  * in the implicit copy/move constructor for a class with an array member
4603
///  * when a lambda-expression captures an array by value
4604
///  * when a decomposition declaration decomposes an array
4605
///
4606
/// There are two subexpressions: a common expression (the source array)
4607
/// that is evaluated once up-front, and a per-element initializer that
4608
/// runs once for each array element.
4609
///
4610
/// Within the per-element initializer, the common expression may be referenced
4611
/// via an OpaqueValueExpr, and the current index may be obtained via an
4612
/// ArrayInitIndexExpr.
4613
class ArrayInitLoopExpr : public Expr {
4614
  Stmt *SubExprs[2];
4615
4616
  explicit ArrayInitLoopExpr(EmptyShell Empty)
4617
1
      : Expr(ArrayInitLoopExprClass, Empty), SubExprs{} {}
4618
4619
public:
4620
  explicit ArrayInitLoopExpr(QualType T, Expr *CommonInit, Expr *ElementInit)
4621
      : Expr(ArrayInitLoopExprClass, T, VK_RValue, OK_Ordinary, false,
4622
             CommonInit->isValueDependent() || ElementInit->isValueDependent(),
4623
             T->isInstantiationDependentType(),
4624
             CommonInit->containsUnexpandedParameterPack() ||
4625
                 ElementInit->containsUnexpandedParameterPack()),
4626
1.04k
        SubExprs{CommonInit, ElementInit} {}
4627
4628
  /// Get the common subexpression shared by all initializations (the source
4629
  /// array).
4630
900
  OpaqueValueExpr *getCommonExpr() const {
4631
900
    return cast<OpaqueValueExpr>(SubExprs[0]);
4632
900
  }
4633
4634
  /// Get the initializer to use for each array element.
4635
67
  Expr *getSubExpr() const { return cast<Expr>(SubExprs[1]); }
4636
4637
28
  llvm::APInt getArraySize() const {
4638
28
    return cast<ConstantArrayType>(getType()->castAsArrayTypeUnsafe())
4639
28
        ->getSize();
4640
28
  }
4641
4642
1.28M
  static bool classof(const Stmt *S) {
4643
1.28M
    return S->getStmtClass() == ArrayInitLoopExprClass;
4644
1.28M
  }
4645
4646
473
  SourceLocation getBeginLoc() const LLVM_READONLY {
4647
473
    return getCommonExpr()->getBeginLoc();
4648
473
  }
4649
386
  SourceLocation getEndLoc() const LLVM_READONLY {
4650
386
    return getCommonExpr()->getEndLoc();
4651
386
  }
4652
4653
1.11k
  child_range children() {
4654
1.11k
    return child_range(SubExprs, SubExprs + 2);
4655
1.11k
  }
4656
0
  const_child_range children() const {
4657
0
    return const_child_range(SubExprs, SubExprs + 2);
4658
0
  }
4659
4660
  friend class ASTReader;
4661
  friend class ASTStmtReader;
4662
  friend class ASTStmtWriter;
4663
};
4664
4665
/// Represents the index of the current element of an array being
4666
/// initialized by an ArrayInitLoopExpr. This can only appear within the
4667
/// subexpression of an ArrayInitLoopExpr.
4668
class ArrayInitIndexExpr : public Expr {
4669
  explicit ArrayInitIndexExpr(EmptyShell Empty)
4670
1
      : Expr(ArrayInitIndexExprClass, Empty) {}
4671
4672
public:
4673
  explicit ArrayInitIndexExpr(QualType T)
4674
      : Expr(ArrayInitIndexExprClass, T, VK_RValue, OK_Ordinary,
4675
1.04k
             false, false, false, false) {}
4676
4677
  static bool classof(const Stmt *S) {
4678
    return S->getStmtClass() == ArrayInitIndexExprClass;
4679
  }
4680
4681
140
  SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
4682
73
  SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
4683
4684
93
  child_range children() {
4685
93
    return child_range(child_iterator(), child_iterator());
4686
93
  }
4687
0
  const_child_range children() const {
4688
0
    return const_child_range(const_child_iterator(), const_child_iterator());
4689
0
  }
4690
4691
  friend class ASTReader;
4692
  friend class ASTStmtReader;
4693
};
4694
4695
/// Represents an implicitly-generated value initialization of
4696
/// an object of a given type.
4697
///
4698
/// Implicit value initializations occur within semantic initializer
4699
/// list expressions (InitListExpr) as placeholders for subobject
4700
/// initializations not explicitly specified by the user.
4701
///
4702
/// \see InitListExpr
4703
class ImplicitValueInitExpr : public Expr {
4704
public:
4705
  explicit ImplicitValueInitExpr(QualType ty)
4706
    : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary,
4707
464k
           false, false, ty->isInstantiationDependentType(), false) { }
4708
4709
  /// Construct an empty implicit value initialization.
4710
  explicit ImplicitValueInitExpr(EmptyShell Empty)
4711
63
    : Expr(ImplicitValueInitExprClass, Empty) { }
4712
4713
2.08M
  static bool classof(const Stmt *T) {
4714
2.08M
    return T->getStmtClass() == ImplicitValueInitExprClass;
4715
2.08M
  }
4716
4717
22.7k
  SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
4718
180
  SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
4719
4720
  // Iterators
4721
36.5k
  child_range children() {
4722
36.5k
    return child_range(child_iterator(), child_iterator());
4723
36.5k
  }
4724
0
  const_child_range children() const {
4725
0
    return const_child_range(const_child_iterator(), const_child_iterator());
4726
0
  }
4727
};
4728
4729
class ParenListExpr : public Expr {
4730
  Stmt **Exprs;
4731
  unsigned NumExprs;
4732
  SourceLocation LParenLoc, RParenLoc;
4733
4734
public:
4735
  ParenListExpr(const ASTContext& C, SourceLocation lparenloc,
4736
                ArrayRef<Expr*> exprs, SourceLocation rparenloc);
4737
4738
  /// Build an empty paren list.
4739
868
  explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
4740
4741
938k
  unsigned getNumExprs() const { return NumExprs; }
4742
4743
3
  const Expr* getExpr(unsigned Init) const {
4744
3
    assert(Init < getNumExprs() && "Initializer access out of range!");
4745
3
    return cast_or_null<Expr>(Exprs[Init]);
4746
3
  }
4747
4748
478k
  Expr* getExpr(unsigned Init) {
4749
478k
    assert(Init < getNumExprs() && "Initializer access out of range!");
4750
478k
    return cast_or_null<Expr>(Exprs[Init]);
4751
478k
  }
4752
4753
448k
  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
4754
4755
192
  ArrayRef<Expr *> exprs() {
4756
192
    return llvm::makeArrayRef(getExprs(), getNumExprs());
4757
192
  }
4758
4759
528k
  SourceLocation getLParenLoc() const { return LParenLoc; }
4760
528k
  SourceLocation getRParenLoc() const { return RParenLoc; }
4761
4762
414k
  SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
4763
409k
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4764
4765
19.3M
  static bool classof(const Stmt *T) {
4766
19.3M
    return T->getStmtClass() == ParenListExprClass;
4767
19.3M
  }
4768
4769
  // Iterators
4770
38.1k
  child_range children() {
4771
38.1k
    return child_range(&Exprs[0], &Exprs[0]+NumExprs);
4772
38.1k
  }
4773
0
  const_child_range children() const {
4774
0
    return const_child_range(&Exprs[0], &Exprs[0] + NumExprs);
4775
0
  }
4776
4777
  friend class ASTStmtReader;
4778
  friend class ASTStmtWriter;
4779
};
4780
4781
/// Represents a C11 generic selection.
4782
///
4783
/// A generic selection (C11 6.5.1.1) contains an unevaluated controlling
4784
/// expression, followed by one or more generic associations.  Each generic
4785
/// association specifies a type name and an expression, or "default" and an
4786
/// expression (in which case it is known as a default generic association).
4787
/// The type and value of the generic selection are identical to those of its
4788
/// result expression, which is defined as the expression in the generic
4789
/// association with a type name that is compatible with the type of the
4790
/// controlling expression, or the expression in the default generic association
4791
/// if no types are compatible.  For example:
4792
///
4793
/// @code
4794
/// _Generic(X, double: 1, float: 2, default: 3)
4795
/// @endcode
4796
///
4797
/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f
4798
/// or 3 if "hello".
4799
///
4800
/// As an extension, generic selections are allowed in C++, where the following
4801
/// additional semantics apply:
4802
///
4803
/// Any generic selection whose controlling expression is type-dependent or
4804
/// which names a dependent type in its association list is result-dependent,
4805
/// which means that the choice of result expression is dependent.
4806
/// Result-dependent generic associations are both type- and value-dependent.
4807
class GenericSelectionExpr : public Expr {
4808
  enum { CONTROLLING, END_EXPR };
4809
  TypeSourceInfo **AssocTypes;
4810
  Stmt **SubExprs;
4811
  unsigned NumAssocs, ResultIndex;
4812
  SourceLocation GenericLoc, DefaultLoc, RParenLoc;
4813
4814
public:
4815
  GenericSelectionExpr(const ASTContext &Context,
4816
                       SourceLocation GenericLoc, Expr *ControllingExpr,
4817
                       ArrayRef<TypeSourceInfo*> AssocTypes,
4818
                       ArrayRef<Expr*> AssocExprs,
4819
                       SourceLocation DefaultLoc, SourceLocation RParenLoc,
4820
                       bool ContainsUnexpandedParameterPack,
4821
                       unsigned ResultIndex);
4822
4823
  /// This constructor is used in the result-dependent case.
4824
  GenericSelectionExpr(const ASTContext &Context,
4825
                       SourceLocation GenericLoc, Expr *ControllingExpr,
4826
                       ArrayRef<TypeSourceInfo*> AssocTypes,
4827
                       ArrayRef<Expr*> AssocExprs,
4828
                       SourceLocation DefaultLoc, SourceLocation RParenLoc,
4829
                       bool ContainsUnexpandedParameterPack);
4830
4831
  explicit GenericSelectionExpr(EmptyShell Empty)
4832
1
    : Expr(GenericSelectionExprClass, Empty) { }
4833
4834
114
  unsigned getNumAssocs() const { return NumAssocs; }
4835
4836
15
  SourceLocation getGenericLoc() const { return GenericLoc; }
4837
15
  SourceLocation getDefaultLoc() const { return DefaultLoc; }
4838
15
  SourceLocation getRParenLoc() const { return RParenLoc; }
4839
4840
59
  const Expr *getAssocExpr(unsigned i) const {
4841
59
    return cast<Expr>(SubExprs[END_EXPR+i]);
4842
59
  }
4843
600
  Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); }
4844
1
  ArrayRef<Expr *> getAssocExprs() const {
4845
1
    return NumAssocs
4846
1
               ? llvm::makeArrayRef(
4847
1
                     &reinterpret_cast<Expr **>(SubExprs)[END_EXPR], NumAssocs)
4848
1
               : 
None0
;
4849
1
  }
4850
12
  const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const {
4851
12
    return AssocTypes[i];
4852
12
  }
4853
76
  TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; }
4854
1
  ArrayRef<TypeSourceInfo *> getAssocTypeSourceInfos() const {
4855
1
    return NumAssocs ? llvm::makeArrayRef(&AssocTypes[0], NumAssocs) : 
None0
;
4856
1
  }
4857
4858
12
  QualType getAssocType(unsigned i) const {
4859
12
    if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i))
4860
9
      return TS->getType();
4861
3
    else
4862
3
      return QualType();
4863
12
  }
4864
4865
1
  const Expr *getControllingExpr() const {
4866
1
    return cast<Expr>(SubExprs[CONTROLLING]);
4867
1
  }
4868
24
  Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); }
4869
4870
  /// Whether this generic selection is result-dependent.
4871
489
  bool isResultDependent() const { return ResultIndex == -1U; }
4872
4873
  /// The zero-based index of the result expression's generic association in
4874
  /// the generic selection's association list.  Defined only if the
4875
  /// generic selection is not result-dependent.
4876
581
  unsigned getResultIndex() const {
4877
581
    assert(!isResultDependent() && "Generic selection is result-dependent");
4878
581
    return ResultIndex;
4879
581
  }
4880
4881
  /// The generic selection's result expression.  Defined only if the
4882
  /// generic selection is not result-dependent.
4883
55
  const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); }
4884
524
  Expr *getResultExpr() { return getAssocExpr(getResultIndex()); }
4885
4886
373
  SourceLocation getBeginLoc() const LLVM_READONLY { return GenericLoc; }
4887
33
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4888
4889
349M
  static bool classof(const Stmt *T) {
4890
349M
    return T->getStmtClass() == GenericSelectionExprClass;
4891
349M
  }
4892
4893
7
  child_range children() {
4894
7
    return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs);
4895
7
  }
4896
0
  const_child_range children() const {
4897
0
    return const_child_range(SubExprs, SubExprs + END_EXPR + NumAssocs);
4898
0
  }
4899
  friend class ASTStmtReader;
4900
};
4901
4902
//===----------------------------------------------------------------------===//
4903
// Clang Extensions
4904
//===----------------------------------------------------------------------===//
4905
4906
/// ExtVectorElementExpr - This represents access to specific elements of a
4907
/// vector, and may occur on the left hand side or right hand side.  For example
4908
/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
4909
///
4910
/// Note that the base may have either vector or pointer to vector type, just
4911
/// like a struct field reference.
4912
///
4913
class ExtVectorElementExpr : public Expr {
4914
  Stmt *Base;
4915
  IdentifierInfo *Accessor;
4916
  SourceLocation AccessorLoc;
4917
public:
4918
  ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base,
4919
                       IdentifierInfo &accessor, SourceLocation loc)
4920
    : Expr(ExtVectorElementExprClass, ty, VK,
4921
           (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent),
4922
           base->isTypeDependent(), base->isValueDependent(),
4923
           base->isInstantiationDependent(),
4924
           base->containsUnexpandedParameterPack()),
4925
402
      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
4926
4927
  /// Build an empty vector element expression.
4928
  explicit ExtVectorElementExpr(EmptyShell Empty)
4929
15
    : Expr(ExtVectorElementExprClass, Empty) { }
4930
4931
4.27k
  const Expr *getBase() const { return cast<Expr>(Base); }
4932
29
  Expr *getBase() { return cast<Expr>(Base); }
4933
15
  void setBase(Expr *E) { Base = E; }
4934
4935
57
  IdentifierInfo &getAccessor() const { return *Accessor; }
4936
15
  void setAccessor(IdentifierInfo *II) { Accessor = II; }
4937
4938
17
  SourceLocation getAccessorLoc() const { return AccessorLoc; }
4939
15
  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
4940
4941
  /// getNumElements - Get the number of components being selected.
4942
  unsigned getNumElements() const;
4943
4944
  /// containsDuplicateElements - Return true if any element access is
4945
  /// repeated.
4946
  bool containsDuplicateElements() const;
4947
4948
  /// getEncodedElementAccess - Encode the elements accessed into an llvm
4949
  /// aggregate Constant of ConstantInt(s).
4950
  void getEncodedElementAccess(SmallVectorImpl<uint32_t> &Elts) const;
4951
4952
3.27k
  SourceLocation getBeginLoc() const LLVM_READONLY {
4953
3.27k
    return getBase()->getBeginLoc();
4954
3.27k
  }
4955
52
  SourceLocation getEndLoc() const LLVM_READONLY { return AccessorLoc; }
4956
4957
  /// isArrow - Return true if the base expression is a pointer to vector,
4958
  /// return false if the base expression is a vector.
4959
  bool isArrow() const;
4960
4961
706k
  static bool classof(const Stmt *T) {
4962
706k
    return T->getStmtClass() == ExtVectorElementExprClass;
4963
706k
  }
4964
4965
  // Iterators
4966
1.01k
  child_range children() { return child_range(&Base, &Base+1); }
4967
0
  const_child_range children() const {
4968
0
    return const_child_range(&Base, &Base + 1);
4969
0
  }
4970
};
4971
4972
/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
4973
/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
4974
class BlockExpr : public Expr {
4975
protected:
4976
  BlockDecl *TheBlock;
4977
public:
4978
  BlockExpr(BlockDecl *BD, QualType ty)
4979
    : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary,
4980
           ty->isDependentType(), ty->isDependentType(),
4981
           ty->isInstantiationDependentType() || BD->isDependentContext(),
4982
           false),
4983
2.58k
      TheBlock(BD) {}
4984
4985
  /// Build an empty block expression.
4986
11
  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
4987
4988
4.92k
  const BlockDecl *getBlockDecl() const { return TheBlock; }
4989
12.4k
  BlockDecl *getBlockDecl() { return TheBlock; }
4990
11
  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
4991
4992
  // Convenience functions for probing the underlying BlockDecl.
4993
  SourceLocation getCaretLocation() const;
4994
  const Stmt *getBody() const;
4995
  Stmt *getBody();
4996
4997
20.1k
  SourceLocation getBeginLoc() const LLVM_READONLY {
4998
20.1k
    return getCaretLocation();
4999
20.1k
  }
5000
3.39k
  SourceLocation getEndLoc() const LLVM_READONLY {
5001
3.39k
    return getBody()->getEndLoc();
5002
3.39k
  }
5003
5004
  /// getFunctionType - Return the underlying function type for this block.
5005
  const FunctionProtoType *getFunctionType() const;
5006
5007
19.2k
  static bool classof(const Stmt *T) {
5008
19.2k
    return T->getStmtClass() == BlockExprClass;
5009
19.2k
  }
5010
5011
  // Iterators
5012
4.22k
  child_range children() {
5013
4.22k
    return child_range(child_iterator(), child_iterator());
5014
4.22k
  }
5015
0
  const_child_range children() const {
5016
0
    return const_child_range(const_child_iterator(), const_child_iterator());
5017
0
  }
5018
};
5019
5020
/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2]
5021
/// This AST node provides support for reinterpreting a type to another
5022
/// type of the same size.
5023
class AsTypeExpr : public Expr {
5024
private:
5025
  Stmt *SrcExpr;
5026
  SourceLocation BuiltinLoc, RParenLoc;
5027
5028
  friend class ASTReader;
5029
  friend class ASTStmtReader;
5030
0
  explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {}
5031
5032
public:
5033
  AsTypeExpr(Expr* SrcExpr, QualType DstType,
5034
             ExprValueKind VK, ExprObjectKind OK,
5035
             SourceLocation BuiltinLoc, SourceLocation RParenLoc)
5036
    : Expr(AsTypeExprClass, DstType, VK, OK,
5037
           DstType->isDependentType(),
5038
           DstType->isDependentType() || SrcExpr->isValueDependent(),
5039
           (DstType->isInstantiationDependentType() ||
5040
            SrcExpr->isInstantiationDependent()),
5041
           (DstType->containsUnexpandedParameterPack() ||
5042
            SrcExpr->containsUnexpandedParameterPack())),
5043
20
  SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {}
5044
5045
  /// getSrcExpr - Return the Expr to be converted.
5046
17
  Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
5047
5048
  /// getBuiltinLoc - Return the location of the __builtin_astype token.
5049
0
  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
5050
5051
  /// getRParenLoc - Return the location of final right parenthesis.
5052
0
  SourceLocation getRParenLoc() const { return RParenLoc; }
5053
5054
158
  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
5055
0
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
5056
5057
  static bool classof(const Stmt *T) {
5058
    return T->getStmtClass() == AsTypeExprClass;
5059
  }
5060
5061
  // Iterators
5062
72
  child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
5063
0
  const_child_range children() const {
5064
0
    return const_child_range(&SrcExpr, &SrcExpr + 1);
5065
0
  }
5066
};
5067
5068
/// PseudoObjectExpr - An expression which accesses a pseudo-object
5069
/// l-value.  A pseudo-object is an abstract object, accesses to which
5070
/// are translated to calls.  The pseudo-object expression has a
5071
/// syntactic form, which shows how the expression was actually
5072
/// written in the source code, and a semantic form, which is a series
5073
/// of expressions to be executed in order which detail how the
5074
/// operation is actually evaluated.  Optionally, one of the semantic
5075
/// forms may also provide a result value for the expression.
5076
///
5077
/// If any of the semantic-form expressions is an OpaqueValueExpr,
5078
/// that OVE is required to have a source expression, and it is bound
5079
/// to the result of that source expression.  Such OVEs may appear
5080
/// only in subsequent semantic-form expressions and as
5081
/// sub-expressions of the syntactic form.
5082
///
5083
/// PseudoObjectExpr should be used only when an operation can be
5084
/// usefully described in terms of fairly simple rewrite rules on
5085
/// objects and functions that are meant to be used by end-developers.
5086
/// For example, under the Itanium ABI, dynamic casts are implemented
5087
/// as a call to a runtime function called __dynamic_cast; using this
5088
/// class to describe that would be inappropriate because that call is
5089
/// not really part of the user-visible semantics, and instead the
5090
/// cast is properly reflected in the AST and IR-generation has been
5091
/// taught to generate the call as necessary.  In contrast, an
5092
/// Objective-C property access is semantically defined to be
5093
/// equivalent to a particular message send, and this is very much
5094
/// part of the user model.  The name of this class encourages this
5095
/// modelling design.
5096
class PseudoObjectExpr final
5097
    : public Expr,
5098
      private llvm::TrailingObjects<PseudoObjectExpr, Expr *> {
5099
  // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions.
5100
  // Always at least two, because the first sub-expression is the
5101
  // syntactic form.
5102
5103
  // PseudoObjectExprBits.ResultIndex - The index of the
5104
  // sub-expression holding the result.  0 means the result is void,
5105
  // which is unambiguous because it's the index of the syntactic
5106
  // form.  Note that this is therefore 1 higher than the value passed
5107
  // in to Create, which is an index within the semantic forms.
5108
  // Note also that ASTStmtWriter assumes this encoding.
5109
5110
24.5k
  Expr **getSubExprsBuffer() { return getTrailingObjects<Expr *>(); }
5111
25.3k
  const Expr * const *getSubExprsBuffer() const {
5112
25.3k
    return getTrailingObjects<Expr *>();
5113
25.3k
  }
5114
5115
  PseudoObjectExpr(QualType type, ExprValueKind VK,
5116
                   Expr *syntactic, ArrayRef<Expr*> semantic,
5117
                   unsigned resultIndex);
5118
5119
  PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs);
5120
5121
10.8k
  unsigned getNumSubExprs() const {
5122
10.8k
    return PseudoObjectExprBits.NumSubExprs;
5123
10.8k
  }
5124
5125
public:
5126
  /// NoResult - A value for the result index indicating that there is
5127
  /// no semantic result.
5128
  enum : unsigned { NoResult = ~0U };
5129
5130
  static PseudoObjectExpr *Create(const ASTContext &Context, Expr *syntactic,
5131
                                  ArrayRef<Expr*> semantic,
5132
                                  unsigned resultIndex);
5133
5134
  static PseudoObjectExpr *Create(const ASTContext &Context, EmptyShell shell,
5135
                                  unsigned numSemanticExprs);
5136
5137
  /// Return the syntactic form of this expression, i.e. the
5138
  /// expression it actually looks like.  Likely to be expressed in
5139
  /// terms of OpaqueValueExprs bound in the semantic form.
5140
3.52k
  Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; }
5141
19.3k
  const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; }
5142
5143
  /// Return the index of the result-bearing expression into the semantics
5144
  /// expressions, or PseudoObjectExpr::NoResult if there is none.
5145
31
  unsigned getResultExprIndex() const {
5146
31
    if (PseudoObjectExprBits.ResultIndex == 0) 
return NoResult3
;
5147
28
    return PseudoObjectExprBits.ResultIndex - 1;
5148
28
  }
5149
5150
  /// Return the result-bearing expression, or null if there is none.
5151
1.09k
  Expr *getResultExpr() {
5152
1.09k
    if (PseudoObjectExprBits.ResultIndex == 0)
5153
14
      return nullptr;
5154
1.08k
    return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex];
5155
1.08k
  }
5156
672
  const Expr *getResultExpr() const {
5157
672
    return const_cast<PseudoObjectExpr*>(this)->getResultExpr();
5158
672
  }
5159
5160
990
  unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; }
5161
5162
  typedef Expr * const *semantics_iterator;
5163
  typedef const Expr * const *const_semantics_iterator;
5164
4.24k
  semantics_iterator semantics_begin() {
5165
4.24k
    return getSubExprsBuffer() + 1;
5166
4.24k
  }
5167
392
  const_semantics_iterator semantics_begin() const {
5168
392
    return getSubExprsBuffer() + 1;
5169
392
  }
5170
4.24k
  semantics_iterator semantics_end() {
5171
4.24k
    return getSubExprsBuffer() + getNumSubExprs();
5172
4.24k
  }
5173
392
  const_semantics_iterator semantics_end() const {
5174
392
    return getSubExprsBuffer() + getNumSubExprs();
5175
392
  }
5176
5177
2.42k
  llvm::iterator_range<semantics_iterator> semantics() {
5178
2.42k
    return llvm::make_range(semantics_begin(), semantics_end());
5179
2.42k
  }
5180
0
  llvm::iterator_range<const_semantics_iterator> semantics() const {
5181
0
    return llvm::make_range(semantics_begin(), semantics_end());
5182
0
  }
5183
5184
2.25k
  Expr *getSemanticExpr(unsigned index) {
5185
2.25k
    assert(index + 1 < getNumSubExprs());
5186
2.25k
    return getSubExprsBuffer()[index + 1];
5187
2.25k
  }
5188
24
  const Expr *getSemanticExpr(unsigned index) const {
5189
24
    return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index);
5190
24
  }
5191
5192
6.62k
  SourceLocation getExprLoc() const LLVM_READONLY {
5193
6.62k
    return getSyntacticForm()->getExprLoc();
5194
6.62k
  }
5195
5196
8.57k
  SourceLocation getBeginLoc() const LLVM_READONLY {
5197
8.57k
    return getSyntacticForm()->getBeginLoc();
5198
8.57k
  }
5199
1.81k
  SourceLocation getEndLoc() const LLVM_READONLY {
5200
1.81k
    return getSyntacticForm()->getEndLoc();
5201
1.81k
  }
5202
5203
5.24k
  child_range children() {
5204
5.24k
    const_child_range CCR =
5205
5.24k
        const_cast<const PseudoObjectExpr *>(this)->children();
5206
5.24k
    return child_range(cast_away_const(CCR.begin()),
5207
5.24k
                       cast_away_const(CCR.end()));
5208
5.24k
  }
5209
5.24k
  const_child_range children() const {
5210
5.24k
    Stmt *const *cs = const_cast<Stmt *const *>(
5211
5.24k
        reinterpret_cast<const Stmt *const *>(getSubExprsBuffer()));
5212
5.24k
    return const_child_range(cs, cs + getNumSubExprs());
5213
5.24k
  }
5214
5215
35.3M
  static bool classof(const Stmt *T) {
5216
35.3M
    return T->getStmtClass() == PseudoObjectExprClass;
5217
35.3M
  }
5218
5219
  friend TrailingObjects;
5220
  friend class ASTStmtReader;
5221
};
5222
5223
/// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*,
5224
/// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the
5225
/// similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>,
5226
/// and corresponding __opencl_atomic_* for OpenCL 2.0.
5227
/// All of these instructions take one primary pointer, at least one memory
5228
/// order. The instructions for which getScopeModel returns non-null value
5229
/// take one synch scope.
5230
class AtomicExpr : public Expr {
5231
public:
5232
  enum AtomicOp {
5233
#define BUILTIN(ID, TYPE, ATTRS)
5234
#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID,
5235
#include "clang/Basic/Builtins.def"
5236
    // Avoid trailing comma
5237
    BI_First = 0
5238
  };
5239
5240
private:
5241
  /// Location of sub-expressions.
5242
  /// The location of Scope sub-expression is NumSubExprs - 1, which is
5243
  /// not fixed, therefore is not defined in enum.
5244
  enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR };
5245
  Stmt *SubExprs[END_EXPR + 1];
5246
  unsigned NumSubExprs;
5247
  SourceLocation BuiltinLoc, RParenLoc;
5248
  AtomicOp Op;
5249
5250
  friend class ASTStmtReader;
5251
public:
5252
  AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, QualType t,
5253
             AtomicOp op, SourceLocation RP);
5254
5255
  /// Determine the number of arguments the specified atomic builtin
5256
  /// should have.
5257
  static unsigned getNumSubExprs(AtomicOp Op);
5258
5259
  /// Build an empty AtomicExpr.
5260
120
  explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { }
5261
5262
2.43k
  Expr *getPtr() const {
5263
2.43k
    return cast<Expr>(SubExprs[PTR]);
5264
2.43k
  }
5265
657
  Expr *getOrder() const {
5266
657
    return cast<Expr>(SubExprs[ORDER]);
5267
657
  }
5268
73
  Expr *getScope() const {
5269
73
    assert(getScopeModel() && "No scope");
5270
73
    return cast<Expr>(SubExprs[NumSubExprs - 1]);
5271
73
  }
5272
623
  Expr *getVal1() const {
5273
623
    if (Op == AO__c11_atomic_init || 
Op == AO__opencl_atomic_init608
)
5274
17
      return cast<Expr>(SubExprs[ORDER]);
5275
606
    assert(NumSubExprs > VAL1);
5276
606
    return cast<Expr>(SubExprs[VAL1]);
5277
606
  }
5278
69
  Expr *getOrderFail() const {
5279
69
    assert(NumSubExprs > ORDER_FAIL);
5280
69
    return cast<Expr>(SubExprs[ORDER_FAIL]);
5281
69
  }
5282
83
  Expr *getVal2() const {
5283
83
    if (Op == AO__atomic_exchange)
5284
14
      return cast<Expr>(SubExprs[ORDER_FAIL]);
5285
69
    assert(NumSubExprs > VAL2);
5286
69
    return cast<Expr>(SubExprs[VAL2]);
5287
69
  }
5288
30
  Expr *getWeak() const {
5289
30
    assert(NumSubExprs > WEAK);
5290
30
    return cast<Expr>(SubExprs[WEAK]);
5291
30
  }
5292
  QualType getValueType() const;
5293
5294
13.6k
  AtomicOp getOp() const { return Op; }
5295
166
  unsigned getNumSubExprs() const { return NumSubExprs; }
5296
5297
441
  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
5298
117
  const Expr * const *getSubExprs() const {
5299
117
    return reinterpret_cast<Expr * const *>(SubExprs);
5300
117
  }
5301
5302
870
  bool isVolatile() const {
5303
870
    return getPtr()->getType()->getPointeeType().isVolatileQualified();
5304
870
  }
5305
5306
729
  bool isCmpXChg() const {
5307
729
    return getOp() == AO__c11_atomic_compare_exchange_strong ||
5308
729
           
getOp() == AO__c11_atomic_compare_exchange_weak706
||
5309
729
           
getOp() == AO__opencl_atomic_compare_exchange_strong704
||
5310
729
           
getOp() == AO__opencl_atomic_compare_exchange_weak694
||
5311
729
           
getOp() == AO__atomic_compare_exchange674
||
5312
729
           
getOp() == AO__atomic_compare_exchange_n643
;
5313
729
  }
5314
5315
475
  bool isOpenCL() const {
5316
475
    return getOp() >= AO__opencl_atomic_init &&
5317
475
           
getOp() <= AO__opencl_atomic_fetch_max92
;
5318
475
  }
5319
5320
124
  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
5321
124
  SourceLocation getRParenLoc() const { return RParenLoc; }
5322
5323
16.9k
  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
5324
547
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
5325
5326
835
  static bool classof(const Stmt *T) {
5327
835
    return T->getStmtClass() == AtomicExprClass;
5328
835
  }
5329
5330
  // Iterators
5331
8.82k
  child_range children() {
5332
8.82k
    return child_range(SubExprs, SubExprs+NumSubExprs);
5333
8.82k
  }
5334
0
  const_child_range children() const {
5335
0
    return const_child_range(SubExprs, SubExprs + NumSubExprs);
5336
0
  }
5337
5338
  /// Get atomic scope model for the atomic op code.
5339
  /// \return empty atomic scope model if the atomic op code does not have
5340
  ///   scope operand.
5341
5.40k
  static std::unique_ptr<AtomicScopeModel> getScopeModel(AtomicOp Op) {
5342
5.40k
    auto Kind =
5343
5.40k
        (Op >= AO__opencl_atomic_load && 
Op <= AO__opencl_atomic_fetch_max420
)
5344