Coverage Report

Created: 2021-01-26 06:56

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