Coverage Report

Created: 2020-02-18 08:44

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