Coverage Report

Created: 2021-08-24 07:12

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