Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/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
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file implements the C++ related Decl classes.
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/CXXInheritance.h"
18
#include "clang/AST/DeclTemplate.h"
19
#include "clang/AST/Expr.h"
20
#include "clang/AST/ExprCXX.h"
21
#include "clang/AST/ODRHash.h"
22
#include "clang/AST/TypeLoc.h"
23
#include "clang/Basic/IdentifierTable.h"
24
#include "llvm/ADT/STLExtras.h"
25
#include "llvm/ADT/SmallPtrSet.h"
26
using namespace clang;
27
28
//===----------------------------------------------------------------------===//
29
// Decl Allocation/Deallocation Method Implementations
30
//===----------------------------------------------------------------------===//
31
32
0
void AccessSpecDecl::anchor() { }
33
34
273
AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
35
273
  return new (C, ID) AccessSpecDecl(EmptyShell());
36
273
}
37
38
15
void LazyASTUnresolvedSet::getFromExternalSource(ASTContext &C) const {
39
15
  ExternalASTSource *Source = C.getExternalSource();
40
15
  assert(Impl.Decls.isLazy() && "getFromExternalSource for non-lazy set");
41
15
  assert(Source && "getFromExternalSource with no external source");
42
15
43
41
  for (ASTUnresolvedSet::iterator I = Impl.begin(); 
I != Impl.end()41
;
++I26
)
44
26
    I.setDecl(cast<NamedDecl>(Source->GetExternalDecl(
45
26
        reinterpret_cast<uintptr_t>(I.getDecl()) >> 2)));
46
15
  Impl.Decls.setLazy(false);
47
15
}
48
49
CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D)
50
    : UserDeclaredConstructor(false), UserDeclaredSpecialMembers(0),
51
      Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false),
52
      Abstract(false), IsStandardLayout(true), HasNoNonEmptyBases(true),
53
      HasPrivateFields(false), HasProtectedFields(false),
54
      HasPublicFields(false), HasMutableFields(false), HasVariantMembers(false),
55
      HasOnlyCMembers(true), HasInClassInitializer(false),
56
      HasUninitializedReferenceMember(false), HasUninitializedFields(false),
57
      HasInheritedConstructor(false), HasInheritedAssignment(false),
58
      NeedOverloadResolutionForCopyConstructor(false),
59
      NeedOverloadResolutionForMoveConstructor(false),
60
      NeedOverloadResolutionForMoveAssignment(false),
61
      NeedOverloadResolutionForDestructor(false),
62
      DefaultedCopyConstructorIsDeleted(false),
63
      DefaultedMoveConstructorIsDeleted(false),
64
      DefaultedMoveAssignmentIsDeleted(false),
65
      DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
66
      DeclaredNonTrivialSpecialMembers(0), HasIrrelevantDestructor(true),
67
      HasConstexprNonCopyMoveConstructor(false),
68
      HasDefaultedDefaultConstructor(false),
69
      CanPassInRegisters(true),
70
      DefaultedDefaultConstructorIsConstexpr(true),
71
      HasConstexprDefaultConstructor(false),
72
      HasNonLiteralTypeFieldsOrBases(false), ComputedVisibleConversions(false),
73
      UserProvidedDefaultConstructor(false), DeclaredSpecialMembers(0),
74
      ImplicitCopyConstructorCanHaveConstParamForVBase(true),
75
      ImplicitCopyConstructorCanHaveConstParamForNonVBase(true),
76
      ImplicitCopyAssignmentHasConstParam(true),
77
      HasDeclaredCopyConstructorWithConstParam(false),
78
      HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false),
79
      IsParsingBaseSpecifiers(false), HasODRHash(false), ODRHash(0),
80
      NumBases(0), NumVBases(0), Bases(), VBases(), Definition(D),
81
359k
      FirstFriend() {}
82
83
230
CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const {
84
230
  return Bases.get(Definition->getASTContext().getExternalSource());
85
230
}
86
87
4
CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getVBasesSlowCase() const {
88
4
  return VBases.get(Definition->getASTContext().getExternalSource());
89
4
}
90
91
CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C,
92
                             DeclContext *DC, SourceLocation StartLoc,
93
                             SourceLocation IdLoc, IdentifierInfo *Id,
94
                             CXXRecordDecl *PrevDecl)
95
    : RecordDecl(K, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl),
96
      DefinitionData(PrevDecl ? PrevDecl->DefinitionData
97
                              : nullptr),
98
615k
      TemplateOrInstantiation() {}
99
100
CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK,
101
                                     DeclContext *DC, SourceLocation StartLoc,
102
                                     SourceLocation IdLoc, IdentifierInfo *Id,
103
                                     CXXRecordDecl* PrevDecl,
104
559k
                                     bool DelayTypeCreation) {
105
559k
  CXXRecordDecl *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc,
106
559k
                                               IdLoc, Id, PrevDecl);
107
559k
  R->MayHaveOutOfDateDef = C.getLangOpts().Modules;
108
559k
109
559k
  // FIXME: DelayTypeCreation seems like such a hack
110
559k
  if (!DelayTypeCreation)
111
352k
    C.getTypeDeclType(R, PrevDecl);
112
559k
  return R;
113
559k
}
114
115
CXXRecordDecl *
116
CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC,
117
                            TypeSourceInfo *Info, SourceLocation Loc,
118
                            bool Dependent, bool IsGeneric,
119
3.97k
                            LambdaCaptureDefault CaptureDefault) {
120
3.97k
  CXXRecordDecl *R =
121
3.97k
      new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc,
122
3.97k
                                nullptr, nullptr);
123
3.97k
  R->IsBeingDefined = true;
124
3.97k
  R->DefinitionData =
125
3.97k
      new (C) struct LambdaDefinitionData(R, Info, Dependent, IsGeneric,
126
3.97k
                                          CaptureDefault);
127
3.97k
  R->MayHaveOutOfDateDef = false;
128
3.97k
  R->setImplicit(true);
129
3.97k
  C.getTypeDeclType(R, /*PrevDecl=*/nullptr);
130
3.97k
  return R;
131
3.97k
}
132
133
CXXRecordDecl *
134
8.11k
CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
135
8.11k
  CXXRecordDecl *R = new (C, ID) CXXRecordDecl(
136
8.11k
      CXXRecord, TTK_Struct, C, nullptr, SourceLocation(), SourceLocation(),
137
8.11k
      nullptr, nullptr);
138
8.11k
  R->MayHaveOutOfDateDef = false;
139
8.11k
  return R;
140
8.11k
}
141
142
void
143
CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases,
144
41.7k
                        unsigned NumBases) {
145
41.7k
  ASTContext &C = getASTContext();
146
41.7k
147
41.7k
  if (
!data().Bases.isOffset() && 41.7k
data().NumBases > 041.7k
)
148
0
    C.Deallocate(data().getBases());
149
41.7k
150
41.7k
  if (
NumBases41.7k
) {
151
41.7k
    if (
!C.getLangOpts().CPlusPlus1z41.7k
) {
152
41.3k
      // C++ [dcl.init.aggr]p1:
153
41.3k
      //   An aggregate is [...] a class with [...] no base classes [...].
154
41.3k
      data().Aggregate = false;
155
41.3k
    }
156
41.7k
157
41.7k
    // C++ [class]p4:
158
41.7k
    //   A POD-struct is an aggregate class...
159
41.7k
    data().PlainOldData = false;
160
41.7k
  }
161
41.7k
162
41.7k
  // The set of seen virtual base types.
163
41.7k
  llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes;
164
41.7k
  
165
41.7k
  // The virtual bases of this class.
166
41.7k
  SmallVector<const CXXBaseSpecifier *, 8> VBases;
167
41.7k
168
41.7k
  data().Bases = new(C) CXXBaseSpecifier [NumBases];
169
41.7k
  data().NumBases = NumBases;
170
87.2k
  for (unsigned i = 0; 
i < NumBases87.2k
;
++i45.5k
) {
171
45.5k
    data().getBases()[i] = *Bases[i];
172
45.5k
    // Keep track of inherited vbases for this base class.
173
45.5k
    const CXXBaseSpecifier *Base = Bases[i];
174
45.5k
    QualType BaseType = Base->getType();
175
45.5k
    // Skip dependent types; we can't do any checking on them now.
176
45.5k
    if (BaseType->isDependentType())
177
2.83k
      continue;
178
42.6k
    CXXRecordDecl *BaseClassDecl
179
42.6k
      = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl());
180
42.6k
181
42.6k
    if (
!BaseClassDecl->isEmpty()42.6k
) {
182
37.8k
      if (
!data().Empty37.8k
) {
183
2.74k
        // C++0x [class]p7:
184
2.74k
        //   A standard-layout class is a class that:
185
2.74k
        //    [...]
186
2.74k
        //    -- either has no non-static data members in the most derived
187
2.74k
        //       class and at most one base class with non-static data members,
188
2.74k
        //       or has no base classes with non-static data members, and
189
2.74k
        // If this is the second non-empty base, then neither of these two
190
2.74k
        // clauses can be true.
191
2.74k
        data().IsStandardLayout = false;
192
2.74k
      }
193
37.8k
194
37.8k
      // C++14 [meta.unary.prop]p4:
195
37.8k
      //   T is a class type [...] with [...] no base class B for which
196
37.8k
      //   is_empty<B>::value is false.
197
37.8k
      data().Empty = false;
198
37.8k
      data().HasNoNonEmptyBases = false;
199
37.8k
    }
200
42.6k
    
201
42.6k
    // C++1z [dcl.init.agg]p1:
202
42.6k
    //   An aggregate is a class with [...] no private or protected base classes
203
42.6k
    if (Base->getAccessSpecifier() != AS_public)
204
888
      data().Aggregate = false;
205
42.6k
206
42.6k
    // C++ [class.virtual]p1:
207
42.6k
    //   A class that declares or inherits a virtual function is called a 
208
42.6k
    //   polymorphic class.
209
42.6k
    if (BaseClassDecl->isPolymorphic())
210
26.0k
      data().Polymorphic = true;
211
42.6k
212
42.6k
    // C++0x [class]p7:
213
42.6k
    //   A standard-layout class is a class that: [...]
214
42.6k
    //    -- has no non-standard-layout base classes
215
42.6k
    if (!BaseClassDecl->isStandardLayout())
216
27.1k
      data().IsStandardLayout = false;
217
42.6k
218
42.6k
    // Record if this base is the first non-literal field or base.
219
42.6k
    if (
!hasNonLiteralTypeFieldsOrBases() && 42.6k
!BaseType->isLiteralType(C)40.0k
)
220
32.3k
      data().HasNonLiteralTypeFieldsOrBases = true;
221
42.6k
    
222
42.6k
    // Now go through all virtual bases of this base and add them.
223
2.41k
    for (const auto &VBase : BaseClassDecl->vbases()) {
224
2.41k
      // Add this base if it's not already in the list.
225
2.41k
      if (
SeenVBaseTypes.insert(C.getCanonicalType(VBase.getType())).second2.41k
) {
226
2.13k
        VBases.push_back(&VBase);
227
2.13k
228
2.13k
        // C++11 [class.copy]p8:
229
2.13k
        //   The implicitly-declared copy constructor for a class X will have
230
2.13k
        //   the form 'X::X(const X&)' if each [...] virtual base class B of X
231
2.13k
        //   has a copy constructor whose first parameter is of type
232
2.13k
        //   'const B&' or 'const volatile B&' [...]
233
2.13k
        if (CXXRecordDecl *VBaseDecl = VBase.getType()->getAsCXXRecordDecl())
234
2.13k
          
if (2.13k
!VBaseDecl->hasCopyConstructorWithConstParam()2.13k
)
235
1
            data().ImplicitCopyConstructorCanHaveConstParamForVBase = false;
236
2.13k
237
2.13k
        // C++1z [dcl.init.agg]p1:
238
2.13k
        //   An aggregate is a class with [...] no virtual base classes
239
2.13k
        data().Aggregate = false;
240
2.13k
      }
241
2.41k
    }
242
42.6k
243
42.6k
    if (
Base->isVirtual()42.6k
) {
244
1.82k
      // Add this base if it's not already in the list.
245
1.82k
      if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)).second)
246
1.76k
        VBases.push_back(Base);
247
1.82k
248
1.82k
      // C++14 [meta.unary.prop] is_empty:
249
1.82k
      //   T is a class type, but not a union type, with ... no virtual base
250
1.82k
      //   classes
251
1.82k
      data().Empty = false;
252
1.82k
253
1.82k
      // C++1z [dcl.init.agg]p1:
254
1.82k
      //   An aggregate is a class with [...] no virtual base classes
255
1.82k
      data().Aggregate = false;
256
1.82k
257
1.82k
      // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25:
258
1.82k
      //   A [default constructor, copy/move constructor, or copy/move assignment
259
1.82k
      //   operator for a class X] is trivial [...] if:
260
1.82k
      //    -- class X has [...] no virtual base classes
261
1.82k
      data().HasTrivialSpecialMembers &= SMF_Destructor;
262
1.82k
263
1.82k
      // C++0x [class]p7:
264
1.82k
      //   A standard-layout class is a class that: [...]
265
1.82k
      //    -- has [...] no virtual base classes
266
1.82k
      data().IsStandardLayout = false;
267
1.82k
268
1.82k
      // C++11 [dcl.constexpr]p4:
269
1.82k
      //   In the definition of a constexpr constructor [...]
270
1.82k
      //    -- the class shall not have any virtual base classes
271
1.82k
      data().DefaultedDefaultConstructorIsConstexpr = false;
272
1.82k
273
1.82k
      // C++1z [class.copy]p8:
274
1.82k
      //   The implicitly-declared copy constructor for a class X will have
275
1.82k
      //   the form 'X::X(const X&)' if each potentially constructed subobject
276
1.82k
      //   has a copy constructor whose first parameter is of type
277
1.82k
      //   'const B&' or 'const volatile B&' [...]
278
1.82k
      if (!BaseClassDecl->hasCopyConstructorWithConstParam())
279
12
        data().ImplicitCopyConstructorCanHaveConstParamForVBase = false;
280
42.6k
    } else {
281
40.8k
      // C++ [class.ctor]p5:
282
40.8k
      //   A default constructor is trivial [...] if:
283
40.8k
      //    -- all the direct base classes of its class have trivial default
284
40.8k
      //       constructors.
285
40.8k
      if (!BaseClassDecl->hasTrivialDefaultConstructor())
286
34.3k
        data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
287
40.8k
288
40.8k
      // C++0x [class.copy]p13:
289
40.8k
      //   A copy/move constructor for class X is trivial if [...]
290
40.8k
      //    [...]
291
40.8k
      //    -- the constructor selected to copy/move each direct base class
292
40.8k
      //       subobject is trivial, and
293
40.8k
      if (!BaseClassDecl->hasTrivialCopyConstructor())
294
30.7k
        data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor;
295
40.8k
      // If the base class doesn't have a simple move constructor, we'll eagerly
296
40.8k
      // declare it and perform overload resolution to determine which function
297
40.8k
      // it actually calls. If it does have a simple move constructor, this
298
40.8k
      // check is correct.
299
40.8k
      if (!BaseClassDecl->hasTrivialMoveConstructor())
300
31.2k
        data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor;
301
40.8k
302
40.8k
      // C++0x [class.copy]p27:
303
40.8k
      //   A copy/move assignment operator for class X is trivial if [...]
304
40.8k
      //    [...]
305
40.8k
      //    -- the assignment operator selected to copy/move each direct base
306
40.8k
      //       class subobject is trivial, and
307
40.8k
      if (!BaseClassDecl->hasTrivialCopyAssignment())
308
26.4k
        data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment;
309
40.8k
      // If the base class doesn't have a simple move assignment, we'll eagerly
310
40.8k
      // declare it and perform overload resolution to determine which function
311
40.8k
      // it actually calls. If it does have a simple move assignment, this
312
40.8k
      // check is correct.
313
40.8k
      if (!BaseClassDecl->hasTrivialMoveAssignment())
314
31.2k
        data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment;
315
40.8k
316
40.8k
      // C++11 [class.ctor]p6:
317
40.8k
      //   If that user-written default constructor would satisfy the
318
40.8k
      //   requirements of a constexpr constructor, the implicitly-defined
319
40.8k
      //   default constructor is constexpr.
320
40.8k
      if (!BaseClassDecl->hasConstexprDefaultConstructor())
321
19.9k
        data().DefaultedDefaultConstructorIsConstexpr = false;
322
40.8k
323
40.8k
      // C++1z [class.copy]p8:
324
40.8k
      //   The implicitly-declared copy constructor for a class X will have
325
40.8k
      //   the form 'X::X(const X&)' if each potentially constructed subobject
326
40.8k
      //   has a copy constructor whose first parameter is of type
327
40.8k
      //   'const B&' or 'const volatile B&' [...]
328
40.8k
      if (!BaseClassDecl->hasCopyConstructorWithConstParam())
329
37
        data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false;
330
40.8k
    }
331
42.6k
332
42.6k
    // C++ [class.ctor]p3:
333
42.6k
    //   A destructor is trivial if all the direct base classes of its class
334
42.6k
    //   have trivial destructors.
335
42.6k
    if (!BaseClassDecl->hasTrivialDestructor())
336
24.8k
      data().HasTrivialSpecialMembers &= ~SMF_Destructor;
337
42.6k
338
42.6k
    if (!BaseClassDecl->hasIrrelevantDestructor())
339
24.9k
      data().HasIrrelevantDestructor = false;
340
42.6k
341
42.6k
    // C++11 [class.copy]p18:
342
42.6k
    //   The implicitly-declared copy assignment oeprator for a class X will
343
42.6k
    //   have the form 'X& X::operator=(const X&)' if each direct base class B
344
42.6k
    //   of X has a copy assignment operator whose parameter is of type 'const
345
42.6k
    //   B&', 'const volatile B&', or 'B' [...]
346
42.6k
    if (!BaseClassDecl->hasCopyAssignmentWithConstParam())
347
163
      data().ImplicitCopyAssignmentHasConstParam = false;
348
42.6k
349
42.6k
    // A class has an Objective-C object member if... or any of its bases
350
42.6k
    // has an Objective-C object member.
351
42.6k
    if (BaseClassDecl->hasObjectMember())
352
3
      setHasObjectMember(true);
353
42.6k
    
354
42.6k
    if (BaseClassDecl->hasVolatileMember())
355
725
      setHasVolatileMember(true);
356
42.6k
357
42.6k
    // Keep track of the presence of mutable fields.
358
42.6k
    if (
BaseClassDecl->hasMutableFields()42.6k
) {
359
79
      data().HasMutableFields = true;
360
79
      data().NeedOverloadResolutionForCopyConstructor = true;
361
79
    }
362
42.6k
363
42.6k
    if (BaseClassDecl->hasUninitializedReferenceMember())
364
29
      data().HasUninitializedReferenceMember = true;
365
42.6k
366
42.6k
    if (!BaseClassDecl->allowConstDefaultInit())
367
6.18k
      data().HasUninitializedFields = true;
368
45.5k
369
45.5k
    addedClassSubobject(BaseClassDecl);
370
45.5k
  }
371
41.7k
  
372
41.7k
  if (
VBases.empty()41.7k
) {
373
39.7k
    data().IsParsingBaseSpecifiers = false;
374
39.7k
    return;
375
39.7k
  }
376
2.01k
377
2.01k
  // Create base specifier for any direct or indirect virtual bases.
378
2.01k
  data().VBases = new (C) CXXBaseSpecifier[VBases.size()];
379
2.01k
  data().NumVBases = VBases.size();
380
5.90k
  for (int I = 0, E = VBases.size(); 
I != E5.90k
;
++I3.89k
) {
381
3.89k
    QualType Type = VBases[I]->getType();
382
3.89k
    if (!Type->isDependentType())
383
3.89k
      addedClassSubobject(Type->getAsCXXRecordDecl());
384
3.89k
    data().getVBases()[I] = *VBases[I];
385
3.89k
  }
386
41.7k
387
41.7k
  data().IsParsingBaseSpecifiers = false;
388
41.7k
}
389
390
6.63k
unsigned CXXRecordDecl::getODRHash() const {
391
6.63k
  assert(hasDefinition() && "ODRHash only for records with definitions");
392
6.63k
393
6.63k
  // Previously calculated hash is stored in DefinitionData.
394
6.63k
  if (DefinitionData->HasODRHash)
395
690
    return DefinitionData->ODRHash;
396
5.94k
397
5.94k
  // Only calculate hash on first call of getODRHash per record.
398
5.94k
  ODRHash Hash;
399
5.94k
  Hash.AddCXXRecordDecl(getDefinition());
400
5.94k
  DefinitionData->HasODRHash = true;
401
5.94k
  DefinitionData->ODRHash = Hash.CalculateHash();
402
5.94k
403
5.94k
  return DefinitionData->ODRHash;
404
5.94k
}
405
406
407
182k
void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) {
408
182k
  // C++11 [class.copy]p11:
409
182k
  //   A defaulted copy/move constructor for a class X is defined as
410
182k
  //   deleted if X has:
411
182k
  //    -- a direct or virtual base class B that cannot be copied/moved [...]
412
182k
  //    -- a non-static data member of class type M (or array thereof)
413
182k
  //       that cannot be copied or moved [...]
414
182k
  if (!Subobj->hasSimpleCopyConstructor())
415
13.4k
    data().NeedOverloadResolutionForCopyConstructor = true;
416
182k
  if (!Subobj->hasSimpleMoveConstructor())
417
27.4k
    data().NeedOverloadResolutionForMoveConstructor = true;
418
182k
419
182k
  // C++11 [class.copy]p23:
420
182k
  //   A defaulted copy/move assignment operator for a class X is defined as
421
182k
  //   deleted if X has:
422
182k
  //    -- a direct or virtual base class B that cannot be copied/moved [...]
423
182k
  //    -- a non-static data member of class type M (or array thereof)
424
182k
  //        that cannot be copied or moved [...]
425
182k
  if (!Subobj->hasSimpleMoveAssignment())
426
27.5k
    data().NeedOverloadResolutionForMoveAssignment = true;
427
182k
428
182k
  // C++11 [class.ctor]p5, C++11 [class.copy]p11, C++11 [class.dtor]p5:
429
182k
  //   A defaulted [ctor or dtor] for a class X is defined as
430
182k
  //   deleted if X has:
431
182k
  //    -- any direct or virtual base class [...] has a type with a destructor
432
182k
  //       that is deleted or inaccessible from the defaulted [ctor or dtor].
433
182k
  //    -- any non-static data member has a type with a destructor
434
182k
  //       that is deleted or inaccessible from the defaulted [ctor or dtor].
435
182k
  if (
!Subobj->hasSimpleDestructor()182k
) {
436
18.4k
    data().NeedOverloadResolutionForCopyConstructor = true;
437
18.4k
    data().NeedOverloadResolutionForMoveConstructor = true;
438
18.4k
    data().NeedOverloadResolutionForDestructor = true;
439
18.4k
  }
440
182k
}
441
442
1.94k
bool CXXRecordDecl::hasAnyDependentBases() const {
443
1.94k
  if (!isDependentContext())
444
1.21k
    return false;
445
724
446
724
  
return !forallBases([](const CXXRecordDecl *) 724
{ return true; }110
);
447
1.94k
}
448
449
37.0k
bool CXXRecordDecl::isTriviallyCopyable() const {
450
37.0k
  // C++0x [class]p5:
451
37.0k
  //   A trivially copyable class is a class that:
452
37.0k
  //   -- has no non-trivial copy constructors,
453
37.0k
  if (
hasNonTrivialCopyConstructor()37.0k
)
return false14.1k
;
454
22.8k
  //   -- has no non-trivial move constructors,
455
22.8k
  
if (22.8k
hasNonTrivialMoveConstructor()22.8k
)
return false150
;
456
22.6k
  //   -- has no non-trivial copy assignment operators,
457
22.6k
  
if (22.6k
hasNonTrivialCopyAssignment()22.6k
)
return false147
;
458
22.5k
  //   -- has no non-trivial move assignment operators, and
459
22.5k
  
if (22.5k
hasNonTrivialMoveAssignment()22.5k
)
return false86
;
460
22.4k
  //   -- has a trivial destructor.
461
22.4k
  
if (22.4k
!hasTrivialDestructor()22.4k
)
return false2.22k
;
462
20.2k
463
20.2k
  return true;
464
20.2k
}
465
466
24.5k
void CXXRecordDecl::markedVirtualFunctionPure() {
467
24.5k
  // C++ [class.abstract]p2: 
468
24.5k
  //   A class is abstract if it has at least one pure virtual function.
469
24.5k
  data().Abstract = true;
470
24.5k
}
471
472
1.99M
void CXXRecordDecl::addedMember(Decl *D) {
473
1.99M
  if (!D->isImplicit() &&
474
1.51M
      !isa<FieldDecl>(D) &&
475
720k
      !isa<IndirectFieldDecl>(D) &&
476
720k
      
(!isa<TagDecl>(D) || 720k
cast<TagDecl>(D)->getTagKind() == TTK_Class18.3k
||
477
16.5k
        cast<TagDecl>(D)->getTagKind() == TTK_Interface))
478
703k
    data().HasOnlyCMembers = false;
479
1.99M
480
1.99M
  // Ignore friends and invalid declarations.
481
1.99M
  if (
D->getFriendObjectKind() || 1.99M
D->isInvalidDecl()1.99M
)
482
8.14k
    return;
483
1.98M
  
484
1.98M
  FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D);
485
1.98M
  if (FunTmpl)
486
15.2k
    D = FunTmpl->getTemplatedDecl();
487
1.98M
488
1.98M
  // FIXME: Pass NamedDecl* to addedMember?
489
1.98M
  Decl *DUnderlying = D;
490
1.98M
  if (auto *
ND1.98M
= dyn_cast<NamedDecl>(DUnderlying)) {
491
1.90M
    DUnderlying = ND->getUnderlyingDecl();
492
1.90M
    if (FunctionTemplateDecl *UnderlyingFunTmpl =
493
1.90M
            dyn_cast<FunctionTemplateDecl>(DUnderlying))
494
89
      DUnderlying = UnderlyingFunTmpl->getTemplatedDecl();
495
1.90M
  }
496
1.98M
  
497
1.98M
  if (CXXMethodDecl *
Method1.98M
= dyn_cast<CXXMethodDecl>(D)) {
498
758k
    if (
Method->isVirtual()758k
) {
499
114k
      // C++ [dcl.init.aggr]p1:
500
114k
      //   An aggregate is an array or a class with [...] no virtual functions.
501
114k
      data().Aggregate = false;
502
114k
      
503
114k
      // C++ [class]p4:
504
114k
      //   A POD-struct is an aggregate class...
505
114k
      data().PlainOldData = false;
506
114k
      
507
114k
      // C++14 [meta.unary.prop]p4:
508
114k
      //   T is a class type [...] with [...] no virtual member functions...
509
114k
      data().Empty = false;
510
114k
511
114k
      // C++ [class.virtual]p1:
512
114k
      //   A class that declares or inherits a virtual function is called a 
513
114k
      //   polymorphic class.
514
114k
      data().Polymorphic = true;
515
114k
516
114k
      // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25:
517
114k
      //   A [default constructor, copy/move constructor, or copy/move
518
114k
      //   assignment operator for a class X] is trivial [...] if:
519
114k
      //    -- class X has no virtual functions [...]
520
114k
      data().HasTrivialSpecialMembers &= SMF_Destructor;
521
114k
522
114k
      // C++0x [class]p7:
523
114k
      //   A standard-layout class is a class that: [...]
524
114k
      //    -- has no virtual functions
525
114k
      data().IsStandardLayout = false;
526
114k
    }
527
758k
  }
528
1.98M
529
1.98M
  // Notify the listener if an implicit member was added after the definition
530
1.98M
  // was completed.
531
1.98M
  if (
!isBeingDefined() && 1.98M
D->isImplicit()111k
)
532
110k
    
if (ASTMutationListener *110k
L110k
= getASTMutationListener())
533
1.55k
      L->AddedCXXImplicitMember(data().Definition, D);
534
1.98M
535
1.98M
  // The kind of special member this declaration is, if any.
536
1.98M
  unsigned SMKind = 0;
537
1.98M
538
1.98M
  // Handle constructors.
539
1.98M
  if (CXXConstructorDecl *
Constructor1.98M
= dyn_cast<CXXConstructorDecl>(D)) {
540
187k
    if (
!Constructor->isImplicit()187k
) {
541
80.4k
      // Note that we have a user-declared constructor.
542
80.4k
      data().UserDeclaredConstructor = true;
543
80.4k
544
80.4k
      // C++ [class]p4:
545
80.4k
      //   A POD-struct is an aggregate class [...]
546
80.4k
      // Since the POD bit is meant to be C++03 POD-ness, clear it even if the
547
80.4k
      // type is technically an aggregate in C++0x since it wouldn't be in 03.
548
80.4k
      data().PlainOldData = false;
549
80.4k
    }
550
187k
551
187k
    if (
Constructor->isDefaultConstructor()187k
) {
552
61.0k
      SMKind |= SMF_DefaultConstructor;
553
61.0k
554
61.0k
      if (Constructor->isUserProvided())
555
32.0k
        data().UserProvidedDefaultConstructor = true;
556
61.0k
      if (Constructor->isConstexpr())
557
7.14k
        data().HasConstexprDefaultConstructor = true;
558
61.0k
      if (Constructor->isDefaulted())
559
28.8k
        data().HasDefaultedDefaultConstructor = true;
560
61.0k
    }
561
187k
562
187k
    if (
!FunTmpl187k
) {
563
185k
      unsigned Quals;
564
185k
      if (
Constructor->isCopyConstructor(Quals)185k
) {
565
72.2k
        SMKind |= SMF_CopyConstructor;
566
72.2k
567
72.2k
        if (Quals & Qualifiers::Const)
568
71.7k
          data().HasDeclaredCopyConstructorWithConstParam = true;
569
185k
      } else 
if (113k
Constructor->isMoveConstructor()113k
)
570
20.8k
        SMKind |= SMF_MoveConstructor;
571
185k
    }
572
187k
573
187k
    // C++11 [dcl.init.aggr]p1: DR1518
574
187k
    //   An aggregate is an array or a class with no user-provided, explicit, or
575
187k
    //   inherited constructors
576
187k
    if (
Constructor->isUserProvided() || 187k
Constructor->isExplicit()110k
)
577
77.0k
      data().Aggregate = false;
578
187k
  }
579
1.98M
580
1.98M
  // Handle constructors, including those inherited from base classes.
581
1.98M
  if (CXXConstructorDecl *Constructor =
582
188k
          dyn_cast<CXXConstructorDecl>(DUnderlying)) {
583
188k
    // Record if we see any constexpr constructors which are neither copy
584
188k
    // nor move constructors.
585
188k
    // C++1z [basic.types]p10:
586
188k
    //   [...] has at least one constexpr constructor or constructor template
587
188k
    //   (possibly inherited from a base class) that is not a copy or move
588
188k
    //   constructor [...]
589
188k
    if (
Constructor->isConstexpr() && 188k
!Constructor->isCopyOrMoveConstructor()45.3k
)
590
8.05k
      data().HasConstexprNonCopyMoveConstructor = true;
591
188k
  }
592
1.98M
593
1.98M
  // Handle destructors.
594
1.98M
  if (CXXDestructorDecl *
DD1.98M
= dyn_cast<CXXDestructorDecl>(D)) {
595
66.5k
    SMKind |= SMF_Destructor;
596
66.5k
597
66.5k
    if (DD->isUserProvided())
598
19.5k
      data().HasIrrelevantDestructor = false;
599
66.5k
    // If the destructor is explicitly defaulted and not trivial or not public
600
66.5k
    // or if the destructor is deleted, we clear HasIrrelevantDestructor in
601
66.5k
    // finishedDefaultedOrDeletedMember.
602
66.5k
603
66.5k
    // C++11 [class.dtor]p5:
604
66.5k
    //   A destructor is trivial if [...] the destructor is not virtual.
605
66.5k
    if (DD->isVirtual())
606
25.3k
      data().HasTrivialSpecialMembers &= ~SMF_Destructor;
607
66.5k
  }
608
1.98M
609
1.98M
  // Handle member functions.
610
1.98M
  if (CXXMethodDecl *
Method1.98M
= dyn_cast<CXXMethodDecl>(D)) {
611
758k
    if (
Method->isCopyAssignmentOperator()758k
) {
612
46.4k
      SMKind |= SMF_CopyAssignment;
613
46.4k
614
46.4k
      const ReferenceType *ParamTy =
615
46.4k
        Method->getParamDecl(0)->getType()->getAs<ReferenceType>();
616
46.4k
      if (
!ParamTy || 46.4k
ParamTy->getPointeeType().isConstQualified()46.4k
)
617
45.9k
        data().HasDeclaredCopyAssignmentWithConstParam = true;
618
46.4k
    }
619
758k
620
758k
    if (Method->isMoveAssignmentOperator())
621
8.44k
      SMKind |= SMF_MoveAssignment;
622
758k
623
758k
    // Keep the list of conversion functions up-to-date.
624
758k
    if (CXXConversionDecl *
Conversion758k
= dyn_cast<CXXConversionDecl>(D)) {
625
7.55k
      // FIXME: We use the 'unsafe' accessor for the access specifier here,
626
7.55k
      // because Sema may not have set it yet. That's really just a misdesign
627
7.55k
      // in Sema. However, LLDB *will* have set the access specifier correctly,
628
7.55k
      // and adds declarations after the class is technically completed,
629
7.55k
      // so completeDefinition()'s overriding of the access specifiers doesn't
630
7.55k
      // work.
631
7.55k
      AccessSpecifier AS = Conversion->getAccessUnsafe();
632
7.55k
633
7.55k
      if (
Conversion->getPrimaryTemplate()7.55k
) {
634
0
        // We don't record specializations.
635
7.55k
      } else {
636
7.55k
        ASTContext &Ctx = getASTContext();
637
7.55k
        ASTUnresolvedSet &Conversions = data().Conversions.get(Ctx);
638
7.55k
        NamedDecl *Primary =
639
7.55k
            FunTmpl ? 
cast<NamedDecl>(FunTmpl)1.20k
:
cast<NamedDecl>(Conversion)6.35k
;
640
7.55k
        if (Primary->getPreviousDecl())
641
0
          Conversions.replace(cast<NamedDecl>(Primary->getPreviousDecl()),
642
0
                              Primary, AS);
643
7.55k
        else
644
7.55k
          Conversions.addDecl(Ctx, Primary, AS);
645
7.55k
      }
646
7.55k
    }
647
758k
648
758k
    if (
SMKind758k
) {
649
275k
      // If this is the first declaration of a special member, we no longer have
650
275k
      // an implicit trivial special member.
651
275k
      data().HasTrivialSpecialMembers &=
652
275k
        data().DeclaredSpecialMembers | ~SMKind;
653
275k
654
275k
      if (
!Method->isImplicit() && 275k
!Method->isUserProvided()78.8k
) {
655
6.06k
        // This method is user-declared but not user-provided. We can't work out
656
6.06k
        // whether it's trivial yet (not until we get to the end of the class).
657
6.06k
        // We'll handle this method in finishedDefaultedOrDeletedMember.
658
275k
      } else 
if (269k
Method->isTrivial()269k
)
659
110k
        data().HasTrivialSpecialMembers |= SMKind;
660
269k
      else
661
159k
        data().DeclaredNonTrivialSpecialMembers |= SMKind;
662
275k
663
275k
      // Note when we have declared a declared special member, and suppress the
664
275k
      // implicit declaration of this special member.
665
275k
      data().DeclaredSpecialMembers |= SMKind;
666
275k
667
275k
      if (
!Method->isImplicit()275k
) {
668
78.8k
        data().UserDeclaredSpecialMembers |= SMKind;
669
78.8k
670
78.8k
        // C++03 [class]p4:
671
78.8k
        //   A POD-struct is an aggregate class that has [...] no user-defined
672
78.8k
        //   copy assignment operator and no user-defined destructor.
673
78.8k
        //
674
78.8k
        // Since the POD bit is meant to be C++03 POD-ness, and in C++03,
675
78.8k
        // aggregates could not have any constructors, clear it even for an
676
78.8k
        // explicitly defaulted or deleted constructor.
677
78.8k
        // type is technically an aggregate in C++0x since it wouldn't be in 03.
678
78.8k
        //
679
78.8k
        // Also, a user-declared move assignment operator makes a class non-POD.
680
78.8k
        // This is an extension in C++03.
681
78.8k
        data().PlainOldData = false;
682
78.8k
      }
683
275k
    }
684
758k
685
758k
    return;
686
758k
  }
687
1.23M
688
1.23M
  // Handle non-static data members.
689
1.23M
  
if (FieldDecl *1.23M
Field1.23M
= dyn_cast<FieldDecl>(D)) {
690
853k
    // C++ [class.bit]p2:
691
853k
    //   A declaration for a bit-field that omits the identifier declares an 
692
853k
    //   unnamed bit-field. Unnamed bit-fields are not members and cannot be 
693
853k
    //   initialized.
694
853k
    if (Field->isUnnamedBitfield())
695
363
      return;
696
853k
    
697
853k
    // C++ [dcl.init.aggr]p1:
698
853k
    //   An aggregate is an array or a class (clause 9) with [...] no
699
853k
    //   private or protected non-static data members (clause 11).
700
853k
    //
701
853k
    // A POD must be an aggregate.    
702
853k
    
if (853k
D->getAccess() == AS_private || 853k
D->getAccess() == AS_protected742k
) {
703
121k
      data().Aggregate = false;
704
121k
      data().PlainOldData = false;
705
121k
    }
706
853k
707
853k
    // C++0x [class]p7:
708
853k
    //   A standard-layout class is a class that:
709
853k
    //    [...]
710
853k
    //    -- has the same access control for all non-static data members,
711
853k
    switch (D->getAccess()) {
712
110k
    case AS_private:    data().HasPrivateFields = true;   break;
713
10.7k
    case AS_protected:  data().HasProtectedFields = true; break;
714
731k
    case AS_public:     data().HasPublicFields = true;    break;
715
0
    
case AS_none: 0
llvm_unreachable0
("Invalid access specifier");
716
853k
    };
717
853k
    if ((data().HasPrivateFields + data().HasProtectedFields +
718
853k
         data().HasPublicFields) > 1)
719
3.53k
      data().IsStandardLayout = false;
720
853k
721
853k
    // Keep track of the presence of mutable fields.
722
853k
    if (
Field->isMutable()853k
) {
723
1.06k
      data().HasMutableFields = true;
724
1.06k
      data().NeedOverloadResolutionForCopyConstructor = true;
725
1.06k
    }
726
853k
727
853k
    // C++11 [class.union]p8, DR1460:
728
853k
    //   If X is a union, a non-static data member of X that is not an anonymous
729
853k
    //   union is a variant member of X.
730
853k
    if (
isUnion() && 853k
!Field->isAnonymousStructOrUnion()47.2k
)
731
47.1k
      data().HasVariantMembers = true;
732
853k
733
853k
    // C++0x [class]p9:
734
853k
    //   A POD struct is a class that is both a trivial class and a 
735
853k
    //   standard-layout class, and has no non-static data members of type 
736
853k
    //   non-POD struct, non-POD union (or array of such types).
737
853k
    //
738
853k
    // Automatic Reference Counting: the presence of a member of Objective-C pointer type
739
853k
    // that does not explicitly have no lifetime makes the class a non-POD.
740
853k
    ASTContext &Context = getASTContext();
741
853k
    QualType T = Context.getBaseElementType(Field->getType());
742
853k
    if (
T->isObjCRetainableType() || 853k
T.isObjCGCStrong()852k
) {
743
146
      if (
T.hasNonTrivialObjCLifetime()146
) {
744
38
        // Objective-C Automatic Reference Counting:
745
38
        //   If a class has a non-static data member of Objective-C pointer
746
38
        //   type (or array thereof), it is a non-POD type and its
747
38
        //   default constructor (if any), copy constructor, move constructor,
748
38
        //   copy assignment operator, move assignment operator, and destructor are
749
38
        //   non-trivial.
750
38
        setHasObjectMember(true);
751
38
        struct DefinitionData &Data = data();
752
38
        Data.PlainOldData = false;
753
38
        Data.HasTrivialSpecialMembers = 0;
754
38
        Data.HasIrrelevantDestructor = false;
755
146
      } else 
if (108
!Context.getLangOpts().ObjCAutoRefCount108
) {
756
105
        setHasObjectMember(true);
757
105
      }
758
853k
    } else 
if (852k
!T.isCXX98PODType(Context)852k
)
759
59.7k
      data().PlainOldData = false;
760
853k
    
761
853k
    if (
T->isReferenceType()853k
) {
762
36.1k
      if (!Field->hasInClassInitializer())
763
35.9k
        data().HasUninitializedReferenceMember = true;
764
36.1k
765
36.1k
      // C++0x [class]p7:
766
36.1k
      //   A standard-layout class is a class that:
767
36.1k
      //    -- has no non-static data members of type [...] reference,
768
36.1k
      data().IsStandardLayout = false;
769
36.1k
770
36.1k
      // C++1z [class.copy.ctor]p10:
771
36.1k
      //   A defaulted copy constructor for a class X is defined as deleted if X has:
772
36.1k
      //    -- a non-static data member of rvalue reference type
773
36.1k
      if (T->isRValueReferenceType())
774
43
        data().DefaultedCopyConstructorIsDeleted = true;
775
36.1k
    }
776
853k
777
853k
    if (
!Field->hasInClassInitializer() && 853k
!Field->isMutable()852k
) {
778
850k
      if (CXXRecordDecl *
FieldType850k
= T->getAsCXXRecordDecl()) {
779
135k
        if (
FieldType->hasDefinition() && 135k
!FieldType->allowConstDefaultInit()135k
)
780
118k
          data().HasUninitializedFields = true;
781
850k
      } else {
782
715k
        data().HasUninitializedFields = true;
783
715k
      }
784
850k
    }
785
853k
786
853k
    // Record if this field is the first non-literal or volatile field or base.
787
853k
    if (
!T->isLiteralType(Context) || 853k
T.isVolatileQualified()821k
)
788
34.9k
      data().HasNonLiteralTypeFieldsOrBases = true;
789
853k
790
853k
    if (Field->hasInClassInitializer() ||
791
852k
        (Field->isAnonymousStructOrUnion() &&
792
853k
         
Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer()2.16k
)) {
793
1.12k
      data().HasInClassInitializer = true;
794
1.12k
795
1.12k
      // C++11 [class]p5:
796
1.12k
      //   A default constructor is trivial if [...] no non-static data member
797
1.12k
      //   of its class has a brace-or-equal-initializer.
798
1.12k
      data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
799
1.12k
800
1.12k
      // C++11 [dcl.init.aggr]p1:
801
1.12k
      //   An aggregate is a [...] class with [...] no
802
1.12k
      //   brace-or-equal-initializers for non-static data members.
803
1.12k
      //
804
1.12k
      // This rule was removed in C++14.
805
1.12k
      if (!getASTContext().getLangOpts().CPlusPlus14)
806
624
        data().Aggregate = false;
807
1.12k
808
1.12k
      // C++11 [class]p10:
809
1.12k
      //   A POD struct is [...] a trivial class.
810
1.12k
      data().PlainOldData = false;
811
1.12k
    }
812
853k
813
853k
    // C++11 [class.copy]p23:
814
853k
    //   A defaulted copy/move assignment operator for a class X is defined
815
853k
    //   as deleted if X has:
816
853k
    //    -- a non-static data member of reference type
817
853k
    if (T->isReferenceType())
818
36.1k
      data().DefaultedMoveAssignmentIsDeleted = true;
819
853k
820
853k
    if (const RecordType *
RecordTy853k
= T->getAs<RecordType>()) {
821
136k
      CXXRecordDecl* FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl());
822
136k
      if (
FieldRec->getDefinition()136k
) {
823
136k
        addedClassSubobject(FieldRec);
824
136k
825
136k
        // We may need to perform overload resolution to determine whether a
826
136k
        // field can be moved if it's const or volatile qualified.
827
136k
        if (
T.getCVRQualifiers() & (Qualifiers::Const | Qualifiers::Volatile)136k
) {
828
41
          // We need to care about 'const' for the copy constructor because an
829
41
          // implicit copy constructor might be declared with a non-const
830
41
          // parameter.
831
41
          data().NeedOverloadResolutionForCopyConstructor = true;
832
41
          data().NeedOverloadResolutionForMoveConstructor = true;
833
41
          data().NeedOverloadResolutionForMoveAssignment = true;
834
41
        }
835
136k
836
136k
        // C++11 [class.ctor]p5, C++11 [class.copy]p11:
837
136k
        //   A defaulted [special member] for a class X is defined as
838
136k
        //   deleted if:
839
136k
        //    -- X is a union-like class that has a variant member with a
840
136k
        //       non-trivial [corresponding special member]
841
136k
        if (
isUnion()136k
) {
842
24.9k
          if (FieldRec->hasNonTrivialCopyConstructor())
843
33
            data().DefaultedCopyConstructorIsDeleted = true;
844
24.9k
          if (FieldRec->hasNonTrivialMoveConstructor())
845
14
            data().DefaultedMoveConstructorIsDeleted = true;
846
24.9k
          if (FieldRec->hasNonTrivialMoveAssignment())
847
12
            data().DefaultedMoveAssignmentIsDeleted = true;
848
24.9k
          if (FieldRec->hasNonTrivialDestructor())
849
21
            data().DefaultedDestructorIsDeleted = true;
850
24.9k
        }
851
136k
852
136k
        // For an anonymous union member, our overload resolution will perform
853
136k
        // overload resolution for its members.
854
136k
        if (
Field->isAnonymousStructOrUnion()136k
) {
855
2.16k
          data().NeedOverloadResolutionForCopyConstructor |=
856
2.16k
              FieldRec->data().NeedOverloadResolutionForCopyConstructor;
857
2.16k
          data().NeedOverloadResolutionForMoveConstructor |=
858
2.16k
              FieldRec->data().NeedOverloadResolutionForMoveConstructor;
859
2.16k
          data().NeedOverloadResolutionForMoveAssignment |=
860
2.16k
              FieldRec->data().NeedOverloadResolutionForMoveAssignment;
861
2.16k
          data().NeedOverloadResolutionForDestructor |=
862
2.16k
              FieldRec->data().NeedOverloadResolutionForDestructor;
863
2.16k
        }
864
136k
865
136k
        // C++0x [class.ctor]p5:
866
136k
        //   A default constructor is trivial [...] if:
867
136k
        //    -- for all the non-static data members of its class that are of
868
136k
        //       class type (or array thereof), each such class has a trivial
869
136k
        //       default constructor.
870
136k
        if (!FieldRec->hasTrivialDefaultConstructor())
871
17.2k
          data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
872
136k
873
136k
        // C++0x [class.copy]p13:
874
136k
        //   A copy/move constructor for class X is trivial if [...]
875
136k
        //    [...]
876
136k
        //    -- for each non-static data member of X that is of class type (or
877
136k
        //       an array thereof), the constructor selected to copy/move that
878
136k
        //       member is trivial;
879
136k
        if (!FieldRec->hasTrivialCopyConstructor())
880
8.42k
          data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor;
881
136k
        // If the field doesn't have a simple move constructor, we'll eagerly
882
136k
        // declare the move constructor for this class and we'll decide whether
883
136k
        // it's trivial then.
884
136k
        if (!FieldRec->hasTrivialMoveConstructor())
885
9.22k
          data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor;
886
136k
887
136k
        // C++0x [class.copy]p27:
888
136k
        //   A copy/move assignment operator for class X is trivial if [...]
889
136k
        //    [...]
890
136k
        //    -- for each non-static data member of X that is of class type (or
891
136k
        //       an array thereof), the assignment operator selected to
892
136k
        //       copy/move that member is trivial;
893
136k
        if (!FieldRec->hasTrivialCopyAssignment())
894
8.10k
          data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment;
895
136k
        // If the field doesn't have a simple move assignment, we'll eagerly
896
136k
        // declare the move assignment for this class and we'll decide whether
897
136k
        // it's trivial then.
898
136k
        if (!FieldRec->hasTrivialMoveAssignment())
899
9.24k
          data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment;
900
136k
901
136k
        if (!FieldRec->hasTrivialDestructor())
902
6.26k
          data().HasTrivialSpecialMembers &= ~SMF_Destructor;
903
136k
        if (!FieldRec->hasIrrelevantDestructor())
904
6.28k
          data().HasIrrelevantDestructor = false;
905
136k
        if (FieldRec->hasObjectMember())
906
12
          setHasObjectMember(true);
907
136k
        if (FieldRec->hasVolatileMember())
908
3.72k
          setHasVolatileMember(true);
909
136k
910
136k
        // C++0x [class]p7:
911
136k
        //   A standard-layout class is a class that:
912
136k
        //    -- has no non-static data members of type non-standard-layout
913
136k
        //       class (or array of such types) [...]
914
136k
        if (!FieldRec->isStandardLayout())
915
2.61k
          data().IsStandardLayout = false;
916
136k
917
136k
        // C++0x [class]p7:
918
136k
        //   A standard-layout class is a class that:
919
136k
        //    [...]
920
136k
        //    -- has no base classes of the same type as the first non-static
921
136k
        //       data member.
922
136k
        // We don't want to expend bits in the state of the record decl
923
136k
        // tracking whether this is the first non-static data member so we
924
136k
        // cheat a bit and use some of the existing state: the empty bit.
925
136k
        // Virtual bases and virtual methods make a class non-empty, but they
926
136k
        // also make it non-standard-layout so we needn't check here.
927
136k
        // A non-empty base class may leave the class standard-layout, but not
928
136k
        // if we have arrived here, and have at least one non-static data
929
136k
        // member. If IsStandardLayout remains true, then the first non-static
930
136k
        // data member must come through here with Empty still true, and Empty
931
136k
        // will subsequently be set to false below.
932
136k
        if (
data().IsStandardLayout && 136k
data().Empty128k
) {
933
270
          for (const auto &BI : bases()) {
934
270
            if (
Context.hasSameUnqualifiedType(BI.getType(), T)270
) {
935
49
              data().IsStandardLayout = false;
936
49
              break;
937
49
            }
938
136k
          }
939
38.9k
        }
940
136k
        
941
136k
        // Keep track of the presence of mutable fields.
942
136k
        if (
FieldRec->hasMutableFields()136k
) {
943
361
          data().HasMutableFields = true;
944
361
          data().NeedOverloadResolutionForCopyConstructor = true;
945
361
        }
946
136k
947
136k
        // C++11 [class.copy]p13:
948
136k
        //   If the implicitly-defined constructor would satisfy the
949
136k
        //   requirements of a constexpr constructor, the implicitly-defined
950
136k
        //   constructor is constexpr.
951
136k
        // C++11 [dcl.constexpr]p4:
952
136k
        //    -- every constructor involved in initializing non-static data
953
136k
        //       members [...] shall be a constexpr constructor
954
136k
        if (!Field->hasInClassInitializer() &&
955
136k
            
!FieldRec->hasConstexprDefaultConstructor()135k
&&
!isUnion()134k
)
956
136k
          // The standard requires any in-class initializer to be a constant
957
136k
          // expression. We consider this to be a defect.
958
109k
          data().DefaultedDefaultConstructorIsConstexpr = false;
959
136k
960
136k
        // C++11 [class.copy]p8:
961
136k
        //   The implicitly-declared copy constructor for a class X will have
962
136k
        //   the form 'X::X(const X&)' if each potentially constructed subobject
963
136k
        //   of a class type M (or array thereof) has a copy constructor whose
964
136k
        //   first parameter is of type 'const M&' or 'const volatile M&'.
965
136k
        if (!FieldRec->hasCopyConstructorWithConstParam())
966
23
          data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false;
967
136k
968
136k
        // C++11 [class.copy]p18:
969
136k
        //   The implicitly-declared copy assignment oeprator for a class X will
970
136k
        //   have the form 'X& X::operator=(const X&)' if [...] for all the
971
136k
        //   non-static data members of X that are of a class type M (or array
972
136k
        //   thereof), each such class type has a copy assignment operator whose
973
136k
        //   parameter is of type 'const M&', 'const volatile M&' or 'M'.
974
136k
        if (!FieldRec->hasCopyAssignmentWithConstParam())
975
31
          data().ImplicitCopyAssignmentHasConstParam = false;
976
136k
977
136k
        if (FieldRec->hasUninitializedReferenceMember() &&
978
30
            !Field->hasInClassInitializer())
979
17
          data().HasUninitializedReferenceMember = true;
980
136k
981
136k
        // C++11 [class.union]p8, DR1460:
982
136k
        //   a non-static data member of an anonymous union that is a member of
983
136k
        //   X is also a variant member of X.
984
136k
        if (FieldRec->hasVariantMembers() &&
985
6.66k
            Field->isAnonymousStructOrUnion())
986
1.96k
          data().HasVariantMembers = true;
987
136k
      }
988
853k
    } else {
989
717k
      // Base element type of field is a non-class type.
990
717k
      if (!T->isLiteralType(Context) ||
991
705k
          
(!Field->hasInClassInitializer() && 705k
!isUnion()705k
))
992
694k
        data().DefaultedDefaultConstructorIsConstexpr = false;
993
717k
994
717k
      // C++11 [class.copy]p23:
995
717k
      //   A defaulted copy/move assignment operator for a class X is defined
996
717k
      //   as deleted if X has:
997
717k
      //    -- a non-static data member of const non-class type (or array
998
717k
      //       thereof)
999
717k
      if (T.isConstQualified())
1000
1.47k
        data().DefaultedMoveAssignmentIsDeleted = true;
1001
717k
    }
1002
853k
1003
853k
    // C++0x [class]p7:
1004
853k
    //   A standard-layout class is a class that:
1005
853k
    //    [...]
1006
853k
    //    -- either has no non-static data members in the most derived
1007
853k
    //       class and at most one base class with non-static data members,
1008
853k
    //       or has no base classes with non-static data members, and
1009
853k
    // At this point we know that we have a non-static data member, so the last
1010
853k
    // clause holds.
1011
853k
    if (!data().HasNoNonEmptyBases)
1012
33.3k
      data().IsStandardLayout = false;
1013
853k
1014
853k
    // C++14 [meta.unary.prop]p4:
1015
853k
    //   T is a class type [...] with [...] no non-static data members other
1016
853k
    //   than bit-fields of length 0...
1017
853k
    if (
data().Empty853k
) {
1018
216k
      if (!Field->isBitField() ||
1019
2.30k
          (!Field->getBitWidth()->isTypeDependent() &&
1020
2.30k
           !Field->getBitWidth()->isValueDependent() &&
1021
2.29k
           Field->getBitWidthValue(Context) != 0))
1022
216k
        data().Empty = false;
1023
216k
    }
1024
853k
  }
1025
1.23M
  
1026
1.23M
  // Handle using declarations of conversion functions.
1027
1.23M
  
if (UsingShadowDecl *1.23M
Shadow1.23M
= dyn_cast<UsingShadowDecl>(D)) {
1028
2.03k
    if (Shadow->getDeclName().getNameKind()
1029
2.03k
          == DeclarationName::CXXConversionFunctionName) {
1030
31
      ASTContext &Ctx = getASTContext();
1031
31
      data().Conversions.get(Ctx).addDecl(Ctx, Shadow, Shadow->getAccess());
1032
31
    }
1033
2.03k
  }
1034
1.23M
1035
1.23M
  if (UsingDecl *
Using1.23M
= dyn_cast<UsingDecl>(D)) {
1036
1.18k
    if (Using->getDeclName().getNameKind() ==
1037
1.18k
        DeclarationName::CXXConstructorName) {
1038
281
      data().HasInheritedConstructor = true;
1039
281
      // C++1z [dcl.init.aggr]p1:
1040
281
      //  An aggregate is [...] a class [...] with no inherited constructors
1041
281
      data().Aggregate = false;
1042
281
    }
1043
1.18k
1044
1.18k
    if (Using->getDeclName().getCXXOverloadedOperator() == OO_Equal)
1045
28
      data().HasInheritedAssignment = true;
1046
1.18k
  }
1047
1.99M
}
1048
1049
3.94k
void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) {
1050
3.94k
  assert(!D->isImplicit() && !D->isUserProvided());
1051
3.94k
1052
3.94k
  // The kind of special member this declaration is, if any.
1053
3.94k
  unsigned SMKind = 0;
1054
3.94k
1055
3.94k
  if (CXXConstructorDecl *
Constructor3.94k
= dyn_cast<CXXConstructorDecl>(D)) {
1056
2.44k
    if (
Constructor->isDefaultConstructor()2.44k
) {
1057
909
      SMKind |= SMF_DefaultConstructor;
1058
909
      if (Constructor->isConstexpr())
1059
217
        data().HasConstexprDefaultConstructor = true;
1060
909
    }
1061
2.44k
    if (Constructor->isCopyConstructor())
1062
902
      SMKind |= SMF_CopyConstructor;
1063
1.54k
    else 
if (1.54k
Constructor->isMoveConstructor()1.54k
)
1064
633
      SMKind |= SMF_MoveConstructor;
1065
909
    else 
if (909
Constructor->isConstexpr()909
)
1066
909
      // We may now know that the constructor is constexpr.
1067
217
      data().HasConstexprNonCopyMoveConstructor = true;
1068
3.94k
  } else 
if (1.49k
isa<CXXDestructorDecl>(D)1.49k
) {
1069
145
    SMKind |= SMF_Destructor;
1070
145
    if (
!D->isTrivial() || 145
D->getAccess() != AS_public107
||
D->isDeleted()96
)
1071
84
      data().HasIrrelevantDestructor = false;
1072
1.49k
  } else 
if (1.35k
D->isCopyAssignmentOperator()1.35k
)
1073
735
    SMKind |= SMF_CopyAssignment;
1074
618
  else 
if (618
D->isMoveAssignmentOperator()618
)
1075
618
    SMKind |= SMF_MoveAssignment;
1076
3.94k
1077
3.94k
  // Update which trivial / non-trivial special members we have.
1078
3.94k
  // addedMember will have skipped this step for this member.
1079
3.94k
  if (D->isTrivial())
1080
3.66k
    data().HasTrivialSpecialMembers |= SMKind;
1081
3.94k
  else
1082
275
    data().DeclaredNonTrivialSpecialMembers |= SMKind;
1083
3.94k
}
1084
1085
14.5k
bool CXXRecordDecl::isCLike() const {
1086
14.5k
  if (
getTagKind() == TTK_Class || 14.5k
getTagKind() == TTK_Interface14.3k
||
1087
14.3k
      !TemplateOrInstantiation.isNull())
1088
244
    return false;
1089
14.3k
  
if (14.3k
!hasDefinition()14.3k
)
1090
1
    return true;
1091
14.3k
1092
14.3k
  
return isPOD() && 14.3k
data().HasOnlyCMembers14.2k
;
1093
14.5k
}
1094
 
1095
447k
bool CXXRecordDecl::isGenericLambda() const { 
1096
447k
  if (
!isLambda()447k
)
return false429k
;
1097
18.2k
  return getLambdaData().IsGenericLambda;
1098
18.2k
}
1099
1100
13.5k
CXXMethodDecl* CXXRecordDecl::getLambdaCallOperator() const {
1101
13.5k
  if (
!isLambda()13.5k
)
return nullptr0
;
1102
13.5k
  DeclarationName Name = 
1103
13.5k
    getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
1104
13.5k
  DeclContext::lookup_result Calls = lookup(Name);
1105
13.5k
1106
13.5k
  assert(!Calls.empty() && "Missing lambda call operator!");
1107
13.5k
  assert(Calls.size() == 1 && "More than one lambda call operator!"); 
1108
13.5k
   
1109
13.5k
  NamedDecl *CallOp = Calls.front();
1110
13.5k
  if (FunctionTemplateDecl *CallOpTmpl = 
1111
13.5k
                    dyn_cast<FunctionTemplateDecl>(CallOp)) 
1112
5.94k
    return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl());
1113
7.56k
  
1114
7.56k
  return cast<CXXMethodDecl>(CallOp);
1115
7.56k
}
1116
1117
1.25k
CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const {
1118
1.25k
  if (
!isLambda()1.25k
)
return nullptr0
;
1119
1.25k
  DeclarationName Name = 
1120
1.25k
    &getASTContext().Idents.get(getLambdaStaticInvokerName());
1121
1.25k
  DeclContext::lookup_result Invoker = lookup(Name);
1122
1.25k
  if (
Invoker.empty()1.25k
)
return nullptr437
;
1123
1.25k
  assert(Invoker.size() == 1 && "More than one static invoker operator!");  
1124
818
  NamedDecl *InvokerFun = Invoker.front();
1125
818
  if (FunctionTemplateDecl *InvokerTemplate =
1126
818
                  dyn_cast<FunctionTemplateDecl>(InvokerFun)) 
1127
480
    return cast<CXXMethodDecl>(InvokerTemplate->getTemplatedDecl());
1128
338
  
1129
338
  return cast<CXXMethodDecl>(InvokerFun); 
1130
338
}
1131
1132
void CXXRecordDecl::getCaptureFields(
1133
       llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1134
1.01k
       FieldDecl *&ThisCapture) const {
1135
1.01k
  Captures.clear();
1136
1.01k
  ThisCapture = nullptr;
1137
1.01k
1138
1.01k
  LambdaDefinitionData &Lambda = getLambdaData();
1139
1.01k
  RecordDecl::field_iterator Field = field_begin();
1140
1.01k
  for (const LambdaCapture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures;
1141
2.15k
       
C != CEnd2.15k
;
++C, ++Field1.14k
) {
1142
1.14k
    if (C->capturesThis())
1143
208
      ThisCapture = *Field;
1144
932
    else 
if (932
C->capturesVariable()932
)
1145
905
      Captures[C->getCapturedVar()] = *Field;
1146
1.14k
  }
1147
1.01k
  assert(Field == field_end());
1148
1.01k
}
1149
1150
TemplateParameterList * 
1151
1.25k
CXXRecordDecl::getGenericLambdaTemplateParameterList() const {
1152
1.25k
  if (
!isLambda()1.25k
)
return nullptr0
;
1153
1.25k
  CXXMethodDecl *CallOp = getLambdaCallOperator();     
1154
1.25k
  if (FunctionTemplateDecl *Tmpl = CallOp->getDescribedFunctionTemplate())
1155
581
    return Tmpl->getTemplateParameters();
1156
670
  return nullptr;
1157
670
}
1158
1159
5.08k
Decl *CXXRecordDecl::getLambdaContextDecl() const {
1160
5.08k
  assert(isLambda() && "Not a lambda closure type!");
1161
5.08k
  ExternalASTSource *Source = getParentASTContext().getExternalSource();
1162
5.08k
  return getLambdaData().ContextDecl.get(Source);
1163
5.08k
}
1164
1165
1.07k
static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) {
1166
1.07k
  QualType T =
1167
1.07k
      cast<CXXConversionDecl>(Conv->getUnderlyingDecl()->getAsFunction())
1168
1.07k
          ->getConversionType();
1169
1.07k
  return Context.getCanonicalType(T);
1170
1.07k
}
1171
1172
/// Collect the visible conversions of a base class.
1173
///
1174
/// \param Record a base class of the class we're considering
1175
/// \param InVirtual whether this base class is a virtual base (or a base
1176
///   of a virtual base)
1177
/// \param Access the access along the inheritance path to this base
1178
/// \param ParentHiddenTypes the conversions provided by the inheritors
1179
///   of this base
1180
/// \param Output the set to which to add conversions from non-virtual bases
1181
/// \param VOutput the set to which to add conversions from virtual bases
1182
/// \param HiddenVBaseCs the set of conversions which were hidden in a
1183
///   virtual base along some inheritance path
1184
static void CollectVisibleConversions(ASTContext &Context,
1185
                                      CXXRecordDecl *Record,
1186
                                      bool InVirtual,
1187
                                      AccessSpecifier Access,
1188
                  const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes,
1189
                                      ASTUnresolvedSet &Output,
1190
                                      UnresolvedSetImpl &VOutput,
1191
4.19k
                           llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) {
1192
4.19k
  // The set of types which have conversions in this class or its
1193
4.19k
  // subclasses.  As an optimization, we don't copy the derived set
1194
4.19k
  // unless it might change.
1195
4.19k
  const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes;
1196
4.19k
  llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer;
1197
4.19k
1198
4.19k
  // Collect the direct conversions and figure out which conversions
1199
4.19k
  // will be hidden in the subclasses.
1200
4.19k
  CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
1201
4.19k
  CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
1202
4.19k
  if (
ConvI != ConvE4.19k
) {
1203
705
    HiddenTypesBuffer = ParentHiddenTypes;
1204
705
    HiddenTypes = &HiddenTypesBuffer;
1205
705
1206
1.70k
    for (CXXRecordDecl::conversion_iterator I = ConvI; 
I != ConvE1.70k
;
++I1.00k
) {
1207
1.00k
      CanQualType ConvType(GetConversionType(Context, I.getDecl()));
1208
1.00k
      bool Hidden = ParentHiddenTypes.count(ConvType);
1209
1.00k
      if (!Hidden)
1210
939
        HiddenTypesBuffer.insert(ConvType);
1211
1.00k
1212
1.00k
      // If this conversion is hidden and we're in a virtual base,
1213
1.00k
      // remember that it's hidden along some inheritance path.
1214
1.00k
      if (
Hidden && 1.00k
InVirtual62
)
1215
0
        HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()));
1216
1.00k
1217
1.00k
      // If this conversion isn't hidden, add it to the appropriate output.
1218
1.00k
      else 
if (1.00k
!Hidden1.00k
) {
1219
939
        AccessSpecifier IAccess
1220
939
          = CXXRecordDecl::MergeAccess(Access, I.getAccess());
1221
939
1222
939
        if (InVirtual)
1223
0
          VOutput.addDecl(I.getDecl(), IAccess);
1224
939
        else
1225
939
          Output.addDecl(Context, I.getDecl(), IAccess);
1226
1.00k
      }
1227
1.00k
    }
1228
705
  }
1229
4.19k
1230
4.19k
  // Collect information recursively from any base classes.
1231
709
  for (const auto &I : Record->bases()) {
1232
709
    const RecordType *RT = I.getType()->getAs<RecordType>();
1233
709
    if (
!RT709
)
continue0
;
1234
709
1235
709
    AccessSpecifier BaseAccess
1236
709
      = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier());
1237
696
    bool BaseInVirtual = InVirtual || I.isVirtual();
1238
709
1239
709
    CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl());
1240
709
    CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess,
1241
709
                              *HiddenTypes, Output, VOutput, HiddenVBaseCs);
1242
709
  }
1243
4.19k
}
1244
1245
/// Collect the visible conversions of a class.
1246
///
1247
/// This would be extremely straightforward if it weren't for virtual
1248
/// bases.  It might be worth special-casing that, really.
1249
static void CollectVisibleConversions(ASTContext &Context,
1250
                                      CXXRecordDecl *Record,
1251
3.35k
                                      ASTUnresolvedSet &Output) {
1252
3.35k
  // The collection of all conversions in virtual bases that we've
1253
3.35k
  // found.  These will be added to the output as long as they don't
1254
3.35k
  // appear in the hidden-conversions set.
1255
3.35k
  UnresolvedSet<8> VBaseCs;
1256
3.35k
  
1257
3.35k
  // The set of conversions in virtual bases that we've determined to
1258
3.35k
  // be hidden.
1259
3.35k
  llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs;
1260
3.35k
1261
3.35k
  // The set of types hidden by classes derived from this one.
1262
3.35k
  llvm::SmallPtrSet<CanQualType, 8> HiddenTypes;
1263
3.35k
1264
3.35k
  // Go ahead and collect the direct conversions and add them to the
1265
3.35k
  // hidden-types set.
1266
3.35k
  CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
1267
3.35k
  CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
1268
3.35k
  Output.append(Context, ConvI, ConvE);
1269
3.42k
  for (; 
ConvI != ConvE3.42k
;
++ConvI70
)
1270
70
    HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl()));
1271
3.35k
1272
3.35k
  // Recursively collect conversions from base classes.
1273
3.48k
  for (const auto &I : Record->bases()) {
1274
3.48k
    const RecordType *RT = I.getType()->getAs<RecordType>();
1275
3.48k
    if (
!RT3.48k
)
continue0
;
1276
3.48k
1277
3.48k
    CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()),
1278
3.48k
                              I.isVirtual(), I.getAccessSpecifier(),
1279
3.48k
                              HiddenTypes, Output, VBaseCs, HiddenVBaseCs);
1280
3.48k
  }
1281
3.35k
1282
3.35k
  // Add any unhidden conversions provided by virtual bases.
1283
3.35k
  for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end();
1284
3.35k
         
I != E3.35k
;
++I0
) {
1285
0
    if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())))
1286
0
      Output.addDecl(Context, I.getDecl(), I.getAccess());
1287
0
  }
1288
3.35k
}
1289
1290
/// getVisibleConversionFunctions - get all conversion functions visible
1291
/// in current class; including conversion function templates.
1292
llvm::iterator_range<CXXRecordDecl::conversion_iterator>
1293
3.02M
CXXRecordDecl::getVisibleConversionFunctions() {
1294
3.02M
  ASTContext &Ctx = getASTContext();
1295
3.02M
1296
3.02M
  ASTUnresolvedSet *Set;
1297
3.02M
  if (
bases_begin() == bases_end()3.02M
) {
1298
2.67M
    // If root class, all conversions are visible.
1299
2.67M
    Set = &data().Conversions.get(Ctx);
1300
3.02M
  } else {
1301
352k
    Set = &data().VisibleConversions.get(Ctx);
1302
352k
    // If visible conversion list is not evaluated, evaluate it.
1303
352k
    if (
!data().ComputedVisibleConversions352k
) {
1304
3.35k
      CollectVisibleConversions(Ctx, this, *Set);
1305
3.35k
      data().ComputedVisibleConversions = true;
1306
3.35k
    }
1307
352k
  }
1308
3.02M
  return llvm::make_range(Set->begin(), Set->end());
1309
3.02M
}
1310
1311
0
void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) {
1312
0
  // This operation is O(N) but extremely rare.  Sema only uses it to
1313
0
  // remove UsingShadowDecls in a class that were followed by a direct
1314
0
  // declaration, e.g.:
1315
0
  //   class A : B {
1316
0
  //     using B::operator int;
1317
0
  //     operator int();
1318
0
  //   };
1319
0
  // This is uncommon by itself and even more uncommon in conjunction
1320
0
  // with sufficiently large numbers of directly-declared conversions
1321
0
  // that asymptotic behavior matters.
1322
0
1323
0
  ASTUnresolvedSet &Convs = data().Conversions.get(getASTContext());
1324
0
  for (unsigned I = 0, E = Convs.size(); 
I != E0
;
++I0
) {
1325
0
    if (
Convs[I].getDecl() == ConvDecl0
) {
1326
0
      Convs.erase(I);
1327
0
      assert(std::find(Convs.begin(), Convs.end(), ConvDecl) == Convs.end()
1328
0
             && "conversion was found multiple times in unresolved set");
1329
0
      return;
1330
0
    }
1331
0
  }
1332
0
1333
0
  
llvm_unreachable0
("conversion not found in set!");
1334
0
}
1335
1336
219k
CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const {
1337
219k
  if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo())
1338
4.95k
    return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom());
1339
214k
1340
214k
  return nullptr;
1341
214k
}
1342
1343
368k
MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const {
1344
368k
  return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
1345
368k
}
1346
1347
void 
1348
CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD,
1349
1.24k
                                             TemplateSpecializationKind TSK) {
1350
1.24k
  assert(TemplateOrInstantiation.isNull() && 
1351
1.24k
         "Previous template or instantiation?");
1352
1.24k
  assert(!isa<ClassTemplatePartialSpecializationDecl>(this));
1353
1.24k
  TemplateOrInstantiation 
1354
1.24k
    = new (getASTContext()) MemberSpecializationInfo(RD, TSK);
1355
1.24k
}
1356
1357
11.7M
ClassTemplateDecl *CXXRecordDecl::getDescribedClassTemplate() const {
1358
11.7M
  return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl *>();
1359
11.7M
}
1360
1361
45.9k
void CXXRecordDecl::setDescribedClassTemplate(ClassTemplateDecl *Template) {
1362
45.9k
  TemplateOrInstantiation = Template;
1363
45.9k
}
1364
1365
212k
TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{
1366
212k
  if (const ClassTemplateSpecializationDecl *Spec
1367
212k
        = dyn_cast<ClassTemplateSpecializationDecl>(this))
1368
117k
    return Spec->getSpecializationKind();
1369
94.7k
  
1370
94.7k
  
if (MemberSpecializationInfo *94.7k
MSInfo94.7k
= getMemberSpecializationInfo())
1371
621
    return MSInfo->getTemplateSpecializationKind();
1372
94.0k
  
1373
94.0k
  return TSK_Undeclared;
1374
94.0k
}
1375
1376
void 
1377
26.8k
CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) {
1378
26.8k
  if (ClassTemplateSpecializationDecl *Spec
1379
26.7k
      = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
1380
26.7k
    Spec->setSpecializationKind(TSK);
1381
26.7k
    return;
1382
26.7k
  }
1383
69
  
1384
69
  
if (MemberSpecializationInfo *69
MSInfo69
= getMemberSpecializationInfo()) {
1385
69
    MSInfo->setTemplateSpecializationKind(TSK);
1386
69
    return;
1387
69
  }
1388
0
  
1389
0
  
llvm_unreachable0
("Not a class template or member class specialization");
1390
0
}
1391
1392
22.3k
const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {
1393
22.3k
  auto GetDefinitionOrSelf =
1394
15.5k
      [](const CXXRecordDecl *D) -> const CXXRecordDecl * {
1395
15.5k
    if (auto *Def = D->getDefinition())
1396
15.5k
      return Def;
1397
0
    return D;
1398
0
  };
1399
22.3k
1400
22.3k
  // If it's a class template specialization, find the template or partial
1401
22.3k
  // specialization from which it was instantiated.
1402
22.3k
  if (auto *
TD22.3k
= dyn_cast<ClassTemplateSpecializationDecl>(this)) {
1403
15.6k
    auto From = TD->getInstantiatedFrom();
1404
15.6k
    if (auto *
CTD15.6k
= From.dyn_cast<ClassTemplateDecl *>()) {
1405
15.1k
      while (auto *
NewCTD15.1k
= CTD->getInstantiatedFromMemberTemplate()) {
1406
82
        if (NewCTD->isMemberSpecialization())
1407
0
          break;
1408
82
        CTD = NewCTD;
1409
82
      }
1410
15.0k
      return GetDefinitionOrSelf(CTD->getTemplatedDecl());
1411
15.0k
    }
1412
547
    
if (auto *547
CTPSD547
=
1413
161
            From.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) {
1414
161
      while (auto *
NewCTPSD161
= CTPSD->getInstantiatedFromMember()) {
1415
0
        if (NewCTPSD->isMemberSpecialization())
1416
0
          break;
1417
0
        CTPSD = NewCTPSD;
1418
0
      }
1419
161
      return GetDefinitionOrSelf(CTPSD);
1420
161
    }
1421
7.11k
  }
1422
7.11k
1423
7.11k
  
if (MemberSpecializationInfo *7.11k
MSInfo7.11k
= getMemberSpecializationInfo()) {
1424
325
    if (
isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())325
) {
1425
310
      const CXXRecordDecl *RD = this;
1426
620
      while (auto *NewRD = RD->getInstantiatedFromMemberClass())
1427
310
        RD = NewRD;
1428
310
      return GetDefinitionOrSelf(RD);
1429
310
    }
1430
6.80k
  }
1431
6.80k
1432
7.11k
  assert(!isTemplateInstantiation(this->getTemplateSpecializationKind()) &&
1433
6.80k
         "couldn't find pattern for class template instantiation");
1434
6.80k
  return nullptr;
1435
6.80k
}
1436
1437
376k
CXXDestructorDecl *CXXRecordDecl::getDestructor() const {
1438
376k
  ASTContext &Context = getASTContext();
1439
376k
  QualType ClassType = Context.getTypeDeclType(this);
1440
376k
1441
376k
  DeclarationName Name
1442
376k
    = Context.DeclarationNames.getCXXDestructorName(
1443
376k
                                          Context.getCanonicalType(ClassType));
1444
376k
1445
376k
  DeclContext::lookup_result R = lookup(Name);
1446
376k
1447
376k
  return R.empty() ? 
nullptr209k
:
dyn_cast<CXXDestructorDecl>(R.front())166k
;
1448
376k
}
1449
1450
24.6k
bool CXXRecordDecl::isAnyDestructorNoReturn() const {
1451
24.6k
  // Destructor is noreturn.
1452
24.6k
  if (const CXXDestructorDecl *Destructor = getDestructor())
1453
24.2k
    
if (24.2k
Destructor->isNoReturn()24.2k
)
1454
251
      return true;
1455
24.4k
1456
24.4k
  // Check base classes destructor for noreturn.
1457
24.4k
  for (const auto &Base : bases())
1458
1.63k
    
if (const CXXRecordDecl *1.63k
RD1.63k
= Base.getType()->getAsCXXRecordDecl())
1459
1.63k
      
if (1.63k
RD->isAnyDestructorNoReturn()1.63k
)
1460
45
        return true;
1461
24.3k
1462
24.3k
  // Check fields for noreturn.
1463
24.3k
  for (const auto *Field : fields())
1464
30.1k
    
if (const CXXRecordDecl *30.1k
RD30.1k
=
1465
30.1k
            Field->getType()->getBaseElementTypeUnsafe()->getAsCXXRecordDecl())
1466
1.78k
      
if (1.78k
RD->isAnyDestructorNoReturn()1.78k
)
1467
3
        return true;
1468
24.3k
1469
24.3k
  // All destructors are not noreturn.
1470
24.3k
  return false;
1471
24.3k
}
1472
1473
32
bool CXXRecordDecl::isInterfaceLike() const {
1474
32
  assert(hasDefinition() && "checking for interface-like without a definition");
1475
32
  // All __interfaces are inheritently interface-like.
1476
32
  if (isInterface())
1477
7
    return true;
1478
25
1479
25
  // Interface-like types cannot have a user declared constructor, destructor,
1480
25
  // friends, VBases, conversion functions, or fields.  Additionally, lambdas
1481
25
  // cannot be interface types.
1482
25
  
if (25
isLambda() || 25
hasUserDeclaredConstructor()25
||
1483
25
      
hasUserDeclaredDestructor()25
||
!field_empty()25
||
hasFriends()25
||
1484
25
      
getNumVBases() > 025
||
conversion_end() - conversion_begin() > 025
)
1485
0
    return false;
1486
25
1487
25
  // No interface-like type can have a method with a definition.
1488
25
  for (const auto *const Method : methods())
1489
13
    
if (13
Method->isDefined()13
)
1490
2
      return false;
1491
23
1492
23
  // Check "Special" types.
1493
23
  const auto *Uuid = getAttr<UuidAttr>();
1494
23
  if (
Uuid && 23
isStruct()9
&& (getDeclContext()->isTranslationUnit() ||
1495
9
                             getDeclContext()->isExternCXXContext()) &&
1496
7
      ((getName() == "IUnknown" &&
1497
7
        Uuid->getGuid() == "00000000-0000-0000-C000-000000000046") ||
1498
0
       (getName() == "IDispatch" &&
1499
23
        
Uuid->getGuid() == "00020400-0000-0000-C000-000000000046"0
))) {
1500
7
    if (getNumBases() > 0)
1501
0
      return false;
1502
7
    return true;
1503
7
  }
1504
16
1505
16
  // FIXME: Any access specifiers is supposed to make this no longer interface
1506
16
  // like.
1507
16
1508
16
  // If this isn't a 'special' type, it must have a single interface-like base.
1509
16
  
if (16
getNumBases() != 116
)
1510
6
    return false;
1511
10
1512
10
  const auto BaseSpec = *bases_begin();
1513
10
  if (
BaseSpec.isVirtual() || 10
BaseSpec.getAccessSpecifier() != AS_public10
)
1514
0
    return false;
1515
10
  const auto *Base = BaseSpec.getType()->getAsCXXRecordDecl();
1516
10
  if (
Base->isInterface() || 10
!Base->isInterfaceLike()9
)
1517
1
    return false;
1518
9
  return true;
1519
9
}
1520
1521
351k
void CXXRecordDecl::completeDefinition() {
1522
351k
  completeDefinition(nullptr);
1523
351k
}
1524
1525
353k
void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) {
1526
353k
  RecordDecl::completeDefinition();
1527
353k
1528
353k
  // If the class may be abstract (but hasn't been marked as such), check for
1529
353k
  // any pure final overriders.
1530
353k
  if (
mayBeAbstract()353k
) {
1531
10.1k
    CXXFinalOverriderMap MyFinalOverriders;
1532
10.1k
    if (
!FinalOverriders10.1k
) {
1533
10.0k
      getFinalOverriders(MyFinalOverriders);
1534
10.0k
      FinalOverriders = &MyFinalOverriders;
1535
10.0k
    }
1536
10.1k
    
1537
10.1k
    bool Done = false;
1538
10.1k
    for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(), 
1539
10.1k
                                     MEnd = FinalOverriders->end();
1540
184k
         
M != MEnd && 184k
!Done174k
;
++M174k
) {
1541
174k
      for (OverridingMethods::iterator SO = M->second.begin(), 
1542
174k
                                    SOEnd = M->second.end();
1543
351k
           
SO != SOEnd && 351k
!Done177k
;
++SO176k
) {
1544
177k
        assert(SO->second.size() > 0 && 
1545
177k
               "All virtual functions have overridding virtual functions");
1546
177k
        
1547
177k
        // C++ [class.abstract]p4:
1548
177k
        //   A class is abstract if it contains or inherits at least one
1549
177k
        //   pure virtual function for which the final overrider is pure
1550
177k
        //   virtual.
1551
177k
        if (
SO->second.front().Method->isPure()177k
) {
1552
430
          data().Abstract = true;
1553
430
          Done = true;
1554
430
          break;
1555
430
        }
1556
177k
      }
1557
174k
    }
1558
10.1k
  }
1559
353k
  
1560
353k
  // Set access bits correctly on the directly-declared conversions.
1561
353k
  for (conversion_iterator I = conversion_begin(), E = conversion_end();
1562
361k
       
I != E361k
;
++I7.58k
)
1563
7.58k
    I.setAccess((*I)->getAccess());
1564
353k
}
1565
1566
353k
bool CXXRecordDecl::mayBeAbstract() const {
1567
353k
  if (
data().Abstract || 353k
isInvalidDecl()341k
||
!data().Polymorphic334k
||
1568
18.5k
      isDependentContext())
1569
335k
    return false;
1570
17.6k
  
1571
17.6k
  
for (const auto &B : bases()) 17.6k
{
1572
15.0k
    CXXRecordDecl *BaseDecl 
1573
15.0k
      = cast<CXXRecordDecl>(B.getType()->getAs<RecordType>()->getDecl());
1574
15.0k
    if (BaseDecl->isAbstract())
1575
10.1k
      return true;
1576
7.56k
  }
1577
7.56k
  
1578
7.56k
  return false;
1579
7.56k
}
1580
1581
0
void CXXDeductionGuideDecl::anchor() { }
1582
1583
CXXDeductionGuideDecl *CXXDeductionGuideDecl::Create(
1584
    ASTContext &C, DeclContext *DC, SourceLocation StartLoc, bool IsExplicit,
1585
    const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
1586
333
    SourceLocation EndLocation) {
1587
333
  return new (C, DC) CXXDeductionGuideDecl(C, DC, StartLoc, IsExplicit,
1588
333
                                           NameInfo, T, TInfo, EndLocation);
1589
333
}
1590
1591
CXXDeductionGuideDecl *CXXDeductionGuideDecl::CreateDeserialized(ASTContext &C,
1592
0
                                                                 unsigned ID) {
1593
0
  return new (C, ID) CXXDeductionGuideDecl(C, nullptr, SourceLocation(), false,
1594
0
                                           DeclarationNameInfo(), QualType(),
1595
0
                                           nullptr, SourceLocation());
1596
0
}
1597
1598
0
void CXXMethodDecl::anchor() { }
1599
1600
5.88M
bool CXXMethodDecl::isStatic() const {
1601
5.88M
  const CXXMethodDecl *MD = getCanonicalDecl();
1602
5.88M
1603
5.88M
  if (MD->getStorageClass() == SC_Static)
1604
152k
    return true;
1605
5.73M
1606
5.73M
  OverloadedOperatorKind OOK = getDeclName().getCXXOverloadedOperator();
1607
5.73M
  return isStaticOverloadedOperator(OOK);
1608
5.73M
}
1609
1610
static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD,
1611
120
                                 const CXXMethodDecl *BaseMD) {
1612
120
  for (CXXMethodDecl::method_iterator I = DerivedMD->begin_overridden_methods(),
1613
128
         E = DerivedMD->end_overridden_methods(); 
I != E128
;
++I8
) {
1614
116
    const CXXMethodDecl *MD = *I;
1615
116
    if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl())
1616
100
      return true;
1617
16
    
if (16
recursivelyOverrides(MD, BaseMD)16
)
1618
8
      return true;
1619
116
  }
1620
12
  return false;
1621
120
}
1622
1623
CXXMethodDecl *
1624
CXXMethodDecl::getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1625
42.1k
                                             bool MayBeBase) {
1626
42.1k
  if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl())
1627
30.2k
    return this;
1628
11.8k
1629
11.8k
  // Lookup doesn't work for destructors, so handle them separately.
1630
11.8k
  
if (11.8k
isa<CXXDestructorDecl>(this)11.8k
) {
1631
4
    CXXMethodDecl *MD = RD->getDestructor();
1632
4
    if (
MD4
) {
1633
4
      if (recursivelyOverrides(MD, this))
1634
4
        return MD;
1635
0
      
if (0
MayBeBase && 0
recursivelyOverrides(this, MD)0
)
1636
0
        return MD;
1637
0
    }
1638
0
    return nullptr;
1639
0
  }
1640
11.8k
1641
11.8k
  
for (auto *ND : RD->lookup(getDeclName())) 11.8k
{
1642
98
    CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(ND);
1643
98
    if (!MD)
1644
0
      continue;
1645
98
    
if (98
recursivelyOverrides(MD, this)98
)
1646
95
      return MD;
1647
3
    
if (3
MayBeBase && 3
recursivelyOverrides(this, MD)2
)
1648
1
      return MD;
1649
11.7k
  }
1650
11.7k
1651
11.7k
  
for (const auto &I : RD->bases()) 11.7k
{
1652
11.7k
    const RecordType *RT = I.getType()->getAs<RecordType>();
1653
11.7k
    if (!RT)
1654
0
      continue;
1655
11.7k
    const CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl());
1656
11.7k
    CXXMethodDecl *T = this->getCorrespondingMethodInClass(Base);
1657
11.7k
    if (T)
1658
11.7k
      return T;
1659
9
  }
1660
9
1661
9
  return nullptr;
1662
9
}
1663
1664
CXXMethodDecl *
1665
CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
1666
                      SourceLocation StartLoc,
1667
                      const DeclarationNameInfo &NameInfo,
1668
                      QualType T, TypeSourceInfo *TInfo,
1669
                      StorageClass SC, bool isInline,
1670
524k
                      bool isConstexpr, SourceLocation EndLocation) {
1671
524k
  return new (C, RD) CXXMethodDecl(CXXMethod, C, RD, StartLoc, NameInfo,
1672
524k
                                   T, TInfo, SC, isInline, isConstexpr,
1673
524k
                                   EndLocation);
1674
524k
}
1675
1676
1.67k
CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
1677
1.67k
  return new (C, ID) CXXMethodDecl(CXXMethod, C, nullptr, SourceLocation(),
1678
1.67k
                                   DeclarationNameInfo(), QualType(), nullptr,
1679
1.67k
                                   SC_None, false, false, SourceLocation());
1680
1.67k
}
1681
1682
CXXMethodDecl *CXXMethodDecl::getDevirtualizedMethod(const Expr *Base,
1683
30.3k
                                                     bool IsAppleKext) {
1684
30.3k
  assert(isVirtual() && "this method is expected to be virtual");
1685
30.3k
1686
30.3k
  // When building with -fapple-kext, all calls must go through the vtable since
1687
30.3k
  // the kernel linker can do runtime patching of vtables.
1688
30.3k
  if (IsAppleKext)
1689
9
    return nullptr;
1690
30.3k
1691
30.3k
  // If the member function is marked 'final', we know that it can't be
1692
30.3k
  // overridden and can therefore devirtualize it unless it's pure virtual.
1693
30.3k
  
if (30.3k
hasAttr<FinalAttr>()30.3k
)
1694
14
    
return isPure() ? 14
nullptr6
:
this8
;
1695
30.3k
1696
30.3k
  // If Base is unknown, we cannot devirtualize.
1697
30.3k
  
if (30.3k
!Base30.3k
)
1698
219
    return nullptr;
1699
30.1k
1700
30.1k
  // If the base expression (after skipping derived-to-base conversions) is a
1701
30.1k
  // class prvalue, then we can devirtualize.
1702
30.1k
  Base = Base->getBestDynamicClassTypeExpr();
1703
30.1k
  if (
Base->isRValue() && 30.1k
Base->getType()->isRecordType()24.2k
)
1704
173
    return this;
1705
29.9k
1706
29.9k
  // If we don't even know what we would call, we can't devirtualize.
1707
29.9k
  const CXXRecordDecl *BestDynamicDecl = Base->getBestDynamicClassType();
1708
29.9k
  if (!BestDynamicDecl)
1709
8
    return nullptr;
1710
29.9k
1711
29.9k
  // There may be a method corresponding to MD in a derived class.
1712
29.9k
  CXXMethodDecl *DevirtualizedMethod =
1713
29.9k
      getCorrespondingMethodInClass(BestDynamicDecl);
1714
29.9k
1715
29.9k
  // If that method is pure virtual, we can't devirtualize. If this code is
1716
29.9k
  // reached, the result would be UB, not a direct call to the derived class
1717
29.9k
  // function, and we can't assume the derived class function is defined.
1718
29.9k
  if (DevirtualizedMethod->isPure())
1719
11.2k
    return nullptr;
1720
18.6k
1721
18.6k
  // If that method is marked final, we can devirtualize it.
1722
18.6k
  
if (18.6k
DevirtualizedMethod->hasAttr<FinalAttr>()18.6k
)
1723
4
    return DevirtualizedMethod;
1724
18.6k
1725
18.6k
  // Similarly, if the class itself is marked 'final' it can't be overridden
1726
18.6k
  // and we can therefore devirtualize the member function call.
1727
18.6k
  
if (18.6k
BestDynamicDecl->hasAttr<FinalAttr>()18.6k
)
1728
60
    return DevirtualizedMethod;
1729
18.6k
1730
18.6k
  
if (const DeclRefExpr *18.6k
DRE18.6k
= dyn_cast<DeclRefExpr>(Base)) {
1731
5.53k
    if (const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl()))
1732
5.53k
      
if (5.53k
VD->getType()->isRecordType()5.53k
)
1733
5.53k
        // This is a record decl. We know the type and can devirtualize it.
1734
445
        return DevirtualizedMethod;
1735
5.09k
1736
5.09k
    return nullptr;
1737
5.09k
  }
1738
13.0k
1739
13.0k
  // We can devirtualize calls on an object accessed by a class member access
1740
13.0k
  // expression, since by C++11 [basic.life]p6 we know that it can't refer to
1741
13.0k
  // a derived class object constructed in the same location.
1742
13.0k
  
if (const MemberExpr *13.0k
ME13.0k
= dyn_cast<MemberExpr>(Base))
1743
86
    
if (const ValueDecl *86
VD86
= dyn_cast<ValueDecl>(ME->getMemberDecl()))
1744
86
      
return VD->getType()->isRecordType() ? 86
DevirtualizedMethod82
:
nullptr4
;
1745
12.9k
1746
12.9k
  // Likewise for calls on an object accessed by a (non-reference) pointer to
1747
12.9k
  // member access.
1748
12.9k
  
if (auto *12.9k
BO12.9k
= dyn_cast<BinaryOperator>(Base)) {
1749
12
    if (
BO->isPtrMemOp()12
) {
1750
12
      auto *MPT = BO->getRHS()->getType()->castAs<MemberPointerType>();
1751
12
      if (MPT->getPointeeType()->isRecordType())
1752
12
        return DevirtualizedMethod;
1753
12.9k
    }
1754
12
  }
1755
12.9k
1756
12.9k
  // We can't devirtualize the call.
1757
12.9k
  return nullptr;
1758
12.9k
}
1759
1760
1.21k
bool CXXMethodDecl::isUsualDeallocationFunction() const {
1761
1.21k
  if (getOverloadedOperator() != OO_Delete &&
1762
104
      getOverloadedOperator() != OO_Array_Delete)
1763
0
    return false;
1764
1.21k
1765
1.21k
  // C++ [basic.stc.dynamic.deallocation]p2:
1766
1.21k
  //   A template instance is never a usual deallocation function,
1767
1.21k
  //   regardless of its signature.
1768
1.21k
  
if (1.21k
getPrimaryTemplate()1.21k
)
1769
0
    return false;
1770
1.21k
1771
1.21k
  // C++ [basic.stc.dynamic.deallocation]p2:
1772
1.21k
  //   If a class T has a member deallocation function named operator delete 
1773
1.21k
  //   with exactly one parameter, then that function is a usual (non-placement)
1774
1.21k
  //   deallocation function. [...]
1775
1.21k
  
if (1.21k
getNumParams() == 11.21k
)
1776
544
    return true;
1777
674
  unsigned UsualParams = 1;
1778
674
1779
674
  // C++ <=14 [basic.stc.dynamic.deallocation]p2:
1780
674
  //   [...] If class T does not declare such an operator delete but does 
1781
674
  //   declare a member deallocation function named operator delete with 
1782
674
  //   exactly two parameters, the second of which has type std::size_t (18.1),
1783
674
  //   then this function is a usual deallocation function.
1784
674
  //
1785
674
  // C++17 says a usual deallocation function is one with the signature
1786
674
  //   (void* [, size_t] [, std::align_val_t] [, ...])
1787
674
  // and all such functions are usual deallocation functions. It's not clear
1788
674
  // that allowing varargs functions was intentional.
1789
674
  ASTContext &Context = getASTContext();
1790
674
  if (UsualParams < getNumParams() &&
1791
674
      Context.hasSameUnqualifiedType(getParamDecl(UsualParams)->getType(),
1792
674
                                     Context.getSizeType()))
1793
131
    ++UsualParams;
1794
674
1795
674
  if (UsualParams < getNumParams() &&
1796
562
      getParamDecl(UsualParams)->getType()->isAlignValT())
1797
61
    ++UsualParams;
1798
674
1799
674
  if (UsualParams != getNumParams())
1800
505
    return false;
1801
169
1802
169
  // In C++17 onwards, all potential usual deallocation functions are actual
1803
169
  // usual deallocation functions.
1804
169
  
if (169
Context.getLangOpts().AlignedAllocation169
)
1805
69
    return true;
1806
100
                 
1807
100
  // This function is a usual deallocation function if there are no 
1808
100
  // single-parameter deallocation functions of the same kind.
1809
100
  DeclContext::lookup_result R = getDeclContext()->lookup(getDeclName());
1810
100
  for (DeclContext::lookup_result::iterator I = R.begin(), E = R.end();
1811
222
       
I != E222
;
++I122
) {
1812
133
    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I))
1813
130
      
if (130
FD->getNumParams() == 1130
)
1814
11
        return false;
1815
133
  }
1816
100
  
1817
89
  return true;
1818
1.21k
}
1819
1820
1.39M
bool CXXMethodDecl::isCopyAssignmentOperator() const {
1821
1.39M
  // C++0x [class.copy]p17:
1822
1.39M
  //  A user-declared copy assignment operator X::operator= is a non-static 
1823
1.39M
  //  non-template member function of class X with exactly one parameter of 
1824
1.39M
  //  type X, X&, const X&, volatile X& or const volatile X&.
1825
1.39M
  if (/*operator=*/getOverloadedOperator() != OO_Equal ||
1826
121k
      /*non-static*/ isStatic() || 
1827
1.39M
      /*non-template*/
getPrimaryTemplate()121k
||
getDescribedFunctionTemplate()121k
||
1828
120k
      getNumParams() != 1)
1829
1.27M
    return false;
1830
120k
      
1831
120k
  QualType ParamType = getParamDecl(0)->getType();
1832
120k
  if (const LValueReferenceType *Ref = ParamType->getAs<LValueReferenceType>())
1833
97.6k
    ParamType = Ref->getPointeeType();
1834
1.39M
  
1835
1.39M
  ASTContext &Context = getASTContext();
1836
1.39M
  QualType ClassType
1837
1.39M
    = Context.getCanonicalType(Context.getTypeDeclType(getParent()));
1838
1.39M
  return Context.hasSameUnqualifiedType(ClassType, ParamType);
1839
1.39M
}
1840
1841
1.15M
bool CXXMethodDecl::isMoveAssignmentOperator() const {
1842
1.15M
  // C++0x [class.copy]p19:
1843
1.15M
  //  A user-declared move assignment operator X::operator= is a non-static
1844
1.15M
  //  non-template member function of class X with exactly one parameter of type
1845
1.15M
  //  X&&, const X&&, volatile X&&, or const volatile X&&.
1846
1.15M
  if (
getOverloadedOperator() != OO_Equal || 1.15M
isStatic()71.8k
||
1847
1.15M
      
getPrimaryTemplate()71.8k
||
getDescribedFunctionTemplate()71.8k
||
1848
71.5k
      getNumParams() != 1)
1849
1.08M
    return false;
1850
71.5k
1851
71.5k
  QualType ParamType = getParamDecl(0)->getType();
1852
71.5k
  if (!isa<RValueReferenceType>(ParamType))
1853
54.1k
    return false;
1854
17.4k
  ParamType = ParamType->getPointeeType();
1855
17.4k
1856
17.4k
  ASTContext &Context = getASTContext();
1857
17.4k
  QualType ClassType
1858
17.4k
    = Context.getCanonicalType(Context.getTypeDeclType(getParent()));
1859
17.4k
  return Context.hasSameUnqualifiedType(ClassType, ParamType);
1860
17.4k
}
1861
1862
85.0k
void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) {
1863
85.0k
  assert(MD->isCanonicalDecl() && "Method is not canonical!");
1864
85.0k
  assert(!MD->getParent()->isDependentContext() &&
1865
85.0k
         "Can't add an overridden method to a class template!");
1866
85.0k
  assert(MD->isVirtual() && "Method is not virtual!");
1867
85.0k
1868
85.0k
  getASTContext().addOverriddenMethod(this, MD);
1869
85.0k
}
1870
1871
3.51M
CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const {
1872
3.51M
  if (
isa<CXXConstructorDecl>(this)3.51M
)
return nullptr438k
;
1873
3.07M
  return getASTContext().overridden_methods_begin(this);
1874
3.07M
}
1875
1876
3.51M
CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const {
1877
3.51M
  if (
isa<CXXConstructorDecl>(this)3.51M
)
return nullptr438k
;
1878
3.07M
  return getASTContext().overridden_methods_end(this);
1879
3.07M
}
1880
1881
609k
unsigned CXXMethodDecl::size_overridden_methods() const {
1882
609k
  if (
isa<CXXConstructorDecl>(this)609k
)
return 091.6k
;
1883
517k
  return getASTContext().overridden_methods_size(this);
1884
517k
}
1885
1886
CXXMethodDecl::overridden_method_range
1887
191
CXXMethodDecl::overridden_methods() const {
1888
191
  if (isa<CXXConstructorDecl>(this))
1889
78
    return overridden_method_range(nullptr, nullptr);
1890
113
  return getASTContext().overridden_methods(this);
1891
113
}
1892
1893
1.85M
QualType CXXMethodDecl::getThisType(ASTContext &C) const {
1894
1.85M
  // C++ 9.3.2p1: The type of this in a member function of a class X is X*.
1895
1.85M
  // If the member function is declared const, the type of this is const X*,
1896
1.85M
  // if the member function is declared volatile, the type of this is
1897
1.85M
  // volatile X*, and if the member function is declared const volatile,
1898
1.85M
  // the type of this is const volatile X*.
1899
1.85M
1900
1.85M
  assert(isInstance() && "No 'this' for static methods!");
1901
1.85M
1902
1.85M
  QualType ClassTy = C.getTypeDeclType(getParent());
1903
1.85M
  ClassTy = C.getQualifiedType(ClassTy,
1904
1.85M
                               Qualifiers::fromCVRUMask(getTypeQualifiers()));
1905
1.85M
  return C.getPointerType(ClassTy);
1906
1.85M
}
1907
1908
19.9k
bool CXXMethodDecl::hasInlineBody() const {
1909
19.9k
  // If this function is a template instantiation, look at the template from 
1910
19.9k
  // which it was instantiated.
1911
19.9k
  const FunctionDecl *CheckFn = getTemplateInstantiationPattern();
1912
19.9k
  if (!CheckFn)
1913
19.9k
    CheckFn = this;
1914
19.9k
1915
19.9k
  const FunctionDecl *fn;
1916
16.3k
  return CheckFn->isDefined(fn) && !fn->isOutOfLine() &&
1917
14.7k
         
(fn->doesThisDeclarationHaveABody() || 14.7k
fn->willHaveBody()9
);
1918
19.9k
}
1919
1920
24.7k
bool CXXMethodDecl::isLambdaStaticInvoker() const {
1921
24.7k
  const CXXRecordDecl *P = getParent();
1922
24.7k
  if (
P->isLambda()24.7k
) {
1923
429
    if (const CXXMethodDecl *
StaticInvoker429
= P->getLambdaStaticInvoker()) {
1924
153
      if (
StaticInvoker == this153
)
return true18
;
1925
135
      
if (135
P->isGenericLambda() && 135
this->isFunctionTemplateSpecialization()14
)
1926
14
        return StaticInvoker == this->getPrimaryTemplate()->getTemplatedDecl();
1927
24.7k
    }
1928
429
  }
1929
24.7k
  return false;
1930
24.7k
}
1931
1932
CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
1933
                                       TypeSourceInfo *TInfo, bool IsVirtual,
1934
                                       SourceLocation L, Expr *Init,
1935
                                       SourceLocation R,
1936
                                       SourceLocation EllipsisLoc)
1937
  : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init), 
1938
    LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual), 
1939
    IsWritten(false), SourceOrder(0)
1940
20.9k
{
1941
20.9k
}
1942
1943
CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
1944
                                       FieldDecl *Member,
1945
                                       SourceLocation MemberLoc,
1946
                                       SourceLocation L, Expr *Init,
1947
                                       SourceLocation R)
1948
  : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
1949
    LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
1950
    IsWritten(false), SourceOrder(0)
1951
74.7k
{
1952
74.7k
}
1953
1954
CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
1955
                                       IndirectFieldDecl *Member,
1956
                                       SourceLocation MemberLoc,
1957
                                       SourceLocation L, Expr *Init,
1958
                                       SourceLocation R)
1959
  : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
1960
    LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
1961
    IsWritten(false), SourceOrder(0)
1962
618
{
1963
618
}
1964
1965
CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
1966
                                       TypeSourceInfo *TInfo,
1967
                                       SourceLocation L, Expr *Init, 
1968
                                       SourceLocation R)
1969
  : Initializee(TInfo), MemberOrEllipsisLocation(), Init(Init),
1970
    LParenLoc(L), RParenLoc(R), IsDelegating(true), IsVirtual(false),
1971
    IsWritten(false), SourceOrder(0)
1972
60
{
1973
60
}
1974
1975
0
TypeLoc CXXCtorInitializer::getBaseClassLoc() const {
1976
0
  if (isBaseInitializer())
1977
0
    return Initializee.get<TypeSourceInfo*>()->getTypeLoc();
1978
0
  else
1979
0
    return TypeLoc();
1980
0
}
1981
1982
52.1k
const Type *CXXCtorInitializer::getBaseClass() const {
1983
52.1k
  if (isBaseInitializer())
1984
27.8k
    return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr();
1985
52.1k
  else
1986
24.3k
    return nullptr;
1987
0
}
1988
1989
52.4k
SourceLocation CXXCtorInitializer::getSourceLocation() const {
1990
52.4k
  if (isInClassMemberInitializer())
1991
76
    return getAnyMember()->getLocation();
1992
52.3k
  
1993
52.3k
  
if (52.3k
isAnyMemberInitializer()52.3k
)
1994
44.4k
    return getMemberLocation();
1995
7.92k
1996
7.92k
  
if (TypeSourceInfo *7.92k
TSInfo7.92k
= Initializee.get<TypeSourceInfo*>())
1997
7.92k
    return TSInfo->getTypeLoc().getLocalSourceRange().getBegin();
1998
0
  
1999
0
  return SourceLocation();
2000
0
}
2001
2002
43
SourceRange CXXCtorInitializer::getSourceRange() const {
2003
43
  if (
isInClassMemberInitializer()43
) {
2004
0
    FieldDecl *D = getAnyMember();
2005
0
    if (Expr *I = D->getInClassInitializer())
2006
0
      return I->getSourceRange();
2007
0
    return SourceRange();
2008
0
  }
2009
43
2010
43
  return SourceRange(getSourceLocation(), getRParenLoc());
2011
43
}
2012
2013
0
void CXXConstructorDecl::anchor() { }
2014
2015
CXXConstructorDecl *CXXConstructorDecl::CreateDeserialized(ASTContext &C,
2016
                                                           unsigned ID,
2017
2.50k
                                                           bool Inherited) {
2018
2.50k
  unsigned Extra = additionalSizeToAlloc<InheritedConstructor>(Inherited);
2019
2.50k
  auto *Result = new (C, ID, Extra) CXXConstructorDecl(
2020
2.50k
      C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr,
2021
2.50k
      false, false, false, false, InheritedConstructor());
2022
2.50k
  Result->IsInheritingConstructor = Inherited;
2023
2.50k
  return Result;
2024
2.50k
}
2025
2026
CXXConstructorDecl *
2027
CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
2028
                           SourceLocation StartLoc,
2029
                           const DeclarationNameInfo &NameInfo,
2030
                           QualType T, TypeSourceInfo *TInfo,
2031
                           bool isExplicit, bool isInline,
2032
                           bool isImplicitlyDeclared, bool isConstexpr,
2033
191k
                           InheritedConstructor Inherited) {
2034
191k
  assert(NameInfo.getName().getNameKind()
2035
191k
         == DeclarationName::CXXConstructorName &&
2036
191k
         "Name must refer to a constructor");
2037
191k
  unsigned Extra =
2038
191k
      additionalSizeToAlloc<InheritedConstructor>(Inherited ? 
1191
:
0190k
);
2039
191k
  return new (C, RD, Extra) CXXConstructorDecl(
2040
191k
      C, RD, StartLoc, NameInfo, T, TInfo, isExplicit, isInline,
2041
191k
      isImplicitlyDeclared, isConstexpr, Inherited);
2042
191k
}
2043
2044
119k
CXXConstructorDecl::init_const_iterator CXXConstructorDecl::init_begin() const {
2045
119k
  return CtorInitializers.get(getASTContext().getExternalSource());
2046
119k
}
2047
2048
67
CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const {
2049
67
  assert(isDelegatingConstructor() && "Not a delegating constructor!");
2050
67
  Expr *E = (*init_begin())->getInit()->IgnoreImplicit();
2051
67
  if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(E))
2052
65
    return Construct->getConstructor();
2053
2
2054
2
  return nullptr;
2055
2
}
2056
2057
373k
bool CXXConstructorDecl::isDefaultConstructor() const {
2058
373k
  // C++ [class.ctor]p5:
2059
373k
  //   A default constructor for a class X is a constructor of class
2060
373k
  //   X that can be called without an argument.
2061
373k
  return (getNumParams() == 0) ||
2062
222k
         
(getNumParams() > 0 && 222k
getParamDecl(0)->hasDefaultArg()222k
);
2063
373k
}
2064
2065
bool
2066
408k
CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const {
2067
408k
  return isCopyOrMoveConstructor(TypeQuals) &&
2068
179k
         getParamDecl(0)->getType()->isLValueReferenceType();
2069
408k
}
2070
2071
182k
bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const {
2072
182k
  return isCopyOrMoveConstructor(TypeQuals) &&
2073
38.3k
    getParamDecl(0)->getType()->isRValueReferenceType();
2074
182k
}
2075
2076
/// \brief Determine whether this is a copy or move constructor.
2077
894k
bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const {
2078
894k
  // C++ [class.copy]p2:
2079
894k
  //   A non-template constructor for class X is a copy constructor
2080
894k
  //   if its first parameter is of type X&, const X&, volatile X& or
2081
894k
  //   const volatile X&, and either there are no other parameters
2082
894k
  //   or else all other parameters have default arguments (8.3.6).
2083
894k
  // C++0x [class.copy]p3:
2084
894k
  //   A non-template constructor for class X is a move constructor if its
2085
894k
  //   first parameter is of type X&&, const X&&, volatile X&&, or 
2086
894k
  //   const volatile X&&, and either there are no other parameters or else 
2087
894k
  //   all other parameters have default arguments.
2088
894k
  if ((getNumParams() < 1) ||
2089
596k
      
(getNumParams() > 1 && 596k
!getParamDecl(1)->hasDefaultArg()82.7k
) ||
2090
528k
      (getPrimaryTemplate() != nullptr) ||
2091
527k
      (getDescribedFunctionTemplate() != nullptr))
2092
367k
    return false;
2093
526k
  
2094
526k
  const ParmVarDecl *Param = getParamDecl(0);
2095
526k
  
2096
526k
  // Do we have a reference type? 
2097
526k
  const ReferenceType *ParamRefType = Param->getType()->getAs<ReferenceType>();
2098
526k
  if (!ParamRefType)
2099
145k
    return false;
2100
380k
  
2101
380k
  // Is it a reference to our class type?
2102
380k
  ASTContext &Context = getASTContext();
2103
380k
  
2104
380k
  CanQualType PointeeType
2105
380k
    = Context.getCanonicalType(ParamRefType->getPointeeType());
2106
380k
  CanQualType ClassTy 
2107
380k
    = Context.getCanonicalType(Context.getTagDeclType(getParent()));
2108
380k
  if (PointeeType.getUnqualifiedType() != ClassTy)
2109
14.0k
    return false;
2110
366k
  
2111
366k
  // FIXME: other qualifiers?
2112
366k
  
2113
366k
  // We have a copy or move constructor.
2114
366k
  TypeQuals = PointeeType.getCVRQualifiers();
2115
366k
  return true;  
2116
366k
}
2117
2118
380k
bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const {
2119
380k
  // C++ [class.conv.ctor]p1:
2120
380k
  //   A constructor declared without the function-specifier explicit
2121
380k
  //   that can be called with a single parameter specifies a
2122
380k
  //   conversion from the type of its first parameter to the type of
2123
380k
  //   its class. Such a constructor is called a converting
2124
380k
  //   constructor.
2125
380k
  if (
isExplicit() && 380k
!AllowExplicit29.3k
)
2126
29.3k
    return false;
2127
350k
2128
350k
  return (getNumParams() == 0 &&
2129
90.5k
          getType()->getAs<FunctionProtoType>()->isVariadic()) ||
2130
350k
         (getNumParams() == 1) ||
2131
212k
         (getNumParams() > 1 &&
2132
122k
          (getParamDecl(1)->hasDefaultArg() ||
2133
212k
           getParamDecl(1)->isParameterPack()));
2134
380k
}
2135
2136
541k
bool CXXConstructorDecl::isSpecializationCopyingObject() const {
2137
541k
  if ((getNumParams() < 1) ||
2138
433k
      
(getNumParams() > 1 && 433k
!getParamDecl(1)->hasDefaultArg()106k
) ||
2139
330k
      (getDescribedFunctionTemplate() != nullptr))
2140
210k
    return false;
2141
330k
2142
330k
  const ParmVarDecl *Param = getParamDecl(0);
2143
330k
2144
330k
  ASTContext &Context = getASTContext();
2145
330k
  CanQualType ParamType = Context.getCanonicalType(Param->getType());
2146
330k
  
2147
330k
  // Is it the same as our our class type?
2148
330k
  CanQualType ClassTy 
2149
330k
    = Context.getCanonicalType(Context.getTagDeclType(getParent()));
2150
330k
  if (ParamType.getUnqualifiedType() != ClassTy)
2151
330k
    return false;
2152
273
  
2153
273
  return true;  
2154
273
}
2155
2156
0
void CXXDestructorDecl::anchor() { }
2157
2158
CXXDestructorDecl *
2159
530
CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2160
530
  return new (C, ID)
2161
530
      CXXDestructorDecl(C, nullptr, SourceLocation(), DeclarationNameInfo(),
2162
530
                        QualType(), nullptr, false, false);
2163
530
}
2164
2165
CXXDestructorDecl *
2166
CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
2167
                          SourceLocation StartLoc,
2168
                          const DeclarationNameInfo &NameInfo,
2169
                          QualType T, TypeSourceInfo *TInfo,
2170
67.3k
                          bool isInline, bool isImplicitlyDeclared) {
2171
67.3k
  assert(NameInfo.getName().getNameKind()
2172
67.3k
         == DeclarationName::CXXDestructorName &&
2173
67.3k
         "Name must refer to a destructor");
2174
67.3k
  return new (C, RD) CXXDestructorDecl(C, RD, StartLoc, NameInfo, T, TInfo,
2175
67.3k
                                       isInline, isImplicitlyDeclared);
2176
67.3k
}
2177
2178
7.00k
void CXXDestructorDecl::setOperatorDelete(FunctionDecl *OD) {
2179
7.00k
  auto *First = cast<CXXDestructorDecl>(getFirstDecl());
2180
7.00k
  if (
OD && 7.00k
!First->OperatorDelete7.00k
) {
2181
7.00k
    First->OperatorDelete = OD;
2182
7.00k
    if (auto *L = getASTMutationListener())
2183
8
      L->ResolvedOperatorDelete(First, OD);
2184
7.00k
  }
2185
7.00k
}
2186
2187
0
void CXXConversionDecl::anchor() { }
2188
2189
CXXConversionDecl *
2190
160
CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2191
160
  return new (C, ID) CXXConversionDecl(C, nullptr, SourceLocation(),
2192
160
                                       DeclarationNameInfo(), QualType(),
2193
160
                                       nullptr, false, false, false,
2194
160
                                       SourceLocation());
2195
160
}
2196
2197
CXXConversionDecl *
2198
CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD,
2199
                          SourceLocation StartLoc,
2200
                          const DeclarationNameInfo &NameInfo,
2201
                          QualType T, TypeSourceInfo *TInfo,
2202
                          bool isInline, bool isExplicit,
2203
8.08k
                          bool isConstexpr, SourceLocation EndLocation) {
2204
8.08k
  assert(NameInfo.getName().getNameKind()
2205
8.08k
         == DeclarationName::CXXConversionFunctionName &&
2206
8.08k
         "Name must refer to a conversion function");
2207
8.08k
  return new (C, RD) CXXConversionDecl(C, RD, StartLoc, NameInfo, T, TInfo,
2208
8.08k
                                       isInline, isExplicit, isConstexpr,
2209
8.08k
                                       EndLocation);
2210
8.08k
}
2211
2212
305
bool CXXConversionDecl::isLambdaToBlockPointerConversion() const {
2213
305
  return isImplicit() && getParent()->isLambda() &&
2214
305
         getConversionType()->isBlockPointerType();
2215
305
}
2216
2217
0
void LinkageSpecDecl::anchor() { }
2218
2219
LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
2220
                                         DeclContext *DC,
2221
                                         SourceLocation ExternLoc,
2222
                                         SourceLocation LangLoc,
2223
                                         LanguageIDs Lang,
2224
76.6k
                                         bool HasBraces) {
2225
76.6k
  return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces);
2226
76.6k
}
2227
2228
LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C,
2229
168
                                                     unsigned ID) {
2230
168
  return new (C, ID) LinkageSpecDecl(nullptr, SourceLocation(),
2231
168
                                     SourceLocation(), lang_c, false);
2232
168
}
2233
2234
0
void UsingDirectiveDecl::anchor() { }
2235
2236
UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
2237
                                               SourceLocation L,
2238
                                               SourceLocation NamespaceLoc,
2239
                                           NestedNameSpecifierLoc QualifierLoc,
2240
                                               SourceLocation IdentLoc,
2241
                                               NamedDecl *Used,
2242
7.46k
                                               DeclContext *CommonAncestor) {
2243
7.46k
  if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used))
2244
7.45k
    Used = NS->getOriginalNamespace();
2245
7.46k
  return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc,
2246
7.46k
                                        IdentLoc, Used, CommonAncestor);
2247
7.46k
}
2248
2249
UsingDirectiveDecl *UsingDirectiveDecl::CreateDeserialized(ASTContext &C,
2250
41
                                                           unsigned ID) {
2251
41
  return new (C, ID) UsingDirectiveDecl(nullptr, SourceLocation(),
2252
41
                                        SourceLocation(),
2253
41
                                        NestedNameSpecifierLoc(),
2254
41
                                        SourceLocation(), nullptr, nullptr);
2255
41
}
2256
2257
1.98M
NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() {
2258
1.98M
  if (NamespaceAliasDecl *NA =
2259
1.98M
        dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace))
2260
1.08k
    return NA->getNamespace();
2261
1.98M
  return cast_or_null<NamespaceDecl>(NominatedNamespace);
2262
1.98M
}
2263
2264
NamespaceDecl::NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
2265
                             SourceLocation StartLoc, SourceLocation IdLoc,
2266
                             IdentifierInfo *Id, NamespaceDecl *PrevDecl)
2267
    : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace),
2268
      redeclarable_base(C), LocStart(StartLoc), RBraceLoc(),
2269
37.2k
      AnonOrFirstNamespaceAndInline(nullptr, Inline) {
2270
37.2k
  setPreviousDecl(PrevDecl);
2271
37.2k
2272
37.2k
  if (PrevDecl)
2273
12.2k
    AnonOrFirstNamespaceAndInline.setPointer(PrevDecl->getOriginalNamespace());
2274
37.2k
}
2275
2276
NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC,
2277
                                     bool Inline, SourceLocation StartLoc,
2278
                                     SourceLocation IdLoc, IdentifierInfo *Id,
2279
36.4k
                                     NamespaceDecl *PrevDecl) {
2280
36.4k
  return new (C, DC) NamespaceDecl(C, DC, Inline, StartLoc, IdLoc, Id,
2281
36.4k
                                   PrevDecl);
2282
36.4k
}
2283
2284
798
NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2285
798
  return new (C, ID) NamespaceDecl(C, nullptr, false, SourceLocation(),
2286
798
                                   SourceLocation(), nullptr, nullptr);
2287
798
}
2288
2289
44.4M
NamespaceDecl *NamespaceDecl::getOriginalNamespace() {
2290
44.4M
  if (isFirstDecl())
2291
25.1M
    return this;
2292
19.2M
2293
19.2M
  return AnonOrFirstNamespaceAndInline.getPointer();
2294
19.2M
}
2295
2296
357k
const NamespaceDecl *NamespaceDecl::getOriginalNamespace() const {
2297
357k
  if (isFirstDecl())
2298
39.9k
    return this;
2299
317k
2300
317k
  return AnonOrFirstNamespaceAndInline.getPointer();
2301
317k
}
2302
2303
689
bool NamespaceDecl::isOriginalNamespace() const { return isFirstDecl(); }
2304
2305
11.0k
NamespaceDecl *NamespaceDecl::getNextRedeclarationImpl() {
2306
11.0k
  return getNextRedeclaration();
2307
11.0k
}
2308
657
NamespaceDecl *NamespaceDecl::getPreviousDeclImpl() {
2309
657
  return getPreviousDecl();
2310
657
}
2311
35.9k
NamespaceDecl *NamespaceDecl::getMostRecentDeclImpl() {
2312
35.9k
  return getMostRecentDecl();
2313
35.9k
}
2314
2315
0
void NamespaceAliasDecl::anchor() { }
2316
2317
44
NamespaceAliasDecl *NamespaceAliasDecl::getNextRedeclarationImpl() {
2318
44
  return getNextRedeclaration();
2319
44
}
2320
0
NamespaceAliasDecl *NamespaceAliasDecl::getPreviousDeclImpl() {
2321
0
  return getPreviousDecl();
2322
0
}
2323
66
NamespaceAliasDecl *NamespaceAliasDecl::getMostRecentDeclImpl() {
2324
66
  return getMostRecentDecl();
2325
66
}
2326
2327
NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC,
2328
                                               SourceLocation UsingLoc,
2329
                                               SourceLocation AliasLoc,
2330
                                               IdentifierInfo *Alias,
2331
                                           NestedNameSpecifierLoc QualifierLoc,
2332
                                               SourceLocation IdentLoc,
2333
130
                                               NamedDecl *Namespace) {
2334
130
  // FIXME: Preserve the aliased namespace as written.
2335
130
  if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace))
2336
115
    Namespace = NS->getOriginalNamespace();
2337
130
  return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias,
2338
130
                                        QualifierLoc, IdentLoc, Namespace);
2339
130
}
2340
2341
NamespaceAliasDecl *
2342
8
NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2343
8
  return new (C, ID) NamespaceAliasDecl(C, nullptr, SourceLocation(),
2344
8
                                        SourceLocation(), nullptr,
2345
8
                                        NestedNameSpecifierLoc(),
2346
8
                                        SourceLocation(), nullptr);
2347
8
}
2348
2349
0
void UsingShadowDecl::anchor() { }
2350
2351
UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC,
2352
                                 SourceLocation Loc, UsingDecl *Using,
2353
                                 NamedDecl *Target)
2354
    : NamedDecl(K, DC, Loc, Using ? Using->getDeclName() : DeclarationName()),
2355
      redeclarable_base(C), Underlying(Target),
2356
2.95k
      UsingOrNextShadow(cast<NamedDecl>(Using)) {
2357
2.95k
  if (Target)
2358
2.95k
    IdentifierNamespace = Target->getIdentifierNamespace();
2359
2.95k
  setImplicit();
2360
2.95k
}
2361
2362
UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, EmptyShell Empty)
2363
    : NamedDecl(K, nullptr, SourceLocation(), DeclarationName()),
2364
341
      redeclarable_base(C), Underlying(), UsingOrNextShadow() {}
2365
2366
UsingShadowDecl *
2367
289
UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2368
289
  return new (C, ID) UsingShadowDecl(UsingShadow, C, EmptyShell());
2369
289
}
2370
2371
1.40k
UsingDecl *UsingShadowDecl::getUsingDecl() const {
2372
1.40k
  const UsingShadowDecl *Shadow = this;
2373
2.02k
  while (const UsingShadowDecl *NextShadow =
2374
1.40k
         dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow))
2375
621
    Shadow = NextShadow;
2376
1.40k
  return cast<UsingDecl>(Shadow->UsingOrNextShadow);
2377
1.40k
}
2378
2379
0
void ConstructorUsingShadowDecl::anchor() { }
2380
2381
ConstructorUsingShadowDecl *
2382
ConstructorUsingShadowDecl::Create(ASTContext &C, DeclContext *DC,
2383
                                   SourceLocation Loc, UsingDecl *Using,
2384
1.10k
                                   NamedDecl *Target, bool IsVirtual) {
2385
1.10k
  return new (C, DC) ConstructorUsingShadowDecl(C, DC, Loc, Using, Target,
2386
1.10k
                                                IsVirtual);
2387
1.10k
}
2388
2389
ConstructorUsingShadowDecl *
2390
52
ConstructorUsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2391
52
  return new (C, ID) ConstructorUsingShadowDecl(C, EmptyShell());
2392
52
}
2393
2394
646
CXXRecordDecl *ConstructorUsingShadowDecl::getNominatedBaseClass() const {
2395
646
  return getUsingDecl()->getQualifier()->getAsRecordDecl();
2396
646
}
2397
2398
0
void UsingDecl::anchor() { }
2399
2400
2.95k
void UsingDecl::addShadowDecl(UsingShadowDecl *S) {
2401
2.95k
  assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() &&
2402
2.95k
         "declaration already in set");
2403
2.95k
  assert(S->getUsingDecl() == this);
2404
2.95k
2405
2.95k
  if (FirstUsingShadow.getPointer())
2406
969
    S->UsingOrNextShadow = FirstUsingShadow.getPointer();
2407
2.95k
  FirstUsingShadow.setPointer(S);
2408
2.95k
}
2409
2410
156
void UsingDecl::removeShadowDecl(UsingShadowDecl *S) {
2411
156
  assert(std::find(shadow_begin(), shadow_end(), S) != shadow_end() &&
2412
156
         "declaration not in set");
2413
156
  assert(S->getUsingDecl() == this);
2414
156
2415
156
  // Remove S from the shadow decl chain. This is O(n) but hopefully rare.
2416
156
2417
156
  if (
FirstUsingShadow.getPointer() == S156
) {
2418
31
    FirstUsingShadow.setPointer(
2419
31
      dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow));
2420
31
    S->UsingOrNextShadow = this;
2421
31
    return;
2422
31
  }
2423
125
2424
125
  UsingShadowDecl *Prev = FirstUsingShadow.getPointer();
2425
290
  while (Prev->UsingOrNextShadow != S)
2426
165
    Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow);
2427
156
  Prev->UsingOrNextShadow = S->UsingOrNextShadow;
2428
156
  S->UsingOrNextShadow = this;
2429
156
}
2430
2431
UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL,
2432
                             NestedNameSpecifierLoc QualifierLoc,
2433
                             const DeclarationNameInfo &NameInfo,
2434
2.10k
                             bool HasTypename) {
2435
2.10k
  return new (C, DC) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename);
2436
2.10k
}
2437
2438
303
UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2439
303
  return new (C, ID) UsingDecl(nullptr, SourceLocation(),
2440
303
                               NestedNameSpecifierLoc(), DeclarationNameInfo(),
2441
303
                               false);
2442
303
}
2443
2444
59
SourceRange UsingDecl::getSourceRange() const {
2445
59
  SourceLocation Begin = isAccessDeclaration()
2446
59
    ? 
getQualifierLoc().getBeginLoc()1
:
UsingLocation58
;
2447
59
  return SourceRange(Begin, getNameInfo().getEndLoc());
2448
59
}
2449
2450
0
void UsingPackDecl::anchor() { }
2451
2452
UsingPackDecl *UsingPackDecl::Create(ASTContext &C, DeclContext *DC,
2453
                                     NamedDecl *InstantiatedFrom,
2454
44
                                     ArrayRef<NamedDecl *> UsingDecls) {
2455
44
  size_t Extra = additionalSizeToAlloc<NamedDecl *>(UsingDecls.size());
2456
44
  return new (C, DC, Extra) UsingPackDecl(DC, InstantiatedFrom, UsingDecls);
2457
44
}
2458
2459
UsingPackDecl *UsingPackDecl::CreateDeserialized(ASTContext &C, unsigned ID,
2460
1
                                                 unsigned NumExpansions) {
2461
1
  size_t Extra = additionalSizeToAlloc<NamedDecl *>(NumExpansions);
2462
1
  auto *Result = new (C, ID, Extra) UsingPackDecl(nullptr, nullptr, None);
2463
1
  Result->NumExpansions = NumExpansions;
2464
1
  auto *Trail = Result->getTrailingObjects<NamedDecl *>();
2465
4
  for (unsigned I = 0; 
I != NumExpansions4
;
++I3
)
2466
3
    new (Trail + I) NamedDecl*(nullptr);
2467
1
  return Result;
2468
1
}
2469
2470
0
void UnresolvedUsingValueDecl::anchor() { }
2471
2472
UnresolvedUsingValueDecl *
2473
UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC,
2474
                                 SourceLocation UsingLoc,
2475
                                 NestedNameSpecifierLoc QualifierLoc,
2476
                                 const DeclarationNameInfo &NameInfo,
2477
484
                                 SourceLocation EllipsisLoc) {
2478
484
  return new (C, DC) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc,
2479
484
                                              QualifierLoc, NameInfo,
2480
484
                                              EllipsisLoc);
2481
484
}
2482
2483
UnresolvedUsingValueDecl *
2484
42
UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2485
42
  return new (C, ID) UnresolvedUsingValueDecl(nullptr, QualType(),
2486
42
                                              SourceLocation(),
2487
42
                                              NestedNameSpecifierLoc(),
2488
42
                                              DeclarationNameInfo(),
2489
42
                                              SourceLocation());
2490
42
}
2491
2492
73
SourceRange UnresolvedUsingValueDecl::getSourceRange() const {
2493
73
  SourceLocation Begin = isAccessDeclaration()
2494
73
    ? 
getQualifierLoc().getBeginLoc()1
:
UsingLocation72
;
2495
73
  return SourceRange(Begin, getNameInfo().getEndLoc());
2496
73
}
2497
2498
0
void UnresolvedUsingTypenameDecl::anchor() { }
2499
2500
UnresolvedUsingTypenameDecl *
2501
UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC,
2502
                                    SourceLocation UsingLoc,
2503
                                    SourceLocation TypenameLoc,
2504
                                    NestedNameSpecifierLoc QualifierLoc,
2505
                                    SourceLocation TargetNameLoc,
2506
                                    DeclarationName TargetName,
2507
88
                                    SourceLocation EllipsisLoc) {
2508
88
  return new (C, DC) UnresolvedUsingTypenameDecl(
2509
88
      DC, UsingLoc, TypenameLoc, QualifierLoc, TargetNameLoc,
2510
88
      TargetName.getAsIdentifierInfo(), EllipsisLoc);
2511
88
}
2512
2513
UnresolvedUsingTypenameDecl *
2514
37
UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2515
37
  return new (C, ID) UnresolvedUsingTypenameDecl(
2516
37
      nullptr, SourceLocation(), SourceLocation(), NestedNameSpecifierLoc(),
2517
37
      SourceLocation(), nullptr, SourceLocation());
2518
37
}
2519
2520
0
void StaticAssertDecl::anchor() { }
2521
2522
StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC,
2523
                                           SourceLocation StaticAssertLoc,
2524
                                           Expr *AssertExpr,
2525
                                           StringLiteral *Message,
2526
                                           SourceLocation RParenLoc,
2527
4.62k
                                           bool Failed) {
2528
4.62k
  return new (C, DC) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message,
2529
4.62k
                                      RParenLoc, Failed);
2530
4.62k
}
2531
2532
StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C,
2533
21
                                                       unsigned ID) {
2534
21
  return new (C, ID) StaticAssertDecl(nullptr, SourceLocation(), nullptr,
2535
21
                                      nullptr, SourceLocation(), false);
2536
21
}
2537
2538
0
void BindingDecl::anchor() {}
2539
2540
BindingDecl *BindingDecl::Create(ASTContext &C, DeclContext *DC,
2541
273
                                 SourceLocation IdLoc, IdentifierInfo *Id) {
2542
273
  return new (C, DC) BindingDecl(DC, IdLoc, Id);
2543
273
}
2544
2545
4
BindingDecl *BindingDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
2546
4
  return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr);
2547
4
}
2548
2549
53
VarDecl *BindingDecl::getHoldingVar() const {
2550
53
  Expr *B = getBinding();
2551
53
  if (!B)
2552
0
    return nullptr;
2553
53
  auto *DRE = dyn_cast<DeclRefExpr>(B->IgnoreImplicit());
2554
53
  if (!DRE)
2555
34
    return nullptr;
2556
19
2557
19
  auto *VD = dyn_cast<VarDecl>(DRE->getDecl());
2558
19
  assert(VD->isImplicit() && "holding var for binding decl not implicit");
2559
19
  return VD;
2560
19
}
2561
2562
0
void DecompositionDecl::anchor() {}
2563
2564
DecompositionDecl *DecompositionDecl::Create(ASTContext &C, DeclContext *DC,
2565
                                             SourceLocation StartLoc,
2566
                                             SourceLocation LSquareLoc,
2567
                                             QualType T, TypeSourceInfo *TInfo,
2568
                                             StorageClass SC,
2569
154
                                             ArrayRef<BindingDecl *> Bindings) {
2570
154
  size_t Extra = additionalSizeToAlloc<BindingDecl *>(Bindings.size());
2571
154
  return new (C, DC, Extra)
2572
154
      DecompositionDecl(C, DC, StartLoc, LSquareLoc, T, TInfo, SC, Bindings);
2573
154
}
2574
2575
DecompositionDecl *DecompositionDecl::CreateDeserialized(ASTContext &C,
2576
                                                         unsigned ID,
2577
2
                                                         unsigned NumBindings) {
2578
2
  size_t Extra = additionalSizeToAlloc<BindingDecl *>(NumBindings);
2579
2
  auto *Result = new (C, ID, Extra)
2580
2
      DecompositionDecl(C, nullptr, SourceLocation(), SourceLocation(),
2581
2
                        QualType(), nullptr, StorageClass(), None);
2582
2
  // Set up and clean out the bindings array.
2583
2
  Result->NumBindings = NumBindings;
2584
2
  auto *Trail = Result->getTrailingObjects<BindingDecl *>();
2585
6
  for (unsigned I = 0; 
I != NumBindings6
;
++I4
)
2586
4
    new (Trail + I) BindingDecl*(nullptr);
2587
2
  return Result;
2588
2
}
2589
2590
8
void DecompositionDecl::printName(llvm::raw_ostream &os) const {
2591
8
  os << '[';
2592
8
  bool Comma = false;
2593
8
  for (auto *B : bindings()) {
2594
8
    if (Comma)
2595
0
      os << ", ";
2596
8
    B->printName(os);
2597
8
    Comma = true;
2598
8
  }
2599
8
  os << ']';
2600
8
}
2601
2602
MSPropertyDecl *MSPropertyDecl::Create(ASTContext &C, DeclContext *DC,
2603
                                       SourceLocation L, DeclarationName N,
2604
                                       QualType T, TypeSourceInfo *TInfo,
2605
                                       SourceLocation StartL,
2606
                                       IdentifierInfo *Getter,
2607
123
                                       IdentifierInfo *Setter) {
2608
123
  return new (C, DC) MSPropertyDecl(DC, L, N, T, TInfo, StartL, Getter, Setter);
2609
123
}
2610
2611
MSPropertyDecl *MSPropertyDecl::CreateDeserialized(ASTContext &C,
2612
11
                                                   unsigned ID) {
2613
11
  return new (C, ID) MSPropertyDecl(nullptr, SourceLocation(),
2614
11
                                    DeclarationName(), QualType(), nullptr,
2615
11
                                    SourceLocation(), nullptr, nullptr);
2616
11
}
2617
2618
12
static const char *getAccessName(AccessSpecifier AS) {
2619
12
  switch (AS) {
2620
0
    case AS_none:
2621
0
      llvm_unreachable("Invalid access specifier!");
2622
5
    case AS_public:
2623
5
      return "public";
2624
5
    case AS_private:
2625
5
      return "private";
2626
2
    case AS_protected:
2627
2
      return "protected";
2628
0
  }
2629
0
  
llvm_unreachable0
("Invalid access specifier!");
2630
0
}
2631
2632
const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
2633
8
                                           AccessSpecifier AS) {
2634
8
  return DB << getAccessName(AS);
2635
8
}
2636
2637
const PartialDiagnostic &clang::operator<<(const PartialDiagnostic &DB,
2638
4
                                           AccessSpecifier AS) {
2639
4
  return DB << getAccessName(AS);
2640
4
}