Coverage Report

Created: 2020-09-22 08:39

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/ExprCXX.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ExprCXX.cpp - (C++) Expression AST Node Implementation -------------===//
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 implements the subclesses of Expr class declared in ExprCXX.h
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/AST/ExprCXX.h"
14
#include "clang/AST/ASTContext.h"
15
#include "clang/AST/Attr.h"
16
#include "clang/AST/ComputeDependence.h"
17
#include "clang/AST/Decl.h"
18
#include "clang/AST/DeclAccessPair.h"
19
#include "clang/AST/DeclBase.h"
20
#include "clang/AST/DeclCXX.h"
21
#include "clang/AST/DeclTemplate.h"
22
#include "clang/AST/DeclarationName.h"
23
#include "clang/AST/DependenceFlags.h"
24
#include "clang/AST/Expr.h"
25
#include "clang/AST/LambdaCapture.h"
26
#include "clang/AST/NestedNameSpecifier.h"
27
#include "clang/AST/TemplateBase.h"
28
#include "clang/AST/Type.h"
29
#include "clang/AST/TypeLoc.h"
30
#include "clang/Basic/LLVM.h"
31
#include "clang/Basic/OperatorKinds.h"
32
#include "clang/Basic/SourceLocation.h"
33
#include "clang/Basic/Specifiers.h"
34
#include "llvm/ADT/ArrayRef.h"
35
#include "llvm/Support/Casting.h"
36
#include "llvm/Support/ErrorHandling.h"
37
#include <cassert>
38
#include <cstddef>
39
#include <cstring>
40
#include <memory>
41
42
using namespace clang;
43
44
//===----------------------------------------------------------------------===//
45
//  Child Iterators for iterating over subexpressions/substatements
46
//===----------------------------------------------------------------------===//
47
48
358
bool CXXOperatorCallExpr::isInfixBinaryOp() const {
49
  // An infix binary operator is any operator with two arguments other than
50
  // operator() and operator[]. Note that none of these operators can have
51
  // default arguments, so it suffices to check the number of argument
52
  // expressions.
53
358
  if (getNumArgs() != 2)
54
0
    return false;
55
56
358
  switch (getOperator()) {
57
2
  case OO_Call: case OO_Subscript:
58
2
    return false;
59
356
  default:
60
356
    return true;
61
358
  }
62
358
}
63
64
CXXRewrittenBinaryOperator::DecomposedForm
65
752
CXXRewrittenBinaryOperator::getDecomposedForm() const {
66
752
  DecomposedForm Result = {};
67
752
  const Expr *E = getSemanticForm()->IgnoreImplicit();
68
69
  // Remove an outer '!' if it exists (only happens for a '!=' rewrite).
70
752
  bool SkippedNot = false;
71
752
  if (auto *NotEq = dyn_cast<UnaryOperator>(E)) {
72
76
    assert(NotEq->getOpcode() == UO_LNot);
73
76
    E = NotEq->getSubExpr()->IgnoreImplicit();
74
76
    SkippedNot = true;
75
76
  }
76
77
  // Decompose the outer binary operator.
78
752
  if (auto *BO = dyn_cast<BinaryOperator>(E)) {
79
401
    assert(!SkippedNot || BO->getOpcode() == BO_EQ);
80
401
    Result.Opcode = SkippedNot ? 
BO_NE0
: BO->getOpcode();
81
401
    Result.LHS = BO->getLHS();
82
401
    Result.RHS = BO->getRHS();
83
401
    Result.InnerBinOp = BO;
84
351
  } else if (auto *BO = dyn_cast<CXXOperatorCallExpr>(E)) {
85
351
    assert(!SkippedNot || BO->getOperator() == OO_EqualEqual);
86
351
    assert(BO->isInfixBinaryOp());
87
351
    switch (BO->getOperator()) {
88
66
    case OO_Less: Result.Opcode = BO_LT; break;
89
50
    case OO_LessEqual: Result.Opcode = BO_LE; break;
90
50
    case OO_Greater: Result.Opcode = BO_GT; break;
91
50
    case OO_GreaterEqual: Result.Opcode = BO_GE; break;
92
25
    case OO_Spaceship: Result.Opcode = BO_Cmp; break;
93
110
    case OO_EqualEqual: Result.Opcode = SkippedNot ? 
BO_NE76
:
BO_EQ34
; break;
94
0
    default: llvm_unreachable("unexpected binop in rewritten operator expr");
95
351
    }
96
351
    Result.LHS = BO->getArg(0);
97
351
    Result.RHS = BO->getArg(1);
98
351
    Result.InnerBinOp = BO;
99
0
  } else {
100
0
    llvm_unreachable("unexpected rewritten operator form");
101
0
  }
102
103
  // Put the operands in the right order for == and !=, and canonicalize the
104
  // <=> subexpression onto the LHS for all other forms.
105
752
  if (isReversed())
106
234
    std::swap(Result.LHS, Result.RHS);
107
108
  // If this isn't a spaceship rewrite, we're done.
109
752
  if (Result.Opcode == BO_EQ || 
Result.Opcode == BO_NE718
)
110
110
    return Result;
111
112
  // Otherwise, we expect a <=> to now be on the LHS.
113
642
  E = Result.LHS->IgnoreImplicitAsWritten();
114
642
  if (auto *BO = dyn_cast<BinaryOperator>(E)) {
115
0
    assert(BO->getOpcode() == BO_Cmp);
116
0
    Result.LHS = BO->getLHS();
117
0
    Result.RHS = BO->getRHS();
118
0
    Result.InnerBinOp = BO;
119
642
  } else if (auto *BO = dyn_cast<CXXOperatorCallExpr>(E)) {
120
642
    assert(BO->getOperator() == OO_Spaceship);
121
642
    Result.LHS = BO->getArg(0);
122
642
    Result.RHS = BO->getArg(1);
123
642
    Result.InnerBinOp = BO;
124
0
  } else {
125
0
    llvm_unreachable("unexpected rewritten operator form");
126
0
  }
127
128
  // Put the comparison operands in the right order.
129
642
  if (isReversed())
130
189
    std::swap(Result.LHS, Result.RHS);
131
642
  return Result;
132
642
}
133
134
3.60k
bool CXXTypeidExpr::isPotentiallyEvaluated() const {
135
3.60k
  if (isTypeOperand())
136
3.04k
    return false;
137
138
  // C++11 [expr.typeid]p3:
139
  //   When typeid is applied to an expression other than a glvalue of
140
  //   polymorphic class type, [...] the expression is an unevaluated operand.
141
557
  const Expr *E = getExprOperand();
142
557
  if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl())
143
243
    if (RD->isPolymorphic() && 
E->isGLValue()204
)
144
195
      return true;
145
146
362
  return false;
147
362
}
148
149
44
bool CXXTypeidExpr::isMostDerived(ASTContext &Context) const {
150
44
  assert(!isTypeOperand() && "Cannot call isMostDerived for typeid(type)");
151
44
  const Expr *E = getExprOperand()->IgnoreParenNoopCasts(Context);
152
44
  if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) {
153
10
    QualType Ty = DRE->getDecl()->getType();
154
10
    if (!Ty->isPointerType() && !Ty->isReferenceType())
155
6
      return true;
156
38
  }
157
158
38
  return false;
159
38
}
160
161
886
QualType CXXTypeidExpr::getTypeOperand(ASTContext &Context) const {
162
886
  assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
163
886
  Qualifiers Quals;
164
886
  return Context.getUnqualifiedArrayType(
165
886
      Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
166
886
}
167
168
0
QualType CXXUuidofExpr::getTypeOperand(ASTContext &Context) const {
169
0
  assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
170
0
  Qualifiers Quals;
171
0
  return Context.getUnqualifiedArrayType(
172
0
      Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
173
0
}
174
175
// CXXScalarValueInitExpr
176
39.1k
SourceLocation CXXScalarValueInitExpr::getBeginLoc() const {
177
38.9k
  return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : 
getRParenLoc()265
;
178
39.1k
}
179
180
// CXXNewExpr
181
CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
182
                       FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
183
                       bool UsualArrayDeleteWantsSize,
184
                       ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens,
185
                       Optional<Expr *> ArraySize,
186
                       InitializationStyle InitializationStyle,
187
                       Expr *Initializer, QualType Ty,
188
                       TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
189
                       SourceRange DirectInitRange)
190
    : Expr(CXXNewExprClass, Ty, VK_RValue, OK_Ordinary),
191
      OperatorNew(OperatorNew), OperatorDelete(OperatorDelete),
192
      AllocatedTypeInfo(AllocatedTypeInfo), Range(Range),
193
24.7k
      DirectInitRange(DirectInitRange) {
194
195
24.7k
  assert((Initializer != nullptr || InitializationStyle == NoInit) &&
196
24.7k
         "Only NoInit can have no initializer!");
197
198
24.7k
  CXXNewExprBits.IsGlobalNew = IsGlobalNew;
199
24.7k
  CXXNewExprBits.IsArray = ArraySize.hasValue();
200
24.7k
  CXXNewExprBits.ShouldPassAlignment = ShouldPassAlignment;
201
24.7k
  CXXNewExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize;
202
24.7k
  CXXNewExprBits.StoredInitializationStyle =
203
23.1k
      Initializer ? InitializationStyle + 1 : 
01.57k
;
204
24.7k
  bool IsParenTypeId = TypeIdParens.isValid();
205
24.7k
  CXXNewExprBits.IsParenTypeId = IsParenTypeId;
206
24.7k
  CXXNewExprBits.NumPlacementArgs = PlacementArgs.size();
207
208
24.7k
  if (ArraySize)
209
1.17k
    getTrailingObjects<Stmt *>()[arraySizeOffset()] = *ArraySize;
210
24.7k
  if (Initializer)
211
23.1k
    getTrailingObjects<Stmt *>()[initExprOffset()] = Initializer;
212
42.9k
  for (unsigned I = 0; I != PlacementArgs.size(); 
++I18.2k
)
213
18.2k
    getTrailingObjects<Stmt *>()[placementNewArgsOffset() + I] =
214
18.2k
        PlacementArgs[I];
215
24.7k
  if (IsParenTypeId)
216
34
    getTrailingObjects<SourceRange>()[0] = TypeIdParens;
217
218
24.7k
  switch (getInitializationStyle()) {
219
21.6k
  case CallInit:
220
21.6k
    this->Range.setEnd(DirectInitRange.getEnd());
221
21.6k
    break;
222
139
  case ListInit:
223
139
    this->Range.setEnd(getInitializer()->getSourceRange().getEnd());
224
139
    break;
225
2.91k
  default:
226
2.91k
    if (IsParenTypeId)
227
16
      this->Range.setEnd(TypeIdParens.getEnd());
228
2.91k
    break;
229
24.7k
  }
230
231
24.7k
  setDependence(computeDependence(this));
232
24.7k
}
233
234
CXXNewExpr::CXXNewExpr(EmptyShell Empty, bool IsArray,
235
                       unsigned NumPlacementArgs, bool IsParenTypeId)
236
212
    : Expr(CXXNewExprClass, Empty) {
237
212
  CXXNewExprBits.IsArray = IsArray;
238
212
  CXXNewExprBits.NumPlacementArgs = NumPlacementArgs;
239
212
  CXXNewExprBits.IsParenTypeId = IsParenTypeId;
240
212
}
241
242
CXXNewExpr *
243
CXXNewExpr::Create(const ASTContext &Ctx, bool IsGlobalNew,
244
                   FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete,
245
                   bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize,
246
                   ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens,
247
                   Optional<Expr *> ArraySize,
248
                   InitializationStyle InitializationStyle, Expr *Initializer,
249
                   QualType Ty, TypeSourceInfo *AllocatedTypeInfo,
250
24.7k
                   SourceRange Range, SourceRange DirectInitRange) {
251
24.7k
  bool IsArray = ArraySize.hasValue();
252
24.7k
  bool HasInit = Initializer != nullptr;
253
24.7k
  unsigned NumPlacementArgs = PlacementArgs.size();
254
24.7k
  bool IsParenTypeId = TypeIdParens.isValid();
255
24.7k
  void *Mem =
256
24.7k
      Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>(
257
24.7k
                       IsArray + HasInit + NumPlacementArgs, IsParenTypeId),
258
24.7k
                   alignof(CXXNewExpr));
259
24.7k
  return new (Mem)
260
24.7k
      CXXNewExpr(IsGlobalNew, OperatorNew, OperatorDelete, ShouldPassAlignment,
261
24.7k
                 UsualArrayDeleteWantsSize, PlacementArgs, TypeIdParens,
262
24.7k
                 ArraySize, InitializationStyle, Initializer, Ty,
263
24.7k
                 AllocatedTypeInfo, Range, DirectInitRange);
264
24.7k
}
265
266
CXXNewExpr *CXXNewExpr::CreateEmpty(const ASTContext &Ctx, bool IsArray,
267
                                    bool HasInit, unsigned NumPlacementArgs,
268
212
                                    bool IsParenTypeId) {
269
212
  void *Mem =
270
212
      Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>(
271
212
                       IsArray + HasInit + NumPlacementArgs, IsParenTypeId),
272
212
                   alignof(CXXNewExpr));
273
212
  return new (Mem)
274
212
      CXXNewExpr(EmptyShell(), IsArray, NumPlacementArgs, IsParenTypeId);
275
212
}
276
277
1.90k
bool CXXNewExpr::shouldNullCheckAllocation() const {
278
1.90k
  return getOperatorNew()
279
1.90k
             ->getType()
280
1.90k
             ->castAs<FunctionProtoType>()
281
1.90k
             ->isNothrow() &&
282
651
         !getOperatorNew()->isReservedGlobalPlacementOperator();
283
1.90k
}
284
285
// CXXDeleteExpr
286
2.09k
QualType CXXDeleteExpr::getDestroyedType() const {
287
2.09k
  const Expr *Arg = getArgument();
288
289
  // For a destroying operator delete, we may have implicitly converted the
290
  // pointer type to the type of the parameter of the 'operator delete'
291
  // function.
292
2.11k
  while (const auto *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
293
1.85k
    if (ICE->getCastKind() == CK_DerivedToBase ||
294
1.83k
        ICE->getCastKind() == CK_UncheckedDerivedToBase ||
295
1.83k
        ICE->getCastKind() == CK_NoOp) {
296
12
      assert((ICE->getCastKind() == CK_NoOp ||
297
12
              getOperatorDelete()->isDestroyingOperatorDelete()) &&
298
12
             "only a destroying operator delete can have a converted arg");
299
12
      Arg = ICE->getSubExpr();
300
12
    } else
301
1.83k
      break;
302
1.85k
  }
303
304
  // The type-to-delete may not be a pointer if it's a dependent type.
305
2.09k
  const QualType ArgType = Arg->getType();
306
307
2.09k
  if (ArgType->isDependentType() && 
!ArgType->isPointerType()3
)
308
2
    return QualType();
309
310
2.09k
  return ArgType->castAs<PointerType>()->getPointeeType();
311
2.09k
}
312
313
// CXXPseudoDestructorExpr
314
PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
315
7.88k
    : Type(Info) {
316
7.88k
  Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
317
7.88k
}
318
319
CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(
320
    const ASTContext &Context, Expr *Base, bool isArrow,
321
    SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
322
    TypeSourceInfo *ScopeType, SourceLocation ColonColonLoc,
323
    SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType)
324
    : Expr(CXXPseudoDestructorExprClass, Context.BoundMemberTy, VK_RValue,
325
           OK_Ordinary),
326
      Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
327
      OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
328
      ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
329
7.07k
      DestroyedType(DestroyedType) {
330
7.07k
  setDependence(computeDependence(this));
331
7.07k
}
332
333
18.6k
QualType CXXPseudoDestructorExpr::getDestroyedType() const {
334
18.6k
  if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
335
18.5k
    return TInfo->getType();
336
337
7
  return QualType();
338
7
}
339
340
360
SourceLocation CXXPseudoDestructorExpr::getEndLoc() const {
341
360
  SourceLocation End = DestroyedType.getLocation();
342
360
  if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
343
360
    End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
344
360
  return End;
345
360
}
346
347
// UnresolvedLookupExpr
348
UnresolvedLookupExpr::UnresolvedLookupExpr(
349
    const ASTContext &Context, CXXRecordDecl *NamingClass,
350
    NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
351
    const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
352
    const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
353
    UnresolvedSetIterator End)
354
    : OverloadExpr(UnresolvedLookupExprClass, Context, QualifierLoc,
355
                   TemplateKWLoc, NameInfo, TemplateArgs, Begin, End, false,
356
                   false, false),
357
2.20M
      NamingClass(NamingClass) {
358
2.20M
  UnresolvedLookupExprBits.RequiresADL = RequiresADL;
359
2.20M
  UnresolvedLookupExprBits.Overloaded = Overloaded;
360
2.20M
}
361
362
UnresolvedLookupExpr::UnresolvedLookupExpr(EmptyShell Empty,
363
                                           unsigned NumResults,
364
                                           bool HasTemplateKWAndArgsInfo)
365
    : OverloadExpr(UnresolvedLookupExprClass, Empty, NumResults,
366
30.9k
                   HasTemplateKWAndArgsInfo) {}
367
368
UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
369
    const ASTContext &Context, CXXRecordDecl *NamingClass,
370
    NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
371
    bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin,
372
1.86M
    UnresolvedSetIterator End) {
373
1.86M
  unsigned NumResults = End - Begin;
374
1.86M
  unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
375
1.86M
                                   TemplateArgumentLoc>(NumResults, 0, 0);
376
1.86M
  void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
377
1.86M
  return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
378
1.86M
                                        SourceLocation(), NameInfo, RequiresADL,
379
1.86M
                                        Overloaded, nullptr, Begin, End);
380
1.86M
}
381
382
UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
383
    const ASTContext &Context, CXXRecordDecl *NamingClass,
384
    NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
385
    const DeclarationNameInfo &NameInfo, bool RequiresADL,
386
    const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
387
341k
    UnresolvedSetIterator End) {
388
341k
  assert(Args || TemplateKWLoc.isValid());
389
341k
  unsigned NumResults = End - Begin;
390
341k
  unsigned NumTemplateArgs = Args ? Args->size() : 
014
;
391
341k
  unsigned Size =
392
341k
      totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
393
341k
                       TemplateArgumentLoc>(NumResults, 1, NumTemplateArgs);
394
341k
  void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
395
341k
  return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
396
341k
                                        TemplateKWLoc, NameInfo, RequiresADL,
397
341k
                                        /*Overloaded*/ true, Args, Begin, End);
398
341k
}
399
400
UnresolvedLookupExpr *UnresolvedLookupExpr::CreateEmpty(
401
    const ASTContext &Context, unsigned NumResults,
402
30.9k
    bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) {
403
30.9k
  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
404
30.9k
  unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
405
30.9k
                                   TemplateArgumentLoc>(
406
30.9k
      NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
407
30.9k
  void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
408
30.9k
  return new (Mem)
409
30.9k
      UnresolvedLookupExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo);
410
30.9k
}
411
412
OverloadExpr::OverloadExpr(StmtClass SC, const ASTContext &Context,
413
                           NestedNameSpecifierLoc QualifierLoc,
414
                           SourceLocation TemplateKWLoc,
415
                           const DeclarationNameInfo &NameInfo,
416
                           const TemplateArgumentListInfo *TemplateArgs,
417
                           UnresolvedSetIterator Begin,
418
                           UnresolvedSetIterator End, bool KnownDependent,
419
                           bool KnownInstantiationDependent,
420
                           bool KnownContainsUnexpandedParameterPack)
421
    : Expr(SC, Context.OverloadTy, VK_LValue, OK_Ordinary), NameInfo(NameInfo),
422
2.43M
      QualifierLoc(QualifierLoc) {
423
2.43M
  unsigned NumResults = End - Begin;
424
2.43M
  OverloadExprBits.NumResults = NumResults;
425
2.43M
  OverloadExprBits.HasTemplateKWAndArgsInfo =
426
2.43M
      (TemplateArgs != nullptr ) || 
TemplateKWLoc.isValid()2.09M
;
427
428
2.43M
  if (NumResults) {
429
    // Copy the results to the trailing array past UnresolvedLookupExpr
430
    // or UnresolvedMemberExpr.
431
2.37M
    DeclAccessPair *Results = getTrailingResults();
432
2.37M
    memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair));
433
2.37M
  }
434
435
2.43M
  if (TemplateArgs) {
436
344k
    auto Deps = TemplateArgumentDependence::None;
437
344k
    getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(
438
344k
        TemplateKWLoc, *TemplateArgs, getTrailingTemplateArgumentLoc(), Deps);
439
2.09M
  } else if (TemplateKWLoc.isValid()) {
440
56
    getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
441
56
  }
442
443
2.43M
  setDependence(computeDependence(this, KnownDependent,
444
2.43M
                                  KnownInstantiationDependent,
445
2.43M
                                  KnownContainsUnexpandedParameterPack));
446
2.43M
  if (isTypeDependent())
447
665k
    setType(Context.DependentTy);
448
2.43M
}
449
450
OverloadExpr::OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults,
451
                           bool HasTemplateKWAndArgsInfo)
452
33.9k
    : Expr(SC, Empty) {
453
33.9k
  OverloadExprBits.NumResults = NumResults;
454
33.9k
  OverloadExprBits.HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
455
33.9k
}
456
457
// DependentScopeDeclRefExpr
458
DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(
459
    QualType Ty, NestedNameSpecifierLoc QualifierLoc,
460
    SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
461
    const TemplateArgumentListInfo *Args)
462
    : Expr(DependentScopeDeclRefExprClass, Ty, VK_LValue, OK_Ordinary),
463
1.12M
      QualifierLoc(QualifierLoc), NameInfo(NameInfo) {
464
1.12M
  DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo =
465
1.12M
      (Args != nullptr) || 
TemplateKWLoc.isValid()1.08M
;
466
1.12M
  if (Args) {
467
34.1k
    auto Deps = TemplateArgumentDependence::None;
468
34.1k
    getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
469
34.1k
        TemplateKWLoc, *Args, getTrailingObjects<TemplateArgumentLoc>(), Deps);
470
1.08M
  } else if (TemplateKWLoc.isValid()) {
471
9
    getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
472
9
        TemplateKWLoc);
473
9
  }
474
1.12M
  setDependence(computeDependence(this));
475
1.12M
}
476
477
DependentScopeDeclRefExpr *DependentScopeDeclRefExpr::Create(
478
    const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
479
    SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
480
936k
    const TemplateArgumentListInfo *Args) {
481
936k
  assert(QualifierLoc && "should be created for dependent qualifiers");
482
936k
  bool HasTemplateKWAndArgsInfo = Args || 
TemplateKWLoc.isValid()902k
;
483
936k
  std::size_t Size =
484
936k
      totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
485
902k
          HasTemplateKWAndArgsInfo, Args ? 
Args->size()34.1k
: 0);
486
936k
  void *Mem = Context.Allocate(Size);
487
936k
  return new (Mem) DependentScopeDeclRefExpr(Context.DependentTy, QualifierLoc,
488
936k
                                             TemplateKWLoc, NameInfo, Args);
489
936k
}
490
491
DependentScopeDeclRefExpr *
492
DependentScopeDeclRefExpr::CreateEmpty(const ASTContext &Context,
493
                                       bool HasTemplateKWAndArgsInfo,
494
185k
                                       unsigned NumTemplateArgs) {
495
185k
  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
496
185k
  std::size_t Size =
497
185k
      totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
498
185k
          HasTemplateKWAndArgsInfo, NumTemplateArgs);
499
185k
  void *Mem = Context.Allocate(Size);
500
185k
  auto *E = new (Mem) DependentScopeDeclRefExpr(
501
185k
      QualType(), NestedNameSpecifierLoc(), SourceLocation(),
502
185k
      DeclarationNameInfo(), nullptr);
503
185k
  E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo =
504
185k
      HasTemplateKWAndArgsInfo;
505
185k
  return E;
506
185k
}
507
508
1.04M
SourceLocation CXXConstructExpr::getBeginLoc() const {
509
1.04M
  if (isa<CXXTemporaryObjectExpr>(this))
510
3.58k
    return cast<CXXTemporaryObjectExpr>(this)->getBeginLoc();
511
1.03M
  return getLocation();
512
1.03M
}
513
514
312k
SourceLocation CXXConstructExpr::getEndLoc() const {
515
312k
  if (isa<CXXTemporaryObjectExpr>(this))
516
0
    return cast<CXXTemporaryObjectExpr>(this)->getEndLoc();
517
518
312k
  if (ParenOrBraceRange.isValid())
519
60.7k
    return ParenOrBraceRange.getEnd();
520
521
252k
  SourceLocation End = getLocation();
522
259k
  for (unsigned I = getNumArgs(); I > 0; 
--I7.52k
) {
523
225k
    const Expr *Arg = getArg(I-1);
524
225k
    if (!Arg->isDefaultArgument()) {
525
217k
      SourceLocation NewEnd = Arg->getEndLoc();
526
217k
      if (NewEnd.isValid()) {
527
217k
        End = NewEnd;
528
217k
        break;
529
217k
      }
530
217k
    }
531
225k
  }
532
533
252k
  return End;
534
252k
}
535
536
CXXOperatorCallExpr::CXXOperatorCallExpr(OverloadedOperatorKind OpKind,
537
                                         Expr *Fn, ArrayRef<Expr *> Args,
538
                                         QualType Ty, ExprValueKind VK,
539
                                         SourceLocation OperatorLoc,
540
                                         FPOptionsOverride FPFeatures,
541
                                         ADLCallKind UsesADL)
542
    : CallExpr(CXXOperatorCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
543
735k
               OperatorLoc, FPFeatures, /*MinNumArgs=*/0, UsesADL) {
544
735k
  CXXOperatorCallExprBits.OperatorKind = OpKind;
545
735k
  assert(
546
735k
      (CXXOperatorCallExprBits.OperatorKind == static_cast<unsigned>(OpKind)) &&
547
735k
      "OperatorKind overflow!");
548
735k
  Range = getSourceRangeImpl();
549
735k
}
550
551
CXXOperatorCallExpr::CXXOperatorCallExpr(unsigned NumArgs, bool HasFPFeatures,
552
                                         EmptyShell Empty)
553
    : CallExpr(CXXOperatorCallExprClass, /*NumPreArgs=*/0, NumArgs,
554
18.2k
               HasFPFeatures, Empty) {}
555
556
CXXOperatorCallExpr *
557
CXXOperatorCallExpr::Create(const ASTContext &Ctx,
558
                            OverloadedOperatorKind OpKind, Expr *Fn,
559
                            ArrayRef<Expr *> Args, QualType Ty,
560
                            ExprValueKind VK, SourceLocation OperatorLoc,
561
735k
                            FPOptionsOverride FPFeatures, ADLCallKind UsesADL) {
562
  // Allocate storage for the trailing objects of CallExpr.
563
735k
  unsigned NumArgs = Args.size();
564
735k
  unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
565
735k
      /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
566
735k
  void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects,
567
735k
                           alignof(CXXOperatorCallExpr));
568
735k
  return new (Mem) CXXOperatorCallExpr(OpKind, Fn, Args, Ty, VK, OperatorLoc,
569
735k
                                       FPFeatures, UsesADL);
570
735k
}
571
572
CXXOperatorCallExpr *CXXOperatorCallExpr::CreateEmpty(const ASTContext &Ctx,
573
                                                      unsigned NumArgs,
574
                                                      bool HasFPFeatures,
575
18.2k
                                                      EmptyShell Empty) {
576
  // Allocate storage for the trailing objects of CallExpr.
577
18.2k
  unsigned SizeOfTrailingObjects =
578
18.2k
      CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, HasFPFeatures);
579
18.2k
  void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects,
580
18.2k
                           alignof(CXXOperatorCallExpr));
581
18.2k
  return new (Mem) CXXOperatorCallExpr(NumArgs, HasFPFeatures, Empty);
582
18.2k
}
583
584
735k
SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
585
735k
  OverloadedOperatorKind Kind = getOperator();
586
735k
  if (Kind == OO_PlusPlus || 
Kind == OO_MinusMinus728k
) {
587
7.74k
    if (getNumArgs() == 1)
588
      // Prefix operator
589
7.52k
      return SourceRange(getOperatorLoc(), getArg(0)->getEndLoc());
590
220
    else
591
      // Postfix operator
592
220
      return SourceRange(getArg(0)->getBeginLoc(), getOperatorLoc());
593
727k
  } else if (Kind == OO_Arrow) {
594
1.47k
    return SourceRange(getArg(0)->getBeginLoc(), getOperatorLoc());
595
725k
  } else if (Kind == OO_Call) {
596
22.0k
    return SourceRange(getArg(0)->getBeginLoc(), getRParenLoc());
597
703k
  } else if (Kind == OO_Subscript) {
598
2.64k
    return SourceRange(getArg(0)->getBeginLoc(), getRParenLoc());
599
701k
  } else if (getNumArgs() == 1) {
600
21.9k
    return SourceRange(getOperatorLoc(), getArg(0)->getEndLoc());
601
679k
  } else if (getNumArgs() == 2) {
602
679k
    return SourceRange(getArg(0)->getBeginLoc(), getArg(1)->getEndLoc());
603
0
  } else {
604
0
    return getOperatorLoc();
605
0
  }
606
735k
}
607
608
CXXMemberCallExpr::CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args,
609
                                     QualType Ty, ExprValueKind VK,
610
                                     SourceLocation RP,
611
                                     FPOptionsOverride FPOptions,
612
                                     unsigned MinNumArgs)
613
    : CallExpr(CXXMemberCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, RP,
614
180k
               FPOptions, MinNumArgs, NotADL) {}
615
616
CXXMemberCallExpr::CXXMemberCallExpr(unsigned NumArgs, bool HasFPFeatures,
617
                                     EmptyShell Empty)
618
    : CallExpr(CXXMemberCallExprClass, /*NumPreArgs=*/0, NumArgs, HasFPFeatures,
619
4.95k
               Empty) {}
620
621
CXXMemberCallExpr *CXXMemberCallExpr::Create(const ASTContext &Ctx, Expr *Fn,
622
                                             ArrayRef<Expr *> Args, QualType Ty,
623
                                             ExprValueKind VK,
624
                                             SourceLocation RP,
625
                                             FPOptionsOverride FPFeatures,
626
180k
                                             unsigned MinNumArgs) {
627
  // Allocate storage for the trailing objects of CallExpr.
628
180k
  unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
629
180k
  unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
630
180k
      /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
631
180k
  void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects,
632
180k
                           alignof(CXXMemberCallExpr));
633
180k
  return new (Mem)
634
180k
      CXXMemberCallExpr(Fn, Args, Ty, VK, RP, FPFeatures, MinNumArgs);
635
180k
}
636
637
CXXMemberCallExpr *CXXMemberCallExpr::CreateEmpty(const ASTContext &Ctx,
638
                                                  unsigned NumArgs,
639
                                                  bool HasFPFeatures,
640
4.95k
                                                  EmptyShell Empty) {
641
  // Allocate storage for the trailing objects of CallExpr.
642
4.95k
  unsigned SizeOfTrailingObjects =
643
4.95k
      CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, HasFPFeatures);
644
4.95k
  void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects,
645
4.95k
                           alignof(CXXMemberCallExpr));
646
4.95k
  return new (Mem) CXXMemberCallExpr(NumArgs, HasFPFeatures, Empty);
647
4.95k
}
648
649
338k
Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
650
338k
  const Expr *Callee = getCallee()->IgnoreParens();
651
338k
  if (const auto *MemExpr = dyn_cast<MemberExpr>(Callee))
652
338k
    return MemExpr->getBase();
653
61
  if (const auto *BO = dyn_cast<BinaryOperator>(Callee))
654
61
    if (BO->getOpcode() == BO_PtrMemD || 
BO->getOpcode() == BO_PtrMemI46
)
655
61
      return BO->getLHS();
656
657
  // FIXME: Will eventually need to cope with member pointers.
658
0
  return nullptr;
659
0
}
660
661
12
QualType CXXMemberCallExpr::getObjectType() const {
662
12
  QualType Ty = getImplicitObjectArgument()->getType();
663
12
  if (Ty->isPointerType())
664
10
    Ty = Ty->getPointeeType();
665
12
  return Ty;
666
12
}
667
668
364k
CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
669
364k
  if (const auto *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
670
364k
    return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
671
672
  // FIXME: Will eventually need to cope with member pointers.
673
4
  return nullptr;
674
4
}
675
676
0
CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
677
0
  Expr* ThisArg = getImplicitObjectArgument();
678
0
  if (!ThisArg)
679
0
    return nullptr;
680
681
0
  if (ThisArg->getType()->isAnyPointerType())
682
0
    return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
683
684
0
  return ThisArg->getType()->getAsCXXRecordDecl();
685
0
}
686
687
//===----------------------------------------------------------------------===//
688
//  Named casts
689
//===----------------------------------------------------------------------===//
690
691
/// getCastName - Get the name of the C++ cast being used, e.g.,
692
/// "static_cast", "dynamic_cast", "reinterpret_cast", or
693
/// "const_cast". The returned pointer must not be freed.
694
68
const char *CXXNamedCastExpr::getCastName() const {
695
68
  switch (getStmtClass()) {
696
36
  case CXXStaticCastExprClass:      return "static_cast";
697
9
  case CXXDynamicCastExprClass:     return "dynamic_cast";
698
13
  case CXXReinterpretCastExprClass: return "reinterpret_cast";
699
9
  case CXXConstCastExprClass:       return "const_cast";
700
1
  case CXXAddrspaceCastExprClass:   return "addrspace_cast";
701
0
  default:                          return "<invalid cast>";
702
68
  }
703
68
}
704
705
CXXStaticCastExpr *
706
CXXStaticCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK,
707
                          CastKind K, Expr *Op, const CXXCastPath *BasePath,
708
                          TypeSourceInfo *WrittenTy, FPOptionsOverride FPO,
709
                          SourceLocation L, SourceLocation RParenLoc,
710
163k
                          SourceRange AngleBrackets) {
711
163k
  unsigned PathSize = (BasePath ? BasePath->size() : 
00
);
712
163k
  void *Buffer =
713
163k
      C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
714
163k
          PathSize, FPO.requiresTrailingStorage()));
715
163k
  auto *E = new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy,
716
163k
                                           FPO, L, RParenLoc, AngleBrackets);
717
163k
  if (PathSize)
718
876
    std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
719
876
                              E->getTrailingObjects<CXXBaseSpecifier *>());
720
163k
  return E;
721
163k
}
722
723
CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(const ASTContext &C,
724
                                                  unsigned PathSize,
725
3.35k
                                                  bool HasFPFeatures) {
726
3.35k
  void *Buffer =
727
3.35k
      C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
728
3.35k
          PathSize, HasFPFeatures));
729
3.35k
  return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize, HasFPFeatures);
730
3.35k
}
731
732
CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T,
733
                                               ExprValueKind VK,
734
                                               CastKind K, Expr *Op,
735
                                               const CXXCastPath *BasePath,
736
                                               TypeSourceInfo *WrittenTy,
737
                                               SourceLocation L,
738
                                               SourceLocation RParenLoc,
739
1.14k
                                               SourceRange AngleBrackets) {
740
1.14k
  unsigned PathSize = (BasePath ? BasePath->size() : 
00
);
741
1.14k
  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
742
1.14k
  auto *E =
743
1.14k
      new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
744
1.14k
                                      RParenLoc, AngleBrackets);
745
1.14k
  if (PathSize)
746
59
    std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
747
59
                              E->getTrailingObjects<CXXBaseSpecifier *>());
748
1.14k
  return E;
749
1.14k
}
750
751
CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(const ASTContext &C,
752
3
                                                    unsigned PathSize) {
753
3
  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
754
3
  return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
755
3
}
756
757
/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
758
/// to always be null. For example:
759
///
760
/// struct A { };
761
/// struct B final : A { };
762
/// struct C { };
763
///
764
/// C *f(B* b) { return dynamic_cast<C*>(b); }
765
bool CXXDynamicCastExpr::isAlwaysNull() const
766
77
{
767
77
  QualType SrcType = getSubExpr()->getType();
768
77
  QualType DestType = getType();
769
770
77
  if (const auto *SrcPTy = SrcType->getAs<PointerType>()) {
771
64
    SrcType = SrcPTy->getPointeeType();
772
64
    DestType = DestType->castAs<PointerType>()->getPointeeType();
773
64
  }
774
775
77
  if (DestType->isVoidType())
776
6
    return false;
777
778
71
  const auto *SrcRD =
779
71
      cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
780
781
71
  if (!SrcRD->hasAttr<FinalAttr>())
782
69
    return false;
783
784
2
  const auto *DestRD =
785
2
      cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
786
787
2
  return !DestRD->isDerivedFrom(SrcRD);
788
2
}
789
790
CXXReinterpretCastExpr *
791
CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T,
792
                               ExprValueKind VK, CastKind K, Expr *Op,
793
                               const CXXCastPath *BasePath,
794
                               TypeSourceInfo *WrittenTy, SourceLocation L,
795
                               SourceLocation RParenLoc,
796
6.14k
                               SourceRange AngleBrackets) {
797
6.12k
  unsigned PathSize = (BasePath ? 
BasePath->size()21
: 0);
798
6.14k
  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
799
6.14k
  auto *E =
800
6.14k
      new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
801
6.14k
                                          RParenLoc, AngleBrackets);
802
6.14k
  if (PathSize)
803
0
    std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
804
0
                              E->getTrailingObjects<CXXBaseSpecifier *>());
805
6.14k
  return E;
806
6.14k
}
807
808
CXXReinterpretCastExpr *
809
38
CXXReinterpretCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) {
810
38
  void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
811
38
  return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
812
38
}
813
814
CXXConstCastExpr *CXXConstCastExpr::Create(const ASTContext &C, QualType T,
815
                                           ExprValueKind VK, Expr *Op,
816
                                           TypeSourceInfo *WrittenTy,
817
                                           SourceLocation L,
818
                                           SourceLocation RParenLoc,
819
5.20k
                                           SourceRange AngleBrackets) {
820
5.20k
  return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets);
821
5.20k
}
822
823
152
CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(const ASTContext &C) {
824
152
  return new (C) CXXConstCastExpr(EmptyShell());
825
152
}
826
827
CXXAddrspaceCastExpr *
828
CXXAddrspaceCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK,
829
                             CastKind K, Expr *Op, TypeSourceInfo *WrittenTy,
830
                             SourceLocation L, SourceLocation RParenLoc,
831
10
                             SourceRange AngleBrackets) {
832
10
  return new (C) CXXAddrspaceCastExpr(T, VK, K, Op, WrittenTy, L, RParenLoc,
833
10
                                      AngleBrackets);
834
10
}
835
836
0
CXXAddrspaceCastExpr *CXXAddrspaceCastExpr::CreateEmpty(const ASTContext &C) {
837
0
  return new (C) CXXAddrspaceCastExpr(EmptyShell());
838
0
}
839
840
CXXFunctionalCastExpr *CXXFunctionalCastExpr::Create(
841
    const ASTContext &C, QualType T, ExprValueKind VK, TypeSourceInfo *Written,
842
    CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO,
843
68.4k
    SourceLocation L, SourceLocation R) {
844
60.9k
  unsigned PathSize = (BasePath ? BasePath->size() : 
07.43k
);
845
68.4k
  void *Buffer =
846
68.4k
      C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
847
68.4k
          PathSize, FPO.requiresTrailingStorage()));
848
68.4k
  auto *E = new (Buffer)
849
68.4k
      CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, FPO, L, R);
850
68.4k
  if (PathSize)
851
9
    std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
852
9
                              E->getTrailingObjects<CXXBaseSpecifier *>());
853
68.4k
  return E;
854
68.4k
}
855
856
CXXFunctionalCastExpr *CXXFunctionalCastExpr::CreateEmpty(const ASTContext &C,
857
                                                          unsigned PathSize,
858
2.12k
                                                          bool HasFPFeatures) {
859
2.12k
  void *Buffer =
860
2.12k
      C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
861
2.12k
          PathSize, HasFPFeatures));
862
2.12k
  return new (Buffer)
863
2.12k
      CXXFunctionalCastExpr(EmptyShell(), PathSize, HasFPFeatures);
864
2.12k
}
865
866
463k
SourceLocation CXXFunctionalCastExpr::getBeginLoc() const {
867
463k
  return getTypeInfoAsWritten()->getTypeLoc().getBeginLoc();
868
463k
}
869
870
94.5k
SourceLocation CXXFunctionalCastExpr::getEndLoc() const {
871
93.1k
  return RParenLoc.isValid() ? RParenLoc : 
getSubExpr()->getEndLoc()1.38k
;
872
94.5k
}
873
874
UserDefinedLiteral::UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args,
875
                                       QualType Ty, ExprValueKind VK,
876
                                       SourceLocation LitEndLoc,
877
                                       SourceLocation SuffixLoc,
878
                                       FPOptionsOverride FPFeatures)
879
    : CallExpr(UserDefinedLiteralClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
880
               LitEndLoc, FPFeatures, /*MinNumArgs=*/0, NotADL),
881
262
      UDSuffixLoc(SuffixLoc) {}
882
883
UserDefinedLiteral::UserDefinedLiteral(unsigned NumArgs, bool HasFPFeatures,
884
                                       EmptyShell Empty)
885
    : CallExpr(UserDefinedLiteralClass, /*NumPreArgs=*/0, NumArgs,
886
2
               HasFPFeatures, Empty) {}
887
888
UserDefinedLiteral *UserDefinedLiteral::Create(const ASTContext &Ctx, Expr *Fn,
889
                                               ArrayRef<Expr *> Args,
890
                                               QualType Ty, ExprValueKind VK,
891
                                               SourceLocation LitEndLoc,
892
                                               SourceLocation SuffixLoc,
893
262
                                               FPOptionsOverride FPFeatures) {
894
  // Allocate storage for the trailing objects of CallExpr.
895
262
  unsigned NumArgs = Args.size();
896
262
  unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
897
262
      /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
898
262
  void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects,
899
262
                           alignof(UserDefinedLiteral));
900
262
  return new (Mem)
901
262
      UserDefinedLiteral(Fn, Args, Ty, VK, LitEndLoc, SuffixLoc, FPFeatures);
902
262
}
903
904
UserDefinedLiteral *UserDefinedLiteral::CreateEmpty(const ASTContext &Ctx,
905
                                                    unsigned NumArgs,
906
                                                    bool HasFPOptions,
907
2
                                                    EmptyShell Empty) {
908
  // Allocate storage for the trailing objects of CallExpr.
909
2
  unsigned SizeOfTrailingObjects =
910
2
      CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, HasFPOptions);
911
2
  void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects,
912
2
                           alignof(UserDefinedLiteral));
913
2
  return new (Mem) UserDefinedLiteral(NumArgs, HasFPOptions, Empty);
914
2
}
915
916
UserDefinedLiteral::LiteralOperatorKind
917
8.70k
UserDefinedLiteral::getLiteralOperatorKind() const {
918
8.70k
  if (getNumArgs() == 0)
919
618
    return LOK_Template;
920
8.08k
  if (getNumArgs() == 2)
921
2.23k
    return LOK_String;
922
923
5.84k
  assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
924
5.84k
  QualType ParamTy =
925
5.84k
    cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
926
5.84k
  if (ParamTy->isPointerType())
927
628
    return LOK_Raw;
928
5.21k
  if (ParamTy->isAnyCharacterType())
929
1.73k
    return LOK_Character;
930
3.48k
  if (ParamTy->isIntegerType())
931
1.76k
    return LOK_Integer;
932
1.71k
  if (ParamTy->isFloatingType())
933
1.71k
    return LOK_Floating;
934
935
0
  llvm_unreachable("unknown kind of literal operator");
936
0
}
937
938
9
Expr *UserDefinedLiteral::getCookedLiteral() {
939
9
#ifndef NDEBUG
940
9
  LiteralOperatorKind LOK = getLiteralOperatorKind();
941
9
  assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
942
9
#endif
943
9
  return getArg(0);
944
9
}
945
946
14
const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const {
947
14
  return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
948
14
}
949
950
CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &Ctx,
951
                                       SourceLocation Loc, FieldDecl *Field,
952
                                       QualType Ty, DeclContext *UsedContext)
953
    : Expr(CXXDefaultInitExprClass, Ty.getNonLValueExprType(Ctx),
954
           Ty->isLValueReferenceType()
955
               ? VK_LValue
956
               : Ty->isRValueReferenceType() ? VK_XValue : VK_RValue,
957
           /*FIXME*/ OK_Ordinary),
958
1.94k
      Field(Field), UsedContext(UsedContext) {
959
1.94k
  CXXDefaultInitExprBits.Loc = Loc;
960
1.94k
  assert(Field->hasInClassInitializer());
961
962
1.94k
  setDependence(computeDependence(this));
963
1.94k
}
964
965
CXXTemporary *CXXTemporary::Create(const ASTContext &C,
966
36.4k
                                   const CXXDestructorDecl *Destructor) {
967
36.4k
  return new (C) CXXTemporary(Destructor);
968
36.4k
}
969
970
CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(const ASTContext &C,
971
                                                   CXXTemporary *Temp,
972
34.6k
                                                   Expr* SubExpr) {
973
34.6k
  assert((SubExpr->getType()->isRecordType() ||
974
34.6k
          SubExpr->getType()->isArrayType()) &&
975
34.6k
         "Expression bound to a temporary must have record or array type!");
976
977
34.6k
  return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
978
34.6k
}
979
980
CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(
981
    CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI,
982
    ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange,
983
    bool HadMultipleCandidates, bool ListInitialization,
984
    bool StdInitListInitialization, bool ZeroInitialization)
985
    : CXXConstructExpr(
986
          CXXTemporaryObjectExprClass, Ty, TSI->getTypeLoc().getBeginLoc(),
987
          Cons, /* Elidable=*/false, Args, HadMultipleCandidates,
988
          ListInitialization, StdInitListInitialization, ZeroInitialization,
989
          CXXConstructExpr::CK_Complete, ParenOrBraceRange),
990
57.8k
      TSI(TSI) {}
991
992
CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(EmptyShell Empty,
993
                                               unsigned NumArgs)
994
1.33k
    : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty, NumArgs) {}
995
996
CXXTemporaryObjectExpr *CXXTemporaryObjectExpr::Create(
997
    const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty,
998
    TypeSourceInfo *TSI, ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange,
999
    bool HadMultipleCandidates, bool ListInitialization,
1000
57.8k
    bool StdInitListInitialization, bool ZeroInitialization) {
1001
57.8k
  unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size());
1002
57.8k
  void *Mem =
1003
57.8k
      Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects,
1004
57.8k
                   alignof(CXXTemporaryObjectExpr));
1005
57.8k
  return new (Mem) CXXTemporaryObjectExpr(
1006
57.8k
      Cons, Ty, TSI, Args, ParenOrBraceRange, HadMultipleCandidates,
1007
57.8k
      ListInitialization, StdInitListInitialization, ZeroInitialization);
1008
57.8k
}
1009
1010
CXXTemporaryObjectExpr *
1011
1.33k
CXXTemporaryObjectExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs) {
1012
1.33k
  unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs);
1013
1.33k
  void *Mem =
1014
1.33k
      Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects,
1015
1.33k
                   alignof(CXXTemporaryObjectExpr));
1016
1.33k
  return new (Mem) CXXTemporaryObjectExpr(EmptyShell(), NumArgs);
1017
1.33k
}
1018
1019
689k
SourceLocation CXXTemporaryObjectExpr::getBeginLoc() const {
1020
689k
  return getTypeSourceInfo()->getTypeLoc().getBeginLoc();
1021
689k
}
1022
1023
48.9k
SourceLocation CXXTemporaryObjectExpr::getEndLoc() const {
1024
48.9k
  SourceLocation Loc = getParenOrBraceRange().getEnd();
1025
48.9k
  if (Loc.isInvalid() && 
getNumArgs()0
)
1026
0
    Loc = getArg(getNumArgs() - 1)->getEndLoc();
1027
48.9k
  return Loc;
1028
48.9k
}
1029
1030
CXXConstructExpr *CXXConstructExpr::Create(
1031
    const ASTContext &Ctx, QualType Ty, SourceLocation Loc,
1032
    CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args,
1033
    bool HadMultipleCandidates, bool ListInitialization,
1034
    bool StdInitListInitialization, bool ZeroInitialization,
1035
269k
    ConstructionKind ConstructKind, SourceRange ParenOrBraceRange) {
1036
269k
  unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size());
1037
269k
  void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects,
1038
269k
                           alignof(CXXConstructExpr));
1039
269k
  return new (Mem) CXXConstructExpr(
1040
269k
      CXXConstructExprClass, Ty, Loc, Ctor, Elidable, Args,
1041
269k
      HadMultipleCandidates, ListInitialization, StdInitListInitialization,
1042
269k
      ZeroInitialization, ConstructKind, ParenOrBraceRange);
1043
269k
}
1044
1045
CXXConstructExpr *CXXConstructExpr::CreateEmpty(const ASTContext &Ctx,
1046
8.19k
                                                unsigned NumArgs) {
1047
8.19k
  unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs);
1048
8.19k
  void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects,
1049
8.19k
                           alignof(CXXConstructExpr));
1050
8.19k
  return new (Mem)
1051
8.19k
      CXXConstructExpr(CXXConstructExprClass, EmptyShell(), NumArgs);
1052
8.19k
}
1053
1054
CXXConstructExpr::CXXConstructExpr(
1055
    StmtClass SC, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor,
1056
    bool Elidable, ArrayRef<Expr *> Args, bool HadMultipleCandidates,
1057
    bool ListInitialization, bool StdInitListInitialization,
1058
    bool ZeroInitialization, ConstructionKind ConstructKind,
1059
    SourceRange ParenOrBraceRange)
1060
    : Expr(SC, Ty, VK_RValue, OK_Ordinary), Constructor(Ctor),
1061
327k
      ParenOrBraceRange(ParenOrBraceRange), NumArgs(Args.size()) {
1062
327k
  CXXConstructExprBits.Elidable = Elidable;
1063
327k
  CXXConstructExprBits.HadMultipleCandidates = HadMultipleCandidates;
1064
327k
  CXXConstructExprBits.ListInitialization = ListInitialization;
1065
327k
  CXXConstructExprBits.StdInitListInitialization = StdInitListInitialization;
1066
327k
  CXXConstructExprBits.ZeroInitialization = ZeroInitialization;
1067
327k
  CXXConstructExprBits.ConstructionKind = ConstructKind;
1068
327k
  CXXConstructExprBits.Loc = Loc;
1069
1070
327k
  Stmt **TrailingArgs = getTrailingArgs();
1071
566k
  for (unsigned I = 0, N = Args.size(); I != N; 
++I239k
) {
1072
239k
    assert(Args[I] && "NULL argument in CXXConstructExpr!");
1073
239k
    TrailingArgs[I] = Args[I];
1074
239k
  }
1075
1076
327k
  setDependence(computeDependence(this));
1077
327k
}
1078
1079
CXXConstructExpr::CXXConstructExpr(StmtClass SC, EmptyShell Empty,
1080
                                   unsigned NumArgs)
1081
9.52k
    : Expr(SC, Empty), NumArgs(NumArgs) {}
1082
1083
LambdaCapture::LambdaCapture(SourceLocation Loc, bool Implicit,
1084
                             LambdaCaptureKind Kind, VarDecl *Var,
1085
                             SourceLocation EllipsisLoc)
1086
6.24k
    : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) {
1087
6.24k
  unsigned Bits = 0;
1088
6.24k
  if (Implicit)
1089
4.46k
    Bits |= Capture_Implicit;
1090
1091
6.24k
  switch (Kind) {
1092
130
  case LCK_StarThis:
1093
130
    Bits |= Capture_ByCopy;
1094
130
    LLVM_FALLTHROUGH;
1095
740
  case LCK_This:
1096
740
    assert(!Var && "'this' capture cannot have a variable!");
1097
740
    Bits |= Capture_This;
1098
740
    break;
1099
1100
1.31k
  case LCK_ByCopy:
1101
1.31k
    Bits |= Capture_ByCopy;
1102
1.31k
    LLVM_FALLTHROUGH;
1103
5.45k
  case LCK_ByRef:
1104
5.45k
    assert(Var && "capture must have a variable!");
1105
5.45k
    break;
1106
47
  case LCK_VLAType:
1107
47
    assert(!Var && "VLA type capture cannot have a variable!");
1108
47
    break;
1109
6.24k
  }
1110
6.24k
  DeclAndBits.setInt(Bits);
1111
6.24k
}
1112
1113
3.67k
LambdaCaptureKind LambdaCapture::getCaptureKind() const {
1114
3.67k
  if (capturesVLAType())
1115
2
    return LCK_VLAType;
1116
3.67k
  bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy;
1117
3.67k
  if (capturesThis())
1118
585
    return CapByCopy ? 
LCK_StarThis75
:
LCK_This510
;
1119
3.09k
  return CapByCopy ? 
LCK_ByCopy643
:
LCK_ByRef2.44k
;
1120
3.09k
}
1121
1122
LambdaExpr::LambdaExpr(QualType T, SourceRange IntroducerRange,
1123
                       LambdaCaptureDefault CaptureDefault,
1124
                       SourceLocation CaptureDefaultLoc, bool ExplicitParams,
1125
                       bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1126
                       SourceLocation ClosingBrace,
1127
                       bool ContainsUnexpandedParameterPack)
1128
    : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary),
1129
      IntroducerRange(IntroducerRange), CaptureDefaultLoc(CaptureDefaultLoc),
1130
7.35k
      ClosingBrace(ClosingBrace) {
1131
7.35k
  LambdaExprBits.NumCaptures = CaptureInits.size();
1132
7.35k
  LambdaExprBits.CaptureDefault = CaptureDefault;
1133
7.35k
  LambdaExprBits.ExplicitParams = ExplicitParams;
1134
7.35k
  LambdaExprBits.ExplicitResultType = ExplicitResultType;
1135
1136
7.35k
  CXXRecordDecl *Class = getLambdaClass();
1137
7.35k
  (void)Class;
1138
7.35k
  assert(capture_size() == Class->capture_size() && "Wrong number of captures");
1139
7.35k
  assert(getCaptureDefault() == Class->getLambdaCaptureDefault());
1140
1141
  // Copy initialization expressions for the non-static data members.
1142
7.35k
  Stmt **Stored = getStoredStmts();
1143
12.4k
  for (unsigned I = 0, N = CaptureInits.size(); I != N; 
++I5.14k
)
1144
5.14k
    *Stored++ = CaptureInits[I];
1145
1146
  // Copy the body of the lambda.
1147
7.35k
  *Stored++ = getCallOperator()->getBody();
1148
1149
7.35k
  setDependence(computeDependence(this, ContainsUnexpandedParameterPack));
1150
7.35k
}
1151
1152
LambdaExpr::LambdaExpr(EmptyShell Empty, unsigned NumCaptures)
1153
560
    : Expr(LambdaExprClass, Empty) {
1154
560
  LambdaExprBits.NumCaptures = NumCaptures;
1155
1156
  // Initially don't initialize the body of the LambdaExpr. The body will
1157
  // be lazily deserialized when needed.
1158
560
  getStoredStmts()[NumCaptures] = nullptr; // Not one past the end.
1159
560
}
1160
1161
LambdaExpr *LambdaExpr::Create(const ASTContext &Context, CXXRecordDecl *Class,
1162
                               SourceRange IntroducerRange,
1163
                               LambdaCaptureDefault CaptureDefault,
1164
                               SourceLocation CaptureDefaultLoc,
1165
                               bool ExplicitParams, bool ExplicitResultType,
1166
                               ArrayRef<Expr *> CaptureInits,
1167
                               SourceLocation ClosingBrace,
1168
7.35k
                               bool ContainsUnexpandedParameterPack) {
1169
  // Determine the type of the expression (i.e., the type of the
1170
  // function object we're creating).
1171
7.35k
  QualType T = Context.getTypeDeclType(Class);
1172
1173
7.35k
  unsigned Size = totalSizeToAlloc<Stmt *>(CaptureInits.size() + 1);
1174
7.35k
  void *Mem = Context.Allocate(Size);
1175
7.35k
  return new (Mem)
1176
7.35k
      LambdaExpr(T, IntroducerRange, CaptureDefault, CaptureDefaultLoc,
1177
7.35k
                 ExplicitParams, ExplicitResultType, CaptureInits, ClosingBrace,
1178
7.35k
                 ContainsUnexpandedParameterPack);
1179
7.35k
}
1180
1181
LambdaExpr *LambdaExpr::CreateDeserialized(const ASTContext &C,
1182
560
                                           unsigned NumCaptures) {
1183
560
  unsigned Size = totalSizeToAlloc<Stmt *>(NumCaptures + 1);
1184
560
  void *Mem = C.Allocate(Size);
1185
560
  return new (Mem) LambdaExpr(EmptyShell(), NumCaptures);
1186
560
}
1187
1188
9.99k
void LambdaExpr::initBodyIfNeeded() const {
1189
9.99k
  if (!getStoredStmts()[capture_size()]) {
1190
124
    auto *This = const_cast<LambdaExpr *>(this);
1191
124
    This->getStoredStmts()[capture_size()] = getCallOperator()->getBody();
1192
124
  }
1193
9.99k
}
1194
1195
2.70k
Stmt *LambdaExpr::getBody() const {
1196
2.70k
  initBodyIfNeeded();
1197
2.70k
  return getStoredStmts()[capture_size()];
1198
2.70k
}
1199
1200
138
const CompoundStmt *LambdaExpr::getCompoundStmtBody() const {
1201
138
  Stmt *Body = getBody();
1202
138
  if (const auto *CoroBody = dyn_cast<CoroutineBodyStmt>(Body))
1203
0
    return cast<CompoundStmt>(CoroBody->getBody());
1204
138
  return cast<CompoundStmt>(Body);
1205
138
}
1206
1207
1.18k
bool LambdaExpr::isInitCapture(const LambdaCapture *C) const {
1208
1.18k
  return (C->capturesVariable() && 
C->getCapturedVar()->isInitCapture()1.03k
&&
1209
433
          (getCallOperator() == C->getCapturedVar()->getDeclContext()));
1210
1.18k
}
1211
1212
9.96k
LambdaExpr::capture_iterator LambdaExpr::capture_begin() const {
1213
9.96k
  return getLambdaClass()->getLambdaData().Captures;
1214
9.96k
}
1215
1216
3.46k
LambdaExpr::capture_iterator LambdaExpr::capture_end() const {
1217
3.46k
  return capture_begin() + capture_size();
1218
3.46k
}
1219
1220
94
LambdaExpr::capture_range LambdaExpr::captures() const {
1221
94
  return capture_range(capture_begin(), capture_end());
1222
94
}
1223
1224
2.20k
LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const {
1225
2.20k
  return capture_begin();
1226
2.20k
}
1227
1228
2.20k
LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const {
1229
2.20k
  struct CXXRecordDecl::LambdaDefinitionData &Data
1230
2.20k
    = getLambdaClass()->getLambdaData();
1231
2.20k
  return Data.Captures + Data.NumExplicitCaptures;
1232
2.20k
}
1233
1234
0
LambdaExpr::capture_range LambdaExpr::explicit_captures() const {
1235
0
  return capture_range(explicit_capture_begin(), explicit_capture_end());
1236
0
}
1237
1238
0
LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const {
1239
0
  return explicit_capture_end();
1240
0
}
1241
1242
0
LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const {
1243
0
  return capture_end();
1244
0
}
1245
1246
0
LambdaExpr::capture_range LambdaExpr::implicit_captures() const {
1247
0
  return capture_range(implicit_capture_begin(), implicit_capture_end());
1248
0
}
1249
1250
46.0k
CXXRecordDecl *LambdaExpr::getLambdaClass() const {
1251
46.0k
  return getType()->getAsCXXRecordDecl();
1252
46.0k
}
1253
1254
19.6k
CXXMethodDecl *LambdaExpr::getCallOperator() const {
1255
19.6k
  CXXRecordDecl *Record = getLambdaClass();
1256
19.6k
  return Record->getLambdaCallOperator();
1257
19.6k
}
1258
1259
220
FunctionTemplateDecl *LambdaExpr::getDependentCallOperator() const {
1260
220
  CXXRecordDecl *Record = getLambdaClass();
1261
220
  return Record->getDependentLambdaCallOperator();
1262
220
}
1263
1264
1.67k
TemplateParameterList *LambdaExpr::getTemplateParameterList() const {
1265
1.67k
  CXXRecordDecl *Record = getLambdaClass();
1266
1.67k
  return Record->getGenericLambdaTemplateParameterList();
1267
1.67k
}
1268
1269
598
ArrayRef<NamedDecl *> LambdaExpr::getExplicitTemplateParameters() const {
1270
598
  const CXXRecordDecl *Record = getLambdaClass();
1271
598
  return Record->getLambdaExplicitTemplateParameters();
1272
598
}
1273
1274
1.64k
bool LambdaExpr::isMutable() const { return !getCallOperator()->isConst(); }
1275
1276
7.28k
LambdaExpr::child_range LambdaExpr::children() {
1277
7.28k
  initBodyIfNeeded();
1278
7.28k
  return child_range(getStoredStmts(), getStoredStmts() + capture_size() + 1);
1279
7.28k
}
1280
1281
0
LambdaExpr::const_child_range LambdaExpr::children() const {
1282
0
  initBodyIfNeeded();
1283
0
  return const_child_range(getStoredStmts(),
1284
0
                           getStoredStmts() + capture_size() + 1);
1285
0
}
1286
1287
ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
1288
                                   bool CleanupsHaveSideEffects,
1289
                                   ArrayRef<CleanupObject> objects)
1290
104k
    : FullExpr(ExprWithCleanupsClass, subexpr) {
1291
104k
  ExprWithCleanupsBits.CleanupsHaveSideEffects = CleanupsHaveSideEffects;
1292
104k
  ExprWithCleanupsBits.NumObjects = objects.size();
1293
105k
  for (unsigned i = 0, e = objects.size(); i != e; 
++i1.43k
)
1294
1.43k
    getTrailingObjects<CleanupObject>()[i] = objects[i];
1295
104k
}
1296
1297
ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, Expr *subexpr,
1298
                                           bool CleanupsHaveSideEffects,
1299
104k
                                           ArrayRef<CleanupObject> objects) {
1300
104k
  void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(objects.size()),
1301
104k
                            alignof(ExprWithCleanups));
1302
104k
  return new (buffer)
1303
104k
      ExprWithCleanups(subexpr, CleanupsHaveSideEffects, objects);
1304
104k
}
1305
1306
ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
1307
1.91k
    : FullExpr(ExprWithCleanupsClass, empty) {
1308
1.91k
  ExprWithCleanupsBits.NumObjects = numObjects;
1309
1.91k
}
1310
1311
ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C,
1312
                                           EmptyShell empty,
1313
1.91k
                                           unsigned numObjects) {
1314
1.91k
  void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(numObjects),
1315
1.91k
                            alignof(ExprWithCleanups));
1316
1.91k
  return new (buffer) ExprWithCleanups(empty, numObjects);
1317
1.91k
}
1318
1319
CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *TSI,
1320
                                                       SourceLocation LParenLoc,
1321
                                                       ArrayRef<Expr *> Args,
1322
                                                       SourceLocation RParenLoc)
1323
    : Expr(CXXUnresolvedConstructExprClass,
1324
           TSI->getType().getNonReferenceType(),
1325
           (TSI->getType()->isLValueReferenceType()
1326
                ? VK_LValue
1327
                : TSI->getType()->isRValueReferenceType() ? VK_XValue
1328
                                                          : VK_RValue),
1329
           OK_Ordinary),
1330
232k
      TSI(TSI), LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
1331
232k
  CXXUnresolvedConstructExprBits.NumArgs = Args.size();
1332
232k
  auto **StoredArgs = getTrailingObjects<Expr *>();
1333
398k
  for (unsigned I = 0; I != Args.size(); 
++I166k
)
1334
166k
    StoredArgs[I] = Args[I];
1335
232k
  setDependence(computeDependence(this));
1336
232k
}
1337
1338
CXXUnresolvedConstructExpr *CXXUnresolvedConstructExpr::Create(
1339
    const ASTContext &Context, TypeSourceInfo *TSI, SourceLocation LParenLoc,
1340
232k
    ArrayRef<Expr *> Args, SourceLocation RParenLoc) {
1341
232k
  void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(Args.size()));
1342
232k
  return new (Mem) CXXUnresolvedConstructExpr(TSI, LParenLoc, Args, RParenLoc);
1343
232k
}
1344
1345
CXXUnresolvedConstructExpr *
1346
CXXUnresolvedConstructExpr::CreateEmpty(const ASTContext &Context,
1347
7.32k
                                        unsigned NumArgs) {
1348
7.32k
  void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(NumArgs));
1349
7.32k
  return new (Mem) CXXUnresolvedConstructExpr(EmptyShell(), NumArgs);
1350
7.32k
}
1351
1352
88.9k
SourceLocation CXXUnresolvedConstructExpr::getBeginLoc() const {
1353
88.9k
  return TSI->getTypeLoc().getBeginLoc();
1354
88.9k
}
1355
1356
CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
1357
    const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
1358
    SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1359
    SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1360
    DeclarationNameInfo MemberNameInfo,
1361
    const TemplateArgumentListInfo *TemplateArgs)
1362
    : Expr(CXXDependentScopeMemberExprClass, Ctx.DependentTy, VK_LValue,
1363
           OK_Ordinary),
1364
      Base(Base), BaseType(BaseType), QualifierLoc(QualifierLoc),
1365
894k
      MemberNameInfo(MemberNameInfo) {
1366
894k
  CXXDependentScopeMemberExprBits.IsArrow = IsArrow;
1367
894k
  CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo =
1368
894k
      (TemplateArgs != nullptr) || 
TemplateKWLoc.isValid()892k
;
1369
894k
  CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope =
1370
894k
      FirstQualifierFoundInScope != nullptr;
1371
894k
  CXXDependentScopeMemberExprBits.OperatorLoc = OperatorLoc;
1372
1373
894k
  if (TemplateArgs) {
1374
2.17k
    auto Deps = TemplateArgumentDependence::None;
1375
2.17k
    getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1376
2.17k
        TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
1377
2.17k
        Deps);
1378
892k
  } else if (TemplateKWLoc.isValid()) {
1379
30
    getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1380
30
        TemplateKWLoc);
1381
30
  }
1382
1383
894k
  if (hasFirstQualifierFoundInScope())
1384
54
    *getTrailingObjects<NamedDecl *>() = FirstQualifierFoundInScope;
1385
894k
  setDependence(computeDependence(this));
1386
894k
}
1387
1388
CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
1389
    EmptyShell Empty, bool HasTemplateKWAndArgsInfo,
1390
    bool HasFirstQualifierFoundInScope)
1391
29.9k
    : Expr(CXXDependentScopeMemberExprClass, Empty) {
1392
29.9k
  CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo =
1393
29.9k
      HasTemplateKWAndArgsInfo;
1394
29.9k
  CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope =
1395
29.9k
      HasFirstQualifierFoundInScope;
1396
29.9k
}
1397
1398
CXXDependentScopeMemberExpr *CXXDependentScopeMemberExpr::Create(
1399
    const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
1400
    SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1401
    SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1402
    DeclarationNameInfo MemberNameInfo,
1403
894k
    const TemplateArgumentListInfo *TemplateArgs) {
1404
894k
  bool HasTemplateKWAndArgsInfo =
1405
894k
      (TemplateArgs != nullptr) || 
TemplateKWLoc.isValid()892k
;
1406
892k
  unsigned NumTemplateArgs = TemplateArgs ? 
TemplateArgs->size()2.17k
: 0;
1407
894k
  bool HasFirstQualifierFoundInScope = FirstQualifierFoundInScope != nullptr;
1408
1409
894k
  unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo,
1410
894k
                                   TemplateArgumentLoc, NamedDecl *>(
1411
894k
      HasTemplateKWAndArgsInfo, NumTemplateArgs, HasFirstQualifierFoundInScope);
1412
1413
894k
  void *Mem = Ctx.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
1414
894k
  return new (Mem) CXXDependentScopeMemberExpr(
1415
894k
      Ctx, Base, BaseType, IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
1416
894k
      FirstQualifierFoundInScope, MemberNameInfo, TemplateArgs);
1417
894k
}
1418
1419
CXXDependentScopeMemberExpr *CXXDependentScopeMemberExpr::CreateEmpty(
1420
    const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo,
1421
29.9k
    unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope) {
1422
29.9k
  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
1423
1424
29.9k
  unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo,
1425
29.9k
                                   TemplateArgumentLoc, NamedDecl *>(
1426
29.9k
      HasTemplateKWAndArgsInfo, NumTemplateArgs, HasFirstQualifierFoundInScope);
1427
1428
29.9k
  void *Mem = Ctx.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
1429
29.9k
  return new (Mem) CXXDependentScopeMemberExpr(
1430
29.9k
      EmptyShell(), HasTemplateKWAndArgsInfo, HasFirstQualifierFoundInScope);
1431
29.9k
}
1432
1433
static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
1434
229k
                                            UnresolvedSetIterator end) {
1435
649k
  do {
1436
649k
    NamedDecl *decl = *begin;
1437
649k
    if (isa<UnresolvedUsingValueDecl>(decl))
1438
56
      return false;
1439
1440
    // Unresolved member expressions should only contain methods and
1441
    // method templates.
1442
649k
    if (cast<CXXMethodDecl>(decl->getUnderlyingDecl()->getAsFunction())
1443
649k
            ->isStatic())
1444
5.58k
      return false;
1445
643k
  } while (++begin != end);
1446
1447
223k
  return true;
1448
229k
}
1449
1450
UnresolvedMemberExpr::UnresolvedMemberExpr(
1451
    const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
1452
    QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
1453
    NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1454
    const DeclarationNameInfo &MemberNameInfo,
1455
    const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
1456
    UnresolvedSetIterator End)
1457
    : OverloadExpr(
1458
          UnresolvedMemberExprClass, Context, QualifierLoc, TemplateKWLoc,
1459
          MemberNameInfo, TemplateArgs, Begin, End,
1460
          // Dependent
1461
          ((Base && Base->isTypeDependent()) || BaseType->isDependentType()),
1462
          ((Base && Base->isInstantiationDependent()) ||
1463
           BaseType->isInstantiationDependentType()),
1464
          // Contains unexpanded parameter pack
1465
          ((Base && Base->containsUnexpandedParameterPack()) ||
1466
           BaseType->containsUnexpandedParameterPack())),
1467
229k
      Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
1468
229k
  UnresolvedMemberExprBits.IsArrow = IsArrow;
1469
229k
  UnresolvedMemberExprBits.HasUnresolvedUsing = HasUnresolvedUsing;
1470
1471
  // Check whether all of the members are non-static member functions,
1472
  // and if so, mark give this bound-member type instead of overload type.
1473
229k
  if (hasOnlyNonStaticMemberFunctions(Begin, End))
1474
223k
    setType(Context.BoundMemberTy);
1475
229k
}
1476
1477
UnresolvedMemberExpr::UnresolvedMemberExpr(EmptyShell Empty,
1478
                                           unsigned NumResults,
1479
                                           bool HasTemplateKWAndArgsInfo)
1480
    : OverloadExpr(UnresolvedMemberExprClass, Empty, NumResults,
1481
2.99k
                   HasTemplateKWAndArgsInfo) {}
1482
1483
653k
bool UnresolvedMemberExpr::isImplicitAccess() const {
1484
653k
  if (!Base)
1485
62.8k
    return true;
1486
1487
590k
  return cast<Expr>(Base)->isImplicitCXXThis();
1488
590k
}
1489
1490
UnresolvedMemberExpr *UnresolvedMemberExpr::Create(
1491
    const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
1492
    QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
1493
    NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1494
    const DeclarationNameInfo &MemberNameInfo,
1495
    const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
1496
229k
    UnresolvedSetIterator End) {
1497
229k
  unsigned NumResults = End - Begin;
1498
229k
  bool HasTemplateKWAndArgsInfo = TemplateArgs || 
TemplateKWLoc.isValid()226k
;
1499
226k
  unsigned NumTemplateArgs = TemplateArgs ? 
TemplateArgs->size()3.04k
: 0;
1500
229k
  unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
1501
229k
                                   TemplateArgumentLoc>(
1502
229k
      NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
1503
229k
  void *Mem = Context.Allocate(Size, alignof(UnresolvedMemberExpr));
1504
229k
  return new (Mem) UnresolvedMemberExpr(
1505
229k
      Context, HasUnresolvedUsing, Base, BaseType, IsArrow, OperatorLoc,
1506
229k
      QualifierLoc, TemplateKWLoc, MemberNameInfo, TemplateArgs, Begin, End);
1507
229k
}
1508
1509
UnresolvedMemberExpr *UnresolvedMemberExpr::CreateEmpty(
1510
    const ASTContext &Context, unsigned NumResults,
1511
2.99k
    bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) {
1512
2.99k
  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
1513
2.99k
  unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
1514
2.99k
                                   TemplateArgumentLoc>(
1515
2.99k
      NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
1516
2.99k
  void *Mem = Context.Allocate(Size, alignof(UnresolvedMemberExpr));
1517
2.99k
  return new (Mem)
1518
2.99k
      UnresolvedMemberExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo);
1519
2.99k
}
1520
1521
33.7k
CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() {
1522
  // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1523
1524
  // If there was a nested name specifier, it names the naming class.
1525
  // It can't be dependent: after all, we were actually able to do the
1526
  // lookup.
1527
33.7k
  CXXRecordDecl *Record = nullptr;
1528
33.7k
  auto *NNS = getQualifier();
1529
33.7k
  if (NNS && 
NNS->getKind() != NestedNameSpecifier::Super576
) {
1530
576
    const Type *T = getQualifier()->getAsType();
1531
576
    assert(T && "qualifier in member expression does not name type");
1532
576
    Record = T->getAsCXXRecordDecl();
1533
576
    assert(Record && "qualifier in member expression does not name record");
1534
576
  }
1535
  // Otherwise the naming class must have been the base class.
1536
33.1k
  else {
1537
33.1k
    QualType BaseType = getBaseType().getNonReferenceType();
1538
33.1k
    if (isArrow())
1539
32.6k
      BaseType = BaseType->castAs<PointerType>()->getPointeeType();
1540
1541
33.1k
    Record = BaseType->getAsCXXRecordDecl();
1542
33.1k
    assert(Record && "base of member expression does not name record");
1543
33.1k
  }
1544
1545
33.7k
  return Record;
1546
33.7k
}
1547
1548
SizeOfPackExpr *
1549
SizeOfPackExpr::Create(ASTContext &Context, SourceLocation OperatorLoc,
1550
                       NamedDecl *Pack, SourceLocation PackLoc,
1551
                       SourceLocation RParenLoc,
1552
                       Optional<unsigned> Length,
1553
121k
                       ArrayRef<TemplateArgument> PartialArgs) {
1554
121k
  void *Storage =
1555
121k
      Context.Allocate(totalSizeToAlloc<TemplateArgument>(PartialArgs.size()));
1556
121k
  return new (Storage) SizeOfPackExpr(Context.getSizeType(), OperatorLoc, Pack,
1557
121k
                                      PackLoc, RParenLoc, Length, PartialArgs);
1558
121k
}
1559
1560
SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context,
1561
13.1k
                                                   unsigned NumPartialArgs) {
1562
13.1k
  void *Storage =
1563
13.1k
      Context.Allocate(totalSizeToAlloc<TemplateArgument>(NumPartialArgs));
1564
13.1k
  return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs);
1565
13.1k
}
1566
1567
SubstNonTypeTemplateParmPackExpr::SubstNonTypeTemplateParmPackExpr(
1568
    QualType T, ExprValueKind ValueKind, NonTypeTemplateParmDecl *Param,
1569
    SourceLocation NameLoc, const TemplateArgument &ArgPack)
1570
    : Expr(SubstNonTypeTemplateParmPackExprClass, T, ValueKind, OK_Ordinary),
1571
      Param(Param), Arguments(ArgPack.pack_begin()),
1572
41
      NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) {
1573
41
  setDependence(ExprDependence::TypeValueInstantiation |
1574
41
                ExprDependence::UnexpandedPack);
1575
41
}
1576
1577
196
TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1578
196
  return TemplateArgument(llvm::makeArrayRef(Arguments, NumArguments));
1579
196
}
1580
1581
FunctionParmPackExpr::FunctionParmPackExpr(QualType T, VarDecl *ParamPack,
1582
                                           SourceLocation NameLoc,
1583
                                           unsigned NumParams,
1584
                                           VarDecl *const *Params)
1585
    : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary),
1586
139
      ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1587
139
  if (Params)
1588
131
    std::uninitialized_copy(Params, Params + NumParams,
1589
131
                            getTrailingObjects<VarDecl *>());
1590
139
  setDependence(ExprDependence::TypeValueInstantiation |
1591
139
                ExprDependence::UnexpandedPack);
1592
139
}
1593
1594
FunctionParmPackExpr *
1595
FunctionParmPackExpr::Create(const ASTContext &Context, QualType T,
1596
                             VarDecl *ParamPack, SourceLocation NameLoc,
1597
131
                             ArrayRef<VarDecl *> Params) {
1598
131
  return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(Params.size())))
1599
131
      FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1600
131
}
1601
1602
FunctionParmPackExpr *
1603
FunctionParmPackExpr::CreateEmpty(const ASTContext &Context,
1604
8
                                  unsigned NumParams) {
1605
8
  return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(NumParams)))
1606
8
      FunctionParmPackExpr(QualType(), nullptr, SourceLocation(), 0, nullptr);
1607
8
}
1608
1609
MaterializeTemporaryExpr::MaterializeTemporaryExpr(
1610
    QualType T, Expr *Temporary, bool BoundToLvalueReference,
1611
    LifetimeExtendedTemporaryDecl *MTD)
1612
    : Expr(MaterializeTemporaryExprClass, T,
1613
132k
           BoundToLvalueReference ? VK_LValue : VK_XValue, OK_Ordinary) {
1614
132k
  if (MTD) {
1615
2
    State = MTD;
1616
2
    MTD->ExprWithTemporary = Temporary;
1617
2
    return;
1618
2
  }
1619
132k
  State = Temporary;
1620
132k
  setDependence(computeDependence(this));
1621
132k
}
1622
1623
void MaterializeTemporaryExpr::setExtendingDecl(ValueDecl *ExtendedBy,
1624
2.11k
                                                unsigned ManglingNumber) {
1625
  // We only need extra state if we have to remember more than just the Stmt.
1626
2.11k
  if (!ExtendedBy)
1627
0
    return;
1628
1629
  // We may need to allocate extra storage for the mangling number and the
1630
  // extended-by ValueDecl.
1631
2.11k
  if (!State.is<LifetimeExtendedTemporaryDecl *>())
1632
2.11k
    State = LifetimeExtendedTemporaryDecl::Create(
1633
2.11k
        cast<Expr>(State.get<Stmt *>()), ExtendedBy, ManglingNumber);
1634
1635
2.11k
  auto ES = State.get<LifetimeExtendedTemporaryDecl *>();
1636
2.11k
  ES->ExtendingDecl = ExtendedBy;
1637
2.11k
  ES->ManglingNumber = ManglingNumber;
1638
2.11k
}
1639
1640
TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1641
                             ArrayRef<TypeSourceInfo *> Args,
1642
                             SourceLocation RParenLoc, bool Value)
1643
    : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary), Loc(Loc),
1644
244k
      RParenLoc(RParenLoc) {
1645
244k
  assert(Kind <= TT_Last && "invalid enum value!");
1646
244k
  TypeTraitExprBits.Kind = Kind;
1647
244k
  assert(static_cast<unsigned>(Kind) == TypeTraitExprBits.Kind &&
1648
244k
         "TypeTraitExprBits.Kind overflow!");
1649
244k
  TypeTraitExprBits.Value = Value;
1650
244k
  TypeTraitExprBits.NumArgs = Args.size();
1651
244k
  assert(Args.size() == TypeTraitExprBits.NumArgs &&
1652
244k
         "TypeTraitExprBits.NumArgs overflow!");
1653
1654
244k
  auto **ToArgs = getTrailingObjects<TypeSourceInfo *>();
1655
742k
  for (unsigned I = 0, N = Args.size(); I != N; 
++I497k
)
1656
497k
    ToArgs[I] = Args[I];
1657
1658
244k
  setDependence(computeDependence(this));
1659
244k
}
1660
1661
TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T,
1662
                                     SourceLocation Loc,
1663
                                     TypeTrait Kind,
1664
                                     ArrayRef<TypeSourceInfo *> Args,
1665
                                     SourceLocation RParenLoc,
1666
244k
                                     bool Value) {
1667
244k
  void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(Args.size()));
1668
244k
  return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1669
244k
}
1670
1671
TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const ASTContext &C,
1672
19.8k
                                                 unsigned NumArgs) {
1673
19.8k
  void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(NumArgs));
1674
19.8k
  return new (Mem) TypeTraitExpr(EmptyShell());
1675
19.8k
}
1676
1677
CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config,
1678
                                       ArrayRef<Expr *> Args, QualType Ty,
1679
                                       ExprValueKind VK, SourceLocation RP,
1680
                                       FPOptionsOverride FPFeatures,
1681
                                       unsigned MinNumArgs)
1682
    : CallExpr(CUDAKernelCallExprClass, Fn, /*PreArgs=*/Config, Args, Ty, VK,
1683
100
               RP, FPFeatures, MinNumArgs, NotADL) {}
1684
1685
CUDAKernelCallExpr::CUDAKernelCallExpr(unsigned NumArgs, bool HasFPFeatures,
1686
                                       EmptyShell Empty)
1687
    : CallExpr(CUDAKernelCallExprClass, /*NumPreArgs=*/END_PREARG, NumArgs,
1688
1
               HasFPFeatures, Empty) {}
1689
1690
CUDAKernelCallExpr *
1691
CUDAKernelCallExpr::Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config,
1692
                           ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
1693
                           SourceLocation RP, FPOptionsOverride FPFeatures,
1694
100
                           unsigned MinNumArgs) {
1695
  // Allocate storage for the trailing objects of CallExpr.
1696
100
  unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
1697
100
  unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
1698
100
      /*NumPreArgs=*/END_PREARG, NumArgs, FPFeatures.requiresTrailingStorage());
1699
100
  void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects,
1700
100
                           alignof(CUDAKernelCallExpr));
1701
100
  return new (Mem)
1702
100
      CUDAKernelCallExpr(Fn, Config, Args, Ty, VK, RP, FPFeatures, MinNumArgs);
1703
100
}
1704
1705
CUDAKernelCallExpr *CUDAKernelCallExpr::CreateEmpty(const ASTContext &Ctx,
1706
                                                    unsigned NumArgs,
1707
                                                    bool HasFPFeatures,
1708
1
                                                    EmptyShell Empty) {
1709
  // Allocate storage for the trailing objects of CallExpr.
1710
1
  unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
1711
1
      /*NumPreArgs=*/END_PREARG, NumArgs, HasFPFeatures);
1712
1
  void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects,
1713
1
                           alignof(CUDAKernelCallExpr));
1714
1
  return new (Mem) CUDAKernelCallExpr(NumArgs, HasFPFeatures, Empty);
1715
1
}