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/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"
42 using namespace clang;
44 //===----------------------------------------------------------------------===//
45 // Child Iterators for iterating over subexpressions/substatements
46 //===----------------------------------------------------------------------===//
48 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
53 if (getNumArgs() != 2)
56 switch (getOperator()) {
57 case OO_Call: case OO_Subscript:
64 CXXRewrittenBinaryOperator::DecomposedForm
65 CXXRewrittenBinaryOperator::getDecomposedForm() const {
66 DecomposedForm Result = {};
67 const Expr *E = getSemanticForm()->IgnoreImplicit();
69 // Remove an outer '!' if it exists (only happens for a '!=' rewrite).
70 bool SkippedNot = false;
71 if (auto *NotEq = dyn_cast<UnaryOperator>(E)) {
72 assert(NotEq->getOpcode() == UO_LNot);
73 E = NotEq->getSubExpr()->IgnoreImplicit();
77 // Decompose the outer binary operator.
78 if (auto *BO = dyn_cast<BinaryOperator>(E)) {
79 assert(!SkippedNot || BO->getOpcode() == BO_EQ);
80 Result.Opcode = SkippedNot ? BO_NE : BO->getOpcode();
81 Result.LHS = BO->getLHS();
82 Result.RHS = BO->getRHS();
83 Result.InnerBinOp = BO;
84 } else if (auto *BO = dyn_cast<CXXOperatorCallExpr>(E)) {
85 assert(!SkippedNot || BO->getOperator() == OO_EqualEqual);
86 assert(BO->isInfixBinaryOp());
87 switch (BO->getOperator()) {
88 case OO_Less: Result.Opcode = BO_LT; break;
89 case OO_LessEqual: Result.Opcode = BO_LE; break;
90 case OO_Greater: Result.Opcode = BO_GT; break;
91 case OO_GreaterEqual: Result.Opcode = BO_GE; break;
92 case OO_Spaceship: Result.Opcode = BO_Cmp; break;
93 case OO_EqualEqual: Result.Opcode = SkippedNot ? BO_NE : BO_EQ; break;
94 default: llvm_unreachable("unexpected binop in rewritten operator expr");
96 Result.LHS = BO->getArg(0);
97 Result.RHS = BO->getArg(1);
98 Result.InnerBinOp = BO;
100 llvm_unreachable("unexpected rewritten operator form");
103 // Put the operands in the right order for == and !=, and canonicalize the
104 // <=> subexpression onto the LHS for all other forms.
106 std::swap(Result.LHS, Result.RHS);
108 // If this isn't a spaceship rewrite, we're done.
109 if (Result.Opcode == BO_EQ || Result.Opcode == BO_NE)
112 // Otherwise, we expect a <=> to now be on the LHS.
113 E = Result.LHS->IgnoreImplicitAsWritten();
114 if (auto *BO = dyn_cast<BinaryOperator>(E)) {
115 assert(BO->getOpcode() == BO_Cmp);
116 Result.LHS = BO->getLHS();
117 Result.RHS = BO->getRHS();
118 Result.InnerBinOp = BO;
119 } else if (auto *BO = dyn_cast<CXXOperatorCallExpr>(E)) {
120 assert(BO->getOperator() == OO_Spaceship);
121 Result.LHS = BO->getArg(0);
122 Result.RHS = BO->getArg(1);
123 Result.InnerBinOp = BO;
125 llvm_unreachable("unexpected rewritten operator form");
128 // Put the comparison operands in the right order.
130 std::swap(Result.LHS, Result.RHS);
134 bool CXXTypeidExpr::isPotentiallyEvaluated() const {
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 const Expr *E = getExprOperand();
142 if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl())
143 if (RD->isPolymorphic() && E->isGLValue())
149 QualType CXXTypeidExpr::getTypeOperand(ASTContext &Context) const {
150 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
152 return Context.getUnqualifiedArrayType(
153 Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
156 QualType CXXUuidofExpr::getTypeOperand(ASTContext &Context) const {
157 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
159 return Context.getUnqualifiedArrayType(
160 Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
163 // CXXScalarValueInitExpr
164 SourceLocation CXXScalarValueInitExpr::getBeginLoc() const {
165 return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : getRParenLoc();
169 CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
170 FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
171 bool UsualArrayDeleteWantsSize,
172 ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens,
173 Optional<Expr *> ArraySize,
174 InitializationStyle InitializationStyle,
175 Expr *Initializer, QualType Ty,
176 TypeSourceInfo *AllocatedTypeInfo, SourceRange Range,
177 SourceRange DirectInitRange)
178 : Expr(CXXNewExprClass, Ty, VK_RValue, OK_Ordinary),
179 OperatorNew(OperatorNew), OperatorDelete(OperatorDelete),
180 AllocatedTypeInfo(AllocatedTypeInfo), Range(Range),
181 DirectInitRange(DirectInitRange) {
183 assert((Initializer != nullptr || InitializationStyle == NoInit) &&
184 "Only NoInit can have no initializer!");
186 CXXNewExprBits.IsGlobalNew = IsGlobalNew;
187 CXXNewExprBits.IsArray = ArraySize.hasValue();
188 CXXNewExprBits.ShouldPassAlignment = ShouldPassAlignment;
189 CXXNewExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize;
190 CXXNewExprBits.StoredInitializationStyle =
191 Initializer ? InitializationStyle + 1 : 0;
192 bool IsParenTypeId = TypeIdParens.isValid();
193 CXXNewExprBits.IsParenTypeId = IsParenTypeId;
194 CXXNewExprBits.NumPlacementArgs = PlacementArgs.size();
197 getTrailingObjects<Stmt *>()[arraySizeOffset()] = *ArraySize;
199 getTrailingObjects<Stmt *>()[initExprOffset()] = Initializer;
200 for (unsigned I = 0; I != PlacementArgs.size(); ++I)
201 getTrailingObjects<Stmt *>()[placementNewArgsOffset() + I] =
204 getTrailingObjects<SourceRange>()[0] = TypeIdParens;
206 switch (getInitializationStyle()) {
208 this->Range.setEnd(DirectInitRange.getEnd());
211 this->Range.setEnd(getInitializer()->getSourceRange().getEnd());
215 this->Range.setEnd(TypeIdParens.getEnd());
219 setDependence(computeDependence(this));
222 CXXNewExpr::CXXNewExpr(EmptyShell Empty, bool IsArray,
223 unsigned NumPlacementArgs, bool IsParenTypeId)
224 : Expr(CXXNewExprClass, Empty) {
225 CXXNewExprBits.IsArray = IsArray;
226 CXXNewExprBits.NumPlacementArgs = NumPlacementArgs;
227 CXXNewExprBits.IsParenTypeId = IsParenTypeId;
231 CXXNewExpr::Create(const ASTContext &Ctx, bool IsGlobalNew,
232 FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete,
233 bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize,
234 ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens,
235 Optional<Expr *> ArraySize,
236 InitializationStyle InitializationStyle, Expr *Initializer,
237 QualType Ty, TypeSourceInfo *AllocatedTypeInfo,
238 SourceRange Range, SourceRange DirectInitRange) {
239 bool IsArray = ArraySize.hasValue();
240 bool HasInit = Initializer != nullptr;
241 unsigned NumPlacementArgs = PlacementArgs.size();
242 bool IsParenTypeId = TypeIdParens.isValid();
244 Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>(
245 IsArray + HasInit + NumPlacementArgs, IsParenTypeId),
246 alignof(CXXNewExpr));
248 CXXNewExpr(IsGlobalNew, OperatorNew, OperatorDelete, ShouldPassAlignment,
249 UsualArrayDeleteWantsSize, PlacementArgs, TypeIdParens,
250 ArraySize, InitializationStyle, Initializer, Ty,
251 AllocatedTypeInfo, Range, DirectInitRange);
254 CXXNewExpr *CXXNewExpr::CreateEmpty(const ASTContext &Ctx, bool IsArray,
255 bool HasInit, unsigned NumPlacementArgs,
256 bool IsParenTypeId) {
258 Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>(
259 IsArray + HasInit + NumPlacementArgs, IsParenTypeId),
260 alignof(CXXNewExpr));
262 CXXNewExpr(EmptyShell(), IsArray, NumPlacementArgs, IsParenTypeId);
265 bool CXXNewExpr::shouldNullCheckAllocation() const {
266 return getOperatorNew()
268 ->castAs<FunctionProtoType>()
270 !getOperatorNew()->isReservedGlobalPlacementOperator();
274 QualType CXXDeleteExpr::getDestroyedType() const {
275 const Expr *Arg = getArgument();
277 // For a destroying operator delete, we may have implicitly converted the
278 // pointer type to the type of the parameter of the 'operator delete'
280 while (const auto *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
281 if (ICE->getCastKind() == CK_DerivedToBase ||
282 ICE->getCastKind() == CK_UncheckedDerivedToBase ||
283 ICE->getCastKind() == CK_NoOp) {
284 assert((ICE->getCastKind() == CK_NoOp ||
285 getOperatorDelete()->isDestroyingOperatorDelete()) &&
286 "only a destroying operator delete can have a converted arg");
287 Arg = ICE->getSubExpr();
292 // The type-to-delete may not be a pointer if it's a dependent type.
293 const QualType ArgType = Arg->getType();
295 if (ArgType->isDependentType() && !ArgType->isPointerType())
298 return ArgType->castAs<PointerType>()->getPointeeType();
301 // CXXPseudoDestructorExpr
302 PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
304 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
307 CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(
308 const ASTContext &Context, Expr *Base, bool isArrow,
309 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
310 TypeSourceInfo *ScopeType, SourceLocation ColonColonLoc,
311 SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType)
312 : Expr(CXXPseudoDestructorExprClass, Context.BoundMemberTy, VK_RValue,
314 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
315 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
316 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
317 DestroyedType(DestroyedType) {
318 setDependence(computeDependence(this));
321 QualType CXXPseudoDestructorExpr::getDestroyedType() const {
322 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
323 return TInfo->getType();
328 SourceLocation CXXPseudoDestructorExpr::getEndLoc() const {
329 SourceLocation End = DestroyedType.getLocation();
330 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
331 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
335 // UnresolvedLookupExpr
336 UnresolvedLookupExpr::UnresolvedLookupExpr(
337 const ASTContext &Context, CXXRecordDecl *NamingClass,
338 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
339 const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
340 const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
341 UnresolvedSetIterator End)
342 : OverloadExpr(UnresolvedLookupExprClass, Context, QualifierLoc,
343 TemplateKWLoc, NameInfo, TemplateArgs, Begin, End, false,
345 NamingClass(NamingClass) {
346 UnresolvedLookupExprBits.RequiresADL = RequiresADL;
347 UnresolvedLookupExprBits.Overloaded = Overloaded;
350 UnresolvedLookupExpr::UnresolvedLookupExpr(EmptyShell Empty,
352 bool HasTemplateKWAndArgsInfo)
353 : OverloadExpr(UnresolvedLookupExprClass, Empty, NumResults,
354 HasTemplateKWAndArgsInfo) {}
356 UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
357 const ASTContext &Context, CXXRecordDecl *NamingClass,
358 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
359 bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin,
360 UnresolvedSetIterator End) {
361 unsigned NumResults = End - Begin;
362 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
363 TemplateArgumentLoc>(NumResults, 0, 0);
364 void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
365 return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
366 SourceLocation(), NameInfo, RequiresADL,
367 Overloaded, nullptr, Begin, End);
370 UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
371 const ASTContext &Context, CXXRecordDecl *NamingClass,
372 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
373 const DeclarationNameInfo &NameInfo, bool RequiresADL,
374 const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
375 UnresolvedSetIterator End) {
376 assert(Args || TemplateKWLoc.isValid());
377 unsigned NumResults = End - Begin;
378 unsigned NumTemplateArgs = Args ? Args->size() : 0;
380 totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
381 TemplateArgumentLoc>(NumResults, 1, NumTemplateArgs);
382 void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
383 return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
384 TemplateKWLoc, NameInfo, RequiresADL,
385 /*Overloaded*/ true, Args, Begin, End);
388 UnresolvedLookupExpr *UnresolvedLookupExpr::CreateEmpty(
389 const ASTContext &Context, unsigned NumResults,
390 bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) {
391 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
392 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
393 TemplateArgumentLoc>(
394 NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
395 void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
397 UnresolvedLookupExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo);
400 OverloadExpr::OverloadExpr(StmtClass SC, const ASTContext &Context,
401 NestedNameSpecifierLoc QualifierLoc,
402 SourceLocation TemplateKWLoc,
403 const DeclarationNameInfo &NameInfo,
404 const TemplateArgumentListInfo *TemplateArgs,
405 UnresolvedSetIterator Begin,
406 UnresolvedSetIterator End, bool KnownDependent,
407 bool KnownInstantiationDependent,
408 bool KnownContainsUnexpandedParameterPack)
409 : Expr(SC, Context.OverloadTy, VK_LValue, OK_Ordinary), NameInfo(NameInfo),
410 QualifierLoc(QualifierLoc) {
411 unsigned NumResults = End - Begin;
412 OverloadExprBits.NumResults = NumResults;
413 OverloadExprBits.HasTemplateKWAndArgsInfo =
414 (TemplateArgs != nullptr ) || TemplateKWLoc.isValid();
417 // Copy the results to the trailing array past UnresolvedLookupExpr
418 // or UnresolvedMemberExpr.
419 DeclAccessPair *Results = getTrailingResults();
420 memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair));
424 auto Deps = TemplateArgumentDependence::None;
425 getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(
426 TemplateKWLoc, *TemplateArgs, getTrailingTemplateArgumentLoc(), Deps);
427 } else if (TemplateKWLoc.isValid()) {
428 getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
431 setDependence(computeDependence(this, KnownDependent,
432 KnownInstantiationDependent,
433 KnownContainsUnexpandedParameterPack));
434 if (isTypeDependent())
435 setType(Context.DependentTy);
438 OverloadExpr::OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults,
439 bool HasTemplateKWAndArgsInfo)
441 OverloadExprBits.NumResults = NumResults;
442 OverloadExprBits.HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
445 // DependentScopeDeclRefExpr
446 DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(
447 QualType Ty, NestedNameSpecifierLoc QualifierLoc,
448 SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
449 const TemplateArgumentListInfo *Args)
450 : Expr(DependentScopeDeclRefExprClass, Ty, VK_LValue, OK_Ordinary),
451 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {
452 DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo =
453 (Args != nullptr) || TemplateKWLoc.isValid();
455 auto Deps = TemplateArgumentDependence::None;
456 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
457 TemplateKWLoc, *Args, getTrailingObjects<TemplateArgumentLoc>(), Deps);
458 } else if (TemplateKWLoc.isValid()) {
459 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
462 setDependence(computeDependence(this));
465 DependentScopeDeclRefExpr *DependentScopeDeclRefExpr::Create(
466 const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
467 SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
468 const TemplateArgumentListInfo *Args) {
469 assert(QualifierLoc && "should be created for dependent qualifiers");
470 bool HasTemplateKWAndArgsInfo = Args || TemplateKWLoc.isValid();
472 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
473 HasTemplateKWAndArgsInfo, Args ? Args->size() : 0);
474 void *Mem = Context.Allocate(Size);
475 return new (Mem) DependentScopeDeclRefExpr(Context.DependentTy, QualifierLoc,
476 TemplateKWLoc, NameInfo, Args);
479 DependentScopeDeclRefExpr *
480 DependentScopeDeclRefExpr::CreateEmpty(const ASTContext &Context,
481 bool HasTemplateKWAndArgsInfo,
482 unsigned NumTemplateArgs) {
483 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
485 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
486 HasTemplateKWAndArgsInfo, NumTemplateArgs);
487 void *Mem = Context.Allocate(Size);
488 auto *E = new (Mem) DependentScopeDeclRefExpr(
489 QualType(), NestedNameSpecifierLoc(), SourceLocation(),
490 DeclarationNameInfo(), nullptr);
491 E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo =
492 HasTemplateKWAndArgsInfo;
496 SourceLocation CXXConstructExpr::getBeginLoc() const {
497 if (isa<CXXTemporaryObjectExpr>(this))
498 return cast<CXXTemporaryObjectExpr>(this)->getBeginLoc();
499 return getLocation();
502 SourceLocation CXXConstructExpr::getEndLoc() const {
503 if (isa<CXXTemporaryObjectExpr>(this))
504 return cast<CXXTemporaryObjectExpr>(this)->getEndLoc();
506 if (ParenOrBraceRange.isValid())
507 return ParenOrBraceRange.getEnd();
509 SourceLocation End = getLocation();
510 for (unsigned I = getNumArgs(); I > 0; --I) {
511 const Expr *Arg = getArg(I-1);
512 if (!Arg->isDefaultArgument()) {
513 SourceLocation NewEnd = Arg->getEndLoc();
514 if (NewEnd.isValid()) {
524 CXXOperatorCallExpr::CXXOperatorCallExpr(OverloadedOperatorKind OpKind,
525 Expr *Fn, ArrayRef<Expr *> Args,
526 QualType Ty, ExprValueKind VK,
527 SourceLocation OperatorLoc,
528 FPOptionsOverride FPFeatures,
530 : CallExpr(CXXOperatorCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
531 OperatorLoc, /*MinNumArgs=*/0, UsesADL) {
532 CXXOperatorCallExprBits.OperatorKind = OpKind;
534 (CXXOperatorCallExprBits.OperatorKind == static_cast<unsigned>(OpKind)) &&
535 "OperatorKind overflow!");
536 Range = getSourceRangeImpl();
537 Overrides = FPFeatures;
540 CXXOperatorCallExpr::CXXOperatorCallExpr(unsigned NumArgs, EmptyShell Empty)
541 : CallExpr(CXXOperatorCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {}
543 CXXOperatorCallExpr *
544 CXXOperatorCallExpr::Create(const ASTContext &Ctx,
545 OverloadedOperatorKind OpKind, Expr *Fn,
546 ArrayRef<Expr *> Args, QualType Ty,
547 ExprValueKind VK, SourceLocation OperatorLoc,
548 FPOptionsOverride FPFeatures, ADLCallKind UsesADL) {
549 // Allocate storage for the trailing objects of CallExpr.
550 unsigned NumArgs = Args.size();
551 unsigned SizeOfTrailingObjects =
552 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
553 void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects,
554 alignof(CXXOperatorCallExpr));
555 return new (Mem) CXXOperatorCallExpr(OpKind, Fn, Args, Ty, VK, OperatorLoc,
556 FPFeatures, UsesADL);
559 CXXOperatorCallExpr *CXXOperatorCallExpr::CreateEmpty(const ASTContext &Ctx,
562 // Allocate storage for the trailing objects of CallExpr.
563 unsigned SizeOfTrailingObjects =
564 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
565 void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects,
566 alignof(CXXOperatorCallExpr));
567 return new (Mem) CXXOperatorCallExpr(NumArgs, Empty);
570 SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
571 OverloadedOperatorKind Kind = getOperator();
572 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
573 if (getNumArgs() == 1)
575 return SourceRange(getOperatorLoc(), getArg(0)->getEndLoc());
578 return SourceRange(getArg(0)->getBeginLoc(), getOperatorLoc());
579 } else if (Kind == OO_Arrow) {
580 return SourceRange(getArg(0)->getBeginLoc(), getOperatorLoc());
581 } else if (Kind == OO_Call) {
582 return SourceRange(getArg(0)->getBeginLoc(), getRParenLoc());
583 } else if (Kind == OO_Subscript) {
584 return SourceRange(getArg(0)->getBeginLoc(), getRParenLoc());
585 } else if (getNumArgs() == 1) {
586 return SourceRange(getOperatorLoc(), getArg(0)->getEndLoc());
587 } else if (getNumArgs() == 2) {
588 return SourceRange(getArg(0)->getBeginLoc(), getArg(1)->getEndLoc());
590 return getOperatorLoc();
594 CXXMemberCallExpr::CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args,
595 QualType Ty, ExprValueKind VK,
596 SourceLocation RP, unsigned MinNumArgs)
597 : CallExpr(CXXMemberCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, RP,
598 MinNumArgs, NotADL) {}
600 CXXMemberCallExpr::CXXMemberCallExpr(unsigned NumArgs, EmptyShell Empty)
601 : CallExpr(CXXMemberCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {}
603 CXXMemberCallExpr *CXXMemberCallExpr::Create(const ASTContext &Ctx, Expr *Fn,
604 ArrayRef<Expr *> Args, QualType Ty,
607 unsigned MinNumArgs) {
608 // Allocate storage for the trailing objects of CallExpr.
609 unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
610 unsigned SizeOfTrailingObjects =
611 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
612 void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects,
613 alignof(CXXMemberCallExpr));
614 return new (Mem) CXXMemberCallExpr(Fn, Args, Ty, VK, RP, MinNumArgs);
617 CXXMemberCallExpr *CXXMemberCallExpr::CreateEmpty(const ASTContext &Ctx,
620 // Allocate storage for the trailing objects of CallExpr.
621 unsigned SizeOfTrailingObjects =
622 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
623 void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects,
624 alignof(CXXMemberCallExpr));
625 return new (Mem) CXXMemberCallExpr(NumArgs, Empty);
628 Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
629 const Expr *Callee = getCallee()->IgnoreParens();
630 if (const auto *MemExpr = dyn_cast<MemberExpr>(Callee))
631 return MemExpr->getBase();
632 if (const auto *BO = dyn_cast<BinaryOperator>(Callee))
633 if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
636 // FIXME: Will eventually need to cope with member pointers.
640 QualType CXXMemberCallExpr::getObjectType() const {
641 QualType Ty = getImplicitObjectArgument()->getType();
642 if (Ty->isPointerType())
643 Ty = Ty->getPointeeType();
647 CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
648 if (const auto *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
649 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
651 // FIXME: Will eventually need to cope with member pointers.
655 CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
656 Expr* ThisArg = getImplicitObjectArgument();
660 if (ThisArg->getType()->isAnyPointerType())
661 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
663 return ThisArg->getType()->getAsCXXRecordDecl();
666 //===----------------------------------------------------------------------===//
668 //===----------------------------------------------------------------------===//
670 /// getCastName - Get the name of the C++ cast being used, e.g.,
671 /// "static_cast", "dynamic_cast", "reinterpret_cast", or
672 /// "const_cast". The returned pointer must not be freed.
673 const char *CXXNamedCastExpr::getCastName() const {
674 switch (getStmtClass()) {
675 case CXXStaticCastExprClass: return "static_cast";
676 case CXXDynamicCastExprClass: return "dynamic_cast";
677 case CXXReinterpretCastExprClass: return "reinterpret_cast";
678 case CXXConstCastExprClass: return "const_cast";
679 case CXXAddrspaceCastExprClass: return "addrspace_cast";
680 default: return "<invalid cast>";
684 CXXStaticCastExpr *CXXStaticCastExpr::Create(const ASTContext &C, QualType T,
686 CastKind K, Expr *Op,
687 const CXXCastPath *BasePath,
688 TypeSourceInfo *WrittenTy,
690 SourceLocation RParenLoc,
691 SourceRange AngleBrackets) {
692 unsigned PathSize = (BasePath ? BasePath->size() : 0);
693 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
695 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
696 RParenLoc, AngleBrackets);
698 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
699 E->getTrailingObjects<CXXBaseSpecifier *>());
703 CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(const ASTContext &C,
705 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
706 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
709 CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T,
711 CastKind K, Expr *Op,
712 const CXXCastPath *BasePath,
713 TypeSourceInfo *WrittenTy,
715 SourceLocation RParenLoc,
716 SourceRange AngleBrackets) {
717 unsigned PathSize = (BasePath ? BasePath->size() : 0);
718 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
720 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
721 RParenLoc, AngleBrackets);
723 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
724 E->getTrailingObjects<CXXBaseSpecifier *>());
728 CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(const ASTContext &C,
730 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
731 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
734 /// isAlwaysNull - Return whether the result of the dynamic_cast is proven
735 /// to always be null. For example:
738 /// struct B final : A { };
741 /// C *f(B* b) { return dynamic_cast<C*>(b); }
742 bool CXXDynamicCastExpr::isAlwaysNull() const
744 QualType SrcType = getSubExpr()->getType();
745 QualType DestType = getType();
747 if (const auto *SrcPTy = SrcType->getAs<PointerType>()) {
748 SrcType = SrcPTy->getPointeeType();
749 DestType = DestType->castAs<PointerType>()->getPointeeType();
752 if (DestType->isVoidType())
756 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
758 if (!SrcRD->hasAttr<FinalAttr>())
762 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
764 return !DestRD->isDerivedFrom(SrcRD);
767 CXXReinterpretCastExpr *
768 CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T,
769 ExprValueKind VK, CastKind K, Expr *Op,
770 const CXXCastPath *BasePath,
771 TypeSourceInfo *WrittenTy, SourceLocation L,
772 SourceLocation RParenLoc,
773 SourceRange AngleBrackets) {
774 unsigned PathSize = (BasePath ? BasePath->size() : 0);
775 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
777 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
778 RParenLoc, AngleBrackets);
780 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
781 E->getTrailingObjects<CXXBaseSpecifier *>());
785 CXXReinterpretCastExpr *
786 CXXReinterpretCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) {
787 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
788 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
791 CXXConstCastExpr *CXXConstCastExpr::Create(const ASTContext &C, QualType T,
792 ExprValueKind VK, Expr *Op,
793 TypeSourceInfo *WrittenTy,
795 SourceLocation RParenLoc,
796 SourceRange AngleBrackets) {
797 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets);
800 CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(const ASTContext &C) {
801 return new (C) CXXConstCastExpr(EmptyShell());
804 CXXAddrspaceCastExpr *
805 CXXAddrspaceCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK,
806 CastKind K, Expr *Op, TypeSourceInfo *WrittenTy,
807 SourceLocation L, SourceLocation RParenLoc,
808 SourceRange AngleBrackets) {
809 return new (C) CXXAddrspaceCastExpr(T, VK, K, Op, WrittenTy, L, RParenLoc,
813 CXXAddrspaceCastExpr *CXXAddrspaceCastExpr::CreateEmpty(const ASTContext &C) {
814 return new (C) CXXAddrspaceCastExpr(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,
917 SourceLocation Loc, FieldDecl *Field,
918 QualType Ty, DeclContext *UsedContext)
919 : Expr(CXXDefaultInitExprClass, Ty.getNonLValueExprType(Ctx),
920 Ty->isLValueReferenceType()
922 : Ty->isRValueReferenceType() ? VK_XValue : VK_RValue,
923 /*FIXME*/ OK_Ordinary),
924 Field(Field), UsedContext(UsedContext) {
925 CXXDefaultInitExprBits.Loc = Loc;
926 assert(Field->hasInClassInitializer());
928 setDependence(ExprDependence::None);
931 CXXTemporary *CXXTemporary::Create(const ASTContext &C,
932 const CXXDestructorDecl *Destructor) {
933 return new (C) CXXTemporary(Destructor);
936 CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(const ASTContext &C,
939 assert((SubExpr->getType()->isRecordType() ||
940 SubExpr->getType()->isArrayType()) &&
941 "Expression bound to a temporary must have record or array type!");
943 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
946 CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(
947 CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI,
948 ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange,
949 bool HadMultipleCandidates, bool ListInitialization,
950 bool StdInitListInitialization, bool ZeroInitialization)
952 CXXTemporaryObjectExprClass, Ty, TSI->getTypeLoc().getBeginLoc(),
953 Cons, /* Elidable=*/false, Args, HadMultipleCandidates,
954 ListInitialization, StdInitListInitialization, ZeroInitialization,
955 CXXConstructExpr::CK_Complete, ParenOrBraceRange),
958 CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(EmptyShell Empty,
960 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty, NumArgs) {}
962 CXXTemporaryObjectExpr *CXXTemporaryObjectExpr::Create(
963 const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty,
964 TypeSourceInfo *TSI, ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange,
965 bool HadMultipleCandidates, bool ListInitialization,
966 bool StdInitListInitialization, bool ZeroInitialization) {
967 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size());
969 Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects,
970 alignof(CXXTemporaryObjectExpr));
971 return new (Mem) CXXTemporaryObjectExpr(
972 Cons, Ty, TSI, Args, ParenOrBraceRange, HadMultipleCandidates,
973 ListInitialization, StdInitListInitialization, ZeroInitialization);
976 CXXTemporaryObjectExpr *
977 CXXTemporaryObjectExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs) {
978 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs);
980 Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects,
981 alignof(CXXTemporaryObjectExpr));
982 return new (Mem) CXXTemporaryObjectExpr(EmptyShell(), NumArgs);
985 SourceLocation CXXTemporaryObjectExpr::getBeginLoc() const {
986 return getTypeSourceInfo()->getTypeLoc().getBeginLoc();
989 SourceLocation CXXTemporaryObjectExpr::getEndLoc() const {
990 SourceLocation Loc = getParenOrBraceRange().getEnd();
991 if (Loc.isInvalid() && getNumArgs())
992 Loc = getArg(getNumArgs() - 1)->getEndLoc();
996 CXXConstructExpr *CXXConstructExpr::Create(
997 const ASTContext &Ctx, QualType Ty, SourceLocation Loc,
998 CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args,
999 bool HadMultipleCandidates, bool ListInitialization,
1000 bool StdInitListInitialization, bool ZeroInitialization,
1001 ConstructionKind ConstructKind, SourceRange ParenOrBraceRange) {
1002 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size());
1003 void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects,
1004 alignof(CXXConstructExpr));
1005 return new (Mem) CXXConstructExpr(
1006 CXXConstructExprClass, Ty, Loc, Ctor, Elidable, Args,
1007 HadMultipleCandidates, ListInitialization, StdInitListInitialization,
1008 ZeroInitialization, ConstructKind, ParenOrBraceRange);
1011 CXXConstructExpr *CXXConstructExpr::CreateEmpty(const ASTContext &Ctx,
1013 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs);
1014 void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects,
1015 alignof(CXXConstructExpr));
1017 CXXConstructExpr(CXXConstructExprClass, EmptyShell(), NumArgs);
1020 CXXConstructExpr::CXXConstructExpr(
1021 StmtClass SC, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor,
1022 bool Elidable, ArrayRef<Expr *> Args, bool HadMultipleCandidates,
1023 bool ListInitialization, bool StdInitListInitialization,
1024 bool ZeroInitialization, ConstructionKind ConstructKind,
1025 SourceRange ParenOrBraceRange)
1026 : Expr(SC, Ty, VK_RValue, OK_Ordinary), Constructor(Ctor),
1027 ParenOrBraceRange(ParenOrBraceRange), NumArgs(Args.size()) {
1028 CXXConstructExprBits.Elidable = Elidable;
1029 CXXConstructExprBits.HadMultipleCandidates = HadMultipleCandidates;
1030 CXXConstructExprBits.ListInitialization = ListInitialization;
1031 CXXConstructExprBits.StdInitListInitialization = StdInitListInitialization;
1032 CXXConstructExprBits.ZeroInitialization = ZeroInitialization;
1033 CXXConstructExprBits.ConstructionKind = ConstructKind;
1034 CXXConstructExprBits.Loc = Loc;
1036 Stmt **TrailingArgs = getTrailingArgs();
1037 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1038 assert(Args[I] && "NULL argument in CXXConstructExpr!");
1039 TrailingArgs[I] = Args[I];
1042 setDependence(computeDependence(this));
1045 CXXConstructExpr::CXXConstructExpr(StmtClass SC, EmptyShell Empty,
1047 : Expr(SC, Empty), NumArgs(NumArgs) {}
1049 LambdaCapture::LambdaCapture(SourceLocation Loc, bool Implicit,
1050 LambdaCaptureKind Kind, VarDecl *Var,
1051 SourceLocation EllipsisLoc)
1052 : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) {
1055 Bits |= Capture_Implicit;
1059 Bits |= Capture_ByCopy;
1062 assert(!Var && "'this' capture cannot have a variable!");
1063 Bits |= Capture_This;
1067 Bits |= Capture_ByCopy;
1070 assert(Var && "capture must have a variable!");
1073 assert(!Var && "VLA type capture cannot have a variable!");
1076 DeclAndBits.setInt(Bits);
1079 LambdaCaptureKind LambdaCapture::getCaptureKind() const {
1080 if (capturesVLAType())
1082 bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy;
1084 return CapByCopy ? LCK_StarThis : LCK_This;
1085 return CapByCopy ? LCK_ByCopy : LCK_ByRef;
1088 LambdaExpr::LambdaExpr(QualType T, SourceRange IntroducerRange,
1089 LambdaCaptureDefault CaptureDefault,
1090 SourceLocation CaptureDefaultLoc, bool ExplicitParams,
1091 bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
1092 SourceLocation ClosingBrace,
1093 bool ContainsUnexpandedParameterPack)
1094 : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary),
1095 IntroducerRange(IntroducerRange), CaptureDefaultLoc(CaptureDefaultLoc),
1096 ClosingBrace(ClosingBrace) {
1097 LambdaExprBits.NumCaptures = CaptureInits.size();
1098 LambdaExprBits.CaptureDefault = CaptureDefault;
1099 LambdaExprBits.ExplicitParams = ExplicitParams;
1100 LambdaExprBits.ExplicitResultType = ExplicitResultType;
1102 CXXRecordDecl *Class = getLambdaClass();
1104 assert(capture_size() == Class->capture_size() && "Wrong number of captures");
1105 assert(getCaptureDefault() == Class->getLambdaCaptureDefault());
1107 // Copy initialization expressions for the non-static data members.
1108 Stmt **Stored = getStoredStmts();
1109 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
1110 *Stored++ = CaptureInits[I];
1112 // Copy the body of the lambda.
1113 *Stored++ = getCallOperator()->getBody();
1115 setDependence(computeDependence(this, ContainsUnexpandedParameterPack));
1118 LambdaExpr::LambdaExpr(EmptyShell Empty, unsigned NumCaptures)
1119 : Expr(LambdaExprClass, Empty) {
1120 LambdaExprBits.NumCaptures = NumCaptures;
1122 // Initially don't initialize the body of the LambdaExpr. The body will
1123 // be lazily deserialized when needed.
1124 getStoredStmts()[NumCaptures] = nullptr; // Not one past the end.
1127 LambdaExpr *LambdaExpr::Create(const ASTContext &Context, CXXRecordDecl *Class,
1128 SourceRange IntroducerRange,
1129 LambdaCaptureDefault CaptureDefault,
1130 SourceLocation CaptureDefaultLoc,
1131 bool ExplicitParams, bool ExplicitResultType,
1132 ArrayRef<Expr *> CaptureInits,
1133 SourceLocation ClosingBrace,
1134 bool ContainsUnexpandedParameterPack) {
1135 // Determine the type of the expression (i.e., the type of the
1136 // function object we're creating).
1137 QualType T = Context.getTypeDeclType(Class);
1139 unsigned Size = totalSizeToAlloc<Stmt *>(CaptureInits.size() + 1);
1140 void *Mem = Context.Allocate(Size);
1142 LambdaExpr(T, IntroducerRange, CaptureDefault, CaptureDefaultLoc,
1143 ExplicitParams, ExplicitResultType, CaptureInits, ClosingBrace,
1144 ContainsUnexpandedParameterPack);
1147 LambdaExpr *LambdaExpr::CreateDeserialized(const ASTContext &C,
1148 unsigned NumCaptures) {
1149 unsigned Size = totalSizeToAlloc<Stmt *>(NumCaptures + 1);
1150 void *Mem = C.Allocate(Size);
1151 return new (Mem) LambdaExpr(EmptyShell(), NumCaptures);
1154 void LambdaExpr::initBodyIfNeeded() const {
1155 if (!getStoredStmts()[capture_size()]) {
1156 auto *This = const_cast<LambdaExpr *>(this);
1157 This->getStoredStmts()[capture_size()] = getCallOperator()->getBody();
1161 Stmt *LambdaExpr::getBody() const {
1163 return getStoredStmts()[capture_size()];
1166 const CompoundStmt *LambdaExpr::getCompoundStmtBody() const {
1167 Stmt *Body = getBody();
1168 if (const auto *CoroBody = dyn_cast<CoroutineBodyStmt>(Body))
1169 return cast<CompoundStmt>(CoroBody->getBody());
1170 return cast<CompoundStmt>(Body);
1173 bool LambdaExpr::isInitCapture(const LambdaCapture *C) const {
1174 return (C->capturesVariable() && C->getCapturedVar()->isInitCapture() &&
1175 (getCallOperator() == C->getCapturedVar()->getDeclContext()));
1178 LambdaExpr::capture_iterator LambdaExpr::capture_begin() const {
1179 return getLambdaClass()->getLambdaData().Captures;
1182 LambdaExpr::capture_iterator LambdaExpr::capture_end() const {
1183 return capture_begin() + capture_size();
1186 LambdaExpr::capture_range LambdaExpr::captures() const {
1187 return capture_range(capture_begin(), capture_end());
1190 LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const {
1191 return capture_begin();
1194 LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const {
1195 struct CXXRecordDecl::LambdaDefinitionData &Data
1196 = getLambdaClass()->getLambdaData();
1197 return Data.Captures + Data.NumExplicitCaptures;
1200 LambdaExpr::capture_range LambdaExpr::explicit_captures() const {
1201 return capture_range(explicit_capture_begin(), explicit_capture_end());
1204 LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const {
1205 return explicit_capture_end();
1208 LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const {
1209 return capture_end();
1212 LambdaExpr::capture_range LambdaExpr::implicit_captures() const {
1213 return capture_range(implicit_capture_begin(), implicit_capture_end());
1216 CXXRecordDecl *LambdaExpr::getLambdaClass() const {
1217 return getType()->getAsCXXRecordDecl();
1220 CXXMethodDecl *LambdaExpr::getCallOperator() const {
1221 CXXRecordDecl *Record = getLambdaClass();
1222 return Record->getLambdaCallOperator();
1225 FunctionTemplateDecl *LambdaExpr::getDependentCallOperator() const {
1226 CXXRecordDecl *Record = getLambdaClass();
1227 return Record->getDependentLambdaCallOperator();
1230 TemplateParameterList *LambdaExpr::getTemplateParameterList() const {
1231 CXXRecordDecl *Record = getLambdaClass();
1232 return Record->getGenericLambdaTemplateParameterList();
1235 ArrayRef<NamedDecl *> LambdaExpr::getExplicitTemplateParameters() const {
1236 const CXXRecordDecl *Record = getLambdaClass();
1237 return Record->getLambdaExplicitTemplateParameters();
1240 bool LambdaExpr::isMutable() const { return !getCallOperator()->isConst(); }
1242 LambdaExpr::child_range LambdaExpr::children() {
1244 return child_range(getStoredStmts(), getStoredStmts() + capture_size() + 1);
1247 LambdaExpr::const_child_range LambdaExpr::children() const {
1249 return const_child_range(getStoredStmts(),
1250 getStoredStmts() + capture_size() + 1);
1253 ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
1254 bool CleanupsHaveSideEffects,
1255 ArrayRef<CleanupObject> objects)
1256 : FullExpr(ExprWithCleanupsClass, subexpr) {
1257 ExprWithCleanupsBits.CleanupsHaveSideEffects = CleanupsHaveSideEffects;
1258 ExprWithCleanupsBits.NumObjects = objects.size();
1259 for (unsigned i = 0, e = objects.size(); i != e; ++i)
1260 getTrailingObjects<CleanupObject>()[i] = objects[i];
1263 ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, Expr *subexpr,
1264 bool CleanupsHaveSideEffects,
1265 ArrayRef<CleanupObject> objects) {
1266 void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(objects.size()),
1267 alignof(ExprWithCleanups));
1269 ExprWithCleanups(subexpr, CleanupsHaveSideEffects, objects);
1272 ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
1273 : FullExpr(ExprWithCleanupsClass, empty) {
1274 ExprWithCleanupsBits.NumObjects = numObjects;
1277 ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C,
1279 unsigned numObjects) {
1280 void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(numObjects),
1281 alignof(ExprWithCleanups));
1282 return new (buffer) ExprWithCleanups(empty, numObjects);
1285 CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *TSI,
1286 SourceLocation LParenLoc,
1287 ArrayRef<Expr *> Args,
1288 SourceLocation RParenLoc)
1289 : Expr(CXXUnresolvedConstructExprClass,
1290 TSI->getType().getNonReferenceType(),
1291 (TSI->getType()->isLValueReferenceType()
1293 : TSI->getType()->isRValueReferenceType() ? VK_XValue
1296 TSI(TSI), LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
1297 CXXUnresolvedConstructExprBits.NumArgs = Args.size();
1298 auto **StoredArgs = getTrailingObjects<Expr *>();
1299 for (unsigned I = 0; I != Args.size(); ++I)
1300 StoredArgs[I] = Args[I];
1301 setDependence(computeDependence(this));
1304 CXXUnresolvedConstructExpr *CXXUnresolvedConstructExpr::Create(
1305 const ASTContext &Context, TypeSourceInfo *TSI, SourceLocation LParenLoc,
1306 ArrayRef<Expr *> Args, SourceLocation RParenLoc) {
1307 void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(Args.size()));
1308 return new (Mem) CXXUnresolvedConstructExpr(TSI, LParenLoc, Args, RParenLoc);
1311 CXXUnresolvedConstructExpr *
1312 CXXUnresolvedConstructExpr::CreateEmpty(const ASTContext &Context,
1314 void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(NumArgs));
1315 return new (Mem) CXXUnresolvedConstructExpr(EmptyShell(), NumArgs);
1318 SourceLocation CXXUnresolvedConstructExpr::getBeginLoc() const {
1319 return TSI->getTypeLoc().getBeginLoc();
1322 CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
1323 const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
1324 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1325 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1326 DeclarationNameInfo MemberNameInfo,
1327 const TemplateArgumentListInfo *TemplateArgs)
1328 : Expr(CXXDependentScopeMemberExprClass, Ctx.DependentTy, VK_LValue,
1330 Base(Base), BaseType(BaseType), QualifierLoc(QualifierLoc),
1331 MemberNameInfo(MemberNameInfo) {
1332 CXXDependentScopeMemberExprBits.IsArrow = IsArrow;
1333 CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo =
1334 (TemplateArgs != nullptr) || TemplateKWLoc.isValid();
1335 CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope =
1336 FirstQualifierFoundInScope != nullptr;
1337 CXXDependentScopeMemberExprBits.OperatorLoc = OperatorLoc;
1340 auto Deps = TemplateArgumentDependence::None;
1341 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1342 TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
1344 } else if (TemplateKWLoc.isValid()) {
1345 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1349 if (hasFirstQualifierFoundInScope())
1350 *getTrailingObjects<NamedDecl *>() = FirstQualifierFoundInScope;
1351 setDependence(computeDependence(this));
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 BaseType = BaseType->castAs<PointerType>()->getPointeeType();
1507 Record = BaseType->getAsCXXRecordDecl();
1508 assert(Record && "base of member expression does not name record");
1515 SizeOfPackExpr::Create(ASTContext &Context, SourceLocation OperatorLoc,
1516 NamedDecl *Pack, SourceLocation PackLoc,
1517 SourceLocation RParenLoc,
1518 Optional<unsigned> Length,
1519 ArrayRef<TemplateArgument> PartialArgs) {
1521 Context.Allocate(totalSizeToAlloc<TemplateArgument>(PartialArgs.size()));
1522 return new (Storage) SizeOfPackExpr(Context.getSizeType(), OperatorLoc, Pack,
1523 PackLoc, RParenLoc, Length, PartialArgs);
1526 SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context,
1527 unsigned NumPartialArgs) {
1529 Context.Allocate(totalSizeToAlloc<TemplateArgument>(NumPartialArgs));
1530 return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs);
1533 SubstNonTypeTemplateParmPackExpr::SubstNonTypeTemplateParmPackExpr(
1534 QualType T, ExprValueKind ValueKind, NonTypeTemplateParmDecl *Param,
1535 SourceLocation NameLoc, const TemplateArgument &ArgPack)
1536 : Expr(SubstNonTypeTemplateParmPackExprClass, T, ValueKind, OK_Ordinary),
1537 Param(Param), Arguments(ArgPack.pack_begin()),
1538 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) {
1539 setDependence(ExprDependence::TypeValueInstantiation |
1540 ExprDependence::UnexpandedPack);
1543 TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
1544 return TemplateArgument(llvm::makeArrayRef(Arguments, NumArguments));
1547 FunctionParmPackExpr::FunctionParmPackExpr(QualType T, VarDecl *ParamPack,
1548 SourceLocation NameLoc,
1550 VarDecl *const *Params)
1551 : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary),
1552 ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
1554 std::uninitialized_copy(Params, Params + NumParams,
1555 getTrailingObjects<VarDecl *>());
1556 setDependence(ExprDependence::TypeValueInstantiation |
1557 ExprDependence::UnexpandedPack);
1560 FunctionParmPackExpr *
1561 FunctionParmPackExpr::Create(const ASTContext &Context, QualType T,
1562 VarDecl *ParamPack, SourceLocation NameLoc,
1563 ArrayRef<VarDecl *> Params) {
1564 return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(Params.size())))
1565 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
1568 FunctionParmPackExpr *
1569 FunctionParmPackExpr::CreateEmpty(const ASTContext &Context,
1570 unsigned NumParams) {
1571 return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(NumParams)))
1572 FunctionParmPackExpr(QualType(), nullptr, SourceLocation(), 0, nullptr);
1575 MaterializeTemporaryExpr::MaterializeTemporaryExpr(
1576 QualType T, Expr *Temporary, bool BoundToLvalueReference,
1577 LifetimeExtendedTemporaryDecl *MTD)
1578 : Expr(MaterializeTemporaryExprClass, T,
1579 BoundToLvalueReference ? VK_LValue : VK_XValue, OK_Ordinary) {
1582 MTD->ExprWithTemporary = Temporary;
1586 setDependence(computeDependence(this));
1589 void MaterializeTemporaryExpr::setExtendingDecl(ValueDecl *ExtendedBy,
1590 unsigned ManglingNumber) {
1591 // We only need extra state if we have to remember more than just the Stmt.
1595 // We may need to allocate extra storage for the mangling number and the
1596 // extended-by ValueDecl.
1597 if (!State.is<LifetimeExtendedTemporaryDecl *>())
1598 State = LifetimeExtendedTemporaryDecl::Create(
1599 cast<Expr>(State.get<Stmt *>()), ExtendedBy, ManglingNumber);
1601 auto ES = State.get<LifetimeExtendedTemporaryDecl *>();
1602 ES->ExtendingDecl = ExtendedBy;
1603 ES->ManglingNumber = ManglingNumber;
1606 TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1607 ArrayRef<TypeSourceInfo *> Args,
1608 SourceLocation RParenLoc, bool Value)
1609 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary), Loc(Loc),
1610 RParenLoc(RParenLoc) {
1611 assert(Kind <= TT_Last && "invalid enum value!");
1612 TypeTraitExprBits.Kind = Kind;
1613 assert(static_cast<unsigned>(Kind) == TypeTraitExprBits.Kind &&
1614 "TypeTraitExprBits.Kind overflow!");
1615 TypeTraitExprBits.Value = Value;
1616 TypeTraitExprBits.NumArgs = Args.size();
1617 assert(Args.size() == TypeTraitExprBits.NumArgs &&
1618 "TypeTraitExprBits.NumArgs overflow!");
1620 auto **ToArgs = getTrailingObjects<TypeSourceInfo *>();
1621 for (unsigned I = 0, N = Args.size(); I != N; ++I)
1622 ToArgs[I] = Args[I];
1624 setDependence(computeDependence(this));
1627 TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T,
1630 ArrayRef<TypeSourceInfo *> Args,
1631 SourceLocation RParenLoc,
1633 void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(Args.size()));
1634 return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1637 TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const ASTContext &C,
1639 void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(NumArgs));
1640 return new (Mem) TypeTraitExpr(EmptyShell());
1643 CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config,
1644 ArrayRef<Expr *> Args, QualType Ty,
1645 ExprValueKind VK, SourceLocation RP,
1646 unsigned MinNumArgs)
1647 : CallExpr(CUDAKernelCallExprClass, Fn, /*PreArgs=*/Config, Args, Ty, VK,
1648 RP, MinNumArgs, NotADL) {}
1650 CUDAKernelCallExpr::CUDAKernelCallExpr(unsigned NumArgs, EmptyShell Empty)
1651 : CallExpr(CUDAKernelCallExprClass, /*NumPreArgs=*/END_PREARG, NumArgs,
1654 CUDAKernelCallExpr *
1655 CUDAKernelCallExpr::Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config,
1656 ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
1657 SourceLocation RP, unsigned MinNumArgs) {
1658 // Allocate storage for the trailing objects of CallExpr.
1659 unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
1660 unsigned SizeOfTrailingObjects =
1661 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/END_PREARG, NumArgs);
1662 void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects,
1663 alignof(CUDAKernelCallExpr));
1664 return new (Mem) CUDAKernelCallExpr(Fn, Config, Args, Ty, VK, RP, MinNumArgs);
1667 CUDAKernelCallExpr *CUDAKernelCallExpr::CreateEmpty(const ASTContext &Ctx,
1670 // Allocate storage for the trailing objects of CallExpr.
1671 unsigned SizeOfTrailingObjects =
1672 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/END_PREARG, NumArgs);
1673 void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects,
1674 alignof(CUDAKernelCallExpr));
1675 return new (Mem) CUDAKernelCallExpr(NumArgs, Empty);