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