Coverage Report

Created: 2020-02-15 09:57

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