1 //===- ExprCXX.cpp - (C++) Expression AST Node Implementation -------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements the subclesses of Expr class declared in ExprCXX.h
11 //===----------------------------------------------------------------------===//
13 #include "clang/AST/ExprCXX.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Attr.h"
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclAccessPair.h"
18 #include "clang/AST/DeclBase.h"
19 #include "clang/AST/DeclCXX.h"
20 #include "clang/AST/DeclarationName.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/LambdaCapture.h"
23 #include "clang/AST/NestedNameSpecifier.h"
24 #include "clang/AST/TemplateBase.h"
25 #include "clang/AST/Type.h"
26 #include "clang/AST/TypeLoc.h"
27 #include "clang/Basic/LLVM.h"
28 #include "clang/Basic/OperatorKinds.h"
29 #include "clang/Basic/SourceLocation.h"
30 #include "clang/Basic/Specifiers.h"
31 #include "llvm/ADT/ArrayRef.h"
32 #include "llvm/Support/Casting.h"
33 #include "llvm/Support/ErrorHandling.h"
39 using namespace clang;
41 //===----------------------------------------------------------------------===//
42 // Child Iterators for iterating over subexpressions/substatements
43 //===----------------------------------------------------------------------===//
45 bool CXXOperatorCallExpr::isInfixBinaryOp() const {
46 // An infix binary operator is any operator with two arguments other than
47 // operator() and operator[]. Note that none of these operators can have
48 // default arguments, so it suffices to check the number of argument
50 if (getNumArgs() != 2)
53 switch (getOperator()) {
54 case OO_Call: case OO_Subscript:
61 bool CXXTypeidExpr::isPotentiallyEvaluated() const {
65 // C++11 [expr.typeid]p3:
66 // When typeid is applied to an expression other than a glvalue of
67 // polymorphic class type, [...] the expression is an unevaluated operand.
68 const Expr *E = getExprOperand();
69 if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl())
70 if (RD->isPolymorphic() && E->isGLValue())
76 QualType CXXTypeidExpr::getTypeOperand(ASTContext &Context) const {
77 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
79 return Context.getUnqualifiedArrayType(
80 Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
83 QualType CXXUuidofExpr::getTypeOperand(ASTContext &Context) const {
84 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
86 return Context.getUnqualifiedArrayType(
87 Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
90 // CXXScalarValueInitExpr
91 SourceLocation CXXScalarValueInitExpr::getBeginLoc() const {
92 return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : getRParenLoc();
96 CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
97 FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
98 bool UsualArrayDeleteWantsSize,
99 ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens,
100 Optional<Expr *> ArraySize,
101 InitializationStyle InitializationStyle,
102 Expr *Initializer, QualType Ty,
103 TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
104 SourceRange DirectInitRange)
105 : Expr(CXXNewExprClass, Ty, VK_RValue, OK_Ordinary, Ty->isDependentType(),
106 Ty->isDependentType(), Ty->isInstantiationDependentType(),
107 Ty->containsUnexpandedParameterPack()),
108 OperatorNew(OperatorNew), OperatorDelete(OperatorDelete),
109 AllocatedTypeInfo(AllocatedTypeInfo), Range(Range),
110 DirectInitRange(DirectInitRange) {
112 assert((Initializer != nullptr || InitializationStyle == NoInit) &&
113 "Only NoInit can have no initializer!");
115 CXXNewExprBits.IsGlobalNew = IsGlobalNew;
116 CXXNewExprBits.IsArray = ArraySize.hasValue();
117 CXXNewExprBits.ShouldPassAlignment = ShouldPassAlignment;
118 CXXNewExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize;
119 CXXNewExprBits.StoredInitializationStyle =
120 Initializer ? InitializationStyle + 1 : 0;
121 bool IsParenTypeId = TypeIdParens.isValid();
122 CXXNewExprBits.IsParenTypeId = IsParenTypeId;
123 CXXNewExprBits.NumPlacementArgs = PlacementArgs.size();
126 if (Expr *SizeExpr = *ArraySize) {
127 if (SizeExpr->isInstantiationDependent())
128 ExprBits.InstantiationDependent = true;
129 if (SizeExpr->containsUnexpandedParameterPack())
130 ExprBits.ContainsUnexpandedParameterPack = true;
133 getTrailingObjects<Stmt *>()[arraySizeOffset()] = *ArraySize;
137 if (Initializer->isInstantiationDependent())
138 ExprBits.InstantiationDependent = true;
139 if (Initializer->containsUnexpandedParameterPack())
140 ExprBits.ContainsUnexpandedParameterPack = true;
142 getTrailingObjects<Stmt *>()[initExprOffset()] = Initializer;
145 for (unsigned I = 0; I != PlacementArgs.size(); ++I) {
146 if (PlacementArgs[I]->isInstantiationDependent())
147 ExprBits.InstantiationDependent = true;
148 if (PlacementArgs[I]->containsUnexpandedParameterPack())
149 ExprBits.ContainsUnexpandedParameterPack = true;
151 getTrailingObjects<Stmt *>()[placementNewArgsOffset() + I] =
156 getTrailingObjects<SourceRange>()[0] = TypeIdParens;
158 switch (getInitializationStyle()) {
160 this->Range.setEnd(DirectInitRange.getEnd());
163 this->Range.setEnd(getInitializer()->getSourceRange().getEnd());
167 this->Range.setEnd(TypeIdParens.getEnd());
172 CXXNewExpr::CXXNewExpr(EmptyShell Empty, bool IsArray,
173 unsigned NumPlacementArgs, bool IsParenTypeId)
174 : Expr(CXXNewExprClass, Empty) {
175 CXXNewExprBits.IsArray = IsArray;
176 CXXNewExprBits.NumPlacementArgs = NumPlacementArgs;
177 CXXNewExprBits.IsParenTypeId = IsParenTypeId;
181 CXXNewExpr::Create(const ASTContext &Ctx, bool IsGlobalNew,
182 FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete,
183 bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize,
184 ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens,
185 Optional<Expr *> ArraySize,
186 InitializationStyle InitializationStyle, Expr *Initializer,
187 QualType Ty, TypeSourceInfo *AllocatedTypeInfo,
188 SourceRange Range, SourceRange DirectInitRange) {
189 bool IsArray = ArraySize.hasValue();
190 bool HasInit = Initializer != nullptr;
191 unsigned NumPlacementArgs = PlacementArgs.size();
192 bool IsParenTypeId = TypeIdParens.isValid();
194 Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>(
195 IsArray + HasInit + NumPlacementArgs, IsParenTypeId),
196 alignof(CXXNewExpr));
198 CXXNewExpr(IsGlobalNew, OperatorNew, OperatorDelete, ShouldPassAlignment,
199 UsualArrayDeleteWantsSize, PlacementArgs, TypeIdParens,
200 ArraySize, InitializationStyle, Initializer, Ty,
201 AllocatedTypeInfo, Range, DirectInitRange);
204 CXXNewExpr *CXXNewExpr::CreateEmpty(const ASTContext &Ctx, bool IsArray,
205 bool HasInit, unsigned NumPlacementArgs,
206 bool IsParenTypeId) {
208 Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>(
209 IsArray + HasInit + NumPlacementArgs, IsParenTypeId),
210 alignof(CXXNewExpr));
212 CXXNewExpr(EmptyShell(), IsArray, NumPlacementArgs, IsParenTypeId);
215 bool CXXNewExpr::shouldNullCheckAllocation() const {
216 return getOperatorNew()
218 ->castAs<FunctionProtoType>()
220 !getOperatorNew()->isReservedGlobalPlacementOperator();
224 QualType CXXDeleteExpr::getDestroyedType() const {
225 const Expr *Arg = getArgument();
227 // For a destroying operator delete, we may have implicitly converted the
228 // pointer type to the type of the parameter of the 'operator delete'
230 while (const auto *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
231 if (ICE->getCastKind() == CK_DerivedToBase ||
232 ICE->getCastKind() == CK_UncheckedDerivedToBase ||
233 ICE->getCastKind() == CK_NoOp) {
234 assert((ICE->getCastKind() == CK_NoOp ||
235 getOperatorDelete()->isDestroyingOperatorDelete()) &&
236 "only a destroying operator delete can have a converted arg");
237 Arg = ICE->getSubExpr();
242 // The type-to-delete may not be a pointer if it's a dependent type.
243 const QualType ArgType = Arg->getType();
245 if (ArgType->isDependentType() && !ArgType->isPointerType())
248 return ArgType->getAs<PointerType>()->getPointeeType();
251 // CXXPseudoDestructorExpr
252 PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
254 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
257 CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(const ASTContext &Context,
258 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
259 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
260 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
261 PseudoDestructorTypeStorage DestroyedType)
262 : Expr(CXXPseudoDestructorExprClass,
263 Context.BoundMemberTy,
264 VK_RValue, OK_Ordinary,
265 /*isTypeDependent=*/(Base->isTypeDependent() ||
266 (DestroyedType.getTypeSourceInfo() &&
267 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
268 /*isValueDependent=*/Base->isValueDependent(),
269 (Base->isInstantiationDependent() ||
271 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
273 ScopeType->getType()->isInstantiationDependentType()) ||
274 (DestroyedType.getTypeSourceInfo() &&
275 DestroyedType.getTypeSourceInfo()->getType()
276 ->isInstantiationDependentType())),
277 // ContainsUnexpandedParameterPack
278 (Base->containsUnexpandedParameterPack() ||
280 QualifierLoc.getNestedNameSpecifier()
281 ->containsUnexpandedParameterPack()) ||
283 ScopeType->getType()->containsUnexpandedParameterPack()) ||
284 (DestroyedType.getTypeSourceInfo() &&
285 DestroyedType.getTypeSourceInfo()->getType()
286 ->containsUnexpandedParameterPack()))),
287 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
288 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
289 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
290 DestroyedType(DestroyedType) {}
292 QualType CXXPseudoDestructorExpr::getDestroyedType() const {
293 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
294 return TInfo->getType();
299 SourceLocation CXXPseudoDestructorExpr::getEndLoc() const {
300 SourceLocation End = DestroyedType.getLocation();
301 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
302 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
306 // UnresolvedLookupExpr
307 UnresolvedLookupExpr::UnresolvedLookupExpr(
308 const ASTContext &Context, CXXRecordDecl *NamingClass,
309 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
310 const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
311 const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
312 UnresolvedSetIterator End)
313 : OverloadExpr(UnresolvedLookupExprClass, Context, QualifierLoc,
314 TemplateKWLoc, NameInfo, TemplateArgs, Begin, End, false,
316 NamingClass(NamingClass) {
317 UnresolvedLookupExprBits.RequiresADL = RequiresADL;
318 UnresolvedLookupExprBits.Overloaded = Overloaded;
321 UnresolvedLookupExpr::UnresolvedLookupExpr(EmptyShell Empty,
323 bool HasTemplateKWAndArgsInfo)
324 : OverloadExpr(UnresolvedLookupExprClass, Empty, NumResults,
325 HasTemplateKWAndArgsInfo) {}
327 UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
328 const ASTContext &Context, CXXRecordDecl *NamingClass,
329 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
330 bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin,
331 UnresolvedSetIterator End) {
332 unsigned NumResults = End - Begin;
333 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
334 TemplateArgumentLoc>(NumResults, 0, 0);
335 void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
336 return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
337 SourceLocation(), NameInfo, RequiresADL,
338 Overloaded, nullptr, Begin, End);
341 UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
342 const ASTContext &Context, CXXRecordDecl *NamingClass,
343 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
344 const DeclarationNameInfo &NameInfo, bool RequiresADL,
345 const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
346 UnresolvedSetIterator End) {
347 assert(Args || TemplateKWLoc.isValid());
348 unsigned NumResults = End - Begin;
349 unsigned NumTemplateArgs = Args ? Args->size() : 0;
351 totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
352 TemplateArgumentLoc>(NumResults, 1, NumTemplateArgs);
353 void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
354 return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
355 TemplateKWLoc, NameInfo, RequiresADL,
356 /*Overloaded*/ true, Args, Begin, End);
359 UnresolvedLookupExpr *UnresolvedLookupExpr::CreateEmpty(
360 const ASTContext &Context, unsigned NumResults,
361 bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) {
362 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
363 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
364 TemplateArgumentLoc>(
365 NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
366 void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
368 UnresolvedLookupExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo);
371 OverloadExpr::OverloadExpr(StmtClass SC, const ASTContext &Context,
372 NestedNameSpecifierLoc QualifierLoc,
373 SourceLocation TemplateKWLoc,
374 const DeclarationNameInfo &NameInfo,
375 const TemplateArgumentListInfo *TemplateArgs,
376 UnresolvedSetIterator Begin,
377 UnresolvedSetIterator End, bool KnownDependent,
378 bool KnownInstantiationDependent,
379 bool KnownContainsUnexpandedParameterPack)
381 SC, Context.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
383 (KnownInstantiationDependent || NameInfo.isInstantiationDependent() ||
385 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
386 (KnownContainsUnexpandedParameterPack ||
387 NameInfo.containsUnexpandedParameterPack() ||
388 (QualifierLoc && QualifierLoc.getNestedNameSpecifier()
389 ->containsUnexpandedParameterPack()))),
390 NameInfo(NameInfo), QualifierLoc(QualifierLoc) {
391 unsigned NumResults = End - Begin;
392 OverloadExprBits.NumResults = NumResults;
393 OverloadExprBits.HasTemplateKWAndArgsInfo =
394 (TemplateArgs != nullptr ) || TemplateKWLoc.isValid();
397 // Determine whether this expression is type-dependent.
398 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
399 if ((*I)->getDeclContext()->isDependentContext() ||
400 isa<UnresolvedUsingValueDecl>(*I)) {
401 ExprBits.TypeDependent = true;
402 ExprBits.ValueDependent = true;
403 ExprBits.InstantiationDependent = true;
407 // Copy the results to the trailing array past UnresolvedLookupExpr
408 // or UnresolvedMemberExpr.
409 DeclAccessPair *Results = getTrailingResults();
410 memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair));
413 // If we have explicit template arguments, check for dependent
414 // template arguments and whether they contain any unexpanded pack
417 bool Dependent = false;
418 bool InstantiationDependent = false;
419 bool ContainsUnexpandedParameterPack = false;
420 getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(
421 TemplateKWLoc, *TemplateArgs, getTrailingTemplateArgumentLoc(),
422 Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
425 ExprBits.TypeDependent = true;
426 ExprBits.ValueDependent = true;
428 if (InstantiationDependent)
429 ExprBits.InstantiationDependent = true;
430 if (ContainsUnexpandedParameterPack)
431 ExprBits.ContainsUnexpandedParameterPack = true;
432 } else if (TemplateKWLoc.isValid()) {
433 getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
436 if (isTypeDependent())
437 setType(Context.DependentTy);
440 OverloadExpr::OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults,
441 bool HasTemplateKWAndArgsInfo)
443 OverloadExprBits.NumResults = NumResults;
444 OverloadExprBits.HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
447 // DependentScopeDeclRefExpr
448 DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(
449 QualType Ty, NestedNameSpecifierLoc QualifierLoc,
450 SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
451 const TemplateArgumentListInfo *Args)
453 DependentScopeDeclRefExprClass, Ty, VK_LValue, OK_Ordinary, true,
455 (NameInfo.isInstantiationDependent() ||
457 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
458 (NameInfo.containsUnexpandedParameterPack() ||
459 (QualifierLoc && QualifierLoc.getNestedNameSpecifier()
460 ->containsUnexpandedParameterPack()))),
461 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {
462 DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo =
463 (Args != nullptr) || TemplateKWLoc.isValid();
465 bool Dependent = true;
466 bool InstantiationDependent = true;
467 bool ContainsUnexpandedParameterPack
468 = ExprBits.ContainsUnexpandedParameterPack;
469 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
470 TemplateKWLoc, *Args, getTrailingObjects<TemplateArgumentLoc>(),
471 Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
472 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
473 } else if (TemplateKWLoc.isValid()) {
474 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
479 DependentScopeDeclRefExpr *DependentScopeDeclRefExpr::Create(
480 const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
481 SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
482 const TemplateArgumentListInfo *Args) {
483 assert(QualifierLoc && "should be created for dependent qualifiers");
484 bool HasTemplateKWAndArgsInfo = Args || TemplateKWLoc.isValid();
486 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
487 HasTemplateKWAndArgsInfo, Args ? Args->size() : 0);
488 void *Mem = Context.Allocate(Size);
489 return new (Mem) DependentScopeDeclRefExpr(Context.DependentTy, QualifierLoc,
490 TemplateKWLoc, NameInfo, Args);
493 DependentScopeDeclRefExpr *
494 DependentScopeDeclRefExpr::CreateEmpty(const ASTContext &Context,
495 bool HasTemplateKWAndArgsInfo,
496 unsigned NumTemplateArgs) {
497 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
499 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
500 HasTemplateKWAndArgsInfo, NumTemplateArgs);
501 void *Mem = Context.Allocate(Size);
502 auto *E = new (Mem) DependentScopeDeclRefExpr(
503 QualType(), NestedNameSpecifierLoc(), SourceLocation(),
504 DeclarationNameInfo(), nullptr);
505 E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo =
506 HasTemplateKWAndArgsInfo;
510 SourceLocation CXXConstructExpr::getBeginLoc() const {
511 if (isa<CXXTemporaryObjectExpr>(this))
512 return cast<CXXTemporaryObjectExpr>(this)->getBeginLoc();
513 return getLocation();
516 SourceLocation CXXConstructExpr::getEndLoc() const {
517 if (isa<CXXTemporaryObjectExpr>(this))
518 return cast<CXXTemporaryObjectExpr>(this)->getEndLoc();
520 if (ParenOrBraceRange.isValid())
521 return ParenOrBraceRange.getEnd();
523 SourceLocation End = getLocation();
524 for (unsigned I = getNumArgs(); I > 0; --I) {
525 const Expr *Arg = getArg(I-1);
526 if (!Arg->isDefaultArgument()) {
527 SourceLocation NewEnd = Arg->getEndLoc();
528 if (NewEnd.isValid()) {
538 CXXOperatorCallExpr::CXXOperatorCallExpr(OverloadedOperatorKind OpKind,
539 Expr *Fn, ArrayRef<Expr *> Args,
540 QualType Ty, ExprValueKind VK,
541 SourceLocation OperatorLoc,
542 FPOptions FPFeatures,
544 : CallExpr(CXXOperatorCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
545 OperatorLoc, /*MinNumArgs=*/0, UsesADL) {
546 CXXOperatorCallExprBits.OperatorKind = OpKind;
547 CXXOperatorCallExprBits.FPFeatures = FPFeatures.getInt();
549 (CXXOperatorCallExprBits.OperatorKind == static_cast<unsigned>(OpKind)) &&
550 "OperatorKind overflow!");
551 assert((CXXOperatorCallExprBits.FPFeatures == FPFeatures.getInt()) &&
552 "FPFeatures overflow!");
553 Range = getSourceRangeImpl();
556 CXXOperatorCallExpr::CXXOperatorCallExpr(unsigned NumArgs, EmptyShell Empty)
557 : CallExpr(CXXOperatorCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {}
559 CXXOperatorCallExpr *CXXOperatorCallExpr::Create(
560 const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn,
561 ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
562 SourceLocation OperatorLoc, FPOptions FPFeatures, ADLCallKind UsesADL) {
563 // Allocate storage for the trailing objects of CallExpr.
564 unsigned NumArgs = Args.size();
565 unsigned SizeOfTrailingObjects =
566 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
567 void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects,
568 alignof(CXXOperatorCallExpr));
569 return new (Mem) CXXOperatorCallExpr(OpKind, Fn, Args, Ty, VK, OperatorLoc,
570 FPFeatures, UsesADL);
573 CXXOperatorCallExpr *CXXOperatorCallExpr::CreateEmpty(const ASTContext &Ctx,
576 // Allocate storage for the trailing objects of CallExpr.
577 unsigned SizeOfTrailingObjects =
578 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
579 void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects,
580 alignof(CXXOperatorCallExpr));
581 return new (Mem) CXXOperatorCallExpr(NumArgs, Empty);
584 SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
585 OverloadedOperatorKind Kind = getOperator();
586 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
587 if (getNumArgs() == 1)
589 return SourceRange(getOperatorLoc(), getArg(0)->getEndLoc());
592 return SourceRange(getArg(0)->getBeginLoc(), getOperatorLoc());
593 } else if (Kind == OO_Arrow) {
594 return getArg(0)->getSourceRange();
595 } else if (Kind == OO_Call) {
596 return SourceRange(getArg(0)->getBeginLoc(), getRParenLoc());
597 } else if (Kind == OO_Subscript) {
598 return SourceRange(getArg(0)->getBeginLoc(), getRParenLoc());
599 } else if (getNumArgs() == 1) {
600 return SourceRange(getOperatorLoc(), getArg(0)->getEndLoc());
601 } else if (getNumArgs() == 2) {
602 return SourceRange(getArg(0)->getBeginLoc(), getArg(1)->getEndLoc());
604 return getOperatorLoc();
608 CXXMemberCallExpr::CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args,
609 QualType Ty, ExprValueKind VK,
610 SourceLocation RP, unsigned MinNumArgs)
611 : CallExpr(CXXMemberCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, RP,
612 MinNumArgs, NotADL) {}
614 CXXMemberCallExpr::CXXMemberCallExpr(unsigned NumArgs, EmptyShell Empty)
615 : CallExpr(CXXMemberCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {}
617 CXXMemberCallExpr *CXXMemberCallExpr::Create(const ASTContext &Ctx, Expr *Fn,
618 ArrayRef<Expr *> Args, QualType Ty,
621 unsigned MinNumArgs) {
622 // Allocate storage for the trailing objects of CallExpr.
623 unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
624 unsigned SizeOfTrailingObjects =
625 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
626 void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects,
627 alignof(CXXMemberCallExpr));
628 return new (Mem) CXXMemberCallExpr(Fn, Args, Ty, VK, RP, MinNumArgs);
631 CXXMemberCallExpr *CXXMemberCallExpr::CreateEmpty(const ASTContext &Ctx,
634 // Allocate storage for the trailing objects of CallExpr.
635 unsigned SizeOfTrailingObjects =
636 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
637 void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects,
638 alignof(CXXMemberCallExpr));
639 return new (Mem) CXXMemberCallExpr(NumArgs, Empty);
642 Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
643 const Expr *Callee = getCallee()->IgnoreParens();
644 if (const auto *MemExpr = dyn_cast<MemberExpr>(Callee))
645 return MemExpr->getBase();
646 if (const auto *BO = dyn_cast<BinaryOperator>(Callee))
647 if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
650 // FIXME: Will eventually need to cope with member pointers.
654 QualType CXXMemberCallExpr::getObjectType() const {
655 QualType Ty = getImplicitObjectArgument()->getType();
656 if (Ty->isPointerType())
657 Ty = Ty->getPointeeType();
661 CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
662 if (const auto *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
663 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
665 // FIXME: Will eventually need to cope with member pointers.
669 CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
670 Expr* ThisArg = getImplicitObjectArgument();
674 if (ThisArg->getType()->isAnyPointerType())
675 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
677 return ThisArg->getType()->getAsCXXRecordDecl();
680 //===----------------------------------------------------------------------===//
682 //===----------------------------------------------------------------------===//
684 /// getCastName - Get the name of the C++ cast being used, e.g.,
685 /// "static_cast", "dynamic_cast", "reinterpret_cast", or
686 /// "const_cast". The returned pointer must not be freed.
687 const char *CXXNamedCastExpr::getCastName() const {
688 switch (getStmtClass()) {
689 case CXXStaticCastExprClass: return "static_cast";
690 case CXXDynamicCastExprClass: return "dynamic_cast";
691 case CXXReinterpretCastExprClass: return "reinterpret_cast";
692 case CXXConstCastExprClass: return "const_cast";
693 default: return "<invalid cast>";
697 CXXStaticCastExpr *CXXStaticCastExpr::Create(const ASTContext &C, QualType T,
699 CastKind K, Expr *Op,
700 const CXXCastPath *BasePath,
701 TypeSourceInfo *WrittenTy,
703 SourceLocation RParenLoc,
704 SourceRange AngleBrackets) {
705 unsigned PathSize = (BasePath ? BasePath->size() : 0);
706 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
708 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
709 RParenLoc, AngleBrackets);
711 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
712 E->getTrailingObjects<CXXBaseSpecifier *>());
716 CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(const ASTContext &C,
718 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
719 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
722 CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T,
724 CastKind K, Expr *Op,
725 const CXXCastPath *BasePath,
726 TypeSourceInfo *WrittenTy,
728 SourceLocation RParenLoc,
729 SourceRange AngleBrackets) {
730 unsigned PathSize = (BasePath ? BasePath->size() : 0);
731 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
733 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
734 RParenLoc, AngleBrackets);
736 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
737 E->getTrailingObjects<CXXBaseSpecifier *>());
741 CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(const ASTContext &C,
743 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
744 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
747 /// isAlwaysNull - Return whether the result of the dynamic_cast is proven
748 /// to always be null. For example:
751 /// struct B final : A { };
754 /// C *f(B* b) { return dynamic_cast<C*>(b); }
755 bool CXXDynamicCastExpr::isAlwaysNull() const
757 QualType SrcType = getSubExpr()->getType();
758 QualType DestType = getType();
760 if (const auto *SrcPTy = SrcType->getAs<PointerType>()) {
761 SrcType = SrcPTy->getPointeeType();
762 DestType = DestType->castAs<PointerType>()->getPointeeType();
765 if (DestType->isVoidType())
769 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
771 if (!SrcRD->hasAttr<FinalAttr>())
775 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
777 return !DestRD->isDerivedFrom(SrcRD);
780 CXXReinterpretCastExpr *
781 CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T,
782 ExprValueKind VK, CastKind K, Expr *Op,
783 const CXXCastPath *BasePath,
784 TypeSourceInfo *WrittenTy, SourceLocation L,
785 SourceLocation RParenLoc,
786 SourceRange AngleBrackets) {
787 unsigned PathSize = (BasePath ? BasePath->size() : 0);
788 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
790 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
791 RParenLoc, AngleBrackets);
793 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
794 E->getTrailingObjects<CXXBaseSpecifier *>());
798 CXXReinterpretCastExpr *
799 CXXReinterpretCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) {
800 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
801 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
804 CXXConstCastExpr *CXXConstCastExpr::Create(const ASTContext &C, QualType T,
805 ExprValueKind VK, Expr *Op,
806 TypeSourceInfo *WrittenTy,
808 SourceLocation RParenLoc,
809 SourceRange AngleBrackets) {
810 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets);
813 CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(const ASTContext &C) {
814 return new (C) CXXConstCastExpr(EmptyShell());
817 CXXFunctionalCastExpr *
818 CXXFunctionalCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK,
819 TypeSourceInfo *Written, CastKind K, Expr *Op,
820 const CXXCastPath *BasePath,
821 SourceLocation L, SourceLocation R) {
822 unsigned PathSize = (BasePath ? BasePath->size() : 0);
823 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
825 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R);
827 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
828 E->getTrailingObjects<CXXBaseSpecifier *>());
832 CXXFunctionalCastExpr *
833 CXXFunctionalCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) {
834 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
835 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
838 SourceLocation CXXFunctionalCastExpr::getBeginLoc() const {
839 return getTypeInfoAsWritten()->getTypeLoc().getBeginLoc();
842 SourceLocation CXXFunctionalCastExpr::getEndLoc() const {
843 return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getEndLoc();
846 UserDefinedLiteral::UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args,
847 QualType Ty, ExprValueKind VK,
848 SourceLocation LitEndLoc,
849 SourceLocation SuffixLoc)
850 : CallExpr(UserDefinedLiteralClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
851 LitEndLoc, /*MinNumArgs=*/0, NotADL),
852 UDSuffixLoc(SuffixLoc) {}
854 UserDefinedLiteral::UserDefinedLiteral(unsigned NumArgs, EmptyShell Empty)
855 : CallExpr(UserDefinedLiteralClass, /*NumPreArgs=*/0, NumArgs, Empty) {}
857 UserDefinedLiteral *UserDefinedLiteral::Create(const ASTContext &Ctx, Expr *Fn,
858 ArrayRef<Expr *> Args,
859 QualType Ty, ExprValueKind VK,
860 SourceLocation LitEndLoc,
861 SourceLocation SuffixLoc) {
862 // Allocate storage for the trailing objects of CallExpr.
863 unsigned NumArgs = Args.size();
864 unsigned SizeOfTrailingObjects =
865 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
866 void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects,
867 alignof(UserDefinedLiteral));
868 return new (Mem) UserDefinedLiteral(Fn, Args, Ty, VK, LitEndLoc, SuffixLoc);
871 UserDefinedLiteral *UserDefinedLiteral::CreateEmpty(const ASTContext &Ctx,
874 // Allocate storage for the trailing objects of CallExpr.
875 unsigned SizeOfTrailingObjects =
876 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
877 void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects,
878 alignof(UserDefinedLiteral));
879 return new (Mem) UserDefinedLiteral(NumArgs, Empty);
882 UserDefinedLiteral::LiteralOperatorKind
883 UserDefinedLiteral::getLiteralOperatorKind() const {
884 if (getNumArgs() == 0)
886 if (getNumArgs() == 2)
889 assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
891 cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
892 if (ParamTy->isPointerType())
894 if (ParamTy->isAnyCharacterType())
895 return LOK_Character;
896 if (ParamTy->isIntegerType())
898 if (ParamTy->isFloatingType())
901 llvm_unreachable("unknown kind of literal operator");
904 Expr *UserDefinedLiteral::getCookedLiteral() {
906 LiteralOperatorKind LOK = getLiteralOperatorKind();
907 assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
912 const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const {
913 return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
916 CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc,
917 FieldDecl *Field, QualType Ty,
918 DeclContext *UsedContext)
919 : Expr(CXXDefaultInitExprClass, Ty.getNonLValueExprType(Ctx),
920 Ty->isLValueReferenceType() ? VK_LValue : Ty->isRValueReferenceType()
923 /*FIXME*/ OK_Ordinary, false, false, false, false),
924 Field(Field), UsedContext(UsedContext) {
925 CXXDefaultInitExprBits.Loc = Loc;
926 assert(Field->hasInClassInitializer());
929 CXXTemporary *CXXTemporary::Create(const ASTContext &C,
930 const CXXDestructorDecl *Destructor) {
931 return new (C) CXXTemporary(Destructor);
934 CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(const ASTContext &C,
937 assert((SubExpr->getType()->isRecordType() ||
938 SubExpr->getType()->isArrayType()) &&
939 "Expression bound to a temporary must have record or array type!");
941 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
944 CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(
945 CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI,
946 ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange,
947 bool HadMultipleCandidates, bool ListInitialization,
948 bool StdInitListInitialization, bool ZeroInitialization)
950 CXXTemporaryObjectExprClass, Ty, TSI->getTypeLoc().getBeginLoc(),
951 Cons, /* Elidable=*/false, Args, HadMultipleCandidates,
952 ListInitialization, StdInitListInitialization, ZeroInitialization,
953 CXXConstructExpr::CK_Complete, ParenOrBraceRange),
956 CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(EmptyShell Empty,
958 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty, NumArgs) {}
960 CXXTemporaryObjectExpr *CXXTemporaryObjectExpr::Create(
961 const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty,
962 TypeSourceInfo *TSI, ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange,
963 bool HadMultipleCandidates, bool ListInitialization,
964 bool StdInitListInitialization, bool ZeroInitialization) {
965 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size());
967 Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects,
968 alignof(CXXTemporaryObjectExpr));
969 return new (Mem) CXXTemporaryObjectExpr(
970 Cons, Ty, TSI, Args, ParenOrBraceRange, HadMultipleCandidates,
971 ListInitialization, StdInitListInitialization, ZeroInitialization);
974 CXXTemporaryObjectExpr *
975 CXXTemporaryObjectExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs) {
976 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs);
978 Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects,
979 alignof(CXXTemporaryObjectExpr));
980 return new (Mem) CXXTemporaryObjectExpr(EmptyShell(), NumArgs);
983 SourceLocation CXXTemporaryObjectExpr::getBeginLoc() const {
984 return getTypeSourceInfo()->getTypeLoc().getBeginLoc();
987 SourceLocation CXXTemporaryObjectExpr::getEndLoc() const {
988 SourceLocation Loc = getParenOrBraceRange().getEnd();
989 if (Loc.isInvalid() && getNumArgs())
990 Loc = getArg(getNumArgs() - 1)->getEndLoc();
994 CXXConstructExpr *CXXConstructExpr::Create(
995 const ASTContext &Ctx, QualType Ty, SourceLocation Loc,
996 CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args,
997 bool HadMultipleCandidates, bool ListInitialization,
998 bool StdInitListInitialization, bool ZeroInitialization,
999 ConstructionKind ConstructKind, SourceRange ParenOrBraceRange) {
1000 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size());
1001 void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects,
1002 alignof(CXXConstructExpr));
1003 return new (Mem) CXXConstructExpr(
1004 CXXConstructExprClass, Ty, Loc, Ctor, Elidable, Args,
1005 HadMultipleCandidates, ListInitialization, StdInitListInitialization,
1006 ZeroInitialization, ConstructKind, ParenOrBraceRange);
1009 CXXConstructExpr *CXXConstructExpr::CreateEmpty(const ASTContext &Ctx,
1011 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs);
1012 void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects,
1013 alignof(CXXConstructExpr));
1015 CXXConstructExpr(CXXConstructExprClass, EmptyShell(), NumArgs);
1018 CXXConstructExpr::CXXConstructExpr(
1019 StmtClass SC, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor,
1020 bool Elidable, ArrayRef<Expr *> Args, bool HadMultipleCandidates,
1021 bool ListInitialization, bool StdInitListInitialization,
1022 bool ZeroInitialization, ConstructionKind ConstructKind,
1023 SourceRange ParenOrBraceRange)
1024 : Expr(SC, Ty, VK_RValue, OK_Ordinary, Ty->isDependentType(),
1025 Ty->isDependentType(), Ty->isInstantiationDependentType(),
1026 Ty->containsUnexpandedParameterPack()),
1027 Constructor(Ctor), ParenOrBraceRange(ParenOrBraceRange),
1028 NumArgs(Args.size()) {
1029 CXXConstructExprBits.Elidable = Elidable;
1030 CXXConstructExprBits.HadMultipleCandidates = HadMultipleCandidates;
1031 CXXConstructExprBits.ListInitialization = ListInitialization;
1032 CXXConstructExprBits.StdInitListInitialization = StdInitListInitialization;
1033 CXXConstructExprBits.ZeroInitialization = ZeroInitialization;
1034 CXXConstructExprBits.ConstructionKind = ConstructKind;
1035 CXXConstructExprBits.Loc = Loc;
1037 Stmt **TrailingArgs = getTrailingArgs();
1038 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1039 assert(Args[I] && "NULL argument in CXXConstructExpr!");
1041 if (Args[I]->isValueDependent())
1042 ExprBits.ValueDependent = true;
1043 if (Args[I]->isInstantiationDependent())
1044 ExprBits.InstantiationDependent = true;
1045 if (Args[I]->containsUnexpandedParameterPack())
1046 ExprBits.ContainsUnexpandedParameterPack = true;
1048 TrailingArgs[I] = Args[I];
1052 CXXConstructExpr::CXXConstructExpr(StmtClass SC, EmptyShell Empty,
1054 : Expr(SC, Empty), NumArgs(NumArgs) {}
1056 LambdaCapture::LambdaCapture(SourceLocation Loc, bool Implicit,
1057 LambdaCaptureKind Kind, VarDecl *Var,
1058 SourceLocation EllipsisLoc)
1059 : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) {
1062 Bits |= Capture_Implicit;
1066 Bits |= Capture_ByCopy;
1069 assert(!Var && "'this' capture cannot have a variable!");
1070 Bits |= Capture_This;
1074 Bits |= Capture_ByCopy;
1077 assert(Var && "capture must have a variable!");
1080 assert(!Var && "VLA type capture cannot have a variable!");
1083 DeclAndBits.setInt(Bits);
1086 LambdaCaptureKind LambdaCapture::getCaptureKind() const {
1087 if (capturesVLAType())
1089 bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy;
1091 return CapByCopy ? LCK_StarThis : LCK_This;
1092 return CapByCopy ? LCK_ByCopy : LCK_ByRef;
1095 LambdaExpr::LambdaExpr(QualType T, SourceRange IntroducerRange,
1096 LambdaCaptureDefault CaptureDefault,
1097 SourceLocation CaptureDefaultLoc,
1098 ArrayRef<LambdaCapture> Captures, bool ExplicitParams,
1099 bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1100 SourceLocation ClosingBrace,
1101 bool ContainsUnexpandedParameterPack)
1102 : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary, T->isDependentType(),
1103 T->isDependentType(), T->isDependentType(),
1104 ContainsUnexpandedParameterPack),
1105 IntroducerRange(IntroducerRange), CaptureDefaultLoc(CaptureDefaultLoc),
1106 NumCaptures(Captures.size()), CaptureDefault(CaptureDefault),
1107 ExplicitParams(ExplicitParams), ExplicitResultType(ExplicitResultType),
1108 ClosingBrace(ClosingBrace) {
1109 assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
1110 CXXRecordDecl *Class = getLambdaClass();
1111 CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData();
1113 // FIXME: Propagate "has unexpanded parameter pack" bit.
1116 const ASTContext &Context = Class->getASTContext();
1117 Data.NumCaptures = NumCaptures;
1118 Data.NumExplicitCaptures = 0;
1120 (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) * NumCaptures);
1121 LambdaCapture *ToCapture = Data.Captures;
1122 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
1123 if (Captures[I].isExplicit())
1124 ++Data.NumExplicitCaptures;
1126 *ToCapture++ = Captures[I];
1129 // Copy initialization expressions for the non-static data members.
1130 Stmt **Stored = getStoredStmts();
1131 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
1132 *Stored++ = CaptureInits[I];
1134 // Copy the body of the lambda.
1135 *Stored++ = getCallOperator()->getBody();
1138 LambdaExpr *LambdaExpr::Create(
1139 const ASTContext &Context, CXXRecordDecl *Class,
1140 SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault,
1141 SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures,
1142 bool ExplicitParams, bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1143 SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack) {
1144 // Determine the type of the expression (i.e., the type of the
1145 // function object we're creating).
1146 QualType T = Context.getTypeDeclType(Class);
1148 unsigned Size = totalSizeToAlloc<Stmt *>(Captures.size() + 1);
1149 void *Mem = Context.Allocate(Size);
1151 LambdaExpr(T, IntroducerRange, CaptureDefault, CaptureDefaultLoc,
1152 Captures, ExplicitParams, ExplicitResultType, CaptureInits,
1153 ClosingBrace, ContainsUnexpandedParameterPack);
1156 LambdaExpr *LambdaExpr::CreateDeserialized(const ASTContext &C,
1157 unsigned NumCaptures) {
1158 unsigned Size = totalSizeToAlloc<Stmt *>(NumCaptures + 1);
1159 void *Mem = C.Allocate(Size);
1160 return new (Mem) LambdaExpr(EmptyShell(), NumCaptures);
1163 bool LambdaExpr::isInitCapture(const LambdaCapture *C) const {
1164 return (C->capturesVariable() && C->getCapturedVar()->isInitCapture() &&
1165 (getCallOperator() == C->getCapturedVar()->getDeclContext()));
1168 LambdaExpr::capture_iterator LambdaExpr::capture_begin() const {
1169 return getLambdaClass()->getLambdaData().Captures;
1172 LambdaExpr::capture_iterator LambdaExpr::capture_end() const {
1173 return capture_begin() + NumCaptures;
1176 LambdaExpr::capture_range LambdaExpr::captures() const {
1177 return capture_range(capture_begin(), capture_end());
1180 LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const {
1181 return capture_begin();
1184 LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const {
1185 struct CXXRecordDecl::LambdaDefinitionData &Data
1186 = getLambdaClass()->getLambdaData();
1187 return Data.Captures + Data.NumExplicitCaptures;
1190 LambdaExpr::capture_range LambdaExpr::explicit_captures() const {
1191 return capture_range(explicit_capture_begin(), explicit_capture_end());
1194 LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const {
1195 return explicit_capture_end();
1198 LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const {
1199 return capture_end();
1202 LambdaExpr::capture_range LambdaExpr::implicit_captures() const {
1203 return capture_range(implicit_capture_begin(), implicit_capture_end());
1206 CXXRecordDecl *LambdaExpr::getLambdaClass() const {
1207 return getType()->getAsCXXRecordDecl();
1210 CXXMethodDecl *LambdaExpr::getCallOperator() const {
1211 CXXRecordDecl *Record = getLambdaClass();
1212 return Record->getLambdaCallOperator();
1215 TemplateParameterList *LambdaExpr::getTemplateParameterList() const {
1216 CXXRecordDecl *Record = getLambdaClass();
1217 return Record->getGenericLambdaTemplateParameterList();
1220 ArrayRef<NamedDecl *> LambdaExpr::getExplicitTemplateParameters() const {
1221 const CXXRecordDecl *Record = getLambdaClass();
1222 return Record->getLambdaExplicitTemplateParameters();
1225 CompoundStmt *LambdaExpr::getBody() const {
1226 // FIXME: this mutation in getBody is bogus. It should be
1227 // initialized in ASTStmtReader::VisitLambdaExpr, but for reasons I
1228 // don't understand, that doesn't work.
1229 if (!getStoredStmts()[NumCaptures])
1230 *const_cast<Stmt **>(&getStoredStmts()[NumCaptures]) =
1231 getCallOperator()->getBody();
1233 return static_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
1236 bool LambdaExpr::isMutable() const {
1237 return !getCallOperator()->isConst();
1240 ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
1241 bool CleanupsHaveSideEffects,
1242 ArrayRef<CleanupObject> objects)
1243 : FullExpr(ExprWithCleanupsClass, subexpr) {
1244 ExprWithCleanupsBits.CleanupsHaveSideEffects = CleanupsHaveSideEffects;
1245 ExprWithCleanupsBits.NumObjects = objects.size();
1246 for (unsigned i = 0, e = objects.size(); i != e; ++i)
1247 getTrailingObjects<CleanupObject>()[i] = objects[i];
1250 ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, Expr *subexpr,
1251 bool CleanupsHaveSideEffects,
1252 ArrayRef<CleanupObject> objects) {
1253 void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(objects.size()),
1254 alignof(ExprWithCleanups));
1256 ExprWithCleanups(subexpr, CleanupsHaveSideEffects, objects);
1259 ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
1260 : FullExpr(ExprWithCleanupsClass, empty) {
1261 ExprWithCleanupsBits.NumObjects = numObjects;
1264 ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C,
1266 unsigned numObjects) {
1267 void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(numObjects),
1268 alignof(ExprWithCleanups));
1269 return new (buffer) ExprWithCleanups(empty, numObjects);
1272 CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *TSI,
1273 SourceLocation LParenLoc,
1274 ArrayRef<Expr *> Args,
1275 SourceLocation RParenLoc)
1276 : Expr(CXXUnresolvedConstructExprClass,
1277 TSI->getType().getNonReferenceType(),
1278 (TSI->getType()->isLValueReferenceType()
1280 : TSI->getType()->isRValueReferenceType() ? VK_XValue
1283 TSI->getType()->isDependentType() ||
1284 TSI->getType()->getContainedDeducedType(),
1285 true, true, TSI->getType()->containsUnexpandedParameterPack()),
1286 TSI(TSI), LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
1287 CXXUnresolvedConstructExprBits.NumArgs = Args.size();
1288 auto **StoredArgs = getTrailingObjects<Expr *>();
1289 for (unsigned I = 0; I != Args.size(); ++I) {
1290 if (Args[I]->containsUnexpandedParameterPack())
1291 ExprBits.ContainsUnexpandedParameterPack = true;
1293 StoredArgs[I] = Args[I];
1297 CXXUnresolvedConstructExpr *CXXUnresolvedConstructExpr::Create(
1298 const ASTContext &Context, TypeSourceInfo *TSI, SourceLocation LParenLoc,
1299 ArrayRef<Expr *> Args, SourceLocation RParenLoc) {
1300 void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(Args.size()));
1301 return new (Mem) CXXUnresolvedConstructExpr(TSI, LParenLoc, Args, RParenLoc);
1304 CXXUnresolvedConstructExpr *
1305 CXXUnresolvedConstructExpr::CreateEmpty(const ASTContext &Context,
1307 void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(NumArgs));
1308 return new (Mem) CXXUnresolvedConstructExpr(EmptyShell(), NumArgs);
1311 SourceLocation CXXUnresolvedConstructExpr::getBeginLoc() const {
1312 return TSI->getTypeLoc().getBeginLoc();
1315 CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
1316 const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
1317 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1318 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1319 DeclarationNameInfo MemberNameInfo,
1320 const TemplateArgumentListInfo *TemplateArgs)
1321 : Expr(CXXDependentScopeMemberExprClass, Ctx.DependentTy, VK_LValue,
1322 OK_Ordinary, true, true, true,
1323 ((Base && Base->containsUnexpandedParameterPack()) ||
1324 (QualifierLoc && QualifierLoc.getNestedNameSpecifier()
1325 ->containsUnexpandedParameterPack()) ||
1326 MemberNameInfo.containsUnexpandedParameterPack())),
1327 Base(Base), BaseType(BaseType), QualifierLoc(QualifierLoc),
1328 MemberNameInfo(MemberNameInfo) {
1329 CXXDependentScopeMemberExprBits.IsArrow = IsArrow;
1330 CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo =
1331 (TemplateArgs != nullptr) || TemplateKWLoc.isValid();
1332 CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope =
1333 FirstQualifierFoundInScope != nullptr;
1334 CXXDependentScopeMemberExprBits.OperatorLoc = OperatorLoc;
1337 bool Dependent = true;
1338 bool InstantiationDependent = true;
1339 bool ContainsUnexpandedParameterPack = false;
1340 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1341 TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
1342 Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
1343 if (ContainsUnexpandedParameterPack)
1344 ExprBits.ContainsUnexpandedParameterPack = true;
1345 } else if (TemplateKWLoc.isValid()) {
1346 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1350 if (hasFirstQualifierFoundInScope())
1351 *getTrailingObjects<NamedDecl *>() = FirstQualifierFoundInScope;
1354 CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
1355 EmptyShell Empty, bool HasTemplateKWAndArgsInfo,
1356 bool HasFirstQualifierFoundInScope)
1357 : Expr(CXXDependentScopeMemberExprClass, Empty) {
1358 CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo =
1359 HasTemplateKWAndArgsInfo;
1360 CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope =
1361 HasFirstQualifierFoundInScope;
1364 CXXDependentScopeMemberExpr *CXXDependentScopeMemberExpr::Create(
1365 const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
1366 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1367 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1368 DeclarationNameInfo MemberNameInfo,
1369 const TemplateArgumentListInfo *TemplateArgs) {
1370 bool HasTemplateKWAndArgsInfo =
1371 (TemplateArgs != nullptr) || TemplateKWLoc.isValid();
1372 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1373 bool HasFirstQualifierFoundInScope = FirstQualifierFoundInScope != nullptr;
1375 unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo,
1376 TemplateArgumentLoc, NamedDecl *>(
1377 HasTemplateKWAndArgsInfo, NumTemplateArgs, HasFirstQualifierFoundInScope);
1379 void *Mem = Ctx.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
1380 return new (Mem) CXXDependentScopeMemberExpr(
1381 Ctx, Base, BaseType, IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
1382 FirstQualifierFoundInScope, MemberNameInfo, TemplateArgs);
1385 CXXDependentScopeMemberExpr *CXXDependentScopeMemberExpr::CreateEmpty(
1386 const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo,
1387 unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope) {
1388 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
1390 unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo,
1391 TemplateArgumentLoc, NamedDecl *>(
1392 HasTemplateKWAndArgsInfo, NumTemplateArgs, HasFirstQualifierFoundInScope);
1394 void *Mem = Ctx.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
1395 return new (Mem) CXXDependentScopeMemberExpr(
1396 EmptyShell(), HasTemplateKWAndArgsInfo, HasFirstQualifierFoundInScope);
1399 static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
1400 UnresolvedSetIterator end) {
1402 NamedDecl *decl = *begin;
1403 if (isa<UnresolvedUsingValueDecl>(decl))
1406 // Unresolved member expressions should only contain methods and
1407 // method templates.
1408 if (cast<CXXMethodDecl>(decl->getUnderlyingDecl()->getAsFunction())
1411 } while (++begin != end);
1416 UnresolvedMemberExpr::UnresolvedMemberExpr(
1417 const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
1418 QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
1419 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1420 const DeclarationNameInfo &MemberNameInfo,
1421 const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
1422 UnresolvedSetIterator End)
1424 UnresolvedMemberExprClass, Context, QualifierLoc, TemplateKWLoc,
1425 MemberNameInfo, TemplateArgs, Begin, End,
1427 ((Base && Base->isTypeDependent()) || BaseType->isDependentType()),
1428 ((Base && Base->isInstantiationDependent()) ||
1429 BaseType->isInstantiationDependentType()),
1430 // Contains unexpanded parameter pack
1431 ((Base && Base->containsUnexpandedParameterPack()) ||
1432 BaseType->containsUnexpandedParameterPack())),
1433 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
1434 UnresolvedMemberExprBits.IsArrow = IsArrow;
1435 UnresolvedMemberExprBits.HasUnresolvedUsing = HasUnresolvedUsing;
1437 // Check whether all of the members are non-static member functions,
1438 // and if so, mark give this bound-member type instead of overload type.
1439 if (hasOnlyNonStaticMemberFunctions(Begin, End))
1440 setType(Context.BoundMemberTy);
1443 UnresolvedMemberExpr::UnresolvedMemberExpr(EmptyShell Empty,
1444 unsigned NumResults,
1445 bool HasTemplateKWAndArgsInfo)
1446 : OverloadExpr(UnresolvedMemberExprClass, Empty, NumResults,
1447 HasTemplateKWAndArgsInfo) {}
1449 bool UnresolvedMemberExpr::isImplicitAccess() const {
1453 return cast<Expr>(Base)->isImplicitCXXThis();
1456 UnresolvedMemberExpr *UnresolvedMemberExpr::Create(
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 unsigned NumResults = End - Begin;
1464 bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
1465 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1466 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
1467 TemplateArgumentLoc>(
1468 NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
1469 void *Mem = Context.Allocate(Size, alignof(UnresolvedMemberExpr));
1470 return new (Mem) UnresolvedMemberExpr(
1471 Context, HasUnresolvedUsing, Base, BaseType, IsArrow, OperatorLoc,
1472 QualifierLoc, TemplateKWLoc, MemberNameInfo, TemplateArgs, Begin, End);
1475 UnresolvedMemberExpr *UnresolvedMemberExpr::CreateEmpty(
1476 const ASTContext &Context, unsigned NumResults,
1477 bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) {
1478 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
1479 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
1480 TemplateArgumentLoc>(
1481 NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
1482 void *Mem = Context.Allocate(Size, alignof(UnresolvedMemberExpr));
1484 UnresolvedMemberExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo);
1487 CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() {
1488 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1490 // If there was a nested name specifier, it names the naming class.
1491 // It can't be dependent: after all, we were actually able to do the
1493 CXXRecordDecl *Record = nullptr;
1494 auto *NNS = getQualifier();
1495 if (NNS && NNS->getKind() != NestedNameSpecifier::Super) {
1496 const Type *T = getQualifier()->getAsType();
1497 assert(T && "qualifier in member expression does not name type");
1498 Record = T->getAsCXXRecordDecl();
1499 assert(Record && "qualifier in member expression does not name record");
1501 // Otherwise the naming class must have been the base class.
1503 QualType BaseType = getBaseType().getNonReferenceType();
1505 const auto *PT = BaseType->getAs<PointerType>();
1506 assert(PT && "base of arrow member access is not pointer");
1507 BaseType = PT->getPointeeType();
1510 Record = BaseType->getAsCXXRecordDecl();
1511 assert(Record && "base of member expression does not name record");
1518 SizeOfPackExpr::Create(ASTContext &Context, SourceLocation OperatorLoc,
1519 NamedDecl *Pack, SourceLocation PackLoc,
1520 SourceLocation RParenLoc,
1521 Optional<unsigned> Length,
1522 ArrayRef<TemplateArgument> PartialArgs) {
1524 Context.Allocate(totalSizeToAlloc<TemplateArgument>(PartialArgs.size()));
1525 return new (Storage) SizeOfPackExpr(Context.getSizeType(), OperatorLoc, Pack,
1526 PackLoc, RParenLoc, Length, PartialArgs);
1529 SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context,
1530 unsigned NumPartialArgs) {
1532 Context.Allocate(totalSizeToAlloc<TemplateArgument>(NumPartialArgs));
1533 return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs);
1536 SubstNonTypeTemplateParmPackExpr::
1537 SubstNonTypeTemplateParmPackExpr(QualType T,
1538 ExprValueKind ValueKind,
1539 NonTypeTemplateParmDecl *Param,
1540 SourceLocation NameLoc,
1541 const TemplateArgument &ArgPack)
1542 : Expr(SubstNonTypeTemplateParmPackExprClass, T, ValueKind, OK_Ordinary,
1543 true, true, true, true),
1544 Param(Param), Arguments(ArgPack.pack_begin()),
1545 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) {}
1547 TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1548 return TemplateArgument(llvm::makeArrayRef(Arguments, NumArguments));
1551 FunctionParmPackExpr::FunctionParmPackExpr(QualType T, VarDecl *ParamPack,
1552 SourceLocation NameLoc,
1554 VarDecl *const *Params)
1555 : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary, true, true,
1557 ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1559 std::uninitialized_copy(Params, Params + NumParams,
1560 getTrailingObjects<VarDecl *>());
1563 FunctionParmPackExpr *
1564 FunctionParmPackExpr::Create(const ASTContext &Context, QualType T,
1565 VarDecl *ParamPack, SourceLocation NameLoc,
1566 ArrayRef<VarDecl *> Params) {
1567 return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(Params.size())))
1568 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1571 FunctionParmPackExpr *
1572 FunctionParmPackExpr::CreateEmpty(const ASTContext &Context,
1573 unsigned NumParams) {
1574 return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(NumParams)))
1575 FunctionParmPackExpr(QualType(), nullptr, SourceLocation(), 0, nullptr);
1578 void MaterializeTemporaryExpr::setExtendingDecl(const ValueDecl *ExtendedBy,
1579 unsigned ManglingNumber) {
1580 // We only need extra state if we have to remember more than just the Stmt.
1584 // We may need to allocate extra storage for the mangling number and the
1585 // extended-by ValueDecl.
1586 if (!State.is<ExtraState *>()) {
1587 auto *ES = new (ExtendedBy->getASTContext()) ExtraState;
1588 ES->Temporary = State.get<Stmt *>();
1592 auto ES = State.get<ExtraState *>();
1593 ES->ExtendingDecl = ExtendedBy;
1594 ES->ManglingNumber = ManglingNumber;
1597 TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1598 ArrayRef<TypeSourceInfo *> Args,
1599 SourceLocation RParenLoc,
1601 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary,
1602 /*TypeDependent=*/false,
1603 /*ValueDependent=*/false,
1604 /*InstantiationDependent=*/false,
1605 /*ContainsUnexpandedParameterPack=*/false),
1606 Loc(Loc), RParenLoc(RParenLoc) {
1607 TypeTraitExprBits.Kind = Kind;
1608 TypeTraitExprBits.Value = Value;
1609 TypeTraitExprBits.NumArgs = Args.size();
1611 auto **ToArgs = getTrailingObjects<TypeSourceInfo *>();
1613 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1614 if (Args[I]->getType()->isDependentType())
1615 setValueDependent(true);
1616 if (Args[I]->getType()->isInstantiationDependentType())
1617 setInstantiationDependent(true);
1618 if (Args[I]->getType()->containsUnexpandedParameterPack())
1619 setContainsUnexpandedParameterPack(true);
1621 ToArgs[I] = Args[I];
1625 TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T,
1628 ArrayRef<TypeSourceInfo *> Args,
1629 SourceLocation RParenLoc,
1631 void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(Args.size()));
1632 return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1635 TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const ASTContext &C,
1637 void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(NumArgs));
1638 return new (Mem) TypeTraitExpr(EmptyShell());
1641 CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config,
1642 ArrayRef<Expr *> Args, QualType Ty,
1643 ExprValueKind VK, SourceLocation RP,
1644 unsigned MinNumArgs)
1645 : CallExpr(CUDAKernelCallExprClass, Fn, /*PreArgs=*/Config, Args, Ty, VK,
1646 RP, MinNumArgs, NotADL) {}
1648 CUDAKernelCallExpr::CUDAKernelCallExpr(unsigned NumArgs, EmptyShell Empty)
1649 : CallExpr(CUDAKernelCallExprClass, /*NumPreArgs=*/END_PREARG, NumArgs,
1652 CUDAKernelCallExpr *
1653 CUDAKernelCallExpr::Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config,
1654 ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
1655 SourceLocation RP, unsigned MinNumArgs) {
1656 // Allocate storage for the trailing objects of CallExpr.
1657 unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
1658 unsigned SizeOfTrailingObjects =
1659 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/END_PREARG, NumArgs);
1660 void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects,
1661 alignof(CUDAKernelCallExpr));
1662 return new (Mem) CUDAKernelCallExpr(Fn, Config, Args, Ty, VK, RP, MinNumArgs);
1665 CUDAKernelCallExpr *CUDAKernelCallExpr::CreateEmpty(const ASTContext &Ctx,
1668 // Allocate storage for the trailing objects of CallExpr.
1669 unsigned SizeOfTrailingObjects =
1670 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/END_PREARG, NumArgs);
1671 void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects,
1672 alignof(CUDAKernelCallExpr));
1673 return new (Mem) CUDAKernelCallExpr(NumArgs, Empty);