Coverage Report

Created: 2022-01-18 06:27

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