Coverage Report

Created: 2020-09-15 12:33

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