/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/DeclCXX.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- DeclCXX.cpp - C++ Declaration 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 C++ related Decl classes. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "clang/AST/DeclCXX.h" |
14 | | #include "clang/AST/ASTContext.h" |
15 | | #include "clang/AST/ASTLambda.h" |
16 | | #include "clang/AST/ASTMutationListener.h" |
17 | | #include "clang/AST/ASTUnresolvedSet.h" |
18 | | #include "clang/AST/Attr.h" |
19 | | #include "clang/AST/CXXInheritance.h" |
20 | | #include "clang/AST/DeclBase.h" |
21 | | #include "clang/AST/DeclTemplate.h" |
22 | | #include "clang/AST/DeclarationName.h" |
23 | | #include "clang/AST/Expr.h" |
24 | | #include "clang/AST/ExprCXX.h" |
25 | | #include "clang/AST/LambdaCapture.h" |
26 | | #include "clang/AST/NestedNameSpecifier.h" |
27 | | #include "clang/AST/ODRHash.h" |
28 | | #include "clang/AST/Type.h" |
29 | | #include "clang/AST/TypeLoc.h" |
30 | | #include "clang/AST/UnresolvedSet.h" |
31 | | #include "clang/Basic/Diagnostic.h" |
32 | | #include "clang/Basic/IdentifierTable.h" |
33 | | #include "clang/Basic/LLVM.h" |
34 | | #include "clang/Basic/LangOptions.h" |
35 | | #include "clang/Basic/OperatorKinds.h" |
36 | | #include "clang/Basic/PartialDiagnostic.h" |
37 | | #include "clang/Basic/SourceLocation.h" |
38 | | #include "clang/Basic/Specifiers.h" |
39 | | #include "llvm/ADT/None.h" |
40 | | #include "llvm/ADT/SmallPtrSet.h" |
41 | | #include "llvm/ADT/SmallVector.h" |
42 | | #include "llvm/ADT/iterator_range.h" |
43 | | #include "llvm/Support/Casting.h" |
44 | | #include "llvm/Support/ErrorHandling.h" |
45 | | #include "llvm/Support/Format.h" |
46 | | #include "llvm/Support/raw_ostream.h" |
47 | | #include <algorithm> |
48 | | #include <cassert> |
49 | | #include <cstddef> |
50 | | #include <cstdint> |
51 | | |
52 | | using namespace clang; |
53 | | |
54 | | //===----------------------------------------------------------------------===// |
55 | | // Decl Allocation/Deallocation Method Implementations |
56 | | //===----------------------------------------------------------------------===// |
57 | | |
58 | 0 | void AccessSpecDecl::anchor() {} |
59 | | |
60 | 66.9k | AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
61 | 66.9k | return new (C, ID) AccessSpecDecl(EmptyShell()); |
62 | 66.9k | } |
63 | | |
64 | 189 | void LazyASTUnresolvedSet::getFromExternalSource(ASTContext &C) const { |
65 | 189 | ExternalASTSource *Source = C.getExternalSource(); |
66 | 189 | assert(Impl.Decls.isLazy() && "getFromExternalSource for non-lazy set"); |
67 | 0 | assert(Source && "getFromExternalSource with no external source"); |
68 | | |
69 | 394 | for (ASTUnresolvedSet::iterator I = Impl.begin(); I != Impl.end(); ++I205 ) |
70 | 205 | I.setDecl(cast<NamedDecl>(Source->GetExternalDecl( |
71 | 205 | reinterpret_cast<uintptr_t>(I.getDecl()) >> 2))); |
72 | 189 | Impl.Decls.setLazy(false); |
73 | 189 | } |
74 | | |
75 | | CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) |
76 | | : UserDeclaredConstructor(false), UserDeclaredSpecialMembers(0), |
77 | | Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false), |
78 | | Abstract(false), IsStandardLayout(true), IsCXX11StandardLayout(true), |
79 | | HasBasesWithFields(false), HasBasesWithNonStaticDataMembers(false), |
80 | | HasPrivateFields(false), HasProtectedFields(false), |
81 | | HasPublicFields(false), HasMutableFields(false), HasVariantMembers(false), |
82 | | HasOnlyCMembers(true), HasInitMethod(false), HasInClassInitializer(false), |
83 | | HasUninitializedReferenceMember(false), HasUninitializedFields(false), |
84 | | HasInheritedConstructor(false), HasInheritedDefaultConstructor(false), |
85 | | HasInheritedAssignment(false), |
86 | | NeedOverloadResolutionForCopyConstructor(false), |
87 | | NeedOverloadResolutionForMoveConstructor(false), |
88 | | NeedOverloadResolutionForCopyAssignment(false), |
89 | | NeedOverloadResolutionForMoveAssignment(false), |
90 | | NeedOverloadResolutionForDestructor(false), |
91 | | DefaultedCopyConstructorIsDeleted(false), |
92 | | DefaultedMoveConstructorIsDeleted(false), |
93 | | DefaultedCopyAssignmentIsDeleted(false), |
94 | | DefaultedMoveAssignmentIsDeleted(false), |
95 | | DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All), |
96 | | HasTrivialSpecialMembersForCall(SMF_All), |
97 | | DeclaredNonTrivialSpecialMembers(0), |
98 | | DeclaredNonTrivialSpecialMembersForCall(0), HasIrrelevantDestructor(true), |
99 | | HasConstexprNonCopyMoveConstructor(false), |
100 | | HasDefaultedDefaultConstructor(false), |
101 | | DefaultedDefaultConstructorIsConstexpr(true), |
102 | | HasConstexprDefaultConstructor(false), |
103 | | DefaultedDestructorIsConstexpr(true), |
104 | | HasNonLiteralTypeFieldsOrBases(false), StructuralIfLiteral(true), |
105 | | UserProvidedDefaultConstructor(false), DeclaredSpecialMembers(0), |
106 | | ImplicitCopyConstructorCanHaveConstParamForVBase(true), |
107 | | ImplicitCopyConstructorCanHaveConstParamForNonVBase(true), |
108 | | ImplicitCopyAssignmentHasConstParam(true), |
109 | | HasDeclaredCopyConstructorWithConstParam(false), |
110 | | HasDeclaredCopyAssignmentWithConstParam(false), |
111 | | IsAnyDestructorNoReturn(false), IsLambda(false), |
112 | | IsParsingBaseSpecifiers(false), ComputedVisibleConversions(false), |
113 | 3.92M | HasODRHash(false), Definition(D) {} |
114 | | |
115 | 54.5k | CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const { |
116 | 54.5k | return Bases.get(Definition->getASTContext().getExternalSource()); |
117 | 54.5k | } |
118 | | |
119 | 13 | CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getVBasesSlowCase() const { |
120 | 13 | return VBases.get(Definition->getASTContext().getExternalSource()); |
121 | 13 | } |
122 | | |
123 | | CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, |
124 | | DeclContext *DC, SourceLocation StartLoc, |
125 | | SourceLocation IdLoc, IdentifierInfo *Id, |
126 | | CXXRecordDecl *PrevDecl) |
127 | | : RecordDecl(K, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl), |
128 | | DefinitionData(PrevDecl ? PrevDecl->DefinitionData |
129 | 6.39M | : nullptr) {} |
130 | | |
131 | | CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, |
132 | | DeclContext *DC, SourceLocation StartLoc, |
133 | | SourceLocation IdLoc, IdentifierInfo *Id, |
134 | | CXXRecordDecl *PrevDecl, |
135 | 3.30M | bool DelayTypeCreation) { |
136 | 3.30M | auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, IdLoc, Id, |
137 | 3.30M | PrevDecl); |
138 | 3.30M | R->setMayHaveOutOfDateDef(C.getLangOpts().Modules); |
139 | | |
140 | | // FIXME: DelayTypeCreation seems like such a hack |
141 | 3.30M | if (!DelayTypeCreation) |
142 | 1.18M | C.getTypeDeclType(R, PrevDecl); |
143 | 3.30M | return R; |
144 | 3.30M | } |
145 | | |
146 | | CXXRecordDecl * |
147 | | CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC, |
148 | | TypeSourceInfo *Info, SourceLocation Loc, |
149 | | unsigned DependencyKind, bool IsGeneric, |
150 | 11.2k | LambdaCaptureDefault CaptureDefault) { |
151 | 11.2k | auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc, |
152 | 11.2k | nullptr, nullptr); |
153 | 11.2k | R->setBeingDefined(true); |
154 | 11.2k | R->DefinitionData = new (C) struct LambdaDefinitionData( |
155 | 11.2k | R, Info, DependencyKind, IsGeneric, CaptureDefault); |
156 | 11.2k | R->setMayHaveOutOfDateDef(false); |
157 | 11.2k | R->setImplicit(true); |
158 | | |
159 | 11.2k | C.getTypeDeclType(R, /*PrevDecl=*/nullptr); |
160 | 11.2k | return R; |
161 | 11.2k | } |
162 | | |
163 | | CXXRecordDecl * |
164 | 510k | CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { |
165 | 510k | auto *R = new (C, ID) CXXRecordDecl( |
166 | 510k | CXXRecord, TTK_Struct, C, nullptr, SourceLocation(), SourceLocation(), |
167 | 510k | nullptr, nullptr); |
168 | 510k | R->setMayHaveOutOfDateDef(false); |
169 | 510k | return R; |
170 | 510k | } |
171 | | |
172 | | /// Determine whether a class has a repeated base class. This is intended for |
173 | | /// use when determining if a class is standard-layout, so makes no attempt to |
174 | | /// handle virtual bases. |
175 | 7.63k | static bool hasRepeatedBaseClass(const CXXRecordDecl *StartRD) { |
176 | 7.63k | llvm::SmallPtrSet<const CXXRecordDecl*, 8> SeenBaseTypes; |
177 | 7.63k | SmallVector<const CXXRecordDecl*, 8> WorkList = {StartRD}; |
178 | 30.8k | while (!WorkList.empty()) { |
179 | 23.2k | const CXXRecordDecl *RD = WorkList.pop_back_val(); |
180 | 23.2k | if (RD->getTypeForDecl()->isDependentType()) |
181 | 3.22k | continue; |
182 | 20.0k | for (const CXXBaseSpecifier &BaseSpec : RD->bases()) { |
183 | 15.7k | if (const CXXRecordDecl *B = BaseSpec.getType()->getAsCXXRecordDecl()) { |
184 | 15.7k | if (!SeenBaseTypes.insert(B).second) |
185 | 82 | return true; |
186 | 15.6k | WorkList.push_back(B); |
187 | 15.6k | } |
188 | 15.7k | } |
189 | 20.0k | } |
190 | 7.55k | return false; |
191 | 7.63k | } |
192 | | |
193 | | void |
194 | | CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, |
195 | 674k | unsigned NumBases) { |
196 | 674k | ASTContext &C = getASTContext(); |
197 | | |
198 | 674k | if (!data().Bases.isOffset() && data().NumBases > 0) |
199 | 0 | C.Deallocate(data().getBases()); |
200 | | |
201 | 674k | if (NumBases) { |
202 | 674k | if (!C.getLangOpts().CPlusPlus17) { |
203 | | // C++ [dcl.init.aggr]p1: |
204 | | // An aggregate is [...] a class with [...] no base classes [...]. |
205 | 625k | data().Aggregate = false; |
206 | 625k | } |
207 | | |
208 | | // C++ [class]p4: |
209 | | // A POD-struct is an aggregate class... |
210 | 674k | data().PlainOldData = false; |
211 | 674k | } |
212 | | |
213 | | // The set of seen virtual base types. |
214 | 674k | llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes; |
215 | | |
216 | | // The virtual bases of this class. |
217 | 674k | SmallVector<const CXXBaseSpecifier *, 8> VBases; |
218 | | |
219 | 674k | data().Bases = new(C) CXXBaseSpecifier [NumBases]; |
220 | 674k | data().NumBases = NumBases; |
221 | 1.37M | for (unsigned i = 0; i < NumBases; ++i695k ) { |
222 | 695k | data().getBases()[i] = *Bases[i]; |
223 | | // Keep track of inherited vbases for this base class. |
224 | 695k | const CXXBaseSpecifier *Base = Bases[i]; |
225 | 695k | QualType BaseType = Base->getType(); |
226 | | // Skip dependent types; we can't do any checking on them now. |
227 | 695k | if (BaseType->isDependentType()) |
228 | 150k | continue; |
229 | 544k | auto *BaseClassDecl = |
230 | 544k | cast<CXXRecordDecl>(BaseType->castAs<RecordType>()->getDecl()); |
231 | | |
232 | | // C++2a [class]p7: |
233 | | // A standard-layout class is a class that: |
234 | | // [...] |
235 | | // -- has all non-static data members and bit-fields in the class and |
236 | | // its base classes first declared in the same class |
237 | 544k | if (BaseClassDecl->data().HasBasesWithFields || |
238 | 544k | !BaseClassDecl->field_empty()532k ) { |
239 | 35.9k | if (data().HasBasesWithFields) |
240 | | // Two bases have members or bit-fields: not standard-layout. |
241 | 10.1k | data().IsStandardLayout = false; |
242 | 35.9k | data().HasBasesWithFields = true; |
243 | 35.9k | } |
244 | | |
245 | | // C++11 [class]p7: |
246 | | // A standard-layout class is a class that: |
247 | | // -- [...] has [...] at most one base class with non-static data |
248 | | // members |
249 | 544k | if (BaseClassDecl->data().HasBasesWithNonStaticDataMembers || |
250 | 544k | BaseClassDecl->hasDirectFields()532k ) { |
251 | 35.9k | if (data().HasBasesWithNonStaticDataMembers) |
252 | 10.1k | data().IsCXX11StandardLayout = false; |
253 | 35.9k | data().HasBasesWithNonStaticDataMembers = true; |
254 | 35.9k | } |
255 | | |
256 | 544k | if (!BaseClassDecl->isEmpty()) { |
257 | | // C++14 [meta.unary.prop]p4: |
258 | | // T is a class type [...] with [...] no base class B for which |
259 | | // is_empty<B>::value is false. |
260 | 45.0k | data().Empty = false; |
261 | 45.0k | } |
262 | | |
263 | | // C++1z [dcl.init.agg]p1: |
264 | | // An aggregate is a class with [...] no private or protected base classes |
265 | 544k | if (Base->getAccessSpecifier() != AS_public) { |
266 | 39.9k | data().Aggregate = false; |
267 | | |
268 | | // C++20 [temp.param]p7: |
269 | | // A structural type is [...] a literal class type with [...] all base |
270 | | // classes [...] public |
271 | 39.9k | data().StructuralIfLiteral = false; |
272 | 39.9k | } |
273 | | |
274 | | // C++ [class.virtual]p1: |
275 | | // A class that declares or inherits a virtual function is called a |
276 | | // polymorphic class. |
277 | 544k | if (BaseClassDecl->isPolymorphic()) { |
278 | 23.7k | data().Polymorphic = true; |
279 | | |
280 | | // An aggregate is a class with [...] no virtual functions. |
281 | 23.7k | data().Aggregate = false; |
282 | 23.7k | } |
283 | | |
284 | | // C++0x [class]p7: |
285 | | // A standard-layout class is a class that: [...] |
286 | | // -- has no non-standard-layout base classes |
287 | 544k | if (!BaseClassDecl->isStandardLayout()) |
288 | 27.1k | data().IsStandardLayout = false; |
289 | 544k | if (!BaseClassDecl->isCXX11StandardLayout()) |
290 | 27.1k | data().IsCXX11StandardLayout = false; |
291 | | |
292 | | // Record if this base is the first non-literal field or base. |
293 | 544k | if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C)523k ) |
294 | 26.6k | data().HasNonLiteralTypeFieldsOrBases = true; |
295 | | |
296 | | // Now go through all virtual bases of this base and add them. |
297 | 544k | for (const auto &VBase : BaseClassDecl->vbases()) { |
298 | | // Add this base if it's not already in the list. |
299 | 2.99k | if (SeenVBaseTypes.insert(C.getCanonicalType(VBase.getType())).second) { |
300 | 2.53k | VBases.push_back(&VBase); |
301 | | |
302 | | // C++11 [class.copy]p8: |
303 | | // The implicitly-declared copy constructor for a class X will have |
304 | | // the form 'X::X(const X&)' if each [...] virtual base class B of X |
305 | | // has a copy constructor whose first parameter is of type |
306 | | // 'const B&' or 'const volatile B&' [...] |
307 | 2.53k | if (CXXRecordDecl *VBaseDecl = VBase.getType()->getAsCXXRecordDecl()) |
308 | 2.53k | if (!VBaseDecl->hasCopyConstructorWithConstParam()) |
309 | 1 | data().ImplicitCopyConstructorCanHaveConstParamForVBase = false; |
310 | | |
311 | | // C++1z [dcl.init.agg]p1: |
312 | | // An aggregate is a class with [...] no virtual base classes |
313 | 2.53k | data().Aggregate = false; |
314 | 2.53k | } |
315 | 2.99k | } |
316 | | |
317 | 544k | if (Base->isVirtual()) { |
318 | | // Add this base if it's not already in the list. |
319 | 2.71k | if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)).second) |
320 | 2.64k | VBases.push_back(Base); |
321 | | |
322 | | // C++14 [meta.unary.prop] is_empty: |
323 | | // T is a class type, but not a union type, with ... no virtual base |
324 | | // classes |
325 | 2.71k | data().Empty = false; |
326 | | |
327 | | // C++1z [dcl.init.agg]p1: |
328 | | // An aggregate is a class with [...] no virtual base classes |
329 | 2.71k | data().Aggregate = false; |
330 | | |
331 | | // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25: |
332 | | // A [default constructor, copy/move constructor, or copy/move assignment |
333 | | // operator for a class X] is trivial [...] if: |
334 | | // -- class X has [...] no virtual base classes |
335 | 2.71k | data().HasTrivialSpecialMembers &= SMF_Destructor; |
336 | 2.71k | data().HasTrivialSpecialMembersForCall &= SMF_Destructor; |
337 | | |
338 | | // C++0x [class]p7: |
339 | | // A standard-layout class is a class that: [...] |
340 | | // -- has [...] no virtual base classes |
341 | 2.71k | data().IsStandardLayout = false; |
342 | 2.71k | data().IsCXX11StandardLayout = false; |
343 | | |
344 | | // C++20 [dcl.constexpr]p3: |
345 | | // In the definition of a constexpr function [...] |
346 | | // -- if the function is a constructor or destructor, |
347 | | // its class shall not have any virtual base classes |
348 | 2.71k | data().DefaultedDefaultConstructorIsConstexpr = false; |
349 | 2.71k | data().DefaultedDestructorIsConstexpr = false; |
350 | | |
351 | | // C++1z [class.copy]p8: |
352 | | // The implicitly-declared copy constructor for a class X will have |
353 | | // the form 'X::X(const X&)' if each potentially constructed subobject |
354 | | // has a copy constructor whose first parameter is of type |
355 | | // 'const B&' or 'const volatile B&' [...] |
356 | 2.71k | if (!BaseClassDecl->hasCopyConstructorWithConstParam()) |
357 | 20 | data().ImplicitCopyConstructorCanHaveConstParamForVBase = false; |
358 | 541k | } else { |
359 | | // C++ [class.ctor]p5: |
360 | | // A default constructor is trivial [...] if: |
361 | | // -- all the direct base classes of its class have trivial default |
362 | | // constructors. |
363 | 541k | if (!BaseClassDecl->hasTrivialDefaultConstructor()) |
364 | 59.5k | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; |
365 | | |
366 | | // C++0x [class.copy]p13: |
367 | | // A copy/move constructor for class X is trivial if [...] |
368 | | // [...] |
369 | | // -- the constructor selected to copy/move each direct base class |
370 | | // subobject is trivial, and |
371 | 541k | if (!BaseClassDecl->hasTrivialCopyConstructor()) |
372 | 26.2k | data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; |
373 | | |
374 | 541k | if (!BaseClassDecl->hasTrivialCopyConstructorForCall()) |
375 | 26.2k | data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor; |
376 | | |
377 | | // If the base class doesn't have a simple move constructor, we'll eagerly |
378 | | // declare it and perform overload resolution to determine which function |
379 | | // it actually calls. If it does have a simple move constructor, this |
380 | | // check is correct. |
381 | 541k | if (!BaseClassDecl->hasTrivialMoveConstructor()) |
382 | 28.2k | data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; |
383 | | |
384 | 541k | if (!BaseClassDecl->hasTrivialMoveConstructorForCall()) |
385 | 28.2k | data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor; |
386 | | |
387 | | // C++0x [class.copy]p27: |
388 | | // A copy/move assignment operator for class X is trivial if [...] |
389 | | // [...] |
390 | | // -- the assignment operator selected to copy/move each direct base |
391 | | // class subobject is trivial, and |
392 | 541k | if (!BaseClassDecl->hasTrivialCopyAssignment()) |
393 | 26.9k | data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; |
394 | | // If the base class doesn't have a simple move assignment, we'll eagerly |
395 | | // declare it and perform overload resolution to determine which function |
396 | | // it actually calls. If it does have a simple move assignment, this |
397 | | // check is correct. |
398 | 541k | if (!BaseClassDecl->hasTrivialMoveAssignment()) |
399 | 28.6k | data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; |
400 | | |
401 | | // C++11 [class.ctor]p6: |
402 | | // If that user-written default constructor would satisfy the |
403 | | // requirements of a constexpr constructor, the implicitly-defined |
404 | | // default constructor is constexpr. |
405 | 541k | if (!BaseClassDecl->hasConstexprDefaultConstructor()) |
406 | 51.7k | data().DefaultedDefaultConstructorIsConstexpr = false; |
407 | | |
408 | | // C++1z [class.copy]p8: |
409 | | // The implicitly-declared copy constructor for a class X will have |
410 | | // the form 'X::X(const X&)' if each potentially constructed subobject |
411 | | // has a copy constructor whose first parameter is of type |
412 | | // 'const B&' or 'const volatile B&' [...] |
413 | 541k | if (!BaseClassDecl->hasCopyConstructorWithConstParam()) |
414 | 51 | data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false; |
415 | 541k | } |
416 | | |
417 | | // C++ [class.ctor]p3: |
418 | | // A destructor is trivial if all the direct base classes of its class |
419 | | // have trivial destructors. |
420 | 544k | if (!BaseClassDecl->hasTrivialDestructor()) |
421 | 25.1k | data().HasTrivialSpecialMembers &= ~SMF_Destructor; |
422 | | |
423 | 544k | if (!BaseClassDecl->hasTrivialDestructorForCall()) |
424 | 25.1k | data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor; |
425 | | |
426 | 544k | if (!BaseClassDecl->hasIrrelevantDestructor()) |
427 | 25.2k | data().HasIrrelevantDestructor = false; |
428 | | |
429 | 544k | if (BaseClassDecl->isAnyDestructorNoReturn()) |
430 | 14 | data().IsAnyDestructorNoReturn = true; |
431 | | |
432 | | // C++11 [class.copy]p18: |
433 | | // The implicitly-declared copy assignment operator for a class X will |
434 | | // have the form 'X& X::operator=(const X&)' if each direct base class B |
435 | | // of X has a copy assignment operator whose parameter is of type 'const |
436 | | // B&', 'const volatile B&', or 'B' [...] |
437 | 544k | if (!BaseClassDecl->hasCopyAssignmentWithConstParam()) |
438 | 236 | data().ImplicitCopyAssignmentHasConstParam = false; |
439 | | |
440 | | // A class has an Objective-C object member if... or any of its bases |
441 | | // has an Objective-C object member. |
442 | 544k | if (BaseClassDecl->hasObjectMember()) |
443 | 8 | setHasObjectMember(true); |
444 | | |
445 | 544k | if (BaseClassDecl->hasVolatileMember()) |
446 | 3 | setHasVolatileMember(true); |
447 | | |
448 | 544k | if (BaseClassDecl->getArgPassingRestrictions() == |
449 | 544k | RecordDecl::APK_CanNeverPassInRegs) |
450 | 5 | setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs); |
451 | | |
452 | | // Keep track of the presence of mutable fields. |
453 | 544k | if (BaseClassDecl->hasMutableFields()) |
454 | 1.35k | data().HasMutableFields = true; |
455 | | |
456 | 544k | if (BaseClassDecl->hasUninitializedReferenceMember()) |
457 | 36 | data().HasUninitializedReferenceMember = true; |
458 | | |
459 | 544k | if (!BaseClassDecl->allowConstDefaultInit()) |
460 | 4.67k | data().HasUninitializedFields = true; |
461 | | |
462 | 544k | addedClassSubobject(BaseClassDecl); |
463 | 544k | } |
464 | | |
465 | | // C++2a [class]p7: |
466 | | // A class S is a standard-layout class if it: |
467 | | // -- has at most one base class subobject of any given type |
468 | | // |
469 | | // Note that we only need to check this for classes with more than one base |
470 | | // class. If there's only one base class, and it's standard layout, then |
471 | | // we know there are no repeated base classes. |
472 | 674k | if (data().IsStandardLayout && NumBases > 1640k && hasRepeatedBaseClass(this)7.63k ) |
473 | 82 | data().IsStandardLayout = false; |
474 | | |
475 | 674k | if (VBases.empty()) { |
476 | 671k | data().IsParsingBaseSpecifiers = false; |
477 | 671k | return; |
478 | 671k | } |
479 | | |
480 | | // Create base specifier for any direct or indirect virtual bases. |
481 | 3.15k | data().VBases = new (C) CXXBaseSpecifier[VBases.size()]; |
482 | 3.15k | data().NumVBases = VBases.size(); |
483 | 8.32k | for (int I = 0, E = VBases.size(); I != E; ++I5.17k ) { |
484 | 5.17k | QualType Type = VBases[I]->getType(); |
485 | 5.17k | if (!Type->isDependentType()) |
486 | 5.17k | addedClassSubobject(Type->getAsCXXRecordDecl()); |
487 | 5.17k | data().getVBases()[I] = *VBases[I]; |
488 | 5.17k | } |
489 | | |
490 | 3.15k | data().IsParsingBaseSpecifiers = false; |
491 | 3.15k | } |
492 | | |
493 | 122k | unsigned CXXRecordDecl::getODRHash() const { |
494 | 122k | assert(hasDefinition() && "ODRHash only for records with definitions"); |
495 | | |
496 | | // Previously calculated hash is stored in DefinitionData. |
497 | 122k | if (DefinitionData->HasODRHash) |
498 | 974 | return DefinitionData->ODRHash; |
499 | | |
500 | | // Only calculate hash on first call of getODRHash per record. |
501 | 122k | ODRHash Hash; |
502 | 122k | Hash.AddCXXRecordDecl(getDefinition()); |
503 | 122k | DefinitionData->HasODRHash = true; |
504 | 122k | DefinitionData->ODRHash = Hash.CalculateHash(); |
505 | | |
506 | 122k | return DefinitionData->ODRHash; |
507 | 122k | } |
508 | | |
509 | 898k | void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) { |
510 | | // C++11 [class.copy]p11: |
511 | | // A defaulted copy/move constructor for a class X is defined as |
512 | | // deleted if X has: |
513 | | // -- a direct or virtual base class B that cannot be copied/moved [...] |
514 | | // -- a non-static data member of class type M (or array thereof) |
515 | | // that cannot be copied or moved [...] |
516 | 898k | if (!Subobj->hasSimpleCopyConstructor()) |
517 | 38.1k | data().NeedOverloadResolutionForCopyConstructor = true; |
518 | 898k | if (!Subobj->hasSimpleMoveConstructor()) |
519 | 43.9k | data().NeedOverloadResolutionForMoveConstructor = true; |
520 | | |
521 | | // C++11 [class.copy]p23: |
522 | | // A defaulted copy/move assignment operator for a class X is defined as |
523 | | // deleted if X has: |
524 | | // -- a direct or virtual base class B that cannot be copied/moved [...] |
525 | | // -- a non-static data member of class type M (or array thereof) |
526 | | // that cannot be copied or moved [...] |
527 | 898k | if (!Subobj->hasSimpleCopyAssignment()) |
528 | 34.5k | data().NeedOverloadResolutionForCopyAssignment = true; |
529 | 898k | if (!Subobj->hasSimpleMoveAssignment()) |
530 | 45.4k | data().NeedOverloadResolutionForMoveAssignment = true; |
531 | | |
532 | | // C++11 [class.ctor]p5, C++11 [class.copy]p11, C++11 [class.dtor]p5: |
533 | | // A defaulted [ctor or dtor] for a class X is defined as |
534 | | // deleted if X has: |
535 | | // -- any direct or virtual base class [...] has a type with a destructor |
536 | | // that is deleted or inaccessible from the defaulted [ctor or dtor]. |
537 | | // -- any non-static data member has a type with a destructor |
538 | | // that is deleted or inaccessible from the defaulted [ctor or dtor]. |
539 | 898k | if (!Subobj->hasSimpleDestructor()) { |
540 | 39.2k | data().NeedOverloadResolutionForCopyConstructor = true; |
541 | 39.2k | data().NeedOverloadResolutionForMoveConstructor = true; |
542 | 39.2k | data().NeedOverloadResolutionForDestructor = true; |
543 | 39.2k | } |
544 | | |
545 | | // C++2a [dcl.constexpr]p4: |
546 | | // The definition of a constexpr destructor [shall] satisfy the |
547 | | // following requirement: |
548 | | // -- for every subobject of class type or (possibly multi-dimensional) |
549 | | // array thereof, that class type shall have a constexpr destructor |
550 | 898k | if (!Subobj->hasConstexprDestructor()) |
551 | 883k | data().DefaultedDestructorIsConstexpr = false; |
552 | | |
553 | | // C++20 [temp.param]p7: |
554 | | // A structural type is [...] a literal class type [for which] the types |
555 | | // of all base classes and non-static data members are structural types or |
556 | | // (possibly multi-dimensional) array thereof |
557 | 898k | if (!Subobj->data().StructuralIfLiteral) |
558 | 79.4k | data().StructuralIfLiteral = false; |
559 | 898k | } |
560 | | |
561 | 934k | bool CXXRecordDecl::hasConstexprDestructor() const { |
562 | 934k | auto *Dtor = getDestructor(); |
563 | 934k | return Dtor ? Dtor->isConstexpr()343k : defaultedDestructorIsConstexpr()591k ; |
564 | 934k | } |
565 | | |
566 | 1.20k | bool CXXRecordDecl::hasAnyDependentBases() const { |
567 | 1.20k | if (!isDependentContext()) |
568 | 546 | return false; |
569 | | |
570 | 662 | return !forallBases([](const CXXRecordDecl *) { return true; }479 ); |
571 | 1.20k | } |
572 | | |
573 | 256k | bool CXXRecordDecl::isTriviallyCopyable() const { |
574 | | // C++0x [class]p5: |
575 | | // A trivially copyable class is a class that: |
576 | | // -- has no non-trivial copy constructors, |
577 | 256k | if (hasNonTrivialCopyConstructor()) return false64.5k ; |
578 | | // -- has no non-trivial move constructors, |
579 | 191k | if (hasNonTrivialMoveConstructor()) return false7.27k ; |
580 | | // -- has no non-trivial copy assignment operators, |
581 | 184k | if (hasNonTrivialCopyAssignment()) return false5.16k ; |
582 | | // -- has no non-trivial move assignment operators, and |
583 | 179k | if (hasNonTrivialMoveAssignment()) return false277 ; |
584 | | // -- has a trivial destructor. |
585 | 178k | if (!hasTrivialDestructor()) return false9.06k ; |
586 | | |
587 | 169k | return true; |
588 | 178k | } |
589 | | |
590 | 6.04k | void CXXRecordDecl::markedVirtualFunctionPure() { |
591 | | // C++ [class.abstract]p2: |
592 | | // A class is abstract if it has at least one pure virtual function. |
593 | 6.04k | data().Abstract = true; |
594 | 6.04k | } |
595 | | |
596 | | bool CXXRecordDecl::hasSubobjectAtOffsetZeroOfEmptyBaseType( |
597 | 93.1k | ASTContext &Ctx, const CXXRecordDecl *XFirst) { |
598 | 93.1k | if (!getNumBases()) |
599 | 92.9k | return false; |
600 | | |
601 | 269 | llvm::SmallPtrSet<const CXXRecordDecl*, 8> Bases; |
602 | 269 | llvm::SmallPtrSet<const CXXRecordDecl*, 8> M; |
603 | 269 | SmallVector<const CXXRecordDecl*, 8> WorkList; |
604 | | |
605 | | // Visit a type that we have determined is an element of M(S). |
606 | 351 | auto Visit = [&](const CXXRecordDecl *RD) -> bool { |
607 | 351 | RD = RD->getCanonicalDecl(); |
608 | | |
609 | | // C++2a [class]p8: |
610 | | // A class S is a standard-layout class if it [...] has no element of the |
611 | | // set M(S) of types as a base class. |
612 | | // |
613 | | // If we find a subobject of an empty type, it might also be a base class, |
614 | | // so we'll need to walk the base classes to check. |
615 | 351 | if (!RD->data().HasBasesWithFields) { |
616 | | // Walk the bases the first time, stopping if we find the type. Build a |
617 | | // set of them so we don't need to walk them again. |
618 | 342 | if (Bases.empty()) { |
619 | 373 | bool RDIsBase = !forallBases([&](const CXXRecordDecl *Base) -> bool { |
620 | 373 | Base = Base->getCanonicalDecl(); |
621 | 373 | if (RD == Base) |
622 | 95 | return false; |
623 | 278 | Bases.insert(Base); |
624 | 278 | return true; |
625 | 373 | }); |
626 | 260 | if (RDIsBase) |
627 | 96 | return true; |
628 | 260 | } else { |
629 | 82 | if (Bases.count(RD)) |
630 | 34 | return true; |
631 | 82 | } |
632 | 342 | } |
633 | | |
634 | 221 | if (M.insert(RD).second) |
635 | 221 | WorkList.push_back(RD); |
636 | 221 | return false; |
637 | 351 | }; |
638 | | |
639 | 269 | if (Visit(XFirst)) |
640 | 96 | return true; |
641 | | |
642 | 360 | while (173 !WorkList.empty()) { |
643 | 221 | const CXXRecordDecl *X = WorkList.pop_back_val(); |
644 | | |
645 | | // FIXME: We don't check the bases of X. That matches the standard, but |
646 | | // that sure looks like a wording bug. |
647 | | |
648 | | // -- If X is a non-union class type with a non-static data member |
649 | | // [recurse to each field] that is either of zero size or is the |
650 | | // first non-static data member of X |
651 | | // -- If X is a union type, [recurse to union members] |
652 | 221 | bool IsFirstField = true; |
653 | 247 | for (auto *FD : X->fields()) { |
654 | | // FIXME: Should we really care about the type of the first non-static |
655 | | // data member of a non-union if there are preceding unnamed bit-fields? |
656 | 247 | if (FD->isUnnamedBitfield()) |
657 | 0 | continue; |
658 | | |
659 | 247 | if (!IsFirstField && !FD->isZeroSize(Ctx)62 ) |
660 | 62 | continue; |
661 | | |
662 | | // -- If X is n array type, [visit the element type] |
663 | 185 | QualType T = Ctx.getBaseElementType(FD->getType()); |
664 | 185 | if (auto *RD = T->getAsCXXRecordDecl()) |
665 | 82 | if (Visit(RD)) |
666 | 34 | return true; |
667 | | |
668 | 151 | if (!X->isUnion()) |
669 | 116 | IsFirstField = false; |
670 | 151 | } |
671 | 221 | } |
672 | | |
673 | 139 | return false; |
674 | 173 | } |
675 | | |
676 | 59.2k | bool CXXRecordDecl::lambdaIsDefaultConstructibleAndAssignable() const { |
677 | 59.2k | assert(isLambda() && "not a lambda"); |
678 | | |
679 | | // C++2a [expr.prim.lambda.capture]p11: |
680 | | // The closure type associated with a lambda-expression has no default |
681 | | // constructor if the lambda-expression has a lambda-capture and a |
682 | | // defaulted default constructor otherwise. It has a deleted copy |
683 | | // assignment operator if the lambda-expression has a lambda-capture and |
684 | | // defaulted copy and move assignment operators otherwise. |
685 | | // |
686 | | // C++17 [expr.prim.lambda]p21: |
687 | | // The closure type associated with a lambda-expression has no default |
688 | | // constructor and a deleted copy assignment operator. |
689 | 59.2k | if (getLambdaCaptureDefault() != LCD_None || capture_size() != 041.5k ) |
690 | 25.9k | return false; |
691 | 33.3k | return getASTContext().getLangOpts().CPlusPlus20; |
692 | 59.2k | } |
693 | | |
694 | 10.5M | void CXXRecordDecl::addedMember(Decl *D) { |
695 | 10.5M | if (!D->isImplicit() && |
696 | 10.5M | !isa<FieldDecl>(D)7.81M && |
697 | 10.5M | !isa<IndirectFieldDecl>(D)6.02M && |
698 | 10.5M | (6.02M !isa<TagDecl>(D)6.02M || cast<TagDecl>(D)->getTagKind() == TTK_Class89.6k || |
699 | 6.02M | cast<TagDecl>(D)->getTagKind() == TTK_Interface81.9k )) |
700 | 5.94M | data().HasOnlyCMembers = false; |
701 | | |
702 | | // Ignore friends and invalid declarations. |
703 | 10.5M | if (D->getFriendObjectKind() || D->isInvalidDecl()10.5M ) |
704 | 11.7k | return; |
705 | | |
706 | 10.5M | auto *FunTmpl = dyn_cast<FunctionTemplateDecl>(D); |
707 | 10.5M | if (FunTmpl) |
708 | 548k | D = FunTmpl->getTemplatedDecl(); |
709 | | |
710 | | // FIXME: Pass NamedDecl* to addedMember? |
711 | 10.5M | Decl *DUnderlying = D; |
712 | 10.5M | if (auto *ND = dyn_cast<NamedDecl>(DUnderlying)) { |
713 | 9.78M | DUnderlying = ND->getUnderlyingDecl(); |
714 | 9.78M | if (auto *UnderlyingFunTmpl = dyn_cast<FunctionTemplateDecl>(DUnderlying)) |
715 | 231 | DUnderlying = UnderlyingFunTmpl->getTemplatedDecl(); |
716 | 9.78M | } |
717 | | |
718 | 10.5M | if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
719 | 3.71M | if (Method->isVirtual()) { |
720 | | // C++ [dcl.init.aggr]p1: |
721 | | // An aggregate is an array or a class with [...] no virtual functions. |
722 | 95.3k | data().Aggregate = false; |
723 | | |
724 | | // C++ [class]p4: |
725 | | // A POD-struct is an aggregate class... |
726 | 95.3k | data().PlainOldData = false; |
727 | | |
728 | | // C++14 [meta.unary.prop]p4: |
729 | | // T is a class type [...] with [...] no virtual member functions... |
730 | 95.3k | data().Empty = false; |
731 | | |
732 | | // C++ [class.virtual]p1: |
733 | | // A class that declares or inherits a virtual function is called a |
734 | | // polymorphic class. |
735 | 95.3k | data().Polymorphic = true; |
736 | | |
737 | | // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25: |
738 | | // A [default constructor, copy/move constructor, or copy/move |
739 | | // assignment operator for a class X] is trivial [...] if: |
740 | | // -- class X has no virtual functions [...] |
741 | 95.3k | data().HasTrivialSpecialMembers &= SMF_Destructor; |
742 | 95.3k | data().HasTrivialSpecialMembersForCall &= SMF_Destructor; |
743 | | |
744 | | // C++0x [class]p7: |
745 | | // A standard-layout class is a class that: [...] |
746 | | // -- has no virtual functions |
747 | 95.3k | data().IsStandardLayout = false; |
748 | 95.3k | data().IsCXX11StandardLayout = false; |
749 | 95.3k | } |
750 | 3.71M | } |
751 | | |
752 | | // Notify the listener if an implicit member was added after the definition |
753 | | // was completed. |
754 | 10.5M | if (!isBeingDefined() && D->isImplicit()2.00M ) |
755 | 523k | if (ASTMutationListener *L = getASTMutationListener()) |
756 | 19.3k | L->AddedCXXImplicitMember(data().Definition, D); |
757 | | |
758 | | // The kind of special member this declaration is, if any. |
759 | 10.5M | unsigned SMKind = 0; |
760 | | |
761 | | // Handle constructors. |
762 | 10.5M | if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
763 | 1.01M | if (Constructor->isInheritingConstructor()) { |
764 | | // Ignore constructor shadow declarations. They are lazily created and |
765 | | // so shouldn't affect any properties of the class. |
766 | 1.01M | } else { |
767 | 1.01M | if (!Constructor->isImplicit()) { |
768 | | // Note that we have a user-declared constructor. |
769 | 701k | data().UserDeclaredConstructor = true; |
770 | | |
771 | | // C++ [class]p4: |
772 | | // A POD-struct is an aggregate class [...] |
773 | | // Since the POD bit is meant to be C++03 POD-ness, clear it even if |
774 | | // the type is technically an aggregate in C++0x since it wouldn't be |
775 | | // in 03. |
776 | 701k | data().PlainOldData = false; |
777 | 701k | } |
778 | | |
779 | 1.01M | if (Constructor->isDefaultConstructor()) { |
780 | 219k | SMKind |= SMF_DefaultConstructor; |
781 | | |
782 | 219k | if (Constructor->isUserProvided()) |
783 | 126k | data().UserProvidedDefaultConstructor = true; |
784 | 219k | if (Constructor->isConstexpr()) |
785 | 79.7k | data().HasConstexprDefaultConstructor = true; |
786 | 219k | if (Constructor->isDefaulted()) |
787 | 90.8k | data().HasDefaultedDefaultConstructor = true; |
788 | 219k | } |
789 | | |
790 | 1.01M | if (!FunTmpl) { |
791 | 775k | unsigned Quals; |
792 | 775k | if (Constructor->isCopyConstructor(Quals)) { |
793 | 191k | SMKind |= SMF_CopyConstructor; |
794 | | |
795 | 191k | if (Quals & Qualifiers::Const) |
796 | 189k | data().HasDeclaredCopyConstructorWithConstParam = true; |
797 | 584k | } else if (Constructor->isMoveConstructor()) |
798 | 140k | SMKind |= SMF_MoveConstructor; |
799 | 775k | } |
800 | | |
801 | | // C++11 [dcl.init.aggr]p1: DR1518 |
802 | | // An aggregate is an array or a class with no user-provided [or] |
803 | | // explicit [...] constructors |
804 | | // C++20 [dcl.init.aggr]p1: |
805 | | // An aggregate is an array or a class with no user-declared [...] |
806 | | // constructors |
807 | 1.01M | if (getASTContext().getLangOpts().CPlusPlus20 |
808 | 1.01M | ? !Constructor->isImplicit()24.4k |
809 | 1.01M | : (985k Constructor->isUserProvided()985k || Constructor->isExplicit()361k )) |
810 | 642k | data().Aggregate = false; |
811 | 1.01M | } |
812 | 1.01M | } |
813 | | |
814 | | // Handle constructors, including those inherited from base classes. |
815 | 10.5M | if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(DUnderlying)) { |
816 | | // Record if we see any constexpr constructors which are neither copy |
817 | | // nor move constructors. |
818 | | // C++1z [basic.types]p10: |
819 | | // [...] has at least one constexpr constructor or constructor template |
820 | | // (possibly inherited from a base class) that is not a copy or move |
821 | | // constructor [...] |
822 | 1.01M | if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor()389k ) |
823 | 159k | data().HasConstexprNonCopyMoveConstructor = true; |
824 | 1.01M | if (!isa<CXXConstructorDecl>(D) && Constructor->isDefaultConstructor()2.60k ) |
825 | 254 | data().HasInheritedDefaultConstructor = true; |
826 | 1.01M | } |
827 | | |
828 | | // Handle member functions. |
829 | 10.5M | if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
830 | 3.71M | if (isa<CXXDestructorDecl>(D)) |
831 | 176k | SMKind |= SMF_Destructor; |
832 | | |
833 | 3.71M | if (Method->isCopyAssignmentOperator()) { |
834 | 106k | SMKind |= SMF_CopyAssignment; |
835 | | |
836 | 106k | const auto *ParamTy = |
837 | 106k | Method->getParamDecl(0)->getType()->getAs<ReferenceType>(); |
838 | 106k | if (!ParamTy || ParamTy->getPointeeType().isConstQualified()106k ) |
839 | 105k | data().HasDeclaredCopyAssignmentWithConstParam = true; |
840 | 106k | } |
841 | | |
842 | 3.71M | if (Method->isMoveAssignmentOperator()) |
843 | 60.6k | SMKind |= SMF_MoveAssignment; |
844 | | |
845 | | // Keep the list of conversion functions up-to-date. |
846 | 3.71M | if (auto *Conversion = dyn_cast<CXXConversionDecl>(D)) { |
847 | | // FIXME: We use the 'unsafe' accessor for the access specifier here, |
848 | | // because Sema may not have set it yet. That's really just a misdesign |
849 | | // in Sema. However, LLDB *will* have set the access specifier correctly, |
850 | | // and adds declarations after the class is technically completed, |
851 | | // so completeDefinition()'s overriding of the access specifiers doesn't |
852 | | // work. |
853 | 37.5k | AccessSpecifier AS = Conversion->getAccessUnsafe(); |
854 | | |
855 | 37.5k | if (Conversion->getPrimaryTemplate()) { |
856 | | // We don't record specializations. |
857 | 37.5k | } else { |
858 | 37.5k | ASTContext &Ctx = getASTContext(); |
859 | 37.5k | ASTUnresolvedSet &Conversions = data().Conversions.get(Ctx); |
860 | 37.5k | NamedDecl *Primary = |
861 | 37.5k | FunTmpl ? cast<NamedDecl>(FunTmpl)5.25k : cast<NamedDecl>(Conversion)32.2k ; |
862 | 37.5k | if (Primary->getPreviousDecl()) |
863 | 0 | Conversions.replace(cast<NamedDecl>(Primary->getPreviousDecl()), |
864 | 0 | Primary, AS); |
865 | 37.5k | else |
866 | 37.5k | Conversions.addDecl(Ctx, Primary, AS); |
867 | 37.5k | } |
868 | 37.5k | } |
869 | | |
870 | 3.71M | if (SMKind) { |
871 | | // If this is the first declaration of a special member, we no longer have |
872 | | // an implicit trivial special member. |
873 | 896k | data().HasTrivialSpecialMembers &= |
874 | 896k | data().DeclaredSpecialMembers | ~SMKind; |
875 | 896k | data().HasTrivialSpecialMembersForCall &= |
876 | 896k | data().DeclaredSpecialMembers | ~SMKind; |
877 | | |
878 | | // Note when we have declared a declared special member, and suppress the |
879 | | // implicit declaration of this special member. |
880 | 896k | data().DeclaredSpecialMembers |= SMKind; |
881 | 896k | if (!Method->isImplicit()) { |
882 | 382k | data().UserDeclaredSpecialMembers |= SMKind; |
883 | | |
884 | | // C++03 [class]p4: |
885 | | // A POD-struct is an aggregate class that has [...] no user-defined |
886 | | // copy assignment operator and no user-defined destructor. |
887 | | // |
888 | | // Since the POD bit is meant to be C++03 POD-ness, and in C++03, |
889 | | // aggregates could not have any constructors, clear it even for an |
890 | | // explicitly defaulted or deleted constructor. |
891 | | // type is technically an aggregate in C++0x since it wouldn't be in 03. |
892 | | // |
893 | | // Also, a user-declared move assignment operator makes a class non-POD. |
894 | | // This is an extension in C++03. |
895 | 382k | data().PlainOldData = false; |
896 | 382k | } |
897 | | // We delay updating destructor relevant properties until |
898 | | // addedSelectedDestructor. |
899 | | // FIXME: Defer this for the other special member functions as well. |
900 | 896k | if (!Method->isIneligibleOrNotSelected()) { |
901 | 839k | addedEligibleSpecialMemberFunction(Method, SMKind); |
902 | 839k | } |
903 | 896k | } |
904 | | |
905 | 3.71M | return; |
906 | 3.71M | } |
907 | | |
908 | | // Handle non-static data members. |
909 | 6.79M | if (const auto *Field = dyn_cast<FieldDecl>(D)) { |
910 | 2.19M | ASTContext &Context = getASTContext(); |
911 | | |
912 | | // C++2a [class]p7: |
913 | | // A standard-layout class is a class that: |
914 | | // [...] |
915 | | // -- has all non-static data members and bit-fields in the class and |
916 | | // its base classes first declared in the same class |
917 | 2.19M | if (data().HasBasesWithFields) |
918 | 14.9k | data().IsStandardLayout = false; |
919 | | |
920 | | // C++ [class.bit]p2: |
921 | | // A declaration for a bit-field that omits the identifier declares an |
922 | | // unnamed bit-field. Unnamed bit-fields are not members and cannot be |
923 | | // initialized. |
924 | 2.19M | if (Field->isUnnamedBitfield()) { |
925 | | // C++ [meta.unary.prop]p4: [LWG2358] |
926 | | // T is a class type [...] with [...] no unnamed bit-fields of non-zero |
927 | | // length |
928 | 2.67k | if (data().Empty && !Field->isZeroLengthBitField(Context)157 && |
929 | 2.67k | Context.getLangOpts().getClangABICompat() > |
930 | 87 | LangOptions::ClangABI::Ver6) |
931 | 86 | data().Empty = false; |
932 | 2.67k | return; |
933 | 2.67k | } |
934 | | |
935 | | // C++11 [class]p7: |
936 | | // A standard-layout class is a class that: |
937 | | // -- either has no non-static data members in the most derived class |
938 | | // [...] or has no base classes with non-static data members |
939 | 2.19M | if (data().HasBasesWithNonStaticDataMembers) |
940 | 14.9k | data().IsCXX11StandardLayout = false; |
941 | | |
942 | | // C++ [dcl.init.aggr]p1: |
943 | | // An aggregate is an array or a class (clause 9) with [...] no |
944 | | // private or protected non-static data members (clause 11). |
945 | | // |
946 | | // A POD must be an aggregate. |
947 | 2.19M | if (D->getAccess() == AS_private || D->getAccess() == AS_protected1.59M ) { |
948 | 612k | data().Aggregate = false; |
949 | 612k | data().PlainOldData = false; |
950 | | |
951 | | // C++20 [temp.param]p7: |
952 | | // A structural type is [...] a literal class type [for which] all |
953 | | // non-static data members are public |
954 | 612k | data().StructuralIfLiteral = false; |
955 | 612k | } |
956 | | |
957 | | // Track whether this is the first field. We use this when checking |
958 | | // whether the class is standard-layout below. |
959 | 2.19M | bool IsFirstField = !data().HasPrivateFields && |
960 | 2.19M | !data().HasProtectedFields1.91M && !data().HasPublicFields1.90M ; |
961 | | |
962 | | // C++0x [class]p7: |
963 | | // A standard-layout class is a class that: |
964 | | // [...] |
965 | | // -- has the same access control for all non-static data members, |
966 | 2.19M | switch (D->getAccess()) { |
967 | 591k | case AS_private: data().HasPrivateFields = true; break; |
968 | 21.2k | case AS_protected: data().HasProtectedFields = true; break; |
969 | 1.57M | case AS_public: data().HasPublicFields = true; break; |
970 | 0 | case AS_none: llvm_unreachable("Invalid access specifier"); |
971 | 2.19M | }; |
972 | 2.19M | if ((data().HasPrivateFields + data().HasProtectedFields + |
973 | 2.19M | data().HasPublicFields) > 1) { |
974 | 6.97k | data().IsStandardLayout = false; |
975 | 6.97k | data().IsCXX11StandardLayout = false; |
976 | 6.97k | } |
977 | | |
978 | | // Keep track of the presence of mutable fields. |
979 | 2.19M | if (Field->isMutable()) { |
980 | 4.41k | data().HasMutableFields = true; |
981 | | |
982 | | // C++20 [temp.param]p7: |
983 | | // A structural type is [...] a literal class type [for which] all |
984 | | // non-static data members are public |
985 | 4.41k | data().StructuralIfLiteral = false; |
986 | 4.41k | } |
987 | | |
988 | | // C++11 [class.union]p8, DR1460: |
989 | | // If X is a union, a non-static data member of X that is not an anonymous |
990 | | // union is a variant member of X. |
991 | 2.19M | if (isUnion() && !Field->isAnonymousStructOrUnion()65.5k ) |
992 | 65.3k | data().HasVariantMembers = true; |
993 | | |
994 | | // C++0x [class]p9: |
995 | | // A POD struct is a class that is both a trivial class and a |
996 | | // standard-layout class, and has no non-static data members of type |
997 | | // non-POD struct, non-POD union (or array of such types). |
998 | | // |
999 | | // Automatic Reference Counting: the presence of a member of Objective-C pointer type |
1000 | | // that does not explicitly have no lifetime makes the class a non-POD. |
1001 | 2.19M | QualType T = Context.getBaseElementType(Field->getType()); |
1002 | 2.19M | if (T->isObjCRetainableType() || T.isObjCGCStrong()2.18M ) { |
1003 | 3.26k | if (T.hasNonTrivialObjCLifetime()) { |
1004 | | // Objective-C Automatic Reference Counting: |
1005 | | // If a class has a non-static data member of Objective-C pointer |
1006 | | // type (or array thereof), it is a non-POD type and its |
1007 | | // default constructor (if any), copy constructor, move constructor, |
1008 | | // copy assignment operator, move assignment operator, and destructor are |
1009 | | // non-trivial. |
1010 | 129 | setHasObjectMember(true); |
1011 | 129 | struct DefinitionData &Data = data(); |
1012 | 129 | Data.PlainOldData = false; |
1013 | 129 | Data.HasTrivialSpecialMembers = 0; |
1014 | | |
1015 | | // __strong or __weak fields do not make special functions non-trivial |
1016 | | // for the purpose of calls. |
1017 | 129 | Qualifiers::ObjCLifetime LT = T.getQualifiers().getObjCLifetime(); |
1018 | 129 | if (LT != Qualifiers::OCL_Strong && LT != Qualifiers::OCL_Weak29 ) |
1019 | 0 | data().HasTrivialSpecialMembersForCall = 0; |
1020 | | |
1021 | | // Structs with __weak fields should never be passed directly. |
1022 | 129 | if (LT == Qualifiers::OCL_Weak) |
1023 | 29 | setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs); |
1024 | | |
1025 | 129 | Data.HasIrrelevantDestructor = false; |
1026 | | |
1027 | 129 | if (isUnion()) { |
1028 | 11 | data().DefaultedCopyConstructorIsDeleted = true; |
1029 | 11 | data().DefaultedMoveConstructorIsDeleted = true; |
1030 | 11 | data().DefaultedCopyAssignmentIsDeleted = true; |
1031 | 11 | data().DefaultedMoveAssignmentIsDeleted = true; |
1032 | 11 | data().DefaultedDestructorIsDeleted = true; |
1033 | 11 | data().NeedOverloadResolutionForCopyConstructor = true; |
1034 | 11 | data().NeedOverloadResolutionForMoveConstructor = true; |
1035 | 11 | data().NeedOverloadResolutionForCopyAssignment = true; |
1036 | 11 | data().NeedOverloadResolutionForMoveAssignment = true; |
1037 | 11 | data().NeedOverloadResolutionForDestructor = true; |
1038 | 11 | } |
1039 | 3.13k | } else if (!Context.getLangOpts().ObjCAutoRefCount) { |
1040 | 3.13k | setHasObjectMember(true); |
1041 | 3.13k | } |
1042 | 2.18M | } else if (!T.isCXX98PODType(Context)) |
1043 | 343k | data().PlainOldData = false; |
1044 | | |
1045 | 2.19M | if (T->isReferenceType()) { |
1046 | 210k | if (!Field->hasInClassInitializer()) |
1047 | 209k | data().HasUninitializedReferenceMember = true; |
1048 | | |
1049 | | // C++0x [class]p7: |
1050 | | // A standard-layout class is a class that: |
1051 | | // -- has no non-static data members of type [...] reference, |
1052 | 210k | data().IsStandardLayout = false; |
1053 | 210k | data().IsCXX11StandardLayout = false; |
1054 | | |
1055 | | // C++1z [class.copy.ctor]p10: |
1056 | | // A defaulted copy constructor for a class X is defined as deleted if X has: |
1057 | | // -- a non-static data member of rvalue reference type |
1058 | 210k | if (T->isRValueReferenceType()) |
1059 | 230 | data().DefaultedCopyConstructorIsDeleted = true; |
1060 | 210k | } |
1061 | | |
1062 | 2.19M | if (!Field->hasInClassInitializer() && !Field->isMutable()2.18M ) { |
1063 | 2.17M | if (CXXRecordDecl *FieldType = T->getAsCXXRecordDecl()) { |
1064 | 348k | if (FieldType->hasDefinition() && !FieldType->allowConstDefaultInit()346k ) |
1065 | 312k | data().HasUninitializedFields = true; |
1066 | 1.82M | } else { |
1067 | 1.82M | data().HasUninitializedFields = true; |
1068 | 1.82M | } |
1069 | 2.17M | } |
1070 | | |
1071 | | // Record if this field is the first non-literal or volatile field or base. |
1072 | 2.19M | if (!T->isLiteralType(Context) || T.isVolatileQualified()2.03M ) |
1073 | 160k | data().HasNonLiteralTypeFieldsOrBases = true; |
1074 | | |
1075 | 2.19M | if (Field->hasInClassInitializer() || |
1076 | 2.19M | (2.18M Field->isAnonymousStructOrUnion()2.18M && |
1077 | 2.18M | Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer()7.53k )) { |
1078 | 8.79k | data().HasInClassInitializer = true; |
1079 | | |
1080 | | // C++11 [class]p5: |
1081 | | // A default constructor is trivial if [...] no non-static data member |
1082 | | // of its class has a brace-or-equal-initializer. |
1083 | 8.79k | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; |
1084 | | |
1085 | | // C++11 [dcl.init.aggr]p1: |
1086 | | // An aggregate is a [...] class with [...] no |
1087 | | // brace-or-equal-initializers for non-static data members. |
1088 | | // |
1089 | | // This rule was removed in C++14. |
1090 | 8.79k | if (!getASTContext().getLangOpts().CPlusPlus14) |
1091 | 6.87k | data().Aggregate = false; |
1092 | | |
1093 | | // C++11 [class]p10: |
1094 | | // A POD struct is [...] a trivial class. |
1095 | 8.79k | data().PlainOldData = false; |
1096 | 8.79k | } |
1097 | | |
1098 | | // C++11 [class.copy]p23: |
1099 | | // A defaulted copy/move assignment operator for a class X is defined |
1100 | | // as deleted if X has: |
1101 | | // -- a non-static data member of reference type |
1102 | 2.19M | if (T->isReferenceType()) { |
1103 | 210k | data().DefaultedCopyAssignmentIsDeleted = true; |
1104 | 210k | data().DefaultedMoveAssignmentIsDeleted = true; |
1105 | 210k | } |
1106 | | |
1107 | | // Bitfields of length 0 are also zero-sized, but we already bailed out for |
1108 | | // those because they are always unnamed. |
1109 | 2.19M | bool IsZeroSize = Field->isZeroSize(Context); |
1110 | | |
1111 | 2.19M | if (const auto *RecordTy = T->getAs<RecordType>()) { |
1112 | 350k | auto *FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl()); |
1113 | 350k | if (FieldRec->getDefinition()) { |
1114 | 349k | addedClassSubobject(FieldRec); |
1115 | | |
1116 | | // We may need to perform overload resolution to determine whether a |
1117 | | // field can be moved if it's const or volatile qualified. |
1118 | 349k | if (T.getCVRQualifiers() & (Qualifiers::Const | Qualifiers::Volatile)) { |
1119 | | // We need to care about 'const' for the copy constructor because an |
1120 | | // implicit copy constructor might be declared with a non-const |
1121 | | // parameter. |
1122 | 166 | data().NeedOverloadResolutionForCopyConstructor = true; |
1123 | 166 | data().NeedOverloadResolutionForMoveConstructor = true; |
1124 | 166 | data().NeedOverloadResolutionForCopyAssignment = true; |
1125 | 166 | data().NeedOverloadResolutionForMoveAssignment = true; |
1126 | 166 | } |
1127 | | |
1128 | | // C++11 [class.ctor]p5, C++11 [class.copy]p11: |
1129 | | // A defaulted [special member] for a class X is defined as |
1130 | | // deleted if: |
1131 | | // -- X is a union-like class that has a variant member with a |
1132 | | // non-trivial [corresponding special member] |
1133 | 349k | if (isUnion()) { |
1134 | 39.7k | if (FieldRec->hasNonTrivialCopyConstructor()) |
1135 | 65 | data().DefaultedCopyConstructorIsDeleted = true; |
1136 | 39.7k | if (FieldRec->hasNonTrivialMoveConstructor()) |
1137 | 40 | data().DefaultedMoveConstructorIsDeleted = true; |
1138 | 39.7k | if (FieldRec->hasNonTrivialCopyAssignment()) |
1139 | 52 | data().DefaultedCopyAssignmentIsDeleted = true; |
1140 | 39.7k | if (FieldRec->hasNonTrivialMoveAssignment()) |
1141 | 38 | data().DefaultedMoveAssignmentIsDeleted = true; |
1142 | 39.7k | if (FieldRec->hasNonTrivialDestructor()) |
1143 | 58 | data().DefaultedDestructorIsDeleted = true; |
1144 | 39.7k | } |
1145 | | |
1146 | | // For an anonymous union member, our overload resolution will perform |
1147 | | // overload resolution for its members. |
1148 | 349k | if (Field->isAnonymousStructOrUnion()) { |
1149 | 7.53k | data().NeedOverloadResolutionForCopyConstructor |= |
1150 | 7.53k | FieldRec->data().NeedOverloadResolutionForCopyConstructor; |
1151 | 7.53k | data().NeedOverloadResolutionForMoveConstructor |= |
1152 | 7.53k | FieldRec->data().NeedOverloadResolutionForMoveConstructor; |
1153 | 7.53k | data().NeedOverloadResolutionForCopyAssignment |= |
1154 | 7.53k | FieldRec->data().NeedOverloadResolutionForCopyAssignment; |
1155 | 7.53k | data().NeedOverloadResolutionForMoveAssignment |= |
1156 | 7.53k | FieldRec->data().NeedOverloadResolutionForMoveAssignment; |
1157 | 7.53k | data().NeedOverloadResolutionForDestructor |= |
1158 | 7.53k | FieldRec->data().NeedOverloadResolutionForDestructor; |
1159 | 7.53k | } |
1160 | | |
1161 | | // C++0x [class.ctor]p5: |
1162 | | // A default constructor is trivial [...] if: |
1163 | | // -- for all the non-static data members of its class that are of |
1164 | | // class type (or array thereof), each such class has a trivial |
1165 | | // default constructor. |
1166 | 349k | if (!FieldRec->hasTrivialDefaultConstructor()) |
1167 | 32.8k | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; |
1168 | | |
1169 | | // C++0x [class.copy]p13: |
1170 | | // A copy/move constructor for class X is trivial if [...] |
1171 | | // [...] |
1172 | | // -- for each non-static data member of X that is of class type (or |
1173 | | // an array thereof), the constructor selected to copy/move that |
1174 | | // member is trivial; |
1175 | 349k | if (!FieldRec->hasTrivialCopyConstructor()) |
1176 | 12.3k | data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; |
1177 | | |
1178 | 349k | if (!FieldRec->hasTrivialCopyConstructorForCall()) |
1179 | 12.3k | data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor; |
1180 | | |
1181 | | // If the field doesn't have a simple move constructor, we'll eagerly |
1182 | | // declare the move constructor for this class and we'll decide whether |
1183 | | // it's trivial then. |
1184 | 349k | if (!FieldRec->hasTrivialMoveConstructor()) |
1185 | 17.0k | data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; |
1186 | | |
1187 | 349k | if (!FieldRec->hasTrivialMoveConstructorForCall()) |
1188 | 17.0k | data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor; |
1189 | | |
1190 | | // C++0x [class.copy]p27: |
1191 | | // A copy/move assignment operator for class X is trivial if [...] |
1192 | | // [...] |
1193 | | // -- for each non-static data member of X that is of class type (or |
1194 | | // an array thereof), the assignment operator selected to |
1195 | | // copy/move that member is trivial; |
1196 | 349k | if (!FieldRec->hasTrivialCopyAssignment()) |
1197 | 12.2k | data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; |
1198 | | // If the field doesn't have a simple move assignment, we'll eagerly |
1199 | | // declare the move assignment for this class and we'll decide whether |
1200 | | // it's trivial then. |
1201 | 349k | if (!FieldRec->hasTrivialMoveAssignment()) |
1202 | 17.0k | data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; |
1203 | | |
1204 | 349k | if (!FieldRec->hasTrivialDestructor()) |
1205 | 15.0k | data().HasTrivialSpecialMembers &= ~SMF_Destructor; |
1206 | 349k | if (!FieldRec->hasTrivialDestructorForCall()) |
1207 | 14.9k | data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor; |
1208 | 349k | if (!FieldRec->hasIrrelevantDestructor()) |
1209 | 14.6k | data().HasIrrelevantDestructor = false; |
1210 | 349k | if (FieldRec->isAnyDestructorNoReturn()) |
1211 | 2 | data().IsAnyDestructorNoReturn = true; |
1212 | 349k | if (FieldRec->hasObjectMember()) |
1213 | 42 | setHasObjectMember(true); |
1214 | 349k | if (FieldRec->hasVolatileMember()) |
1215 | 5 | setHasVolatileMember(true); |
1216 | 349k | if (FieldRec->getArgPassingRestrictions() == |
1217 | 349k | RecordDecl::APK_CanNeverPassInRegs) |
1218 | 10 | setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs); |
1219 | | |
1220 | | // C++0x [class]p7: |
1221 | | // A standard-layout class is a class that: |
1222 | | // -- has no non-static data members of type non-standard-layout |
1223 | | // class (or array of such types) [...] |
1224 | 349k | if (!FieldRec->isStandardLayout()) |
1225 | 9.35k | data().IsStandardLayout = false; |
1226 | 349k | if (!FieldRec->isCXX11StandardLayout()) |
1227 | 9.35k | data().IsCXX11StandardLayout = false; |
1228 | | |
1229 | | // C++2a [class]p7: |
1230 | | // A standard-layout class is a class that: |
1231 | | // [...] |
1232 | | // -- has no element of the set M(S) of types as a base class. |
1233 | 349k | if (data().IsStandardLayout && |
1234 | 349k | (331k isUnion()331k || IsFirstField291k || IsZeroSize238k ) && |
1235 | 349k | hasSubobjectAtOffsetZeroOfEmptyBaseType(Context, FieldRec)93.1k ) |
1236 | 130 | data().IsStandardLayout = false; |
1237 | | |
1238 | | // C++11 [class]p7: |
1239 | | // A standard-layout class is a class that: |
1240 | | // -- has no base classes of the same type as the first non-static |
1241 | | // data member |
1242 | 349k | if (data().IsCXX11StandardLayout && IsFirstField331k ) { |
1243 | | // FIXME: We should check all base classes here, not just direct |
1244 | | // base classes. |
1245 | 58.7k | for (const auto &BI : bases()) { |
1246 | 325 | if (Context.hasSameUnqualifiedType(BI.getType(), T)) { |
1247 | 83 | data().IsCXX11StandardLayout = false; |
1248 | 83 | break; |
1249 | 83 | } |
1250 | 325 | } |
1251 | 58.7k | } |
1252 | | |
1253 | | // Keep track of the presence of mutable fields. |
1254 | 349k | if (FieldRec->hasMutableFields()) |
1255 | 417 | data().HasMutableFields = true; |
1256 | | |
1257 | 349k | if (Field->isMutable()) { |
1258 | | // Our copy constructor/assignment might call something other than |
1259 | | // the subobject's copy constructor/assignment if it's mutable and of |
1260 | | // class type. |
1261 | 680 | data().NeedOverloadResolutionForCopyConstructor = true; |
1262 | 680 | data().NeedOverloadResolutionForCopyAssignment = true; |
1263 | 680 | } |
1264 | | |
1265 | | // C++11 [class.copy]p13: |
1266 | | // If the implicitly-defined constructor would satisfy the |
1267 | | // requirements of a constexpr constructor, the implicitly-defined |
1268 | | // constructor is constexpr. |
1269 | | // C++11 [dcl.constexpr]p4: |
1270 | | // -- every constructor involved in initializing non-static data |
1271 | | // members [...] shall be a constexpr constructor |
1272 | 349k | if (!Field->hasInClassInitializer() && |
1273 | 349k | !FieldRec->hasConstexprDefaultConstructor()347k && !isUnion()329k ) |
1274 | | // The standard requires any in-class initializer to be a constant |
1275 | | // expression. We consider this to be a defect. |
1276 | 291k | data().DefaultedDefaultConstructorIsConstexpr = false; |
1277 | | |
1278 | | // C++11 [class.copy]p8: |
1279 | | // The implicitly-declared copy constructor for a class X will have |
1280 | | // the form 'X::X(const X&)' if each potentially constructed subobject |
1281 | | // of a class type M (or array thereof) has a copy constructor whose |
1282 | | // first parameter is of type 'const M&' or 'const volatile M&'. |
1283 | 349k | if (!FieldRec->hasCopyConstructorWithConstParam()) |
1284 | 57 | data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false; |
1285 | | |
1286 | | // C++11 [class.copy]p18: |
1287 | | // The implicitly-declared copy assignment oeprator for a class X will |
1288 | | // have the form 'X& X::operator=(const X&)' if [...] for all the |
1289 | | // non-static data members of X that are of a class type M (or array |
1290 | | // thereof), each such class type has a copy assignment operator whose |
1291 | | // parameter is of type 'const M&', 'const volatile M&' or 'M'. |
1292 | 349k | if (!FieldRec->hasCopyAssignmentWithConstParam()) |
1293 | 96 | data().ImplicitCopyAssignmentHasConstParam = false; |
1294 | | |
1295 | 349k | if (FieldRec->hasUninitializedReferenceMember() && |
1296 | 349k | !Field->hasInClassInitializer()41 ) |
1297 | 28 | data().HasUninitializedReferenceMember = true; |
1298 | | |
1299 | | // C++11 [class.union]p8, DR1460: |
1300 | | // a non-static data member of an anonymous union that is a member of |
1301 | | // X is also a variant member of X. |
1302 | 349k | if (FieldRec->hasVariantMembers() && |
1303 | 349k | Field->isAnonymousStructOrUnion()10.9k ) |
1304 | 2.78k | data().HasVariantMembers = true; |
1305 | 349k | } |
1306 | 1.84M | } else { |
1307 | | // Base element type of field is a non-class type. |
1308 | 1.84M | if (!T->isLiteralType(Context) || |
1309 | 1.84M | (1.71M !Field->hasInClassInitializer()1.71M && !isUnion()1.70M && |
1310 | 1.71M | !Context.getLangOpts().CPlusPlus201.68M )) |
1311 | 1.78M | data().DefaultedDefaultConstructorIsConstexpr = false; |
1312 | | |
1313 | | // C++11 [class.copy]p23: |
1314 | | // A defaulted copy/move assignment operator for a class X is defined |
1315 | | // as deleted if X has: |
1316 | | // -- a non-static data member of const non-class type (or array |
1317 | | // thereof) |
1318 | 1.84M | if (T.isConstQualified()) { |
1319 | 9.30k | data().DefaultedCopyAssignmentIsDeleted = true; |
1320 | 9.30k | data().DefaultedMoveAssignmentIsDeleted = true; |
1321 | 9.30k | } |
1322 | | |
1323 | | // C++20 [temp.param]p7: |
1324 | | // A structural type is [...] a literal class type [for which] the |
1325 | | // types of all non-static data members are structural types or |
1326 | | // (possibly multidimensional) array thereof |
1327 | | // We deal with class types elsewhere. |
1328 | 1.84M | if (!T->isStructuralType()) |
1329 | 92.4k | data().StructuralIfLiteral = false; |
1330 | 1.84M | } |
1331 | | |
1332 | | // C++14 [meta.unary.prop]p4: |
1333 | | // T is a class type [...] with [...] no non-static data members other |
1334 | | // than subobjects of zero size |
1335 | 2.19M | if (data().Empty && !IsZeroSize659k ) |
1336 | 659k | data().Empty = false; |
1337 | 2.19M | } |
1338 | | |
1339 | | // Handle using declarations of conversion functions. |
1340 | 6.78M | if (auto *Shadow = dyn_cast<UsingShadowDecl>(D)) { |
1341 | 5.41k | if (Shadow->getDeclName().getNameKind() |
1342 | 5.41k | == DeclarationName::CXXConversionFunctionName) { |
1343 | 40 | ASTContext &Ctx = getASTContext(); |
1344 | 40 | data().Conversions.get(Ctx).addDecl(Ctx, Shadow, Shadow->getAccess()); |
1345 | 40 | } |
1346 | 5.41k | } |
1347 | | |
1348 | 6.78M | if (const auto *Using = dyn_cast<UsingDecl>(D)) { |
1349 | 2.84k | if (Using->getDeclName().getNameKind() == |
1350 | 2.84k | DeclarationName::CXXConstructorName) { |
1351 | 518 | data().HasInheritedConstructor = true; |
1352 | | // C++1z [dcl.init.aggr]p1: |
1353 | | // An aggregate is [...] a class [...] with no inherited constructors |
1354 | 518 | data().Aggregate = false; |
1355 | 518 | } |
1356 | | |
1357 | 2.84k | if (Using->getDeclName().getCXXOverloadedOperator() == OO_Equal) |
1358 | 135 | data().HasInheritedAssignment = true; |
1359 | 2.84k | } |
1360 | 6.78M | } |
1361 | | |
1362 | 39.6k | void CXXRecordDecl::addedSelectedDestructor(CXXDestructorDecl *DD) { |
1363 | 39.6k | DD->setIneligibleOrNotSelected(false); |
1364 | 39.6k | addedEligibleSpecialMemberFunction(DD, SMF_Destructor); |
1365 | 39.6k | } |
1366 | | |
1367 | | void CXXRecordDecl::addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD, |
1368 | 879k | unsigned SMKind) { |
1369 | 879k | if (const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) { |
1370 | 159k | if (DD->isUserProvided()) |
1371 | 49.2k | data().HasIrrelevantDestructor = false; |
1372 | | // If the destructor is explicitly defaulted and not trivial or not public |
1373 | | // or if the destructor is deleted, we clear HasIrrelevantDestructor in |
1374 | | // finishedDefaultedOrDeletedMember. |
1375 | | |
1376 | | // C++11 [class.dtor]p5: |
1377 | | // A destructor is trivial if [...] the destructor is not virtual. |
1378 | 159k | if (DD->isVirtual()) { |
1379 | 21.7k | data().HasTrivialSpecialMembers &= ~SMF_Destructor; |
1380 | 21.7k | data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor; |
1381 | 21.7k | } |
1382 | | |
1383 | 159k | if (DD->isNoReturn()) |
1384 | 33 | data().IsAnyDestructorNoReturn = true; |
1385 | 159k | } |
1386 | | |
1387 | 879k | if (!MD->isImplicit() && !MD->isUserProvided()365k ) { |
1388 | | // This method is user-declared but not user-provided. We can't work |
1389 | | // out whether it's trivial yet (not until we get to the end of the |
1390 | | // class). We'll handle this method in |
1391 | | // finishedDefaultedOrDeletedMember. |
1392 | 799k | } else if (MD->isTrivial()) { |
1393 | 443k | data().HasTrivialSpecialMembers |= SMKind; |
1394 | 443k | data().HasTrivialSpecialMembersForCall |= SMKind; |
1395 | 443k | } else if (355k MD->isTrivialForCall()355k ) { |
1396 | 165 | data().HasTrivialSpecialMembersForCall |= SMKind; |
1397 | 165 | data().DeclaredNonTrivialSpecialMembers |= SMKind; |
1398 | 355k | } else { |
1399 | 355k | data().DeclaredNonTrivialSpecialMembers |= SMKind; |
1400 | | // If this is a user-provided function, do not set |
1401 | | // DeclaredNonTrivialSpecialMembersForCall here since we don't know |
1402 | | // yet whether the method would be considered non-trivial for the |
1403 | | // purpose of calls (attribute "trivial_abi" can be dropped from the |
1404 | | // class later, which can change the special method's triviality). |
1405 | 355k | if (!MD->isUserProvided()) |
1406 | 70.1k | data().DeclaredNonTrivialSpecialMembersForCall |= SMKind; |
1407 | 355k | } |
1408 | 879k | } |
1409 | | |
1410 | 44.1k | void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) { |
1411 | 44.1k | assert(!D->isImplicit() && !D->isUserProvided()); |
1412 | | |
1413 | | // The kind of special member this declaration is, if any. |
1414 | 0 | unsigned SMKind = 0; |
1415 | | |
1416 | 44.1k | if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
1417 | 35.9k | if (Constructor->isDefaultConstructor()) { |
1418 | 16.7k | SMKind |= SMF_DefaultConstructor; |
1419 | 16.7k | if (Constructor->isConstexpr()) |
1420 | 10.8k | data().HasConstexprDefaultConstructor = true; |
1421 | 16.7k | } |
1422 | 35.9k | if (Constructor->isCopyConstructor()) |
1423 | 15.2k | SMKind |= SMF_CopyConstructor; |
1424 | 20.7k | else if (Constructor->isMoveConstructor()) |
1425 | 4.04k | SMKind |= SMF_MoveConstructor; |
1426 | 16.7k | else if (Constructor->isConstexpr()) |
1427 | | // We may now know that the constructor is constexpr. |
1428 | 10.8k | data().HasConstexprNonCopyMoveConstructor = true; |
1429 | 35.9k | } else if (8.21k isa<CXXDestructorDecl>(D)8.21k ) { |
1430 | 1.17k | SMKind |= SMF_Destructor; |
1431 | 1.17k | if (!D->isTrivial() || D->getAccess() != AS_public843 || D->isDeleted()748 ) |
1432 | 1.00k | data().HasIrrelevantDestructor = false; |
1433 | 7.03k | } else if (D->isCopyAssignmentOperator()) |
1434 | 6.65k | SMKind |= SMF_CopyAssignment; |
1435 | 373 | else if (D->isMoveAssignmentOperator()) |
1436 | 373 | SMKind |= SMF_MoveAssignment; |
1437 | | |
1438 | | // Update which trivial / non-trivial special members we have. |
1439 | | // addedMember will have skipped this step for this member. |
1440 | 44.1k | if (D->isTrivial()) |
1441 | 29.5k | data().HasTrivialSpecialMembers |= SMKind; |
1442 | 14.6k | else |
1443 | 14.6k | data().DeclaredNonTrivialSpecialMembers |= SMKind; |
1444 | 44.1k | } |
1445 | | |
1446 | | void CXXRecordDecl::setCaptures(ASTContext &Context, |
1447 | 11.0k | ArrayRef<LambdaCapture> Captures) { |
1448 | 11.0k | CXXRecordDecl::LambdaDefinitionData &Data = getLambdaData(); |
1449 | | |
1450 | | // Copy captures. |
1451 | 11.0k | Data.NumCaptures = Captures.size(); |
1452 | 11.0k | Data.NumExplicitCaptures = 0; |
1453 | 11.0k | Data.Captures = (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) * |
1454 | 11.0k | Captures.size()); |
1455 | 11.0k | LambdaCapture *ToCapture = Data.Captures; |
1456 | 17.0k | for (unsigned I = 0, N = Captures.size(); I != N; ++I6.04k ) { |
1457 | 6.04k | if (Captures[I].isExplicit()) |
1458 | 2.05k | ++Data.NumExplicitCaptures; |
1459 | | |
1460 | 6.04k | *ToCapture++ = Captures[I]; |
1461 | 6.04k | } |
1462 | | |
1463 | 11.0k | if (!lambdaIsDefaultConstructibleAndAssignable()) |
1464 | 10.0k | Data.DefaultedCopyAssignmentIsDeleted = true; |
1465 | 11.0k | } |
1466 | | |
1467 | 106k | void CXXRecordDecl::setTrivialForCallFlags(CXXMethodDecl *D) { |
1468 | 106k | unsigned SMKind = 0; |
1469 | | |
1470 | 106k | if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
1471 | 59.8k | if (Constructor->isCopyConstructor()) |
1472 | 31.8k | SMKind = SMF_CopyConstructor; |
1473 | 28.0k | else if (Constructor->isMoveConstructor()) |
1474 | 11.3k | SMKind = SMF_MoveConstructor; |
1475 | 59.8k | } else if (46.6k isa<CXXDestructorDecl>(D)46.6k ) |
1476 | 39.6k | SMKind = SMF_Destructor; |
1477 | | |
1478 | 106k | if (D->isTrivialForCall()) |
1479 | 29.6k | data().HasTrivialSpecialMembersForCall |= SMKind; |
1480 | 76.9k | else |
1481 | 76.9k | data().DeclaredNonTrivialSpecialMembersForCall |= SMKind; |
1482 | 106k | } |
1483 | | |
1484 | 59.7k | bool CXXRecordDecl::isCLike() const { |
1485 | 59.7k | if (getTagKind() == TTK_Class || getTagKind() == TTK_Interface59.4k || |
1486 | 59.7k | !TemplateOrInstantiation.isNull()59.4k ) |
1487 | 386 | return false; |
1488 | 59.3k | if (!hasDefinition()) |
1489 | 4 | return true; |
1490 | | |
1491 | 59.3k | return isPOD() && data().HasOnlyCMembers59.0k ; |
1492 | 59.3k | } |
1493 | | |
1494 | 8.54M | bool CXXRecordDecl::isGenericLambda() const { |
1495 | 8.54M | if (!isLambda()) return false8.43M ; |
1496 | 113k | return getLambdaData().IsGenericLambda; |
1497 | 8.54M | } |
1498 | | |
1499 | | #ifndef NDEBUG |
1500 | 51.5k | static bool allLookupResultsAreTheSame(const DeclContext::lookup_result &R) { |
1501 | 51.5k | for (auto *D : R) |
1502 | 51.6k | if (!declaresSameEntity(D, R.front())) |
1503 | 0 | return false; |
1504 | 51.5k | return true; |
1505 | 51.5k | } |
1506 | | #endif |
1507 | | |
1508 | 51.5k | static NamedDecl* getLambdaCallOperatorHelper(const CXXRecordDecl &RD) { |
1509 | 51.5k | if (!RD.isLambda()) return nullptr0 ; |
1510 | 51.5k | DeclarationName Name = |
1511 | 51.5k | RD.getASTContext().DeclarationNames.getCXXOperatorName(OO_Call); |
1512 | 51.5k | DeclContext::lookup_result Calls = RD.lookup(Name); |
1513 | | |
1514 | 51.5k | assert(!Calls.empty() && "Missing lambda call operator!"); |
1515 | 0 | assert(allLookupResultsAreTheSame(Calls) && |
1516 | 51.5k | "More than one lambda call operator!"); |
1517 | 0 | return Calls.front(); |
1518 | 51.5k | } |
1519 | | |
1520 | 260 | FunctionTemplateDecl* CXXRecordDecl::getDependentLambdaCallOperator() const { |
1521 | 260 | NamedDecl *CallOp = getLambdaCallOperatorHelper(*this); |
1522 | 260 | return dyn_cast_or_null<FunctionTemplateDecl>(CallOp); |
1523 | 260 | } |
1524 | | |
1525 | 51.3k | CXXMethodDecl *CXXRecordDecl::getLambdaCallOperator() const { |
1526 | 51.3k | NamedDecl *CallOp = getLambdaCallOperatorHelper(*this); |
1527 | | |
1528 | 51.3k | if (CallOp == nullptr) |
1529 | 0 | return nullptr; |
1530 | | |
1531 | 51.3k | if (const auto *CallOpTmpl = dyn_cast<FunctionTemplateDecl>(CallOp)) |
1532 | 21.5k | return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl()); |
1533 | | |
1534 | 29.7k | return cast<CXXMethodDecl>(CallOp); |
1535 | 51.3k | } |
1536 | | |
1537 | 7.98k | CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const { |
1538 | 7.98k | CXXMethodDecl *CallOp = getLambdaCallOperator(); |
1539 | 7.98k | CallingConv CC = CallOp->getType()->castAs<FunctionType>()->getCallConv(); |
1540 | 7.98k | return getLambdaStaticInvoker(CC); |
1541 | 7.98k | } |
1542 | | |
1543 | | static DeclContext::lookup_result |
1544 | 8.72k | getLambdaStaticInvokers(const CXXRecordDecl &RD) { |
1545 | 8.72k | assert(RD.isLambda() && "Must be a lambda"); |
1546 | 0 | DeclarationName Name = |
1547 | 8.72k | &RD.getASTContext().Idents.get(getLambdaStaticInvokerName()); |
1548 | 8.72k | return RD.lookup(Name); |
1549 | 8.72k | } |
1550 | | |
1551 | 2.46k | static CXXMethodDecl *getInvokerAsMethod(NamedDecl *ND) { |
1552 | 2.46k | if (const auto *InvokerTemplate = dyn_cast<FunctionTemplateDecl>(ND)) |
1553 | 845 | return cast<CXXMethodDecl>(InvokerTemplate->getTemplatedDecl()); |
1554 | 1.61k | return cast<CXXMethodDecl>(ND); |
1555 | 2.46k | } |
1556 | | |
1557 | 8.72k | CXXMethodDecl *CXXRecordDecl::getLambdaStaticInvoker(CallingConv CC) const { |
1558 | 8.72k | if (!isLambda()) |
1559 | 0 | return nullptr; |
1560 | 8.72k | DeclContext::lookup_result Invoker = getLambdaStaticInvokers(*this); |
1561 | | |
1562 | 8.72k | for (NamedDecl *ND : Invoker) { |
1563 | 2.47k | const auto *FTy = |
1564 | 2.47k | cast<ValueDecl>(ND->getAsFunction())->getType()->castAs<FunctionType>(); |
1565 | 2.47k | if (FTy->getCallConv() == CC) |
1566 | 2.46k | return getInvokerAsMethod(ND); |
1567 | 2.47k | } |
1568 | | |
1569 | 6.26k | return nullptr; |
1570 | 8.72k | } |
1571 | | |
1572 | | void CXXRecordDecl::getCaptureFields( |
1573 | | llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, |
1574 | 2.75k | FieldDecl *&ThisCapture) const { |
1575 | 2.75k | Captures.clear(); |
1576 | 2.75k | ThisCapture = nullptr; |
1577 | | |
1578 | 2.75k | LambdaDefinitionData &Lambda = getLambdaData(); |
1579 | 2.75k | RecordDecl::field_iterator Field = field_begin(); |
1580 | 2.75k | for (const LambdaCapture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures; |
1581 | 6.51k | C != CEnd; ++C, ++Field3.76k ) { |
1582 | 3.76k | if (C->capturesThis()) |
1583 | 94 | ThisCapture = *Field; |
1584 | 3.66k | else if (C->capturesVariable()) |
1585 | 3.64k | Captures[C->getCapturedVar()] = *Field; |
1586 | 3.76k | } |
1587 | 2.75k | assert(Field == field_end()); |
1588 | 2.75k | } |
1589 | | |
1590 | | TemplateParameterList * |
1591 | 12.3k | CXXRecordDecl::getGenericLambdaTemplateParameterList() const { |
1592 | 12.3k | if (!isGenericLambda()) return nullptr8.48k ; |
1593 | 3.85k | CXXMethodDecl *CallOp = getLambdaCallOperator(); |
1594 | 3.85k | if (FunctionTemplateDecl *Tmpl = CallOp->getDescribedFunctionTemplate()) |
1595 | 3.85k | return Tmpl->getTemplateParameters(); |
1596 | 0 | return nullptr; |
1597 | 3.85k | } |
1598 | | |
1599 | | ArrayRef<NamedDecl *> |
1600 | 8.14k | CXXRecordDecl::getLambdaExplicitTemplateParameters() const { |
1601 | 8.14k | TemplateParameterList *List = getGenericLambdaTemplateParameterList(); |
1602 | 8.14k | if (!List) |
1603 | 5.88k | return {}; |
1604 | | |
1605 | 2.25k | assert(std::is_partitioned(List->begin(), List->end(), |
1606 | 2.25k | [](const NamedDecl *D) { return !D->isImplicit(); }) |
1607 | 2.25k | && "Explicit template params should be ordered before implicit ones"); |
1608 | | |
1609 | 0 | const auto ExplicitEnd = llvm::partition_point( |
1610 | 2.36k | *List, [](const NamedDecl *D) { return !D->isImplicit(); }); |
1611 | 2.25k | return llvm::makeArrayRef(List->begin(), ExplicitEnd); |
1612 | 8.14k | } |
1613 | | |
1614 | 51.1k | Decl *CXXRecordDecl::getLambdaContextDecl() const { |
1615 | 51.1k | assert(isLambda() && "Not a lambda closure type!"); |
1616 | 0 | ExternalASTSource *Source = getParentASTContext().getExternalSource(); |
1617 | 51.1k | return getLambdaData().ContextDecl.get(Source); |
1618 | 51.1k | } |
1619 | | |
1620 | 7.53k | void CXXRecordDecl::setDeviceLambdaManglingNumber(unsigned Num) const { |
1621 | 7.53k | assert(isLambda() && "Not a lambda closure type!"); |
1622 | 7.53k | if (Num) |
1623 | 105 | getASTContext().DeviceLambdaManglingNumbers[this] = Num; |
1624 | 7.53k | } |
1625 | | |
1626 | 994 | unsigned CXXRecordDecl::getDeviceLambdaManglingNumber() const { |
1627 | 994 | assert(isLambda() && "Not a lambda closure type!"); |
1628 | 0 | auto I = getASTContext().DeviceLambdaManglingNumbers.find(this); |
1629 | 994 | if (I != getASTContext().DeviceLambdaManglingNumbers.end()) |
1630 | 128 | return I->second; |
1631 | 866 | return 0; |
1632 | 994 | } |
1633 | | |
1634 | 929 | static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) { |
1635 | 929 | QualType T = |
1636 | 929 | cast<CXXConversionDecl>(Conv->getUnderlyingDecl()->getAsFunction()) |
1637 | 929 | ->getConversionType(); |
1638 | 929 | return Context.getCanonicalType(T); |
1639 | 929 | } |
1640 | | |
1641 | | /// Collect the visible conversions of a base class. |
1642 | | /// |
1643 | | /// \param Record a base class of the class we're considering |
1644 | | /// \param InVirtual whether this base class is a virtual base (or a base |
1645 | | /// of a virtual base) |
1646 | | /// \param Access the access along the inheritance path to this base |
1647 | | /// \param ParentHiddenTypes the conversions provided by the inheritors |
1648 | | /// of this base |
1649 | | /// \param Output the set to which to add conversions from non-virtual bases |
1650 | | /// \param VOutput the set to which to add conversions from virtual bases |
1651 | | /// \param HiddenVBaseCs the set of conversions which were hidden in a |
1652 | | /// virtual base along some inheritance path |
1653 | | static void CollectVisibleConversions( |
1654 | | ASTContext &Context, const CXXRecordDecl *Record, bool InVirtual, |
1655 | | AccessSpecifier Access, |
1656 | | const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes, |
1657 | | ASTUnresolvedSet &Output, UnresolvedSetImpl &VOutput, |
1658 | 8.22k | llvm::SmallPtrSet<NamedDecl *, 8> &HiddenVBaseCs) { |
1659 | | // The set of types which have conversions in this class or its |
1660 | | // subclasses. As an optimization, we don't copy the derived set |
1661 | | // unless it might change. |
1662 | 8.22k | const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes; |
1663 | 8.22k | llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer; |
1664 | | |
1665 | | // Collect the direct conversions and figure out which conversions |
1666 | | // will be hidden in the subclasses. |
1667 | 8.22k | CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); |
1668 | 8.22k | CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); |
1669 | 8.22k | if (ConvI != ConvE) { |
1670 | 537 | HiddenTypesBuffer = ParentHiddenTypes; |
1671 | 537 | HiddenTypes = &HiddenTypesBuffer; |
1672 | | |
1673 | 1.30k | for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I770 ) { |
1674 | 770 | CanQualType ConvType(GetConversionType(Context, I.getDecl())); |
1675 | 770 | bool Hidden = ParentHiddenTypes.count(ConvType); |
1676 | 770 | if (!Hidden) |
1677 | 689 | HiddenTypesBuffer.insert(ConvType); |
1678 | | |
1679 | | // If this conversion is hidden and we're in a virtual base, |
1680 | | // remember that it's hidden along some inheritance path. |
1681 | 770 | if (Hidden && InVirtual81 ) |
1682 | 0 | HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())); |
1683 | | |
1684 | | // If this conversion isn't hidden, add it to the appropriate output. |
1685 | 770 | else if (!Hidden) { |
1686 | 689 | AccessSpecifier IAccess |
1687 | 689 | = CXXRecordDecl::MergeAccess(Access, I.getAccess()); |
1688 | | |
1689 | 689 | if (InVirtual) |
1690 | 116 | VOutput.addDecl(I.getDecl(), IAccess); |
1691 | 573 | else |
1692 | 573 | Output.addDecl(Context, I.getDecl(), IAccess); |
1693 | 689 | } |
1694 | 770 | } |
1695 | 537 | } |
1696 | | |
1697 | | // Collect information recursively from any base classes. |
1698 | 8.22k | for (const auto &I : Record->bases()) { |
1699 | 2.21k | const auto *RT = I.getType()->getAs<RecordType>(); |
1700 | 2.21k | if (!RT) continue0 ; |
1701 | | |
1702 | 2.21k | AccessSpecifier BaseAccess |
1703 | 2.21k | = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier()); |
1704 | 2.21k | bool BaseInVirtual = InVirtual || I.isVirtual()2.05k ; |
1705 | | |
1706 | 2.21k | auto *Base = cast<CXXRecordDecl>(RT->getDecl()); |
1707 | 2.21k | CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess, |
1708 | 2.21k | *HiddenTypes, Output, VOutput, HiddenVBaseCs); |
1709 | 2.21k | } |
1710 | 8.22k | } |
1711 | | |
1712 | | /// Collect the visible conversions of a class. |
1713 | | /// |
1714 | | /// This would be extremely straightforward if it weren't for virtual |
1715 | | /// bases. It might be worth special-casing that, really. |
1716 | | static void CollectVisibleConversions(ASTContext &Context, |
1717 | | const CXXRecordDecl *Record, |
1718 | 5.71k | ASTUnresolvedSet &Output) { |
1719 | | // The collection of all conversions in virtual bases that we've |
1720 | | // found. These will be added to the output as long as they don't |
1721 | | // appear in the hidden-conversions set. |
1722 | 5.71k | UnresolvedSet<8> VBaseCs; |
1723 | | |
1724 | | // The set of conversions in virtual bases that we've determined to |
1725 | | // be hidden. |
1726 | 5.71k | llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs; |
1727 | | |
1728 | | // The set of types hidden by classes derived from this one. |
1729 | 5.71k | llvm::SmallPtrSet<CanQualType, 8> HiddenTypes; |
1730 | | |
1731 | | // Go ahead and collect the direct conversions and add them to the |
1732 | | // hidden-types set. |
1733 | 5.71k | CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); |
1734 | 5.71k | CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); |
1735 | 5.71k | Output.append(Context, ConvI, ConvE); |
1736 | 5.87k | for (; ConvI != ConvE; ++ConvI159 ) |
1737 | 159 | HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl())); |
1738 | | |
1739 | | // Recursively collect conversions from base classes. |
1740 | 6.01k | for (const auto &I : Record->bases()) { |
1741 | 6.01k | const auto *RT = I.getType()->getAs<RecordType>(); |
1742 | 6.01k | if (!RT) continue0 ; |
1743 | | |
1744 | 6.01k | CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()), |
1745 | 6.01k | I.isVirtual(), I.getAccessSpecifier(), |
1746 | 6.01k | HiddenTypes, Output, VBaseCs, HiddenVBaseCs); |
1747 | 6.01k | } |
1748 | | |
1749 | | // Add any unhidden conversions provided by virtual bases. |
1750 | 5.71k | for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end(); |
1751 | 5.83k | I != E; ++I116 ) { |
1752 | 116 | if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()))) |
1753 | 116 | Output.addDecl(Context, I.getDecl(), I.getAccess()); |
1754 | 116 | } |
1755 | 5.71k | } |
1756 | | |
1757 | | /// getVisibleConversionFunctions - get all conversion functions visible |
1758 | | /// in current class; including conversion function templates. |
1759 | | llvm::iterator_range<CXXRecordDecl::conversion_iterator> |
1760 | 3.92M | CXXRecordDecl::getVisibleConversionFunctions() const { |
1761 | 3.92M | ASTContext &Ctx = getASTContext(); |
1762 | | |
1763 | 3.92M | ASTUnresolvedSet *Set; |
1764 | 3.92M | if (bases_begin() == bases_end()) { |
1765 | | // If root class, all conversions are visible. |
1766 | 3.86M | Set = &data().Conversions.get(Ctx); |
1767 | 3.86M | } else { |
1768 | 64.9k | Set = &data().VisibleConversions.get(Ctx); |
1769 | | // If visible conversion list is not evaluated, evaluate it. |
1770 | 64.9k | if (!data().ComputedVisibleConversions) { |
1771 | 5.71k | CollectVisibleConversions(Ctx, this, *Set); |
1772 | 5.71k | data().ComputedVisibleConversions = true; |
1773 | 5.71k | } |
1774 | 64.9k | } |
1775 | 3.92M | return llvm::make_range(Set->begin(), Set->end()); |
1776 | 3.92M | } |
1777 | | |
1778 | 0 | void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) { |
1779 | | // This operation is O(N) but extremely rare. Sema only uses it to |
1780 | | // remove UsingShadowDecls in a class that were followed by a direct |
1781 | | // declaration, e.g.: |
1782 | | // class A : B { |
1783 | | // using B::operator int; |
1784 | | // operator int(); |
1785 | | // }; |
1786 | | // This is uncommon by itself and even more uncommon in conjunction |
1787 | | // with sufficiently large numbers of directly-declared conversions |
1788 | | // that asymptotic behavior matters. |
1789 | |
|
1790 | 0 | ASTUnresolvedSet &Convs = data().Conversions.get(getASTContext()); |
1791 | 0 | for (unsigned I = 0, E = Convs.size(); I != E; ++I) { |
1792 | 0 | if (Convs[I].getDecl() == ConvDecl) { |
1793 | 0 | Convs.erase(I); |
1794 | 0 | assert(!llvm::is_contained(Convs, ConvDecl) && |
1795 | 0 | "conversion was found multiple times in unresolved set"); |
1796 | 0 | return; |
1797 | 0 | } |
1798 | 0 | } |
1799 | | |
1800 | 0 | llvm_unreachable("conversion not found in set!"); |
1801 | 0 | } |
1802 | | |
1803 | 2.06M | CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const { |
1804 | 2.06M | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) |
1805 | 195k | return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom()); |
1806 | | |
1807 | 1.86M | return nullptr; |
1808 | 2.06M | } |
1809 | | |
1810 | 6.13M | MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const { |
1811 | 6.13M | return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>(); |
1812 | 6.13M | } |
1813 | | |
1814 | | void |
1815 | | CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD, |
1816 | 27.0k | TemplateSpecializationKind TSK) { |
1817 | 27.0k | assert(TemplateOrInstantiation.isNull() && |
1818 | 27.0k | "Previous template or instantiation?"); |
1819 | 0 | assert(!isa<ClassTemplatePartialSpecializationDecl>(this)); |
1820 | 0 | TemplateOrInstantiation |
1821 | 27.0k | = new (getASTContext()) MemberSpecializationInfo(RD, TSK); |
1822 | 27.0k | } |
1823 | | |
1824 | 90.9M | ClassTemplateDecl *CXXRecordDecl::getDescribedClassTemplate() const { |
1825 | 90.9M | return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl *>(); |
1826 | 90.9M | } |
1827 | | |
1828 | 791k | void CXXRecordDecl::setDescribedClassTemplate(ClassTemplateDecl *Template) { |
1829 | 791k | TemplateOrInstantiation = Template; |
1830 | 791k | } |
1831 | | |
1832 | 4.49M | TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ |
1833 | 4.49M | if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this)) |
1834 | 2.58M | return Spec->getSpecializationKind(); |
1835 | | |
1836 | 1.90M | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) |
1837 | 21.4k | return MSInfo->getTemplateSpecializationKind(); |
1838 | | |
1839 | 1.88M | return TSK_Undeclared; |
1840 | 1.90M | } |
1841 | | |
1842 | | void |
1843 | 1.03M | CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { |
1844 | 1.03M | if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this)) { |
1845 | 1.03M | Spec->setSpecializationKind(TSK); |
1846 | 1.03M | return; |
1847 | 1.03M | } |
1848 | | |
1849 | 72 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { |
1850 | 72 | MSInfo->setTemplateSpecializationKind(TSK); |
1851 | 72 | return; |
1852 | 72 | } |
1853 | | |
1854 | 0 | llvm_unreachable("Not a class template or member class specialization"); |
1855 | 0 | } |
1856 | | |
1857 | 1.90M | const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const { |
1858 | 1.90M | auto GetDefinitionOrSelf = |
1859 | 1.90M | [](const CXXRecordDecl *D) -> const CXXRecordDecl * { |
1860 | 1.06M | if (auto *Def = D->getDefinition()) |
1861 | 1.06M | return Def; |
1862 | 0 | return D; |
1863 | 1.06M | }; |
1864 | | |
1865 | | // If it's a class template specialization, find the template or partial |
1866 | | // specialization from which it was instantiated. |
1867 | 1.90M | if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(this)) { |
1868 | 1.10M | auto From = TD->getInstantiatedFrom(); |
1869 | 1.10M | if (auto *CTD = From.dyn_cast<ClassTemplateDecl *>()) { |
1870 | 945k | while (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate()) { |
1871 | 3.68k | if (NewCTD->isMemberSpecialization()) |
1872 | 0 | break; |
1873 | 3.68k | CTD = NewCTD; |
1874 | 3.68k | } |
1875 | 941k | return GetDefinitionOrSelf(CTD->getTemplatedDecl()); |
1876 | 941k | } |
1877 | 161k | if (auto *CTPSD = |
1878 | 161k | From.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) { |
1879 | 102k | while (auto *NewCTPSD = CTPSD->getInstantiatedFromMember()) { |
1880 | 429 | if (NewCTPSD->isMemberSpecialization()) |
1881 | 0 | break; |
1882 | 429 | CTPSD = NewCTPSD; |
1883 | 429 | } |
1884 | 102k | return GetDefinitionOrSelf(CTPSD); |
1885 | 102k | } |
1886 | 161k | } |
1887 | | |
1888 | 864k | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { |
1889 | 20.5k | if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) { |
1890 | 20.5k | const CXXRecordDecl *RD = this; |
1891 | 41.0k | while (auto *NewRD = RD->getInstantiatedFromMemberClass()) |
1892 | 20.5k | RD = NewRD; |
1893 | 20.5k | return GetDefinitionOrSelf(RD); |
1894 | 20.5k | } |
1895 | 20.5k | } |
1896 | | |
1897 | 844k | assert(!isTemplateInstantiation(this->getTemplateSpecializationKind()) && |
1898 | 844k | "couldn't find pattern for class template instantiation"); |
1899 | 0 | return nullptr; |
1900 | 864k | } |
1901 | | |
1902 | 7.44M | CXXDestructorDecl *CXXRecordDecl::getDestructor() const { |
1903 | 7.44M | ASTContext &Context = getASTContext(); |
1904 | 7.44M | QualType ClassType = Context.getTypeDeclType(this); |
1905 | | |
1906 | 7.44M | DeclarationName Name |
1907 | 7.44M | = Context.DeclarationNames.getCXXDestructorName( |
1908 | 7.44M | Context.getCanonicalType(ClassType)); |
1909 | | |
1910 | 7.44M | DeclContext::lookup_result R = lookup(Name); |
1911 | | |
1912 | | // If a destructor was marked as not selected, we skip it. We don't always |
1913 | | // have a selected destructor: dependent types, unnamed structs. |
1914 | 7.44M | for (auto *Decl : R) { |
1915 | 1.67M | auto* DD = dyn_cast<CXXDestructorDecl>(Decl); |
1916 | 1.67M | if (DD && !DD->isIneligibleOrNotSelected()1.67M ) |
1917 | 1.62M | return DD; |
1918 | 1.67M | } |
1919 | 5.82M | return nullptr; |
1920 | 7.44M | } |
1921 | | |
1922 | 11 | static bool isDeclContextInNamespace(const DeclContext *DC) { |
1923 | 19 | while (!DC->isTranslationUnit()) { |
1924 | 11 | if (DC->isNamespace()) |
1925 | 3 | return true; |
1926 | 8 | DC = DC->getParent(); |
1927 | 8 | } |
1928 | 8 | return false; |
1929 | 11 | } |
1930 | | |
1931 | 34 | bool CXXRecordDecl::isInterfaceLike() const { |
1932 | 34 | assert(hasDefinition() && "checking for interface-like without a definition"); |
1933 | | // All __interfaces are inheritently interface-like. |
1934 | 34 | if (isInterface()) |
1935 | 7 | return true; |
1936 | | |
1937 | | // Interface-like types cannot have a user declared constructor, destructor, |
1938 | | // friends, VBases, conversion functions, or fields. Additionally, lambdas |
1939 | | // cannot be interface types. |
1940 | 27 | if (isLambda() || hasUserDeclaredConstructor() || |
1941 | 27 | hasUserDeclaredDestructor() || !field_empty() || hasFriends() || |
1942 | 27 | getNumVBases() > 0 || conversion_end() - conversion_begin() > 0) |
1943 | 0 | return false; |
1944 | | |
1945 | | // No interface-like type can have a method with a definition. |
1946 | 27 | for (const auto *const Method : methods()) |
1947 | 19 | if (Method->isDefined() && !Method->isImplicit()5 ) |
1948 | 2 | return false; |
1949 | | |
1950 | | // Check "Special" types. |
1951 | 25 | const auto *Uuid = getAttr<UuidAttr>(); |
1952 | | // MS SDK declares IUnknown/IDispatch both in the root of a TU, or in an |
1953 | | // extern C++ block directly in the TU. These are only valid if in one |
1954 | | // of these two situations. |
1955 | 25 | if (Uuid && isStruct()11 && !getDeclContext()->isExternCContext()11 && |
1956 | 25 | !isDeclContextInNamespace(getDeclContext())11 && |
1957 | 25 | (8 (8 getName() == "IUnknown"8 && |
1958 | 8 | Uuid->getGuid() == "00000000-0000-0000-C000-000000000046") || |
1959 | 8 | (0 getName() == "IDispatch"0 && |
1960 | 8 | Uuid->getGuid() == "00020400-0000-0000-C000-000000000046"0 ))) { |
1961 | 8 | if (getNumBases() > 0) |
1962 | 0 | return false; |
1963 | 8 | return true; |
1964 | 8 | } |
1965 | | |
1966 | | // FIXME: Any access specifiers is supposed to make this no longer interface |
1967 | | // like. |
1968 | | |
1969 | | // If this isn't a 'special' type, it must have a single interface-like base. |
1970 | 17 | if (getNumBases() != 1) |
1971 | 7 | return false; |
1972 | | |
1973 | 10 | const auto BaseSpec = *bases_begin(); |
1974 | 10 | if (BaseSpec.isVirtual() || BaseSpec.getAccessSpecifier() != AS_public) |
1975 | 0 | return false; |
1976 | 10 | const auto *Base = BaseSpec.getType()->getAsCXXRecordDecl(); |
1977 | 10 | if (Base->isInterface() || !Base->isInterfaceLike()9 ) |
1978 | 1 | return false; |
1979 | 9 | return true; |
1980 | 10 | } |
1981 | | |
1982 | 2.60M | void CXXRecordDecl::completeDefinition() { |
1983 | 2.60M | completeDefinition(nullptr); |
1984 | 2.60M | } |
1985 | | |
1986 | 2.60M | void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) { |
1987 | 2.60M | RecordDecl::completeDefinition(); |
1988 | | |
1989 | | // If the class may be abstract (but hasn't been marked as such), check for |
1990 | | // any pure final overriders. |
1991 | 2.60M | if (mayBeAbstract()) { |
1992 | 1.03k | CXXFinalOverriderMap MyFinalOverriders; |
1993 | 1.03k | if (!FinalOverriders) { |
1994 | 986 | getFinalOverriders(MyFinalOverriders); |
1995 | 986 | FinalOverriders = &MyFinalOverriders; |
1996 | 986 | } |
1997 | | |
1998 | 1.03k | bool Done = false; |
1999 | 1.03k | for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(), |
2000 | 1.03k | MEnd = FinalOverriders->end(); |
2001 | 4.75k | M != MEnd && !Done3.98k ; ++M3.72k ) { |
2002 | 3.72k | for (OverridingMethods::iterator SO = M->second.begin(), |
2003 | 3.72k | SOEnd = M->second.end(); |
2004 | 7.02k | SO != SOEnd && !Done3.72k ; ++SO3.30k ) { |
2005 | 3.72k | assert(SO->second.size() > 0 && |
2006 | 3.72k | "All virtual functions have overriding virtual functions"); |
2007 | | |
2008 | | // C++ [class.abstract]p4: |
2009 | | // A class is abstract if it contains or inherits at least one |
2010 | | // pure virtual function for which the final overrider is pure |
2011 | | // virtual. |
2012 | 3.72k | if (SO->second.front().Method->isPure()) { |
2013 | 427 | data().Abstract = true; |
2014 | 427 | Done = true; |
2015 | 427 | break; |
2016 | 427 | } |
2017 | 3.72k | } |
2018 | 3.72k | } |
2019 | 1.03k | } |
2020 | | |
2021 | | // Set access bits correctly on the directly-declared conversions. |
2022 | 2.60M | for (conversion_iterator I = conversion_begin(), E = conversion_end(); |
2023 | 2.63M | I != E; ++I34.2k ) |
2024 | 34.2k | I.setAccess((*I)->getAccess()); |
2025 | 2.60M | } |
2026 | | |
2027 | 2.60M | bool CXXRecordDecl::mayBeAbstract() const { |
2028 | 2.60M | if (data().Abstract || isInvalidDecl()2.60M || !data().Polymorphic2.57M || |
2029 | 2.60M | isDependentContext()33.3k ) |
2030 | 2.57M | return false; |
2031 | | |
2032 | 25.3k | for (const auto &B : bases()) { |
2033 | 22.4k | const auto *BaseDecl = |
2034 | 22.4k | cast<CXXRecordDecl>(B.getType()->castAs<RecordType>()->getDecl()); |
2035 | 22.4k | if (BaseDecl->isAbstract()) |
2036 | 1.03k | return true; |
2037 | 22.4k | } |
2038 | | |
2039 | 24.3k | return false; |
2040 | 25.3k | } |
2041 | | |
2042 | 1.09M | bool CXXRecordDecl::isEffectivelyFinal() const { |
2043 | 1.09M | auto *Def = getDefinition(); |
2044 | 1.09M | if (!Def) |
2045 | 0 | return false; |
2046 | 1.09M | if (Def->hasAttr<FinalAttr>()) |
2047 | 320 | return true; |
2048 | 1.09M | if (const auto *Dtor = Def->getDestructor()) |
2049 | 930k | if (Dtor->hasAttr<FinalAttr>()) |
2050 | 46 | return true; |
2051 | 1.09M | return false; |
2052 | 1.09M | } |
2053 | | |
2054 | 0 | void CXXDeductionGuideDecl::anchor() {} |
2055 | | |
2056 | 279k | bool ExplicitSpecifier::isEquivalent(const ExplicitSpecifier Other) const { |
2057 | 279k | if ((getKind() != Other.getKind() || |
2058 | 279k | getKind() == ExplicitSpecKind::Unresolved202k )) { |
2059 | 77.4k | if (getKind() == ExplicitSpecKind::Unresolved && |
2060 | 77.4k | Other.getKind() == ExplicitSpecKind::Unresolved4 ) { |
2061 | 4 | ODRHash SelfHash, OtherHash; |
2062 | 4 | SelfHash.AddStmt(getExpr()); |
2063 | 4 | OtherHash.AddStmt(Other.getExpr()); |
2064 | 4 | return SelfHash.CalculateHash() == OtherHash.CalculateHash(); |
2065 | 4 | } else |
2066 | 77.4k | return false; |
2067 | 77.4k | } |
2068 | 202k | return true; |
2069 | 279k | } |
2070 | | |
2071 | 2.41M | ExplicitSpecifier ExplicitSpecifier::getFromDecl(FunctionDecl *Function) { |
2072 | 2.41M | switch (Function->getDeclKind()) { |
2073 | 1.55M | case Decl::Kind::CXXConstructor: |
2074 | 1.55M | return cast<CXXConstructorDecl>(Function)->getExplicitSpecifier(); |
2075 | 17.6k | case Decl::Kind::CXXConversion: |
2076 | 17.6k | return cast<CXXConversionDecl>(Function)->getExplicitSpecifier(); |
2077 | 723 | case Decl::Kind::CXXDeductionGuide: |
2078 | 723 | return cast<CXXDeductionGuideDecl>(Function)->getExplicitSpecifier(); |
2079 | 835k | default: |
2080 | 835k | return {}; |
2081 | 2.41M | } |
2082 | 2.41M | } |
2083 | | |
2084 | | CXXDeductionGuideDecl * |
2085 | | CXXDeductionGuideDecl::Create(ASTContext &C, DeclContext *DC, |
2086 | | SourceLocation StartLoc, ExplicitSpecifier ES, |
2087 | | const DeclarationNameInfo &NameInfo, QualType T, |
2088 | | TypeSourceInfo *TInfo, SourceLocation EndLocation, |
2089 | 4.96k | CXXConstructorDecl *Ctor) { |
2090 | 4.96k | return new (C, DC) CXXDeductionGuideDecl(C, DC, StartLoc, ES, NameInfo, T, |
2091 | 4.96k | TInfo, EndLocation, Ctor); |
2092 | 4.96k | } |
2093 | | |
2094 | | CXXDeductionGuideDecl *CXXDeductionGuideDecl::CreateDeserialized(ASTContext &C, |
2095 | 180 | unsigned ID) { |
2096 | 180 | return new (C, ID) CXXDeductionGuideDecl( |
2097 | 180 | C, nullptr, SourceLocation(), ExplicitSpecifier(), DeclarationNameInfo(), |
2098 | 180 | QualType(), nullptr, SourceLocation(), nullptr); |
2099 | 180 | } |
2100 | | |
2101 | | RequiresExprBodyDecl *RequiresExprBodyDecl::Create( |
2102 | 3.29k | ASTContext &C, DeclContext *DC, SourceLocation StartLoc) { |
2103 | 3.29k | return new (C, DC) RequiresExprBodyDecl(C, DC, StartLoc); |
2104 | 3.29k | } |
2105 | | |
2106 | | RequiresExprBodyDecl *RequiresExprBodyDecl::CreateDeserialized(ASTContext &C, |
2107 | 148 | unsigned ID) { |
2108 | 148 | return new (C, ID) RequiresExprBodyDecl(C, nullptr, SourceLocation()); |
2109 | 148 | } |
2110 | | |
2111 | 0 | void CXXMethodDecl::anchor() {} |
2112 | | |
2113 | 31.7M | bool CXXMethodDecl::isStatic() const { |
2114 | 31.7M | const CXXMethodDecl *MD = getCanonicalDecl(); |
2115 | | |
2116 | 31.7M | if (MD->getStorageClass() == SC_Static) |
2117 | 2.87M | return true; |
2118 | | |
2119 | 28.8M | OverloadedOperatorKind OOK = getDeclName().getCXXOverloadedOperator(); |
2120 | 28.8M | return isStaticOverloadedOperator(OOK); |
2121 | 31.7M | } |
2122 | | |
2123 | | static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD, |
2124 | 323 | const CXXMethodDecl *BaseMD) { |
2125 | 323 | for (const CXXMethodDecl *MD : DerivedMD->overridden_methods()) { |
2126 | 265 | if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl()) |
2127 | 220 | return true; |
2128 | 45 | if (recursivelyOverrides(MD, BaseMD)) |
2129 | 31 | return true; |
2130 | 45 | } |
2131 | 72 | return false; |
2132 | 323 | } |
2133 | | |
2134 | | CXXMethodDecl * |
2135 | | CXXMethodDecl::getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2136 | 12.5k | bool MayBeBase) { |
2137 | 12.5k | if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl()) |
2138 | 11.3k | return this; |
2139 | | |
2140 | | // Lookup doesn't work for destructors, so handle them separately. |
2141 | 1.25k | if (isa<CXXDestructorDecl>(this)) { |
2142 | 8 | CXXMethodDecl *MD = RD->getDestructor(); |
2143 | 8 | if (MD) { |
2144 | 8 | if (recursivelyOverrides(MD, this)) |
2145 | 8 | return MD; |
2146 | 0 | if (MayBeBase && recursivelyOverrides(this, MD)) |
2147 | 0 | return MD; |
2148 | 0 | } |
2149 | 0 | return nullptr; |
2150 | 8 | } |
2151 | | |
2152 | 1.24k | for (auto *ND : RD->lookup(getDeclName())) { |
2153 | 358 | auto *MD = dyn_cast<CXXMethodDecl>(ND); |
2154 | 358 | if (!MD) |
2155 | 108 | continue; |
2156 | 250 | if (recursivelyOverrides(MD, this)) |
2157 | 199 | return MD; |
2158 | 51 | if (MayBeBase && recursivelyOverrides(this, MD)2 ) |
2159 | 1 | return MD; |
2160 | 51 | } |
2161 | | |
2162 | 1.04k | return nullptr; |
2163 | 1.24k | } |
2164 | | |
2165 | | CXXMethodDecl * |
2166 | | CXXMethodDecl::getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2167 | 12.3k | bool MayBeBase) { |
2168 | 12.3k | if (auto *MD = getCorrespondingMethodDeclaredInClass(RD, MayBeBase)) |
2169 | 11.3k | return MD; |
2170 | | |
2171 | 1.04k | llvm::SmallVector<CXXMethodDecl*, 4> FinalOverriders; |
2172 | 1.04k | auto AddFinalOverrider = [&](CXXMethodDecl *D) { |
2173 | | // If this function is overridden by a candidate final overrider, it is not |
2174 | | // a final overrider. |
2175 | 923 | for (CXXMethodDecl *OtherD : FinalOverriders) { |
2176 | 14 | if (declaresSameEntity(D, OtherD) || recursivelyOverrides(OtherD, D)12 ) |
2177 | 8 | return; |
2178 | 14 | } |
2179 | | |
2180 | | // Other candidate final overriders might be overridden by this function. |
2181 | 915 | llvm::erase_if(FinalOverriders, [&](CXXMethodDecl *OtherD) { |
2182 | 6 | return recursivelyOverrides(D, OtherD); |
2183 | 6 | }); |
2184 | | |
2185 | 915 | FinalOverriders.push_back(D); |
2186 | 915 | }; |
2187 | | |
2188 | 1.05k | for (const auto &I : RD->bases()) { |
2189 | 1.05k | const RecordType *RT = I.getType()->getAs<RecordType>(); |
2190 | 1.05k | if (!RT) |
2191 | 0 | continue; |
2192 | 1.05k | const auto *Base = cast<CXXRecordDecl>(RT->getDecl()); |
2193 | 1.05k | if (CXXMethodDecl *D = this->getCorrespondingMethodInClass(Base)) |
2194 | 923 | AddFinalOverrider(D); |
2195 | 1.05k | } |
2196 | | |
2197 | 1.04k | return FinalOverriders.size() == 1 ? FinalOverriders.front()909 : nullptr131 ; |
2198 | 12.3k | } |
2199 | | |
2200 | | CXXMethodDecl * |
2201 | | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2202 | | const DeclarationNameInfo &NameInfo, QualType T, |
2203 | | TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin, |
2204 | | bool isInline, ConstexprSpecKind ConstexprKind, |
2205 | | SourceLocation EndLocation, |
2206 | 2.77M | Expr *TrailingRequiresClause) { |
2207 | 2.77M | return new (C, RD) CXXMethodDecl( |
2208 | 2.77M | CXXMethod, C, RD, StartLoc, NameInfo, T, TInfo, SC, UsesFPIntrin, |
2209 | 2.77M | isInline, ConstexprKind, EndLocation, TrailingRequiresClause); |
2210 | 2.77M | } |
2211 | | |
2212 | 753k | CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
2213 | 753k | return new (C, ID) CXXMethodDecl( |
2214 | 753k | CXXMethod, C, nullptr, SourceLocation(), DeclarationNameInfo(), |
2215 | 753k | QualType(), nullptr, SC_None, false, false, |
2216 | 753k | ConstexprSpecKind::Unspecified, SourceLocation(), nullptr); |
2217 | 753k | } |
2218 | | |
2219 | | CXXMethodDecl *CXXMethodDecl::getDevirtualizedMethod(const Expr *Base, |
2220 | 15.4k | bool IsAppleKext) { |
2221 | 15.4k | assert(isVirtual() && "this method is expected to be virtual"); |
2222 | | |
2223 | | // When building with -fapple-kext, all calls must go through the vtable since |
2224 | | // the kernel linker can do runtime patching of vtables. |
2225 | 15.4k | if (IsAppleKext) |
2226 | 11 | return nullptr; |
2227 | | |
2228 | | // If the member function is marked 'final', we know that it can't be |
2229 | | // overridden and can therefore devirtualize it unless it's pure virtual. |
2230 | 15.4k | if (hasAttr<FinalAttr>()) |
2231 | 35 | return isPure() ? nullptr7 : this28 ; |
2232 | | |
2233 | | // If Base is unknown, we cannot devirtualize. |
2234 | 15.4k | if (!Base) |
2235 | 221 | return nullptr; |
2236 | | |
2237 | | // If the base expression (after skipping derived-to-base conversions) is a |
2238 | | // class prvalue, then we can devirtualize. |
2239 | 15.1k | Base = Base->getBestDynamicClassTypeExpr(); |
2240 | 15.1k | if (Base->isPRValue() && Base->getType()->isRecordType()13.4k ) |
2241 | 191 | return this; |
2242 | | |
2243 | | // If we don't even know what we would call, we can't devirtualize. |
2244 | 14.9k | const CXXRecordDecl *BestDynamicDecl = Base->getBestDynamicClassType(); |
2245 | 14.9k | if (!BestDynamicDecl) |
2246 | 4.40k | return nullptr; |
2247 | | |
2248 | | // There may be a method corresponding to MD in a derived class. |
2249 | 10.5k | CXXMethodDecl *DevirtualizedMethod = |
2250 | 10.5k | getCorrespondingMethodInClass(BestDynamicDecl); |
2251 | | |
2252 | | // If there final overrider in the dynamic type is ambiguous, we can't |
2253 | | // devirtualize this call. |
2254 | 10.5k | if (!DevirtualizedMethod) |
2255 | 0 | return nullptr; |
2256 | | |
2257 | | // If that method is pure virtual, we can't devirtualize. If this code is |
2258 | | // reached, the result would be UB, not a direct call to the derived class |
2259 | | // function, and we can't assume the derived class function is defined. |
2260 | 10.5k | if (DevirtualizedMethod->isPure()) |
2261 | 920 | return nullptr; |
2262 | | |
2263 | | // If that method is marked final, we can devirtualize it. |
2264 | 9.67k | if (DevirtualizedMethod->hasAttr<FinalAttr>()) |
2265 | 6 | return DevirtualizedMethod; |
2266 | | |
2267 | | // Similarly, if the class itself or its destructor is marked 'final', |
2268 | | // the class can't be derived from and we can therefore devirtualize the |
2269 | | // member function call. |
2270 | 9.66k | if (BestDynamicDecl->isEffectivelyFinal()) |
2271 | 93 | return DevirtualizedMethod; |
2272 | | |
2273 | 9.57k | if (const auto *DRE = dyn_cast<DeclRefExpr>(Base)) { |
2274 | 932 | if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) |
2275 | 932 | if (VD->getType()->isRecordType()) |
2276 | | // This is a record decl. We know the type and can devirtualize it. |
2277 | 688 | return DevirtualizedMethod; |
2278 | | |
2279 | 244 | return nullptr; |
2280 | 932 | } |
2281 | | |
2282 | | // We can devirtualize calls on an object accessed by a class member access |
2283 | | // expression, since by C++11 [basic.life]p6 we know that it can't refer to |
2284 | | // a derived class object constructed in the same location. |
2285 | 8.63k | if (const auto *ME = dyn_cast<MemberExpr>(Base)) { |
2286 | 40 | const ValueDecl *VD = ME->getMemberDecl(); |
2287 | 40 | return VD->getType()->isRecordType() ? DevirtualizedMethod : nullptr0 ; |
2288 | 40 | } |
2289 | | |
2290 | | // Likewise for calls on an object accessed by a (non-reference) pointer to |
2291 | | // member access. |
2292 | 8.59k | if (auto *BO = dyn_cast<BinaryOperator>(Base)) { |
2293 | 12 | if (BO->isPtrMemOp()) { |
2294 | 12 | auto *MPT = BO->getRHS()->getType()->castAs<MemberPointerType>(); |
2295 | 12 | if (MPT->getPointeeType()->isRecordType()) |
2296 | 12 | return DevirtualizedMethod; |
2297 | 12 | } |
2298 | 12 | } |
2299 | | |
2300 | | // We can't devirtualize the call. |
2301 | 8.58k | return nullptr; |
2302 | 8.59k | } |
2303 | | |
2304 | | bool CXXMethodDecl::isUsualDeallocationFunction( |
2305 | 904 | SmallVectorImpl<const FunctionDecl *> &PreventedBy) const { |
2306 | 904 | assert(PreventedBy.empty() && "PreventedBy is expected to be empty"); |
2307 | 904 | if (getOverloadedOperator() != OO_Delete && |
2308 | 904 | getOverloadedOperator() != OO_Array_Delete126 ) |
2309 | 0 | return false; |
2310 | | |
2311 | | // C++ [basic.stc.dynamic.deallocation]p2: |
2312 | | // A template instance is never a usual deallocation function, |
2313 | | // regardless of its signature. |
2314 | 904 | if (getPrimaryTemplate()) |
2315 | 1 | return false; |
2316 | | |
2317 | | // C++ [basic.stc.dynamic.deallocation]p2: |
2318 | | // If a class T has a member deallocation function named operator delete |
2319 | | // with exactly one parameter, then that function is a usual (non-placement) |
2320 | | // deallocation function. [...] |
2321 | 903 | if (getNumParams() == 1) |
2322 | 286 | return true; |
2323 | 617 | unsigned UsualParams = 1; |
2324 | | |
2325 | | // C++ P0722: |
2326 | | // A destroying operator delete is a usual deallocation function if |
2327 | | // removing the std::destroying_delete_t parameter and changing the |
2328 | | // first parameter type from T* to void* results in the signature of |
2329 | | // a usual deallocation function. |
2330 | 617 | if (isDestroyingOperatorDelete()) |
2331 | 260 | ++UsualParams; |
2332 | | |
2333 | | // C++ <=14 [basic.stc.dynamic.deallocation]p2: |
2334 | | // [...] If class T does not declare such an operator delete but does |
2335 | | // declare a member deallocation function named operator delete with |
2336 | | // exactly two parameters, the second of which has type std::size_t (18.1), |
2337 | | // then this function is a usual deallocation function. |
2338 | | // |
2339 | | // C++17 says a usual deallocation function is one with the signature |
2340 | | // (void* [, size_t] [, std::align_val_t] [, ...]) |
2341 | | // and all such functions are usual deallocation functions. It's not clear |
2342 | | // that allowing varargs functions was intentional. |
2343 | 617 | ASTContext &Context = getASTContext(); |
2344 | 617 | if (UsualParams < getNumParams() && |
2345 | 617 | Context.hasSameUnqualifiedType(getParamDecl(UsualParams)->getType(), |
2346 | 483 | Context.getSizeType())) |
2347 | 274 | ++UsualParams; |
2348 | | |
2349 | 617 | if (UsualParams < getNumParams() && |
2350 | 617 | getParamDecl(UsualParams)->getType()->isAlignValT()282 ) |
2351 | 164 | ++UsualParams; |
2352 | | |
2353 | 617 | if (UsualParams != getNumParams()) |
2354 | 123 | return false; |
2355 | | |
2356 | | // In C++17 onwards, all potential usual deallocation functions are actual |
2357 | | // usual deallocation functions. Honor this behavior when post-C++14 |
2358 | | // deallocation functions are offered as extensions too. |
2359 | | // FIXME(EricWF): Destroying Delete should be a language option. How do we |
2360 | | // handle when destroying delete is used prior to C++17? |
2361 | 494 | if (Context.getLangOpts().CPlusPlus17 || |
2362 | 494 | Context.getLangOpts().AlignedAllocation176 || |
2363 | 494 | isDestroyingOperatorDelete()110 ) |
2364 | 384 | return true; |
2365 | | |
2366 | | // This function is a usual deallocation function if there are no |
2367 | | // single-parameter deallocation functions of the same kind. |
2368 | 110 | DeclContext::lookup_result R = getDeclContext()->lookup(getDeclName()); |
2369 | 110 | bool Result = true; |
2370 | 172 | for (const auto *D : R) { |
2371 | 172 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { |
2372 | 168 | if (FD->getNumParams() == 1) { |
2373 | 34 | PreventedBy.push_back(FD); |
2374 | 34 | Result = false; |
2375 | 34 | } |
2376 | 168 | } |
2377 | 172 | } |
2378 | 110 | return Result; |
2379 | 494 | } |
2380 | | |
2381 | 12.0M | bool CXXMethodDecl::isCopyAssignmentOperator() const { |
2382 | | // C++0x [class.copy]p17: |
2383 | | // A user-declared copy assignment operator X::operator= is a non-static |
2384 | | // non-template member function of class X with exactly one parameter of |
2385 | | // type X, X&, const X&, volatile X& or const volatile X&. |
2386 | 12.0M | if (/*operator=*/getOverloadedOperator() != OO_Equal || |
2387 | 12.0M | /*non-static*/ isStatic()577k || |
2388 | 12.0M | /*non-template*/getPrimaryTemplate()577k || getDescribedFunctionTemplate()577k || |
2389 | 12.0M | getNumParams() != 1519k ) |
2390 | 11.5M | return false; |
2391 | | |
2392 | 519k | QualType ParamType = getParamDecl(0)->getType(); |
2393 | 519k | if (const auto *Ref = ParamType->getAs<LValueReferenceType>()) |
2394 | 294k | ParamType = Ref->getPointeeType(); |
2395 | | |
2396 | 519k | ASTContext &Context = getASTContext(); |
2397 | 519k | QualType ClassType |
2398 | 519k | = Context.getCanonicalType(Context.getTypeDeclType(getParent())); |
2399 | 519k | return Context.hasSameUnqualifiedType(ClassType, ParamType); |
2400 | 12.0M | } |
2401 | | |
2402 | 11.5M | bool CXXMethodDecl::isMoveAssignmentOperator() const { |
2403 | | // C++0x [class.copy]p19: |
2404 | | // A user-declared move assignment operator X::operator= is a non-static |
2405 | | // non-template member function of class X with exactly one parameter of type |
2406 | | // X&&, const X&&, volatile X&&, or const volatile X&&. |
2407 | 11.5M | if (getOverloadedOperator() != OO_Equal || isStatic()428k || |
2408 | 11.5M | getPrimaryTemplate()428k || getDescribedFunctionTemplate()428k || |
2409 | 11.5M | getNumParams() != 1371k ) |
2410 | 11.1M | return false; |
2411 | | |
2412 | 371k | QualType ParamType = getParamDecl(0)->getType(); |
2413 | 371k | if (!ParamType->isRValueReferenceType()) |
2414 | 197k | return false; |
2415 | 173k | ParamType = ParamType->getPointeeType(); |
2416 | | |
2417 | 173k | ASTContext &Context = getASTContext(); |
2418 | 173k | QualType ClassType |
2419 | 173k | = Context.getCanonicalType(Context.getTypeDeclType(getParent())); |
2420 | 173k | return Context.hasSameUnqualifiedType(ClassType, ParamType); |
2421 | 371k | } |
2422 | | |
2423 | 37.6k | void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { |
2424 | 37.6k | assert(MD->isCanonicalDecl() && "Method is not canonical!"); |
2425 | 0 | assert(!MD->getParent()->isDependentContext() && |
2426 | 37.6k | "Can't add an overridden method to a class template!"); |
2427 | 0 | assert(MD->isVirtual() && "Method is not virtual!"); |
2428 | | |
2429 | 0 | getASTContext().addOverriddenMethod(this, MD); |
2430 | 37.6k | } |
2431 | | |
2432 | 1.85k | CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { |
2433 | 1.85k | if (isa<CXXConstructorDecl>(this)) return nullptr0 ; |
2434 | 1.85k | return getASTContext().overridden_methods_begin(this); |
2435 | 1.85k | } |
2436 | | |
2437 | 0 | CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { |
2438 | 0 | if (isa<CXXConstructorDecl>(this)) return nullptr; |
2439 | 0 | return getASTContext().overridden_methods_end(this); |
2440 | 0 | } |
2441 | | |
2442 | 14.7M | unsigned CXXMethodDecl::size_overridden_methods() const { |
2443 | 14.7M | if (isa<CXXConstructorDecl>(this)) return 03.61M ; |
2444 | 11.0M | return getASTContext().overridden_methods_size(this); |
2445 | 14.7M | } |
2446 | | |
2447 | | CXXMethodDecl::overridden_method_range |
2448 | 3.70M | CXXMethodDecl::overridden_methods() const { |
2449 | 3.70M | if (isa<CXXConstructorDecl>(this)) |
2450 | 671k | return overridden_method_range(nullptr, nullptr); |
2451 | 3.02M | return getASTContext().overridden_methods(this); |
2452 | 3.70M | } |
2453 | | |
2454 | | static QualType getThisObjectType(ASTContext &C, const FunctionProtoType *FPT, |
2455 | 5.58M | const CXXRecordDecl *Decl) { |
2456 | 5.58M | QualType ClassTy = C.getTypeDeclType(Decl); |
2457 | 5.58M | return C.getQualifiedType(ClassTy, FPT->getMethodQuals()); |
2458 | 5.58M | } |
2459 | | |
2460 | | QualType CXXMethodDecl::getThisType(const FunctionProtoType *FPT, |
2461 | 4.78M | const CXXRecordDecl *Decl) { |
2462 | 4.78M | ASTContext &C = Decl->getASTContext(); |
2463 | 4.78M | QualType ObjectTy = ::getThisObjectType(C, FPT, Decl); |
2464 | 4.78M | return C.getPointerType(ObjectTy); |
2465 | 4.78M | } |
2466 | | |
2467 | | QualType CXXMethodDecl::getThisObjectType(const FunctionProtoType *FPT, |
2468 | 798k | const CXXRecordDecl *Decl) { |
2469 | 798k | ASTContext &C = Decl->getASTContext(); |
2470 | 798k | return ::getThisObjectType(C, FPT, Decl); |
2471 | 798k | } |
2472 | | |
2473 | 4.78M | QualType CXXMethodDecl::getThisType() const { |
2474 | | // C++ 9.3.2p1: The type of this in a member function of a class X is X*. |
2475 | | // If the member function is declared const, the type of this is const X*, |
2476 | | // if the member function is declared volatile, the type of this is |
2477 | | // volatile X*, and if the member function is declared const volatile, |
2478 | | // the type of this is const volatile X*. |
2479 | 4.78M | assert(isInstance() && "No 'this' for static methods!"); |
2480 | 0 | return CXXMethodDecl::getThisType(getType()->castAs<FunctionProtoType>(), |
2481 | 4.78M | getParent()); |
2482 | 4.78M | } |
2483 | | |
2484 | 798k | QualType CXXMethodDecl::getThisObjectType() const { |
2485 | | // Ditto getThisType. |
2486 | 798k | assert(isInstance() && "No 'this' for static methods!"); |
2487 | 0 | return CXXMethodDecl::getThisObjectType( |
2488 | 798k | getType()->castAs<FunctionProtoType>(), getParent()); |
2489 | 798k | } |
2490 | | |
2491 | 20.5k | bool CXXMethodDecl::hasInlineBody() const { |
2492 | | // If this function is a template instantiation, look at the template from |
2493 | | // which it was instantiated. |
2494 | 20.5k | const FunctionDecl *CheckFn = getTemplateInstantiationPattern(); |
2495 | 20.5k | if (!CheckFn) |
2496 | 20.5k | CheckFn = this; |
2497 | | |
2498 | 20.5k | const FunctionDecl *fn; |
2499 | 20.5k | return CheckFn->isDefined(fn) && !fn->isOutOfLine()9.50k && |
2500 | 20.5k | (5.77k fn->doesThisDeclarationHaveABody()5.77k || fn->willHaveBody()72 ); |
2501 | 20.5k | } |
2502 | | |
2503 | 143k | bool CXXMethodDecl::isLambdaStaticInvoker() const { |
2504 | 143k | const CXXRecordDecl *P = getParent(); |
2505 | 143k | return P->isLambda() && getDeclName().isIdentifier()1.79k && |
2506 | 143k | getName() == getLambdaStaticInvokerName()87 ; |
2507 | 143k | } |
2508 | | |
2509 | | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
2510 | | TypeSourceInfo *TInfo, bool IsVirtual, |
2511 | | SourceLocation L, Expr *Init, |
2512 | | SourceLocation R, |
2513 | | SourceLocation EllipsisLoc) |
2514 | | : Initializee(TInfo), Init(Init), MemberOrEllipsisLocation(EllipsisLoc), |
2515 | | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual), |
2516 | 85.1k | IsWritten(false), SourceOrder(0) {} |
2517 | | |
2518 | | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, |
2519 | | SourceLocation MemberLoc, |
2520 | | SourceLocation L, Expr *Init, |
2521 | | SourceLocation R) |
2522 | | : Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc), |
2523 | | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), |
2524 | 458k | IsWritten(false), SourceOrder(0) {} |
2525 | | |
2526 | | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
2527 | | IndirectFieldDecl *Member, |
2528 | | SourceLocation MemberLoc, |
2529 | | SourceLocation L, Expr *Init, |
2530 | | SourceLocation R) |
2531 | | : Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc), |
2532 | | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), |
2533 | 411 | IsWritten(false), SourceOrder(0) {} |
2534 | | |
2535 | | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
2536 | | TypeSourceInfo *TInfo, |
2537 | | SourceLocation L, Expr *Init, |
2538 | | SourceLocation R) |
2539 | | : Initializee(TInfo), Init(Init), LParenLoc(L), RParenLoc(R), |
2540 | 678 | IsDelegating(true), IsVirtual(false), IsWritten(false), SourceOrder(0) {} |
2541 | | |
2542 | 5 | int64_t CXXCtorInitializer::getID(const ASTContext &Context) const { |
2543 | 5 | return Context.getAllocator() |
2544 | 5 | .identifyKnownAlignedObject<CXXCtorInitializer>(this); |
2545 | 5 | } |
2546 | | |
2547 | 0 | TypeLoc CXXCtorInitializer::getBaseClassLoc() const { |
2548 | 0 | if (isBaseInitializer()) |
2549 | 0 | return Initializee.get<TypeSourceInfo*>()->getTypeLoc(); |
2550 | 0 | else |
2551 | 0 | return {}; |
2552 | 0 | } |
2553 | | |
2554 | 102k | const Type *CXXCtorInitializer::getBaseClass() const { |
2555 | 102k | if (isBaseInitializer()) |
2556 | 77.1k | return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr(); |
2557 | 25.8k | else |
2558 | 25.8k | return nullptr; |
2559 | 102k | } |
2560 | | |
2561 | 139k | SourceLocation CXXCtorInitializer::getSourceLocation() const { |
2562 | 139k | if (isInClassMemberInitializer()) |
2563 | 1.35k | return getAnyMember()->getLocation(); |
2564 | | |
2565 | 138k | if (isAnyMemberInitializer()) |
2566 | 109k | return getMemberLocation(); |
2567 | | |
2568 | 28.9k | if (const auto *TSInfo = Initializee.get<TypeSourceInfo *>()) |
2569 | 28.9k | return TSInfo->getTypeLoc().getLocalSourceRange().getBegin(); |
2570 | | |
2571 | 0 | return {}; |
2572 | 28.9k | } |
2573 | | |
2574 | 168 | SourceRange CXXCtorInitializer::getSourceRange() const { |
2575 | 168 | if (isInClassMemberInitializer()) { |
2576 | 0 | FieldDecl *D = getAnyMember(); |
2577 | 0 | if (Expr *I = D->getInClassInitializer()) |
2578 | 0 | return I->getSourceRange(); |
2579 | 0 | return {}; |
2580 | 0 | } |
2581 | | |
2582 | 168 | return SourceRange(getSourceLocation(), getRParenLoc()); |
2583 | 168 | } |
2584 | | |
2585 | | CXXConstructorDecl::CXXConstructorDecl( |
2586 | | ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2587 | | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2588 | | ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline, |
2589 | | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2590 | | InheritedConstructor Inherited, Expr *TrailingRequiresClause) |
2591 | | : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo, |
2592 | | SC_None, UsesFPIntrin, isInline, ConstexprKind, |
2593 | 1.30M | SourceLocation(), TrailingRequiresClause) { |
2594 | 1.30M | setNumCtorInitializers(0); |
2595 | 1.30M | setInheritingConstructor(static_cast<bool>(Inherited)); |
2596 | 1.30M | setImplicit(isImplicitlyDeclared); |
2597 | 1.30M | CXXConstructorDeclBits.HasTrailingExplicitSpecifier = ES.getExpr() ? 1169 : 01.30M ; |
2598 | 1.30M | if (Inherited) |
2599 | 337 | *getTrailingObjects<InheritedConstructor>() = Inherited; |
2600 | 1.30M | setExplicitSpecifier(ES); |
2601 | 1.30M | } |
2602 | | |
2603 | 0 | void CXXConstructorDecl::anchor() {} |
2604 | | |
2605 | | CXXConstructorDecl *CXXConstructorDecl::CreateDeserialized(ASTContext &C, |
2606 | | unsigned ID, |
2607 | 207k | uint64_t AllocKind) { |
2608 | 207k | bool hasTrailingExplicit = static_cast<bool>(AllocKind & TAKHasTailExplicit); |
2609 | 207k | bool isInheritingConstructor = |
2610 | 207k | static_cast<bool>(AllocKind & TAKInheritsConstructor); |
2611 | 207k | unsigned Extra = |
2612 | 207k | additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>( |
2613 | 207k | isInheritingConstructor, hasTrailingExplicit); |
2614 | 207k | auto *Result = new (C, ID, Extra) CXXConstructorDecl( |
2615 | 207k | C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr, |
2616 | 207k | ExplicitSpecifier(), false, false, false, ConstexprSpecKind::Unspecified, |
2617 | 207k | InheritedConstructor(), nullptr); |
2618 | 207k | Result->setInheritingConstructor(isInheritingConstructor); |
2619 | 207k | Result->CXXConstructorDeclBits.HasTrailingExplicitSpecifier = |
2620 | 207k | hasTrailingExplicit; |
2621 | 207k | Result->setExplicitSpecifier(ExplicitSpecifier()); |
2622 | 207k | return Result; |
2623 | 207k | } |
2624 | | |
2625 | | CXXConstructorDecl *CXXConstructorDecl::Create( |
2626 | | ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2627 | | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2628 | | ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline, |
2629 | | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2630 | 1.09M | InheritedConstructor Inherited, Expr *TrailingRequiresClause) { |
2631 | 1.09M | assert(NameInfo.getName().getNameKind() |
2632 | 1.09M | == DeclarationName::CXXConstructorName && |
2633 | 1.09M | "Name must refer to a constructor"); |
2634 | 0 | unsigned Extra = |
2635 | 1.09M | additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>( |
2636 | 1.09M | Inherited ? 1337 : 01.09M , ES.getExpr() ? 1169 : 01.09M ); |
2637 | 1.09M | return new (C, RD, Extra) CXXConstructorDecl( |
2638 | 1.09M | C, RD, StartLoc, NameInfo, T, TInfo, ES, UsesFPIntrin, isInline, |
2639 | 1.09M | isImplicitlyDeclared, ConstexprKind, Inherited, TrailingRequiresClause); |
2640 | 1.09M | } |
2641 | | |
2642 | 682k | CXXConstructorDecl::init_const_iterator CXXConstructorDecl::init_begin() const { |
2643 | 682k | return CtorInitializers.get(getASTContext().getExternalSource()); |
2644 | 682k | } |
2645 | | |
2646 | 551 | CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const { |
2647 | 551 | assert(isDelegatingConstructor() && "Not a delegating constructor!"); |
2648 | 0 | Expr *E = (*init_begin())->getInit()->IgnoreImplicit(); |
2649 | 551 | if (const auto *Construct = dyn_cast<CXXConstructExpr>(E)) |
2650 | 546 | return Construct->getConstructor(); |
2651 | | |
2652 | 5 | return nullptr; |
2653 | 551 | } |
2654 | | |
2655 | 1.95M | bool CXXConstructorDecl::isDefaultConstructor() const { |
2656 | | // C++ [class.default.ctor]p1: |
2657 | | // A default constructor for a class X is a constructor of class X for |
2658 | | // which each parameter that is not a function parameter pack has a default |
2659 | | // argument (including the case of a constructor with no parameters) |
2660 | 1.95M | return getMinRequiredArguments() == 0; |
2661 | 1.95M | } |
2662 | | |
2663 | | bool |
2664 | 1.55M | CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const { |
2665 | 1.55M | return isCopyOrMoveConstructor(TypeQuals) && |
2666 | 1.55M | getParamDecl(0)->getType()->isLValueReferenceType()805k ; |
2667 | 1.55M | } |
2668 | | |
2669 | 986k | bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const { |
2670 | 986k | return isCopyOrMoveConstructor(TypeQuals) && |
2671 | 986k | getParamDecl(0)->getType()->isRValueReferenceType()386k ; |
2672 | 986k | } |
2673 | | |
2674 | | /// Determine whether this is a copy or move constructor. |
2675 | 5.13M | bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const { |
2676 | | // C++ [class.copy]p2: |
2677 | | // A non-template constructor for class X is a copy constructor |
2678 | | // if its first parameter is of type X&, const X&, volatile X& or |
2679 | | // const volatile X&, and either there are no other parameters |
2680 | | // or else all other parameters have default arguments (8.3.6). |
2681 | | // C++0x [class.copy]p3: |
2682 | | // A non-template constructor for class X is a move constructor if its |
2683 | | // first parameter is of type X&&, const X&&, volatile X&&, or |
2684 | | // const volatile X&&, and either there are no other parameters or else |
2685 | | // all other parameters have default arguments. |
2686 | 5.13M | if (!hasOneParamOrDefaultArgs() || getPrimaryTemplate() != nullptr3.23M || |
2687 | 5.13M | getDescribedFunctionTemplate() != nullptr3.13M ) |
2688 | 2.31M | return false; |
2689 | | |
2690 | 2.81M | const ParmVarDecl *Param = getParamDecl(0); |
2691 | | |
2692 | | // Do we have a reference type? |
2693 | 2.81M | const auto *ParamRefType = Param->getType()->getAs<ReferenceType>(); |
2694 | 2.81M | if (!ParamRefType) |
2695 | 646k | return false; |
2696 | | |
2697 | | // Is it a reference to our class type? |
2698 | 2.17M | ASTContext &Context = getASTContext(); |
2699 | | |
2700 | 2.17M | CanQualType PointeeType |
2701 | 2.17M | = Context.getCanonicalType(ParamRefType->getPointeeType()); |
2702 | 2.17M | CanQualType ClassTy |
2703 | 2.17M | = Context.getCanonicalType(Context.getTagDeclType(getParent())); |
2704 | 2.17M | if (PointeeType.getUnqualifiedType() != ClassTy) |
2705 | 250k | return false; |
2706 | | |
2707 | | // FIXME: other qualifiers? |
2708 | | |
2709 | | // We have a copy or move constructor. |
2710 | 1.92M | TypeQuals = PointeeType.getCVRQualifiers(); |
2711 | 1.92M | return true; |
2712 | 2.17M | } |
2713 | | |
2714 | 932k | bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const { |
2715 | | // C++ [class.conv.ctor]p1: |
2716 | | // A constructor declared without the function-specifier explicit |
2717 | | // that can be called with a single parameter specifies a |
2718 | | // conversion from the type of its first parameter to the type of |
2719 | | // its class. Such a constructor is called a converting |
2720 | | // constructor. |
2721 | 932k | if (isExplicit() && !AllowExplicit174k ) |
2722 | 465 | return false; |
2723 | | |
2724 | | // FIXME: This has nothing to do with the definition of converting |
2725 | | // constructor, but is convenient for how we use this function in overload |
2726 | | // resolution. |
2727 | 932k | return getNumParams() == 0 |
2728 | 932k | ? getType()->castAs<FunctionProtoType>()->isVariadic()150k |
2729 | 932k | : getMinRequiredArguments() <= 1781k ; |
2730 | 932k | } |
2731 | | |
2732 | 1.38M | bool CXXConstructorDecl::isSpecializationCopyingObject() const { |
2733 | 1.38M | if (!hasOneParamOrDefaultArgs() || getDescribedFunctionTemplate() != nullptr1.13M ) |
2734 | 248k | return false; |
2735 | | |
2736 | 1.13M | const ParmVarDecl *Param = getParamDecl(0); |
2737 | | |
2738 | 1.13M | ASTContext &Context = getASTContext(); |
2739 | 1.13M | CanQualType ParamType = Context.getCanonicalType(Param->getType()); |
2740 | | |
2741 | | // Is it the same as our class type? |
2742 | 1.13M | CanQualType ClassTy |
2743 | 1.13M | = Context.getCanonicalType(Context.getTagDeclType(getParent())); |
2744 | 1.13M | if (ParamType.getUnqualifiedType() != ClassTy) |
2745 | 1.13M | return false; |
2746 | | |
2747 | 328 | return true; |
2748 | 1.13M | } |
2749 | | |
2750 | 0 | void CXXDestructorDecl::anchor() {} |
2751 | | |
2752 | | CXXDestructorDecl * |
2753 | 26.6k | CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
2754 | 26.6k | return new (C, ID) CXXDestructorDecl( |
2755 | 26.6k | C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr, |
2756 | 26.6k | false, false, false, ConstexprSpecKind::Unspecified, nullptr); |
2757 | 26.6k | } |
2758 | | |
2759 | | CXXDestructorDecl *CXXDestructorDecl::Create( |
2760 | | ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2761 | | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2762 | | bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared, |
2763 | 182k | ConstexprSpecKind ConstexprKind, Expr *TrailingRequiresClause) { |
2764 | 182k | assert(NameInfo.getName().getNameKind() |
2765 | 182k | == DeclarationName::CXXDestructorName && |
2766 | 182k | "Name must refer to a destructor"); |
2767 | 0 | return new (C, RD) CXXDestructorDecl( |
2768 | 182k | C, RD, StartLoc, NameInfo, T, TInfo, UsesFPIntrin, isInline, |
2769 | 182k | isImplicitlyDeclared, ConstexprKind, TrailingRequiresClause); |
2770 | 182k | } |
2771 | | |
2772 | 23.4k | void CXXDestructorDecl::setOperatorDelete(FunctionDecl *OD, Expr *ThisArg) { |
2773 | 23.4k | auto *First = cast<CXXDestructorDecl>(getFirstDecl()); |
2774 | 23.4k | if (OD && !First->OperatorDelete1.84k ) { |
2775 | 1.84k | First->OperatorDelete = OD; |
2776 | 1.84k | First->OperatorDeleteThisArg = ThisArg; |
2777 | 1.84k | if (auto *L = getASTMutationListener()) |
2778 | 60 | L->ResolvedOperatorDelete(First, OD, ThisArg); |
2779 | 1.84k | } |
2780 | 23.4k | } |
2781 | | |
2782 | 0 | void CXXConversionDecl::anchor() {} |
2783 | | |
2784 | | CXXConversionDecl * |
2785 | 5.31k | CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
2786 | 5.31k | return new (C, ID) CXXConversionDecl( |
2787 | 5.31k | C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr, |
2788 | 5.31k | false, false, ExplicitSpecifier(), ConstexprSpecKind::Unspecified, |
2789 | 5.31k | SourceLocation(), nullptr); |
2790 | 5.31k | } |
2791 | | |
2792 | | CXXConversionDecl *CXXConversionDecl::Create( |
2793 | | ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2794 | | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2795 | | bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES, |
2796 | | ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, |
2797 | 38.6k | Expr *TrailingRequiresClause) { |
2798 | 38.6k | assert(NameInfo.getName().getNameKind() |
2799 | 38.6k | == DeclarationName::CXXConversionFunctionName && |
2800 | 38.6k | "Name must refer to a conversion function"); |
2801 | 0 | return new (C, RD) CXXConversionDecl( |
2802 | 38.6k | C, RD, StartLoc, NameInfo, T, TInfo, UsesFPIntrin, isInline, ES, |
2803 | 38.6k | ConstexprKind, EndLocation, TrailingRequiresClause); |
2804 | 38.6k | } |
2805 | | |
2806 | 749 | bool CXXConversionDecl::isLambdaToBlockPointerConversion() const { |
2807 | 749 | return isImplicit() && getParent()->isLambda() && |
2808 | 749 | getConversionType()->isBlockPointerType(); |
2809 | 749 | } |
2810 | | |
2811 | | LinkageSpecDecl::LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, |
2812 | | SourceLocation LangLoc, LanguageIDs lang, |
2813 | | bool HasBraces) |
2814 | | : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec), |
2815 | 386k | ExternLoc(ExternLoc), RBraceLoc(SourceLocation()) { |
2816 | 386k | setLanguage(lang); |
2817 | 386k | LinkageSpecDeclBits.HasBraces = HasBraces; |
2818 | 386k | } |
2819 | | |
2820 | 0 | void LinkageSpecDecl::anchor() {} |
2821 | | |
2822 | | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, |
2823 | | DeclContext *DC, |
2824 | | SourceLocation ExternLoc, |
2825 | | SourceLocation LangLoc, |
2826 | | LanguageIDs Lang, |
2827 | 361k | bool HasBraces) { |
2828 | 361k | return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces); |
2829 | 361k | } |
2830 | | |
2831 | | LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C, |
2832 | 24.3k | unsigned ID) { |
2833 | 24.3k | return new (C, ID) LinkageSpecDecl(nullptr, SourceLocation(), |
2834 | 24.3k | SourceLocation(), lang_c, false); |
2835 | 24.3k | } |
2836 | | |
2837 | 0 | void UsingDirectiveDecl::anchor() {} |
2838 | | |
2839 | | UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, |
2840 | | SourceLocation L, |
2841 | | SourceLocation NamespaceLoc, |
2842 | | NestedNameSpecifierLoc QualifierLoc, |
2843 | | SourceLocation IdentLoc, |
2844 | | NamedDecl *Used, |
2845 | 5.12k | DeclContext *CommonAncestor) { |
2846 | 5.12k | if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Used)) |
2847 | 5.07k | Used = NS->getOriginalNamespace(); |
2848 | 5.12k | return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc, |
2849 | 5.12k | IdentLoc, Used, CommonAncestor); |
2850 | 5.12k | } |
2851 | | |
2852 | | UsingDirectiveDecl *UsingDirectiveDecl::CreateDeserialized(ASTContext &C, |
2853 | 1.06k | unsigned ID) { |
2854 | 1.06k | return new (C, ID) UsingDirectiveDecl(nullptr, SourceLocation(), |
2855 | 1.06k | SourceLocation(), |
2856 | 1.06k | NestedNameSpecifierLoc(), |
2857 | 1.06k | SourceLocation(), nullptr, nullptr); |
2858 | 1.06k | } |
2859 | | |
2860 | 44.9M | NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { |
2861 | 44.9M | if (auto *NA = dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace)) |
2862 | 3.91k | return NA->getNamespace(); |
2863 | 44.9M | return cast_or_null<NamespaceDecl>(NominatedNamespace); |
2864 | 44.9M | } |
2865 | | |
2866 | | NamespaceDecl::NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline, |
2867 | | SourceLocation StartLoc, SourceLocation IdLoc, |
2868 | | IdentifierInfo *Id, NamespaceDecl *PrevDecl) |
2869 | | : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace), |
2870 | | redeclarable_base(C), LocStart(StartLoc), |
2871 | 1.64M | AnonOrFirstNamespaceAndInline(nullptr, Inline) { |
2872 | 1.64M | setPreviousDecl(PrevDecl); |
2873 | | |
2874 | 1.64M | if (PrevDecl) |
2875 | 395k | AnonOrFirstNamespaceAndInline.setPointer(PrevDecl->getOriginalNamespace()); |
2876 | 1.64M | } |
2877 | | |
2878 | | NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, |
2879 | | bool Inline, SourceLocation StartLoc, |
2880 | | SourceLocation IdLoc, IdentifierInfo *Id, |
2881 | 445k | NamespaceDecl *PrevDecl) { |
2882 | 445k | return new (C, DC) NamespaceDecl(C, DC, Inline, StartLoc, IdLoc, Id, |
2883 | 445k | PrevDecl); |
2884 | 445k | } |
2885 | | |
2886 | 1.20M | NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
2887 | 1.20M | return new (C, ID) NamespaceDecl(C, nullptr, false, SourceLocation(), |
2888 | 1.20M | SourceLocation(), nullptr, nullptr); |
2889 | 1.20M | } |
2890 | | |
2891 | 413M | NamespaceDecl *NamespaceDecl::getOriginalNamespace() { |
2892 | 413M | if (isFirstDecl()) |
2893 | 128M | return this; |
2894 | | |
2895 | 284M | return AnonOrFirstNamespaceAndInline.getPointer(); |
2896 | 413M | } |
2897 | | |
2898 | 1.21M | const NamespaceDecl *NamespaceDecl::getOriginalNamespace() const { |
2899 | 1.21M | if (isFirstDecl()) |
2900 | 125k | return this; |
2901 | | |
2902 | 1.08M | return AnonOrFirstNamespaceAndInline.getPointer(); |
2903 | 1.21M | } |
2904 | | |
2905 | 15.7k | bool NamespaceDecl::isOriginalNamespace() const { return isFirstDecl(); } |
2906 | | |
2907 | 47.2M | NamespaceDecl *NamespaceDecl::getNextRedeclarationImpl() { |
2908 | 47.2M | return getNextRedeclaration(); |
2909 | 47.2M | } |
2910 | | |
2911 | 479k | NamespaceDecl *NamespaceDecl::getPreviousDeclImpl() { |
2912 | 479k | return getPreviousDecl(); |
2913 | 479k | } |
2914 | | |
2915 | 8.27M | NamespaceDecl *NamespaceDecl::getMostRecentDeclImpl() { |
2916 | 8.27M | return getMostRecentDecl(); |
2917 | 8.27M | } |
2918 | | |
2919 | 0 | void NamespaceAliasDecl::anchor() {} |
2920 | | |
2921 | 89 | NamespaceAliasDecl *NamespaceAliasDecl::getNextRedeclarationImpl() { |
2922 | 89 | return getNextRedeclaration(); |
2923 | 89 | } |
2924 | | |
2925 | 351 | NamespaceAliasDecl *NamespaceAliasDecl::getPreviousDeclImpl() { |
2926 | 351 | return getPreviousDecl(); |
2927 | 351 | } |
2928 | | |
2929 | 121 | NamespaceAliasDecl *NamespaceAliasDecl::getMostRecentDeclImpl() { |
2930 | 121 | return getMostRecentDecl(); |
2931 | 121 | } |
2932 | | |
2933 | | NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, |
2934 | | SourceLocation UsingLoc, |
2935 | | SourceLocation AliasLoc, |
2936 | | IdentifierInfo *Alias, |
2937 | | NestedNameSpecifierLoc QualifierLoc, |
2938 | | SourceLocation IdentLoc, |
2939 | 356 | NamedDecl *Namespace) { |
2940 | | // FIXME: Preserve the aliased namespace as written. |
2941 | 356 | if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Namespace)) |
2942 | 339 | Namespace = NS->getOriginalNamespace(); |
2943 | 356 | return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias, |
2944 | 356 | QualifierLoc, IdentLoc, Namespace); |
2945 | 356 | } |
2946 | | |
2947 | | NamespaceAliasDecl * |
2948 | 20 | NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
2949 | 20 | return new (C, ID) NamespaceAliasDecl(C, nullptr, SourceLocation(), |
2950 | 20 | SourceLocation(), nullptr, |
2951 | 20 | NestedNameSpecifierLoc(), |
2952 | 20 | SourceLocation(), nullptr); |
2953 | 20 | } |
2954 | | |
2955 | 0 | void LifetimeExtendedTemporaryDecl::anchor() {} |
2956 | | |
2957 | | /// Retrieve the storage duration for the materialized temporary. |
2958 | 11.9k | StorageDuration LifetimeExtendedTemporaryDecl::getStorageDuration() const { |
2959 | 11.9k | const ValueDecl *ExtendingDecl = getExtendingDecl(); |
2960 | 11.9k | if (!ExtendingDecl) |
2961 | 0 | return SD_FullExpression; |
2962 | | // FIXME: This is not necessarily correct for a temporary materialized |
2963 | | // within a default initializer. |
2964 | 11.9k | if (isa<FieldDecl>(ExtendingDecl)) |
2965 | 83 | return SD_Automatic; |
2966 | | // FIXME: This only works because storage class specifiers are not allowed |
2967 | | // on decomposition declarations. |
2968 | 11.8k | if (isa<BindingDecl>(ExtendingDecl)) |
2969 | 0 | return ExtendingDecl->getDeclContext()->isFunctionOrMethod() ? SD_Automatic |
2970 | 0 | : SD_Static; |
2971 | 11.8k | return cast<VarDecl>(ExtendingDecl)->getStorageDuration(); |
2972 | 11.8k | } |
2973 | | |
2974 | 1.84k | APValue *LifetimeExtendedTemporaryDecl::getOrCreateValue(bool MayCreate) const { |
2975 | 1.84k | assert(getStorageDuration() == SD_Static && |
2976 | 1.84k | "don't need to cache the computed value for this temporary"); |
2977 | 1.84k | if (MayCreate && !Value908 ) { |
2978 | 786 | Value = (new (getASTContext()) APValue); |
2979 | 786 | getASTContext().addDestruction(Value); |
2980 | 786 | } |
2981 | 1.84k | assert(Value && "may not be null"); |
2982 | 0 | return Value; |
2983 | 1.84k | } |
2984 | | |
2985 | 0 | void UsingShadowDecl::anchor() {} |
2986 | | |
2987 | | UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, |
2988 | | SourceLocation Loc, DeclarationName Name, |
2989 | | BaseUsingDecl *Introducer, NamedDecl *Target) |
2990 | | : NamedDecl(K, DC, Loc, Name), redeclarable_base(C), |
2991 | 403k | UsingOrNextShadow(Introducer) { |
2992 | 403k | if (Target) { |
2993 | 403k | assert(!isa<UsingShadowDecl>(Target)); |
2994 | 0 | setTargetDecl(Target); |
2995 | 403k | } |
2996 | 0 | setImplicit(); |
2997 | 403k | } |
2998 | | |
2999 | | UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, EmptyShell Empty) |
3000 | | : NamedDecl(K, nullptr, SourceLocation(), DeclarationName()), |
3001 | 50.0k | redeclarable_base(C) {} |
3002 | | |
3003 | | UsingShadowDecl * |
3004 | 49.9k | UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3005 | 49.9k | return new (C, ID) UsingShadowDecl(UsingShadow, C, EmptyShell()); |
3006 | 49.9k | } |
3007 | | |
3008 | 452k | BaseUsingDecl *UsingShadowDecl::getIntroducer() const { |
3009 | 452k | const UsingShadowDecl *Shadow = this; |
3010 | 1.08M | while (const auto *NextShadow = |
3011 | 452k | dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow)) |
3012 | 636k | Shadow = NextShadow; |
3013 | 452k | return cast<BaseUsingDecl>(Shadow->UsingOrNextShadow); |
3014 | 452k | } |
3015 | | |
3016 | 0 | void ConstructorUsingShadowDecl::anchor() {} |
3017 | | |
3018 | | ConstructorUsingShadowDecl * |
3019 | | ConstructorUsingShadowDecl::Create(ASTContext &C, DeclContext *DC, |
3020 | | SourceLocation Loc, UsingDecl *Using, |
3021 | 2.60k | NamedDecl *Target, bool IsVirtual) { |
3022 | 2.60k | return new (C, DC) ConstructorUsingShadowDecl(C, DC, Loc, Using, Target, |
3023 | 2.60k | IsVirtual); |
3024 | 2.60k | } |
3025 | | |
3026 | | ConstructorUsingShadowDecl * |
3027 | 75 | ConstructorUsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3028 | 75 | return new (C, ID) ConstructorUsingShadowDecl(C, EmptyShell()); |
3029 | 75 | } |
3030 | | |
3031 | 1.10k | CXXRecordDecl *ConstructorUsingShadowDecl::getNominatedBaseClass() const { |
3032 | 1.10k | return getIntroducer()->getQualifier()->getAsRecordDecl(); |
3033 | 1.10k | } |
3034 | | |
3035 | 0 | void BaseUsingDecl::anchor() {} |
3036 | | |
3037 | 403k | void BaseUsingDecl::addShadowDecl(UsingShadowDecl *S) { |
3038 | 403k | assert(!llvm::is_contained(shadows(), S) && "declaration already in set"); |
3039 | 0 | assert(S->getIntroducer() == this); |
3040 | | |
3041 | 403k | if (FirstUsingShadow.getPointer()) |
3042 | 170k | S->UsingOrNextShadow = FirstUsingShadow.getPointer(); |
3043 | 403k | FirstUsingShadow.setPointer(S); |
3044 | 403k | } |
3045 | | |
3046 | 303 | void BaseUsingDecl::removeShadowDecl(UsingShadowDecl *S) { |
3047 | 303 | assert(llvm::is_contained(shadows(), S) && "declaration not in set"); |
3048 | 0 | assert(S->getIntroducer() == this); |
3049 | | |
3050 | | // Remove S from the shadow decl chain. This is O(n) but hopefully rare. |
3051 | | |
3052 | 303 | if (FirstUsingShadow.getPointer() == S) { |
3053 | 58 | FirstUsingShadow.setPointer( |
3054 | 58 | dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow)); |
3055 | 58 | S->UsingOrNextShadow = this; |
3056 | 58 | return; |
3057 | 58 | } |
3058 | | |
3059 | 245 | UsingShadowDecl *Prev = FirstUsingShadow.getPointer(); |
3060 | 548 | while (Prev->UsingOrNextShadow != S) |
3061 | 303 | Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow); |
3062 | 245 | Prev->UsingOrNextShadow = S->UsingOrNextShadow; |
3063 | 245 | S->UsingOrNextShadow = this; |
3064 | 245 | } |
3065 | | |
3066 | 0 | void UsingDecl::anchor() {} |
3067 | | |
3068 | | UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL, |
3069 | | NestedNameSpecifierLoc QualifierLoc, |
3070 | | const DeclarationNameInfo &NameInfo, |
3071 | 232k | bool HasTypename) { |
3072 | 232k | return new (C, DC) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename); |
3073 | 232k | } |
3074 | | |
3075 | 13.9k | UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3076 | 13.9k | return new (C, ID) UsingDecl(nullptr, SourceLocation(), |
3077 | 13.9k | NestedNameSpecifierLoc(), DeclarationNameInfo(), |
3078 | 13.9k | false); |
3079 | 13.9k | } |
3080 | | |
3081 | 144 | SourceRange UsingDecl::getSourceRange() const { |
3082 | 144 | SourceLocation Begin = isAccessDeclaration() |
3083 | 144 | ? getQualifierLoc().getBeginLoc()1 : UsingLocation143 ; |
3084 | 144 | return SourceRange(Begin, getNameInfo().getEndLoc()); |
3085 | 144 | } |
3086 | | |
3087 | 0 | void UsingEnumDecl::anchor() {} |
3088 | | |
3089 | | UsingEnumDecl *UsingEnumDecl::Create(ASTContext &C, DeclContext *DC, |
3090 | | SourceLocation UL, SourceLocation EL, |
3091 | 54 | SourceLocation NL, EnumDecl *Enum) { |
3092 | 54 | return new (C, DC) UsingEnumDecl(DC, Enum->getDeclName(), UL, EL, NL, Enum); |
3093 | 54 | } |
3094 | | |
3095 | 1 | UsingEnumDecl *UsingEnumDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3096 | 1 | return new (C, ID) UsingEnumDecl(nullptr, DeclarationName(), SourceLocation(), |
3097 | 1 | SourceLocation(), SourceLocation(), nullptr); |
3098 | 1 | } |
3099 | | |
3100 | 10 | SourceRange UsingEnumDecl::getSourceRange() const { |
3101 | 10 | return SourceRange(EnumLocation, getLocation()); |
3102 | 10 | } |
3103 | | |
3104 | 0 | void UsingPackDecl::anchor() {} |
3105 | | |
3106 | | UsingPackDecl *UsingPackDecl::Create(ASTContext &C, DeclContext *DC, |
3107 | | NamedDecl *InstantiatedFrom, |
3108 | 82 | ArrayRef<NamedDecl *> UsingDecls) { |
3109 | 82 | size_t Extra = additionalSizeToAlloc<NamedDecl *>(UsingDecls.size()); |
3110 | 82 | return new (C, DC, Extra) UsingPackDecl(DC, InstantiatedFrom, UsingDecls); |
3111 | 82 | } |
3112 | | |
3113 | | UsingPackDecl *UsingPackDecl::CreateDeserialized(ASTContext &C, unsigned ID, |
3114 | 6 | unsigned NumExpansions) { |
3115 | 6 | size_t Extra = additionalSizeToAlloc<NamedDecl *>(NumExpansions); |
3116 | 6 | auto *Result = new (C, ID, Extra) UsingPackDecl(nullptr, nullptr, None); |
3117 | 6 | Result->NumExpansions = NumExpansions; |
3118 | 6 | auto *Trail = Result->getTrailingObjects<NamedDecl *>(); |
3119 | 20 | for (unsigned I = 0; I != NumExpansions; ++I14 ) |
3120 | 14 | new (Trail + I) NamedDecl*(nullptr); |
3121 | 6 | return Result; |
3122 | 6 | } |
3123 | | |
3124 | 0 | void UnresolvedUsingValueDecl::anchor() {} |
3125 | | |
3126 | | UnresolvedUsingValueDecl * |
3127 | | UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC, |
3128 | | SourceLocation UsingLoc, |
3129 | | NestedNameSpecifierLoc QualifierLoc, |
3130 | | const DeclarationNameInfo &NameInfo, |
3131 | 1.44k | SourceLocation EllipsisLoc) { |
3132 | 1.44k | return new (C, DC) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc, |
3133 | 1.44k | QualifierLoc, NameInfo, |
3134 | 1.44k | EllipsisLoc); |
3135 | 1.44k | } |
3136 | | |
3137 | | UnresolvedUsingValueDecl * |
3138 | 86 | UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3139 | 86 | return new (C, ID) UnresolvedUsingValueDecl(nullptr, QualType(), |
3140 | 86 | SourceLocation(), |
3141 | 86 | NestedNameSpecifierLoc(), |
3142 | 86 | DeclarationNameInfo(), |
3143 | 86 | SourceLocation()); |
3144 | 86 | } |
3145 | | |
3146 | 103 | SourceRange UnresolvedUsingValueDecl::getSourceRange() const { |
3147 | 103 | SourceLocation Begin = isAccessDeclaration() |
3148 | 103 | ? getQualifierLoc().getBeginLoc()1 : UsingLocation102 ; |
3149 | 103 | return SourceRange(Begin, getNameInfo().getEndLoc()); |
3150 | 103 | } |
3151 | | |
3152 | 0 | void UnresolvedUsingTypenameDecl::anchor() {} |
3153 | | |
3154 | | UnresolvedUsingTypenameDecl * |
3155 | | UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC, |
3156 | | SourceLocation UsingLoc, |
3157 | | SourceLocation TypenameLoc, |
3158 | | NestedNameSpecifierLoc QualifierLoc, |
3159 | | SourceLocation TargetNameLoc, |
3160 | | DeclarationName TargetName, |
3161 | 543 | SourceLocation EllipsisLoc) { |
3162 | 543 | return new (C, DC) UnresolvedUsingTypenameDecl( |
3163 | 543 | DC, UsingLoc, TypenameLoc, QualifierLoc, TargetNameLoc, |
3164 | 543 | TargetName.getAsIdentifierInfo(), EllipsisLoc); |
3165 | 543 | } |
3166 | | |
3167 | | UnresolvedUsingTypenameDecl * |
3168 | 705 | UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3169 | 705 | return new (C, ID) UnresolvedUsingTypenameDecl( |
3170 | 705 | nullptr, SourceLocation(), SourceLocation(), NestedNameSpecifierLoc(), |
3171 | 705 | SourceLocation(), nullptr, SourceLocation()); |
3172 | 705 | } |
3173 | | |
3174 | | UnresolvedUsingIfExistsDecl * |
3175 | | UnresolvedUsingIfExistsDecl::Create(ASTContext &Ctx, DeclContext *DC, |
3176 | 1.54k | SourceLocation Loc, DeclarationName Name) { |
3177 | 1.54k | return new (Ctx, DC) UnresolvedUsingIfExistsDecl(DC, Loc, Name); |
3178 | 1.54k | } |
3179 | | |
3180 | | UnresolvedUsingIfExistsDecl * |
3181 | 0 | UnresolvedUsingIfExistsDecl::CreateDeserialized(ASTContext &Ctx, unsigned ID) { |
3182 | 0 | return new (Ctx, ID) |
3183 | 0 | UnresolvedUsingIfExistsDecl(nullptr, SourceLocation(), DeclarationName()); |
3184 | 0 | } |
3185 | | |
3186 | | UnresolvedUsingIfExistsDecl::UnresolvedUsingIfExistsDecl(DeclContext *DC, |
3187 | | SourceLocation Loc, |
3188 | | DeclarationName Name) |
3189 | 1.54k | : NamedDecl(Decl::UnresolvedUsingIfExists, DC, Loc, Name) {} |
3190 | | |
3191 | 0 | void UnresolvedUsingIfExistsDecl::anchor() {} |
3192 | | |
3193 | 0 | void StaticAssertDecl::anchor() {} |
3194 | | |
3195 | | StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, |
3196 | | SourceLocation StaticAssertLoc, |
3197 | | Expr *AssertExpr, |
3198 | | StringLiteral *Message, |
3199 | | SourceLocation RParenLoc, |
3200 | 139k | bool Failed) { |
3201 | 139k | return new (C, DC) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message, |
3202 | 139k | RParenLoc, Failed); |
3203 | 139k | } |
3204 | | |
3205 | | StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C, |
3206 | 22.1k | unsigned ID) { |
3207 | 22.1k | return new (C, ID) StaticAssertDecl(nullptr, SourceLocation(), nullptr, |
3208 | 22.1k | nullptr, SourceLocation(), false); |
3209 | 22.1k | } |
3210 | | |
3211 | 0 | void BindingDecl::anchor() {} |
3212 | | |
3213 | | BindingDecl *BindingDecl::Create(ASTContext &C, DeclContext *DC, |
3214 | 1.04k | SourceLocation IdLoc, IdentifierInfo *Id) { |
3215 | 1.04k | return new (C, DC) BindingDecl(DC, IdLoc, Id); |
3216 | 1.04k | } |
3217 | | |
3218 | 12 | BindingDecl *BindingDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3219 | 12 | return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr); |
3220 | 12 | } |
3221 | | |
3222 | 1.21k | VarDecl *BindingDecl::getHoldingVar() const { |
3223 | 1.21k | Expr *B = getBinding(); |
3224 | 1.21k | if (!B) |
3225 | 16 | return nullptr; |
3226 | 1.19k | auto *DRE = dyn_cast<DeclRefExpr>(B->IgnoreImplicit()); |
3227 | 1.19k | if (!DRE) |
3228 | 1.15k | return nullptr; |
3229 | | |
3230 | 46 | auto *VD = cast<VarDecl>(DRE->getDecl()); |
3231 | 46 | assert(VD->isImplicit() && "holding var for binding decl not implicit"); |
3232 | 0 | return VD; |
3233 | 1.19k | } |
3234 | | |
3235 | 0 | void DecompositionDecl::anchor() {} |
3236 | | |
3237 | | DecompositionDecl *DecompositionDecl::Create(ASTContext &C, DeclContext *DC, |
3238 | | SourceLocation StartLoc, |
3239 | | SourceLocation LSquareLoc, |
3240 | | QualType T, TypeSourceInfo *TInfo, |
3241 | | StorageClass SC, |
3242 | 518 | ArrayRef<BindingDecl *> Bindings) { |
3243 | 518 | size_t Extra = additionalSizeToAlloc<BindingDecl *>(Bindings.size()); |
3244 | 518 | return new (C, DC, Extra) |
3245 | 518 | DecompositionDecl(C, DC, StartLoc, LSquareLoc, T, TInfo, SC, Bindings); |
3246 | 518 | } |
3247 | | |
3248 | | DecompositionDecl *DecompositionDecl::CreateDeserialized(ASTContext &C, |
3249 | | unsigned ID, |
3250 | 7 | unsigned NumBindings) { |
3251 | 7 | size_t Extra = additionalSizeToAlloc<BindingDecl *>(NumBindings); |
3252 | 7 | auto *Result = new (C, ID, Extra) |
3253 | 7 | DecompositionDecl(C, nullptr, SourceLocation(), SourceLocation(), |
3254 | 7 | QualType(), nullptr, StorageClass(), None); |
3255 | | // Set up and clean out the bindings array. |
3256 | 7 | Result->NumBindings = NumBindings; |
3257 | 7 | auto *Trail = Result->getTrailingObjects<BindingDecl *>(); |
3258 | 19 | for (unsigned I = 0; I != NumBindings; ++I12 ) |
3259 | 12 | new (Trail + I) BindingDecl*(nullptr); |
3260 | 7 | return Result; |
3261 | 7 | } |
3262 | | |
3263 | 63 | void DecompositionDecl::printName(llvm::raw_ostream &os) const { |
3264 | 63 | os << '['; |
3265 | 63 | bool Comma = false; |
3266 | 115 | for (const auto *B : bindings()) { |
3267 | 115 | if (Comma) |
3268 | 52 | os << ", "; |
3269 | 115 | B->printName(os); |
3270 | 115 | Comma = true; |
3271 | 115 | } |
3272 | 63 | os << ']'; |
3273 | 63 | } |
3274 | | |
3275 | 0 | void MSPropertyDecl::anchor() {} |
3276 | | |
3277 | | MSPropertyDecl *MSPropertyDecl::Create(ASTContext &C, DeclContext *DC, |
3278 | | SourceLocation L, DeclarationName N, |
3279 | | QualType T, TypeSourceInfo *TInfo, |
3280 | | SourceLocation StartL, |
3281 | | IdentifierInfo *Getter, |
3282 | 125 | IdentifierInfo *Setter) { |
3283 | 125 | return new (C, DC) MSPropertyDecl(DC, L, N, T, TInfo, StartL, Getter, Setter); |
3284 | 125 | } |
3285 | | |
3286 | | MSPropertyDecl *MSPropertyDecl::CreateDeserialized(ASTContext &C, |
3287 | 11 | unsigned ID) { |
3288 | 11 | return new (C, ID) MSPropertyDecl(nullptr, SourceLocation(), |
3289 | 11 | DeclarationName(), QualType(), nullptr, |
3290 | 11 | SourceLocation(), nullptr, nullptr); |
3291 | 11 | } |
3292 | | |
3293 | 0 | void MSGuidDecl::anchor() {} |
3294 | | |
3295 | | MSGuidDecl::MSGuidDecl(DeclContext *DC, QualType T, Parts P) |
3296 | | : ValueDecl(Decl::MSGuid, DC, SourceLocation(), DeclarationName(), T), |
3297 | 68 | PartVal(P) {} |
3298 | | |
3299 | 67 | MSGuidDecl *MSGuidDecl::Create(const ASTContext &C, QualType T, Parts P) { |
3300 | 67 | DeclContext *DC = C.getTranslationUnitDecl(); |
3301 | 67 | return new (C, DC) MSGuidDecl(DC, T, P); |
3302 | 67 | } |
3303 | | |
3304 | 1 | MSGuidDecl *MSGuidDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3305 | 1 | return new (C, ID) MSGuidDecl(nullptr, QualType(), Parts()); |
3306 | 1 | } |
3307 | | |
3308 | 6 | void MSGuidDecl::printName(llvm::raw_ostream &OS) const { |
3309 | 6 | OS << llvm::format("GUID{%08" PRIx32 "-%04" PRIx16 "-%04" PRIx16 "-", |
3310 | 6 | PartVal.Part1, PartVal.Part2, PartVal.Part3); |
3311 | 6 | unsigned I = 0; |
3312 | 48 | for (uint8_t Byte : PartVal.Part4And5) { |
3313 | 48 | OS << llvm::format("%02" PRIx8, Byte); |
3314 | 48 | if (++I == 2) |
3315 | 6 | OS << '-'; |
3316 | 48 | } |
3317 | 6 | OS << '}'; |
3318 | 6 | } |
3319 | | |
3320 | | /// Determine if T is a valid 'struct _GUID' of the shape that we expect. |
3321 | 49 | static bool isValidStructGUID(ASTContext &Ctx, QualType T) { |
3322 | | // FIXME: We only need to check this once, not once each time we compute a |
3323 | | // GUID APValue. |
3324 | 49 | using MatcherRef = llvm::function_ref<bool(QualType)>; |
3325 | | |
3326 | 196 | auto IsInt = [&Ctx](unsigned N) { |
3327 | 196 | return [&Ctx, N](QualType T) { |
3328 | 93 | return T->isUnsignedIntegerOrEnumerationType() && |
3329 | 93 | Ctx.getIntWidth(T) == N; |
3330 | 93 | }; |
3331 | 196 | }; |
3332 | | |
3333 | 49 | auto IsArray = [&Ctx](MatcherRef Elem, unsigned N) { |
3334 | 49 | return [&Ctx, Elem, N](QualType T) { |
3335 | 19 | const ConstantArrayType *CAT = Ctx.getAsConstantArrayType(T); |
3336 | 19 | return CAT && CAT->getSize() == N && Elem(CAT->getElementType()); |
3337 | 19 | }; |
3338 | 49 | }; |
3339 | | |
3340 | 49 | auto IsStruct = [](std::initializer_list<MatcherRef> Fields) { |
3341 | 49 | return [Fields](QualType T) { |
3342 | 49 | const RecordDecl *RD = T->getAsRecordDecl(); |
3343 | 49 | if (!RD || RD->isUnion()) |
3344 | 0 | return false; |
3345 | 49 | RD = RD->getDefinition(); |
3346 | 49 | if (!RD) |
3347 | 13 | return false; |
3348 | 36 | if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) |
3349 | 36 | if (CXXRD->getNumBases()) |
3350 | 0 | return false; |
3351 | 36 | auto MatcherIt = Fields.begin(); |
3352 | 93 | for (const FieldDecl *FD : RD->fields()) { |
3353 | 93 | if (FD->isUnnamedBitfield()) continue0 ; |
3354 | 93 | if (FD->isBitField() || MatcherIt == Fields.end() || |
3355 | 93 | !(*MatcherIt)(FD->getType())) |
3356 | 0 | return false; |
3357 | 93 | ++MatcherIt; |
3358 | 93 | } |
3359 | 36 | return MatcherIt == Fields.end(); |
3360 | 36 | }; |
3361 | 49 | }; |
3362 | | |
3363 | | // We expect an {i32, i16, i16, [8 x i8]}. |
3364 | 49 | return IsStruct({IsInt(32), IsInt(16), IsInt(16), IsArray(IsInt(8), 8)})(T); |
3365 | 49 | } |
3366 | | |
3367 | 135 | APValue &MSGuidDecl::getAsAPValue() const { |
3368 | 135 | if (APVal.isAbsent() && isValidStructGUID(getASTContext(), getType())49 ) { |
3369 | 19 | using llvm::APInt; |
3370 | 19 | using llvm::APSInt; |
3371 | 19 | APVal = APValue(APValue::UninitStruct(), 0, 4); |
3372 | 19 | APVal.getStructField(0) = APValue(APSInt(APInt(32, PartVal.Part1), true)); |
3373 | 19 | APVal.getStructField(1) = APValue(APSInt(APInt(16, PartVal.Part2), true)); |
3374 | 19 | APVal.getStructField(2) = APValue(APSInt(APInt(16, PartVal.Part3), true)); |
3375 | 19 | APValue &Arr = APVal.getStructField(3) = |
3376 | 19 | APValue(APValue::UninitArray(), 8, 8); |
3377 | 171 | for (unsigned I = 0; I != 8; ++I152 ) { |
3378 | 152 | Arr.getArrayInitializedElt(I) = |
3379 | 152 | APValue(APSInt(APInt(8, PartVal.Part4And5[I]), true)); |
3380 | 152 | } |
3381 | | // Register this APValue to be destroyed if necessary. (Note that the |
3382 | | // MSGuidDecl destructor is never run.) |
3383 | 19 | getASTContext().addDestruction(&APVal); |
3384 | 19 | } |
3385 | | |
3386 | 135 | return APVal; |
3387 | 135 | } |
3388 | | |
3389 | 0 | void UnnamedGlobalConstantDecl::anchor() {} |
3390 | | |
3391 | | UnnamedGlobalConstantDecl::UnnamedGlobalConstantDecl(const ASTContext &C, |
3392 | | DeclContext *DC, |
3393 | | QualType Ty, |
3394 | | const APValue &Val) |
3395 | | : ValueDecl(Decl::UnnamedGlobalConstant, DC, SourceLocation(), |
3396 | | DeclarationName(), Ty), |
3397 | 83 | Value(Val) { |
3398 | | // Cleanup the embedded APValue if required (note that our destructor is never |
3399 | | // run) |
3400 | 83 | if (Value.needsCleanup()) |
3401 | 83 | C.addDestruction(&Value); |
3402 | 83 | } |
3403 | | |
3404 | | UnnamedGlobalConstantDecl * |
3405 | | UnnamedGlobalConstantDecl::Create(const ASTContext &C, QualType T, |
3406 | 83 | const APValue &Value) { |
3407 | 83 | DeclContext *DC = C.getTranslationUnitDecl(); |
3408 | 83 | return new (C, DC) UnnamedGlobalConstantDecl(C, DC, T, Value); |
3409 | 83 | } |
3410 | | |
3411 | | UnnamedGlobalConstantDecl * |
3412 | 0 | UnnamedGlobalConstantDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3413 | 0 | return new (C, ID) |
3414 | 0 | UnnamedGlobalConstantDecl(C, nullptr, QualType(), APValue()); |
3415 | 0 | } |
3416 | | |
3417 | 0 | void UnnamedGlobalConstantDecl::printName(llvm::raw_ostream &OS) const { |
3418 | 0 | OS << "unnamed-global-constant"; |
3419 | 0 | } |
3420 | | |
3421 | 24 | static const char *getAccessName(AccessSpecifier AS) { |
3422 | 24 | switch (AS) { |
3423 | 0 | case AS_none: |
3424 | 0 | llvm_unreachable("Invalid access specifier!"); |
3425 | 10 | case AS_public: |
3426 | 10 | return "public"; |
3427 | 8 | case AS_private: |
3428 | 8 | return "private"; |
3429 | 6 | case AS_protected: |
3430 | 6 | return "protected"; |
3431 | 24 | } |
3432 | 0 | llvm_unreachable("Invalid access specifier!"); |
3433 | 0 | } |
3434 | | |
3435 | | const StreamingDiagnostic &clang::operator<<(const StreamingDiagnostic &DB, |
3436 | 24 | AccessSpecifier AS) { |
3437 | 24 | return DB << getAccessName(AS); |
3438 | 24 | } |