Coverage Report

Created: 2021-09-21 08:58

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