Coverage Report

Created: 2020-09-19 12:23

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