Coverage Report

Created: 2019-07-24 05:18

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