Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/DeclCXX.h
Line
Count
Source (jump to first uncovered line)
1
//===- DeclCXX.h - Classes for representing C++ declarations --*- C++ -*-=====//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
/// \file
10
/// Defines the C++ Decl subclasses, other than those for templates
11
/// (found in DeclTemplate.h) and friends (in DeclFriend.h).
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_AST_DECLCXX_H
16
#define LLVM_CLANG_AST_DECLCXX_H
17
18
#include "clang/AST/ASTUnresolvedSet.h"
19
#include "clang/AST/Decl.h"
20
#include "clang/AST/DeclBase.h"
21
#include "clang/AST/DeclarationName.h"
22
#include "clang/AST/Expr.h"
23
#include "clang/AST/ExternalASTSource.h"
24
#include "clang/AST/LambdaCapture.h"
25
#include "clang/AST/NestedNameSpecifier.h"
26
#include "clang/AST/Redeclarable.h"
27
#include "clang/AST/Stmt.h"
28
#include "clang/AST/Type.h"
29
#include "clang/AST/TypeLoc.h"
30
#include "clang/AST/UnresolvedSet.h"
31
#include "clang/Basic/LLVM.h"
32
#include "clang/Basic/Lambda.h"
33
#include "clang/Basic/LangOptions.h"
34
#include "clang/Basic/OperatorKinds.h"
35
#include "clang/Basic/SourceLocation.h"
36
#include "clang/Basic/Specifiers.h"
37
#include "llvm/ADT/ArrayRef.h"
38
#include "llvm/ADT/DenseMap.h"
39
#include "llvm/ADT/PointerIntPair.h"
40
#include "llvm/ADT/PointerUnion.h"
41
#include "llvm/ADT/STLExtras.h"
42
#include "llvm/ADT/TinyPtrVector.h"
43
#include "llvm/ADT/iterator_range.h"
44
#include "llvm/Support/Casting.h"
45
#include "llvm/Support/Compiler.h"
46
#include "llvm/Support/PointerLikeTypeTraits.h"
47
#include "llvm/Support/TrailingObjects.h"
48
#include <cassert>
49
#include <cstddef>
50
#include <iterator>
51
#include <memory>
52
#include <vector>
53
54
namespace clang {
55
56
class ASTContext;
57
class ClassTemplateDecl;
58
class ConstructorUsingShadowDecl;
59
class CXXBasePath;
60
class CXXBasePaths;
61
class CXXConstructorDecl;
62
class CXXDestructorDecl;
63
class CXXFinalOverriderMap;
64
class CXXIndirectPrimaryBaseSet;
65
class CXXMethodDecl;
66
class DecompositionDecl;
67
class FriendDecl;
68
class FunctionTemplateDecl;
69
class IdentifierInfo;
70
class MemberSpecializationInfo;
71
class BaseUsingDecl;
72
class TemplateDecl;
73
class TemplateParameterList;
74
class UsingDecl;
75
76
/// Represents an access specifier followed by colon ':'.
77
///
78
/// An objects of this class represents sugar for the syntactic occurrence
79
/// of an access specifier followed by a colon in the list of member
80
/// specifiers of a C++ class definition.
81
///
82
/// Note that they do not represent other uses of access specifiers,
83
/// such as those occurring in a list of base specifiers.
84
/// Also note that this class has nothing to do with so-called
85
/// "access declarations" (C++98 11.3 [class.access.dcl]).
86
class AccessSpecDecl : public Decl {
87
  /// The location of the ':'.
88
  SourceLocation ColonLoc;
89
90
  AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
91
                 SourceLocation ASLoc, SourceLocation ColonLoc)
92
462k
    : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
93
462k
    setAccess(AS);
94
462k
  }
95
96
66.9k
  AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {}
97
98
  virtual void anchor();
99
100
public:
101
  /// The location of the access specifier.
102
187k
  SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
103
104
  /// Sets the location of the access specifier.
105
0
  void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
106
107
  /// The location of the colon following the access specifier.
108
294k
  SourceLocation getColonLoc() const { return ColonLoc; }
109
110
  /// Sets the location of the colon.
111
66.9k
  void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
112
113
495
  SourceRange getSourceRange() const override LLVM_READONLY {
114
495
    return SourceRange(getAccessSpecifierLoc(), getColonLoc());
115
495
  }
116
117
  static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
118
                                DeclContext *DC, SourceLocation ASLoc,
119
462k
                                SourceLocation ColonLoc) {
120
462k
    return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
121
462k
  }
122
123
  static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
124
125
  // Implement isa/cast/dyncast/etc.
126
25.2k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
127
25.2k
  static bool classofKind(Kind K) { return K == AccessSpec; }
128
};
129
130
/// Represents a base class of a C++ class.
131
///
132
/// Each CXXBaseSpecifier represents a single, direct base class (or
133
/// struct) of a C++ class (or struct). It specifies the type of that
134
/// base class, whether it is a virtual or non-virtual base, and what
135
/// level of access (public, protected, private) is used for the
136
/// derivation. For example:
137
///
138
/// \code
139
///   class A { };
140
///   class B { };
141
///   class C : public virtual A, protected B { };
142
/// \endcode
143
///
144
/// In this code, C will have two CXXBaseSpecifiers, one for "public
145
/// virtual A" and the other for "protected B".
146
class CXXBaseSpecifier {
147
  /// The source code range that covers the full base
148
  /// specifier, including the "virtual" (if present) and access
149
  /// specifier (if present).
150
  SourceRange Range;
151
152
  /// The source location of the ellipsis, if this is a pack
153
  /// expansion.
154
  SourceLocation EllipsisLoc;
155
156
  /// Whether this is a virtual base class or not.
157
  unsigned Virtual : 1;
158
159
  /// Whether this is the base of a class (true) or of a struct (false).
160
  ///
161
  /// This determines the mapping from the access specifier as written in the
162
  /// source code to the access specifier used for semantic analysis.
163
  unsigned BaseOfClass : 1;
164
165
  /// Access specifier as written in the source code (may be AS_none).
166
  ///
167
  /// The actual type of data stored here is an AccessSpecifier, but we use
168
  /// "unsigned" here to work around a VC++ bug.
169
  unsigned Access : 2;
170
171
  /// Whether the class contains a using declaration
172
  /// to inherit the named class's constructors.
173
  unsigned InheritConstructors : 1;
174
175
  /// The type of the base class.
176
  ///
177
  /// This will be a class or struct (or a typedef of such). The source code
178
  /// range does not include the \c virtual or the access specifier.
179
  TypeSourceInfo *BaseTypeInfo;
180
181
public:
182
761k
  CXXBaseSpecifier() = default;
183
  CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
184
                   TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
185
    : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
186
667k
      Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {}
187
188
  /// Retrieves the source range that contains the entire base specifier.
189
670k
  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
190
99.9k
  SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
191
12
  SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
192
193
  /// Get the location at which the base class type was written.
194
41.1k
  SourceLocation getBaseTypeLoc() const LLVM_READONLY {
195
41.1k
    return BaseTypeInfo->getTypeLoc().getBeginLoc();
196
41.1k
  }
197
198
  /// Determines whether the base class is a virtual base class (or not).
199
9.86M
  bool isVirtual() const { return Virtual; }
200
201
  /// Determine whether this base class is a base of a class declared
202
  /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
203
85.1k
  bool isBaseOfClass() const { return BaseOfClass; }
204
205
  /// Determine whether this base specifier is a pack expansion.
206
364k
  bool isPackExpansion() const { return EllipsisLoc.isValid(); }
207
208
  /// Determine whether this base class's constructors get inherited.
209
28.6k
  bool getInheritConstructors() const { return InheritConstructors; }
210
211
  /// Set that this base class's constructors should be inherited.
212
62.0k
  void setInheritConstructors(bool Inherit = true) {
213
62.0k
    InheritConstructors = Inherit;
214
62.0k
  }
215
216
  /// For a pack expansion, determine the location of the ellipsis.
217
3.90k
  SourceLocation getEllipsisLoc() const {
218
3.90k
    return EllipsisLoc;
219
3.90k
  }
220
221
  /// Returns the access specifier for this base specifier.
222
  ///
223
  /// This is the actual base specifier as used for semantic analysis, so
224
  /// the result can never be AS_none. To retrieve the access specifier as
225
  /// written in the source code, use getAccessSpecifierAsWritten().
226
2.11M
  AccessSpecifier getAccessSpecifier() const {
227
2.11M
    if ((AccessSpecifier)Access == AS_none)
228
804k
      return BaseOfClass? 
AS_private6.07k
:
AS_public798k
;
229
1.31M
    else
230
1.31M
      return (AccessSpecifier)Access;
231
2.11M
  }
232
233
  /// Retrieves the access specifier as written in the source code
234
  /// (which may mean that no access specifier was explicitly written).
235
  ///
236
  /// Use getAccessSpecifier() to retrieve the access specifier for use in
237
  /// semantic analysis.
238
373k
  AccessSpecifier getAccessSpecifierAsWritten() const {
239
373k
    return (AccessSpecifier)Access;
240
373k
  }
241
242
  /// Retrieves the type of the base class.
243
  ///
244
  /// This type will always be an unqualified class type.
245
19.6M
  QualType getType() const {
246
19.6M
    return BaseTypeInfo->getType().getUnqualifiedType();
247
19.6M
  }
248
249
  /// Retrieves the type and source location of the base class.
250
439k
  TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
251
};
252
253
/// Represents a C++ struct/union/class.
254
class CXXRecordDecl : public RecordDecl {
255
  friend class ASTDeclReader;
256
  friend class ASTDeclWriter;
257
  friend class ASTNodeImporter;
258
  friend class ASTReader;
259
  friend class ASTRecordWriter;
260
  friend class ASTWriter;
261
  friend class DeclContext;
262
  friend class LambdaExpr;
263
264
  friend void FunctionDecl::setPure(bool);
265
  friend void TagDecl::startDefinition();
266
267
  /// Values used in DefinitionData fields to represent special members.
268
  enum SpecialMemberFlags {
269
    SMF_DefaultConstructor = 0x1,
270
    SMF_CopyConstructor = 0x2,
271
    SMF_MoveConstructor = 0x4,
272
    SMF_CopyAssignment = 0x8,
273
    SMF_MoveAssignment = 0x10,
274
    SMF_Destructor = 0x20,
275
    SMF_All = 0x3f
276
  };
277
278
public:
279
  enum LambdaDependencyKind {
280
    LDK_Unknown = 0,
281
    LDK_AlwaysDependent,
282
    LDK_NeverDependent,
283
  };
284
285
private:
286
  struct DefinitionData {
287
    #define FIELD(Name, Width, Merge) \
288
    unsigned Name : Width;
289
    #include "CXXRecordDeclDefinitionBits.def"
290
291
    /// Whether this class describes a C++ lambda.
292
    unsigned IsLambda : 1;
293
294
    /// Whether we are currently parsing base specifiers.
295
    unsigned IsParsingBaseSpecifiers : 1;
296
297
    /// True when visible conversion functions are already computed
298
    /// and are available.
299
    unsigned ComputedVisibleConversions : 1;
300
301
    unsigned HasODRHash : 1;
302
303
    /// A hash of parts of the class to help in ODR checking.
304
    unsigned ODRHash = 0;
305
306
    /// The number of base class specifiers in Bases.
307
    unsigned NumBases = 0;
308
309
    /// The number of virtual base class specifiers in VBases.
310
    unsigned NumVBases = 0;
311
312
    /// Base classes of this class.
313
    ///
314
    /// FIXME: This is wasted space for a union.
315
    LazyCXXBaseSpecifiersPtr Bases;
316
317
    /// direct and indirect virtual base classes of this class.
318
    LazyCXXBaseSpecifiersPtr VBases;
319
320
    /// The conversion functions of this C++ class (but not its
321
    /// inherited conversion functions).
322
    ///
323
    /// Each of the entries in this overload set is a CXXConversionDecl.
324
    LazyASTUnresolvedSet Conversions;
325
326
    /// The conversion functions of this C++ class and all those
327
    /// inherited conversion functions that are visible in this class.
328
    ///
329
    /// Each of the entries in this overload set is a CXXConversionDecl or a
330
    /// FunctionTemplateDecl.
331
    LazyASTUnresolvedSet VisibleConversions;
332
333
    /// The declaration which defines this record.
334
    CXXRecordDecl *Definition;
335
336
    /// The first friend declaration in this class, or null if there
337
    /// aren't any.
338
    ///
339
    /// This is actually currently stored in reverse order.
340
    LazyDeclPtr FirstFriend;
341
342
    DefinitionData(CXXRecordDecl *D);
343
344
    /// Retrieve the set of direct base classes.
345
50.2M
    CXXBaseSpecifier *getBases() const {
346
50.2M
      if (!Bases.isOffset())
347
50.1M
        return Bases.get(nullptr);
348
54.5k
      return getBasesSlowCase();
349
50.2M
    }
350
351
    /// Retrieve the set of virtual base classes.
352
3.95M
    CXXBaseSpecifier *getVBases() const {
353
3.95M
      if (!VBases.isOffset())
354
3.95M
        return VBases.get(nullptr);
355
13
      return getVBasesSlowCase();
356
3.95M
    }
357
358
24.9k
    ArrayRef<CXXBaseSpecifier> bases() const {
359
24.9k
      return llvm::makeArrayRef(getBases(), NumBases);
360
24.9k
    }
361
362
117
    ArrayRef<CXXBaseSpecifier> vbases() const {
363
117
      return llvm::makeArrayRef(getVBases(), NumVBases);
364
117
    }
365
366
  private:
367
    CXXBaseSpecifier *getBasesSlowCase() const;
368
    CXXBaseSpecifier *getVBasesSlowCase() const;
369
  };
370
371
  struct DefinitionData *DefinitionData;
372
373
  /// Describes a C++ closure type (generated by a lambda expression).
374
  struct LambdaDefinitionData : public DefinitionData {
375
    using Capture = LambdaCapture;
376
377
    /// Whether this lambda is known to be dependent, even if its
378
    /// context isn't dependent.
379
    ///
380
    /// A lambda with a non-dependent context can be dependent if it occurs
381
    /// within the default argument of a function template, because the
382
    /// lambda will have been created with the enclosing context as its
383
    /// declaration context, rather than function. This is an unfortunate
384
    /// artifact of having to parse the default arguments before.
385
    unsigned DependencyKind : 2;
386
387
    /// Whether this lambda is a generic lambda.
388
    unsigned IsGenericLambda : 1;
389
390
    /// The Default Capture.
391
    unsigned CaptureDefault : 2;
392
393
    /// The number of captures in this lambda is limited 2^NumCaptures.
394
    unsigned NumCaptures : 15;
395
396
    /// The number of explicit captures in this lambda.
397
    unsigned NumExplicitCaptures : 13;
398
399
    /// Has known `internal` linkage.
400
    unsigned HasKnownInternalLinkage : 1;
401
402
    /// The number used to indicate this lambda expression for name
403
    /// mangling in the Itanium C++ ABI.
404
    unsigned ManglingNumber : 31;
405
406
    /// The declaration that provides context for this lambda, if the
407
    /// actual DeclContext does not suffice. This is used for lambdas that
408
    /// occur within default arguments of function parameters within the class
409
    /// or within a data member initializer.
410
    LazyDeclPtr ContextDecl;
411
412
    /// The list of captures, both explicit and implicit, for this
413
    /// lambda.
414
    Capture *Captures = nullptr;
415
416
    /// The type of the call method.
417
    TypeSourceInfo *MethodTyInfo;
418
419
    LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, unsigned DK,
420
                         bool IsGeneric, LambdaCaptureDefault CaptureDefault)
421
        : DefinitionData(D), DependencyKind(DK), IsGenericLambda(IsGeneric),
422
          CaptureDefault(CaptureDefault), NumCaptures(0),
423
          NumExplicitCaptures(0), HasKnownInternalLinkage(0), ManglingNumber(0),
424
11.8k
          MethodTyInfo(Info) {
425
11.8k
      IsLambda = true;
426
427
      // C++1z [expr.prim.lambda]p4:
428
      //   This class type is not an aggregate type.
429
11.8k
      Aggregate = false;
430
11.8k
      PlainOldData = false;
431
11.8k
    }
432
  };
433
434
330M
  struct DefinitionData *dataPtr() const {
435
    // Complete the redecl chain (if necessary).
436
330M
    getMostRecentDecl();
437
330M
    return DefinitionData;
438
330M
  }
439
440
328M
  struct DefinitionData &data() const {
441
328M
    auto *DD = dataPtr();
442
328M
    assert(DD && "queried property of class with no definition");
443
0
    return *DD;
444
328M
  }
445
446
1.17M
  struct LambdaDefinitionData &getLambdaData() const {
447
    // No update required: a merged definition cannot change any lambda
448
    // properties.
449
1.17M
    auto *DD = DefinitionData;
450
1.17M
    assert(DD && DD->IsLambda && "queried lambda property of non-lambda class");
451
0
    return static_cast<LambdaDefinitionData&>(*DD);
452
1.17M
  }
453
454
  /// The template or declaration that this declaration
455
  /// describes or was instantiated from, respectively.
456
  ///
457
  /// For non-templates, this value will be null. For record
458
  /// declarations that describe a class template, this will be a
459
  /// pointer to a ClassTemplateDecl. For member
460
  /// classes of class template specializations, this will be the
461
  /// MemberSpecializationInfo referring to the member class that was
462
  /// instantiated or specialized.
463
  llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *>
464
      TemplateOrInstantiation;
465
466
  /// Called from setBases and addedMember to notify the class that a
467
  /// direct or virtual base class or a member of class type has been added.
468
  void addedClassSubobject(CXXRecordDecl *Base);
469
470
  /// Notify the class that member has been added.
471
  ///
472
  /// This routine helps maintain information about the class based on which
473
  /// members have been added. It will be invoked by DeclContext::addDecl()
474
  /// whenever a member is added to this record.
475
  void addedMember(Decl *D);
476
477
  void markedVirtualFunctionPure();
478
479
  /// Get the head of our list of friend declarations, possibly
480
  /// deserializing the friends from an external AST source.
481
  FriendDecl *getFirstFriend() const;
482
483
  /// Determine whether this class has an empty base class subobject of type X
484
  /// or of one of the types that might be at offset 0 within X (per the C++
485
  /// "standard layout" rules).
486
  bool hasSubobjectAtOffsetZeroOfEmptyBaseType(ASTContext &Ctx,
487
                                               const CXXRecordDecl *X);
488
489
protected:
490
  CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC,
491
                SourceLocation StartLoc, SourceLocation IdLoc,
492
                IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
493
494
public:
495
  /// Iterator that traverses the base classes of a class.
496
  using base_class_iterator = CXXBaseSpecifier *;
497
498
  /// Iterator that traverses the base classes of a class.
499
  using base_class_const_iterator = const CXXBaseSpecifier *;
500
501
52.6M
  CXXRecordDecl *getCanonicalDecl() override {
502
52.6M
    return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
503
52.6M
  }
504
505
8.34M
  const CXXRecordDecl *getCanonicalDecl() const {
506
8.34M
    return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl();
507
8.34M
  }
508
509
2.20M
  CXXRecordDecl *getPreviousDecl() {
510
2.20M
    return cast_or_null<CXXRecordDecl>(
511
2.20M
            static_cast<RecordDecl *>(this)->getPreviousDecl());
512
2.20M
  }
513
514
269k
  const CXXRecordDecl *getPreviousDecl() const {
515
269k
    return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
516
269k
  }
517
518
333M
  CXXRecordDecl *getMostRecentDecl() {
519
333M
    return cast<CXXRecordDecl>(
520
333M
            static_cast<RecordDecl *>(this)->getMostRecentDecl());
521
333M
  }
522
523
330M
  const CXXRecordDecl *getMostRecentDecl() const {
524
330M
    return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
525
330M
  }
526
527
2.60M
  CXXRecordDecl *getMostRecentNonInjectedDecl() {
528
2.60M
    CXXRecordDecl *Recent =
529
2.60M
        static_cast<CXXRecordDecl *>(this)->getMostRecentDecl();
530
2.60M
    while (Recent->isInjectedClassName()) {
531
      // FIXME: Does injected class name need to be in the redeclarations chain?
532
0
      assert(Recent->getPreviousDecl());
533
0
      Recent = Recent->getPreviousDecl();
534
0
    }
535
2.60M
    return Recent;
536
2.60M
  }
537
538
4.15k
  const CXXRecordDecl *getMostRecentNonInjectedDecl() const {
539
4.15k
    return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl();
540
4.15k
  }
541
542
102M
  CXXRecordDecl *getDefinition() const {
543
    // We only need an update if we don't already know which
544
    // declaration is the definition.
545
102M
    auto *DD = DefinitionData ? 
DefinitionData101M
:
dataPtr()1.50M
;
546
102M
    return DD ? 
DD->Definition101M
:
nullptr1.50M
;
547
102M
  }
548
549
5.81M
  bool hasDefinition() const { return DefinitionData || 
dataPtr()229k
; }
550
551
  static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
552
                               SourceLocation StartLoc, SourceLocation IdLoc,
553
                               IdentifierInfo *Id,
554
                               CXXRecordDecl *PrevDecl = nullptr,
555
                               bool DelayTypeCreation = false);
556
  static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
557
                                     TypeSourceInfo *Info, SourceLocation Loc,
558
                                     unsigned DependencyKind, bool IsGeneric,
559
                                     LambdaCaptureDefault CaptureDefault);
560
  static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
561
562
5.59M
  bool isDynamicClass() const {
563
5.59M
    return data().Polymorphic || 
data().NumVBases != 05.40M
;
564
5.59M
  }
565
566
  /// @returns true if class is dynamic or might be dynamic because the
567
  /// definition is incomplete of dependent.
568
26
  bool mayBeDynamicClass() const {
569
26
    return !hasDefinition() || 
isDynamicClass()16
||
hasAnyDependentBases()3
;
570
26
  }
571
572
  /// @returns true if class is non dynamic or might be non dynamic because the
573
  /// definition is incomplete of dependent.
574
13
  bool mayBeNonDynamicClass() const {
575
13
    return !hasDefinition() || 
!isDynamicClass()5
||
hasAnyDependentBases()3
;
576
13
  }
577
578
265k
  void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; }
579
580
2.06k
  bool isParsingBaseSpecifiers() const {
581
2.06k
    return data().IsParsingBaseSpecifiers;
582
2.06k
  }
583
584
  unsigned getODRHash() const;
585
586
  /// Sets the base classes of this struct or class.
587
  void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
588
589
  /// Retrieves the number of base classes of this class.
590
1.23M
  unsigned getNumBases() const { return data().NumBases; }
591
592
  using base_class_range = llvm::iterator_range<base_class_iterator>;
593
  using base_class_const_range =
594
      llvm::iterator_range<base_class_const_iterator>;
595
596
3.19M
  base_class_range bases() {
597
3.19M
    return base_class_range(bases_begin(), bases_end());
598
3.19M
  }
599
16.8M
  base_class_const_range bases() const {
600
16.8M
    return base_class_const_range(bases_begin(), bases_end());
601
16.8M
  }
602
603
7.46M
  base_class_iterator bases_begin() { return data().getBases(); }
604
42.0M
  base_class_const_iterator bases_begin() const { return data().getBases(); }
605
3.55M
  base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
606
21.0M
  base_class_const_iterator bases_end() const {
607
21.0M
    return bases_begin() + data().NumBases;
608
21.0M
  }
609
610
  /// Retrieves the number of virtual base classes of this class.
611
3.40M
  unsigned getNumVBases() const { return data().NumVBases; }
612
613
1.40M
  base_class_range vbases() {
614
1.40M
    return base_class_range(vbases_begin(), vbases_end());
615
1.40M
  }
616
542k
  base_class_const_range vbases() const {
617
542k
    return base_class_const_range(vbases_begin(), vbases_end());
618
542k
  }
619
620
2.81M
  base_class_iterator vbases_begin() { return data().getVBases(); }
621
1.13M
  base_class_const_iterator vbases_begin() const { return data().getVBases(); }
622
1.40M
  base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
623
567k
  base_class_const_iterator vbases_end() const {
624
567k
    return vbases_begin() + data().NumVBases;
625
567k
  }
626
627
  /// Determine whether this class has any dependent base classes which
628
  /// are not the current instantiation.
629
  bool hasAnyDependentBases() const;
630
631
  /// Iterator access to method members.  The method iterator visits
632
  /// all method members of the class, including non-instance methods,
633
  /// special methods, etc.
634
  using method_iterator = specific_decl_iterator<CXXMethodDecl>;
635
  using method_range =
636
      llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>;
637
638
3.10M
  method_range methods() const {
639
3.10M
    return method_range(method_begin(), method_end());
640
3.10M
  }
641
642
  /// Method begin iterator.  Iterates in the order the methods
643
  /// were declared.
644
3.10M
  method_iterator method_begin() const {
645
3.10M
    return method_iterator(decls_begin());
646
3.10M
  }
647
648
  /// Method past-the-end iterator.
649
3.10M
  method_iterator method_end() const {
650
3.10M
    return method_iterator(decls_end());
651
3.10M
  }
652
653
  /// Iterator access to constructor members.
654
  using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>;
655
  using ctor_range =
656
      llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>;
657
658
6.32k
  ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); }
659
660
6.33k
  ctor_iterator ctor_begin() const {
661
6.33k
    return ctor_iterator(decls_begin());
662
6.33k
  }
663
664
6.32k
  ctor_iterator ctor_end() const {
665
6.32k
    return ctor_iterator(decls_end());
666
6.32k
  }
667
668
  /// An iterator over friend declarations.  All of these are defined
669
  /// in DeclFriend.h.
670
  class friend_iterator;
671
  using friend_range = llvm::iterator_range<friend_iterator>;
672
673
  friend_range friends() const;
674
  friend_iterator friend_begin() const;
675
  friend_iterator friend_end() const;
676
  void pushFriendDecl(FriendDecl *FD);
677
678
  /// Determines whether this record has any friends.
679
29
  bool hasFriends() const {
680
29
    return data().FirstFriend.isValid();
681
29
  }
682
683
  /// \c true if a defaulted copy constructor for this class would be
684
  /// deleted.
685
1.22M
  bool defaultedCopyConstructorIsDeleted() const {
686
1.22M
    assert((!needsOverloadResolutionForCopyConstructor() ||
687
1.22M
            (data().DeclaredSpecialMembers & SMF_CopyConstructor)) &&
688
1.22M
           "this property has not yet been computed by Sema");
689
0
    return data().DefaultedCopyConstructorIsDeleted;
690
1.22M
  }
691
692
  /// \c true if a defaulted move constructor for this class would be
693
  /// deleted.
694
1.19M
  bool defaultedMoveConstructorIsDeleted() const {
695
1.19M
    assert((!needsOverloadResolutionForMoveConstructor() ||
696
1.19M
            (data().DeclaredSpecialMembers & SMF_MoveConstructor)) &&
697
1.19M
           "this property has not yet been computed by Sema");
698
0
    return data().DefaultedMoveConstructorIsDeleted;
699
1.19M
  }
700
701
  /// \c true if a defaulted destructor for this class would be deleted.
702
1.21M
  bool defaultedDestructorIsDeleted() const {
703
1.21M
    assert((!needsOverloadResolutionForDestructor() ||
704
1.21M
            (data().DeclaredSpecialMembers & SMF_Destructor)) &&
705
1.21M
           "this property has not yet been computed by Sema");
706
0
    return data().DefaultedDestructorIsDeleted;
707
1.21M
  }
708
709
  /// \c true if we know for sure that this class has a single,
710
  /// accessible, unambiguous copy constructor that is not deleted.
711
900k
  bool hasSimpleCopyConstructor() const {
712
900k
    return !hasUserDeclaredCopyConstructor() &&
713
900k
           
!data().DefaultedCopyConstructorIsDeleted872k
;
714
900k
  }
715
716
  /// \c true if we know for sure that this class has a single,
717
  /// accessible, unambiguous move constructor that is not deleted.
718
900k
  bool hasSimpleMoveConstructor() const {
719
900k
    return !hasUserDeclaredMoveConstructor() && 
hasMoveConstructor()887k
&&
720
900k
           
!data().DefaultedMoveConstructorIsDeleted857k
;
721
900k
  }
722
723
  /// \c true if we know for sure that this class has a single,
724
  /// accessible, unambiguous copy assignment operator that is not deleted.
725
900k
  bool hasSimpleCopyAssignment() const {
726
900k
    return !hasUserDeclaredCopyAssignment() &&
727
900k
           
!data().DefaultedCopyAssignmentIsDeleted878k
;
728
900k
  }
729
730
  /// \c true if we know for sure that this class has a single,
731
  /// accessible, unambiguous move assignment operator that is not deleted.
732
900k
  bool hasSimpleMoveAssignment() const {
733
900k
    return !hasUserDeclaredMoveAssignment() && 
hasMoveAssignment()890k
&&
734
900k
           
!data().DefaultedMoveAssignmentIsDeleted856k
;
735
900k
  }
736
737
  /// \c true if we know for sure that this class has an accessible
738
  /// destructor that is not deleted.
739
900k
  bool hasSimpleDestructor() const {
740
900k
    return !hasUserDeclaredDestructor() &&
741
900k
           
!data().DefaultedDestructorIsDeleted861k
;
742
900k
  }
743
744
  /// Determine whether this class has any default constructors.
745
1.20M
  bool hasDefaultConstructor() const {
746
1.20M
    return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
747
1.20M
           
needsImplicitDefaultConstructor()775k
;
748
1.20M
  }
749
750
  /// Determine if we need to declare a default constructor for
751
  /// this class.
752
  ///
753
  /// This value is used for lazy creation of default constructors.
754
3.82M
  bool needsImplicitDefaultConstructor() const {
755
3.82M
    return (!data().UserDeclaredConstructor &&
756
3.82M
            
!(data().DeclaredSpecialMembers & SMF_DefaultConstructor)3.10M
&&
757
3.82M
            
(2.97M
!isLambda()2.97M
||
lambdaIsDefaultConstructibleAndAssignable()18.8k
)) ||
758
           // FIXME: Proposed fix to core wording issue: if a class inherits
759
           // a default constructor and doesn't explicitly declare one, one
760
           // is declared implicitly.
761
3.82M
           
(869k
data().HasInheritedDefaultConstructor869k
&&
762
869k
            
!(data().DeclaredSpecialMembers & SMF_DefaultConstructor)829
);
763
3.82M
  }
764
765
  /// Determine whether this class has any user-declared constructors.
766
  ///
767
  /// When true, a default constructor will not be implicitly declared.
768
1.45M
  bool hasUserDeclaredConstructor() const {
769
1.45M
    return data().UserDeclaredConstructor;
770
1.45M
  }
771
772
  /// Whether this class has a user-provided default constructor
773
  /// per C++11.
774
1.67k
  bool hasUserProvidedDefaultConstructor() const {
775
1.67k
    return data().UserProvidedDefaultConstructor;
776
1.67k
  }
777
778
  /// Determine whether this class has a user-declared copy constructor.
779
  ///
780
  /// When false, a copy constructor will be implicitly declared.
781
10.4M
  bool hasUserDeclaredCopyConstructor() const {
782
10.4M
    return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
783
10.4M
  }
784
785
  /// Determine whether this class needs an implicit copy
786
  /// constructor to be lazily declared.
787
3.94M
  bool needsImplicitCopyConstructor() const {
788
3.94M
    return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
789
3.94M
  }
790
791
  /// Determine whether we need to eagerly declare a defaulted copy
792
  /// constructor for this class.
793
2.73M
  bool needsOverloadResolutionForCopyConstructor() const {
794
    // C++17 [class.copy.ctor]p6:
795
    //   If the class definition declares a move constructor or move assignment
796
    //   operator, the implicitly declared copy constructor is defined as
797
    //   deleted.
798
    // In MSVC mode, sometimes a declared move assignment does not delete an
799
    // implicit copy constructor, so defer this choice to Sema.
800
2.73M
    if (data().UserDeclaredSpecialMembers &
801
2.73M
        (SMF_MoveConstructor | SMF_MoveAssignment))
802
10.4k
      return true;
803
2.72M
    return data().NeedOverloadResolutionForCopyConstructor;
804
2.73M
  }
805
806
  /// Determine whether an implicit copy constructor for this type
807
  /// would have a parameter with a const-qualified reference type.
808
720k
  bool implicitCopyConstructorHasConstParam() const {
809
720k
    return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase &&
810
720k
           
(720k
isAbstract()720k
||
811
720k
            
data().ImplicitCopyConstructorCanHaveConstParamForVBase719k
);
812
720k
  }
813
814
  /// Determine whether this class has a copy constructor with
815
  /// a parameter type which is a reference to a const-qualified type.
816
897k
  bool hasCopyConstructorWithConstParam() const {
817
897k
    return data().HasDeclaredCopyConstructorWithConstParam ||
818
897k
           
(585k
needsImplicitCopyConstructor()585k
&&
819
585k
            
implicitCopyConstructorHasConstParam()585k
);
820
897k
  }
821
822
  /// Whether this class has a user-declared move constructor or
823
  /// assignment operator.
824
  ///
825
  /// When false, a move constructor and assignment operator may be
826
  /// implicitly declared.
827
0
  bool hasUserDeclaredMoveOperation() const {
828
0
    return data().UserDeclaredSpecialMembers &
829
0
             (SMF_MoveConstructor | SMF_MoveAssignment);
830
0
  }
831
832
  /// Determine whether this class has had a move constructor
833
  /// declared by the user.
834
4.31M
  bool hasUserDeclaredMoveConstructor() const {
835
4.31M
    return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
836
4.31M
  }
837
838
  /// Determine whether this class has a move constructor.
839
4.05M
  bool hasMoveConstructor() const {
840
4.05M
    return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
841
4.05M
           
needsImplicitMoveConstructor()3.21M
;
842
4.05M
  }
843
844
  /// Set that we attempted to declare an implicit copy
845
  /// constructor, but overload resolution failed so we deleted it.
846
10.3k
  void setImplicitCopyConstructorIsDeleted() {
847
10.3k
    assert((data().DefaultedCopyConstructorIsDeleted ||
848
10.3k
            needsOverloadResolutionForCopyConstructor()) &&
849
10.3k
           "Copy constructor should not be deleted");
850
0
    data().DefaultedCopyConstructorIsDeleted = true;
851
10.3k
  }
852
853
  /// Set that we attempted to declare an implicit move
854
  /// constructor, but overload resolution failed so we deleted it.
855
1.98k
  void setImplicitMoveConstructorIsDeleted() {
856
1.98k
    assert((data().DefaultedMoveConstructorIsDeleted ||
857
1.98k
            needsOverloadResolutionForMoveConstructor()) &&
858
1.98k
           "move constructor should not be deleted");
859
0
    data().DefaultedMoveConstructorIsDeleted = true;
860
1.98k
  }
861
862
  /// Set that we attempted to declare an implicit destructor,
863
  /// but overload resolution failed so we deleted it.
864
795
  void setImplicitDestructorIsDeleted() {
865
795
    assert((data().DefaultedDestructorIsDeleted ||
866
795
            needsOverloadResolutionForDestructor()) &&
867
795
           "destructor should not be deleted");
868
0
    data().DefaultedDestructorIsDeleted = true;
869
795
  }
870
871
  /// Determine whether this class should get an implicit move
872
  /// constructor or if any existing special member function inhibits this.
873
6.72M
  bool needsImplicitMoveConstructor() const {
874
6.72M
    return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
875
6.72M
           
!hasUserDeclaredCopyConstructor()6.22M
&&
876
6.72M
           
!hasUserDeclaredCopyAssignment()5.99M
&&
877
6.72M
           
!hasUserDeclaredMoveAssignment()5.98M
&&
878
6.72M
           
!hasUserDeclaredDestructor()5.98M
;
879
6.72M
  }
880
881
  /// Determine whether we need to eagerly declare a defaulted move
882
  /// constructor for this class.
883
2.63M
  bool needsOverloadResolutionForMoveConstructor() const {
884
2.63M
    return data().NeedOverloadResolutionForMoveConstructor;
885
2.63M
  }
886
887
  /// Determine whether this class has a user-declared copy assignment
888
  /// operator.
889
  ///
890
  /// When false, a copy assignment operator will be implicitly declared.
891
10.1M
  bool hasUserDeclaredCopyAssignment() const {
892
10.1M
    return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
893
10.1M
  }
894
895
  /// Set that we attempted to declare an implicit copy assignment
896
  /// operator, but overload resolution failed so we deleted it.
897
12.0k
  void setImplicitCopyAssignmentIsDeleted() {
898
12.0k
    assert((data().DefaultedCopyAssignmentIsDeleted ||
899
12.0k
            needsOverloadResolutionForCopyAssignment()) &&
900
12.0k
           "copy assignment should not be deleted");
901
0
    data().DefaultedCopyAssignmentIsDeleted = true;
902
12.0k
  }
903
904
  /// Determine whether this class needs an implicit copy
905
  /// assignment operator to be lazily declared.
906
2.26M
  bool needsImplicitCopyAssignment() const {
907
2.26M
    return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
908
2.26M
  }
909
910
  /// Determine whether we need to eagerly declare a defaulted copy
911
  /// assignment operator for this class.
912
1.31M
  bool needsOverloadResolutionForCopyAssignment() const {
913
    // C++20 [class.copy.assign]p2:
914
    //   If the class definition declares a move constructor or move assignment
915
    //   operator, the implicitly declared copy assignment operator is defined
916
    //   as deleted.
917
    // In MSVC mode, sometimes a declared move constructor does not delete an
918
    // implicit copy assignment, so defer this choice to Sema.
919
1.31M
    if (data().UserDeclaredSpecialMembers &
920
1.31M
        (SMF_MoveConstructor | SMF_MoveAssignment))
921
10.1k
      return true;
922
1.30M
    return data().NeedOverloadResolutionForCopyAssignment;
923
1.31M
  }
924
925
  /// Determine whether an implicit copy assignment operator for this
926
  /// type would have a parameter with a const-qualified reference type.
927
894k
  bool implicitCopyAssignmentHasConstParam() const {
928
894k
    return data().ImplicitCopyAssignmentHasConstParam;
929
894k
  }
930
931
  /// Determine whether this class has a copy assignment operator with
932
  /// a parameter type which is a reference to a const-qualified type or is not
933
  /// a reference.
934
895k
  bool hasCopyAssignmentWithConstParam() const {
935
895k
    return data().HasDeclaredCopyAssignmentWithConstParam ||
936
895k
           
(837k
needsImplicitCopyAssignment()837k
&&
937
837k
            
implicitCopyAssignmentHasConstParam()837k
);
938
895k
  }
939
940
  /// Determine whether this class has had a move assignment
941
  /// declared by the user.
942
7.07M
  bool hasUserDeclaredMoveAssignment() const {
943
7.07M
    return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
944
7.07M
  }
945
946
  /// Determine whether this class has a move assignment operator.
947
1.81M
  bool hasMoveAssignment() const {
948
1.81M
    return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
949
1.81M
           
needsImplicitMoveAssignment()1.76M
;
950
1.81M
  }
951
952
  /// Set that we attempted to declare an implicit move assignment
953
  /// operator, but overload resolution failed so we deleted it.
954
2.86k
  void setImplicitMoveAssignmentIsDeleted() {
955
2.86k
    assert((data().DefaultedMoveAssignmentIsDeleted ||
956
2.86k
            needsOverloadResolutionForMoveAssignment()) &&
957
2.86k
           "move assignment should not be deleted");
958
0
    data().DefaultedMoveAssignmentIsDeleted = true;
959
2.86k
  }
960
961
  /// Determine whether this class should get an implicit move
962
  /// assignment operator or if any existing special member function inhibits
963
  /// this.
964
3.36M
  bool needsImplicitMoveAssignment() const {
965
3.36M
    return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
966
3.36M
           
!hasUserDeclaredCopyConstructor()3.31M
&&
967
3.36M
           
!hasUserDeclaredCopyAssignment()3.22M
&&
968
3.36M
           
!hasUserDeclaredMoveConstructor()3.22M
&&
969
3.36M
           
!hasUserDeclaredDestructor()3.22M
&&
970
3.36M
           
(3.16M
!isLambda()3.16M
||
lambdaIsDefaultConstructibleAndAssignable()14.3k
);
971
3.36M
  }
972
973
  /// Determine whether we need to eagerly declare a move assignment
974
  /// operator for this class.
975
1.25M
  bool needsOverloadResolutionForMoveAssignment() const {
976
1.25M
    return data().NeedOverloadResolutionForMoveAssignment;
977
1.25M
  }
978
979
  /// Determine whether this class has a user-declared destructor.
980
  ///
981
  /// When false, a destructor will be implicitly declared.
982
11.4M
  bool hasUserDeclaredDestructor() const {
983
11.4M
    return data().UserDeclaredSpecialMembers & SMF_Destructor;
984
11.4M
  }
985
986
  /// Determine whether this class needs an implicit destructor to
987
  /// be lazily declared.
988
2.88M
  bool needsImplicitDestructor() const {
989
2.88M
    return !(data().DeclaredSpecialMembers & SMF_Destructor);
990
2.88M
  }
991
992
  /// Determine whether we need to eagerly declare a destructor for this
993
  /// class.
994
2.46M
  bool needsOverloadResolutionForDestructor() const {
995
2.46M
    return data().NeedOverloadResolutionForDestructor;
996
2.46M
  }
997
998
  /// Determine whether this class describes a lambda function object.
999
152M
  bool isLambda() const {
1000
    // An update record can't turn a non-lambda into a lambda.
1001
152M
    auto *DD = DefinitionData;
1002
152M
    return DD && 
DD->IsLambda140M
;
1003
152M
  }
1004
1005
  /// Determine whether this class describes a generic
1006
  /// lambda function object (i.e. function call operator is
1007
  /// a template).
1008
  bool isGenericLambda() const;
1009
1010
  /// Determine whether this lambda should have an implicit default constructor
1011
  /// and copy and move assignment operators.
1012
  bool lambdaIsDefaultConstructibleAndAssignable() const;
1013
1014
  /// Retrieve the lambda call operator of the closure type
1015
  /// if this is a closure type.
1016
  CXXMethodDecl *getLambdaCallOperator() const;
1017
1018
  /// Retrieve the dependent lambda call operator of the closure type
1019
  /// if this is a templated closure type.
1020
  FunctionTemplateDecl *getDependentLambdaCallOperator() const;
1021
1022
  /// Retrieve the lambda static invoker, the address of which
1023
  /// is returned by the conversion operator, and the body of which
1024
  /// is forwarded to the lambda call operator. The version that does not
1025
  /// take a calling convention uses the 'default' calling convention for free
1026
  /// functions if the Lambda's calling convention was not modified via
1027
  /// attribute. Otherwise, it will return the calling convention specified for
1028
  /// the lambda.
1029
  CXXMethodDecl *getLambdaStaticInvoker() const;
1030
  CXXMethodDecl *getLambdaStaticInvoker(CallingConv CC) const;
1031
1032
  /// Retrieve the generic lambda's template parameter list.
1033
  /// Returns null if the class does not represent a lambda or a generic
1034
  /// lambda.
1035
  TemplateParameterList *getGenericLambdaTemplateParameterList() const;
1036
1037
  /// Retrieve the lambda template parameters that were specified explicitly.
1038
  ArrayRef<NamedDecl *> getLambdaExplicitTemplateParameters() const;
1039
1040
74.6k
  LambdaCaptureDefault getLambdaCaptureDefault() const {
1041
74.6k
    assert(isLambda());
1042
0
    return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
1043
74.6k
  }
1044
1045
  /// Set the captures for this lambda closure type.
1046
  void setCaptures(ASTContext &Context, ArrayRef<LambdaCapture> Captures);
1047
1048
  /// For a closure type, retrieve the mapping from captured
1049
  /// variables and \c this to the non-static data members that store the
1050
  /// values or references of the captures.
1051
  ///
1052
  /// \param Captures Will be populated with the mapping from captured
1053
  /// variables to the corresponding fields.
1054
  ///
1055
  /// \param ThisCapture Will be set to the field declaration for the
1056
  /// \c this capture.
1057
  ///
1058
  /// \note No entries will be added for init-captures, as they do not capture
1059
  /// variables.
1060
  void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1061
                        FieldDecl *&ThisCapture) const;
1062
1063
  using capture_const_iterator = const LambdaCapture *;
1064
  using capture_const_range = llvm::iterator_range<capture_const_iterator>;
1065
1066
3.05k
  capture_const_range captures() const {
1067
3.05k
    return capture_const_range(captures_begin(), captures_end());
1068
3.05k
  }
1069
1070
6.35k
  capture_const_iterator captures_begin() const {
1071
6.35k
    return isLambda() ? getLambdaData().Captures : 
nullptr0
;
1072
6.35k
  }
1073
1074
3.16k
  capture_const_iterator captures_end() const {
1075
3.16k
    return isLambda() ? captures_begin() + getLambdaData().NumCaptures
1076
3.16k
                      : 
nullptr0
;
1077
3.16k
  }
1078
1079
52.6k
  unsigned capture_size() const { return getLambdaData().NumCaptures; }
1080
1081
  using conversion_iterator = UnresolvedSetIterator;
1082
1083
4.34M
  conversion_iterator conversion_begin() const {
1084
4.34M
    return data().Conversions.get(getASTContext()).begin();
1085
4.34M
  }
1086
1087
4.34M
  conversion_iterator conversion_end() const {
1088
4.34M
    return data().Conversions.get(getASTContext()).end();
1089
4.34M
  }
1090
1091
  /// Removes a conversion function from this class.  The conversion
1092
  /// function must currently be a member of this class.  Furthermore,
1093
  /// this class must currently be in the process of being defined.
1094
  void removeConversion(const NamedDecl *Old);
1095
1096
  /// Get all conversion functions visible in current class,
1097
  /// including conversion function templates.
1098
  llvm::iterator_range<conversion_iterator>
1099
  getVisibleConversionFunctions() const;
1100
1101
  /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]),
1102
  /// which is a class with no user-declared constructors, no private
1103
  /// or protected non-static data members, no base classes, and no virtual
1104
  /// functions (C++ [dcl.init.aggr]p1).
1105
2.30M
  bool isAggregate() const { return data().Aggregate; }
1106
1107
  /// Whether this class has any in-class initializers
1108
  /// for non-static data members (including those in anonymous unions or
1109
  /// structs).
1110
24.0k
  bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1111
1112
  /// Whether this class or any of its subobjects has any members of
1113
  /// reference type which would make value-initialization ill-formed.
1114
  ///
1115
  /// Per C++03 [dcl.init]p5:
1116
  ///  - if T is a non-union class type without a user-declared constructor,
1117
  ///    then every non-static data member and base-class component of T is
1118
  ///    value-initialized [...] A program that calls for [...]
1119
  ///    value-initialization of an entity of reference type is ill-formed.
1120
894k
  bool hasUninitializedReferenceMember() const {
1121
894k
    return !isUnion() && 
!hasUserDeclaredConstructor()884k
&&
1122
894k
           
data().HasUninitializedReferenceMember793k
;
1123
894k
  }
1124
1125
  /// Whether this class is a POD-type (C++ [class]p4)
1126
  ///
1127
  /// For purposes of this function a class is POD if it is an aggregate
1128
  /// that has no non-static non-POD data members, no reference data
1129
  /// members, no user-defined copy assignment operator and no
1130
  /// user-defined destructor.
1131
  ///
1132
  /// Note that this is the C++ TR1 definition of POD.
1133
755k
  bool isPOD() const { return data().PlainOldData; }
1134
1135
  /// True if this class is C-like, without C++-specific features, e.g.
1136
  /// it contains only public fields, no bases, tag kind is not 'class', etc.
1137
  bool isCLike() const;
1138
1139
  /// Determine whether this is an empty class in the sense of
1140
  /// (C++11 [meta.unary.prop]).
1141
  ///
1142
  /// The CXXRecordDecl is a class type, but not a union type,
1143
  /// with no non-static data members other than bit-fields of length 0,
1144
  /// no virtual member functions, no virtual base classes,
1145
  /// and no base class B for which is_empty<B>::value is false.
1146
  ///
1147
  /// \note This does NOT include a check for union-ness.
1148
3.32M
  bool isEmpty() const { return data().Empty; }
1149
1150
14
  void setInitMethod(bool Val) { data().HasInitMethod = Val; }
1151
17
  bool hasInitMethod() const { return data().HasInitMethod; }
1152
1153
99
  bool hasPrivateFields() const {
1154
99
    return data().HasPrivateFields;
1155
99
  }
1156
1157
99
  bool hasProtectedFields() const {
1158
99
    return data().HasProtectedFields;
1159
99
  }
1160
1161
  /// Determine whether this class has direct non-static data members.
1162
532k
  bool hasDirectFields() const {
1163
532k
    auto &D = data();
1164
532k
    return D.HasPublicFields || 
D.HasProtectedFields527k
||
D.HasPrivateFields524k
;
1165
532k
  }
1166
1167
  /// Whether this class is polymorphic (C++ [class.virtual]),
1168
  /// which means that the class contains or inherits a virtual function.
1169
2.47M
  bool isPolymorphic() const { return data().Polymorphic; }
1170
1171
  /// Determine whether this class has a pure virtual function.
1172
  ///
1173
  /// The class is is abstract per (C++ [class.abstract]p2) if it declares
1174
  /// a pure virtual function or inherits a pure virtual function that is
1175
  /// not overridden.
1176
5.93M
  bool isAbstract() const { return data().Abstract; }
1177
1178
  /// Determine whether this class is standard-layout per
1179
  /// C++ [class]p7.
1180
933k
  bool isStandardLayout() const { return data().IsStandardLayout; }
1181
1182
  /// Determine whether this class was standard-layout per
1183
  /// C++11 [class]p7, specifically using the C++11 rules without any DRs.
1184
893k
  bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; }
1185
1186
  /// Determine whether this class, or any of its class subobjects,
1187
  /// contains a mutable field.
1188
944k
  bool hasMutableFields() const { return data().HasMutableFields; }
1189
1190
  /// Determine whether this class has any variant members.
1191
365k
  bool hasVariantMembers() const { return data().HasVariantMembers; }
1192
1193
  /// Determine whether this class has a trivial default constructor
1194
  /// (C++11 [class.ctor]p5).
1195
1.20M
  bool hasTrivialDefaultConstructor() const {
1196
1.20M
    return hasDefaultConstructor() &&
1197
1.20M
           
(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)1.16M
;
1198
1.20M
  }
1199
1200
  /// Determine whether this class has a non-trivial default constructor
1201
  /// (C++11 [class.ctor]p5).
1202
2.06k
  bool hasNonTrivialDefaultConstructor() const {
1203
2.06k
    return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
1204
2.06k
           
(1.86k
needsImplicitDefaultConstructor()1.86k
&&
1205
1.86k
            
!(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)1.21k
);
1206
2.06k
  }
1207
1208
  /// Determine whether this class has at least one constexpr constructor
1209
  /// other than the copy or move constructors.
1210
150k
  bool hasConstexprNonCopyMoveConstructor() const {
1211
150k
    return data().HasConstexprNonCopyMoveConstructor ||
1212
150k
           
(90.1k
needsImplicitDefaultConstructor()90.1k
&&
1213
90.1k
            
defaultedDefaultConstructorIsConstexpr()58.0k
);
1214
150k
  }
1215
1216
  /// Determine whether a defaulted default constructor for this class
1217
  /// would be constexpr.
1218
676k
  bool defaultedDefaultConstructorIsConstexpr() const {
1219
676k
    return data().DefaultedDefaultConstructorIsConstexpr &&
1220
676k
           
(348k
!isUnion()348k
||
hasInClassInitializer()13.8k
||
!hasVariantMembers()13.6k
||
1221
348k
            
getLangOpts().CPlusPlus2013.4k
);
1222
676k
  }
1223
1224
  /// Determine whether this class has a constexpr default constructor.
1225
890k
  bool hasConstexprDefaultConstructor() const {
1226
890k
    return data().HasConstexprDefaultConstructor ||
1227
890k
           
(616k
needsImplicitDefaultConstructor()616k
&&
1228
616k
            
defaultedDefaultConstructorIsConstexpr()540k
);
1229
890k
  }
1230
1231
  /// Determine whether this class has a trivial copy constructor
1232
  /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1233
1.33M
  bool hasTrivialCopyConstructor() const {
1234
1.33M
    return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
1235
1.33M
  }
1236
1237
2.23M
  bool hasTrivialCopyConstructorForCall() const {
1238
2.23M
    return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor;
1239
2.23M
  }
1240
1241
  /// Determine whether this class has a non-trivial copy constructor
1242
  /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1243
329k
  bool hasNonTrivialCopyConstructor() const {
1244
329k
    return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
1245
329k
           
!hasTrivialCopyConstructor()265k
;
1246
329k
  }
1247
1248
484
  bool hasNonTrivialCopyConstructorForCall() const {
1249
484
    return (data().DeclaredNonTrivialSpecialMembersForCall &
1250
484
            SMF_CopyConstructor) ||
1251
484
           
!hasTrivialCopyConstructorForCall()468
;
1252
484
  }
1253
1254
  /// Determine whether this class has a trivial move constructor
1255
  /// (C++11 [class.copy]p12)
1256
987k
  bool hasTrivialMoveConstructor() const {
1257
987k
    return hasMoveConstructor() &&
1258
987k
           
(data().HasTrivialSpecialMembers & SMF_MoveConstructor)959k
;
1259
987k
  }
1260
1261
2.17M
  bool hasTrivialMoveConstructorForCall() const {
1262
2.17M
    return hasMoveConstructor() &&
1263
2.17M
           
(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor)2.14M
;
1264
2.17M
  }
1265
1266
  /// Determine whether this class has a non-trivial move constructor
1267
  /// (C++11 [class.copy]p12)
1268
233k
  bool hasNonTrivialMoveConstructor() const {
1269
233k
    return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
1270
233k
           
(225k
needsImplicitMoveConstructor()225k
&&
1271
225k
            
!(data().HasTrivialSpecialMembers & SMF_MoveConstructor)145k
);
1272
233k
  }
1273
1274
0
  bool hasNonTrivialMoveConstructorForCall() const {
1275
0
    return (data().DeclaredNonTrivialSpecialMembersForCall &
1276
0
            SMF_MoveConstructor) ||
1277
0
           (needsImplicitMoveConstructor() &&
1278
0
            !(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor));
1279
0
  }
1280
1281
  /// Determine whether this class has a trivial copy assignment operator
1282
  /// (C++ [class.copy]p11, C++11 [class.copy]p25)
1283
1.20M
  bool hasTrivialCopyAssignment() const {
1284
1.20M
    return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
1285
1.20M
  }
1286
1287
  /// Determine whether this class has a non-trivial copy assignment
1288
  /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
1289
257k
  bool hasNonTrivialCopyAssignment() const {
1290
257k
    return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
1291
257k
           
!hasTrivialCopyAssignment()251k
;
1292
257k
  }
1293
1294
  /// Determine whether this class has a trivial move assignment operator
1295
  /// (C++11 [class.copy]p25)
1296
917k
  bool hasTrivialMoveAssignment() const {
1297
917k
    return hasMoveAssignment() &&
1298
917k
           
(data().HasTrivialSpecialMembers & SMF_MoveAssignment)885k
;
1299
917k
  }
1300
1301
  /// Determine whether this class has a non-trivial move assignment
1302
  /// operator (C++11 [class.copy]p25)
1303
220k
  bool hasNonTrivialMoveAssignment() const {
1304
220k
    return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
1305
220k
           
(220k
needsImplicitMoveAssignment()220k
&&
1306
220k
            
!(data().HasTrivialSpecialMembers & SMF_MoveAssignment)190k
);
1307
220k
  }
1308
1309
  /// Determine whether a defaulted default constructor for this class
1310
  /// would be constexpr.
1311
688k
  bool defaultedDestructorIsConstexpr() const {
1312
688k
    return data().DefaultedDestructorIsConstexpr &&
1313
688k
           
getLangOpts().CPlusPlus20542k
;
1314
688k
  }
1315
1316
  /// Determine whether this class has a constexpr destructor.
1317
  bool hasConstexprDestructor() const;
1318
1319
  /// Determine whether this class has a trivial destructor
1320
  /// (C++ [class.dtor]p3)
1321
2.71M
  bool hasTrivialDestructor() const {
1322
2.71M
    return data().HasTrivialSpecialMembers & SMF_Destructor;
1323
2.71M
  }
1324
1325
2.20M
  bool hasTrivialDestructorForCall() const {
1326
2.20M
    return data().HasTrivialSpecialMembersForCall & SMF_Destructor;
1327
2.20M
  }
1328
1329
  /// Determine whether this class has a non-trivial destructor
1330
  /// (C++ [class.dtor]p3)
1331
1.79M
  bool hasNonTrivialDestructor() const {
1332
1.79M
    return !(data().HasTrivialSpecialMembers & SMF_Destructor);
1333
1.79M
  }
1334
1335
500
  bool hasNonTrivialDestructorForCall() const {
1336
500
    return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor);
1337
500
  }
1338
1339
9.14k
  void setHasTrivialSpecialMemberForCall() {
1340
9.14k
    data().HasTrivialSpecialMembersForCall =
1341
9.14k
        (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
1342
9.14k
  }
1343
1344
  /// Determine whether declaring a const variable with this type is ok
1345
  /// per core issue 253.
1346
897k
  bool allowConstDefaultInit() const {
1347
897k
    return !data().HasUninitializedFields ||
1348
897k
           
!(351k
data().HasDefaultedDefaultConstructor351k
||
1349
351k
             
needsImplicitDefaultConstructor()339k
);
1350
897k
  }
1351
1352
  /// Determine whether this class has a destructor which has no
1353
  /// semantic effect.
1354
  ///
1355
  /// Any such destructor will be trivial, public, defaulted and not deleted,
1356
  /// and will call only irrelevant destructors.
1357
1.20M
  bool hasIrrelevantDestructor() const {
1358
1.20M
    return data().HasIrrelevantDestructor;
1359
1.20M
  }
1360
1361
  /// Determine whether this class has a non-literal or/ volatile type
1362
  /// non-static data member or base class.
1363
1.48M
  bool hasNonLiteralTypeFieldsOrBases() const {
1364
1.48M
    return data().HasNonLiteralTypeFieldsOrBases;
1365
1.48M
  }
1366
1367
  /// Determine whether this class has a using-declaration that names
1368
  /// a user-declared base class constructor.
1369
3.64M
  bool hasInheritedConstructor() const {
1370
3.64M
    return data().HasInheritedConstructor;
1371
3.64M
  }
1372
1373
  /// Determine whether this class has a using-declaration that names
1374
  /// a base class assignment operator.
1375
2.44M
  bool hasInheritedAssignment() const {
1376
2.44M
    return data().HasInheritedAssignment;
1377
2.44M
  }
1378
1379
  /// Determine whether this class is considered trivially copyable per
1380
  /// (C++11 [class]p6).
1381
  bool isTriviallyCopyable() const;
1382
1383
  /// Determine whether this class is considered trivial.
1384
  ///
1385
  /// C++11 [class]p6:
1386
  ///    "A trivial class is a class that has a trivial default constructor and
1387
  ///    is trivially copyable."
1388
211k
  bool isTrivial() const {
1389
211k
    return isTriviallyCopyable() && 
hasTrivialDefaultConstructor()163k
;
1390
211k
  }
1391
1392
  /// Determine whether this class is a literal type.
1393
  ///
1394
  /// C++11 [basic.types]p10:
1395
  ///   A class type that has all the following properties:
1396
  ///     - it has a trivial destructor
1397
  ///     - every constructor call and full-expression in the
1398
  ///       brace-or-equal-intializers for non-static data members (if any) is
1399
  ///       a constant expression.
1400
  ///     - it is an aggregate type or has at least one constexpr constructor
1401
  ///       or constructor template that is not a copy or move constructor, and
1402
  ///     - all of its non-static data members and base classes are of literal
1403
  ///       types
1404
  ///
1405
  /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
1406
  /// treating types with trivial default constructors as literal types.
1407
  ///
1408
  /// Only in C++17 and beyond, are lambdas literal types.
1409
986k
  bool isLiteral() const {
1410
986k
    const LangOptions &LangOpts = getLangOpts();
1411
986k
    return (LangOpts.CPlusPlus20 ? 
hasConstexprDestructor()34.7k
1412
986k
                                          : 
hasTrivialDestructor()951k
) &&
1413
986k
           
(937k
!isLambda()937k
||
LangOpts.CPlusPlus171.70k
) &&
1414
986k
           
!hasNonLiteralTypeFieldsOrBases()936k
&&
1415
986k
           
(927k
isAggregate()927k
||
isLambda()149k
||
1416
927k
            
hasConstexprNonCopyMoveConstructor()148k
||
1417
927k
            
hasTrivialDefaultConstructor()34.7k
);
1418
986k
  }
1419
1420
  /// Determine whether this is a structural type.
1421
339
  bool isStructural() const {
1422
339
    return isLiteral() && 
data().StructuralIfLiteral331
;
1423
339
  }
1424
1425
  /// Notify the class that this destructor is now selected.
1426
  /// 
1427
  /// Important properties of the class depend on destructor properties. Since
1428
  /// C++20, it is possible to have multiple destructor declarations in a class
1429
  /// out of which one will be selected at the end.
1430
  /// This is called separately from addedMember because it has to be deferred
1431
  /// to the completion of the class.
1432
  void addedSelectedDestructor(CXXDestructorDecl *DD);
1433
1434
  /// Notify the class that an eligible SMF has been added.
1435
  /// This updates triviality and destructor based properties of the class accordingly.
1436
  void addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD, unsigned SMKind);
1437
1438
  /// If this record is an instantiation of a member class,
1439
  /// retrieves the member class from which it was instantiated.
1440
  ///
1441
  /// This routine will return non-null for (non-templated) member
1442
  /// classes of class templates. For example, given:
1443
  ///
1444
  /// \code
1445
  /// template<typename T>
1446
  /// struct X {
1447
  ///   struct A { };
1448
  /// };
1449
  /// \endcode
1450
  ///
1451
  /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1452
  /// whose parent is the class template specialization X<int>. For
1453
  /// this declaration, getInstantiatedFromMemberClass() will return
1454
  /// the CXXRecordDecl X<T>::A. When a complete definition of
1455
  /// X<int>::A is required, it will be instantiated from the
1456
  /// declaration returned by getInstantiatedFromMemberClass().
1457
  CXXRecordDecl *getInstantiatedFromMemberClass() const;
1458
1459
  /// If this class is an instantiation of a member class of a
1460
  /// class template specialization, retrieves the member specialization
1461
  /// information.
1462
  MemberSpecializationInfo *getMemberSpecializationInfo() const;
1463
1464
  /// Specify that this record is an instantiation of the
1465
  /// member class \p RD.
1466
  void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1467
                                     TemplateSpecializationKind TSK);
1468
1469
  /// Retrieves the class template that is described by this
1470
  /// class declaration.
1471
  ///
1472
  /// Every class template is represented as a ClassTemplateDecl and a
1473
  /// CXXRecordDecl. The former contains template properties (such as
1474
  /// the template parameter lists) while the latter contains the
1475
  /// actual description of the template's
1476
  /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1477
  /// CXXRecordDecl that from a ClassTemplateDecl, while
1478
  /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1479
  /// a CXXRecordDecl.
1480
  ClassTemplateDecl *getDescribedClassTemplate() const;
1481
1482
  void setDescribedClassTemplate(ClassTemplateDecl *Template);
1483
1484
  /// Determine whether this particular class is a specialization or
1485
  /// instantiation of a class template or member class of a class template,
1486
  /// and how it was instantiated or specialized.
1487
  TemplateSpecializationKind getTemplateSpecializationKind() const;
1488
1489
  /// Set the kind of specialization or template instantiation this is.
1490
  void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1491
1492
  /// Retrieve the record declaration from which this record could be
1493
  /// instantiated. Returns null if this class is not a template instantiation.
1494
  const CXXRecordDecl *getTemplateInstantiationPattern() const;
1495
1496
1.90M
  CXXRecordDecl *getTemplateInstantiationPattern() {
1497
1.90M
    return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this)
1498
1.90M
                                           ->getTemplateInstantiationPattern());
1499
1.90M
  }
1500
1501
  /// Returns the destructor decl for this class.
1502
  CXXDestructorDecl *getDestructor() const;
1503
1504
  /// Returns true if the class destructor, or any implicitly invoked
1505
  /// destructors are marked noreturn.
1506
904k
  bool isAnyDestructorNoReturn() const { return data().IsAnyDestructorNoReturn; }
1507
1508
  /// If the class is a local class [class.local], returns
1509
  /// the enclosing function declaration.
1510
6.42M
  const FunctionDecl *isLocalClass() const {
1511
6.42M
    if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1512
1.16M
      return RD->isLocalClass();
1513
1514
5.26M
    return dyn_cast<FunctionDecl>(getDeclContext());
1515
6.42M
  }
1516
1517
1.64M
  FunctionDecl *isLocalClass() {
1518
1.64M
    return const_cast<FunctionDecl*>(
1519
1.64M
        const_cast<const CXXRecordDecl*>(this)->isLocalClass());
1520
1.64M
  }
1521
1522
  /// Determine whether this dependent class is a current instantiation,
1523
  /// when viewed from within the given context.
1524
  bool isCurrentInstantiation(const DeclContext *CurContext) const;
1525
1526
  /// Determine whether this class is derived from the class \p Base.
1527
  ///
1528
  /// This routine only determines whether this class is derived from \p Base,
1529
  /// but does not account for factors that may make a Derived -> Base class
1530
  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1531
  /// base class subobjects.
1532
  ///
1533
  /// \param Base the base class we are searching for.
1534
  ///
1535
  /// \returns true if this class is derived from Base, false otherwise.
1536
  bool isDerivedFrom(const CXXRecordDecl *Base) const;
1537
1538
  /// Determine whether this class is derived from the type \p Base.
1539
  ///
1540
  /// This routine only determines whether this class is derived from \p Base,
1541
  /// but does not account for factors that may make a Derived -> Base class
1542
  /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1543
  /// base class subobjects.
1544
  ///
1545
  /// \param Base the base class we are searching for.
1546
  ///
1547
  /// \param Paths will contain the paths taken from the current class to the
1548
  /// given \p Base class.
1549
  ///
1550
  /// \returns true if this class is derived from \p Base, false otherwise.
1551
  ///
1552
  /// \todo add a separate parameter to configure IsDerivedFrom, rather than
1553
  /// tangling input and output in \p Paths
1554
  bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1555
1556
  /// Determine whether this class is virtually derived from
1557
  /// the class \p Base.
1558
  ///
1559
  /// This routine only determines whether this class is virtually
1560
  /// derived from \p Base, but does not account for factors that may
1561
  /// make a Derived -> Base class ill-formed, such as
1562
  /// private/protected inheritance or multiple, ambiguous base class
1563
  /// subobjects.
1564
  ///
1565
  /// \param Base the base class we are searching for.
1566
  ///
1567
  /// \returns true if this class is virtually derived from Base,
1568
  /// false otherwise.
1569
  bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1570
1571
  /// Determine whether this class is provably not derived from
1572
  /// the type \p Base.
1573
  bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1574
1575
  /// Function type used by forallBases() as a callback.
1576
  ///
1577
  /// \param BaseDefinition the definition of the base class
1578
  ///
1579
  /// \returns true if this base matched the search criteria
1580
  using ForallBasesCallback =
1581
      llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>;
1582
1583
  /// Determines if the given callback holds for all the direct
1584
  /// or indirect base classes of this type.
1585
  ///
1586
  /// The class itself does not count as a base class.  This routine
1587
  /// returns false if the class has non-computable base classes.
1588
  ///
1589
  /// \param BaseMatches Callback invoked for each (direct or indirect) base
1590
  /// class of this type until a call returns false.
1591
  bool forallBases(ForallBasesCallback BaseMatches) const;
1592
1593
  /// Function type used by lookupInBases() to determine whether a
1594
  /// specific base class subobject matches the lookup criteria.
1595
  ///
1596
  /// \param Specifier the base-class specifier that describes the inheritance
1597
  /// from the base class we are trying to match.
1598
  ///
1599
  /// \param Path the current path, from the most-derived class down to the
1600
  /// base named by the \p Specifier.
1601
  ///
1602
  /// \returns true if this base matched the search criteria, false otherwise.
1603
  using BaseMatchesCallback =
1604
      llvm::function_ref<bool(const CXXBaseSpecifier *Specifier,
1605
                              CXXBasePath &Path)>;
1606
1607
  /// Look for entities within the base classes of this C++ class,
1608
  /// transitively searching all base class subobjects.
1609
  ///
1610
  /// This routine uses the callback function \p BaseMatches to find base
1611
  /// classes meeting some search criteria, walking all base class subobjects
1612
  /// and populating the given \p Paths structure with the paths through the
1613
  /// inheritance hierarchy that resulted in a match. On a successful search,
1614
  /// the \p Paths structure can be queried to retrieve the matching paths and
1615
  /// to determine if there were any ambiguities.
1616
  ///
1617
  /// \param BaseMatches callback function used to determine whether a given
1618
  /// base matches the user-defined search criteria.
1619
  ///
1620
  /// \param Paths used to record the paths from this class to its base class
1621
  /// subobjects that match the search criteria.
1622
  ///
1623
  /// \param LookupInDependent can be set to true to extend the search to
1624
  /// dependent base classes.
1625
  ///
1626
  /// \returns true if there exists any path from this class to a base class
1627
  /// subobject that matches the search criteria.
1628
  bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths,
1629
                     bool LookupInDependent = false) const;
1630
1631
  /// Base-class lookup callback that determines whether the given
1632
  /// base class specifier refers to a specific class declaration.
1633
  ///
1634
  /// This callback can be used with \c lookupInBases() to determine whether
1635
  /// a given derived class has is a base class subobject of a particular type.
1636
  /// The base record pointer should refer to the canonical CXXRecordDecl of the
1637
  /// base class that we are searching for.
1638
  static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1639
                            CXXBasePath &Path, const CXXRecordDecl *BaseRecord);
1640
1641
  /// Base-class lookup callback that determines whether the
1642
  /// given base class specifier refers to a specific class
1643
  /// declaration and describes virtual derivation.
1644
  ///
1645
  /// This callback can be used with \c lookupInBases() to determine
1646
  /// whether a given derived class has is a virtual base class
1647
  /// subobject of a particular type.  The base record pointer should
1648
  /// refer to the canonical CXXRecordDecl of the base class that we
1649
  /// are searching for.
1650
  static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1651
                                   CXXBasePath &Path,
1652
                                   const CXXRecordDecl *BaseRecord);
1653
1654
  /// Retrieve the final overriders for each virtual member
1655
  /// function in the class hierarchy where this class is the
1656
  /// most-derived class in the class hierarchy.
1657
  void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1658
1659
  /// Get the indirect primary bases for this class.
1660
  void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1661
1662
  /// Determine whether this class has a member with the given name, possibly
1663
  /// in a non-dependent base class.
1664
  ///
1665
  /// No check for ambiguity is performed, so this should never be used when
1666
  /// implementing language semantics, but it may be appropriate for warnings,
1667
  /// static analysis, or similar.
1668
  bool hasMemberName(DeclarationName N) const;
1669
1670
  /// Performs an imprecise lookup of a dependent name in this class.
1671
  ///
1672
  /// This function does not follow strict semantic rules and should be used
1673
  /// only when lookup rules can be relaxed, e.g. indexing.
1674
  std::vector<const NamedDecl *>
1675
  lookupDependentName(DeclarationName Name,
1676
                      llvm::function_ref<bool(const NamedDecl *ND)> Filter);
1677
1678
  /// Renders and displays an inheritance diagram
1679
  /// for this C++ class and all of its base classes (transitively) using
1680
  /// GraphViz.
1681
  void viewInheritance(ASTContext& Context) const;
1682
1683
  /// Calculates the access of a decl that is reached
1684
  /// along a path.
1685
  static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1686
1.19M
                                     AccessSpecifier DeclAccess) {
1687
1.19M
    assert(DeclAccess != AS_none);
1688
1.19M
    if (DeclAccess == AS_private) 
return AS_none38.8k
;
1689
1.15M
    return (PathAccess > DeclAccess ? 
PathAccess82.8k
:
DeclAccess1.07M
);
1690
1.19M
  }
1691
1692
  /// Indicates that the declaration of a defaulted or deleted special
1693
  /// member function is now complete.
1694
  void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD);
1695
1696
  void setTrivialForCallFlags(CXXMethodDecl *MD);
1697
1698
  /// Indicates that the definition of this class is now complete.
1699
  void completeDefinition() override;
1700
1701
  /// Indicates that the definition of this class is now complete,
1702
  /// and provides a final overrider map to help determine
1703
  ///
1704
  /// \param FinalOverriders The final overrider map for this class, which can
1705
  /// be provided as an optimization for abstract-class checking. If NULL,
1706
  /// final overriders will be computed if they are needed to complete the
1707
  /// definition.
1708
  void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1709
1710
  /// Determine whether this class may end up being abstract, even though
1711
  /// it is not yet known to be abstract.
1712
  ///
1713
  /// \returns true if this class is not known to be abstract but has any
1714
  /// base classes that are abstract. In this case, \c completeDefinition()
1715
  /// will need to compute final overriders to determine whether the class is
1716
  /// actually abstract.
1717
  bool mayBeAbstract() const;
1718
1719
  /// Determine whether it's impossible for a class to be derived from this
1720
  /// class. This is best-effort, and may conservatively return false.
1721
  bool isEffectivelyFinal() const;
1722
1723
  /// If this is the closure type of a lambda expression, retrieve the
1724
  /// number to be used for name mangling in the Itanium C++ ABI.
1725
  ///
1726
  /// Zero indicates that this closure type has internal linkage, so the
1727
  /// mangling number does not matter, while a non-zero value indicates which
1728
  /// lambda expression this is in this particular context.
1729
22.6k
  unsigned getLambdaManglingNumber() const {
1730
22.6k
    assert(isLambda() && "Not a lambda closure type!");
1731
0
    return getLambdaData().ManglingNumber;
1732
22.6k
  }
1733
1734
  /// The lambda is known to has internal linkage no matter whether it has name
1735
  /// mangling number.
1736
12.1k
  bool hasKnownLambdaInternalLinkage() const {
1737
12.1k
    assert(isLambda() && "Not a lambda closure type!");
1738
0
    return getLambdaData().HasKnownInternalLinkage;
1739
12.1k
  }
1740
1741
  /// Retrieve the declaration that provides additional context for a
1742
  /// lambda, when the normal declaration context is not specific enough.
1743
  ///
1744
  /// Certain contexts (default arguments of in-class function parameters and
1745
  /// the initializers of data members) have separate name mangling rules for
1746
  /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1747
  /// the declaration in which the lambda occurs, e.g., the function parameter
1748
  /// or the non-static data member. Otherwise, it returns NULL to imply that
1749
  /// the declaration context suffices.
1750
  Decl *getLambdaContextDecl() const;
1751
1752
  /// Set the mangling number and context declaration for a lambda
1753
  /// class.
1754
  void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl,
1755
6.89k
                         bool HasKnownInternalLinkage = false) {
1756
6.89k
    assert(isLambda() && "Not a lambda closure type!");
1757
0
    getLambdaData().ManglingNumber = ManglingNumber;
1758
6.89k
    getLambdaData().ContextDecl = ContextDecl;
1759
6.89k
    getLambdaData().HasKnownInternalLinkage = HasKnownInternalLinkage;
1760
6.89k
  }
1761
1762
  /// Set the device side mangling number.
1763
  void setDeviceLambdaManglingNumber(unsigned Num) const;
1764
1765
  /// Retrieve the device side mangling number.
1766
  unsigned getDeviceLambdaManglingNumber() const;
1767
1768
  /// Returns the inheritance model used for this record.
1769
  MSInheritanceModel getMSInheritanceModel() const;
1770
1771
  /// Calculate what the inheritance model would be for this class.
1772
  MSInheritanceModel calculateInheritanceModel() const;
1773
1774
  /// In the Microsoft C++ ABI, use zero for the field offset of a null data
1775
  /// member pointer if we can guarantee that zero is not a valid field offset,
1776
  /// or if the member pointer has multiple fields.  Polymorphic classes have a
1777
  /// vfptr at offset zero, so we can use zero for null.  If there are multiple
1778
  /// fields, we can use zero even if it is a valid field offset because
1779
  /// null-ness testing will check the other fields.
1780
  bool nullFieldOffsetIsZero() const;
1781
1782
  /// Controls when vtordisps will be emitted if this record is used as a
1783
  /// virtual base.
1784
  MSVtorDispMode getMSVtorDispMode() const;
1785
1786
  /// Determine whether this lambda expression was known to be dependent
1787
  /// at the time it was created, even if its context does not appear to be
1788
  /// dependent.
1789
  ///
1790
  /// This flag is a workaround for an issue with parsing, where default
1791
  /// arguments are parsed before their enclosing function declarations have
1792
  /// been created. This means that any lambda expressions within those
1793
  /// default arguments will have as their DeclContext the context enclosing
1794
  /// the function declaration, which may be non-dependent even when the
1795
  /// function declaration itself is dependent. This flag indicates when we
1796
  /// know that the lambda is dependent despite that.
1797
50.4M
  bool isDependentLambda() const {
1798
50.4M
    return isLambda() && 
getLambdaData().DependencyKind == LDK_AlwaysDependent400k
;
1799
50.4M
  }
1800
1801
50.3M
  bool isNeverDependentLambda() const {
1802
50.3M
    return isLambda() && 
getLambdaData().DependencyKind == LDK_NeverDependent372k
;
1803
50.3M
  }
1804
1805
89
  unsigned getLambdaDependencyKind() const {
1806
89
    if (!isLambda())
1807
0
      return LDK_Unknown;
1808
89
    return getLambdaData().DependencyKind;
1809
89
  }
1810
1811
8.07k
  TypeSourceInfo *getLambdaTypeInfo() const {
1812
8.07k
    return getLambdaData().MethodTyInfo;
1813
8.07k
  }
1814
1815
  // Determine whether this type is an Interface Like type for
1816
  // __interface inheritance purposes.
1817
  bool isInterfaceLike() const;
1818
1819
828M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1820
1.63G
  static bool classofKind(Kind K) {
1821
1.63G
    return K >= firstCXXRecord && 
K <= lastCXXRecord1.27G
;
1822
1.63G
  }
1823
12
  void markAbstract() { data().Abstract = true; }
1824
};
1825
1826
/// Store information needed for an explicit specifier.
1827
/// Used by CXXDeductionGuideDecl, CXXConstructorDecl and CXXConversionDecl.
1828
class ExplicitSpecifier {
1829
  llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{
1830
      nullptr, ExplicitSpecKind::ResolvedFalse};
1831
1832
public:
1833
150M
  ExplicitSpecifier() = default;
1834
  ExplicitSpecifier(Expr *Expression, ExplicitSpecKind Kind)
1835
4.28M
      : ExplicitSpec(Expression, Kind) {}
1836
1.09M
  ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); }
1837
5.72k
  const Expr *getExpr() const { return ExplicitSpec.getPointer(); }
1838
7.27M
  Expr *getExpr() { return ExplicitSpec.getPointer(); }
1839
1840
  /// Determine if the declaration had an explicit specifier of any kind.
1841
167M
  bool isSpecified() const {
1842
167M
    return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse ||
1843
167M
           
ExplicitSpec.getPointer()167M
;
1844
167M
  }
1845
1846
  /// Check for equivalence of explicit specifiers.
1847
  /// \return true if the explicit specifier are equivalent, false otherwise.
1848
  bool isEquivalent(const ExplicitSpecifier Other) const;
1849
  /// Determine whether this specifier is known to correspond to an explicit
1850
  /// declaration. Returns false if the specifier is absent or has an
1851
  /// expression that is value-dependent or evaluates to false.
1852
5.59M
  bool isExplicit() const {
1853
5.59M
    return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue;
1854
5.59M
  }
1855
  /// Determine if the explicit specifier is invalid.
1856
  /// This state occurs after a substitution failures.
1857
1.12M
  bool isInvalid() const {
1858
1.12M
    return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved &&
1859
1.12M
           
!ExplicitSpec.getPointer()176
;
1860
1.12M
  }
1861
323
  void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); }
1862
323
  void setExpr(Expr *E) { ExplicitSpec.setPointer(E); }
1863
  // Retrieve the explicit specifier in the given declaration, if any.
1864
  static ExplicitSpecifier getFromDecl(FunctionDecl *Function);
1865
42
  static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) {
1866
42
    return getFromDecl(const_cast<FunctionDecl *>(Function));
1867
42
  }
1868
142
  static ExplicitSpecifier Invalid() {
1869
142
    return ExplicitSpecifier(nullptr, ExplicitSpecKind::Unresolved);
1870
142
  }
1871
};
1872
1873
/// Represents a C++ deduction guide declaration.
1874
///
1875
/// \code
1876
/// template<typename T> struct A { A(); A(T); };
1877
/// A() -> A<int>;
1878
/// \endcode
1879
///
1880
/// In this example, there will be an explicit deduction guide from the
1881
/// second line, and implicit deduction guide templates synthesized from
1882
/// the constructors of \c A.
1883
class CXXDeductionGuideDecl : public FunctionDecl {
1884
  void anchor() override;
1885
1886
private:
1887
  CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1888
                        ExplicitSpecifier ES,
1889
                        const DeclarationNameInfo &NameInfo, QualType T,
1890
                        TypeSourceInfo *TInfo, SourceLocation EndLocation,
1891
                        CXXConstructorDecl *Ctor)
1892
      : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo,
1893
                     SC_None, false, false, ConstexprSpecKind::Unspecified),
1894
5.14k
        Ctor(Ctor), ExplicitSpec(ES) {
1895
5.14k
    if (EndLocation.isValid())
1896
4.96k
      setRangeEnd(EndLocation);
1897
5.14k
    setIsCopyDeductionCandidate(false);
1898
5.14k
  }
1899
1900
  CXXConstructorDecl *Ctor;
1901
  ExplicitSpecifier ExplicitSpec;
1902
180
  void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; }
1903
1904
public:
1905
  friend class ASTDeclReader;
1906
  friend class ASTDeclWriter;
1907
1908
  static CXXDeductionGuideDecl *
1909
  Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1910
         ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T,
1911
         TypeSourceInfo *TInfo, SourceLocation EndLocation,
1912
         CXXConstructorDecl *Ctor = nullptr);
1913
1914
  static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1915
1916
3.15k
  ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; }
1917
0
  const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; }
1918
1919
  /// Return true if the declartion is already resolved to be explicit.
1920
150
  bool isExplicit() const { return ExplicitSpec.isExplicit(); }
1921
1922
  /// Get the template for which this guide performs deduction.
1923
1.53k
  TemplateDecl *getDeducedTemplate() const {
1924
1.53k
    return getDeclName().getCXXDeductionGuideTemplate();
1925
1.53k
  }
1926
1927
  /// Get the constructor from which this deduction guide was generated, if
1928
  /// this is an implicit deduction guide.
1929
52
  CXXConstructorDecl *getCorrespondingConstructor() const {
1930
52
    return Ctor;
1931
52
  }
1932
1933
5.85k
  void setIsCopyDeductionCandidate(bool isCDC = true) {
1934
5.85k
    FunctionDeclBits.IsCopyDeductionCandidate = isCDC;
1935
5.85k
  }
1936
1937
2.43k
  bool isCopyDeductionCandidate() const {
1938
2.43k
    return FunctionDeclBits.IsCopyDeductionCandidate;
1939
2.43k
  }
1940
1941
  // Implement isa/cast/dyncast/etc.
1942
17.5M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1943
18.8M
  static bool classofKind(Kind K) { return K == CXXDeductionGuide; }
1944
};
1945
1946
/// \brief Represents the body of a requires-expression.
1947
///
1948
/// This decl exists merely to serve as the DeclContext for the local
1949
/// parameters of the requires expression as well as other declarations inside
1950
/// it.
1951
///
1952
/// \code
1953
/// template<typename T> requires requires (T t) { {t++} -> regular; }
1954
/// \endcode
1955
///
1956
/// In this example, a RequiresExpr object will be generated for the expression,
1957
/// and a RequiresExprBodyDecl will be created to hold the parameter t and the
1958
/// template argument list imposed by the compound requirement.
1959
class RequiresExprBodyDecl : public Decl, public DeclContext {
1960
  RequiresExprBodyDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
1961
3.44k
      : Decl(RequiresExprBody, DC, StartLoc), DeclContext(RequiresExprBody) {}
1962
1963
public:
1964
  friend class ASTDeclReader;
1965
  friend class ASTDeclWriter;
1966
1967
  static RequiresExprBodyDecl *Create(ASTContext &C, DeclContext *DC,
1968
                                      SourceLocation StartLoc);
1969
1970
  static RequiresExprBodyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1971
1972
  // Implement isa/cast/dyncast/etc.
1973
288
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1974
140M
  static bool classofKind(Kind K) { return K == RequiresExprBody; }
1975
};
1976
1977
/// Represents a static or instance method of a struct/union/class.
1978
///
1979
/// In the terminology of the C++ Standard, these are the (static and
1980
/// non-static) member functions, whether virtual or not.
1981
class CXXMethodDecl : public FunctionDecl {
1982
  void anchor() override;
1983
1984
protected:
1985
  CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD,
1986
                SourceLocation StartLoc, const DeclarationNameInfo &NameInfo,
1987
                QualType T, TypeSourceInfo *TInfo, StorageClass SC,
1988
                bool UsesFPIntrin, bool isInline,
1989
                ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
1990
                Expr *TrailingRequiresClause = nullptr)
1991
      : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, UsesFPIntrin,
1992
5.08M
                     isInline, ConstexprKind, TrailingRequiresClause) {
1993
5.08M
    if (EndLocation.isValid())
1994
850k
      setRangeEnd(EndLocation);
1995
5.08M
  }
1996
1997
public:
1998
  static CXXMethodDecl *
1999
  Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2000
         const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2001
         StorageClass SC, bool UsesFPIntrin, bool isInline,
2002
         ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
2003
         Expr *TrailingRequiresClause = nullptr);
2004
2005
  static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2006
2007
  bool isStatic() const;
2008
13.9M
  bool isInstance() const { return !isStatic(); }
2009
2010
  /// Returns true if the given operator is implicitly static in a record
2011
  /// context.
2012
29.3M
  static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
2013
    // [class.free]p1:
2014
    // Any allocation function for a class T is a static member
2015
    // (even if not explicitly declared static).
2016
    // [class.free]p6 Any deallocation function for a class X is a static member
2017
    // (even if not explicitly declared static).
2018
29.3M
    return OOK == OO_New || 
OOK == OO_Array_New29.3M
||
OOK == OO_Delete29.3M
||
2019
29.3M
           
OOK == OO_Array_Delete29.3M
;
2020
29.3M
  }
2021
2022
1.55M
  bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
2023
1.37M
  bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
2024
2025
13.9M
  bool isVirtual() const {
2026
13.9M
    CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
2027
2028
    // Member function is virtual if it is marked explicitly so, or if it is
2029
    // declared in __interface -- then it is automatically pure virtual.
2030
13.9M
    if (CD->isVirtualAsWritten() || 
CD->isPure()13.3M
)
2031
614k
      return true;
2032
2033
13.3M
    return CD->size_overridden_methods() != 0;
2034
13.9M
  }
2035
2036
  /// If it's possible to devirtualize a call to this method, return the called
2037
  /// function. Otherwise, return null.
2038
2039
  /// \param Base The object on which this virtual function is called.
2040
  /// \param IsAppleKext True if we are compiling for Apple kext.
2041
  CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext);
2042
2043
  const CXXMethodDecl *getDevirtualizedMethod(const Expr *Base,
2044
1.70k
                                              bool IsAppleKext) const {
2045
1.70k
    return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod(
2046
1.70k
        Base, IsAppleKext);
2047
1.70k
  }
2048
2049
  /// Determine whether this is a usual deallocation function (C++
2050
  /// [basic.stc.dynamic.deallocation]p2), which is an overloaded delete or
2051
  /// delete[] operator with a particular signature. Populates \p PreventedBy
2052
  /// with the declarations of the functions of the same kind if they were the
2053
  /// reason for this function returning false. This is used by
2054
  /// Sema::isUsualDeallocationFunction to reconsider the answer based on the
2055
  /// context.
2056
  bool isUsualDeallocationFunction(
2057
      SmallVectorImpl<const FunctionDecl *> &PreventedBy) const;
2058
2059
  /// Determine whether this is a copy-assignment operator, regardless
2060
  /// of whether it was declared implicitly or explicitly.
2061
  bool isCopyAssignmentOperator() const;
2062
2063
  /// Determine whether this is a move assignment operator.
2064
  bool isMoveAssignmentOperator() const;
2065
2066
95.8M
  CXXMethodDecl *getCanonicalDecl() override {
2067
95.8M
    return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
2068
95.8M
  }
2069
46.8M
  const CXXMethodDecl *getCanonicalDecl() const {
2070
46.8M
    return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
2071
46.8M
  }
2072
2073
176k
  CXXMethodDecl *getMostRecentDecl() {
2074
176k
    return cast<CXXMethodDecl>(
2075
176k
            static_cast<FunctionDecl *>(this)->getMostRecentDecl());
2076
176k
  }
2077
0
  const CXXMethodDecl *getMostRecentDecl() const {
2078
0
    return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl();
2079
0
  }
2080
2081
  void addOverriddenMethod(const CXXMethodDecl *MD);
2082
2083
  using method_iterator = const CXXMethodDecl *const *;
2084
2085
  method_iterator begin_overridden_methods() const;
2086
  method_iterator end_overridden_methods() const;
2087
  unsigned size_overridden_methods() const;
2088
2089
  using overridden_method_range = llvm::iterator_range<
2090
      llvm::TinyPtrVector<const CXXMethodDecl *>::const_iterator>;
2091
2092
  overridden_method_range overridden_methods() const;
2093
2094
  /// Return the parent of this method declaration, which
2095
  /// is the class in which this method is defined.
2096
39.9M
  const CXXRecordDecl *getParent() const {
2097
39.9M
    return cast<CXXRecordDecl>(FunctionDecl::getParent());
2098
39.9M
  }
2099
2100
  /// Return the parent of this method declaration, which
2101
  /// is the class in which this method is defined.
2102
13.5M
  CXXRecordDecl *getParent() {
2103
13.5M
    return const_cast<CXXRecordDecl *>(
2104
13.5M
             cast<CXXRecordDecl>(FunctionDecl::getParent()));
2105
13.5M
  }
2106
2107
  /// Return the type of the \c this pointer.
2108
  ///
2109
  /// Should only be called for instance (i.e., non-static) methods. Note
2110
  /// that for the call operator of a lambda closure type, this returns the
2111
  /// desugared 'this' type (a pointer to the closure type), not the captured
2112
  /// 'this' type.
2113
  QualType getThisType() const;
2114
2115
  /// Return the type of the object pointed by \c this.
2116
  ///
2117
  /// See getThisType() for usage restriction.
2118
  QualType getThisObjectType() const;
2119
2120
  static QualType getThisType(const FunctionProtoType *FPT,
2121
                              const CXXRecordDecl *Decl);
2122
2123
  static QualType getThisObjectType(const FunctionProtoType *FPT,
2124
                                    const CXXRecordDecl *Decl);
2125
2126
6.63M
  Qualifiers getMethodQualifiers() const {
2127
6.63M
    return getType()->castAs<FunctionProtoType>()->getMethodQuals();
2128
6.63M
  }
2129
2130
  /// Retrieve the ref-qualifier associated with this method.
2131
  ///
2132
  /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
2133
  /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
2134
  /// @code
2135
  /// struct X {
2136
  ///   void f() &;
2137
  ///   void g() &&;
2138
  ///   void h();
2139
  /// };
2140
  /// @endcode
2141
7.40M
  RefQualifierKind getRefQualifier() const {
2142
7.40M
    return getType()->castAs<FunctionProtoType>()->getRefQualifier();
2143
7.40M
  }
2144
2145
  bool hasInlineBody() const;
2146
2147
  /// Determine whether this is a lambda closure type's static member
2148
  /// function that is used for the result of the lambda's conversion to
2149
  /// function pointer (for a lambda with no captures).
2150
  ///
2151
  /// The function itself, if used, will have a placeholder body that will be
2152
  /// supplied by IR generation to either forward to the function call operator
2153
  /// or clone the function call operator.
2154
  bool isLambdaStaticInvoker() const;
2155
2156
  /// Find the method in \p RD that corresponds to this one.
2157
  ///
2158
  /// Find if \p RD or one of the classes it inherits from override this method.
2159
  /// If so, return it. \p RD is assumed to be a subclass of the class defining
2160
  /// this method (or be the class itself), unless \p MayBeBase is set to true.
2161
  CXXMethodDecl *
2162
  getCorrespondingMethodInClass(const CXXRecordDecl *RD,
2163
                                bool MayBeBase = false);
2164
2165
  const CXXMethodDecl *
2166
  getCorrespondingMethodInClass(const CXXRecordDecl *RD,
2167
721
                                bool MayBeBase = false) const {
2168
721
    return const_cast<CXXMethodDecl *>(this)
2169
721
              ->getCorrespondingMethodInClass(RD, MayBeBase);
2170
721
  }
2171
2172
  /// Find if \p RD declares a function that overrides this function, and if so,
2173
  /// return it. Does not search base classes.
2174
  CXXMethodDecl *getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD,
2175
                                                       bool MayBeBase = false);
2176
  const CXXMethodDecl *
2177
  getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD,
2178
196
                                        bool MayBeBase = false) const {
2179
196
    return const_cast<CXXMethodDecl *>(this)
2180
196
        ->getCorrespondingMethodDeclaredInClass(RD, MayBeBase);
2181
196
  }
2182
2183
  // Implement isa/cast/dyncast/etc.
2184
542M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2185
826M
  static bool classofKind(Kind K) {
2186
826M
    return K >= firstCXXMethod && 
K <= lastCXXMethod357M
;
2187
826M
  }
2188
};
2189
2190
/// Represents a C++ base or member initializer.
2191
///
2192
/// This is part of a constructor initializer that
2193
/// initializes one non-static member variable or one base class. For
2194
/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
2195
/// initializers:
2196
///
2197
/// \code
2198
/// class A { };
2199
/// class B : public A {
2200
///   float f;
2201
/// public:
2202
///   B(A& a) : A(a), f(3.14159) { }
2203
/// };
2204
/// \endcode
2205
class CXXCtorInitializer final {
2206
  /// Either the base class name/delegating constructor type (stored as
2207
  /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
2208
  /// (IndirectFieldDecl*) being initialized.
2209
  llvm::PointerUnion<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
2210
      Initializee;
2211
2212
  /// The argument used to initialize the base or member, which may
2213
  /// end up constructing an object (when multiple arguments are involved).
2214
  Stmt *Init;
2215
2216
  /// The source location for the field name or, for a base initializer
2217
  /// pack expansion, the location of the ellipsis.
2218
  ///
2219
  /// In the case of a delegating
2220
  /// constructor, it will still include the type's source location as the
2221
  /// Initializee points to the CXXConstructorDecl (to allow loop detection).
2222
  SourceLocation MemberOrEllipsisLocation;
2223
2224
  /// Location of the left paren of the ctor-initializer.
2225
  SourceLocation LParenLoc;
2226
2227
  /// Location of the right paren of the ctor-initializer.
2228
  SourceLocation RParenLoc;
2229
2230
  /// If the initializee is a type, whether that type makes this
2231
  /// a delegating initialization.
2232
  unsigned IsDelegating : 1;
2233
2234
  /// If the initializer is a base initializer, this keeps track
2235
  /// of whether the base is virtual or not.
2236
  unsigned IsVirtual : 1;
2237
2238
  /// Whether or not the initializer is explicitly written
2239
  /// in the sources.
2240
  unsigned IsWritten : 1;
2241
2242
  /// If IsWritten is true, then this number keeps track of the textual order
2243
  /// of this initializer in the original sources, counting from 0.
2244
  unsigned SourceOrder : 13;
2245
2246
public:
2247
  /// Creates a new base-class initializer.
2248
  explicit
2249
  CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
2250
                     SourceLocation L, Expr *Init, SourceLocation R,
2251
                     SourceLocation EllipsisLoc);
2252
2253
  /// Creates a new member initializer.
2254
  explicit
2255
  CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
2256
                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
2257
                     SourceLocation R);
2258
2259
  /// Creates a new anonymous field initializer.
2260
  explicit
2261
  CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
2262
                     SourceLocation MemberLoc, SourceLocation L, Expr *Init,
2263
                     SourceLocation R);
2264
2265
  /// Creates a new delegating initializer.
2266
  explicit
2267
  CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
2268
                     SourceLocation L, Expr *Init, SourceLocation R);
2269
2270
  /// \return Unique reproducible object identifier.
2271
  int64_t getID(const ASTContext &Context) const;
2272
2273
  /// Determine whether this initializer is initializing a base class.
2274
573k
  bool isBaseInitializer() const {
2275
573k
    return Initializee.is<TypeSourceInfo*>() && 
!IsDelegating263k
;
2276
573k
  }
2277
2278
  /// Determine whether this initializer is initializing a non-static
2279
  /// data member.
2280
1.85M
  bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
2281
2282
820k
  bool isAnyMemberInitializer() const {
2283
820k
    return isMemberInitializer() || 
isIndirectMemberInitializer()109k
;
2284
820k
  }
2285
2286
203k
  bool isIndirectMemberInitializer() const {
2287
203k
    return Initializee.is<IndirectFieldDecl*>();
2288
203k
  }
2289
2290
  /// Determine whether this initializer is an implicit initializer
2291
  /// generated for a field with an initializer defined on the member
2292
  /// declaration.
2293
  ///
2294
  /// In-class member initializers (also known as "non-static data member
2295
  /// initializations", NSDMIs) were introduced in C++11.
2296
142k
  bool isInClassMemberInitializer() const {
2297
142k
    return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass;
2298
142k
  }
2299
2300
  /// Determine whether this initializer is creating a delegating
2301
  /// constructor.
2302
95.0k
  bool isDelegatingInitializer() const {
2303
95.0k
    return Initializee.is<TypeSourceInfo*>() && 
IsDelegating16.5k
;
2304
95.0k
  }
2305
2306
  /// Determine whether this initializer is a pack expansion.
2307
50.6k
  bool isPackExpansion() const {
2308
50.6k
    return isBaseInitializer() && 
MemberOrEllipsisLocation.isValid()21.7k
;
2309
50.6k
  }
2310
2311
  // For a pack expansion, returns the location of the ellipsis.
2312
647
  SourceLocation getEllipsisLoc() const {
2313
647
    if (!isPackExpansion())
2314
0
      return {};
2315
647
    return MemberOrEllipsisLocation;
2316
647
  }
2317
2318
  /// If this is a base class initializer, returns the type of the
2319
  /// base class with location information. Otherwise, returns an NULL
2320
  /// type location.
2321
  TypeLoc getBaseClassLoc() const;
2322
2323
  /// If this is a base class initializer, returns the type of the base class.
2324
  /// Otherwise, returns null.
2325
  const Type *getBaseClass() const;
2326
2327
  /// Returns whether the base is virtual or not.
2328
43.1k
  bool isBaseVirtual() const {
2329
43.1k
    assert(isBaseInitializer() && "Must call this on base initializer!");
2330
2331
0
    return IsVirtual;
2332
43.1k
  }
2333
2334
  /// Returns the declarator information for a base class or delegating
2335
  /// initializer.
2336
69.1k
  TypeSourceInfo *getTypeSourceInfo() const {
2337
69.1k
    return Initializee.dyn_cast<TypeSourceInfo *>();
2338
69.1k
  }
2339
2340
  /// If this is a member initializer, returns the declaration of the
2341
  /// non-static data member being initialized. Otherwise, returns null.
2342
226k
  FieldDecl *getMember() const {
2343
226k
    if (isMemberInitializer())
2344
224k
      return Initializee.get<FieldDecl*>();
2345
1.74k
    return nullptr;
2346
226k
  }
2347
2348
694k
  FieldDecl *getAnyMember() const {
2349
694k
    if (isMemberInitializer())
2350
684k
      return Initializee.get<FieldDecl*>();
2351
9.74k
    if (isIndirectMemberInitializer())
2352
1.26k
      return Initializee.get<IndirectFieldDecl*>()->getAnonField();
2353
8.48k
    return nullptr;
2354
9.74k
  }
2355
2356
56.4k
  IndirectFieldDecl *getIndirectMember() const {
2357
56.4k
    if (isIndirectMemberInitializer())
2358
1.24k
      return Initializee.get<IndirectFieldDecl*>();
2359
55.2k
    return nullptr;
2360
56.4k
  }
2361
2362
230k
  SourceLocation getMemberLocation() const {
2363
230k
    return MemberOrEllipsisLocation;
2364
230k
  }
2365
2366
  /// Determine the source location of the initializer.
2367
  SourceLocation getSourceLocation() const;
2368
2369
  /// Determine the source range covering the entire initializer.
2370
  SourceRange getSourceRange() const LLVM_READONLY;
2371
2372
  /// Determine whether this initializer is explicitly written
2373
  /// in the source code.
2374
177k
  bool isWritten() const { return IsWritten; }
2375
2376
  /// Return the source position of the initializer, counting from 0.
2377
  /// If the initializer was implicit, -1 is returned.
2378
21.6k
  int getSourceOrder() const {
2379
21.6k
    return IsWritten ? static_cast<int>(SourceOrder) : 
-10
;
2380
21.6k
  }
2381
2382
  /// Set the source order of this initializer.
2383
  ///
2384
  /// This can only be called once for each initializer; it cannot be called
2385
  /// on an initializer having a positive number of (implicit) array indices.
2386
  ///
2387
  /// This assumes that the initializer was written in the source code, and
2388
  /// ensures that isWritten() returns true.
2389
393k
  void setSourceOrder(int Pos) {
2390
393k
    assert(!IsWritten &&
2391
393k
           "setSourceOrder() used on implicit initializer");
2392
0
    assert(SourceOrder == 0 &&
2393
393k
           "calling twice setSourceOrder() on the same initializer");
2394
0
    assert(Pos >= 0 &&
2395
393k
           "setSourceOrder() used to make an initializer implicit");
2396
0
    IsWritten = true;
2397
393k
    SourceOrder = static_cast<unsigned>(Pos);
2398
393k
  }
2399
2400
105k
  SourceLocation getLParenLoc() const { return LParenLoc; }
2401
105k
  SourceLocation getRParenLoc() const { return RParenLoc; }
2402
2403
  /// Get the initializer.
2404
485k
  Expr *getInit() const { return static_cast<Expr *>(Init); }
2405
};
2406
2407
/// Description of a constructor that was inherited from a base class.
2408
class InheritedConstructor {
2409
  ConstructorUsingShadowDecl *Shadow = nullptr;
2410
  CXXConstructorDecl *BaseCtor = nullptr;
2411
2412
public:
2413
2.50M
  InheritedConstructor() = default;
2414
  InheritedConstructor(ConstructorUsingShadowDecl *Shadow,
2415
                       CXXConstructorDecl *BaseCtor)
2416
339
      : Shadow(Shadow), BaseCtor(BaseCtor) {}
2417
2418
4.91M
  explicit operator bool() const { return Shadow; }
2419
2420
1.46k
  ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; }
2421
2.58k
  CXXConstructorDecl *getConstructor() const { return BaseCtor; }
2422
};
2423
2424
/// Represents a C++ constructor within a class.
2425
///
2426
/// For example:
2427
///
2428
/// \code
2429
/// class X {
2430
/// public:
2431
///   explicit X(int); // represented by a CXXConstructorDecl.
2432
/// };
2433
/// \endcode
2434
class CXXConstructorDecl final
2435
    : public CXXMethodDecl,
2436
      private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor,
2437
                                    ExplicitSpecifier> {
2438
  // This class stores some data in DeclContext::CXXConstructorDeclBits
2439
  // to save some space. Use the provided accessors to access it.
2440
2441
  /// \name Support for base and member initializers.
2442
  /// \{
2443
  /// The arguments used to initialize the base or member.
2444
  LazyCXXCtorInitializersPtr CtorInitializers;
2445
2446
  CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2447
                     const DeclarationNameInfo &NameInfo, QualType T,
2448
                     TypeSourceInfo *TInfo, ExplicitSpecifier ES,
2449
                     bool UsesFPIntrin, bool isInline,
2450
                     bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2451
                     InheritedConstructor Inherited,
2452
                     Expr *TrailingRequiresClause);
2453
2454
  void anchor() override;
2455
2456
51.7k
  size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const {
2457
51.7k
    return CXXConstructorDeclBits.IsInheritingConstructor;
2458
51.7k
  }
2459
50.3k
  size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const {
2460
50.3k
    return CXXConstructorDeclBits.HasTrailingExplicitSpecifier;
2461
50.3k
  }
2462
2463
3.72M
  ExplicitSpecifier getExplicitSpecifierInternal() const {
2464
3.72M
    if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier)
2465
1.17k
      return *getTrailingObjects<ExplicitSpecifier>();
2466
3.72M
    return ExplicitSpecifier(
2467
3.72M
        nullptr, CXXConstructorDeclBits.IsSimpleExplicit
2468
3.72M
                     ? 
ExplicitSpecKind::ResolvedTrue776k
2469
3.72M
                     : 
ExplicitSpecKind::ResolvedFalse2.95M
);
2470
3.72M
  }
2471
2472
  enum TrailingAllocKind {
2473
    TAKInheritsConstructor = 1,
2474
    TAKHasTailExplicit = 1 << 1,
2475
  };
2476
2477
50.3k
  uint64_t getTrailingAllocKind() const {
2478
50.3k
    return numTrailingObjects(OverloadToken<InheritedConstructor>()) |
2479
50.3k
           (numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1);
2480
50.3k
  }
2481
2482
public:
2483
  friend class ASTDeclReader;
2484
  friend class ASTDeclWriter;
2485
  friend TrailingObjects;
2486
2487
  static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID,
2488
                                                uint64_t AllocKind);
2489
  static CXXConstructorDecl *
2490
  Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2491
         const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2492
         ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline,
2493
         bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2494
         InheritedConstructor Inherited = InheritedConstructor(),
2495
         Expr *TrailingRequiresClause = nullptr);
2496
2497
1.71M
  void setExplicitSpecifier(ExplicitSpecifier ES) {
2498
1.71M
    assert((!ES.getExpr() ||
2499
1.71M
            CXXConstructorDeclBits.HasTrailingExplicitSpecifier) &&
2500
1.71M
           "cannot set this explicit specifier. no trail-allocated space for "
2501
1.71M
           "explicit");
2502
1.71M
    if (ES.getExpr())
2503
183
      *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES;
2504
1.71M
    else
2505
1.71M
      CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit();
2506
1.71M
  }
2507
2508
2.36M
  ExplicitSpecifier getExplicitSpecifier() {
2509
2.36M
    return getCanonicalDecl()->getExplicitSpecifierInternal();
2510
2.36M
  }
2511
1.36M
  const ExplicitSpecifier getExplicitSpecifier() const {
2512
1.36M
    return getCanonicalDecl()->getExplicitSpecifierInternal();
2513
1.36M
  }
2514
2515
  /// Return true if the declartion is already resolved to be explicit.
2516
1.36M
  bool isExplicit() const { return getExplicitSpecifier().isExplicit(); }
2517
2518
  /// Iterates through the member/base initializer list.
2519
  using init_iterator = CXXCtorInitializer **;
2520
2521
  /// Iterates through the member/base initializer list.
2522
  using init_const_iterator = CXXCtorInitializer *const *;
2523
2524
  using init_range = llvm::iterator_range<init_iterator>;
2525
  using init_const_range = llvm::iterator_range<init_const_iterator>;
2526
2527
173k
  init_range inits() { return init_range(init_begin(), init_end()); }
2528
109k
  init_const_range inits() const {
2529
109k
    return init_const_range(init_begin(), init_end());
2530
109k
  }
2531
2532
  /// Retrieve an iterator to the first initializer.
2533
346k
  init_iterator init_begin() {
2534
346k
    const auto *ConstThis = this;
2535
346k
    return const_cast<init_iterator>(ConstThis->init_begin());
2536
346k
  }
2537
2538
  /// Retrieve an iterator to the first initializer.
2539
  init_const_iterator init_begin() const;
2540
2541
  /// Retrieve an iterator past the last initializer.
2542
173k
  init_iterator       init_end()       {
2543
173k
    return init_begin() + getNumCtorInitializers();
2544
173k
  }
2545
2546
  /// Retrieve an iterator past the last initializer.
2547
150k
  init_const_iterator init_end() const {
2548
150k
    return init_begin() + getNumCtorInitializers();
2549
150k
  }
2550
2551
  using init_reverse_iterator = std::reverse_iterator<init_iterator>;
2552
  using init_const_reverse_iterator =
2553
      std::reverse_iterator<init_const_iterator>;
2554
2555
0
  init_reverse_iterator init_rbegin() {
2556
0
    return init_reverse_iterator(init_end());
2557
0
  }
2558
0
  init_const_reverse_iterator init_rbegin() const {
2559
0
    return init_const_reverse_iterator(init_end());
2560
0
  }
2561
2562
0
  init_reverse_iterator init_rend() {
2563
0
    return init_reverse_iterator(init_begin());
2564
0
  }
2565
0
  init_const_reverse_iterator init_rend() const {
2566
0
    return init_const_reverse_iterator(init_begin());
2567
0
  }
2568
2569
  /// Determine the number of arguments used to initialize the member
2570
  /// or base.
2571
727k
  unsigned getNumCtorInitializers() const {
2572
727k
      return CXXConstructorDeclBits.NumCtorInitializers;
2573
727k
  }
2574
2575
1.72M
  void setNumCtorInitializers(unsigned numCtorInitializers) {
2576
1.72M
    CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers;
2577
    // This assert added because NumCtorInitializers is stored
2578
    // in CXXConstructorDeclBits as a bitfield and its width has
2579
    // been shrunk from 32 bits to fit into CXXConstructorDeclBitfields.
2580
1.72M
    assert(CXXConstructorDeclBits.NumCtorInitializers ==
2581
1.72M
           numCtorInitializers && "NumCtorInitializers overflow!");
2582
1.72M
  }
2583
2584
319k
  void setCtorInitializers(CXXCtorInitializer **Initializers) {
2585
319k
    CtorInitializers = Initializers;
2586
319k
  }
2587
2588
  /// Determine whether this constructor is a delegating constructor.
2589
64.3k
  bool isDelegatingConstructor() const {
2590
64.3k
    return (getNumCtorInitializers() == 1) &&
2591
64.3k
           
init_begin()[0]->isDelegatingInitializer()34.4k
;
2592
64.3k
  }
2593
2594
  /// When this constructor delegates to another, retrieve the target.
2595
  CXXConstructorDecl *getTargetConstructor() const;
2596
2597
  /// Whether this constructor is a default
2598
  /// constructor (C++ [class.ctor]p5), which can be used to
2599
  /// default-initialize a class of this type.
2600
  bool isDefaultConstructor() const;
2601
2602
  /// Whether this constructor is a copy constructor (C++ [class.copy]p2,
2603
  /// which can be used to copy the class.
2604
  ///
2605
  /// \p TypeQuals will be set to the qualifiers on the
2606
  /// argument type. For example, \p TypeQuals would be set to \c
2607
  /// Qualifiers::Const for the following copy constructor:
2608
  ///
2609
  /// \code
2610
  /// class X {
2611
  /// public:
2612
  ///   X(const X&);
2613
  /// };
2614
  /// \endcode
2615
  bool isCopyConstructor(unsigned &TypeQuals) const;
2616
2617
  /// Whether this constructor is a copy
2618
  /// constructor (C++ [class.copy]p2, which can be used to copy the
2619
  /// class.
2620
777k
  bool isCopyConstructor() const {
2621
777k
    unsigned TypeQuals = 0;
2622
777k
    return isCopyConstructor(TypeQuals);
2623
777k
  }
2624
2625
  /// Determine whether this constructor is a move constructor
2626
  /// (C++11 [class.copy]p3), which can be used to move values of the class.
2627
  ///
2628
  /// \param TypeQuals If this constructor is a move constructor, will be set
2629
  /// to the type qualifiers on the referent of the first parameter's type.
2630
  bool isMoveConstructor(unsigned &TypeQuals) const;
2631
2632
  /// Determine whether this constructor is a move constructor
2633
  /// (C++11 [class.copy]p3), which can be used to move values of the class.
2634
986k
  bool isMoveConstructor() const {
2635
986k
    unsigned TypeQuals = 0;
2636
986k
    return isMoveConstructor(TypeQuals);
2637
986k
  }
2638
2639
  /// Determine whether this is a copy or move constructor.
2640
  ///
2641
  /// \param TypeQuals Will be set to the type qualifiers on the reference
2642
  /// parameter, if in fact this is a copy or move constructor.
2643
  bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2644
2645
  /// Determine whether this a copy or move constructor.
2646
2.59M
  bool isCopyOrMoveConstructor() const {
2647
2.59M
    unsigned Quals;
2648
2.59M
    return isCopyOrMoveConstructor(Quals);
2649
2.59M
  }
2650
2651
  /// Whether this constructor is a
2652
  /// converting constructor (C++ [class.conv.ctor]), which can be
2653
  /// used for user-defined conversions.
2654
  bool isConvertingConstructor(bool AllowExplicit) const;
2655
2656
  /// Determine whether this is a member template specialization that
2657
  /// would copy the object to itself. Such constructors are never used to copy
2658
  /// an object.
2659
  bool isSpecializationCopyingObject() const;
2660
2661
  /// Determine whether this is an implicit constructor synthesized to
2662
  /// model a call to a constructor inherited from a base class.
2663
2.78M
  bool isInheritingConstructor() const {
2664
2.78M
    return CXXConstructorDeclBits.IsInheritingConstructor;
2665
2.78M
  }
2666
2667
  /// State that this is an implicit constructor synthesized to
2668
  /// model a call to a constructor inherited from a base class.
2669
1.51M
  void setInheritingConstructor(bool isIC = true) {
2670
1.51M
    CXXConstructorDeclBits.IsInheritingConstructor = isIC;
2671
1.51M
  }
2672
2673
  /// Get the constructor that this inheriting constructor is based on.
2674
1.21M
  InheritedConstructor getInheritedConstructor() const {
2675
1.21M
    return isInheritingConstructor() ?
2676
1.20M
      
*getTrailingObjects<InheritedConstructor>()5.48k
: InheritedConstructor();
2677
1.21M
  }
2678
2679
43.7M
  CXXConstructorDecl *getCanonicalDecl() override {
2680
43.7M
    return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2681
43.7M
  }
2682
1.36M
  const CXXConstructorDecl *getCanonicalDecl() const {
2683
1.36M
    return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl();
2684
1.36M
  }
2685
2686
  // Implement isa/cast/dyncast/etc.
2687
203M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2688
203M
  static bool classofKind(Kind K) { return K == CXXConstructor; }
2689
};
2690
2691
/// Represents a C++ destructor within a class.
2692
///
2693
/// For example:
2694
///
2695
/// \code
2696
/// class X {
2697
/// public:
2698
///   ~X(); // represented by a CXXDestructorDecl.
2699
/// };
2700
/// \endcode
2701
class CXXDestructorDecl : public CXXMethodDecl {
2702
  friend class ASTDeclReader;
2703
  friend class ASTDeclWriter;
2704
2705
  // FIXME: Don't allocate storage for these except in the first declaration
2706
  // of a virtual destructor.
2707
  FunctionDecl *OperatorDelete = nullptr;
2708
  Expr *OperatorDeleteThisArg = nullptr;
2709
2710
  CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2711
                    const DeclarationNameInfo &NameInfo, QualType T,
2712
                    TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline,
2713
                    bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2714
                    Expr *TrailingRequiresClause = nullptr)
2715
      : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
2716
                      SC_None, UsesFPIntrin, isInline, ConstexprKind,
2717
208k
                      SourceLocation(), TrailingRequiresClause) {
2718
208k
    setImplicit(isImplicitlyDeclared);
2719
208k
  }
2720
2721
  void anchor() override;
2722
2723
public:
2724
  static CXXDestructorDecl *
2725
  Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2726
         const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2727
         bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared,
2728
         ConstexprSpecKind ConstexprKind,
2729
         Expr *TrailingRequiresClause = nullptr);
2730
  static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2731
2732
  void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg);
2733
2734
57.3k
  const FunctionDecl *getOperatorDelete() const {
2735
57.3k
    return getCanonicalDecl()->OperatorDelete;
2736
57.3k
  }
2737
2738
22.5k
  Expr *getOperatorDeleteThisArg() const {
2739
22.5k
    return getCanonicalDecl()->OperatorDeleteThisArg;
2740
22.5k
  }
2741
2742
8.57M
  CXXDestructorDecl *getCanonicalDecl() override {
2743
8.57M
    return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl());
2744
8.57M
  }
2745
79.8k
  const CXXDestructorDecl *getCanonicalDecl() const {
2746
79.8k
    return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl();
2747
79.8k
  }
2748
2749
  // Implement isa/cast/dyncast/etc.
2750
145M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2751
145M
  static bool classofKind(Kind K) { return K == CXXDestructor; }
2752
};
2753
2754
/// Represents a C++ conversion function within a class.
2755
///
2756
/// For example:
2757
///
2758
/// \code
2759
/// class X {
2760
/// public:
2761
///   operator bool();
2762
/// };
2763
/// \endcode
2764
class CXXConversionDecl : public CXXMethodDecl {
2765
  CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2766
                    const DeclarationNameInfo &NameInfo, QualType T,
2767
                    TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline,
2768
                    ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind,
2769
                    SourceLocation EndLocation,
2770
                    Expr *TrailingRequiresClause = nullptr)
2771
      : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
2772
                      SC_None, UsesFPIntrin, isInline, ConstexprKind,
2773
                      EndLocation, TrailingRequiresClause),
2774
43.9k
        ExplicitSpec(ES) {}
2775
  void anchor() override;
2776
2777
  ExplicitSpecifier ExplicitSpec;
2778
2779
public:
2780
  friend class ASTDeclReader;
2781
  friend class ASTDeclWriter;
2782
2783
  static CXXConversionDecl *
2784
  Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2785
         const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2786
         bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES,
2787
         ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
2788
         Expr *TrailingRequiresClause = nullptr);
2789
  static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2790
2791
23.9k
  ExplicitSpecifier getExplicitSpecifier() {
2792
23.9k
    return getCanonicalDecl()->ExplicitSpec;
2793
23.9k
  }
2794
2795
1.23M
  const ExplicitSpecifier getExplicitSpecifier() const {
2796
1.23M
    return getCanonicalDecl()->ExplicitSpec;
2797
1.23M
  }
2798
2799
  /// Return true if the declartion is already resolved to be explicit.
2800
1.23M
  bool isExplicit() const { return getExplicitSpecifier().isExplicit(); }
2801
5.31k
  void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; }
2802
2803
  /// Returns the type that this conversion function is converting to.
2804
1.87M
  QualType getConversionType() const {
2805
1.87M
    return getType()->castAs<FunctionType>()->getReturnType();
2806
1.87M
  }
2807
2808
  /// Determine whether this conversion function is a conversion from
2809
  /// a lambda closure type to a block pointer.
2810
  bool isLambdaToBlockPointerConversion() const;
2811
2812
4.28M
  CXXConversionDecl *getCanonicalDecl() override {
2813
4.28M
    return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl());
2814
4.28M
  }
2815
1.23M
  const CXXConversionDecl *getCanonicalDecl() const {
2816
1.23M
    return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl();
2817
1.23M
  }
2818
2819
  // Implement isa/cast/dyncast/etc.
2820
25.9M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2821
25.9M
  static bool classofKind(Kind K) { return K == CXXConversion; }
2822
};
2823
2824
/// Represents a linkage specification.
2825
///
2826
/// For example:
2827
/// \code
2828
///   extern "C" void foo();
2829
/// \endcode
2830
class LinkageSpecDecl : public Decl, public DeclContext {
2831
  virtual void anchor();
2832
  // This class stores some data in DeclContext::LinkageSpecDeclBits to save
2833
  // some space. Use the provided accessors to access it.
2834
public:
2835
  /// Represents the language in a linkage specification.
2836
  ///
2837
  /// The values are part of the serialization ABI for
2838
  /// ASTs and cannot be changed without altering that ABI.
2839
  enum LanguageIDs { lang_c = 1, lang_cxx = 2 };
2840
2841
private:
2842
  /// The source location for the extern keyword.
2843
  SourceLocation ExternLoc;
2844
2845
  /// The source location for the right brace (if valid).
2846
  SourceLocation RBraceLoc;
2847
2848
  LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2849
                  SourceLocation LangLoc, LanguageIDs lang, bool HasBraces);
2850
2851
public:
2852
  static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2853
                                 SourceLocation ExternLoc,
2854
                                 SourceLocation LangLoc, LanguageIDs Lang,
2855
                                 bool HasBraces);
2856
  static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2857
2858
  /// Return the language specified by this linkage specification.
2859
31.9M
  LanguageIDs getLanguage() const {
2860
31.9M
    return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language);
2861
31.9M
  }
2862
2863
  /// Set the language specified by this linkage specification.
2864
410k
  void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; }
2865
2866
  /// Determines whether this linkage specification had braces in
2867
  /// its syntactic form.
2868
212k
  bool hasBraces() const {
2869
212k
    assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces);
2870
0
    return LinkageSpecDeclBits.HasBraces;
2871
212k
  }
2872
2873
31.5k
  SourceLocation getExternLoc() const { return ExternLoc; }
2874
64.9k
  SourceLocation getRBraceLoc() const { return RBraceLoc; }
2875
24.3k
  void setExternLoc(SourceLocation L) { ExternLoc = L; }
2876
96.8k
  void setRBraceLoc(SourceLocation L) {
2877
96.8k
    RBraceLoc = L;
2878
96.8k
    LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid();
2879
96.8k
  }
2880
2881
37.1k
  SourceLocation getEndLoc() const LLVM_READONLY {
2882
37.1k
    if (hasBraces())
2883
37.0k
      return getRBraceLoc();
2884
    // No braces: get the end location of the (only) declaration in context
2885
    // (if present).
2886
78
    return decls_empty() ? 
getLocation()0
: decls_begin()->getEndLoc();
2887
37.1k
  }
2888
2889
37.1k
  SourceRange getSourceRange() const override LLVM_READONLY {
2890
37.1k
    return SourceRange(ExternLoc, getEndLoc());
2891
37.1k
  }
2892
2893
987k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2894
113M
  static bool classofKind(Kind K) { return K == LinkageSpec; }
2895
2896
13.3k
  static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2897
13.3k
    return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2898
13.3k
  }
2899
2900
0
  static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2901
0
    return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2902
0
  }
2903
};
2904
2905
/// Represents C++ using-directive.
2906
///
2907
/// For example:
2908
/// \code
2909
///    using namespace std;
2910
/// \endcode
2911
///
2912
/// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2913
/// artificial names for all using-directives in order to store
2914
/// them in DeclContext effectively.
2915
class UsingDirectiveDecl : public NamedDecl {
2916
  /// The location of the \c using keyword.
2917
  SourceLocation UsingLoc;
2918
2919
  /// The location of the \c namespace keyword.
2920
  SourceLocation NamespaceLoc;
2921
2922
  /// The nested-name-specifier that precedes the namespace.
2923
  NestedNameSpecifierLoc QualifierLoc;
2924
2925
  /// The namespace nominated by this using-directive.
2926
  NamedDecl *NominatedNamespace;
2927
2928
  /// Enclosing context containing both using-directive and nominated
2929
  /// namespace.
2930
  DeclContext *CommonAncestor;
2931
2932
  UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2933
                     SourceLocation NamespcLoc,
2934
                     NestedNameSpecifierLoc QualifierLoc,
2935
                     SourceLocation IdentLoc,
2936
                     NamedDecl *Nominated,
2937
                     DeclContext *CommonAncestor)
2938
      : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2939
        NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2940
6.18k
        NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {}
2941
2942
  /// Returns special DeclarationName used by using-directives.
2943
  ///
2944
  /// This is only used by DeclContext for storing UsingDirectiveDecls in
2945
  /// its lookup structure.
2946
108M
  static DeclarationName getName() {
2947
108M
    return DeclarationName::getUsingDirectiveName();
2948
108M
  }
2949
2950
  void anchor() override;
2951
2952
public:
2953
  friend class ASTDeclReader;
2954
2955
  // Friend for getUsingDirectiveName.
2956
  friend class DeclContext;
2957
2958
  /// Retrieve the nested-name-specifier that qualifies the
2959
  /// name of the namespace, with source-location information.
2960
1.86k
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2961
2962
  /// Retrieve the nested-name-specifier that qualifies the
2963
  /// name of the namespace.
2964
8
  NestedNameSpecifier *getQualifier() const {
2965
8
    return QualifierLoc.getNestedNameSpecifier();
2966
8
  }
2967
2968
10
  NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2969
6
  const NamedDecl *getNominatedNamespaceAsWritten() const {
2970
6
    return NominatedNamespace;
2971
6
  }
2972
2973
  /// Returns the namespace nominated by this using-directive.
2974
  NamespaceDecl *getNominatedNamespace();
2975
2976
905
  const NamespaceDecl *getNominatedNamespace() const {
2977
905
    return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2978
905
  }
2979
2980
  /// Returns the common ancestor context of this using-directive and
2981
  /// its nominated namespace.
2982
1.24k
  DeclContext *getCommonAncestor() { return CommonAncestor; }
2983
0
  const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2984
2985
  /// Return the location of the \c using keyword.
2986
421
  SourceLocation getUsingLoc() const { return UsingLoc; }
2987
2988
  // FIXME: Could omit 'Key' in name.
2989
  /// Returns the location of the \c namespace keyword.
2990
886
  SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2991
2992
  /// Returns the location of this using declaration's identifier.
2993
739
  SourceLocation getIdentLocation() const { return getLocation(); }
2994
2995
  static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2996
                                    SourceLocation UsingLoc,
2997
                                    SourceLocation NamespaceLoc,
2998
                                    NestedNameSpecifierLoc QualifierLoc,
2999
                                    SourceLocation IdentLoc,
3000
                                    NamedDecl *Nominated,
3001
                                    DeclContext *CommonAncestor);
3002
  static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3003
3004
100
  SourceRange getSourceRange() const override LLVM_READONLY {
3005
100
    return SourceRange(UsingLoc, getLocation());
3006
100
  }
3007
3008
23.1M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3009
23.1M
  static bool classofKind(Kind K) { return K == UsingDirective; }
3010
};
3011
3012
/// Represents a C++ namespace alias.
3013
///
3014
/// For example:
3015
///
3016
/// \code
3017
/// namespace Foo = Bar;
3018
/// \endcode
3019
class NamespaceAliasDecl : public NamedDecl,
3020
                           public Redeclarable<NamespaceAliasDecl> {
3021
  friend class ASTDeclReader;
3022
3023
  /// The location of the \c namespace keyword.
3024
  SourceLocation NamespaceLoc;
3025
3026
  /// The location of the namespace's identifier.
3027
  ///
3028
  /// This is accessed by TargetNameLoc.
3029
  SourceLocation IdentLoc;
3030
3031
  /// The nested-name-specifier that precedes the namespace.
3032
  NestedNameSpecifierLoc QualifierLoc;
3033
3034
  /// The Decl that this alias points to, either a NamespaceDecl or
3035
  /// a NamespaceAliasDecl.
3036
  NamedDecl *Namespace;
3037
3038
  NamespaceAliasDecl(ASTContext &C, DeclContext *DC,
3039
                     SourceLocation NamespaceLoc, SourceLocation AliasLoc,
3040
                     IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc,
3041
                     SourceLocation IdentLoc, NamedDecl *Namespace)
3042
      : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C),
3043
        NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
3044
376
        QualifierLoc(QualifierLoc), Namespace(Namespace) {}
3045
3046
  void anchor() override;
3047
3048
  using redeclarable_base = Redeclarable<NamespaceAliasDecl>;
3049
3050
  NamespaceAliasDecl *getNextRedeclarationImpl() override;
3051
  NamespaceAliasDecl *getPreviousDeclImpl() override;
3052
  NamespaceAliasDecl *getMostRecentDeclImpl() override;
3053
3054
public:
3055
  static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
3056
                                    SourceLocation NamespaceLoc,
3057
                                    SourceLocation AliasLoc,
3058
                                    IdentifierInfo *Alias,
3059
                                    NestedNameSpecifierLoc QualifierLoc,
3060
                                    SourceLocation IdentLoc,
3061
                                    NamedDecl *Namespace);
3062
3063
  static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3064
3065
  using redecl_range = redeclarable_base::redecl_range;
3066
  using redecl_iterator = redeclarable_base::redecl_iterator;
3067
3068
  using redeclarable_base::redecls_begin;
3069
  using redeclarable_base::redecls_end;
3070
  using redeclarable_base::redecls;
3071
  using redeclarable_base::getPreviousDecl;
3072
  using redeclarable_base::getMostRecentDecl;
3073
3074
289
  NamespaceAliasDecl *getCanonicalDecl() override {
3075
289
    return getFirstDecl();
3076
289
  }
3077
0
  const NamespaceAliasDecl *getCanonicalDecl() const {
3078
0
    return getFirstDecl();
3079
0
  }
3080
3081
  /// Retrieve the nested-name-specifier that qualifies the
3082
  /// name of the namespace, with source-location information.
3083
333
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3084
3085
  /// Retrieve the nested-name-specifier that qualifies the
3086
  /// name of the namespace.
3087
7
  NestedNameSpecifier *getQualifier() const {
3088
7
    return QualifierLoc.getNestedNameSpecifier();
3089
7
  }
3090
3091
  /// Retrieve the namespace declaration aliased by this directive.
3092
6.58k
  NamespaceDecl *getNamespace() {
3093
6.58k
    if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
3094
145
      return AD->getNamespace();
3095
3096
6.43k
    return cast<NamespaceDecl>(Namespace);
3097
6.58k
  }
3098
3099
14
  const NamespaceDecl *getNamespace() const {
3100
14
    return const_cast<NamespaceAliasDecl *>(this)->getNamespace();
3101
14
  }
3102
3103
  /// Returns the location of the alias name, i.e. 'foo' in
3104
  /// "namespace foo = ns::bar;".
3105
5
  SourceLocation getAliasLoc() const { return getLocation(); }
3106
3107
  /// Returns the location of the \c namespace keyword.
3108
19
  SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
3109
3110
  /// Returns the location of the identifier in the named namespace.
3111
30
  SourceLocation getTargetNameLoc() const { return IdentLoc; }
3112
3113
  /// Retrieve the namespace that this alias refers to, which
3114
  /// may either be a NamespaceDecl or a NamespaceAliasDecl.
3115
102
  NamedDecl *getAliasedNamespace() const { return Namespace; }
3116
3117
48
  SourceRange getSourceRange() const override LLVM_READONLY {
3118
48
    return SourceRange(NamespaceLoc, IdentLoc);
3119
48
  }
3120
3121
47.5M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3122
47.5M
  static bool classofKind(Kind K) { return K == NamespaceAlias; }
3123
};
3124
3125
/// Implicit declaration of a temporary that was materialized by
3126
/// a MaterializeTemporaryExpr and lifetime-extended by a declaration
3127
class LifetimeExtendedTemporaryDecl final
3128
    : public Decl,
3129
      public Mergeable<LifetimeExtendedTemporaryDecl> {
3130
  friend class MaterializeTemporaryExpr;
3131
  friend class ASTDeclReader;
3132
3133
  Stmt *ExprWithTemporary = nullptr;
3134
3135
  /// The declaration which lifetime-extended this reference, if any.
3136
  /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
3137
  ValueDecl *ExtendingDecl = nullptr;
3138
  unsigned ManglingNumber;
3139
3140
  mutable APValue *Value = nullptr;
3141
3142
  virtual void anchor();
3143
3144
  LifetimeExtendedTemporaryDecl(Expr *Temp, ValueDecl *EDecl, unsigned Mangling)
3145
      : Decl(Decl::LifetimeExtendedTemporary, EDecl->getDeclContext(),
3146
             EDecl->getLocation()),
3147
        ExprWithTemporary(Temp), ExtendingDecl(EDecl),
3148
2.41k
        ManglingNumber(Mangling) {}
3149
3150
  LifetimeExtendedTemporaryDecl(EmptyShell)
3151
17
      : Decl(Decl::LifetimeExtendedTemporary, EmptyShell{}) {}
3152
3153
public:
3154
  static LifetimeExtendedTemporaryDecl *Create(Expr *Temp, ValueDecl *EDec,
3155
2.41k
                                               unsigned Mangling) {
3156
2.41k
    return new (EDec->getASTContext(), EDec->getDeclContext())
3157
2.41k
        LifetimeExtendedTemporaryDecl(Temp, EDec, Mangling);
3158
2.41k
  }
3159
  static LifetimeExtendedTemporaryDecl *CreateDeserialized(ASTContext &C,
3160
17
                                                           unsigned ID) {
3161
17
    return new (C, ID) LifetimeExtendedTemporaryDecl(EmptyShell{});
3162
17
  }
3163
3164
2.35k
  ValueDecl *getExtendingDecl() { return ExtendingDecl; }
3165
11.9k
  const ValueDecl *getExtendingDecl() const { return ExtendingDecl; }
3166
3167
  /// Retrieve the storage duration for the materialized temporary.
3168
  StorageDuration getStorageDuration() const;
3169
3170
  /// Retrieve the expression to which the temporary materialization conversion
3171
  /// was applied. This isn't necessarily the initializer of the temporary due
3172
  /// to the C++98 delayed materialization rules, but
3173
  /// skipRValueSubobjectAdjustments can be used to find said initializer within
3174
  /// the subexpression.
3175
29.4k
  Expr *getTemporaryExpr() { return cast<Expr>(ExprWithTemporary); }
3176
0
  const Expr *getTemporaryExpr() const { return cast<Expr>(ExprWithTemporary); }
3177
3178
261
  unsigned getManglingNumber() const { return ManglingNumber; }
3179
3180
  /// Get the storage for the constant value of a materialized temporary
3181
  /// of static storage duration.
3182
  APValue *getOrCreateValue(bool MayCreate) const;
3183
3184
33
  APValue *getValue() const { return Value; }
3185
3186
  // Iterators
3187
6.64k
  Stmt::child_range childrenExpr() {
3188
6.64k
    return Stmt::child_range(&ExprWithTemporary, &ExprWithTemporary + 1);
3189
6.64k
  }
3190
3191
0
  Stmt::const_child_range childrenExpr() const {
3192
0
    return Stmt::const_child_range(&ExprWithTemporary, &ExprWithTemporary + 1);
3193
0
  }
3194
3195
49.0M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3196
49.0M
  static bool classofKind(Kind K) {
3197
49.0M
    return K == Decl::LifetimeExtendedTemporary;
3198
49.0M
  }
3199
};
3200
3201
/// Represents a shadow declaration implicitly introduced into a scope by a
3202
/// (resolved) using-declaration or using-enum-declaration to achieve
3203
/// the desired lookup semantics.
3204
///
3205
/// For example:
3206
/// \code
3207
/// namespace A {
3208
///   void foo();
3209
///   void foo(int);
3210
///   struct foo {};
3211
///   enum bar { bar1, bar2 };
3212
/// }
3213
/// namespace B {
3214
///   // add a UsingDecl and three UsingShadowDecls (named foo) to B.
3215
///   using A::foo;
3216
///   // adds UsingEnumDecl and two UsingShadowDecls (named bar1 and bar2) to B.
3217
///   using enum A::bar;
3218
/// }
3219
/// \endcode
3220
class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
3221
  friend class BaseUsingDecl;
3222
3223
  /// The referenced declaration.
3224
  NamedDecl *Underlying = nullptr;
3225
3226
  /// The using declaration which introduced this decl or the next using
3227
  /// shadow declaration contained in the aforementioned using declaration.
3228
  NamedDecl *UsingOrNextShadow = nullptr;
3229
3230
  void anchor() override;
3231
3232
  using redeclarable_base = Redeclarable<UsingShadowDecl>;
3233
3234
394k
  UsingShadowDecl *getNextRedeclarationImpl() override {
3235
394k
    return getNextRedeclaration();
3236
394k
  }
3237
3238
359k
  UsingShadowDecl *getPreviousDeclImpl() override {
3239
359k
    return getPreviousDecl();
3240
359k
  }
3241
3242
959k
  UsingShadowDecl *getMostRecentDeclImpl() override {
3243
959k
    return getMostRecentDecl();
3244
959k
  }
3245
3246
protected:
3247
  UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc,
3248
                  DeclarationName Name, BaseUsingDecl *Introducer,
3249
                  NamedDecl *Target);
3250
  UsingShadowDecl(Kind K, ASTContext &C, EmptyShell);
3251
3252
public:
3253
  friend class ASTDeclReader;
3254
  friend class ASTDeclWriter;
3255
3256
  static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
3257
                                 SourceLocation Loc, DeclarationName Name,
3258
400k
                                 BaseUsingDecl *Introducer, NamedDecl *Target) {
3259
400k
    return new (C, DC)
3260
400k
        UsingShadowDecl(UsingShadow, C, DC, Loc, Name, Introducer, Target);
3261
400k
  }
3262
3263
  static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3264
3265
  using redecl_range = redeclarable_base::redecl_range;
3266
  using redecl_iterator = redeclarable_base::redecl_iterator;
3267
3268
  using redeclarable_base::redecls_begin;
3269
  using redeclarable_base::redecls_end;
3270
  using redeclarable_base::redecls;
3271
  using redeclarable_base::getPreviousDecl;
3272
  using redeclarable_base::getMostRecentDecl;
3273
  using redeclarable_base::isFirstDecl;
3274
3275
3.03M
  UsingShadowDecl *getCanonicalDecl() override {
3276
3.03M
    return getFirstDecl();
3277
3.03M
  }
3278
0
  const UsingShadowDecl *getCanonicalDecl() const {
3279
0
    return getFirstDecl();
3280
0
  }
3281
3282
  /// Gets the underlying declaration which has been brought into the
3283
  /// local scope.
3284
3.68M
  NamedDecl *getTargetDecl() const { return Underlying; }
3285
3286
  /// Sets the underlying declaration which has been brought into the
3287
  /// local scope.
3288
403k
  void setTargetDecl(NamedDecl *ND) {
3289
403k
    assert(ND && "Target decl is null!");
3290
0
    Underlying = ND;
3291
    // A UsingShadowDecl is never a friend or local extern declaration, even
3292
    // if it is a shadow declaration for one.
3293
403k
    IdentifierNamespace =
3294
403k
        ND->getIdentifierNamespace() &
3295
403k
        ~(IDNS_OrdinaryFriend | IDNS_TagFriend | IDNS_LocalExtern);
3296
403k
  }
3297
3298
  /// Gets the (written or instantiated) using declaration that introduced this
3299
  /// declaration.
3300
  BaseUsingDecl *getIntroducer() const;
3301
3302
  /// The next using shadow declaration contained in the shadow decl
3303
  /// chain of the using declaration which introduced this decl.
3304
1.46M
  UsingShadowDecl *getNextUsingShadowDecl() const {
3305
1.46M
    return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
3306
1.46M
  }
3307
3308
315M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3309
315M
  static bool classofKind(Kind K) {
3310
315M
    return K == Decl::UsingShadow || 
K == Decl::ConstructorUsingShadow310M
;
3311
315M
  }
3312
};
3313
3314
/// Represents a C++ declaration that introduces decls from somewhere else. It
3315
/// provides a set of the shadow decls so introduced.
3316
3317
class BaseUsingDecl : public NamedDecl {
3318
  /// The first shadow declaration of the shadow decl chain associated
3319
  /// with this using declaration.
3320
  ///
3321
  /// The bool member of the pair is a bool flag a derived type may use
3322
  /// (UsingDecl makes use of it).
3323
  llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
3324
3325
protected:
3326
  BaseUsingDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
3327
246k
      : NamedDecl(DK, DC, L, N), FirstUsingShadow(nullptr, false) {}
3328
3329
private:
3330
  void anchor() override;
3331
3332
protected:
3333
  /// A bool flag for use by a derived type
3334
24.9k
  bool getShadowFlag() const { return FirstUsingShadow.getInt(); }
3335
3336
  /// A bool flag a derived type may set
3337
260k
  void setShadowFlag(bool V) { FirstUsingShadow.setInt(V); }
3338
3339
public:
3340
  friend class ASTDeclReader;
3341
  friend class ASTDeclWriter;
3342
3343
  /// Iterates through the using shadow declarations associated with
3344
  /// this using declaration.
3345
  class shadow_iterator {
3346
    /// The current using shadow declaration.
3347
    UsingShadowDecl *Current = nullptr;
3348
3349
  public:
3350
    using value_type = UsingShadowDecl *;
3351
    using reference = UsingShadowDecl *;
3352
    using pointer = UsingShadowDecl *;
3353
    using iterator_category = std::forward_iterator_tag;
3354
    using difference_type = std::ptrdiff_t;
3355
3356
809k
    shadow_iterator() = default;
3357
810k
    explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {}
3358
3359
1.36M
    reference operator*() const { return Current; }
3360
210
    pointer operator->() const { return Current; }
3361
3362
1.46M
    shadow_iterator &operator++() {
3363
1.46M
      Current = Current->getNextUsingShadowDecl();
3364
1.46M
      return *this;
3365
1.46M
    }
3366
3367
0
    shadow_iterator operator++(int) {
3368
0
      shadow_iterator tmp(*this);
3369
0
      ++(*this);
3370
0
      return tmp;
3371
0
    }
3372
3373
155
    friend bool operator==(shadow_iterator x, shadow_iterator y) {
3374
155
      return x.Current == y.Current;
3375
155
    }
3376
2.67M
    friend bool operator!=(shadow_iterator x, shadow_iterator y) {
3377
2.67M
      return x.Current != y.Current;
3378
2.67M
    }
3379
  };
3380
3381
  using shadow_range = llvm::iterator_range<shadow_iterator>;
3382
3383
609k
  shadow_range shadows() const {
3384
609k
    return shadow_range(shadow_begin(), shadow_end());
3385
609k
  }
3386
3387
810k
  shadow_iterator shadow_begin() const {
3388
810k
    return shadow_iterator(FirstUsingShadow.getPointer());
3389
810k
  }
3390
3391
809k
  shadow_iterator shadow_end() const { return shadow_iterator(); }
3392
3393
  /// Return the number of shadowed declarations associated with this
3394
  /// using declaration.
3395
200k
  unsigned shadow_size() const {
3396
200k
    return std::distance(shadow_begin(), shadow_end());
3397
200k
  }
3398
3399
  void addShadowDecl(UsingShadowDecl *S);
3400
  void removeShadowDecl(UsingShadowDecl *S);
3401
3402
544k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3403
544k
  static bool classofKind(Kind K) { return K == Using || 
K == UsingEnum191
; }
3404
};
3405
3406
/// Represents a C++ using-declaration.
3407
///
3408
/// For example:
3409
/// \code
3410
///    using someNameSpace::someIdentifier;
3411
/// \endcode
3412
class UsingDecl : public BaseUsingDecl, public Mergeable<UsingDecl> {
3413
  /// The source location of the 'using' keyword itself.
3414
  SourceLocation UsingLocation;
3415
3416
  /// The nested-name-specifier that precedes the name.
3417
  NestedNameSpecifierLoc QualifierLoc;
3418
3419
  /// Provides source/type location info for the declaration name
3420
  /// embedded in the ValueDecl base class.
3421
  DeclarationNameLoc DNLoc;
3422
3423
  UsingDecl(DeclContext *DC, SourceLocation UL,
3424
            NestedNameSpecifierLoc QualifierLoc,
3425
            const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
3426
      : BaseUsingDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
3427
        UsingLocation(UL), QualifierLoc(QualifierLoc),
3428
246k
        DNLoc(NameInfo.getInfo()) {
3429
246k
    setShadowFlag(HasTypenameKeyword);
3430
246k
  }
3431
3432
  void anchor() override;
3433
3434
public:
3435
  friend class ASTDeclReader;
3436
  friend class ASTDeclWriter;
3437
3438
  /// Return the source location of the 'using' keyword.
3439
12.4k
  SourceLocation getUsingLoc() const { return UsingLocation; }
3440
3441
  /// Set the source location of the 'using' keyword.
3442
13.9k
  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3443
3444
  /// Retrieve the nested-name-specifier that qualifies the name,
3445
  /// with source-location information.
3446
18.6k
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3447
3448
  /// Retrieve the nested-name-specifier that qualifies the name.
3449
35.1k
  NestedNameSpecifier *getQualifier() const {
3450
35.1k
    return QualifierLoc.getNestedNameSpecifier();
3451
35.1k
  }
3452
3453
18.3k
  DeclarationNameInfo getNameInfo() const {
3454
18.3k
    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3455
18.3k
  }
3456
3457
  /// Return true if it is a C++03 access declaration (no 'using').
3458
11.8k
  bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3459
3460
  /// Return true if the using declaration has 'typename'.
3461
24.9k
  bool hasTypename() const { return getShadowFlag(); }
3462
3463
  /// Sets whether the using declaration has 'typename'.
3464
13.9k
  void setTypename(bool TN) { setShadowFlag(TN); }
3465
3466
  static UsingDecl *Create(ASTContext &C, DeclContext *DC,
3467
                           SourceLocation UsingL,
3468
                           NestedNameSpecifierLoc QualifierLoc,
3469
                           const DeclarationNameInfo &NameInfo,
3470
                           bool HasTypenameKeyword);
3471
3472
  static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3473
3474
  SourceRange getSourceRange() const override LLVM_READONLY;
3475
3476
  /// Retrieves the canonical declaration of this declaration.
3477
591k
  UsingDecl *getCanonicalDecl() override {
3478
591k
    return cast<UsingDecl>(getFirstDecl());
3479
591k
  }
3480
0
  const UsingDecl *getCanonicalDecl() const {
3481
0
    return cast<UsingDecl>(getFirstDecl());
3482
0
  }
3483
3484
104M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3485
104M
  static bool classofKind(Kind K) { return K == Using; }
3486
};
3487
3488
/// Represents a shadow constructor declaration introduced into a
3489
/// class by a C++11 using-declaration that names a constructor.
3490
///
3491
/// For example:
3492
/// \code
3493
/// struct Base { Base(int); };
3494
/// struct Derived {
3495
///    using Base::Base; // creates a UsingDecl and a ConstructorUsingShadowDecl
3496
/// };
3497
/// \endcode
3498
class ConstructorUsingShadowDecl final : public UsingShadowDecl {
3499
  /// If this constructor using declaration inherted the constructor
3500
  /// from an indirect base class, this is the ConstructorUsingShadowDecl
3501
  /// in the named direct base class from which the declaration was inherited.
3502
  ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr;
3503
3504
  /// If this constructor using declaration inherted the constructor
3505
  /// from an indirect base class, this is the ConstructorUsingShadowDecl
3506
  /// that will be used to construct the unique direct or virtual base class
3507
  /// that receives the constructor arguments.
3508
  ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr;
3509
3510
  /// \c true if the constructor ultimately named by this using shadow
3511
  /// declaration is within a virtual base class subobject of the class that
3512
  /// contains this declaration.
3513
  unsigned IsVirtual : 1;
3514
3515
  ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc,
3516
                             UsingDecl *Using, NamedDecl *Target,
3517
                             bool TargetInVirtualBase)
3518
      : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc,
3519
                        Using->getDeclName(), Using,
3520
                        Target->getUnderlyingDecl()),
3521
        NominatedBaseClassShadowDecl(
3522
            dyn_cast<ConstructorUsingShadowDecl>(Target)),
3523
        ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl),
3524
2.60k
        IsVirtual(TargetInVirtualBase) {
3525
    // If we found a constructor that chains to a constructor for a virtual
3526
    // base, we should directly call that virtual base constructor instead.
3527
    // FIXME: This logic belongs in Sema.
3528
2.60k
    if (NominatedBaseClassShadowDecl &&
3529
2.60k
        
NominatedBaseClassShadowDecl->constructsVirtualBase()993
) {
3530
159
      ConstructedBaseClassShadowDecl =
3531
159
          NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl;
3532
159
      IsVirtual = true;
3533
159
    }
3534
2.60k
  }
3535
3536
  ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty)
3537
75
      : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {}
3538
3539
  void anchor() override;
3540
3541
public:
3542
  friend class ASTDeclReader;
3543
  friend class ASTDeclWriter;
3544
3545
  static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
3546
                                            SourceLocation Loc,
3547
                                            UsingDecl *Using, NamedDecl *Target,
3548
                                            bool IsVirtual);
3549
  static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C,
3550
                                                        unsigned ID);
3551
3552
  /// Override the UsingShadowDecl's getIntroducer, returning the UsingDecl that
3553
  /// introduced this.
3554
1.10k
  UsingDecl *getIntroducer() const {
3555
1.10k
    return cast<UsingDecl>(UsingShadowDecl::getIntroducer());
3556
1.10k
  }
3557
3558
  /// Returns the parent of this using shadow declaration, which
3559
  /// is the class in which this is declared.
3560
  //@{
3561
0
  const CXXRecordDecl *getParent() const {
3562
0
    return cast<CXXRecordDecl>(getDeclContext());
3563
0
  }
3564
5.20k
  CXXRecordDecl *getParent() {
3565
5.20k
    return cast<CXXRecordDecl>(getDeclContext());
3566
5.20k
  }
3567
  //@}
3568
3569
  /// Get the inheriting constructor declaration for the direct base
3570
  /// class from which this using shadow declaration was inherited, if there is
3571
  /// one. This can be different for each redeclaration of the same shadow decl.
3572
1.26k
  ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const {
3573
1.26k
    return NominatedBaseClassShadowDecl;
3574
1.26k
  }
3575
3576
  /// Get the inheriting constructor declaration for the base class
3577
  /// for which we don't have an explicit initializer, if there is one.
3578
210
  ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const {
3579
210
    return ConstructedBaseClassShadowDecl;
3580
210
  }
3581
3582
  /// Get the base class that was named in the using declaration. This
3583
  /// can be different for each redeclaration of this same shadow decl.
3584
  CXXRecordDecl *getNominatedBaseClass() const;
3585
3586
  /// Get the base class whose constructor or constructor shadow
3587
  /// declaration is passed the constructor arguments.
3588
1.04k
  CXXRecordDecl *getConstructedBaseClass() const {
3589
1.04k
    return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl
3590
1.04k
                                    ? 
ConstructedBaseClassShadowDecl364
3591
1.04k
                                    : 
getTargetDecl()683
)
3592
1.04k
                                   ->getDeclContext());
3593
1.04k
  }
3594
3595
  /// Returns \c true if the constructed base class is a virtual base
3596
  /// class subobject of this declaration's class.
3597
3.54k
  bool constructsVirtualBase() const {
3598
3.54k
    return IsVirtual;
3599
3.54k
  }
3600
3601
2.64M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3602
2.64M
  static bool classofKind(Kind K) { return K == ConstructorUsingShadow; }
3603
};
3604
3605
/// Represents a C++ using-enum-declaration.
3606
///
3607
/// For example:
3608
/// \code
3609
///    using enum SomeEnumTag ;
3610
/// \endcode
3611
3612
class UsingEnumDecl : public BaseUsingDecl, public Mergeable<UsingEnumDecl> {
3613
  /// The source location of the 'using' keyword itself.
3614
  SourceLocation UsingLocation;
3615
3616
  /// Location of the 'enum' keyword.
3617
  SourceLocation EnumLocation;
3618
3619
  /// The enum
3620
  EnumDecl *Enum;
3621
3622
  UsingEnumDecl(DeclContext *DC, DeclarationName DN, SourceLocation UL,
3623
                SourceLocation EL, SourceLocation NL, EnumDecl *ED)
3624
      : BaseUsingDecl(UsingEnum, DC, NL, DN), UsingLocation(UL),
3625
55
        EnumLocation(EL), Enum(ED) {}
3626
3627
  void anchor() override;
3628
3629
public:
3630
  friend class ASTDeclReader;
3631
  friend class ASTDeclWriter;
3632
3633
  /// The source location of the 'using' keyword.
3634
16
  SourceLocation getUsingLoc() const { return UsingLocation; }
3635
1
  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3636
3637
  /// The source location of the 'enum' keyword.
3638
16
  SourceLocation getEnumLoc() const { return EnumLocation; }
3639
1
  void setEnumLoc(SourceLocation L) { EnumLocation = L; }
3640
3641
public:
3642
36
  EnumDecl *getEnumDecl() const { return Enum; }
3643
3644
  static UsingEnumDecl *Create(ASTContext &C, DeclContext *DC,
3645
                               SourceLocation UsingL, SourceLocation EnumL,
3646
                               SourceLocation NameL, EnumDecl *ED);
3647
3648
  static UsingEnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3649
3650
  SourceRange getSourceRange() const override LLVM_READONLY;
3651
3652
  /// Retrieves the canonical declaration of this declaration.
3653
149
  UsingEnumDecl *getCanonicalDecl() override {
3654
149
    return cast<UsingEnumDecl>(getFirstDecl());
3655
149
  }
3656
0
  const UsingEnumDecl *getCanonicalDecl() const {
3657
0
    return cast<UsingEnumDecl>(getFirstDecl());
3658
0
  }
3659
3660
22.0k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3661
22.0k
  static bool classofKind(Kind K) { return K == UsingEnum; }
3662
};
3663
3664
/// Represents a pack of using declarations that a single
3665
/// using-declarator pack-expanded into.
3666
///
3667
/// \code
3668
/// template<typename ...T> struct X : T... {
3669
///   using T::operator()...;
3670
///   using T::operator T...;
3671
/// };
3672
/// \endcode
3673
///
3674
/// In the second case above, the UsingPackDecl will have the name
3675
/// 'operator T' (which contains an unexpanded pack), but the individual
3676
/// UsingDecls and UsingShadowDecls will have more reasonable names.
3677
class UsingPackDecl final
3678
    : public NamedDecl, public Mergeable<UsingPackDecl>,
3679
      private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> {
3680
  /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from
3681
  /// which this waas instantiated.
3682
  NamedDecl *InstantiatedFrom;
3683
3684
  /// The number of using-declarations created by this pack expansion.
3685
  unsigned NumExpansions;
3686
3687
  UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom,
3688
                ArrayRef<NamedDecl *> UsingDecls)
3689
      : NamedDecl(UsingPack, DC,
3690
                  InstantiatedFrom ? InstantiatedFrom->getLocation()
3691
                                   : SourceLocation(),
3692
                  InstantiatedFrom ? InstantiatedFrom->getDeclName()
3693
                                   : DeclarationName()),
3694
88
        InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) {
3695
88
    std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(),
3696
88
                            getTrailingObjects<NamedDecl *>());
3697
88
  }
3698
3699
  void anchor() override;
3700
3701
public:
3702
  friend class ASTDeclReader;
3703
  friend class ASTDeclWriter;
3704
  friend TrailingObjects;
3705
3706
  /// Get the using declaration from which this was instantiated. This will
3707
  /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl
3708
  /// that is a pack expansion.
3709
50
  NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; }
3710
3711
  /// Get the set of using declarations that this pack expanded into. Note that
3712
  /// some of these may still be unresolved.
3713
81
  ArrayRef<NamedDecl *> expansions() const {
3714
81
    return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions);
3715
81
  }
3716
3717
  static UsingPackDecl *Create(ASTContext &C, DeclContext *DC,
3718
                               NamedDecl *InstantiatedFrom,
3719
                               ArrayRef<NamedDecl *> UsingDecls);
3720
3721
  static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3722
                                           unsigned NumExpansions);
3723
3724
0
  SourceRange getSourceRange() const override LLVM_READONLY {
3725
0
    return InstantiatedFrom->getSourceRange();
3726
0
  }
3727
3728
64
  UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); }
3729
0
  const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); }
3730
3731
1.23M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3732
1.23M
  static bool classofKind(Kind K) { return K == UsingPack; }
3733
};
3734
3735
/// Represents a dependent using declaration which was not marked with
3736
/// \c typename.
3737
///
3738
/// Unlike non-dependent using declarations, these *only* bring through
3739
/// non-types; otherwise they would break two-phase lookup.
3740
///
3741
/// \code
3742
/// template \<class T> class A : public Base<T> {
3743
///   using Base<T>::foo;
3744
/// };
3745
/// \endcode
3746
class UnresolvedUsingValueDecl : public ValueDecl,
3747
                                 public Mergeable<UnresolvedUsingValueDecl> {
3748
  /// The source location of the 'using' keyword
3749
  SourceLocation UsingLocation;
3750
3751
  /// If this is a pack expansion, the location of the '...'.
3752
  SourceLocation EllipsisLoc;
3753
3754
  /// The nested-name-specifier that precedes the name.
3755
  NestedNameSpecifierLoc QualifierLoc;
3756
3757
  /// Provides source/type location info for the declaration name
3758
  /// embedded in the ValueDecl base class.
3759
  DeclarationNameLoc DNLoc;
3760
3761
  UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
3762
                           SourceLocation UsingLoc,
3763
                           NestedNameSpecifierLoc QualifierLoc,
3764
                           const DeclarationNameInfo &NameInfo,
3765
                           SourceLocation EllipsisLoc)
3766
      : ValueDecl(UnresolvedUsingValue, DC,
3767
                  NameInfo.getLoc(), NameInfo.getName(), Ty),
3768
        UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc),
3769
1.52k
        QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {}
3770
3771
  void anchor() override;
3772
3773
public:
3774
  friend class ASTDeclReader;
3775
  friend class ASTDeclWriter;
3776
3777
  /// Returns the source location of the 'using' keyword.
3778
1.02k
  SourceLocation getUsingLoc() const { return UsingLocation; }
3779
3780
  /// Set the source location of the 'using' keyword.
3781
86
  void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3782
3783
  /// Return true if it is a C++03 access declaration (no 'using').
3784
136
  bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3785
3786
  /// Retrieve the nested-name-specifier that qualifies the name,
3787
  /// with source-location information.
3788
2.52k
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3789
3790
  /// Retrieve the nested-name-specifier that qualifies the name.
3791
488
  NestedNameSpecifier *getQualifier() const {
3792
488
    return QualifierLoc.getNestedNameSpecifier();
3793
488
  }
3794
3795
2.31k
  DeclarationNameInfo getNameInfo() const {
3796
2.31k
    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3797
2.31k
  }
3798
3799
  /// Determine whether this is a pack expansion.
3800
933
  bool isPackExpansion() const {
3801
933
    return EllipsisLoc.isValid();
3802
933
  }
3803
3804
  /// Get the location of the ellipsis if this is a pack expansion.
3805
1.70k
  SourceLocation getEllipsisLoc() const {
3806
1.70k
    return EllipsisLoc;
3807
1.70k
  }
3808
3809
  static UnresolvedUsingValueDecl *
3810
    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3811
           NestedNameSpecifierLoc QualifierLoc,
3812
           const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc);
3813
3814
  static UnresolvedUsingValueDecl *
3815
  CreateDeserialized(ASTContext &C, unsigned ID);
3816
3817
  SourceRange getSourceRange() const override LLVM_READONLY;
3818
3819
  /// Retrieves the canonical declaration of this declaration.
3820
3.86k
  UnresolvedUsingValueDecl *getCanonicalDecl() override {
3821
3.86k
    return getFirstDecl();
3822
3.86k
  }
3823
0
  const UnresolvedUsingValueDecl *getCanonicalDecl() const {
3824
0
    return getFirstDecl();
3825
0
  }
3826
3827
413M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3828
413M
  static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
3829
};
3830
3831
/// Represents a dependent using declaration which was marked with
3832
/// \c typename.
3833
///
3834
/// \code
3835
/// template \<class T> class A : public Base<T> {
3836
///   using typename Base<T>::foo;
3837
/// };
3838
/// \endcode
3839
///
3840
/// The type associated with an unresolved using typename decl is
3841
/// currently always a typename type.
3842
class UnresolvedUsingTypenameDecl
3843
    : public TypeDecl,
3844
      public Mergeable<UnresolvedUsingTypenameDecl> {
3845
  friend class ASTDeclReader;
3846
3847
  /// The source location of the 'typename' keyword
3848
  SourceLocation TypenameLocation;
3849
3850
  /// If this is a pack expansion, the location of the '...'.
3851
  SourceLocation EllipsisLoc;
3852
3853
  /// The nested-name-specifier that precedes the name.
3854
  NestedNameSpecifierLoc QualifierLoc;
3855
3856
  UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
3857
                              SourceLocation TypenameLoc,
3858
                              NestedNameSpecifierLoc QualifierLoc,
3859
                              SourceLocation TargetNameLoc,
3860
                              IdentifierInfo *TargetName,
3861
                              SourceLocation EllipsisLoc)
3862
    : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
3863
               UsingLoc),
3864
      TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc),
3865
1.24k
      QualifierLoc(QualifierLoc) {}
3866
3867
  void anchor() override;
3868
3869
public:
3870
  /// Returns the source location of the 'using' keyword.
3871
1.02k
  SourceLocation getUsingLoc() const { return getBeginLoc(); }
3872
3873
  /// Returns the source location of the 'typename' keyword.
3874
1.13k
  SourceLocation getTypenameLoc() const { return TypenameLocation; }
3875
3876
  /// Retrieve the nested-name-specifier that qualifies the name,
3877
  /// with source-location information.
3878
1.25k
  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3879
3880
  /// Retrieve the nested-name-specifier that qualifies the name.
3881
50
  NestedNameSpecifier *getQualifier() const {
3882
50
    return QualifierLoc.getNestedNameSpecifier();
3883
50
  }
3884
3885
763
  DeclarationNameInfo getNameInfo() const {
3886
763
    return DeclarationNameInfo(getDeclName(), getLocation());
3887
763
  }
3888
3889
  /// Determine whether this is a pack expansion.
3890
960
  bool isPackExpansion() const {
3891
960
    return EllipsisLoc.isValid();
3892
960
  }
3893
3894
  /// Get the location of the ellipsis if this is a pack expansion.
3895
1.87k
  SourceLocation getEllipsisLoc() const {
3896
1.87k
    return EllipsisLoc;
3897
1.87k
  }
3898
3899
  static UnresolvedUsingTypenameDecl *
3900
    Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3901
           SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
3902
           SourceLocation TargetNameLoc, DeclarationName TargetName,
3903
           SourceLocation EllipsisLoc);
3904
3905
  static UnresolvedUsingTypenameDecl *
3906
  CreateDeserialized(ASTContext &C, unsigned ID);
3907
3908
  /// Retrieves the canonical declaration of this declaration.
3909
3.96k
  UnresolvedUsingTypenameDecl *getCanonicalDecl() override {
3910
3.96k
    return getFirstDecl();
3911
3.96k
  }
3912
1.09k
  const UnresolvedUsingTypenameDecl *getCanonicalDecl() const {
3913
1.09k
    return getFirstDecl();
3914
1.09k
  }
3915
3916
9.59M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3917
9.59M
  static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
3918
};
3919
3920
/// This node is generated when a using-declaration that was annotated with
3921
/// __attribute__((using_if_exists)) failed to resolve to a known declaration.
3922
/// In that case, Sema builds a UsingShadowDecl whose target is an instance of
3923
/// this declaration, adding it to the current scope. Referring to this
3924
/// declaration in any way is an error.
3925
class UnresolvedUsingIfExistsDecl final : public NamedDecl {
3926
  UnresolvedUsingIfExistsDecl(DeclContext *DC, SourceLocation Loc,
3927
                              DeclarationName Name);
3928
3929
  void anchor() override;
3930
3931
public:
3932
  static UnresolvedUsingIfExistsDecl *Create(ASTContext &Ctx, DeclContext *DC,
3933
                                             SourceLocation Loc,
3934
                                             DeclarationName Name);
3935
  static UnresolvedUsingIfExistsDecl *CreateDeserialized(ASTContext &Ctx,
3936
                                                         unsigned ID);
3937
3938
131M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3939
131M
  static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingIfExists; }
3940
};
3941
3942
/// Represents a C++11 static_assert declaration.
3943
class StaticAssertDecl : public Decl {
3944
  llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
3945
  StringLiteral *Message;
3946
  SourceLocation RParenLoc;
3947
3948
  StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
3949
                   Expr *AssertExpr, StringLiteral *Message,
3950
                   SourceLocation RParenLoc, bool Failed)
3951
      : Decl(StaticAssert, DC, StaticAssertLoc),
3952
        AssertExprAndFailed(AssertExpr, Failed), Message(Message),
3953
161k
        RParenLoc(RParenLoc) {}
3954
3955
  virtual void anchor();
3956
3957
public:
3958
  friend class ASTDeclReader;
3959
3960
  static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
3961
                                  SourceLocation StaticAssertLoc,
3962
                                  Expr *AssertExpr, StringLiteral *Message,
3963
                                  SourceLocation RParenLoc, bool Failed);
3964
  static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3965
3966
80.7k
  Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
3967
3.00k
  const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
3968
3969
80.7k
  StringLiteral *getMessage() { return Message; }
3970
3.00k
  const StringLiteral *getMessage() const { return Message; }
3971
3972
119k
  bool isFailed() const { return AssertExprAndFailed.getInt(); }
3973
3974
75.7k
  SourceLocation getRParenLoc() const { return RParenLoc; }
3975
3976
67
  SourceRange getSourceRange() const override LLVM_READONLY {
3977
67
    return SourceRange(getLocation(), getRParenLoc());
3978
67
  }
3979
3980
57.0M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3981
57.0M
  static bool classofKind(Kind K) { return K == StaticAssert; }
3982
};
3983
3984
/// A binding in a decomposition declaration. For instance, given:
3985
///
3986
///   int n[3];
3987
///   auto &[a, b, c] = n;
3988
///
3989
/// a, b, and c are BindingDecls, whose bindings are the expressions
3990
/// x[0], x[1], and x[2] respectively, where x is the implicit
3991
/// DecompositionDecl of type 'int (&)[3]'.
3992
class BindingDecl : public ValueDecl {
3993
  /// The declaration that this binding binds to part of.
3994
  ValueDecl *Decomp;
3995
  /// The binding represented by this declaration. References to this
3996
  /// declaration are effectively equivalent to this expression (except
3997
  /// that it is only evaluated once at the point of declaration of the
3998
  /// binding).
3999
  Expr *Binding = nullptr;
4000
4001
  BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
4002
1.06k
      : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {}
4003
4004
  void anchor() override;
4005
4006
public:
4007
  friend class ASTDeclReader;
4008
4009
  static BindingDecl *Create(ASTContext &C, DeclContext *DC,
4010
                             SourceLocation IdLoc, IdentifierInfo *Id);
4011
  static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4012
4013
  /// Get the expression to which this declaration is bound. This may be null
4014
  /// in two different cases: while parsing the initializer for the
4015
  /// decomposition declaration, and when the initializer is type-dependent.
4016
6.16k
  Expr *getBinding() const { return Binding; }
4017
4018
  /// Get the decomposition declaration that this binding represents a
4019
  /// decomposition of.
4020
214
  ValueDecl *getDecomposedDecl() const { return Decomp; }
4021
4022
  /// Get the variable (if any) that holds the value of evaluating the binding.
4023
  /// Only present for user-defined bindings for tuple-like types.
4024
  VarDecl *getHoldingVar() const;
4025
4026
  /// Set the binding for this BindingDecl, along with its declared type (which
4027
  /// should be a possibly-cv-qualified form of the type of the binding, or a
4028
  /// reference to such a type).
4029
893
  void setBinding(QualType DeclaredType, Expr *Binding) {
4030
893
    setType(DeclaredType);
4031
893
    this->Binding = Binding;
4032
893
  }
4033
4034
  /// Set the decomposed variable for this BindingDecl.
4035
1.09k
  void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; }
4036
4037
26.4M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4038
26.4M
  static bool classofKind(Kind K) { return K == Decl::Binding; }
4039
};
4040
4041
/// A decomposition declaration. For instance, given:
4042
///
4043
///   int n[3];
4044
///   auto &[a, b, c] = n;
4045
///
4046
/// the second line declares a DecompositionDecl of type 'int (&)[3]', and
4047
/// three BindingDecls (named a, b, and c). An instance of this class is always
4048
/// unnamed, but behaves in almost all other respects like a VarDecl.
4049
class DecompositionDecl final
4050
    : public VarDecl,
4051
      private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> {
4052
  /// The number of BindingDecl*s following this object.
4053
  unsigned NumBindings;
4054
4055
  DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
4056
                    SourceLocation LSquareLoc, QualType T,
4057
                    TypeSourceInfo *TInfo, StorageClass SC,
4058
                    ArrayRef<BindingDecl *> Bindings)
4059
      : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo,
4060
                SC),
4061
525
        NumBindings(Bindings.size()) {
4062
525
    std::uninitialized_copy(Bindings.begin(), Bindings.end(),
4063
525
                            getTrailingObjects<BindingDecl *>());
4064
525
    for (auto *B : Bindings)
4065
1.04k
      B->setDecomposedDecl(this);
4066
525
  }
4067
4068
  void anchor() override;
4069
4070
public:
4071
  friend class ASTDeclReader;
4072
  friend TrailingObjects;
4073
4074
  static DecompositionDecl *Create(ASTContext &C, DeclContext *DC,
4075
                                   SourceLocation StartLoc,
4076
                                   SourceLocation LSquareLoc,
4077
                                   QualType T, TypeSourceInfo *TInfo,
4078
                                   StorageClass S,
4079
                                   ArrayRef<BindingDecl *> Bindings);
4080
  static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID,
4081
                                               unsigned NumBindings);
4082
4083
2.52k
  ArrayRef<BindingDecl *> bindings() const {
4084
2.52k
    return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings);
4085
2.52k
  }
4086
4087
  void printName(raw_ostream &os) const override;
4088
4089
125M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4090
125M
  static bool classofKind(Kind K) { return K == Decomposition; }
4091
};
4092
4093
/// An instance of this class represents the declaration of a property
4094
/// member.  This is a Microsoft extension to C++, first introduced in
4095
/// Visual Studio .NET 2003 as a parallel to similar features in C#
4096
/// and Managed C++.
4097
///
4098
/// A property must always be a non-static class member.
4099
///
4100
/// A property member superficially resembles a non-static data
4101
/// member, except preceded by a property attribute:
4102
///   __declspec(property(get=GetX, put=PutX)) int x;
4103
/// Either (but not both) of the 'get' and 'put' names may be omitted.
4104
///
4105
/// A reference to a property is always an lvalue.  If the lvalue
4106
/// undergoes lvalue-to-rvalue conversion, then a getter name is
4107
/// required, and that member is called with no arguments.
4108
/// If the lvalue is assigned into, then a setter name is required,
4109
/// and that member is called with one argument, the value assigned.
4110
/// Both operations are potentially overloaded.  Compound assignments
4111
/// are permitted, as are the increment and decrement operators.
4112
///
4113
/// The getter and putter methods are permitted to be overloaded,
4114
/// although their return and parameter types are subject to certain
4115
/// restrictions according to the type of the property.
4116
///
4117
/// A property declared using an incomplete array type may
4118
/// additionally be subscripted, adding extra parameters to the getter
4119
/// and putter methods.
4120
class MSPropertyDecl : public DeclaratorDecl {
4121
  IdentifierInfo *GetterId, *SetterId;
4122
4123
  MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N,
4124
                 QualType T, TypeSourceInfo *TInfo, SourceLocation StartL,
4125
                 IdentifierInfo *Getter, IdentifierInfo *Setter)
4126
      : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL),
4127
136
        GetterId(Getter), SetterId(Setter) {}
4128
4129
  void anchor() override;
4130
public:
4131
  friend class ASTDeclReader;
4132
4133
  static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC,
4134
                                SourceLocation L, DeclarationName N, QualType T,
4135
                                TypeSourceInfo *TInfo, SourceLocation StartL,
4136
                                IdentifierInfo *Getter, IdentifierInfo *Setter);
4137
  static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4138
4139
6.96M
  static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
4140
4141
177
  bool hasGetter() const { return GetterId != nullptr; }
4142
214
  IdentifierInfo* getGetterId() const { return GetterId; }
4143
100
  bool hasSetter() const { return SetterId != nullptr; }
4144
124
  IdentifierInfo* getSetterId() const { return SetterId; }
4145
};
4146
4147
/// Parts of a decomposed MSGuidDecl. Factored out to avoid unnecessary
4148
/// dependencies on DeclCXX.h.
4149
struct MSGuidDeclParts {
4150
  /// {01234567-...
4151
  uint32_t Part1;
4152
  /// ...-89ab-...
4153
  uint16_t Part2;
4154
  /// ...-cdef-...
4155
  uint16_t Part3;
4156
  /// ...-0123-456789abcdef}
4157
  uint8_t Part4And5[8];
4158
4159
234
  uint64_t getPart4And5AsUint64() const {
4160
234
    uint64_t Val;
4161
234
    memcpy(&Val, &Part4And5, sizeof(Part4And5));
4162
234
    return Val;
4163
234
  }
4164
};
4165
4166
/// A global _GUID constant. These are implicitly created by UuidAttrs.
4167
///
4168
///   struct _declspec(uuid("01234567-89ab-cdef-0123-456789abcdef")) X{};
4169
///
4170
/// X is a CXXRecordDecl that contains a UuidAttr that references the (unique)
4171
/// MSGuidDecl for the specified UUID.
4172
class MSGuidDecl : public ValueDecl,
4173
                   public Mergeable<MSGuidDecl>,
4174
                   public llvm::FoldingSetNode {
4175
public:
4176
  using Parts = MSGuidDeclParts;
4177
4178
private:
4179
  /// The decomposed form of the UUID.
4180
  Parts PartVal;
4181
4182
  /// The resolved value of the UUID as an APValue. Computed on demand and
4183
  /// cached.
4184
  mutable APValue APVal;
4185
4186
  void anchor() override;
4187
4188
  MSGuidDecl(DeclContext *DC, QualType T, Parts P);
4189
4190
  static MSGuidDecl *Create(const ASTContext &C, QualType T, Parts P);
4191
  static MSGuidDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4192
4193
  // Only ASTContext::getMSGuidDecl and deserialization create these.
4194
  friend class ASTContext;
4195
  friend class ASTReader;
4196
  friend class ASTDeclReader;
4197
4198
public:
4199
  /// Print this UUID in a human-readable format.
4200
  void printName(llvm::raw_ostream &OS) const override;
4201
4202
  /// Get the decomposed parts of this declaration.
4203
84
  Parts getParts() const { return PartVal; }
4204
4205
  /// Get the value of this MSGuidDecl as an APValue. This may fail and return
4206
  /// an absent APValue if the type of the declaration is not of the expected
4207
  /// shape.
4208
  APValue &getAsAPValue() const;
4209
4210
234
  static void Profile(llvm::FoldingSetNodeID &ID, Parts P) {
4211
234
    ID.AddInteger(P.Part1);
4212
234
    ID.AddInteger(P.Part2);
4213
234
    ID.AddInteger(P.Part3);
4214
234
    ID.AddInteger(P.getPart4And5AsUint64());
4215
234
  }
4216
85
  void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, PartVal); }
4217
4218
26.9M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4219
26.9M
  static bool classofKind(Kind K) { return K == Decl::MSGuid; }
4220
};
4221
4222
/// An artificial decl, representing a global anonymous constant value which is
4223
/// uniquified by value within a translation unit.
4224
///
4225
/// These is currently only used to back the LValue returned by
4226
/// __builtin_source_location, but could potentially be used for other similar
4227
/// situations in the future.
4228
class UnnamedGlobalConstantDecl : public ValueDecl,
4229
                                  public Mergeable<UnnamedGlobalConstantDecl>,
4230
                                  public llvm::FoldingSetNode {
4231
4232
  // The constant value of this global.
4233
  APValue Value;
4234
4235
  void anchor() override;
4236
4237
  UnnamedGlobalConstantDecl(const ASTContext &C, DeclContext *DC, QualType T,
4238
                            const APValue &Val);
4239
4240
  static UnnamedGlobalConstantDecl *Create(const ASTContext &C, QualType T,
4241
                                           const APValue &APVal);
4242
  static UnnamedGlobalConstantDecl *CreateDeserialized(ASTContext &C,
4243
                                                       unsigned ID);
4244
4245
  // Only ASTContext::getUnnamedGlobalConstantDecl and deserialization create
4246
  // these.
4247
  friend class ASTContext;
4248
  friend class ASTReader;
4249
  friend class ASTDeclReader;
4250
4251
public:
4252
  /// Print this in a human-readable format.
4253
  void printName(llvm::raw_ostream &OS) const override;
4254
4255
179
  const APValue &getValue() const { return Value; }
4256
4257
  static void Profile(llvm::FoldingSetNodeID &ID, QualType Ty,
4258
201
                      const APValue &APVal) {
4259
201
    Ty.Profile(ID);
4260
201
    APVal.Profile(ID);
4261
201
  }
4262
72
  void Profile(llvm::FoldingSetNodeID &ID) {
4263
72
    Profile(ID, getType(), getValue());
4264
72
  }
4265
4266
16.5M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4267
16.5M
  static bool classofKind(Kind K) { return K == Decl::UnnamedGlobalConstant; }
4268
};
4269
4270
/// Insertion operator for diagnostics.  This allows sending an AccessSpecifier
4271
/// into a diagnostic with <<.
4272
const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
4273
                                      AccessSpecifier AS);
4274
4275
} // namespace clang
4276
4277
#endif // LLVM_CLANG_AST_DECLCXX_H