Coverage Report

Created: 2021-01-19 06:58

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