Coverage Report

Created: 2020-02-25 14:32

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