blob: 1d5fd80d0d4700988e6081a8c94bb3cee4fd8817 [file] [log] [blame]
Eugene Zelenko821f6982017-11-18 01:47:41 +00001//===- ExprCXX.cpp - (C++) Expression AST Node Implementation -------------===//
Ted Kremeneke3a0c142007-08-24 20:21:10 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Ted Kremeneke3a0c142007-08-24 20:21:10 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the subclesses of Expr class declared in ExprCXX.h
10//
11//===----------------------------------------------------------------------===//
12
Eugene Zelenko821f6982017-11-18 01:47:41 +000013#include "clang/AST/ExprCXX.h"
Benjamin Kramer4ab984e2012-07-04 20:19:54 +000014#include "clang/AST/ASTContext.h"
Benjamin Kramerea70eb32012-12-01 15:09:41 +000015#include "clang/AST/Attr.h"
Eugene Zelenko821f6982017-11-18 01:47:41 +000016#include "clang/AST/Decl.h"
17#include "clang/AST/DeclAccessPair.h"
18#include "clang/AST/DeclBase.h"
Douglas Gregor993603d2008-11-14 16:09:21 +000019#include "clang/AST/DeclCXX.h"
Eugene Zelenko821f6982017-11-18 01:47:41 +000020#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"
Douglas Gregor651fe5e2010-02-24 23:40:28 +000026#include "clang/AST/TypeLoc.h"
Eugene Zelenko821f6982017-11-18 01:47:41 +000027#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"
34#include <cassert>
35#include <cstddef>
36#include <cstring>
37#include <memory>
Ted Kremeneke3a0c142007-08-24 20:21:10 +000038
Eugene Zelenko821f6982017-11-18 01:47:41 +000039using namespace clang;
Douglas Gregor9da64192010-04-26 22:37:10 +000040
Ted Kremeneke3a0c142007-08-24 20:21:10 +000041//===----------------------------------------------------------------------===//
42// Child Iterators for iterating over subexpressions/substatements
43//===----------------------------------------------------------------------===//
44
Richard Smith66094432016-10-20 00:55:15 +000045bool 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
49 // expressions.
50 if (getNumArgs() != 2)
51 return false;
52
53 switch (getOperator()) {
54 case OO_Call: case OO_Subscript:
55 return false;
56 default:
57 return true;
58 }
59}
60
Richard Smithef8bf432012-08-13 20:08:14 +000061bool CXXTypeidExpr::isPotentiallyEvaluated() const {
62 if (isTypeOperand())
63 return false;
64
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())
71 return true;
72
73 return false;
74}
75
David Majnemer143c55e2013-09-27 07:04:31 +000076QualType CXXTypeidExpr::getTypeOperand(ASTContext &Context) const {
Douglas Gregor9da64192010-04-26 22:37:10 +000077 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
David Majnemer143c55e2013-09-27 07:04:31 +000078 Qualifiers Quals;
79 return Context.getUnqualifiedArrayType(
80 Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
Douglas Gregor9da64192010-04-26 22:37:10 +000081}
82
David Majnemer143c55e2013-09-27 07:04:31 +000083QualType CXXUuidofExpr::getTypeOperand(ASTContext &Context) const {
Francois Pichet9f4f2072010-09-08 12:20:18 +000084 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
David Majnemer143c55e2013-09-27 07:04:31 +000085 Qualifiers Quals;
86 return Context.getUnqualifiedArrayType(
87 Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals);
Francois Pichet9f4f2072010-09-08 12:20:18 +000088}
89
Douglas Gregor747eb782010-07-08 06:14:04 +000090// CXXScalarValueInitExpr
Stephen Kelly724e9e52018-08-09 20:05:03 +000091SourceLocation CXXScalarValueInitExpr::getBeginLoc() const {
Bruno Ricci030dab42019-01-08 16:08:54 +000092 return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : getRParenLoc();
Douglas Gregor2b88c112010-09-08 00:15:04 +000093}
94
Sebastian Redlbd150f42008-11-21 19:14:01 +000095// CXXNewExpr
Bruno Ricci9b6dfac2019-01-07 15:04:45 +000096CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
97 FunctionDecl *OperatorDelete, bool ShouldPassAlignment,
98 bool UsualArrayDeleteWantsSize,
99 ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens,
Richard Smithb9fb1212019-05-06 03:47:15 +0000100 Optional<Expr *> ArraySize,
101 InitializationStyle InitializationStyle,
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000102 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) {
Fangrui Song6907ce22018-07-30 19:24:48 +0000111
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000112 assert((Initializer != nullptr || InitializationStyle == NoInit) &&
113 "Only NoInit can have no initializer!");
114
115 CXXNewExprBits.IsGlobalNew = IsGlobalNew;
Richard Smithb9fb1212019-05-06 03:47:15 +0000116 CXXNewExprBits.IsArray = ArraySize.hasValue();
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000117 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();
124
125 if (ArraySize) {
Richard Smithb9fb1212019-05-06 03:47:15 +0000126 if (Expr *SizeExpr = *ArraySize) {
Richard Smithda1b4342019-09-27 01:26:47 +0000127 if (SizeExpr->isValueDependent())
128 ExprBits.ValueDependent = true;
Richard Smithb9fb1212019-05-06 03:47:15 +0000129 if (SizeExpr->isInstantiationDependent())
130 ExprBits.InstantiationDependent = true;
131 if (SizeExpr->containsUnexpandedParameterPack())
132 ExprBits.ContainsUnexpandedParameterPack = true;
133 }
Douglas Gregora6e053e2010-12-15 01:34:56 +0000134
Richard Smithb9fb1212019-05-06 03:47:15 +0000135 getTrailingObjects<Stmt *>()[arraySizeOffset()] = *ArraySize;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000136 }
137
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000138 if (Initializer) {
Richard Smithda1b4342019-09-27 01:26:47 +0000139 if (Initializer->isValueDependent())
140 ExprBits.ValueDependent = true;
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000141 if (Initializer->isInstantiationDependent())
Sebastian Redl6047f072012-02-16 12:22:20 +0000142 ExprBits.InstantiationDependent = true;
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000143 if (Initializer->containsUnexpandedParameterPack())
Sebastian Redl6047f072012-02-16 12:22:20 +0000144 ExprBits.ContainsUnexpandedParameterPack = true;
145
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000146 getTrailingObjects<Stmt *>()[initExprOffset()] = Initializer;
Sebastian Redl6047f072012-02-16 12:22:20 +0000147 }
148
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000149 for (unsigned I = 0; I != PlacementArgs.size(); ++I) {
Richard Smithda1b4342019-09-27 01:26:47 +0000150 if (PlacementArgs[I]->isValueDependent())
151 ExprBits.ValueDependent = true;
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000152 if (PlacementArgs[I]->isInstantiationDependent())
Douglas Gregor678d76c2011-07-01 01:22:09 +0000153 ExprBits.InstantiationDependent = true;
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000154 if (PlacementArgs[I]->containsUnexpandedParameterPack())
Douglas Gregora6e053e2010-12-15 01:34:56 +0000155 ExprBits.ContainsUnexpandedParameterPack = true;
156
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000157 getTrailingObjects<Stmt *>()[placementNewArgsOffset() + I] =
158 PlacementArgs[I];
Douglas Gregora6e053e2010-12-15 01:34:56 +0000159 }
David Blaikie3a0de212012-11-08 22:53:48 +0000160
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000161 if (IsParenTypeId)
162 getTrailingObjects<SourceRange>()[0] = TypeIdParens;
163
David Blaikie3a0de212012-11-08 22:53:48 +0000164 switch (getInitializationStyle()) {
165 case CallInit:
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000166 this->Range.setEnd(DirectInitRange.getEnd());
167 break;
David Blaikie3a0de212012-11-08 22:53:48 +0000168 case ListInit:
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000169 this->Range.setEnd(getInitializer()->getSourceRange().getEnd());
170 break;
Eli Friedman2dcbdc02013-06-17 22:35:10 +0000171 default:
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000172 if (IsParenTypeId)
Eli Friedman2dcbdc02013-06-17 22:35:10 +0000173 this->Range.setEnd(TypeIdParens.getEnd());
174 break;
David Blaikie3a0de212012-11-08 22:53:48 +0000175 }
Sebastian Redlbd150f42008-11-21 19:14:01 +0000176}
177
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000178CXXNewExpr::CXXNewExpr(EmptyShell Empty, bool IsArray,
179 unsigned NumPlacementArgs, bool IsParenTypeId)
180 : Expr(CXXNewExprClass, Empty) {
181 CXXNewExprBits.IsArray = IsArray;
182 CXXNewExprBits.NumPlacementArgs = NumPlacementArgs;
183 CXXNewExprBits.IsParenTypeId = IsParenTypeId;
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000184}
185
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000186CXXNewExpr *
187CXXNewExpr::Create(const ASTContext &Ctx, bool IsGlobalNew,
188 FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete,
189 bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize,
190 ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens,
Richard Smithb9fb1212019-05-06 03:47:15 +0000191 Optional<Expr *> ArraySize,
192 InitializationStyle InitializationStyle, Expr *Initializer,
193 QualType Ty, TypeSourceInfo *AllocatedTypeInfo,
194 SourceRange Range, SourceRange DirectInitRange) {
195 bool IsArray = ArraySize.hasValue();
Bruno Ricci9b6dfac2019-01-07 15:04:45 +0000196 bool HasInit = Initializer != nullptr;
197 unsigned NumPlacementArgs = PlacementArgs.size();
198 bool IsParenTypeId = TypeIdParens.isValid();
199 void *Mem =
200 Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>(
201 IsArray + HasInit + NumPlacementArgs, IsParenTypeId),
202 alignof(CXXNewExpr));
203 return new (Mem)
204 CXXNewExpr(IsGlobalNew, OperatorNew, OperatorDelete, ShouldPassAlignment,
205 UsualArrayDeleteWantsSize, PlacementArgs, TypeIdParens,
206 ArraySize, InitializationStyle, Initializer, Ty,
207 AllocatedTypeInfo, Range, DirectInitRange);
208}
209
210CXXNewExpr *CXXNewExpr::CreateEmpty(const ASTContext &Ctx, bool IsArray,
211 bool HasInit, unsigned NumPlacementArgs,
212 bool IsParenTypeId) {
213 void *Mem =
214 Ctx.Allocate(totalSizeToAlloc<Stmt *, SourceRange>(
215 IsArray + HasInit + NumPlacementArgs, IsParenTypeId),
216 alignof(CXXNewExpr));
217 return new (Mem)
218 CXXNewExpr(EmptyShell(), IsArray, NumPlacementArgs, IsParenTypeId);
219}
220
221bool CXXNewExpr::shouldNullCheckAllocation() const {
222 return getOperatorNew()
223 ->getType()
224 ->castAs<FunctionProtoType>()
225 ->isNothrow() &&
Richard Smith902a0232015-02-14 01:52:20 +0000226 !getOperatorNew()->isReservedGlobalPlacementOperator();
John McCall75f94982011-03-07 03:12:35 +0000227}
Chris Lattnerabfb58d2010-05-10 01:22:27 +0000228
Sebastian Redlbd150f42008-11-21 19:14:01 +0000229// CXXDeleteExpr
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000230QualType CXXDeleteExpr::getDestroyedType() const {
231 const Expr *Arg = getArgument();
Richard Smith5b349582017-10-13 01:55:36 +0000232
233 // For a destroying operator delete, we may have implicitly converted the
234 // pointer type to the type of the parameter of the 'operator delete'
235 // function.
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000236 while (const auto *ICE = dyn_cast<ImplicitCastExpr>(Arg)) {
Richard Smith5b349582017-10-13 01:55:36 +0000237 if (ICE->getCastKind() == CK_DerivedToBase ||
238 ICE->getCastKind() == CK_UncheckedDerivedToBase ||
239 ICE->getCastKind() == CK_NoOp) {
240 assert((ICE->getCastKind() == CK_NoOp ||
241 getOperatorDelete()->isDestroyingOperatorDelete()) &&
242 "only a destroying operator delete can have a converted arg");
243 Arg = ICE->getSubExpr();
244 } else
245 break;
246 }
247
Craig Silverstein20f7ab72010-10-20 00:38:15 +0000248 // The type-to-delete may not be a pointer if it's a dependent type.
Craig Silverstein3b9936f2010-10-20 00:56:01 +0000249 const QualType ArgType = Arg->getType();
Craig Silverstein9e448da2010-11-16 07:16:25 +0000250
251 if (ArgType->isDependentType() && !ArgType->isPointerType())
252 return QualType();
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000253
Craig Silverstein20f7ab72010-10-20 00:38:15 +0000254 return ArgType->getAs<PointerType>()->getPointeeType();
Douglas Gregor6ed2fee2010-09-14 22:55:20 +0000255}
256
Douglas Gregorad8a3362009-09-04 17:36:40 +0000257// CXXPseudoDestructorExpr
Douglas Gregor678f90d2010-02-25 01:56:36 +0000258PseudoDestructorTypeStorage::PseudoDestructorTypeStorage(TypeSourceInfo *Info)
Eugene Zelenko821f6982017-11-18 01:47:41 +0000259 : Type(Info) {
Abramo Bagnara1108e7b2010-05-20 10:00:11 +0000260 Location = Info->getTypeLoc().getLocalSourceRange().getBegin();
Douglas Gregor678f90d2010-02-25 01:56:36 +0000261}
262
Craig Toppera31a8822013-08-22 07:09:37 +0000263CXXPseudoDestructorExpr::CXXPseudoDestructorExpr(const ASTContext &Context,
Douglas Gregora6ce6082011-02-25 18:19:59 +0000264 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
Fangrui Song6907ce22018-07-30 19:24:48 +0000265 NestedNameSpecifierLoc QualifierLoc, TypeSourceInfo *ScopeType,
266 SourceLocation ColonColonLoc, SourceLocation TildeLoc,
Douglas Gregora6ce6082011-02-25 18:19:59 +0000267 PseudoDestructorTypeStorage DestroyedType)
John McCalldb40c7f2010-12-14 08:05:40 +0000268 : Expr(CXXPseudoDestructorExprClass,
David Majnemerced8bdf2015-02-25 17:36:15 +0000269 Context.BoundMemberTy,
John McCalldb40c7f2010-12-14 08:05:40 +0000270 VK_RValue, OK_Ordinary,
271 /*isTypeDependent=*/(Base->isTypeDependent() ||
272 (DestroyedType.getTypeSourceInfo() &&
273 DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000274 /*isValueDependent=*/Base->isValueDependent(),
Douglas Gregor678d76c2011-07-01 01:22:09 +0000275 (Base->isInstantiationDependent() ||
276 (QualifierLoc &&
277 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent()) ||
278 (ScopeType &&
279 ScopeType->getType()->isInstantiationDependentType()) ||
280 (DestroyedType.getTypeSourceInfo() &&
281 DestroyedType.getTypeSourceInfo()->getType()
282 ->isInstantiationDependentType())),
Douglas Gregora6e053e2010-12-15 01:34:56 +0000283 // ContainsUnexpandedParameterPack
284 (Base->containsUnexpandedParameterPack() ||
Fangrui Song6907ce22018-07-30 19:24:48 +0000285 (QualifierLoc &&
Douglas Gregora6ce6082011-02-25 18:19:59 +0000286 QualifierLoc.getNestedNameSpecifier()
287 ->containsUnexpandedParameterPack()) ||
Fangrui Song6907ce22018-07-30 19:24:48 +0000288 (ScopeType &&
Douglas Gregora6e053e2010-12-15 01:34:56 +0000289 ScopeType->getType()->containsUnexpandedParameterPack()) ||
290 (DestroyedType.getTypeSourceInfo() &&
291 DestroyedType.getTypeSourceInfo()->getType()
292 ->containsUnexpandedParameterPack()))),
John McCalldb40c7f2010-12-14 08:05:40 +0000293 Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
Douglas Gregora6ce6082011-02-25 18:19:59 +0000294 OperatorLoc(OperatorLoc), QualifierLoc(QualifierLoc),
John McCalldb40c7f2010-12-14 08:05:40 +0000295 ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
Eugene Zelenko821f6982017-11-18 01:47:41 +0000296 DestroyedType(DestroyedType) {}
John McCalldb40c7f2010-12-14 08:05:40 +0000297
Douglas Gregor678f90d2010-02-25 01:56:36 +0000298QualType CXXPseudoDestructorExpr::getDestroyedType() const {
299 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
300 return TInfo->getType();
Fangrui Song6907ce22018-07-30 19:24:48 +0000301
Douglas Gregor678f90d2010-02-25 01:56:36 +0000302 return QualType();
303}
304
Stephen Kelly02a67ba2018-08-09 20:05:47 +0000305SourceLocation CXXPseudoDestructorExpr::getEndLoc() const {
Douglas Gregor678f90d2010-02-25 01:56:36 +0000306 SourceLocation End = DestroyedType.getLocation();
307 if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
Abramo Bagnara1108e7b2010-05-20 10:00:11 +0000308 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000309 return End;
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000310}
311
John McCalld14a8642009-11-21 08:51:07 +0000312// UnresolvedLookupExpr
Bruno Riccid7628d92019-01-09 15:43:19 +0000313UnresolvedLookupExpr::UnresolvedLookupExpr(
314 const ASTContext &Context, CXXRecordDecl *NamingClass,
315 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
316 const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
317 const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
318 UnresolvedSetIterator End)
319 : OverloadExpr(UnresolvedLookupExprClass, Context, QualifierLoc,
320 TemplateKWLoc, NameInfo, TemplateArgs, Begin, End, false,
321 false, false),
322 NamingClass(NamingClass) {
323 UnresolvedLookupExprBits.RequiresADL = RequiresADL;
324 UnresolvedLookupExprBits.Overloaded = Overloaded;
325}
326
327UnresolvedLookupExpr::UnresolvedLookupExpr(EmptyShell Empty,
328 unsigned NumResults,
329 bool HasTemplateKWAndArgsInfo)
330 : OverloadExpr(UnresolvedLookupExprClass, Empty, NumResults,
331 HasTemplateKWAndArgsInfo) {}
332
333UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
334 const ASTContext &Context, CXXRecordDecl *NamingClass,
335 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
336 bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin,
337 UnresolvedSetIterator End) {
338 unsigned NumResults = End - Begin;
339 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
340 TemplateArgumentLoc>(NumResults, 0, 0);
341 void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
342 return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
343 SourceLocation(), NameInfo, RequiresADL,
344 Overloaded, nullptr, Begin, End);
345}
346
347UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
348 const ASTContext &Context, CXXRecordDecl *NamingClass,
349 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
350 const DeclarationNameInfo &NameInfo, bool RequiresADL,
351 const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
352 UnresolvedSetIterator End) {
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +0000353 assert(Args || TemplateKWLoc.isValid());
Bruno Riccid7628d92019-01-09 15:43:19 +0000354 unsigned NumResults = End - Begin;
355 unsigned NumTemplateArgs = Args ? Args->size() : 0;
356 unsigned Size =
357 totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
358 TemplateArgumentLoc>(NumResults, 1, NumTemplateArgs);
359 void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
360 return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
361 TemplateKWLoc, NameInfo, RequiresADL,
362 /*Overloaded*/ true, Args, Begin, End);
John McCalle66edc12009-11-24 19:00:30 +0000363}
364
Bruno Riccid7628d92019-01-09 15:43:19 +0000365UnresolvedLookupExpr *UnresolvedLookupExpr::CreateEmpty(
366 const ASTContext &Context, unsigned NumResults,
367 bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) {
James Y Knighte7d82282015-12-29 18:15:14 +0000368 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
Bruno Riccid7628d92019-01-09 15:43:19 +0000369 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
370 TemplateArgumentLoc>(
371 NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
372 void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
373 return new (Mem)
374 UnresolvedLookupExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo);
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +0000375}
376
Bruno Riccid7628d92019-01-09 15:43:19 +0000377OverloadExpr::OverloadExpr(StmtClass SC, const ASTContext &Context,
Douglas Gregor0da1d432011-02-28 20:01:57 +0000378 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000379 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000380 const DeclarationNameInfo &NameInfo,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000381 const TemplateArgumentListInfo *TemplateArgs,
Fangrui Song6907ce22018-07-30 19:24:48 +0000382 UnresolvedSetIterator Begin,
Bruno Riccid7628d92019-01-09 15:43:19 +0000383 UnresolvedSetIterator End, bool KnownDependent,
Douglas Gregor678d76c2011-07-01 01:22:09 +0000384 bool KnownInstantiationDependent,
Douglas Gregora6e053e2010-12-15 01:34:56 +0000385 bool KnownContainsUnexpandedParameterPack)
Bruno Riccid7628d92019-01-09 15:43:19 +0000386 : Expr(
387 SC, Context.OverloadTy, VK_LValue, OK_Ordinary, KnownDependent,
388 KnownDependent,
389 (KnownInstantiationDependent || NameInfo.isInstantiationDependent() ||
390 (QualifierLoc &&
Eugene Zelenko821f6982017-11-18 01:47:41 +0000391 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
Bruno Riccid7628d92019-01-09 15:43:19 +0000392 (KnownContainsUnexpandedParameterPack ||
393 NameInfo.containsUnexpandedParameterPack() ||
394 (QualifierLoc && QualifierLoc.getNestedNameSpecifier()
395 ->containsUnexpandedParameterPack()))),
396 NameInfo(NameInfo), QualifierLoc(QualifierLoc) {
397 unsigned NumResults = End - Begin;
398 OverloadExprBits.NumResults = NumResults;
399 OverloadExprBits.HasTemplateKWAndArgsInfo =
400 (TemplateArgs != nullptr ) || TemplateKWLoc.isValid();
401
Douglas Gregora6e053e2010-12-15 01:34:56 +0000402 if (NumResults) {
403 // Determine whether this expression is type-dependent.
404 for (UnresolvedSetImpl::const_iterator I = Begin; I != End; ++I) {
405 if ((*I)->getDeclContext()->isDependentContext() ||
406 isa<UnresolvedUsingValueDecl>(*I)) {
407 ExprBits.TypeDependent = true;
408 ExprBits.ValueDependent = true;
Richard Smith47726b22012-08-13 21:29:18 +0000409 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000410 }
411 }
412
Bruno Riccid7628d92019-01-09 15:43:19 +0000413 // Copy the results to the trailing array past UnresolvedLookupExpr
414 // or UnresolvedMemberExpr.
415 DeclAccessPair *Results = getTrailingResults();
Benjamin Kramer04ec7e32015-02-01 20:31:36 +0000416 memcpy(Results, Begin.I, NumResults * sizeof(DeclAccessPair));
Douglas Gregora6e053e2010-12-15 01:34:56 +0000417 }
418
419 // If we have explicit template arguments, check for dependent
420 // template arguments and whether they contain any unexpanded pack
421 // expansions.
422 if (TemplateArgs) {
423 bool Dependent = false;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000424 bool InstantiationDependent = false;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000425 bool ContainsUnexpandedParameterPack = false;
James Y Knighte7d82282015-12-29 18:15:14 +0000426 getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(
427 TemplateKWLoc, *TemplateArgs, getTrailingTemplateArgumentLoc(),
428 Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000429
430 if (Dependent) {
Douglas Gregor678d76c2011-07-01 01:22:09 +0000431 ExprBits.TypeDependent = true;
432 ExprBits.ValueDependent = true;
433 }
434 if (InstantiationDependent)
435 ExprBits.InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000436 if (ContainsUnexpandedParameterPack)
437 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000438 } else if (TemplateKWLoc.isValid()) {
James Y Knighte7d82282015-12-29 18:15:14 +0000439 getTrailingASTTemplateKWAndArgsInfo()->initializeFrom(TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000440 }
441
442 if (isTypeDependent())
Bruno Riccid7628d92019-01-09 15:43:19 +0000443 setType(Context.DependentTy);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +0000444}
445
Bruno Riccid7628d92019-01-09 15:43:19 +0000446OverloadExpr::OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults,
447 bool HasTemplateKWAndArgsInfo)
448 : Expr(SC, Empty) {
449 OverloadExprBits.NumResults = NumResults;
450 OverloadExprBits.HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo;
John McCall8c12dc42010-04-22 18:44:12 +0000451}
452
John McCall8cd78132009-11-19 22:55:06 +0000453// DependentScopeDeclRefExpr
Bruno Ricci49ee9642019-01-07 14:27:04 +0000454DependentScopeDeclRefExpr::DependentScopeDeclRefExpr(
455 QualType Ty, NestedNameSpecifierLoc QualifierLoc,
456 SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
457 const TemplateArgumentListInfo *Args)
458 : Expr(
459 DependentScopeDeclRefExprClass, Ty, VK_LValue, OK_Ordinary, true,
460 true,
461 (NameInfo.isInstantiationDependent() ||
462 (QualifierLoc &&
463 QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())),
464 (NameInfo.containsUnexpandedParameterPack() ||
465 (QualifierLoc && QualifierLoc.getNestedNameSpecifier()
466 ->containsUnexpandedParameterPack()))),
467 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {
468 DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo =
469 (Args != nullptr) || TemplateKWLoc.isValid();
Douglas Gregora6e053e2010-12-15 01:34:56 +0000470 if (Args) {
471 bool Dependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +0000472 bool InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +0000473 bool ContainsUnexpandedParameterPack
474 = ExprBits.ContainsUnexpandedParameterPack;
James Y Knighte7d82282015-12-29 18:15:14 +0000475 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
476 TemplateKWLoc, *Args, getTrailingObjects<TemplateArgumentLoc>(),
477 Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000478 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
Abramo Bagnara7945c982012-01-27 09:46:47 +0000479 } else if (TemplateKWLoc.isValid()) {
James Y Knighte7d82282015-12-29 18:15:14 +0000480 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
481 TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +0000482 }
483}
484
Bruno Ricci49ee9642019-01-07 14:27:04 +0000485DependentScopeDeclRefExpr *DependentScopeDeclRefExpr::Create(
486 const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
487 SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo,
488 const TemplateArgumentListInfo *Args) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +0000489 assert(QualifierLoc && "should be created for dependent qualifiers");
James Y Knighte7d82282015-12-29 18:15:14 +0000490 bool HasTemplateKWAndArgsInfo = Args || TemplateKWLoc.isValid();
491 std::size_t Size =
492 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
493 HasTemplateKWAndArgsInfo, Args ? Args->size() : 0);
Bruno Ricci49ee9642019-01-07 14:27:04 +0000494 void *Mem = Context.Allocate(Size);
495 return new (Mem) DependentScopeDeclRefExpr(Context.DependentTy, QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000496 TemplateKWLoc, NameInfo, Args);
John McCalle66edc12009-11-24 19:00:30 +0000497}
498
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000499DependentScopeDeclRefExpr *
Bruno Ricci49ee9642019-01-07 14:27:04 +0000500DependentScopeDeclRefExpr::CreateEmpty(const ASTContext &Context,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000501 bool HasTemplateKWAndArgsInfo,
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000502 unsigned NumTemplateArgs) {
James Y Knighte7d82282015-12-29 18:15:14 +0000503 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
504 std::size_t Size =
505 totalSizeToAlloc<ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
506 HasTemplateKWAndArgsInfo, NumTemplateArgs);
Bruno Ricci49ee9642019-01-07 14:27:04 +0000507 void *Mem = Context.Allocate(Size);
508 auto *E = new (Mem) DependentScopeDeclRefExpr(
509 QualType(), NestedNameSpecifierLoc(), SourceLocation(),
510 DeclarationNameInfo(), nullptr);
511 E->DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo =
512 HasTemplateKWAndArgsInfo;
Douglas Gregor87866ce2011-02-04 12:01:24 +0000513 return E;
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +0000514}
515
Stephen Kelly724e9e52018-08-09 20:05:03 +0000516SourceLocation CXXConstructExpr::getBeginLoc() const {
John McCall701417a2011-02-21 06:23:05 +0000517 if (isa<CXXTemporaryObjectExpr>(this))
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000518 return cast<CXXTemporaryObjectExpr>(this)->getBeginLoc();
Bruno Ricciddb8f6b2018-12-22 14:39:30 +0000519 return getLocation();
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000520}
521
Stephen Kelly02a67ba2018-08-09 20:05:47 +0000522SourceLocation CXXConstructExpr::getEndLoc() const {
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000523 if (isa<CXXTemporaryObjectExpr>(this))
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000524 return cast<CXXTemporaryObjectExpr>(this)->getEndLoc();
John McCall701417a2011-02-21 06:23:05 +0000525
Enea Zaffanella76e98fe2013-09-07 05:49:53 +0000526 if (ParenOrBraceRange.isValid())
527 return ParenOrBraceRange.getEnd();
Douglas Gregor15417cf2010-11-03 00:35:38 +0000528
Bruno Ricciddb8f6b2018-12-22 14:39:30 +0000529 SourceLocation End = getLocation();
Douglas Gregor15417cf2010-11-03 00:35:38 +0000530 for (unsigned I = getNumArgs(); I > 0; --I) {
531 const Expr *Arg = getArg(I-1);
532 if (!Arg->isDefaultArgument()) {
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000533 SourceLocation NewEnd = Arg->getEndLoc();
Douglas Gregor15417cf2010-11-03 00:35:38 +0000534 if (NewEnd.isValid()) {
535 End = NewEnd;
536 break;
537 }
538 }
539 }
540
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000541 return End;
Ted Kremenek49ace5c2009-12-23 04:00:48 +0000542}
543
Bruno Riccic5885cf2018-12-21 15:20:32 +0000544CXXOperatorCallExpr::CXXOperatorCallExpr(OverloadedOperatorKind OpKind,
545 Expr *Fn, ArrayRef<Expr *> Args,
546 QualType Ty, ExprValueKind VK,
547 SourceLocation OperatorLoc,
548 FPOptions FPFeatures,
549 ADLCallKind UsesADL)
550 : CallExpr(CXXOperatorCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
Bruno Riccifeb19232018-12-21 16:51:57 +0000551 OperatorLoc, /*MinNumArgs=*/0, UsesADL) {
552 CXXOperatorCallExprBits.OperatorKind = OpKind;
553 CXXOperatorCallExprBits.FPFeatures = FPFeatures.getInt();
Bruno Riccic4ba5462018-12-21 17:54:51 +0000554 assert(
555 (CXXOperatorCallExprBits.OperatorKind == static_cast<unsigned>(OpKind)) &&
556 "OperatorKind overflow!");
Bruno Riccifeb19232018-12-21 16:51:57 +0000557 assert((CXXOperatorCallExprBits.FPFeatures == FPFeatures.getInt()) &&
558 "FPFeatures overflow!");
Bruno Riccic5885cf2018-12-21 15:20:32 +0000559 Range = getSourceRangeImpl();
560}
561
562CXXOperatorCallExpr::CXXOperatorCallExpr(unsigned NumArgs, EmptyShell Empty)
563 : CallExpr(CXXOperatorCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {}
564
565CXXOperatorCallExpr *CXXOperatorCallExpr::Create(
566 const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn,
567 ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
568 SourceLocation OperatorLoc, FPOptions FPFeatures, ADLCallKind UsesADL) {
569 // Allocate storage for the trailing objects of CallExpr.
570 unsigned NumArgs = Args.size();
571 unsigned SizeOfTrailingObjects =
572 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
573 void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects,
574 alignof(CXXOperatorCallExpr));
575 return new (Mem) CXXOperatorCallExpr(OpKind, Fn, Args, Ty, VK, OperatorLoc,
576 FPFeatures, UsesADL);
577}
578
579CXXOperatorCallExpr *CXXOperatorCallExpr::CreateEmpty(const ASTContext &Ctx,
580 unsigned NumArgs,
581 EmptyShell Empty) {
582 // Allocate storage for the trailing objects of CallExpr.
583 unsigned SizeOfTrailingObjects =
584 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
585 void *Mem = Ctx.Allocate(sizeof(CXXOperatorCallExpr) + SizeOfTrailingObjects,
586 alignof(CXXOperatorCallExpr));
587 return new (Mem) CXXOperatorCallExpr(NumArgs, Empty);
588}
589
Argyrios Kyrtzidisd8e07692012-04-30 22:12:22 +0000590SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const {
Douglas Gregor993603d2008-11-14 16:09:21 +0000591 OverloadedOperatorKind Kind = getOperator();
592 if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) {
593 if (getNumArgs() == 1)
594 // Prefix operator
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000595 return SourceRange(getOperatorLoc(), getArg(0)->getEndLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000596 else
597 // Postfix operator
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000598 return SourceRange(getArg(0)->getBeginLoc(), getOperatorLoc());
Chandler Carruthf20ec9232011-04-02 09:47:38 +0000599 } else if (Kind == OO_Arrow) {
600 return getArg(0)->getSourceRange();
Douglas Gregor993603d2008-11-14 16:09:21 +0000601 } else if (Kind == OO_Call) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000602 return SourceRange(getArg(0)->getBeginLoc(), getRParenLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000603 } else if (Kind == OO_Subscript) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000604 return SourceRange(getArg(0)->getBeginLoc(), getRParenLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000605 } else if (getNumArgs() == 1) {
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000606 return SourceRange(getOperatorLoc(), getArg(0)->getEndLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000607 } else if (getNumArgs() == 2) {
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000608 return SourceRange(getArg(0)->getBeginLoc(), getArg(1)->getEndLoc());
Douglas Gregor993603d2008-11-14 16:09:21 +0000609 } else {
Argyrios Kyrtzidisd8e07692012-04-30 22:12:22 +0000610 return getOperatorLoc();
Douglas Gregor993603d2008-11-14 16:09:21 +0000611 }
612}
613
Bruno Riccic5885cf2018-12-21 15:20:32 +0000614CXXMemberCallExpr::CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args,
615 QualType Ty, ExprValueKind VK,
616 SourceLocation RP, unsigned MinNumArgs)
617 : CallExpr(CXXMemberCallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK, RP,
618 MinNumArgs, NotADL) {}
619
620CXXMemberCallExpr::CXXMemberCallExpr(unsigned NumArgs, EmptyShell Empty)
621 : CallExpr(CXXMemberCallExprClass, /*NumPreArgs=*/0, NumArgs, Empty) {}
622
623CXXMemberCallExpr *CXXMemberCallExpr::Create(const ASTContext &Ctx, Expr *Fn,
624 ArrayRef<Expr *> Args, QualType Ty,
625 ExprValueKind VK,
626 SourceLocation RP,
627 unsigned MinNumArgs) {
628 // Allocate storage for the trailing objects of CallExpr.
629 unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
630 unsigned SizeOfTrailingObjects =
631 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
632 void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects,
633 alignof(CXXMemberCallExpr));
634 return new (Mem) CXXMemberCallExpr(Fn, Args, Ty, VK, RP, MinNumArgs);
635}
636
637CXXMemberCallExpr *CXXMemberCallExpr::CreateEmpty(const ASTContext &Ctx,
638 unsigned NumArgs,
639 EmptyShell Empty) {
640 // Allocate storage for the trailing objects of CallExpr.
641 unsigned SizeOfTrailingObjects =
642 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
643 void *Mem = Ctx.Allocate(sizeof(CXXMemberCallExpr) + SizeOfTrailingObjects,
644 alignof(CXXMemberCallExpr));
645 return new (Mem) CXXMemberCallExpr(NumArgs, Empty);
646}
647
Ted Kremenek98a24e32011-03-30 17:41:19 +0000648Expr *CXXMemberCallExpr::getImplicitObjectArgument() const {
Jordan Rose16fe35e2012-08-03 23:08:39 +0000649 const Expr *Callee = getCallee()->IgnoreParens();
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000650 if (const auto *MemExpr = dyn_cast<MemberExpr>(Callee))
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000651 return MemExpr->getBase();
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000652 if (const auto *BO = dyn_cast<BinaryOperator>(Callee))
Jordan Rose16fe35e2012-08-03 23:08:39 +0000653 if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI)
654 return BO->getLHS();
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000655
656 // FIXME: Will eventually need to cope with member pointers.
Craig Topper36250ad2014-05-12 05:36:57 +0000657 return nullptr;
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000658}
659
Marco Antognini88559632019-07-22 09:39:13 +0000660QualType CXXMemberCallExpr::getObjectType() const {
661 QualType Ty = getImplicitObjectArgument()->getType();
662 if (Ty->isPointerType())
663 Ty = Ty->getPointeeType();
664 return Ty;
665}
666
Ted Kremenek98a24e32011-03-30 17:41:19 +0000667CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const {
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000668 if (const auto *MemExpr = dyn_cast<MemberExpr>(getCallee()->IgnoreParens()))
Ted Kremenek98a24e32011-03-30 17:41:19 +0000669 return cast<CXXMethodDecl>(MemExpr->getMemberDecl());
670
671 // FIXME: Will eventually need to cope with member pointers.
Craig Topper36250ad2014-05-12 05:36:57 +0000672 return nullptr;
Ted Kremenek98a24e32011-03-30 17:41:19 +0000673}
674
David Blaikiec0f58662012-05-03 16:25:49 +0000675CXXRecordDecl *CXXMemberCallExpr::getRecordDecl() const {
Chandler Carruth00426b42010-10-27 06:55:41 +0000676 Expr* ThisArg = getImplicitObjectArgument();
677 if (!ThisArg)
Craig Topper36250ad2014-05-12 05:36:57 +0000678 return nullptr;
Chandler Carruth00426b42010-10-27 06:55:41 +0000679
680 if (ThisArg->getType()->isAnyPointerType())
681 return ThisArg->getType()->getPointeeType()->getAsCXXRecordDecl();
682
683 return ThisArg->getType()->getAsCXXRecordDecl();
684}
685
Douglas Gregore200adc2008-10-27 19:41:14 +0000686//===----------------------------------------------------------------------===//
687// Named casts
688//===----------------------------------------------------------------------===//
689
690/// getCastName - Get the name of the C++ cast being used, e.g.,
691/// "static_cast", "dynamic_cast", "reinterpret_cast", or
692/// "const_cast". The returned pointer must not be freed.
693const char *CXXNamedCastExpr::getCastName() const {
694 switch (getStmtClass()) {
695 case CXXStaticCastExprClass: return "static_cast";
696 case CXXDynamicCastExprClass: return "dynamic_cast";
697 case CXXReinterpretCastExprClass: return "reinterpret_cast";
698 case CXXConstCastExprClass: return "const_cast";
699 default: return "<invalid cast>";
700 }
701}
Douglas Gregordd04d332009-01-16 18:33:17 +0000702
Craig Toppera31a8822013-08-22 07:09:37 +0000703CXXStaticCastExpr *CXXStaticCastExpr::Create(const ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000704 ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000705 CastKind K, Expr *Op,
706 const CXXCastPath *BasePath,
707 TypeSourceInfo *WrittenTy,
Fangrui Song6907ce22018-07-30 19:24:48 +0000708 SourceLocation L,
Fariborz Jahanianf0738712013-02-22 22:02:53 +0000709 SourceLocation RParenLoc,
710 SourceRange AngleBrackets) {
John McCallcf142162010-08-07 06:22:56 +0000711 unsigned PathSize = (BasePath ? BasePath->size() : 0);
Bruno Ricci49391652019-01-09 16:41:33 +0000712 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000713 auto *E =
714 new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
715 RParenLoc, AngleBrackets);
James Y Knight1d75c5e2015-12-30 02:27:28 +0000716 if (PathSize)
717 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
718 E->getTrailingObjects<CXXBaseSpecifier *>());
John McCallcf142162010-08-07 06:22:56 +0000719 return E;
720}
721
Craig Toppera31a8822013-08-22 07:09:37 +0000722CXXStaticCastExpr *CXXStaticCastExpr::CreateEmpty(const ASTContext &C,
John McCallcf142162010-08-07 06:22:56 +0000723 unsigned PathSize) {
Bruno Ricci49391652019-01-09 16:41:33 +0000724 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
John McCallcf142162010-08-07 06:22:56 +0000725 return new (Buffer) CXXStaticCastExpr(EmptyShell(), PathSize);
726}
727
Craig Toppera31a8822013-08-22 07:09:37 +0000728CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000729 ExprValueKind VK,
John McCallcf142162010-08-07 06:22:56 +0000730 CastKind K, Expr *Op,
731 const CXXCastPath *BasePath,
732 TypeSourceInfo *WrittenTy,
Fangrui Song6907ce22018-07-30 19:24:48 +0000733 SourceLocation L,
Fariborz Jahanianf0738712013-02-22 22:02:53 +0000734 SourceLocation RParenLoc,
735 SourceRange AngleBrackets) {
John McCallcf142162010-08-07 06:22:56 +0000736 unsigned PathSize = (BasePath ? BasePath->size() : 0);
Bruno Ricci49391652019-01-09 16:41:33 +0000737 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000738 auto *E =
739 new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
740 RParenLoc, AngleBrackets);
James Y Knight1d75c5e2015-12-30 02:27:28 +0000741 if (PathSize)
742 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
743 E->getTrailingObjects<CXXBaseSpecifier *>());
John McCallcf142162010-08-07 06:22:56 +0000744 return E;
745}
746
Craig Toppera31a8822013-08-22 07:09:37 +0000747CXXDynamicCastExpr *CXXDynamicCastExpr::CreateEmpty(const ASTContext &C,
John McCallcf142162010-08-07 06:22:56 +0000748 unsigned PathSize) {
Bruno Ricci49391652019-01-09 16:41:33 +0000749 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
John McCallcf142162010-08-07 06:22:56 +0000750 return new (Buffer) CXXDynamicCastExpr(EmptyShell(), PathSize);
751}
752
Anders Carlsson267c0c92011-04-11 01:43:55 +0000753/// isAlwaysNull - Return whether the result of the dynamic_cast is proven
754/// to always be null. For example:
755///
756/// struct A { };
757/// struct B final : A { };
758/// struct C { };
759///
760/// C *f(B* b) { return dynamic_cast<C*>(b); }
761bool CXXDynamicCastExpr::isAlwaysNull() const
762{
763 QualType SrcType = getSubExpr()->getType();
764 QualType DestType = getType();
765
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000766 if (const auto *SrcPTy = SrcType->getAs<PointerType>()) {
Anders Carlsson267c0c92011-04-11 01:43:55 +0000767 SrcType = SrcPTy->getPointeeType();
768 DestType = DestType->castAs<PointerType>()->getPointeeType();
769 }
770
Alexis Hunt78e2b912012-06-19 23:44:55 +0000771 if (DestType->isVoidType())
772 return false;
773
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000774 const auto *SrcRD =
775 cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
Anders Carlsson267c0c92011-04-11 01:43:55 +0000776
Jakob Stoklund Olesene1c0ae62012-06-19 21:48:43 +0000777 if (!SrcRD->hasAttr<FinalAttr>())
778 return false;
779
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000780 const auto *DestRD =
781 cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
Anders Carlsson267c0c92011-04-11 01:43:55 +0000782
783 return !DestRD->isDerivedFrom(SrcRD);
784}
785
John McCallcf142162010-08-07 06:22:56 +0000786CXXReinterpretCastExpr *
Craig Toppera31a8822013-08-22 07:09:37 +0000787CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T,
788 ExprValueKind VK, CastKind K, Expr *Op,
John McCallcf142162010-08-07 06:22:56 +0000789 const CXXCastPath *BasePath,
Fangrui Song6907ce22018-07-30 19:24:48 +0000790 TypeSourceInfo *WrittenTy, SourceLocation L,
Fariborz Jahanianf0738712013-02-22 22:02:53 +0000791 SourceLocation RParenLoc,
792 SourceRange AngleBrackets) {
John McCallcf142162010-08-07 06:22:56 +0000793 unsigned PathSize = (BasePath ? BasePath->size() : 0);
Bruno Ricci49391652019-01-09 16:41:33 +0000794 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000795 auto *E =
796 new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
797 RParenLoc, AngleBrackets);
James Y Knight1d75c5e2015-12-30 02:27:28 +0000798 if (PathSize)
799 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
800 E->getTrailingObjects<CXXBaseSpecifier *>());
John McCallcf142162010-08-07 06:22:56 +0000801 return E;
802}
803
804CXXReinterpretCastExpr *
Craig Toppera31a8822013-08-22 07:09:37 +0000805CXXReinterpretCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) {
Bruno Ricci49391652019-01-09 16:41:33 +0000806 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
John McCallcf142162010-08-07 06:22:56 +0000807 return new (Buffer) CXXReinterpretCastExpr(EmptyShell(), PathSize);
808}
809
Craig Toppera31a8822013-08-22 07:09:37 +0000810CXXConstCastExpr *CXXConstCastExpr::Create(const ASTContext &C, QualType T,
John McCall7decc9e2010-11-18 06:31:45 +0000811 ExprValueKind VK, Expr *Op,
John McCallcf142162010-08-07 06:22:56 +0000812 TypeSourceInfo *WrittenTy,
Fangrui Song6907ce22018-07-30 19:24:48 +0000813 SourceLocation L,
Fariborz Jahanianf0738712013-02-22 22:02:53 +0000814 SourceLocation RParenLoc,
815 SourceRange AngleBrackets) {
816 return new (C) CXXConstCastExpr(T, VK, Op, WrittenTy, L, RParenLoc, AngleBrackets);
John McCallcf142162010-08-07 06:22:56 +0000817}
818
Craig Toppera31a8822013-08-22 07:09:37 +0000819CXXConstCastExpr *CXXConstCastExpr::CreateEmpty(const ASTContext &C) {
John McCallcf142162010-08-07 06:22:56 +0000820 return new (C) CXXConstCastExpr(EmptyShell());
821}
822
823CXXFunctionalCastExpr *
Craig Toppera31a8822013-08-22 07:09:37 +0000824CXXFunctionalCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK,
Eli Friedman89fe0d52013-08-15 22:02:56 +0000825 TypeSourceInfo *Written, CastKind K, Expr *Op,
826 const CXXCastPath *BasePath,
827 SourceLocation L, SourceLocation R) {
John McCallcf142162010-08-07 06:22:56 +0000828 unsigned PathSize = (BasePath ? BasePath->size() : 0);
Bruno Ricci49391652019-01-09 16:41:33 +0000829 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
Eugene Zelenkobc5858b2018-04-10 22:54:42 +0000830 auto *E =
831 new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R);
James Y Knight1d75c5e2015-12-30 02:27:28 +0000832 if (PathSize)
833 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
834 E->getTrailingObjects<CXXBaseSpecifier *>());
John McCallcf142162010-08-07 06:22:56 +0000835 return E;
836}
837
838CXXFunctionalCastExpr *
Craig Toppera31a8822013-08-22 07:09:37 +0000839CXXFunctionalCastExpr::CreateEmpty(const ASTContext &C, unsigned PathSize) {
Bruno Ricci49391652019-01-09 16:41:33 +0000840 void *Buffer = C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *>(PathSize));
John McCallcf142162010-08-07 06:22:56 +0000841 return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
842}
843
Stephen Kelly724e9e52018-08-09 20:05:03 +0000844SourceLocation CXXFunctionalCastExpr::getBeginLoc() const {
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000845 return getTypeInfoAsWritten()->getTypeLoc().getBeginLoc();
Eli Friedman89fe0d52013-08-15 22:02:56 +0000846}
847
Stephen Kelly02a67ba2018-08-09 20:05:47 +0000848SourceLocation CXXFunctionalCastExpr::getEndLoc() const {
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000849 return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getEndLoc();
Eli Friedman89fe0d52013-08-15 22:02:56 +0000850}
851
Bruno Riccic5885cf2018-12-21 15:20:32 +0000852UserDefinedLiteral::UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args,
853 QualType Ty, ExprValueKind VK,
854 SourceLocation LitEndLoc,
855 SourceLocation SuffixLoc)
856 : CallExpr(UserDefinedLiteralClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
857 LitEndLoc, /*MinNumArgs=*/0, NotADL),
858 UDSuffixLoc(SuffixLoc) {}
859
860UserDefinedLiteral::UserDefinedLiteral(unsigned NumArgs, EmptyShell Empty)
861 : CallExpr(UserDefinedLiteralClass, /*NumPreArgs=*/0, NumArgs, Empty) {}
862
863UserDefinedLiteral *UserDefinedLiteral::Create(const ASTContext &Ctx, Expr *Fn,
864 ArrayRef<Expr *> Args,
865 QualType Ty, ExprValueKind VK,
866 SourceLocation LitEndLoc,
867 SourceLocation SuffixLoc) {
868 // Allocate storage for the trailing objects of CallExpr.
869 unsigned NumArgs = Args.size();
870 unsigned SizeOfTrailingObjects =
871 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
872 void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects,
873 alignof(UserDefinedLiteral));
874 return new (Mem) UserDefinedLiteral(Fn, Args, Ty, VK, LitEndLoc, SuffixLoc);
875}
876
877UserDefinedLiteral *UserDefinedLiteral::CreateEmpty(const ASTContext &Ctx,
878 unsigned NumArgs,
879 EmptyShell Empty) {
880 // Allocate storage for the trailing objects of CallExpr.
881 unsigned SizeOfTrailingObjects =
882 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs);
883 void *Mem = Ctx.Allocate(sizeof(UserDefinedLiteral) + SizeOfTrailingObjects,
884 alignof(UserDefinedLiteral));
885 return new (Mem) UserDefinedLiteral(NumArgs, Empty);
886}
887
Richard Smithc67fdd42012-03-07 08:35:16 +0000888UserDefinedLiteral::LiteralOperatorKind
889UserDefinedLiteral::getLiteralOperatorKind() const {
890 if (getNumArgs() == 0)
891 return LOK_Template;
892 if (getNumArgs() == 2)
893 return LOK_String;
894
895 assert(getNumArgs() == 1 && "unexpected #args in literal operator call");
896 QualType ParamTy =
897 cast<FunctionDecl>(getCalleeDecl())->getParamDecl(0)->getType();
898 if (ParamTy->isPointerType())
899 return LOK_Raw;
900 if (ParamTy->isAnyCharacterType())
901 return LOK_Character;
902 if (ParamTy->isIntegerType())
903 return LOK_Integer;
904 if (ParamTy->isFloatingType())
905 return LOK_Floating;
906
907 llvm_unreachable("unknown kind of literal operator");
908}
909
910Expr *UserDefinedLiteral::getCookedLiteral() {
911#ifndef NDEBUG
912 LiteralOperatorKind LOK = getLiteralOperatorKind();
913 assert(LOK != LOK_Template && LOK != LOK_Raw && "not a cooked literal");
914#endif
915 return getArg(0);
916}
917
918const IdentifierInfo *UserDefinedLiteral::getUDSuffix() const {
919 return cast<FunctionDecl>(getCalleeDecl())->getLiteralIdentifier();
920}
John McCallcf142162010-08-07 06:22:56 +0000921
Bruno Riccifd66eb82018-11-17 13:02:47 +0000922CXXDefaultInitExpr::CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc,
Eric Fiselier708afb52019-05-16 21:04:15 +0000923 FieldDecl *Field, QualType Ty,
924 DeclContext *UsedContext)
Bruno Riccifd66eb82018-11-17 13:02:47 +0000925 : Expr(CXXDefaultInitExprClass, Ty.getNonLValueExprType(Ctx),
926 Ty->isLValueReferenceType() ? VK_LValue : Ty->isRValueReferenceType()
Richard Smith852c9db2013-04-20 22:23:05 +0000927 ? VK_XValue
928 : VK_RValue,
929 /*FIXME*/ OK_Ordinary, false, false, false, false),
Eric Fiselier708afb52019-05-16 21:04:15 +0000930 Field(Field), UsedContext(UsedContext) {
Bruno Riccifd66eb82018-11-17 13:02:47 +0000931 CXXDefaultInitExprBits.Loc = Loc;
Richard Smith852c9db2013-04-20 22:23:05 +0000932 assert(Field->hasInClassInitializer());
933}
934
Craig Toppera31a8822013-08-22 07:09:37 +0000935CXXTemporary *CXXTemporary::Create(const ASTContext &C,
Anders Carlssonffda6062009-05-30 20:34:37 +0000936 const CXXDestructorDecl *Destructor) {
Anders Carlsson73b836b2009-05-30 22:38:53 +0000937 return new (C) CXXTemporary(Destructor);
938}
939
Craig Toppera31a8822013-08-22 07:09:37 +0000940CXXBindTemporaryExpr *CXXBindTemporaryExpr::Create(const ASTContext &C,
Anders Carlsson993a4b32009-05-30 20:03:25 +0000941 CXXTemporary *Temp,
942 Expr* SubExpr) {
Peter Collingbournefbef4c82011-11-27 22:09:28 +0000943 assert((SubExpr->getType()->isRecordType() ||
944 SubExpr->getType()->isArrayType()) &&
945 "Expression bound to a temporary must have record or array type!");
Anders Carlsson993a4b32009-05-30 20:03:25 +0000946
Douglas Gregora6e053e2010-12-15 01:34:56 +0000947 return new (C) CXXBindTemporaryExpr(Temp, SubExpr);
Anders Carlsson993a4b32009-05-30 20:03:25 +0000948}
949
Bruno Ricciddb8f6b2018-12-22 14:39:30 +0000950CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(
951 CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI,
952 ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange,
953 bool HadMultipleCandidates, bool ListInitialization,
954 bool StdInitListInitialization, bool ZeroInitialization)
955 : CXXConstructExpr(
956 CXXTemporaryObjectExprClass, Ty, TSI->getTypeLoc().getBeginLoc(),
957 Cons, /* Elidable=*/false, Args, HadMultipleCandidates,
958 ListInitialization, StdInitListInitialization, ZeroInitialization,
959 CXXConstructExpr::CK_Complete, ParenOrBraceRange),
960 TSI(TSI) {}
961
962CXXTemporaryObjectExpr::CXXTemporaryObjectExpr(EmptyShell Empty,
963 unsigned NumArgs)
964 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty, NumArgs) {}
965
966CXXTemporaryObjectExpr *CXXTemporaryObjectExpr::Create(
967 const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty,
968 TypeSourceInfo *TSI, ArrayRef<Expr *> Args, SourceRange ParenOrBraceRange,
969 bool HadMultipleCandidates, bool ListInitialization,
970 bool StdInitListInitialization, bool ZeroInitialization) {
971 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size());
972 void *Mem =
973 Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects,
974 alignof(CXXTemporaryObjectExpr));
975 return new (Mem) CXXTemporaryObjectExpr(
976 Cons, Ty, TSI, Args, ParenOrBraceRange, HadMultipleCandidates,
977 ListInitialization, StdInitListInitialization, ZeroInitialization);
978}
979
980CXXTemporaryObjectExpr *
981CXXTemporaryObjectExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs) {
982 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs);
983 void *Mem =
984 Ctx.Allocate(sizeof(CXXTemporaryObjectExpr) + SizeOfTrailingObjects,
985 alignof(CXXTemporaryObjectExpr));
986 return new (Mem) CXXTemporaryObjectExpr(EmptyShell(), NumArgs);
987}
Douglas Gregor2b88c112010-09-08 00:15:04 +0000988
Stephen Kelly724e9e52018-08-09 20:05:03 +0000989SourceLocation CXXTemporaryObjectExpr::getBeginLoc() const {
Bruno Ricciddb8f6b2018-12-22 14:39:30 +0000990 return getTypeSourceInfo()->getTypeLoc().getBeginLoc();
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000991}
992
Stephen Kelly02a67ba2018-08-09 20:05:47 +0000993SourceLocation CXXTemporaryObjectExpr::getEndLoc() const {
Argyrios Kyrtzidis623ecfd2013-09-11 23:23:27 +0000994 SourceLocation Loc = getParenOrBraceRange().getEnd();
995 if (Loc.isInvalid() && getNumArgs())
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000996 Loc = getArg(getNumArgs() - 1)->getEndLoc();
Argyrios Kyrtzidis623ecfd2013-09-11 23:23:27 +0000997 return Loc;
Douglas Gregordd04d332009-01-16 18:33:17 +0000998}
Anders Carlsson6f287832009-04-21 02:22:11 +0000999
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001000CXXConstructExpr *CXXConstructExpr::Create(
1001 const ASTContext &Ctx, QualType Ty, SourceLocation Loc,
1002 CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args,
1003 bool HadMultipleCandidates, bool ListInitialization,
1004 bool StdInitListInitialization, bool ZeroInitialization,
1005 ConstructionKind ConstructKind, SourceRange ParenOrBraceRange) {
1006 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(Args.size());
1007 void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects,
1008 alignof(CXXConstructExpr));
1009 return new (Mem) CXXConstructExpr(
1010 CXXConstructExprClass, Ty, Loc, Ctor, Elidable, Args,
1011 HadMultipleCandidates, ListInitialization, StdInitListInitialization,
1012 ZeroInitialization, ConstructKind, ParenOrBraceRange);
Anders Carlsson0781ce72009-04-23 02:32:43 +00001013}
1014
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001015CXXConstructExpr *CXXConstructExpr::CreateEmpty(const ASTContext &Ctx,
1016 unsigned NumArgs) {
1017 unsigned SizeOfTrailingObjects = sizeOfTrailingObjects(NumArgs);
1018 void *Mem = Ctx.Allocate(sizeof(CXXConstructExpr) + SizeOfTrailingObjects,
1019 alignof(CXXConstructExpr));
1020 return new (Mem)
1021 CXXConstructExpr(CXXConstructExprClass, EmptyShell(), NumArgs);
1022}
Fangrui Song6907ce22018-07-30 19:24:48 +00001023
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001024CXXConstructExpr::CXXConstructExpr(
1025 StmtClass SC, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor,
1026 bool Elidable, ArrayRef<Expr *> Args, bool HadMultipleCandidates,
1027 bool ListInitialization, bool StdInitListInitialization,
1028 bool ZeroInitialization, ConstructionKind ConstructKind,
1029 SourceRange ParenOrBraceRange)
1030 : Expr(SC, Ty, VK_RValue, OK_Ordinary, Ty->isDependentType(),
1031 Ty->isDependentType(), Ty->isInstantiationDependentType(),
1032 Ty->containsUnexpandedParameterPack()),
1033 Constructor(Ctor), ParenOrBraceRange(ParenOrBraceRange),
1034 NumArgs(Args.size()) {
1035 CXXConstructExprBits.Elidable = Elidable;
1036 CXXConstructExprBits.HadMultipleCandidates = HadMultipleCandidates;
1037 CXXConstructExprBits.ListInitialization = ListInitialization;
1038 CXXConstructExprBits.StdInitListInitialization = StdInitListInitialization;
1039 CXXConstructExprBits.ZeroInitialization = ZeroInitialization;
1040 CXXConstructExprBits.ConstructionKind = ConstructKind;
1041 CXXConstructExprBits.Loc = Loc;
Douglas Gregora6e053e2010-12-15 01:34:56 +00001042
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001043 Stmt **TrailingArgs = getTrailingArgs();
1044 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1045 assert(Args[I] && "NULL argument in CXXConstructExpr!");
Fangrui Song6907ce22018-07-30 19:24:48 +00001046
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001047 if (Args[I]->isValueDependent())
1048 ExprBits.ValueDependent = true;
1049 if (Args[I]->isInstantiationDependent())
1050 ExprBits.InstantiationDependent = true;
1051 if (Args[I]->containsUnexpandedParameterPack())
1052 ExprBits.ContainsUnexpandedParameterPack = true;
1053
1054 TrailingArgs[I] = Args[I];
Douglas Gregor4f4b1862009-12-16 18:50:27 +00001055 }
Anders Carlsson0781ce72009-04-23 02:32:43 +00001056}
1057
Bruno Ricciddb8f6b2018-12-22 14:39:30 +00001058CXXConstructExpr::CXXConstructExpr(StmtClass SC, EmptyShell Empty,
1059 unsigned NumArgs)
1060 : Expr(SC, Empty), NumArgs(NumArgs) {}
1061
Benjamin Kramerf3ca26982014-05-10 16:31:55 +00001062LambdaCapture::LambdaCapture(SourceLocation Loc, bool Implicit,
Douglas Gregore31e6062012-02-07 10:09:13 +00001063 LambdaCaptureKind Kind, VarDecl *Var,
1064 SourceLocation EllipsisLoc)
Eugene Zelenko821f6982017-11-18 01:47:41 +00001065 : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc) {
Douglas Gregore31e6062012-02-07 10:09:13 +00001066 unsigned Bits = 0;
1067 if (Implicit)
1068 Bits |= Capture_Implicit;
Fangrui Song6907ce22018-07-30 19:24:48 +00001069
Douglas Gregore31e6062012-02-07 10:09:13 +00001070 switch (Kind) {
Faisal Validc6b5962016-03-21 09:25:37 +00001071 case LCK_StarThis:
1072 Bits |= Capture_ByCopy;
Adrian Prantlf3b3ccd2017-12-19 22:06:11 +00001073 LLVM_FALLTHROUGH;
Craig Topper36250ad2014-05-12 05:36:57 +00001074 case LCK_This:
1075 assert(!Var && "'this' capture cannot have a variable!");
John Brawn771721c2016-06-15 14:14:51 +00001076 Bits |= Capture_This;
Douglas Gregore31e6062012-02-07 10:09:13 +00001077 break;
1078
1079 case LCK_ByCopy:
1080 Bits |= Capture_ByCopy;
Adrian Prantlf3b3ccd2017-12-19 22:06:11 +00001081 LLVM_FALLTHROUGH;
Douglas Gregore31e6062012-02-07 10:09:13 +00001082 case LCK_ByRef:
1083 assert(Var && "capture must have a variable!");
1084 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001085 case LCK_VLAType:
1086 assert(!Var && "VLA type capture cannot have a variable!");
Alexey Bataev39c81e22014-08-28 04:28:19 +00001087 break;
Douglas Gregore31e6062012-02-07 10:09:13 +00001088 }
John Brawn771721c2016-06-15 14:14:51 +00001089 DeclAndBits.setInt(Bits);
Douglas Gregore31e6062012-02-07 10:09:13 +00001090}
1091
Benjamin Kramerf3ca26982014-05-10 16:31:55 +00001092LambdaCaptureKind LambdaCapture::getCaptureKind() const {
John Brawn771721c2016-06-15 14:14:51 +00001093 if (capturesVLAType())
Faisal Validc6b5962016-03-21 09:25:37 +00001094 return LCK_VLAType;
John Brawn771721c2016-06-15 14:14:51 +00001095 bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy;
1096 if (capturesThis())
Faisal Validc6b5962016-03-21 09:25:37 +00001097 return CapByCopy ? LCK_StarThis : LCK_This;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001098 return CapByCopy ? LCK_ByCopy : LCK_ByRef;
Douglas Gregore31e6062012-02-07 10:09:13 +00001099}
1100
James Y Knighte00a67e2015-12-31 04:18:25 +00001101LambdaExpr::LambdaExpr(QualType T, SourceRange IntroducerRange,
Douglas Gregore31e6062012-02-07 10:09:13 +00001102 LambdaCaptureDefault CaptureDefault,
James Dennettddd36ff2013-08-09 23:08:25 +00001103 SourceLocation CaptureDefaultLoc,
James Y Knighte00a67e2015-12-31 04:18:25 +00001104 ArrayRef<LambdaCapture> Captures, bool ExplicitParams,
1105 bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
Richard Smith2589b9802012-07-25 03:56:55 +00001106 SourceLocation ClosingBrace,
1107 bool ContainsUnexpandedParameterPack)
James Y Knighte00a67e2015-12-31 04:18:25 +00001108 : Expr(LambdaExprClass, T, VK_RValue, OK_Ordinary, T->isDependentType(),
1109 T->isDependentType(), T->isDependentType(),
1110 ContainsUnexpandedParameterPack),
1111 IntroducerRange(IntroducerRange), CaptureDefaultLoc(CaptureDefaultLoc),
1112 NumCaptures(Captures.size()), CaptureDefault(CaptureDefault),
1113 ExplicitParams(ExplicitParams), ExplicitResultType(ExplicitResultType),
1114 ClosingBrace(ClosingBrace) {
Douglas Gregore31e6062012-02-07 10:09:13 +00001115 assert(CaptureInits.size() == Captures.size() && "Wrong number of arguments");
Douglas Gregorc8a73492012-02-13 15:44:47 +00001116 CXXRecordDecl *Class = getLambdaClass();
1117 CXXRecordDecl::LambdaDefinitionData &Data = Class->getLambdaData();
Fangrui Song6907ce22018-07-30 19:24:48 +00001118
Douglas Gregorc8a73492012-02-13 15:44:47 +00001119 // FIXME: Propagate "has unexpanded parameter pack" bit.
Fangrui Song6907ce22018-07-30 19:24:48 +00001120
Douglas Gregore5561632012-02-13 17:20:40 +00001121 // Copy captures.
Craig Toppera31a8822013-08-22 07:09:37 +00001122 const ASTContext &Context = Class->getASTContext();
Douglas Gregore5561632012-02-13 17:20:40 +00001123 Data.NumCaptures = NumCaptures;
1124 Data.NumExplicitCaptures = 0;
James Y Knighte00a67e2015-12-31 04:18:25 +00001125 Data.Captures =
1126 (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) * NumCaptures);
1127 LambdaCapture *ToCapture = Data.Captures;
Douglas Gregore5561632012-02-13 17:20:40 +00001128 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
1129 if (Captures[I].isExplicit())
1130 ++Data.NumExplicitCaptures;
Fangrui Song6907ce22018-07-30 19:24:48 +00001131
Douglas Gregore5561632012-02-13 17:20:40 +00001132 *ToCapture++ = Captures[I];
1133 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001134
Douglas Gregore5561632012-02-13 17:20:40 +00001135 // Copy initialization expressions for the non-static data members.
1136 Stmt **Stored = getStoredStmts();
1137 for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I)
1138 *Stored++ = CaptureInits[I];
Fangrui Song6907ce22018-07-30 19:24:48 +00001139
Douglas Gregore5561632012-02-13 17:20:40 +00001140 // Copy the body of the lambda.
1141 *Stored++ = getCallOperator()->getBody();
Douglas Gregore31e6062012-02-07 10:09:13 +00001142}
1143
James Y Knighte00a67e2015-12-31 04:18:25 +00001144LambdaExpr *LambdaExpr::Create(
1145 const ASTContext &Context, CXXRecordDecl *Class,
1146 SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault,
1147 SourceLocation CaptureDefaultLoc, ArrayRef<LambdaCapture> Captures,
1148 bool ExplicitParams, bool ExplicitResultType, ArrayRef<Expr *> CaptureInits,
James Y Knighte00a67e2015-12-31 04:18:25 +00001149 SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack) {
Douglas Gregore31e6062012-02-07 10:09:13 +00001150 // Determine the type of the expression (i.e., the type of the
1151 // function object we're creating).
1152 QualType T = Context.getTypeDeclType(Class);
Douglas Gregore31e6062012-02-07 10:09:13 +00001153
Richard Smith30e304e2016-12-14 00:03:17 +00001154 unsigned Size = totalSizeToAlloc<Stmt *>(Captures.size() + 1);
Douglas Gregore5561632012-02-13 17:20:40 +00001155 void *Mem = Context.Allocate(Size);
Richard Smith30e304e2016-12-14 00:03:17 +00001156 return new (Mem)
1157 LambdaExpr(T, IntroducerRange, CaptureDefault, CaptureDefaultLoc,
1158 Captures, ExplicitParams, ExplicitResultType, CaptureInits,
1159 ClosingBrace, ContainsUnexpandedParameterPack);
Douglas Gregore31e6062012-02-07 10:09:13 +00001160}
1161
Craig Toppera31a8822013-08-22 07:09:37 +00001162LambdaExpr *LambdaExpr::CreateDeserialized(const ASTContext &C,
Richard Smith30e304e2016-12-14 00:03:17 +00001163 unsigned NumCaptures) {
1164 unsigned Size = totalSizeToAlloc<Stmt *>(NumCaptures + 1);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001165 void *Mem = C.Allocate(Size);
Richard Smith30e304e2016-12-14 00:03:17 +00001166 return new (Mem) LambdaExpr(EmptyShell(), NumCaptures);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001167}
1168
James Dennettdd2ffea22015-05-07 18:48:18 +00001169bool LambdaExpr::isInitCapture(const LambdaCapture *C) const {
1170 return (C->capturesVariable() && C->getCapturedVar()->isInitCapture() &&
1171 (getCallOperator() == C->getCapturedVar()->getDeclContext()));
1172}
1173
Douglas Gregorc8a73492012-02-13 15:44:47 +00001174LambdaExpr::capture_iterator LambdaExpr::capture_begin() const {
Douglas Gregore5561632012-02-13 17:20:40 +00001175 return getLambdaClass()->getLambdaData().Captures;
Douglas Gregorc8a73492012-02-13 15:44:47 +00001176}
1177
1178LambdaExpr::capture_iterator LambdaExpr::capture_end() const {
Douglas Gregore5561632012-02-13 17:20:40 +00001179 return capture_begin() + NumCaptures;
Douglas Gregorc8a73492012-02-13 15:44:47 +00001180}
1181
James Dennett1575cb42014-05-27 19:13:04 +00001182LambdaExpr::capture_range LambdaExpr::captures() const {
1183 return capture_range(capture_begin(), capture_end());
1184}
1185
Douglas Gregorc8a73492012-02-13 15:44:47 +00001186LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const {
1187 return capture_begin();
1188}
1189
1190LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const {
1191 struct CXXRecordDecl::LambdaDefinitionData &Data
1192 = getLambdaClass()->getLambdaData();
Douglas Gregore5561632012-02-13 17:20:40 +00001193 return Data.Captures + Data.NumExplicitCaptures;
Douglas Gregorc8a73492012-02-13 15:44:47 +00001194}
1195
James Dennett1575cb42014-05-27 19:13:04 +00001196LambdaExpr::capture_range LambdaExpr::explicit_captures() const {
1197 return capture_range(explicit_capture_begin(), explicit_capture_end());
1198}
1199
Douglas Gregorc8a73492012-02-13 15:44:47 +00001200LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const {
1201 return explicit_capture_end();
1202}
1203
1204LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const {
1205 return capture_end();
1206}
1207
James Dennett1575cb42014-05-27 19:13:04 +00001208LambdaExpr::capture_range LambdaExpr::implicit_captures() const {
1209 return capture_range(implicit_capture_begin(), implicit_capture_end());
1210}
1211
Douglas Gregore31e6062012-02-07 10:09:13 +00001212CXXRecordDecl *LambdaExpr::getLambdaClass() const {
1213 return getType()->getAsCXXRecordDecl();
1214}
1215
1216CXXMethodDecl *LambdaExpr::getCallOperator() const {
1217 CXXRecordDecl *Record = getLambdaClass();
Fangrui Song6907ce22018-07-30 19:24:48 +00001218 return Record->getLambdaCallOperator();
Faisal Vali2b391ab2013-09-26 19:54:12 +00001219}
1220
Erich Keane5c2c60d2019-09-30 19:12:29 +00001221FunctionTemplateDecl *LambdaExpr::getDependentCallOperator() const {
1222 CXXRecordDecl *Record = getLambdaClass();
1223 return Record->getDependentLambdaCallOperator();
1224}
1225
Faisal Vali2b391ab2013-09-26 19:54:12 +00001226TemplateParameterList *LambdaExpr::getTemplateParameterList() const {
1227 CXXRecordDecl *Record = getLambdaClass();
1228 return Record->getGenericLambdaTemplateParameterList();
Hamza Sood8205a812019-05-04 10:49:46 +00001229}
Faisal Vali2b391ab2013-09-26 19:54:12 +00001230
Hamza Sood8205a812019-05-04 10:49:46 +00001231ArrayRef<NamedDecl *> LambdaExpr::getExplicitTemplateParameters() const {
1232 const CXXRecordDecl *Record = getLambdaClass();
1233 return Record->getLambdaExplicitTemplateParameters();
Douglas Gregore31e6062012-02-07 10:09:13 +00001234}
1235
Douglas Gregor99ae8062012-02-14 17:54:36 +00001236CompoundStmt *LambdaExpr::getBody() const {
James Y Knight53c76162015-07-17 18:21:37 +00001237 // FIXME: this mutation in getBody is bogus. It should be
1238 // initialized in ASTStmtReader::VisitLambdaExpr, but for reasons I
1239 // don't understand, that doesn't work.
Douglas Gregor99ae8062012-02-14 17:54:36 +00001240 if (!getStoredStmts()[NumCaptures])
Eugene Zelenko821f6982017-11-18 01:47:41 +00001241 *const_cast<Stmt **>(&getStoredStmts()[NumCaptures]) =
James Y Knight53c76162015-07-17 18:21:37 +00001242 getCallOperator()->getBody();
1243
James Y Knighte00a67e2015-12-31 04:18:25 +00001244 return static_cast<CompoundStmt *>(getStoredStmts()[NumCaptures]);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001245}
1246
Douglas Gregore31e6062012-02-07 10:09:13 +00001247bool LambdaExpr::isMutable() const {
David Blaikief5697e52012-08-10 00:55:35 +00001248 return !getCallOperator()->isConst();
Douglas Gregore31e6062012-02-07 10:09:13 +00001249}
1250
John McCall28fc7092011-11-10 05:35:25 +00001251ExprWithCleanups::ExprWithCleanups(Expr *subexpr,
Tim Shen4a05bb82016-06-21 20:29:17 +00001252 bool CleanupsHaveSideEffects,
John McCall28fc7092011-11-10 05:35:25 +00001253 ArrayRef<CleanupObject> objects)
Bill Wendling7c44da22018-10-31 03:48:47 +00001254 : FullExpr(ExprWithCleanupsClass, subexpr) {
Tim Shen4a05bb82016-06-21 20:29:17 +00001255 ExprWithCleanupsBits.CleanupsHaveSideEffects = CleanupsHaveSideEffects;
John McCall28fc7092011-11-10 05:35:25 +00001256 ExprWithCleanupsBits.NumObjects = objects.size();
1257 for (unsigned i = 0, e = objects.size(); i != e; ++i)
James Y Knighte00a67e2015-12-31 04:18:25 +00001258 getTrailingObjects<CleanupObject>()[i] = objects[i];
Anders Carlssondefc6442009-04-24 22:47:04 +00001259}
1260
Craig Toppera31a8822013-08-22 07:09:37 +00001261ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C, Expr *subexpr,
Tim Shen4a05bb82016-06-21 20:29:17 +00001262 bool CleanupsHaveSideEffects,
John McCall28fc7092011-11-10 05:35:25 +00001263 ArrayRef<CleanupObject> objects) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001264 void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(objects.size()),
Benjamin Kramerc3f89252016-10-20 14:27:22 +00001265 alignof(ExprWithCleanups));
Tim Shen4a05bb82016-06-21 20:29:17 +00001266 return new (buffer)
1267 ExprWithCleanups(subexpr, CleanupsHaveSideEffects, objects);
Chris Lattnercba86142010-05-10 00:25:06 +00001268}
1269
John McCall28fc7092011-11-10 05:35:25 +00001270ExprWithCleanups::ExprWithCleanups(EmptyShell empty, unsigned numObjects)
Bill Wendling7c44da22018-10-31 03:48:47 +00001271 : FullExpr(ExprWithCleanupsClass, empty) {
John McCall28fc7092011-11-10 05:35:25 +00001272 ExprWithCleanupsBits.NumObjects = numObjects;
1273}
Chris Lattnercba86142010-05-10 00:25:06 +00001274
Craig Toppera31a8822013-08-22 07:09:37 +00001275ExprWithCleanups *ExprWithCleanups::Create(const ASTContext &C,
1276 EmptyShell empty,
John McCall28fc7092011-11-10 05:35:25 +00001277 unsigned numObjects) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001278 void *buffer = C.Allocate(totalSizeToAlloc<CleanupObject>(numObjects),
Benjamin Kramerc3f89252016-10-20 14:27:22 +00001279 alignof(ExprWithCleanups));
John McCall28fc7092011-11-10 05:35:25 +00001280 return new (buffer) ExprWithCleanups(empty, numObjects);
Anders Carlsson73b836b2009-05-30 22:38:53 +00001281}
1282
Bruno Ricci49ee9642019-01-07 14:27:04 +00001283CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *TSI,
1284 SourceLocation LParenLoc,
1285 ArrayRef<Expr *> Args,
1286 SourceLocation RParenLoc)
Eugene Zelenko821f6982017-11-18 01:47:41 +00001287 : Expr(CXXUnresolvedConstructExprClass,
Bruno Ricci49ee9642019-01-07 14:27:04 +00001288 TSI->getType().getNonReferenceType(),
1289 (TSI->getType()->isLValueReferenceType()
Eugene Zelenko821f6982017-11-18 01:47:41 +00001290 ? VK_LValue
Bruno Ricci49ee9642019-01-07 14:27:04 +00001291 : TSI->getType()->isRValueReferenceType() ? VK_XValue
1292 : VK_RValue),
Eugene Zelenko821f6982017-11-18 01:47:41 +00001293 OK_Ordinary,
Bruno Ricci49ee9642019-01-07 14:27:04 +00001294 TSI->getType()->isDependentType() ||
1295 TSI->getType()->getContainedDeducedType(),
1296 true, true, TSI->getType()->containsUnexpandedParameterPack()),
1297 TSI(TSI), LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
1298 CXXUnresolvedConstructExprBits.NumArgs = Args.size();
Eugene Zelenkobc5858b2018-04-10 22:54:42 +00001299 auto **StoredArgs = getTrailingObjects<Expr *>();
Benjamin Kramerc215e762012-08-24 11:54:20 +00001300 for (unsigned I = 0; I != Args.size(); ++I) {
Douglas Gregora6e053e2010-12-15 01:34:56 +00001301 if (Args[I]->containsUnexpandedParameterPack())
1302 ExprBits.ContainsUnexpandedParameterPack = true;
1303
1304 StoredArgs[I] = Args[I];
1305 }
Douglas Gregorce934142009-05-20 18:46:25 +00001306}
1307
Bruno Ricci49ee9642019-01-07 14:27:04 +00001308CXXUnresolvedConstructExpr *CXXUnresolvedConstructExpr::Create(
1309 const ASTContext &Context, TypeSourceInfo *TSI, SourceLocation LParenLoc,
1310 ArrayRef<Expr *> Args, SourceLocation RParenLoc) {
1311 void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(Args.size()));
1312 return new (Mem) CXXUnresolvedConstructExpr(TSI, LParenLoc, Args, RParenLoc);
Douglas Gregorce934142009-05-20 18:46:25 +00001313}
1314
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001315CXXUnresolvedConstructExpr *
Bruno Ricci49ee9642019-01-07 14:27:04 +00001316CXXUnresolvedConstructExpr::CreateEmpty(const ASTContext &Context,
1317 unsigned NumArgs) {
1318 void *Mem = Context.Allocate(totalSizeToAlloc<Expr *>(NumArgs));
1319 return new (Mem) CXXUnresolvedConstructExpr(EmptyShell(), NumArgs);
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001320}
1321
Stephen Kelly724e9e52018-08-09 20:05:03 +00001322SourceLocation CXXUnresolvedConstructExpr::getBeginLoc() const {
Bruno Ricci49ee9642019-01-07 14:27:04 +00001323 return TSI->getTypeLoc().getBeginLoc();
Douglas Gregor2b88c112010-09-08 00:15:04 +00001324}
1325
James Y Knighte7d82282015-12-29 18:15:14 +00001326CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001327 const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
James Y Knighte7d82282015-12-29 18:15:14 +00001328 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1329 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1330 DeclarationNameInfo MemberNameInfo,
1331 const TemplateArgumentListInfo *TemplateArgs)
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001332 : Expr(CXXDependentScopeMemberExprClass, Ctx.DependentTy, VK_LValue,
James Y Knighte7d82282015-12-29 18:15:14 +00001333 OK_Ordinary, true, true, true,
1334 ((Base && Base->containsUnexpandedParameterPack()) ||
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001335 (QualifierLoc && QualifierLoc.getNestedNameSpecifier()
1336 ->containsUnexpandedParameterPack()) ||
James Y Knighte7d82282015-12-29 18:15:14 +00001337 MemberNameInfo.containsUnexpandedParameterPack())),
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001338 Base(Base), BaseType(BaseType), QualifierLoc(QualifierLoc),
James Y Knighte7d82282015-12-29 18:15:14 +00001339 MemberNameInfo(MemberNameInfo) {
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001340 CXXDependentScopeMemberExprBits.IsArrow = IsArrow;
1341 CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo =
1342 (TemplateArgs != nullptr) || TemplateKWLoc.isValid();
1343 CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope =
1344 FirstQualifierFoundInScope != nullptr;
1345 CXXDependentScopeMemberExprBits.OperatorLoc = OperatorLoc;
1346
Douglas Gregora6e053e2010-12-15 01:34:56 +00001347 if (TemplateArgs) {
1348 bool Dependent = true;
Douglas Gregor678d76c2011-07-01 01:22:09 +00001349 bool InstantiationDependent = true;
Douglas Gregora6e053e2010-12-15 01:34:56 +00001350 bool ContainsUnexpandedParameterPack = false;
James Y Knighte7d82282015-12-29 18:15:14 +00001351 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1352 TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
1353 Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
Douglas Gregora6e053e2010-12-15 01:34:56 +00001354 if (ContainsUnexpandedParameterPack)
1355 ExprBits.ContainsUnexpandedParameterPack = true;
Abramo Bagnara7945c982012-01-27 09:46:47 +00001356 } else if (TemplateKWLoc.isValid()) {
James Y Knighte7d82282015-12-29 18:15:14 +00001357 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1358 TemplateKWLoc);
Douglas Gregora6e053e2010-12-15 01:34:56 +00001359 }
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001360
1361 if (hasFirstQualifierFoundInScope())
1362 *getTrailingObjects<NamedDecl *>() = FirstQualifierFoundInScope;
Douglas Gregor308047d2009-09-09 00:23:06 +00001363}
1364
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001365CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(
1366 EmptyShell Empty, bool HasTemplateKWAndArgsInfo,
1367 bool HasFirstQualifierFoundInScope)
1368 : Expr(CXXDependentScopeMemberExprClass, Empty) {
1369 CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo =
1370 HasTemplateKWAndArgsInfo;
1371 CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope =
1372 HasFirstQualifierFoundInScope;
1373}
1374
1375CXXDependentScopeMemberExpr *CXXDependentScopeMemberExpr::Create(
1376 const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow,
1377 SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc,
1378 SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope,
1379 DeclarationNameInfo MemberNameInfo,
1380 const TemplateArgumentListInfo *TemplateArgs) {
1381 bool HasTemplateKWAndArgsInfo =
1382 (TemplateArgs != nullptr) || TemplateKWLoc.isValid();
Abramo Bagnara7945c982012-01-27 09:46:47 +00001383 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001384 bool HasFirstQualifierFoundInScope = FirstQualifierFoundInScope != nullptr;
John McCall6b51f282009-11-23 01:53:49 +00001385
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001386 unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo,
1387 TemplateArgumentLoc, NamedDecl *>(
1388 HasTemplateKWAndArgsInfo, NumTemplateArgs, HasFirstQualifierFoundInScope);
1389
1390 void *Mem = Ctx.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
1391 return new (Mem) CXXDependentScopeMemberExpr(
1392 Ctx, Base, BaseType, IsArrow, OperatorLoc, QualifierLoc, TemplateKWLoc,
1393 FirstQualifierFoundInScope, MemberNameInfo, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001394}
1395
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001396CXXDependentScopeMemberExpr *CXXDependentScopeMemberExpr::CreateEmpty(
1397 const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo,
1398 unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope) {
James Y Knighte7d82282015-12-29 18:15:14 +00001399 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +00001400
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001401 unsigned Size = totalSizeToAlloc<ASTTemplateKWAndArgsInfo,
1402 TemplateArgumentLoc, NamedDecl *>(
1403 HasTemplateKWAndArgsInfo, NumTemplateArgs, HasFirstQualifierFoundInScope);
Fangrui Song6907ce22018-07-30 19:24:48 +00001404
Bruno Ricci2e6dc532019-01-08 14:17:00 +00001405 void *Mem = Ctx.Allocate(Size, alignof(CXXDependentScopeMemberExpr));
1406 return new (Mem) CXXDependentScopeMemberExpr(
1407 EmptyShell(), HasTemplateKWAndArgsInfo, HasFirstQualifierFoundInScope);
Douglas Gregor0da1d432011-02-28 20:01:57 +00001408}
1409
John McCall0009fcc2011-04-26 20:42:42 +00001410static bool hasOnlyNonStaticMemberFunctions(UnresolvedSetIterator begin,
1411 UnresolvedSetIterator end) {
1412 do {
1413 NamedDecl *decl = *begin;
1414 if (isa<UnresolvedUsingValueDecl>(decl))
1415 return false;
John McCall0009fcc2011-04-26 20:42:42 +00001416
1417 // Unresolved member expressions should only contain methods and
1418 // method templates.
Alp Tokera2794f92014-01-22 07:29:52 +00001419 if (cast<CXXMethodDecl>(decl->getUnderlyingDecl()->getAsFunction())
1420 ->isStatic())
John McCall0009fcc2011-04-26 20:42:42 +00001421 return false;
1422 } while (++begin != end);
1423
1424 return true;
1425}
1426
Bruno Riccid7628d92019-01-09 15:43:19 +00001427UnresolvedMemberExpr::UnresolvedMemberExpr(
1428 const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
1429 QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
1430 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1431 const DeclarationNameInfo &MemberNameInfo,
1432 const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
1433 UnresolvedSetIterator End)
Eugene Zelenko821f6982017-11-18 01:47:41 +00001434 : OverloadExpr(
Bruno Riccid7628d92019-01-09 15:43:19 +00001435 UnresolvedMemberExprClass, Context, QualifierLoc, TemplateKWLoc,
Eugene Zelenko821f6982017-11-18 01:47:41 +00001436 MemberNameInfo, TemplateArgs, Begin, End,
1437 // Dependent
1438 ((Base && Base->isTypeDependent()) || BaseType->isDependentType()),
1439 ((Base && Base->isInstantiationDependent()) ||
1440 BaseType->isInstantiationDependentType()),
1441 // Contains unexpanded parameter pack
1442 ((Base && Base->containsUnexpandedParameterPack()) ||
1443 BaseType->containsUnexpandedParameterPack())),
Bruno Riccid7628d92019-01-09 15:43:19 +00001444 Base(Base), BaseType(BaseType), OperatorLoc(OperatorLoc) {
1445 UnresolvedMemberExprBits.IsArrow = IsArrow;
1446 UnresolvedMemberExprBits.HasUnresolvedUsing = HasUnresolvedUsing;
1447
John McCall0009fcc2011-04-26 20:42:42 +00001448 // Check whether all of the members are non-static member functions,
1449 // and if so, mark give this bound-member type instead of overload type.
1450 if (hasOnlyNonStaticMemberFunctions(Begin, End))
Bruno Riccid7628d92019-01-09 15:43:19 +00001451 setType(Context.BoundMemberTy);
John McCall10eae182009-11-30 22:42:35 +00001452}
1453
Bruno Riccid7628d92019-01-09 15:43:19 +00001454UnresolvedMemberExpr::UnresolvedMemberExpr(EmptyShell Empty,
1455 unsigned NumResults,
1456 bool HasTemplateKWAndArgsInfo)
1457 : OverloadExpr(UnresolvedMemberExprClass, Empty, NumResults,
1458 HasTemplateKWAndArgsInfo) {}
1459
Douglas Gregor0da1d432011-02-28 20:01:57 +00001460bool UnresolvedMemberExpr::isImplicitAccess() const {
Craig Topper36250ad2014-05-12 05:36:57 +00001461 if (!Base)
Douglas Gregor0da1d432011-02-28 20:01:57 +00001462 return true;
Fangrui Song6907ce22018-07-30 19:24:48 +00001463
Douglas Gregor25b7e052011-03-02 21:06:53 +00001464 return cast<Expr>(Base)->isImplicitCXXThis();
Douglas Gregor0da1d432011-02-28 20:01:57 +00001465}
1466
James Y Knighte7d82282015-12-29 18:15:14 +00001467UnresolvedMemberExpr *UnresolvedMemberExpr::Create(
Bruno Riccid7628d92019-01-09 15:43:19 +00001468 const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base,
1469 QualType BaseType, bool IsArrow, SourceLocation OperatorLoc,
James Y Knighte7d82282015-12-29 18:15:14 +00001470 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1471 const DeclarationNameInfo &MemberNameInfo,
1472 const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
1473 UnresolvedSetIterator End) {
Bruno Riccid7628d92019-01-09 15:43:19 +00001474 unsigned NumResults = End - Begin;
James Y Knighte7d82282015-12-29 18:15:14 +00001475 bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
Bruno Riccid7628d92019-01-09 15:43:19 +00001476 unsigned NumTemplateArgs = TemplateArgs ? TemplateArgs->size() : 0;
1477 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
1478 TemplateArgumentLoc>(
1479 NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
1480 void *Mem = Context.Allocate(Size, alignof(UnresolvedMemberExpr));
James Y Knighte7d82282015-12-29 18:15:14 +00001481 return new (Mem) UnresolvedMemberExpr(
Bruno Riccid7628d92019-01-09 15:43:19 +00001482 Context, HasUnresolvedUsing, Base, BaseType, IsArrow, OperatorLoc,
1483 QualifierLoc, TemplateKWLoc, MemberNameInfo, TemplateArgs, Begin, End);
John McCall10eae182009-11-30 22:42:35 +00001484}
1485
Bruno Riccid7628d92019-01-09 15:43:19 +00001486UnresolvedMemberExpr *UnresolvedMemberExpr::CreateEmpty(
1487 const ASTContext &Context, unsigned NumResults,
1488 bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs) {
James Y Knighte7d82282015-12-29 18:15:14 +00001489 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
Bruno Riccid7628d92019-01-09 15:43:19 +00001490 unsigned Size = totalSizeToAlloc<DeclAccessPair, ASTTemplateKWAndArgsInfo,
1491 TemplateArgumentLoc>(
1492 NumResults, HasTemplateKWAndArgsInfo, NumTemplateArgs);
1493 void *Mem = Context.Allocate(Size, alignof(UnresolvedMemberExpr));
1494 return new (Mem)
1495 UnresolvedMemberExpr(EmptyShell(), NumResults, HasTemplateKWAndArgsInfo);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +00001496}
1497
Bruno Riccid7628d92019-01-09 15:43:19 +00001498CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() {
John McCall58cc69d2010-01-27 01:50:18 +00001499 // Unlike for UnresolvedLookupExpr, it is very easy to re-derive this.
1500
1501 // If there was a nested name specifier, it names the naming class.
1502 // It can't be dependent: after all, we were actually able to do the
1503 // lookup.
Craig Topper36250ad2014-05-12 05:36:57 +00001504 CXXRecordDecl *Record = nullptr;
Nikola Smiljanic67860242014-09-26 00:28:20 +00001505 auto *NNS = getQualifier();
1506 if (NNS && NNS->getKind() != NestedNameSpecifier::Super) {
John McCall424cec92011-01-19 06:33:43 +00001507 const Type *T = getQualifier()->getAsType();
John McCall58cc69d2010-01-27 01:50:18 +00001508 assert(T && "qualifier in member expression does not name type");
Douglas Gregor9262f472010-04-27 18:19:34 +00001509 Record = T->getAsCXXRecordDecl();
1510 assert(Record && "qualifier in member expression does not name record");
1511 }
John McCall58cc69d2010-01-27 01:50:18 +00001512 // Otherwise the naming class must have been the base class.
Douglas Gregor9262f472010-04-27 18:19:34 +00001513 else {
John McCall58cc69d2010-01-27 01:50:18 +00001514 QualType BaseType = getBaseType().getNonReferenceType();
1515 if (isArrow()) {
Eugene Zelenkobc5858b2018-04-10 22:54:42 +00001516 const auto *PT = BaseType->getAs<PointerType>();
John McCall58cc69d2010-01-27 01:50:18 +00001517 assert(PT && "base of arrow member access is not pointer");
1518 BaseType = PT->getPointeeType();
1519 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001520
Douglas Gregor9262f472010-04-27 18:19:34 +00001521 Record = BaseType->getAsCXXRecordDecl();
1522 assert(Record && "base of member expression does not name record");
John McCall58cc69d2010-01-27 01:50:18 +00001523 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001524
Douglas Gregor9262f472010-04-27 18:19:34 +00001525 return Record;
John McCall58cc69d2010-01-27 01:50:18 +00001526}
1527
Richard Smithd784e682015-09-23 21:41:42 +00001528SizeOfPackExpr *
1529SizeOfPackExpr::Create(ASTContext &Context, SourceLocation OperatorLoc,
1530 NamedDecl *Pack, SourceLocation PackLoc,
1531 SourceLocation RParenLoc,
1532 Optional<unsigned> Length,
1533 ArrayRef<TemplateArgument> PartialArgs) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001534 void *Storage =
1535 Context.Allocate(totalSizeToAlloc<TemplateArgument>(PartialArgs.size()));
Richard Smithd784e682015-09-23 21:41:42 +00001536 return new (Storage) SizeOfPackExpr(Context.getSizeType(), OperatorLoc, Pack,
1537 PackLoc, RParenLoc, Length, PartialArgs);
1538}
1539
1540SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context,
1541 unsigned NumPartialArgs) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001542 void *Storage =
1543 Context.Allocate(totalSizeToAlloc<TemplateArgument>(NumPartialArgs));
Richard Smithd784e682015-09-23 21:41:42 +00001544 return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs);
1545}
1546
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001547SubstNonTypeTemplateParmPackExpr::
Fangrui Song6907ce22018-07-30 19:24:48 +00001548SubstNonTypeTemplateParmPackExpr(QualType T,
Richard Smithf1f20e62018-02-14 02:07:53 +00001549 ExprValueKind ValueKind,
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001550 NonTypeTemplateParmDecl *Param,
1551 SourceLocation NameLoc,
1552 const TemplateArgument &ArgPack)
Richard Smithf1f20e62018-02-14 02:07:53 +00001553 : Expr(SubstNonTypeTemplateParmPackExprClass, T, ValueKind, OK_Ordinary,
Eugene Zelenko821f6982017-11-18 01:47:41 +00001554 true, true, true, true),
1555 Param(Param), Arguments(ArgPack.pack_begin()),
1556 NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) {}
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001557
1558TemplateArgument SubstNonTypeTemplateParmPackExpr::getArgumentPack() const {
Benjamin Kramercce63472015-08-05 09:40:22 +00001559 return TemplateArgument(llvm::makeArrayRef(Arguments, NumArguments));
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001560}
1561
Richard Smithb2997f52019-05-21 20:10:50 +00001562FunctionParmPackExpr::FunctionParmPackExpr(QualType T, VarDecl *ParamPack,
Richard Smithb15fe3a2012-09-12 00:56:43 +00001563 SourceLocation NameLoc,
1564 unsigned NumParams,
Richard Smithb2997f52019-05-21 20:10:50 +00001565 VarDecl *const *Params)
James Y Knight48fefa32015-09-30 14:04:23 +00001566 : Expr(FunctionParmPackExprClass, T, VK_LValue, OK_Ordinary, true, true,
1567 true, true),
1568 ParamPack(ParamPack), NameLoc(NameLoc), NumParameters(NumParams) {
Richard Smithb15fe3a2012-09-12 00:56:43 +00001569 if (Params)
1570 std::uninitialized_copy(Params, Params + NumParams,
Richard Smithb2997f52019-05-21 20:10:50 +00001571 getTrailingObjects<VarDecl *>());
Richard Smithb15fe3a2012-09-12 00:56:43 +00001572}
1573
1574FunctionParmPackExpr *
Craig Toppera31a8822013-08-22 07:09:37 +00001575FunctionParmPackExpr::Create(const ASTContext &Context, QualType T,
Richard Smithb2997f52019-05-21 20:10:50 +00001576 VarDecl *ParamPack, SourceLocation NameLoc,
1577 ArrayRef<VarDecl *> Params) {
1578 return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(Params.size())))
James Y Knighte00a67e2015-12-31 04:18:25 +00001579 FunctionParmPackExpr(T, ParamPack, NameLoc, Params.size(), Params.data());
Richard Smithb15fe3a2012-09-12 00:56:43 +00001580}
1581
1582FunctionParmPackExpr *
Craig Toppera31a8822013-08-22 07:09:37 +00001583FunctionParmPackExpr::CreateEmpty(const ASTContext &Context,
1584 unsigned NumParams) {
Richard Smithb2997f52019-05-21 20:10:50 +00001585 return new (Context.Allocate(totalSizeToAlloc<VarDecl *>(NumParams)))
James Y Knighte00a67e2015-12-31 04:18:25 +00001586 FunctionParmPackExpr(QualType(), nullptr, SourceLocation(), 0, nullptr);
Richard Smithb15fe3a2012-09-12 00:56:43 +00001587}
1588
David Majnemerdaff3702014-05-01 17:50:17 +00001589void MaterializeTemporaryExpr::setExtendingDecl(const ValueDecl *ExtendedBy,
1590 unsigned ManglingNumber) {
1591 // We only need extra state if we have to remember more than just the Stmt.
1592 if (!ExtendedBy)
1593 return;
1594
1595 // We may need to allocate extra storage for the mangling number and the
1596 // extended-by ValueDecl.
1597 if (!State.is<ExtraState *>()) {
Eugene Zelenkobc5858b2018-04-10 22:54:42 +00001598 auto *ES = new (ExtendedBy->getASTContext()) ExtraState;
David Majnemerdaff3702014-05-01 17:50:17 +00001599 ES->Temporary = State.get<Stmt *>();
1600 State = ES;
1601 }
1602
1603 auto ES = State.get<ExtraState *>();
1604 ES->ExtendingDecl = ExtendedBy;
1605 ES->ManglingNumber = ManglingNumber;
1606}
1607
Douglas Gregor29c42f22012-02-24 07:38:34 +00001608TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
1609 ArrayRef<TypeSourceInfo *> Args,
1610 SourceLocation RParenLoc,
1611 bool Value)
Eugene Zelenko821f6982017-11-18 01:47:41 +00001612 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary,
1613 /*TypeDependent=*/false,
1614 /*ValueDependent=*/false,
1615 /*InstantiationDependent=*/false,
1616 /*ContainsUnexpandedParameterPack=*/false),
1617 Loc(Loc), RParenLoc(RParenLoc) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00001618 TypeTraitExprBits.Kind = Kind;
1619 TypeTraitExprBits.Value = Value;
1620 TypeTraitExprBits.NumArgs = Args.size();
1621
Eugene Zelenkobc5858b2018-04-10 22:54:42 +00001622 auto **ToArgs = getTrailingObjects<TypeSourceInfo *>();
James Y Knighte00a67e2015-12-31 04:18:25 +00001623
Douglas Gregor29c42f22012-02-24 07:38:34 +00001624 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1625 if (Args[I]->getType()->isDependentType())
1626 setValueDependent(true);
1627 if (Args[I]->getType()->isInstantiationDependentType())
1628 setInstantiationDependent(true);
1629 if (Args[I]->getType()->containsUnexpandedParameterPack())
1630 setContainsUnexpandedParameterPack(true);
Fangrui Song6907ce22018-07-30 19:24:48 +00001631
Douglas Gregor29c42f22012-02-24 07:38:34 +00001632 ToArgs[I] = Args[I];
1633 }
1634}
1635
Craig Toppera31a8822013-08-22 07:09:37 +00001636TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T,
Fangrui Song6907ce22018-07-30 19:24:48 +00001637 SourceLocation Loc,
Douglas Gregor29c42f22012-02-24 07:38:34 +00001638 TypeTrait Kind,
1639 ArrayRef<TypeSourceInfo *> Args,
1640 SourceLocation RParenLoc,
1641 bool Value) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001642 void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(Args.size()));
Douglas Gregor29c42f22012-02-24 07:38:34 +00001643 return new (Mem) TypeTraitExpr(T, Loc, Kind, Args, RParenLoc, Value);
1644}
1645
Craig Toppera31a8822013-08-22 07:09:37 +00001646TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const ASTContext &C,
Douglas Gregor29c42f22012-02-24 07:38:34 +00001647 unsigned NumArgs) {
James Y Knighte00a67e2015-12-31 04:18:25 +00001648 void *Mem = C.Allocate(totalSizeToAlloc<TypeSourceInfo *>(NumArgs));
Douglas Gregor29c42f22012-02-24 07:38:34 +00001649 return new (Mem) TypeTraitExpr(EmptyShell());
1650}
Bruno Riccic5885cf2018-12-21 15:20:32 +00001651
1652CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config,
1653 ArrayRef<Expr *> Args, QualType Ty,
1654 ExprValueKind VK, SourceLocation RP,
1655 unsigned MinNumArgs)
1656 : CallExpr(CUDAKernelCallExprClass, Fn, /*PreArgs=*/Config, Args, Ty, VK,
1657 RP, MinNumArgs, NotADL) {}
1658
1659CUDAKernelCallExpr::CUDAKernelCallExpr(unsigned NumArgs, EmptyShell Empty)
1660 : CallExpr(CUDAKernelCallExprClass, /*NumPreArgs=*/END_PREARG, NumArgs,
1661 Empty) {}
1662
1663CUDAKernelCallExpr *
1664CUDAKernelCallExpr::Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config,
1665 ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
1666 SourceLocation RP, unsigned MinNumArgs) {
1667 // Allocate storage for the trailing objects of CallExpr.
1668 unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
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(Fn, Config, Args, Ty, VK, RP, MinNumArgs);
1674}
1675
1676CUDAKernelCallExpr *CUDAKernelCallExpr::CreateEmpty(const ASTContext &Ctx,
1677 unsigned NumArgs,
1678 EmptyShell Empty) {
1679 // Allocate storage for the trailing objects of CallExpr.
1680 unsigned SizeOfTrailingObjects =
1681 CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/END_PREARG, NumArgs);
1682 void *Mem = Ctx.Allocate(sizeof(CUDAKernelCallExpr) + SizeOfTrailingObjects,
1683 alignof(CUDAKernelCallExpr));
1684 return new (Mem) CUDAKernelCallExpr(NumArgs, Empty);
1685}