Coverage Report

Created: 2019-07-24 05:18

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