Coverage Report

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