Coverage Report

Created: 2018-09-21 05:35

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/Decl.h
Line
Count
Source (jump to first uncovered line)
1
//===- Decl.h - Classes for representing declarations -----------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
//  This file defines the Decl subclasses.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_DECL_H
15
#define LLVM_CLANG_AST_DECL_H
16
17
#include "clang/AST/APValue.h"
18
#include "clang/AST/DeclBase.h"
19
#include "clang/AST/DeclarationName.h"
20
#include "clang/AST/ExternalASTSource.h"
21
#include "clang/AST/NestedNameSpecifier.h"
22
#include "clang/AST/Redeclarable.h"
23
#include "clang/AST/Type.h"
24
#include "clang/Basic/AddressSpaces.h"
25
#include "clang/Basic/Diagnostic.h"
26
#include "clang/Basic/IdentifierTable.h"
27
#include "clang/Basic/LLVM.h"
28
#include "clang/Basic/Linkage.h"
29
#include "clang/Basic/OperatorKinds.h"
30
#include "clang/Basic/PartialDiagnostic.h"
31
#include "clang/Basic/PragmaKinds.h"
32
#include "clang/Basic/SourceLocation.h"
33
#include "clang/Basic/Specifiers.h"
34
#include "clang/Basic/Visibility.h"
35
#include "llvm/ADT/APSInt.h"
36
#include "llvm/ADT/ArrayRef.h"
37
#include "llvm/ADT/Optional.h"
38
#include "llvm/ADT/PointerIntPair.h"
39
#include "llvm/ADT/PointerUnion.h"
40
#include "llvm/ADT/StringRef.h"
41
#include "llvm/ADT/iterator_range.h"
42
#include "llvm/Support/Casting.h"
43
#include "llvm/Support/Compiler.h"
44
#include "llvm/Support/TrailingObjects.h"
45
#include <cassert>
46
#include <cstddef>
47
#include <cstdint>
48
#include <string>
49
#include <utility>
50
51
namespace clang {
52
53
class ASTContext;
54
struct ASTTemplateArgumentListInfo;
55
class Attr;
56
class CompoundStmt;
57
class DependentFunctionTemplateSpecializationInfo;
58
class EnumDecl;
59
class Expr;
60
class FunctionTemplateDecl;
61
class FunctionTemplateSpecializationInfo;
62
class LabelStmt;
63
class MemberSpecializationInfo;
64
class Module;
65
class NamespaceDecl;
66
class ParmVarDecl;
67
class RecordDecl;
68
class Stmt;
69
class StringLiteral;
70
class TagDecl;
71
class TemplateArgumentList;
72
class TemplateArgumentListInfo;
73
class TemplateParameterList;
74
class TypeAliasTemplateDecl;
75
class TypeLoc;
76
class UnresolvedSetImpl;
77
class VarTemplateDecl;
78
79
/// A container of type source information.
80
///
81
/// A client can read the relevant info using TypeLoc wrappers, e.g:
82
/// @code
83
/// TypeLoc TL = TypeSourceInfo->getTypeLoc();
84
/// TL.getBeginLoc().print(OS, SrcMgr);
85
/// @endcode
86
class alignas(8) TypeSourceInfo {
87
  // Contains a memory block after the class, used for type source information,
88
  // allocated by ASTContext.
89
  friend class ASTContext;
90
91
  QualType Ty;
92
93
49.0M
  TypeSourceInfo(QualType ty) : Ty(ty) {}
94
95
public:
96
  /// Return the type wrapped by this type source info.
97
192M
  QualType getType() const { return Ty; }
98
99
  /// Return the TypeLoc wrapper for the type source info.
100
  TypeLoc getTypeLoc() const; // implemented in TypeLoc.h
101
102
  /// Override the type stored in this TypeSourceInfo. Use with caution!
103
44.5k
  void overrideType(QualType T) { Ty = T; }
104
};
105
106
/// The top declaration context.
107
class TranslationUnitDecl : public Decl, public DeclContext {
108
  ASTContext &Ctx;
109
110
  /// The (most recently entered) anonymous namespace for this
111
  /// translation unit, if one has been created.
112
  NamespaceDecl *AnonymousNamespace = nullptr;
113
114
  explicit TranslationUnitDecl(ASTContext &ctx);
115
116
  virtual void anchor();
117
118
public:
119
691M
  ASTContext &getASTContext() const { return Ctx; }
120
121
3.93k
  NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
122
444
  void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; }
123
124
  static TranslationUnitDecl *Create(ASTContext &C);
125
126
  // Implement isa/cast/dyncast/etc.
127
670M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
128
730M
  static bool classofKind(Kind K) { return K == TranslationUnit; }
129
10.7k
  static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
130
10.7k
    return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
131
10.7k
  }
132
0
  static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) {
133
0
    return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
134
0
  }
135
};
136
137
/// Represents a `#pragma comment` line. Always a child of
138
/// TranslationUnitDecl.
139
class PragmaCommentDecl final
140
    : public Decl,
141
      private llvm::TrailingObjects<PragmaCommentDecl, char> {
142
  friend class ASTDeclReader;
143
  friend class ASTDeclWriter;
144
  friend TrailingObjects;
145
146
  PragmaMSCommentKind CommentKind;
147
148
  PragmaCommentDecl(TranslationUnitDecl *TU, SourceLocation CommentLoc,
149
                    PragmaMSCommentKind CommentKind)
150
53
      : Decl(PragmaComment, TU, CommentLoc), CommentKind(CommentKind) {}
151
152
  virtual void anchor();
153
154
public:
155
  static PragmaCommentDecl *Create(const ASTContext &C, TranslationUnitDecl *DC,
156
                                   SourceLocation CommentLoc,
157
                                   PragmaMSCommentKind CommentKind,
158
                                   StringRef Arg);
159
  static PragmaCommentDecl *CreateDeserialized(ASTContext &C, unsigned ID,
160
                                               unsigned ArgSize);
161
162
43
  PragmaMSCommentKind getCommentKind() const { return CommentKind; }
163
164
43
  StringRef getArg() const { return getTrailingObjects<char>(); }
165
166
  // Implement isa/cast/dyncast/etc.
167
347k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
168
347k
  static bool classofKind(Kind K) { return K == PragmaComment; }
169
};
170
171
/// Represents a `#pragma detect_mismatch` line. Always a child of
172
/// TranslationUnitDecl.
173
class PragmaDetectMismatchDecl final
174
    : public Decl,
175
      private llvm::TrailingObjects<PragmaDetectMismatchDecl, char> {
176
  friend class ASTDeclReader;
177
  friend class ASTDeclWriter;
178
  friend TrailingObjects;
179
180
  size_t ValueStart;
181
182
  PragmaDetectMismatchDecl(TranslationUnitDecl *TU, SourceLocation Loc,
183
                           size_t ValueStart)
184
12
      : Decl(PragmaDetectMismatch, TU, Loc), ValueStart(ValueStart) {}
185
186
  virtual void anchor();
187
188
public:
189
  static PragmaDetectMismatchDecl *Create(const ASTContext &C,
190
                                          TranslationUnitDecl *DC,
191
                                          SourceLocation Loc, StringRef Name,
192
                                          StringRef Value);
193
  static PragmaDetectMismatchDecl *
194
  CreateDeserialized(ASTContext &C, unsigned ID, unsigned NameValueSize);
195
196
10
  StringRef getName() const { return getTrailingObjects<char>(); }
197
10
  StringRef getValue() const { return getTrailingObjects<char>() + ValueStart; }
198
199
  // Implement isa/cast/dyncast/etc.
200
347k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
201
347k
  static bool classofKind(Kind K) { return K == PragmaDetectMismatch; }
202
};
203
204
/// Declaration context for names declared as extern "C" in C++. This
205
/// is neither the semantic nor lexical context for such declarations, but is
206
/// used to check for conflicts with other extern "C" declarations. Example:
207
///
208
/// \code
209
///   namespace N { extern "C" void f(); } // #1
210
///   void N::f() {}                       // #2
211
///   namespace M { extern "C" void f(); } // #3
212
/// \endcode
213
///
214
/// The semantic context of #1 is namespace N and its lexical context is the
215
/// LinkageSpecDecl; the semantic context of #2 is namespace N and its lexical
216
/// context is the TU. However, both declarations are also visible in the
217
/// extern "C" context.
218
///
219
/// The declaration at #3 finds it is a redeclaration of \c N::f through
220
/// lookup in the extern "C" context.
221
class ExternCContextDecl : public Decl, public DeclContext {
222
  explicit ExternCContextDecl(TranslationUnitDecl *TU)
223
    : Decl(ExternCContext, TU, SourceLocation()),
224
28.7k
      DeclContext(ExternCContext) {}
225
226
  virtual void anchor();
227
228
public:
229
  static ExternCContextDecl *Create(const ASTContext &C,
230
                                    TranslationUnitDecl *TU);
231
232
  // Implement isa/cast/dyncast/etc.
233
0
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
234
0
  static bool classofKind(Kind K) { return K == ExternCContext; }
235
0
  static DeclContext *castToDeclContext(const ExternCContextDecl *D) {
236
0
    return static_cast<DeclContext *>(const_cast<ExternCContextDecl*>(D));
237
0
  }
238
0
  static ExternCContextDecl *castFromDeclContext(const DeclContext *DC) {
239
0
    return static_cast<ExternCContextDecl *>(const_cast<DeclContext*>(DC));
240
0
  }
241
};
242
243
/// This represents a decl that may have a name.  Many decls have names such
244
/// as ObjCMethodDecl, but not \@class, etc.
245
///
246
/// Note that not every NamedDecl is actually named (e.g., a struct might
247
/// be anonymous), and not every name is an identifier.
248
class NamedDecl : public Decl {
249
  /// The name of this declaration, which is typically a normal
250
  /// identifier but may also be a special kind of name (C++
251
  /// constructor, Objective-C selector, etc.)
252
  DeclarationName Name;
253
254
  virtual void anchor();
255
256
private:
257
  NamedDecl *getUnderlyingDeclImpl() LLVM_READONLY;
258
259
protected:
260
  NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
261
40.4M
      : Decl(DK, DC, L), Name(N) {}
262
263
public:
264
  /// Get the identifier that names this declaration, if there is one.
265
  ///
266
  /// This will return NULL if this declaration has no name (e.g., for
267
  /// an unnamed class) or if the name is a special name (C++ constructor,
268
  /// Objective-C selector, etc.).
269
169M
  IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); }
270
271
  /// Get the name of identifier for this declaration as a StringRef.
272
  ///
273
  /// This requires that the declaration have a name and that it be a simple
274
  /// identifier.
275
3.44M
  StringRef getName() const {
276
3.44M
    assert(Name.isIdentifier() && "Name is not a simple identifier");
277
3.44M
    return getIdentifier() ? 
getIdentifier()->getName()3.34M
:
""98.9k
;
278
3.44M
  }
279
280
  /// Get a human-readable name for the declaration, even if it is one of the
281
  /// special kinds of names (C++ constructor, Objective-C selector, etc).
282
  ///
283
  /// Creating this name requires expensive string manipulation, so it should
284
  /// be called only when performance doesn't matter. For simple declarations,
285
  /// getNameAsCString() should suffice.
286
  //
287
  // FIXME: This function should be renamed to indicate that it is not just an
288
  // alternate form of getName(), and clients should move as appropriate.
289
  //
290
  // FIXME: Deprecated, move clients to getName().
291
31.2k
  std::string getNameAsString() const { return Name.getAsString(); }
292
293
  virtual void printName(raw_ostream &os) const;
294
295
  /// Get the actual, stored name of the declaration, which may be a special
296
  /// name.
297
463M
  DeclarationName getDeclName() const { return Name; }
298
299
  /// Set the name of this declaration.
300
523k
  void setDeclName(DeclarationName N) { Name = N; }
301
302
  /// Returns a human-readable qualified name for this declaration, like
303
  /// A::B::i, for i being member of namespace A::B.
304
  ///
305
  /// If the declaration is not a member of context which can be named (record,
306
  /// namespace), it will return the same result as printName().
307
  ///
308
  /// Creating this name is expensive, so it should be called only when
309
  /// performance doesn't matter.
310
  void printQualifiedName(raw_ostream &OS) const;
311
  void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const;
312
313
  // FIXME: Remove string version.
314
  std::string getQualifiedNameAsString() const;
315
316
  /// Appends a human-readable name for this declaration into the given stream.
317
  ///
318
  /// This is the method invoked by Sema when displaying a NamedDecl
319
  /// in a diagnostic.  It does not necessarily produce the same
320
  /// result as printName(); for example, class template
321
  /// specializations are printed with their template arguments.
322
  virtual void getNameForDiagnostic(raw_ostream &OS,
323
                                    const PrintingPolicy &Policy,
324
                                    bool Qualified) const;
325
326
  /// Determine whether this declaration, if known to be well-formed within
327
  /// its context, will replace the declaration OldD if introduced into scope.
328
  ///
329
  /// A declaration will replace another declaration if, for example, it is
330
  /// a redeclaration of the same variable or function, but not if it is a
331
  /// declaration of a different kind (function vs. class) or an overloaded
332
  /// function.
333
  ///
334
  /// \param IsKnownNewer \c true if this declaration is known to be newer
335
  /// than \p OldD (for instance, if this declaration is newly-created).
336
  bool declarationReplaces(NamedDecl *OldD, bool IsKnownNewer = true) const;
337
338
  /// Determine whether this declaration has linkage.
339
  bool hasLinkage() const;
340
341
  using Decl::isModulePrivate;
342
  using Decl::setModulePrivate;
343
344
  /// Determine whether this declaration is a C++ class member.
345
32.0M
  bool isCXXClassMember() const {
346
32.0M
    const DeclContext *DC = getDeclContext();
347
32.0M
348
32.0M
    // C++0x [class.mem]p1:
349
32.0M
    //   The enumerators of an unscoped enumeration defined in
350
32.0M
    //   the class are members of the class.
351
32.0M
    if (isa<EnumDecl>(DC))
352
318k
      DC = DC->getRedeclContext();
353
32.0M
354
32.0M
    return DC->isRecord();
355
32.0M
  }
356
357
  /// Determine whether the given declaration is an instance member of
358
  /// a C++ class.
359
  bool isCXXInstanceMember() const;
360
361
  /// Determine what kind of linkage this entity has.
362
  ///
363
  /// This is not the linkage as defined by the standard or the codegen notion
364
  /// of linkage. It is just an implementation detail that is used to compute
365
  /// those.
366
  Linkage getLinkageInternal() const;
367
368
  /// Get the linkage from a semantic point of view. Entities in
369
  /// anonymous namespaces are external (in c++98).
370
7.20M
  Linkage getFormalLinkage() const {
371
7.20M
    return clang::getFormalLinkage(getLinkageInternal());
372
7.20M
  }
373
374
  /// True if this decl has external linkage.
375
20.3M
  bool hasExternalFormalLinkage() const {
376
20.3M
    return isExternalFormalLinkage(getLinkageInternal());
377
20.3M
  }
378
379
23.2M
  bool isExternallyVisible() const {
380
23.2M
    return clang::isExternallyVisible(getLinkageInternal());
381
23.2M
  }
382
383
  /// Determine whether this declaration can be redeclared in a
384
  /// different translation unit.
385
2.79k
  bool isExternallyDeclarable() const {
386
2.79k
    return isExternallyVisible() && 
!getOwningModuleForLinkage()2.69k
;
387
2.79k
  }
388
389
  /// Determines the visibility of this entity.
390
29.8k
  Visibility getVisibility() const {
391
29.8k
    return getLinkageAndVisibility().getVisibility();
392
29.8k
  }
393
394
  /// Determines the linkage and visibility of this entity.
395
  LinkageInfo getLinkageAndVisibility() const;
396
397
  /// Kinds of explicit visibility.
398
  enum ExplicitVisibilityKind {
399
    /// Do an LV computation for, ultimately, a type.
400
    /// Visibility may be restricted by type visibility settings and
401
    /// the visibility of template arguments.
402
    VisibilityForType,
403
404
    /// Do an LV computation for, ultimately, a non-type declaration.
405
    /// Visibility may be restricted by value visibility settings and
406
    /// the visibility of template arguments.
407
    VisibilityForValue
408
  };
409
410
  /// If visibility was explicitly specified for this
411
  /// declaration, return that visibility.
412
  Optional<Visibility>
413
  getExplicitVisibility(ExplicitVisibilityKind kind) const;
414
415
  /// True if the computed linkage is valid. Used for consistency
416
  /// checking. Should always return true.
417
  bool isLinkageValid() const;
418
419
  /// True if something has required us to compute the linkage
420
  /// of this declaration.
421
  ///
422
  /// Language features which can retroactively change linkage (like a
423
  /// typedef name for linkage purposes) may need to consider this,
424
  /// but hopefully only in transitory ways during parsing.
425
100k
  bool hasLinkageBeenComputed() const {
426
100k
    return hasCachedLinkage();
427
100k
  }
428
429
  /// Looks through UsingDecls and ObjCCompatibleAliasDecls for
430
  /// the underlying named decl.
431
246M
  NamedDecl *getUnderlyingDecl() {
432
246M
    // Fast-path the common case.
433
246M
    if (this->getKind() != UsingShadow &&
434
246M
        
this->getKind() != ConstructorUsingShadow244M
&&
435
246M
        
this->getKind() != ObjCCompatibleAlias244M
&&
436
246M
        
this->getKind() != NamespaceAlias244M
)
437
244M
      return this;
438
2.40M
439
2.40M
    return getUnderlyingDeclImpl();
440
2.40M
  }
441
2.19M
  const NamedDecl *getUnderlyingDecl() const {
442
2.19M
    return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
443
2.19M
  }
444
445
24.6M
  NamedDecl *getMostRecentDecl() {
446
24.6M
    return cast<NamedDecl>(static_cast<Decl *>(this)->getMostRecentDecl());
447
24.6M
  }
448
18.2M
  const NamedDecl *getMostRecentDecl() const {
449
18.2M
    return const_cast<NamedDecl*>(this)->getMostRecentDecl();
450
18.2M
  }
451
452
  ObjCStringFormatFamily getObjCFStringFormattingFamily() const;
453
454
50.1M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
455
52.7M
  static bool classofKind(Kind K) { return K >= firstNamed && 
K <= lastNamed51.3M
; }
456
};
457
458
431k
inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) {
459
431k
  ND.printName(OS);
460
431k
  return OS;
461
431k
}
462
463
/// Represents the declaration of a label.  Labels also have a
464
/// corresponding LabelStmt, which indicates the position that the label was
465
/// defined at.  For normal labels, the location of the decl is the same as the
466
/// location of the statement.  For GNU local labels (__label__), the decl
467
/// location is where the __label__ is.
468
class LabelDecl : public NamedDecl {
469
  LabelStmt *TheStmt;
470
  StringRef MSAsmName;
471
  bool MSAsmNameResolved = false;
472
473
  /// For normal labels, this is the same as the main declaration
474
  /// label, i.e., the location of the identifier; for GNU local labels,
475
  /// this is the location of the __label__ keyword.
476
  SourceLocation LocStart;
477
478
  LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II,
479
            LabelStmt *S, SourceLocation StartL)
480
4.31k
      : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {}
481
482
  void anchor() override;
483
484
public:
485
  static LabelDecl *Create(ASTContext &C, DeclContext *DC,
486
                           SourceLocation IdentL, IdentifierInfo *II);
487
  static LabelDecl *Create(ASTContext &C, DeclContext *DC,
488
                           SourceLocation IdentL, IdentifierInfo *II,
489
                           SourceLocation GnuLabelL);
490
  static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID);
491
492
21.2k
  LabelStmt *getStmt() const { return TheStmt; }
493
4.04k
  void setStmt(LabelStmt *T) { TheStmt = T; }
494
495
8.04k
  bool isGnuLocal() const { return LocStart != getLocation(); }
496
4.03k
  void setLocStart(SourceLocation L) { LocStart = L; }
497
498
416
  SourceRange getSourceRange() const override LLVM_READONLY {
499
416
    return SourceRange(LocStart, getLocation());
500
416
  }
501
502
11.6k
  bool isMSAsmLabel() const { return !MSAsmName.empty(); }
503
28
  bool isResolvedMSAsmLabel() const { return isMSAsmLabel() && MSAsmNameResolved; }
504
  void setMSAsmLabel(StringRef Name);
505
43
  StringRef getMSAsmLabel() const { return MSAsmName; }
506
18
  void setMSAsmLabelResolved() { MSAsmNameResolved = true; }
507
508
  // Implement isa/cast/dyncast/etc.
509
55.8M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
510
55.8M
  static bool classofKind(Kind K) { return K == Label; }
511
};
512
513
/// Represent a C++ namespace.
514
class NamespaceDecl : public NamedDecl, public DeclContext,
515
                      public Redeclarable<NamespaceDecl>
516
{
517
  /// The starting location of the source range, pointing
518
  /// to either the namespace or the inline keyword.
519
  SourceLocation LocStart;
520
521
  /// The ending location of the source range.
522
  SourceLocation RBraceLoc;
523
524
  /// A pointer to either the anonymous namespace that lives just inside
525
  /// this namespace or to the first namespace in the chain (the latter case
526
  /// only when this is not the first in the chain), along with a
527
  /// boolean value indicating whether this is an inline namespace.
528
  llvm::PointerIntPair<NamespaceDecl *, 1, bool> AnonOrFirstNamespaceAndInline;
529
530
  NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
531
                SourceLocation StartLoc, SourceLocation IdLoc,
532
                IdentifierInfo *Id, NamespaceDecl *PrevDecl);
533
534
  using redeclarable_base = Redeclarable<NamespaceDecl>;
535
536
  NamespaceDecl *getNextRedeclarationImpl() override;
537
  NamespaceDecl *getPreviousDeclImpl() override;
538
  NamespaceDecl *getMostRecentDeclImpl() override;
539
540
public:
541
  friend class ASTDeclReader;
542
  friend class ASTDeclWriter;
543
544
  static NamespaceDecl *Create(ASTContext &C, DeclContext *DC,
545
                               bool Inline, SourceLocation StartLoc,
546
                               SourceLocation IdLoc, IdentifierInfo *Id,
547
                               NamespaceDecl *PrevDecl);
548
549
  static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
550
551
  using redecl_range = redeclarable_base::redecl_range;
552
  using redecl_iterator = redeclarable_base::redecl_iterator;
553
554
  using redeclarable_base::redecls_begin;
555
  using redeclarable_base::redecls_end;
556
  using redeclarable_base::redecls;
557
  using redeclarable_base::getPreviousDecl;
558
  using redeclarable_base::getMostRecentDecl;
559
  using redeclarable_base::isFirstDecl;
560
561
  /// Returns true if this is an anonymous namespace declaration.
562
  ///
563
  /// For example:
564
  /// \code
565
  ///   namespace {
566
  ///     ...
567
  ///   };
568
  /// \endcode
569
  /// q.v. C++ [namespace.unnamed]
570
4.93M
  bool isAnonymousNamespace() const {
571
4.93M
    return !getIdentifier();
572
4.93M
  }
573
574
  /// Returns true if this is an inline namespace declaration.
575
3.92M
  bool isInline() const {
576
3.92M
    return AnonOrFirstNamespaceAndInline.getInt();
577
3.92M
  }
578
579
  /// Set whether this is an inline namespace declaration.
580
951
  void setInline(bool Inline) {
581
951
    AnonOrFirstNamespaceAndInline.setInt(Inline);
582
951
  }
583
584
  /// Get the original (first) namespace declaration.
585
  NamespaceDecl *getOriginalNamespace();
586
587
  /// Get the original (first) namespace declaration.
588
  const NamespaceDecl *getOriginalNamespace() const;
589
590
  /// Return true if this declaration is an original (first) declaration
591
  /// of the namespace. This is false for non-original (subsequent) namespace
592
  /// declarations and anonymous namespaces.
593
  bool isOriginalNamespace() const;
594
595
  /// Retrieve the anonymous namespace nested inside this namespace,
596
  /// if any.
597
1.20k
  NamespaceDecl *getAnonymousNamespace() const {
598
1.20k
    return getOriginalNamespace()->AnonOrFirstNamespaceAndInline.getPointer();
599
1.20k
  }
600
601
631
  void setAnonymousNamespace(NamespaceDecl *D) {
602
631
    getOriginalNamespace()->AnonOrFirstNamespaceAndInline.setPointer(D);
603
631
  }
604
605
  /// Retrieves the canonical declaration of this namespace.
606
9.27M
  NamespaceDecl *getCanonicalDecl() override {
607
9.27M
    return getOriginalNamespace();
608
9.27M
  }
609
0
  const NamespaceDecl *getCanonicalDecl() const {
610
0
    return getOriginalNamespace();
611
0
  }
612
613
715
  SourceRange getSourceRange() const override LLVM_READONLY {
614
715
    return SourceRange(LocStart, RBraceLoc);
615
715
  }
616
617
752
  SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
618
707
  SourceLocation getRBraceLoc() const { return RBraceLoc; }
619
0
  void setLocStart(SourceLocation L) { LocStart = L; }
620
119k
  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
621
622
  // Implement isa/cast/dyncast/etc.
623
66.8M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
624
81.6M
  static bool classofKind(Kind K) { return K == Namespace; }
625
4.38k
  static DeclContext *castToDeclContext(const NamespaceDecl *D) {
626
4.38k
    return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
627
4.38k
  }
628
0
  static NamespaceDecl *castFromDeclContext(const DeclContext *DC) {
629
0
    return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
630
0
  }
631
};
632
633
/// Represent the declaration of a variable (in which case it is
634
/// an lvalue) a function (in which case it is a function designator) or
635
/// an enum constant.
636
class ValueDecl : public NamedDecl {
637
  QualType DeclType;
638
639
  void anchor() override;
640
641
protected:
642
  ValueDecl(Kind DK, DeclContext *DC, SourceLocation L,
643
            DeclarationName N, QualType T)
644
29.6M
    : NamedDecl(DK, DC, L, N), DeclType(T) {}
645
646
public:
647
537M
  QualType getType() const { return DeclType; }
648
2.12M
  void setType(QualType newType) { DeclType = newType; }
649
650
  /// Determine whether this symbol is weakly-imported,
651
  ///        or declared with the weak or weak-ref attr.
652
  bool isWeak() const;
653
654
  // Implement isa/cast/dyncast/etc.
655
22.7M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
656
22.7M
  static bool classofKind(Kind K) { return K >= firstValue && 
K <= lastValue22.4M
; }
657
};
658
659
/// A struct with extended info about a syntactic
660
/// name qualifier, to be used for the case of out-of-line declarations.
661
struct QualifierInfo {
662
  NestedNameSpecifierLoc QualifierLoc;
663
664
  /// The number of "outer" template parameter lists.
665
  /// The count includes all of the template parameter lists that were matched
666
  /// against the template-ids occurring into the NNS and possibly (in the
667
  /// case of an explicit specialization) a final "template <>".
668
  unsigned NumTemplParamLists = 0;
669
670
  /// A new-allocated array of size NumTemplParamLists,
671
  /// containing pointers to the "outer" template parameter lists.
672
  /// It includes all of the template parameter lists that were matched
673
  /// against the template-ids occurring into the NNS and possibly (in the
674
  /// case of an explicit specialization) a final "template <>".
675
  TemplateParameterList** TemplParamLists = nullptr;
676
677
373k
  QualifierInfo() = default;
678
  QualifierInfo(const QualifierInfo &) = delete;
679
  QualifierInfo& operator=(const QualifierInfo &) = delete;
680
681
  /// Sets info about "outer" template parameter lists.
682
  void setTemplateParameterListsInfo(ASTContext &Context,
683
                                     ArrayRef<TemplateParameterList *> TPLists);
684
};
685
686
/// Represents a ValueDecl that came out of a declarator.
687
/// Contains type source information through TypeSourceInfo.
688
class DeclaratorDecl : public ValueDecl {
689
  // A struct representing both a TInfo and a syntactic qualifier,
690
  // to be used for the (uncommon) case of out-of-line declarations.
691
  struct ExtInfo : public QualifierInfo {
692
    TypeSourceInfo *TInfo;
693
  };
694
695
  llvm::PointerUnion<TypeSourceInfo *, ExtInfo *> DeclInfo;
696
697
  /// The start of the source range for this declaration,
698
  /// ignoring outer template declarations.
699
  SourceLocation InnerLocStart;
700
701
48.0M
  bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); }
702
871k
  ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); }
703
1.39M
  const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); }
704
705
protected:
706
  DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L,
707
                 DeclarationName N, QualType T, TypeSourceInfo *TInfo,
708
                 SourceLocation StartL)
709
29.2M
      : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {}
710
711
public:
712
  friend class ASTDeclReader;
713
  friend class ASTDeclWriter;
714
715
36.0M
  TypeSourceInfo *getTypeSourceInfo() const {
716
36.0M
    return hasExtInfo()
717
36.0M
      ? 
getExtInfo()->TInfo681k
718
36.0M
      : 
DeclInfo.get<TypeSourceInfo*>()35.4M
;
719
36.0M
  }
720
721
174k
  void setTypeSourceInfo(TypeSourceInfo *TI) {
722
174k
    if (hasExtInfo())
723
404
      getExtInfo()->TInfo = TI;
724
174k
    else
725
174k
      DeclInfo = TI;
726
174k
  }
727
728
  /// Return start of source range ignoring outer template declarations.
729
11.3M
  SourceLocation getInnerLocStart() const { return InnerLocStart; }
730
464k
  void setInnerLocStart(SourceLocation L) { InnerLocStart = L; }
731
732
  /// Return start of source range taking into account any outer template
733
  /// declarations.
734
  SourceLocation getOuterLocStart() const;
735
736
  SourceRange getSourceRange() const override LLVM_READONLY;
737
738
84.7k
  SourceLocation getBeginLoc() const LLVM_READONLY {
739
84.7k
    return getOuterLocStart();
740
84.7k
  }
741
742
  /// Retrieve the nested-name-specifier that qualifies the name of this
743
  /// declaration, if it was present in the source.
744
1.13M
  NestedNameSpecifier *getQualifier() const {
745
1.13M
    return hasExtInfo() ? 
getExtInfo()->QualifierLoc.getNestedNameSpecifier()504k
746
1.13M
                        : 
nullptr630k
;
747
1.13M
  }
748
749
  /// Retrieve the nested-name-specifier (with source-location
750
  /// information) that qualifies the name of this declaration, if it was
751
  /// present in the source.
752
2.52M
  NestedNameSpecifierLoc getQualifierLoc() const {
753
2.52M
    return hasExtInfo() ? 
getExtInfo()->QualifierLoc63.9k
754
2.52M
                        : 
NestedNameSpecifierLoc()2.45M
;
755
2.52M
  }
756
757
  void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
758
759
6.57M
  unsigned getNumTemplateParameterLists() const {
760
6.57M
    return hasExtInfo() ? 
getExtInfo()->NumTemplParamLists128k
:
06.44M
;
761
6.57M
  }
762
763
19.6k
  TemplateParameterList *getTemplateParameterList(unsigned index) const {
764
19.6k
    assert(index < getNumTemplateParameterLists());
765
19.6k
    return getExtInfo()->TemplParamLists[index];
766
19.6k
  }
767
768
  void setTemplateParameterListsInfo(ASTContext &Context,
769
                                     ArrayRef<TemplateParameterList *> TPLists);
770
771
  SourceLocation getTypeSpecStartLoc() const;
772
773
  // Implement isa/cast/dyncast/etc.
774
8.73M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
775
8.73M
  static bool classofKind(Kind K) {
776
8.73M
    return K >= firstDeclarator && 
K <= lastDeclarator7.06M
;
777
8.73M
  }
778
};
779
780
/// Structure used to store a statement, the constant value to
781
/// which it was evaluated (if any), and whether or not the statement
782
/// is an integral constant expression (if known).
783
struct EvaluatedStmt {
784
  /// Whether this statement was already evaluated.
785
  bool WasEvaluated : 1;
786
787
  /// Whether this statement is being evaluated.
788
  bool IsEvaluating : 1;
789
790
  /// Whether we already checked whether this statement was an
791
  /// integral constant expression.
792
  bool CheckedICE : 1;
793
794
  /// Whether we are checking whether this statement is an
795
  /// integral constant expression.
796
  bool CheckingICE : 1;
797
798
  /// Whether this statement is an integral constant expression,
799
  /// or in C++11, whether the statement is a constant expression. Only
800
  /// valid if CheckedICE is true.
801
  bool IsICE : 1;
802
803
  Stmt *Value;
804
  APValue Evaluated;
805
806
  EvaluatedStmt() : WasEvaluated(false), IsEvaluating(false), CheckedICE(false),
807
454k
                    CheckingICE(false), IsICE(false) {}
808
809
};
810
811
/// Represents a variable declaration or definition.
812
class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
813
public:
814
  /// Initialization styles.
815
  enum InitializationStyle {
816
    /// C-style initialization with assignment
817
    CInit,
818
819
    /// Call-style initialization (C++98)
820
    CallInit,
821
822
    /// Direct list-initialization (C++11)
823
    ListInit
824
  };
825
826
  /// Kinds of thread-local storage.
827
  enum TLSKind {
828
    /// Not a TLS variable.
829
    TLS_None,
830
831
    /// TLS with a known-constant initializer.
832
    TLS_Static,
833
834
    /// TLS with a dynamic initializer.
835
    TLS_Dynamic
836
  };
837
838
  /// Return the string used to specify the storage class \p SC.
839
  ///
840
  /// It is illegal to call this function with SC == None.
841
  static const char *getStorageClassSpecifierString(StorageClass SC);
842
843
protected:
844
  // A pointer union of Stmt * and EvaluatedStmt *. When an EvaluatedStmt, we
845
  // have allocated the auxiliary struct of information there.
846
  //
847
  // TODO: It is a bit unfortunate to use a PointerUnion inside the VarDecl for
848
  // this as *many* VarDecls are ParmVarDecls that don't have default
849
  // arguments. We could save some space by moving this pointer union to be
850
  // allocated in trailing space when necessary.
851
  using InitType = llvm::PointerUnion<Stmt *, EvaluatedStmt *>;
852
853
  /// The initializer for this variable or, for a ParmVarDecl, the
854
  /// C++ default argument.
855
  mutable InitType Init;
856
857
private:
858
  friend class ASTDeclReader;
859
  friend class ASTNodeImporter;
860
  friend class StmtIteratorBase;
861
862
  class VarDeclBitfields {
863
    friend class ASTDeclReader;
864
    friend class VarDecl;
865
866
    unsigned SClass : 3;
867
    unsigned TSCSpec : 2;
868
    unsigned InitStyle : 2;
869
  };
870
  enum { NumVarDeclBits = 7 };
871
872
protected:
873
  enum { NumParameterIndexBits = 8 };
874
875
  enum DefaultArgKind {
876
    DAK_None,
877
    DAK_Unparsed,
878
    DAK_Uninstantiated,
879
    DAK_Normal
880
  };
881
882
  class ParmVarDeclBitfields {
883
    friend class ASTDeclReader;
884
    friend class ParmVarDecl;
885
886
    unsigned : NumVarDeclBits;
887
888
    /// Whether this parameter inherits a default argument from a
889
    /// prior declaration.
890
    unsigned HasInheritedDefaultArg : 1;
891
892
    /// Describes the kind of default argument for this parameter. By default
893
    /// this is none. If this is normal, then the default argument is stored in
894
    /// the \c VarDecl initializer expression unless we were unable to parse
895
    /// (even an invalid) expression for the default argument.
896
    unsigned DefaultArgKind : 2;
897
898
    /// Whether this parameter undergoes K&R argument promotion.
899
    unsigned IsKNRPromoted : 1;
900
901
    /// Whether this parameter is an ObjC method parameter or not.
902
    unsigned IsObjCMethodParam : 1;
903
904
    /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier.
905
    /// Otherwise, the number of function parameter scopes enclosing
906
    /// the function parameter scope in which this parameter was
907
    /// declared.
908
    unsigned ScopeDepthOrObjCQuals : 7;
909
910
    /// The number of parameters preceding this parameter in the
911
    /// function parameter scope in which it was declared.
912
    unsigned ParameterIndex : NumParameterIndexBits;
913
  };
914
915
  class NonParmVarDeclBitfields {
916
    friend class ASTDeclReader;
917
    friend class ImplicitParamDecl;
918
    friend class VarDecl;
919
920
    unsigned : NumVarDeclBits;
921
922
    // FIXME: We need something similar to CXXRecordDecl::DefinitionData.
923
    /// Whether this variable is a definition which was demoted due to
924
    /// module merge.
925
    unsigned IsThisDeclarationADemotedDefinition : 1;
926
927
    /// Whether this variable is the exception variable in a C++ catch
928
    /// or an Objective-C @catch statement.
929
    unsigned ExceptionVar : 1;
930
931
    /// Whether this local variable could be allocated in the return
932
    /// slot of its function, enabling the named return value optimization
933
    /// (NRVO).
934
    unsigned NRVOVariable : 1;
935
936
    /// Whether this variable is the for-range-declaration in a C++0x
937
    /// for-range statement.
938
    unsigned CXXForRangeDecl : 1;
939
940
    /// Whether this variable is the for-in loop declaration in Objective-C.
941
    unsigned ObjCForDecl : 1;
942
943
    /// Whether this variable is an ARC pseudo-__strong
944
    /// variable;  see isARCPseudoStrong() for details.
945
    unsigned ARCPseudoStrong : 1;
946
947
    /// Whether this variable is (C++1z) inline.
948
    unsigned IsInline : 1;
949
950
    /// Whether this variable has (C++1z) inline explicitly specified.
951
    unsigned IsInlineSpecified : 1;
952
953
    /// Whether this variable is (C++0x) constexpr.
954
    unsigned IsConstexpr : 1;
955
956
    /// Whether this variable is the implicit variable for a lambda
957
    /// init-capture.
958
    unsigned IsInitCapture : 1;
959
960
    /// Whether this local extern variable's previous declaration was
961
    /// declared in the same block scope. This controls whether we should merge
962
    /// the type of this declaration with its previous declaration.
963
    unsigned PreviousDeclInSameBlockScope : 1;
964
965
    /// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or
966
    /// something else.
967
    unsigned ImplicitParamKind : 3;
968
  };
969
970
  union {
971
    unsigned AllBits;
972
    VarDeclBitfields VarDeclBits;
973
    ParmVarDeclBitfields ParmVarDeclBits;
974
    NonParmVarDeclBitfields NonParmVarDeclBits;
975
  };
976
977
  VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
978
          SourceLocation IdLoc, IdentifierInfo *Id, QualType T,
979
          TypeSourceInfo *TInfo, StorageClass SC);
980
981
  using redeclarable_base = Redeclarable<VarDecl>;
982
983
8.19M
  VarDecl *getNextRedeclarationImpl() override {
984
8.19M
    return getNextRedeclaration();
985
8.19M
  }
986
987
20.8k
  VarDecl *getPreviousDeclImpl() override {
988
20.8k
    return getPreviousDecl();
989
20.8k
  }
990
991
37.8M
  VarDecl *getMostRecentDeclImpl() override {
992
37.8M
    return getMostRecentDecl();
993
37.8M
  }
994
995
public:
996
  using redecl_range = redeclarable_base::redecl_range;
997
  using redecl_iterator = redeclarable_base::redecl_iterator;
998
999
  using redeclarable_base::redecls_begin;
1000
  using redeclarable_base::redecls_end;
1001
  using redeclarable_base::redecls;
1002
  using redeclarable_base::getPreviousDecl;
1003
  using redeclarable_base::getMostRecentDecl;
1004
  using redeclarable_base::isFirstDecl;
1005
1006
  static VarDecl *Create(ASTContext &C, DeclContext *DC,
1007
                         SourceLocation StartLoc, SourceLocation IdLoc,
1008
                         IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
1009
                         StorageClass S);
1010
1011
  static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1012
1013
  SourceRange getSourceRange() const override LLVM_READONLY;
1014
1015
  /// Returns the storage class as written in the source. For the
1016
  /// computed linkage of symbol, see getLinkage.
1017
123M
  StorageClass getStorageClass() const {
1018
123M
    return (StorageClass) VarDeclBits.SClass;
1019
123M
  }
1020
  void setStorageClass(StorageClass SC);
1021
1022
325k
  void setTSCSpec(ThreadStorageClassSpecifier TSC) {
1023
325k
    VarDeclBits.TSCSpec = TSC;
1024
325k
    assert(VarDeclBits.TSCSpec == TSC && "truncation");
1025
325k
  }
1026
42.3M
  ThreadStorageClassSpecifier getTSCSpec() const {
1027
42.3M
    return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec);
1028
42.3M
  }
1029
  TLSKind getTLSKind() const;
1030
1031
  /// Returns true if a variable with function scope is a non-static local
1032
  /// variable.
1033
47.3M
  bool hasLocalStorage() const {
1034
47.3M
    if (getStorageClass() == SC_None) {
1035
39.6M
      // OpenCL v1.2 s6.5.3: The __constant or constant address space name is
1036
39.6M
      // used to describe variables allocated in global memory and which are
1037
39.6M
      // accessed inside a kernel(s) as read-only variables. As such, variables
1038
39.6M
      // in constant address space cannot have local storage.
1039
39.6M
      if (getType().getAddressSpace() == LangAS::opencl_constant)
1040
1.12k
        return false;
1041
39.6M
      // Second check is for C++11 [dcl.stc]p4.
1042
39.6M
      return !isFileVarDecl() && 
getTSCSpec() == TSCS_unspecified35.2M
;
1043
39.6M
    }
1044
7.77M
1045
7.77M
    // Global Named Register (GNU extension)
1046
7.77M
    if (getStorageClass() == SC_Register && 
!isLocalVarDeclOrParm()103k
)
1047
814
      return false;
1048
7.77M
1049
7.77M
    // Return true for:  Auto, Register.
1050
7.77M
    // Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal.
1051
7.77M
1052
7.77M
    return getStorageClass() >= SC_Auto;
1053
7.77M
  }
1054
1055
  /// Returns true if a variable with function scope is a static local
1056
  /// variable.
1057
7.84M
  bool isStaticLocal() const {
1058
7.84M
    return (getStorageClass() == SC_Static ||
1059
7.84M
            // C++11 [dcl.stc]p4
1060
7.84M
            
(6.77M
getStorageClass() == SC_None6.77M
&&
getTSCSpec() == TSCS_thread_local6.43M
))
1061
7.84M
      && 
!isFileVarDecl()1.07M
;
1062
7.84M
  }
1063
1064
  /// Returns true if a variable has extern or __private_extern__
1065
  /// storage.
1066
18.1M
  bool hasExternalStorage() const {
1067
18.1M
    return getStorageClass() == SC_Extern ||
1068
18.1M
           
getStorageClass() == SC_PrivateExtern17.1M
;
1069
18.1M
  }
1070
1071
  /// Returns true for all variables that do not have local storage.
1072
  ///
1073
  /// This includes all global variables as well as static variables declared
1074
  /// within a function.
1075
12.0M
  bool hasGlobalStorage() const { return !hasLocalStorage(); }
1076
1077
  /// Get the storage duration of this variable, per C++ [basic.stc].
1078
836k
  StorageDuration getStorageDuration() const {
1079
836k
    return hasLocalStorage() ? 
SD_Automatic816k
:
1080
836k
           
getTSCSpec() 20.1k
?
SD_Thread168
:
SD_Static19.9k
;
1081
836k
  }
1082
1083
  /// Compute the language linkage.
1084
  LanguageLinkage getLanguageLinkage() const;
1085
1086
  /// Determines whether this variable is a variable with external, C linkage.
1087
  bool isExternC() const;
1088
1089
  /// Determines whether this variable's context is, or is nested within,
1090
  /// a C++ extern "C" linkage spec.
1091
  bool isInExternCContext() const;
1092
1093
  /// Determines whether this variable's context is, or is nested within,
1094
  /// a C++ extern "C++" linkage spec.
1095
  bool isInExternCXXContext() const;
1096
1097
  /// Returns true for local variable declarations other than parameters.
1098
  /// Note that this includes static variables inside of functions. It also
1099
  /// includes variables inside blocks.
1100
  ///
1101
  ///   void foo() { int x; static int y; extern int z; }
1102
9.47M
  bool isLocalVarDecl() const {
1103
9.47M
    if (getKind() != Decl::Var && 
getKind() != Decl::Decomposition1.00M
)
1104
1.00M
      return false;
1105
8.47M
    if (const DeclContext *DC = getLexicalDeclContext())
1106
8.47M
      return DC->getRedeclContext()->isFunctionOrMethod();
1107
0
    return false;
1108
0
  }
1109
1110
  /// Similar to isLocalVarDecl but also includes parameters.
1111
187k
  bool isLocalVarDeclOrParm() const {
1112
187k
    return isLocalVarDecl() || 
getKind() == Decl::ParmVar88.9k
;
1113
187k
  }
1114
1115
  /// Similar to isLocalVarDecl, but excludes variables declared in blocks.
1116
226k
  bool isFunctionOrMethodVarDecl() const {
1117
226k
    if (getKind() != Decl::Var && 
getKind() != Decl::Decomposition67.9k
)
1118
67.9k
      return false;
1119
158k
    const DeclContext *DC = getLexicalDeclContext()->getRedeclContext();
1120
158k
    return DC->isFunctionOrMethod() && 
DC->getDeclKind() != Decl::Block143k
;
1121
158k
  }
1122
1123
  /// Determines whether this is a static data member.
1124
  ///
1125
  /// This will only be true in C++, and applies to, e.g., the
1126
  /// variable 'x' in:
1127
  /// \code
1128
  /// struct S {
1129
  ///   static int x;
1130
  /// };
1131
  /// \endcode
1132
205M
  bool isStaticDataMember() const {
1133
205M
    // If it wasn't static, it would be a FieldDecl.
1134
205M
    return getKind() != Decl::ParmVar && 
getDeclContext()->isRecord()184M
;
1135
205M
  }
1136
1137
  VarDecl *getCanonicalDecl() override;
1138
12.8M
  const VarDecl *getCanonicalDecl() const {
1139
12.8M
    return const_cast<VarDecl*>(this)->getCanonicalDecl();
1140
12.8M
  }
1141
1142
  enum DefinitionKind {
1143
    /// This declaration is only a declaration.
1144
    DeclarationOnly,
1145
1146
    /// This declaration is a tentative definition.
1147
    TentativeDefinition,
1148
1149
    /// This declaration is definitely a definition.
1150
    Definition
1151
  };
1152
1153
  /// Check whether this declaration is a definition. If this could be
1154
  /// a tentative definition (in C), don't check whether there's an overriding
1155
  /// definition.
1156
  DefinitionKind isThisDeclarationADefinition(ASTContext &) const;
1157
13.3M
  DefinitionKind isThisDeclarationADefinition() const {
1158
13.3M
    return isThisDeclarationADefinition(getASTContext());
1159
13.3M
  }
1160
1161
  /// Check whether this variable is defined in this translation unit.
1162
  DefinitionKind hasDefinition(ASTContext &) const;
1163
39.7k
  DefinitionKind hasDefinition() const {
1164
39.7k
    return hasDefinition(getASTContext());
1165
39.7k
  }
1166
1167
  /// Get the tentative definition that acts as the real definition in a TU.
1168
  /// Returns null if there is a proper definition available.
1169
  VarDecl *getActingDefinition();
1170
578
  const VarDecl *getActingDefinition() const {
1171
578
    return const_cast<VarDecl*>(this)->getActingDefinition();
1172
578
  }
1173
1174
  /// Get the real (not just tentative) definition for this declaration.
1175
  VarDecl *getDefinition(ASTContext &);
1176
6.84M
  const VarDecl *getDefinition(ASTContext &C) const {
1177
6.84M
    return const_cast<VarDecl*>(this)->getDefinition(C);
1178
6.84M
  }
1179
4.53M
  VarDecl *getDefinition() {
1180
4.53M
    return getDefinition(getASTContext());
1181
4.53M
  }
1182
4.39k
  const VarDecl *getDefinition() const {
1183
4.39k
    return const_cast<VarDecl*>(this)->getDefinition();
1184
4.39k
  }
1185
1186
  /// Determine whether this is or was instantiated from an out-of-line
1187
  /// definition of a static data member.
1188
  bool isOutOfLine() const override;
1189
1190
  /// Returns true for file scoped variable declaration.
1191
52.6M
  bool isFileVarDecl() const {
1192
52.6M
    Kind K = getKind();
1193
52.6M
    if (K == ParmVar || 
K == ImplicitParam44.5M
)
1194
8.76M
      return false;
1195
43.9M
1196
43.9M
    if (getLexicalDeclContext()->getRedeclContext()->isFileContext())
1197
7.04M
      return true;
1198
36.8M
1199
36.8M
    if (isStaticDataMember())
1200
1.65M
      return true;
1201
35.2M
1202
35.2M
    return false;
1203
35.2M
  }
1204
1205
  /// Get the initializer for this variable, no matter which
1206
  /// declaration it is attached to.
1207
2.07M
  const Expr *getAnyInitializer() const {
1208
2.07M
    const VarDecl *D;
1209
2.07M
    return getAnyInitializer(D);
1210
2.07M
  }
1211
1212
  /// Get the initializer for this variable, no matter which
1213
  /// declaration it is attached to. Also get that declaration.
1214
  const Expr *getAnyInitializer(const VarDecl *&D) const;
1215
1216
  bool hasInit() const;
1217
3.35M
  const Expr *getInit() const {
1218
3.35M
    return const_cast<VarDecl *>(this)->getInit();
1219
3.35M
  }
1220
  Expr *getInit();
1221
1222
  /// Retrieve the address of the initializer expression.
1223
  Stmt **getInitAddress();
1224
1225
  void setInit(Expr *I);
1226
1227
  /// Determine whether this variable's value can be used in a
1228
  /// constant expression, according to the relevant language standard.
1229
  /// This only checks properties of the declaration, and does not check
1230
  /// whether the initializer is in fact a constant expression.
1231
  bool isUsableInConstantExpressions(ASTContext &C) const;
1232
1233
  EvaluatedStmt *ensureEvaluatedStmt() const;
1234
1235
  /// Attempt to evaluate the value of the initializer attached to this
1236
  /// declaration, and produce notes explaining why it cannot be evaluated or is
1237
  /// not a constant expression. Returns a pointer to the value if evaluation
1238
  /// succeeded, 0 otherwise.
1239
  APValue *evaluateValue() const;
1240
  APValue *evaluateValue(SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
1241
1242
  /// Return the already-evaluated value of this variable's
1243
  /// initializer, or NULL if the value is not yet known. Returns pointer
1244
  /// to untyped APValue if the value could not be evaluated.
1245
  APValue *getEvaluatedValue() const;
1246
1247
  /// Determines whether it is already known whether the
1248
  /// initializer is an integral constant expression or not.
1249
  bool isInitKnownICE() const;
1250
1251
  /// Determines whether the initializer is an integral constant
1252
  /// expression, or in C++11, whether the initializer is a constant
1253
  /// expression.
1254
  ///
1255
  /// \pre isInitKnownICE()
1256
  bool isInitICE() const;
1257
1258
  /// Determine whether the value of the initializer attached to this
1259
  /// declaration is an integral constant expression.
1260
  bool checkInitIsICE() const;
1261
1262
488k
  void setInitStyle(InitializationStyle Style) {
1263
488k
    VarDeclBits.InitStyle = Style;
1264
488k
  }
1265
1266
  /// The style of initialization for this declaration.
1267
  ///
1268
  /// C-style initialization is "int x = 1;". Call-style initialization is
1269
  /// a C++98 direct-initializer, e.g. "int x(1);". The Init expression will be
1270
  /// the expression inside the parens or a "ClassType(a,b,c)" class constructor
1271
  /// expression for class types. List-style initialization is C++11 syntax,
1272
  /// e.g. "int x{1};". Clients can distinguish between different forms of
1273
  /// initialization by checking this value. In particular, "int x = {1};" is
1274
  /// C-style, "int x({1})" is call-style, and "int x{1};" is list-style; the
1275
  /// Init expression in all three cases is an InitListExpr.
1276
1.43M
  InitializationStyle getInitStyle() const {
1277
1.43M
    return static_cast<InitializationStyle>(VarDeclBits.InitStyle);
1278
1.43M
  }
1279
1280
  /// Whether the initializer is a direct-initializer (list or call).
1281
292k
  bool isDirectInit() const {
1282
292k
    return getInitStyle() != CInit;
1283
292k
  }
1284
1285
  /// If this definition should pretend to be a declaration.
1286
35.2M
  bool isThisDeclarationADemotedDefinition() const {
1287
35.2M
    return isa<ParmVarDecl>(this) ? 
false5.88M
:
1288
35.2M
      
NonParmVarDeclBits.IsThisDeclarationADemotedDefinition29.3M
;
1289
35.2M
  }
1290
1291
  /// This is a definition which should be demoted to a declaration.
1292
  ///
1293
  /// In some cases (mostly module merging) we can end up with two visible
1294
  /// definitions one of which needs to be demoted to a declaration to keep
1295
  /// the AST invariants.
1296
26
  void demoteThisDefinitionToDeclaration() {
1297
26
    assert(isThisDeclarationADefinition() && "Not a definition!");
1298
26
    assert(!isa<ParmVarDecl>(this) && "Cannot demote ParmVarDecls!");
1299
26
    NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = 1;
1300
26
  }
1301
1302
  /// Determine whether this variable is the exception variable in a
1303
  /// C++ catch statememt or an Objective-C \@catch statement.
1304
2.31M
  bool isExceptionVariable() const {
1305
2.31M
    return isa<ParmVarDecl>(this) ? 
false3.32k
:
NonParmVarDeclBits.ExceptionVar2.30M
;
1306
2.31M
  }
1307
915
  void setExceptionVariable(bool EV) {
1308
915
    assert(!isa<ParmVarDecl>(this));
1309
915
    NonParmVarDeclBits.ExceptionVar = EV;
1310
915
  }
1311
1312
  /// Determine whether this local variable can be used with the named
1313
  /// return value optimization (NRVO).
1314
  ///
1315
  /// The named return value optimization (NRVO) works by marking certain
1316
  /// non-volatile local variables of class type as NRVO objects. These
1317
  /// locals can be allocated within the return slot of their containing
1318
  /// function, in which case there is no need to copy the object to the
1319
  /// return slot when returning from the function. Within the function body,
1320
  /// each return that returns the NRVO object will have this variable as its
1321
  /// NRVO candidate.
1322
894k
  bool isNRVOVariable() const {
1323
894k
    return isa<ParmVarDecl>(this) ? 
false933
:
NonParmVarDeclBits.NRVOVariable893k
;
1324
894k
  }
1325
38.4k
  void setNRVOVariable(bool NRVO) {
1326
38.4k
    assert(!isa<ParmVarDecl>(this));
1327
38.4k
    NonParmVarDeclBits.NRVOVariable = NRVO;
1328
38.4k
  }
1329
1330
  /// Determine whether this variable is the for-range-declaration in
1331
  /// a C++0x for-range statement.
1332
500k
  bool isCXXForRangeDecl() const {
1333
500k
    return isa<ParmVarDecl>(this) ? 
false0
: NonParmVarDeclBits.CXXForRangeDecl;
1334
500k
  }
1335
327k
  void setCXXForRangeDecl(bool FRD) {
1336
327k
    assert(!isa<ParmVarDecl>(this));
1337
327k
    NonParmVarDeclBits.CXXForRangeDecl = FRD;
1338
327k
  }
1339
1340
  /// Determine whether this variable is a for-loop declaration for a
1341
  /// for-in statement in Objective-C.
1342
469k
  bool isObjCForDecl() const {
1343
469k
    return NonParmVarDeclBits.ObjCForDecl;
1344
469k
  }
1345
1346
324k
  void setObjCForDecl(bool FRD) {
1347
324k
    NonParmVarDeclBits.ObjCForDecl = FRD;
1348
324k
  }
1349
1350
  /// Determine whether this variable is an ARC pseudo-__strong
1351
  /// variable.  A pseudo-__strong variable has a __strong-qualified
1352
  /// type but does not actually retain the object written into it.
1353
  /// Generally such variables are also 'const' for safety.
1354
125k
  bool isARCPseudoStrong() const {
1355
125k
    return isa<ParmVarDecl>(this) ? 
false181
:
NonParmVarDeclBits.ARCPseudoStrong124k
;
1356
125k
  }
1357
1.99k
  void setARCPseudoStrong(bool ps) {
1358
1.99k
    assert(!isa<ParmVarDecl>(this));
1359
1.99k
    NonParmVarDeclBits.ARCPseudoStrong = ps;
1360
1.99k
  }
1361
1362
  /// Whether this variable is (C++1z) inline.
1363
18.7M
  bool isInline() const {
1364
18.7M
    return isa<ParmVarDecl>(this) ? 
false933
:
NonParmVarDeclBits.IsInline18.7M
;
1365
18.7M
  }
1366
449k
  bool isInlineSpecified() const {
1367
449k
    return isa<ParmVarDecl>(this) ? 
false0
1368
449k
                                  : NonParmVarDeclBits.IsInlineSpecified;
1369
449k
  }
1370
139
  void setInlineSpecified() {
1371
139
    assert(!isa<ParmVarDecl>(this));
1372
139
    NonParmVarDeclBits.IsInline = true;
1373
139
    NonParmVarDeclBits.IsInlineSpecified = true;
1374
139
  }
1375
188
  void setImplicitlyInline() {
1376
188
    assert(!isa<ParmVarDecl>(this));
1377
188
    NonParmVarDeclBits.IsInline = true;
1378
188
  }
1379
1380
  /// Whether this variable is (C++11) constexpr.
1381
18.3M
  bool isConstexpr() const {
1382
18.3M
    return isa<ParmVarDecl>(this) ? 
false1.75M
:
NonParmVarDeclBits.IsConstexpr16.6M
;
1383
18.3M
  }
1384
502k
  void setConstexpr(bool IC) {
1385
502k
    assert(!isa<ParmVarDecl>(this));
1386
502k
    NonParmVarDeclBits.IsConstexpr = IC;
1387
502k
  }
1388
1389
  /// Whether this variable is the implicit variable for a lambda init-capture.
1390
38.1M
  bool isInitCapture() const {
1391
38.1M
    return isa<ParmVarDecl>(this) ? 
false18.5M
:
NonParmVarDeclBits.IsInitCapture19.5M
;
1392
38.1M
  }
1393
324k
  void setInitCapture(bool IC) {
1394
324k
    assert(!isa<ParmVarDecl>(this));
1395
324k
    NonParmVarDeclBits.IsInitCapture = IC;
1396
324k
  }
1397
1398
  /// Whether this local extern variable declaration's previous declaration
1399
  /// was declared in the same block scope. Only correct in C++.
1400
525k
  bool isPreviousDeclInSameBlockScope() const {
1401
525k
    return isa<ParmVarDecl>(this)
1402
525k
               ? 
false0
1403
525k
               : NonParmVarDeclBits.PreviousDeclInSameBlockScope;
1404
525k
  }
1405
324k
  void setPreviousDeclInSameBlockScope(bool Same) {
1406
324k
    assert(!isa<ParmVarDecl>(this));
1407
324k
    NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
1408
324k
  }
1409
1410
  /// Retrieve the variable declaration from which this variable could
1411
  /// be instantiated, if it is an instantiation (rather than a non-template).
1412
  VarDecl *getTemplateInstantiationPattern() const;
1413
1414
  /// If this variable is an instantiated static data member of a
1415
  /// class template specialization, returns the templated static data member
1416
  /// from which it was instantiated.
1417
  VarDecl *getInstantiatedFromStaticDataMember() const;
1418
1419
  /// If this variable is an instantiation of a variable template or a
1420
  /// static data member of a class template, determine what kind of
1421
  /// template specialization or instantiation this is.
1422
  TemplateSpecializationKind getTemplateSpecializationKind() const;
1423
1424
  /// If this variable is an instantiation of a variable template or a
1425
  /// static data member of a class template, determine its point of
1426
  /// instantiation.
1427
  SourceLocation getPointOfInstantiation() const;
1428
1429
  /// If this variable is an instantiation of a static data member of a
1430
  /// class template specialization, retrieves the member specialization
1431
  /// information.
1432
  MemberSpecializationInfo *getMemberSpecializationInfo() const;
1433
1434
  /// For a static data member that was instantiated from a static
1435
  /// data member of a class template, set the template specialiation kind.
1436
  void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
1437
                        SourceLocation PointOfInstantiation = SourceLocation());
1438
1439
  /// Specify that this variable is an instantiation of the
1440
  /// static data member VD.
1441
  void setInstantiationOfStaticDataMember(VarDecl *VD,
1442
                                          TemplateSpecializationKind TSK);
1443
1444
  /// Retrieves the variable template that is described by this
1445
  /// variable declaration.
1446
  ///
1447
  /// Every variable template is represented as a VarTemplateDecl and a
1448
  /// VarDecl. The former contains template properties (such as
1449
  /// the template parameter lists) while the latter contains the
1450
  /// actual description of the template's
1451
  /// contents. VarTemplateDecl::getTemplatedDecl() retrieves the
1452
  /// VarDecl that from a VarTemplateDecl, while
1453
  /// getDescribedVarTemplate() retrieves the VarTemplateDecl from
1454
  /// a VarDecl.
1455
  VarTemplateDecl *getDescribedVarTemplate() const;
1456
1457
  void setDescribedVarTemplate(VarTemplateDecl *Template);
1458
1459
  // Is this variable known to have a definition somewhere in the complete
1460
  // program? This may be true even if the declaration has internal linkage and
1461
  // has no definition within this source file.
1462
  bool isKnownToBeDefined() const;
1463
1464
  /// Do we need to emit an exit-time destructor for this variable?
1465
  bool isNoDestroy(const ASTContext &) const;
1466
1467
  // Implement isa/cast/dyncast/etc.
1468
232M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1469
232M
  static bool classofKind(Kind K) { return K >= firstVar && 
K <= lastVar117M
; }
1470
};
1471
1472
class ImplicitParamDecl : public VarDecl {
1473
  void anchor() override;
1474
1475
public:
1476
  /// Defines the kind of the implicit parameter: is this an implicit parameter
1477
  /// with pointer to 'this', 'self', '_cmd', virtual table pointers, captured
1478
  /// context or something else.
1479
  enum ImplicitParamKind : unsigned {
1480
    /// Parameter for Objective-C 'self' argument
1481
    ObjCSelf,
1482
1483
    /// Parameter for Objective-C '_cmd' argument
1484
    ObjCCmd,
1485
1486
    /// Parameter for C++ 'this' argument
1487
    CXXThis,
1488
1489
    /// Parameter for C++ virtual table pointers
1490
    CXXVTT,
1491
1492
    /// Parameter for captured context
1493
    CapturedContext,
1494
1495
    /// Other implicit parameter
1496
    Other,
1497
  };
1498
1499
  /// Create implicit parameter.
1500
  static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC,
1501
                                   SourceLocation IdLoc, IdentifierInfo *Id,
1502
                                   QualType T, ImplicitParamKind ParamKind);
1503
  static ImplicitParamDecl *Create(ASTContext &C, QualType T,
1504
                                   ImplicitParamKind ParamKind);
1505
1506
  static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1507
1508
  ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc,
1509
                    IdentifierInfo *Id, QualType Type,
1510
                    ImplicitParamKind ParamKind)
1511
      : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
1512
1.23M
                /*TInfo=*/nullptr, SC_None) {
1513
1.23M
    NonParmVarDeclBits.ImplicitParamKind = ParamKind;
1514
1.23M
    setImplicit();
1515
1.23M
  }
1516
1517
  ImplicitParamDecl(ASTContext &C, QualType Type, ImplicitParamKind ParamKind)
1518
      : VarDecl(ImplicitParam, C, /*DC=*/nullptr, SourceLocation(),
1519
                SourceLocation(), /*Id=*/nullptr, Type,
1520
67.9k
                /*TInfo=*/nullptr, SC_None) {
1521
67.9k
    NonParmVarDeclBits.ImplicitParamKind = ParamKind;
1522
67.9k
    setImplicit();
1523
67.9k
  }
1524
1525
  /// Returns the implicit parameter kind.
1526
68.9k
  ImplicitParamKind getParameterKind() const {
1527
68.9k
    return static_cast<ImplicitParamKind>(NonParmVarDeclBits.ImplicitParamKind);
1528
68.9k
  }
1529
1530
  // Implement isa/cast/dyncast/etc.
1531
1.04M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1532
1.04M
  static bool classofKind(Kind K) { return K == ImplicitParam; }
1533
};
1534
1535
/// Represents a parameter to a function.
1536
class ParmVarDecl : public VarDecl {
1537
public:
1538
  enum { MaxFunctionScopeDepth = 255 };
1539
  enum { MaxFunctionScopeIndex = 255 };
1540
1541
protected:
1542
  ParmVarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1543
              SourceLocation IdLoc, IdentifierInfo *Id, QualType T,
1544
              TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
1545
13.3M
      : VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) {
1546
13.3M
    assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
1547
13.3M
    assert(ParmVarDeclBits.DefaultArgKind == DAK_None);
1548
13.3M
    assert(ParmVarDeclBits.IsKNRPromoted == false);
1549
13.3M
    assert(ParmVarDeclBits.IsObjCMethodParam == false);
1550
13.3M
    setDefaultArg(DefArg);
1551
13.3M
  }
1552
1553
public:
1554
  static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
1555
                             SourceLocation StartLoc,
1556
                             SourceLocation IdLoc, IdentifierInfo *Id,
1557
                             QualType T, TypeSourceInfo *TInfo,
1558
                             StorageClass S, Expr *DefArg);
1559
1560
  static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1561
1562
  SourceRange getSourceRange() const override LLVM_READONLY;
1563
1564
65.3k
  void setObjCMethodScopeInfo(unsigned parameterIndex) {
1565
65.3k
    ParmVarDeclBits.IsObjCMethodParam = true;
1566
65.3k
    setParameterIndex(parameterIndex);
1567
65.3k
  }
1568
1569
12.8M
  void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) {
1570
12.8M
    assert(!ParmVarDeclBits.IsObjCMethodParam);
1571
12.8M
1572
12.8M
    ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth;
1573
12.8M
    assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth
1574
12.8M
           && "truncation!");
1575
12.8M
1576
12.8M
    setParameterIndex(parameterIndex);
1577
12.8M
  }
1578
1579
146k
  bool isObjCMethodParameter() const {
1580
146k
    return ParmVarDeclBits.IsObjCMethodParam;
1581
146k
  }
1582
1583
2.61M
  unsigned getFunctionScopeDepth() const {
1584
2.61M
    if (ParmVarDeclBits.IsObjCMethodParam) 
return 0263
;
1585
2.61M
    return ParmVarDeclBits.ScopeDepthOrObjCQuals;
1586
2.61M
  }
1587
1588
  /// Returns the index of this parameter in its prototype or method scope.
1589
8.20M
  unsigned getFunctionScopeIndex() const {
1590
8.20M
    return getParameterIndex();
1591
8.20M
  }
1592
1593
247k
  ObjCDeclQualifier getObjCDeclQualifier() const {
1594
247k
    if (!ParmVarDeclBits.IsObjCMethodParam) 
return OBJC_TQ_None240k
;
1595
7.36k
    return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals);
1596
7.36k
  }
1597
65.1k
  void setObjCDeclQualifier(ObjCDeclQualifier QTVal) {
1598
65.1k
    assert(ParmVarDeclBits.IsObjCMethodParam);
1599
65.1k
    ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal;
1600
65.1k
  }
1601
1602
  /// True if the value passed to this parameter must undergo
1603
  /// K&R-style default argument promotion:
1604
  ///
1605
  /// C99 6.5.2.2.
1606
  ///   If the expression that denotes the called function has a type
1607
  ///   that does not include a prototype, the integer promotions are
1608
  ///   performed on each argument, and arguments that have type float
1609
  ///   are promoted to double.
1610
636k
  bool isKNRPromoted() const {
1611
636k
    return ParmVarDeclBits.IsKNRPromoted;
1612
636k
  }
1613
539
  void setKNRPromoted(bool promoted) {
1614
539
    ParmVarDeclBits.IsKNRPromoted = promoted;
1615
539
  }
1616
1617
  Expr *getDefaultArg();
1618
2.66k
  const Expr *getDefaultArg() const {
1619
2.66k
    return const_cast<ParmVarDecl *>(this)->getDefaultArg();
1620
2.66k
  }
1621
1622
  void setDefaultArg(Expr *defarg);
1623
1624
  /// Retrieve the source range that covers the entire default
1625
  /// argument.
1626
  SourceRange getDefaultArgRange() const;
1627
  void setUninstantiatedDefaultArg(Expr *arg);
1628
  Expr *getUninstantiatedDefaultArg();
1629
1
  const Expr *getUninstantiatedDefaultArg() const {
1630
1
    return const_cast<ParmVarDecl *>(this)->getUninstantiatedDefaultArg();
1631
1
  }
1632
1633
  /// Determines whether this parameter has a default argument,
1634
  /// either parsed or not.
1635
  bool hasDefaultArg() const;
1636
1637
  /// Determines whether this parameter has a default argument that has not
1638
  /// yet been parsed. This will occur during the processing of a C++ class
1639
  /// whose member functions have default arguments, e.g.,
1640
  /// @code
1641
  ///   class X {
1642
  ///   public:
1643
  ///     void f(int x = 17); // x has an unparsed default argument now
1644
  ///   }; // x has a regular default argument now
1645
  /// @endcode
1646
44.6M
  bool hasUnparsedDefaultArg() const {
1647
44.6M
    return ParmVarDeclBits.DefaultArgKind == DAK_Unparsed;
1648
44.6M
  }
1649
1650
42.7M
  bool hasUninstantiatedDefaultArg() const {
1651
42.7M
    return ParmVarDeclBits.DefaultArgKind == DAK_Uninstantiated;
1652
42.7M
  }
1653
1654
  /// Specify that this parameter has an unparsed default argument.
1655
  /// The argument will be replaced with a real default argument via
1656
  /// setDefaultArg when the class definition enclosing the function
1657
  /// declaration that owns this default argument is completed.
1658
84.5k
  void setUnparsedDefaultArg() {
1659
84.5k
    ParmVarDeclBits.DefaultArgKind = DAK_Unparsed;
1660
84.5k
  }
1661
1662
2.57M
  bool hasInheritedDefaultArg() const {
1663
2.57M
    return ParmVarDeclBits.HasInheritedDefaultArg;
1664
2.57M
  }
1665
1666
2.31M
  void setHasInheritedDefaultArg(bool I = true) {
1667
2.31M
    ParmVarDeclBits.HasInheritedDefaultArg = I;
1668
2.31M
  }
1669
1670
  QualType getOriginalType() const;
1671
1672
  /// Determine whether this parameter is actually a function
1673
  /// parameter pack.
1674
  bool isParameterPack() const;
1675
1676
  /// Sets the function declaration that owns this
1677
  /// ParmVarDecl. Since ParmVarDecls are often created before the
1678
  /// FunctionDecls that own them, this routine is required to update
1679
  /// the DeclContext appropriately.
1680
6.71M
  void setOwningFunction(DeclContext *FD) { setDeclContext(FD); }
1681
1682
  // Implement isa/cast/dyncast/etc.
1683
258M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1684
258M
  static bool classofKind(Kind K) { return K == ParmVar; }
1685
1686
private:
1687
  enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };
1688
1689
12.8M
  void setParameterIndex(unsigned parameterIndex) {
1690
12.8M
    if (parameterIndex >= ParameterIndexSentinel) {
1691
47
      setParameterIndexLarge(parameterIndex);
1692
47
      return;
1693
47
    }
1694
12.8M
1695
12.8M
    ParmVarDeclBits.ParameterIndex = parameterIndex;
1696
12.8M
    assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
1697
12.8M
  }
1698
8.20M
  unsigned getParameterIndex() const {
1699
8.20M
    unsigned d = ParmVarDeclBits.ParameterIndex;
1700
8.20M
    return d == ParameterIndexSentinel ? 
getParameterIndexLarge()2
:
d8.20M
;
1701
8.20M
  }
1702
1703
  void setParameterIndexLarge(unsigned parameterIndex);
1704
  unsigned getParameterIndexLarge() const;
1705
};
1706
1707
/// Represents a function declaration or definition.
1708
///
1709
/// Since a given function can be declared several times in a program,
1710
/// there may be several FunctionDecls that correspond to that
1711
/// function. Only one of those FunctionDecls will be found when
1712
/// traversing the list of declarations in the context of the
1713
/// FunctionDecl (e.g., the translation unit); this FunctionDecl
1714
/// contains all of the information known about the function. Other,
1715
/// previous declarations of the function are available via the
1716
/// getPreviousDecl() chain.
1717
class FunctionDecl : public DeclaratorDecl,
1718
                     public DeclContext,
1719
                     public Redeclarable<FunctionDecl> {
1720
  // This class stores some data in DeclContext::FunctionDeclBits
1721
  // to save some space. Use the provided accessors to access it.
1722
public:
1723
  /// The kind of templated function a FunctionDecl can be.
1724
  enum TemplatedKind {
1725
    TK_NonTemplate,
1726
    TK_FunctionTemplate,
1727
    TK_MemberSpecialization,
1728
    TK_FunctionTemplateSpecialization,
1729
    TK_DependentFunctionTemplateSpecialization
1730
  };
1731
1732
private:
1733
  /// A new[]'d array of pointers to VarDecls for the formal
1734
  /// parameters of this function.  This is null if a prototype or if there are
1735
  /// no formals.
1736
  ParmVarDecl **ParamInfo = nullptr;
1737
1738
  LazyDeclStmtPtr Body;
1739
1740
  unsigned ODRHash;
1741
1742
  /// End part of this FunctionDecl's source range.
1743
  ///
1744
  /// We could compute the full range in getSourceRange(). However, when we're
1745
  /// dealing with a function definition deserialized from a PCH/AST file,
1746
  /// we can only compute the full range once the function body has been
1747
  /// de-serialized, so it's far better to have the (sometimes-redundant)
1748
  /// EndRangeLoc.
1749
  SourceLocation EndRangeLoc;
1750
1751
  /// The template or declaration that this declaration
1752
  /// describes or was instantiated from, respectively.
1753
  ///
1754
  /// For non-templates, this value will be NULL. For function
1755
  /// declarations that describe a function template, this will be a
1756
  /// pointer to a FunctionTemplateDecl. For member functions
1757
  /// of class template specializations, this will be a MemberSpecializationInfo
1758
  /// pointer containing information about the specialization.
1759
  /// For function template specializations, this will be a
1760
  /// FunctionTemplateSpecializationInfo, which contains information about
1761
  /// the template being specialized and the template arguments involved in
1762
  /// that specialization.
1763
  llvm::PointerUnion4<FunctionTemplateDecl *,
1764
                      MemberSpecializationInfo *,
1765
                      FunctionTemplateSpecializationInfo *,
1766
                      DependentFunctionTemplateSpecializationInfo *>
1767
    TemplateOrSpecialization;
1768
1769
  /// Provides source/type location info for the declaration name embedded in
1770
  /// the DeclaratorDecl base class.
1771
  DeclarationNameLoc DNLoc;
1772
1773
  /// Specify that this function declaration is actually a function
1774
  /// template specialization.
1775
  ///
1776
  /// \param C the ASTContext.
1777
  ///
1778
  /// \param Template the function template that this function template
1779
  /// specialization specializes.
1780
  ///
1781
  /// \param TemplateArgs the template arguments that produced this
1782
  /// function template specialization from the template.
1783
  ///
1784
  /// \param InsertPos If non-NULL, the position in the function template
1785
  /// specialization set where the function template specialization data will
1786
  /// be inserted.
1787
  ///
1788
  /// \param TSK the kind of template specialization this is.
1789
  ///
1790
  /// \param TemplateArgsAsWritten location info of template arguments.
1791
  ///
1792
  /// \param PointOfInstantiation point at which the function template
1793
  /// specialization was first instantiated.
1794
  void setFunctionTemplateSpecialization(ASTContext &C,
1795
                                         FunctionTemplateDecl *Template,
1796
                                       const TemplateArgumentList *TemplateArgs,
1797
                                         void *InsertPos,
1798
                                         TemplateSpecializationKind TSK,
1799
                          const TemplateArgumentListInfo *TemplateArgsAsWritten,
1800
                                         SourceLocation PointOfInstantiation);
1801
1802
  /// Specify that this record is an instantiation of the
1803
  /// member function FD.
1804
  void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD,
1805
                                        TemplateSpecializationKind TSK);
1806
1807
  void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo);
1808
1809
  // This is unfortunately needed because ASTDeclWriter::VisitFunctionDecl
1810
  // need to access this bit but we want to avoid making ASTDeclWriter
1811
  // a friend of FunctionDeclBitfields just for this.
1812
94.9k
  bool isDeletedBit() const { return FunctionDeclBits.IsDeleted; }
1813
1814
  /// Whether an ODRHash has been stored.
1815
103k
  bool hasODRHash() const { return FunctionDeclBits.HasODRHash; }
1816
1817
  /// State that an ODRHash has been stored.
1818
8.37M
  void setHasODRHash(bool B = true) { FunctionDeclBits.HasODRHash = B; }
1819
1820
protected:
1821
  FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1822
               const DeclarationNameInfo &NameInfo, QualType T,
1823
               TypeSourceInfo *TInfo, StorageClass S, bool isInlineSpecified,
1824
               bool isConstexprSpecified);
1825
1826
  using redeclarable_base = Redeclarable<FunctionDecl>;
1827
1828
1.99M
  FunctionDecl *getNextRedeclarationImpl() override {
1829
1.99M
    return getNextRedeclaration();
1830
1.99M
  }
1831
1832
3.81M
  FunctionDecl *getPreviousDeclImpl() override {
1833
3.81M
    return getPreviousDecl();
1834
3.81M
  }
1835
1836
25.0M
  FunctionDecl *getMostRecentDeclImpl() override {
1837
25.0M
    return getMostRecentDecl();
1838
25.0M
  }
1839
1840
public:
1841
  friend class ASTDeclReader;
1842
  friend class ASTDeclWriter;
1843
1844
  using redecl_range = redeclarable_base::redecl_range;
1845
  using redecl_iterator = redeclarable_base::redecl_iterator;
1846
1847
  using redeclarable_base::redecls_begin;
1848
  using redeclarable_base::redecls_end;
1849
  using redeclarable_base::redecls;
1850
  using redeclarable_base::getPreviousDecl;
1851
  using redeclarable_base::getMostRecentDecl;
1852
  using redeclarable_base::isFirstDecl;
1853
1854
  static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
1855
                              SourceLocation StartLoc, SourceLocation NLoc,
1856
                              DeclarationName N, QualType T,
1857
                              TypeSourceInfo *TInfo,
1858
                              StorageClass SC,
1859
                              bool isInlineSpecified = false,
1860
                              bool hasWrittenPrototype = true,
1861
511k
                              bool isConstexprSpecified = false) {
1862
511k
    DeclarationNameInfo NameInfo(N, NLoc);
1863
511k
    return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo,
1864
511k
                                SC,
1865
511k
                                isInlineSpecified, hasWrittenPrototype,
1866
511k
                                isConstexprSpecified);
1867
511k
  }
1868
1869
  static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
1870
                              SourceLocation StartLoc,
1871
                              const DeclarationNameInfo &NameInfo,
1872
                              QualType T, TypeSourceInfo *TInfo,
1873
                              StorageClass SC,
1874
                              bool isInlineSpecified,
1875
                              bool hasWrittenPrototype,
1876
                              bool isConstexprSpecified = false);
1877
1878
  static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1879
1880
1.74M
  DeclarationNameInfo getNameInfo() const {
1881
1.74M
    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
1882
1.74M
  }
1883
1884
  void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
1885
                            bool Qualified) const override;
1886
1887
7.20M
  void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
1888
1889
  SourceRange getSourceRange() const override LLVM_READONLY;
1890
1891
  // Function definitions.
1892
  //
1893
  // A function declaration may be:
1894
  // - a non defining declaration,
1895
  // - a definition. A function may be defined because:
1896
  //   - it has a body, or will have it in the case of late parsing.
1897
  //   - it has an uninstantiated body. The body does not exist because the
1898
  //     function is not used yet, but the declaration is considered a
1899
  //     definition and does not allow other definition of this function.
1900
  //   - it does not have a user specified body, but it does not allow
1901
  //     redefinition, because it is deleted/defaulted or is defined through
1902
  //     some other mechanism (alias, ifunc).
1903
1904
  /// Returns true if the function has a body.
1905
  ///
1906
  /// The function body might be in any of the (re-)declarations of this
1907
  /// function. The variant that accepts a FunctionDecl pointer will set that
1908
  /// function declaration to the actual declaration containing the body (if
1909
  /// there is one).
1910
  bool hasBody(const FunctionDecl *&Definition) const;
1911
1912
876k
  bool hasBody() const override {
1913
876k
    const FunctionDecl* Definition;
1914
876k
    return hasBody(Definition);
1915
876k
  }
1916
1917
  /// Returns whether the function has a trivial body that does not require any
1918
  /// specific codegen.
1919
  bool hasTrivialBody() const;
1920
1921
  /// Returns true if the function has a definition that does not need to be
1922
  /// instantiated.
1923
  ///
1924
  /// The variant that accepts a FunctionDecl pointer will set that function
1925
  /// declaration to the declaration that is a definition (if there is one).
1926
  bool isDefined(const FunctionDecl *&Definition) const;
1927
1928
3.48M
  virtual bool isDefined() const {
1929
3.48M
    const FunctionDecl* Definition;
1930
3.48M
    return isDefined(Definition);
1931
3.48M
  }
1932
1933
  /// Get the definition for this declaration.
1934
4.44M
  FunctionDecl *getDefinition() {
1935
4.44M
    const FunctionDecl *Definition;
1936
4.44M
    if (isDefined(Definition))
1937
4.20M
      return const_cast<FunctionDecl *>(Definition);
1938
243k
    return nullptr;
1939
243k
  }
1940
428k
  const FunctionDecl *getDefinition() const {
1941
428k
    return const_cast<FunctionDecl *>(this)->getDefinition();
1942
428k
  }
1943
1944
  /// Retrieve the body (definition) of the function. The function body might be
1945
  /// in any of the (re-)declarations of this function. The variant that accepts
1946
  /// a FunctionDecl pointer will set that function declaration to the actual
1947
  /// declaration containing the body (if there is one).
1948
  /// NOTE: For checking if there is a body, use hasBody() instead, to avoid
1949
  /// unnecessary AST de-serialization of the body.
1950
  Stmt *getBody(const FunctionDecl *&Definition) const;
1951
1952
5.43M
  Stmt *getBody() const override {
1953
5.43M
    const FunctionDecl* Definition;
1954
5.43M
    return getBody(Definition);
1955
5.43M
  }
1956
1957
  /// Returns whether this specific declaration of the function is also a
1958
  /// definition that does not contain uninstantiated body.
1959
  ///
1960
  /// This does not determine whether the function has been defined (e.g., in a
1961
  /// previous definition); for that information, use isDefined.
1962
15.1M
  bool isThisDeclarationADefinition() const {
1963
15.1M
    return isDeletedAsWritten() || 
isDefaulted()15.0M
||
Body14.8M
||
hasSkippedBody()8.42M
||
1964
15.1M
           
isLateTemplateParsed()8.42M
||
willHaveBody()8.41M
||
hasDefiningAttr()8.39M
;
1965
15.1M
  }
1966
1967
  /// Returns whether this specific declaration of the function has a body.
1968
19.8M
  bool doesThisDeclarationHaveABody() const {
1969
19.8M
    return Body || 
isLateTemplateParsed()8.21M
;
1970
19.8M
  }
1971
1972
  void setBody(Stmt *B);
1973
10.3k
  void setLazyBody(uint64_t Offset) { Body = Offset; }
1974
1975
  /// Whether this function is variadic.
1976
  bool isVariadic() const;
1977
1978
  /// Whether this function is marked as virtual explicitly.
1979
11.0M
  bool isVirtualAsWritten() const {
1980
11.0M
    return FunctionDeclBits.IsVirtualAsWritten;
1981
11.0M
  }
1982
1983
  /// State that this function is marked as virtual explicitly.
1984
8.41M
  void setVirtualAsWritten(bool V) { FunctionDeclBits.IsVirtualAsWritten = V; }
1985
1986
  /// Whether this virtual function is pure, i.e. makes the containing class
1987
  /// abstract.
1988
12.0M
  bool isPure() const { return FunctionDeclBits.IsPure; }
1989
  void setPure(bool P = true);
1990
1991
  /// Whether this templated function will be late parsed.
1992
19.1M
  bool isLateTemplateParsed() const {
1993
19.1M
    return FunctionDeclBits.IsLateTemplateParsed;
1994
19.1M
  }
1995
1996
  /// State that this templated function will be late parsed.
1997
8.27M
  void setLateTemplateParsed(bool ILT = true) {
1998
8.27M
    FunctionDeclBits.IsLateTemplateParsed = ILT;
1999
8.27M
  }
2000
2001
  /// Whether this function is "trivial" in some specialized C++ senses.
2002
  /// Can only be true for default constructors, copy constructors,
2003
  /// copy assignment operators, and destructors.  Not meaningful until
2004
  /// the class has been fully built by Sema.
2005
2.39M
  bool isTrivial() const { return FunctionDeclBits.IsTrivial; }
2006
9.09M
  void setTrivial(bool IT) { FunctionDeclBits.IsTrivial = IT; }
2007
2008
795k
  bool isTrivialForCall() const { return FunctionDeclBits.IsTrivialForCall; }
2009
8.78M
  void setTrivialForCall(bool IT) { FunctionDeclBits.IsTrivialForCall = IT; }
2010
2011
  /// Whether this function is defaulted per C++0x. Only valid for
2012
  /// special member functions.
2013
35.9M
  bool isDefaulted() const { return FunctionDeclBits.IsDefaulted; }
2014
8.87M
  void setDefaulted(bool D = true) { FunctionDeclBits.IsDefaulted = D; }
2015
2016
  /// Whether this function is explicitly defaulted per C++0x. Only valid
2017
  /// for special member functions.
2018
5.71M
  bool isExplicitlyDefaulted() const {
2019
5.71M
    return FunctionDeclBits.IsExplicitlyDefaulted;
2020
5.71M
  }
2021
2022
  /// State that this function is explicitly defaulted per C++0x. Only valid
2023
  /// for special member functions.
2024
8.29M
  void setExplicitlyDefaulted(bool ED = true) {
2025
8.29M
    FunctionDeclBits.IsExplicitlyDefaulted = ED;
2026
8.29M
  }
2027
2028
  /// Whether falling off this function implicitly returns null/zero.
2029
  /// If a more specific implicit return value is required, front-ends
2030
  /// should synthesize the appropriate return statements.
2031
3.77M
  bool hasImplicitReturnZero() const {
2032
3.77M
    return FunctionDeclBits.HasImplicitReturnZero;
2033
3.77M
  }
2034
2035
  /// State that falling off this function implicitly returns null/zero.
2036
  /// If a more specific implicit return value is required, front-ends
2037
  /// should synthesize the appropriate return statements.
2038
8.28M
  void setHasImplicitReturnZero(bool IRZ) {
2039
8.28M
    FunctionDeclBits.HasImplicitReturnZero = IRZ;
2040
8.28M
  }
2041
2042
  /// Whether this function has a prototype, either because one
2043
  /// was explicitly written or because it was "inherited" by merging
2044
  /// a declaration without a prototype with a declaration that has a
2045
  /// prototype.
2046
1.34M
  bool hasPrototype() const {
2047
1.34M
    return hasWrittenPrototype() || 
hasInheritedPrototype()118k
;
2048
1.34M
  }
2049
2050
  /// Whether this function has a written prototype.
2051
1.72M
  bool hasWrittenPrototype() const {
2052
1.72M
    return FunctionDeclBits.HasWrittenPrototype;
2053
1.72M
  }
2054
2055
  /// State that this function has a written prototype.
2056
12.7M
  void setHasWrittenPrototype(bool P = true) {
2057
12.7M
    FunctionDeclBits.HasWrittenPrototype = P;
2058
12.7M
  }
2059
2060
  /// Whether this function inherited its prototype from a
2061
  /// previous declaration.
2062
215k
  bool hasInheritedPrototype() const {
2063
215k
    return FunctionDeclBits.HasInheritedPrototype;
2064
215k
  }
2065
2066
  /// State that this function inherited its prototype from a
2067
  /// previous declaration.
2068
8.27M
  void setHasInheritedPrototype(bool P = true) {
2069
8.27M
    FunctionDeclBits.HasInheritedPrototype = P;
2070
8.27M
  }
2071
2072
  /// Whether this is a (C++11) constexpr function or constexpr constructor.
2073
11.1M
  bool isConstexpr() const { return FunctionDeclBits.IsConstexpr; }
2074
8.29M
  void setConstexpr(bool IC) { FunctionDeclBits.IsConstexpr = IC; }
2075
2076
  /// Whether the instantiation of this function is pending.
2077
  /// This bit is set when the decision to instantiate this function is made
2078
  /// and unset if and when the function body is created. That leaves out
2079
  /// cases where instantiation did not happen because the template definition
2080
  /// was not seen in this TU. This bit remains set in those cases, under the
2081
  /// assumption that the instantiation will happen in some other TU.
2082
0
  bool instantiationIsPending() const {
2083
0
    return FunctionDeclBits.InstantiationIsPending;
2084
0
  }
2085
2086
  /// State that the instantiation of this function is pending.
2087
  /// (see instantiationIsPending)
2088
8.81M
  void setInstantiationIsPending(bool IC) {
2089
8.81M
    FunctionDeclBits.InstantiationIsPending = IC;
2090
8.81M
  }
2091
2092
  /// Indicates the function uses __try.
2093
541k
  bool usesSEHTry() const { return FunctionDeclBits.UsesSEHTry; }
2094
8.27M
  void setUsesSEHTry(bool UST) { FunctionDeclBits.UsesSEHTry = UST; }
2095
2096
  /// Whether this function has been deleted.
2097
  ///
2098
  /// A function that is "deleted" (via the C++0x "= delete" syntax)
2099
  /// acts like a normal function, except that it cannot actually be
2100
  /// called or have its address taken. Deleted functions are
2101
  /// typically used in C++ overload resolution to attract arguments
2102
  /// whose type or lvalue/rvalue-ness would permit the use of a
2103
  /// different overload that would behave incorrectly. For example,
2104
  /// one might use deleted functions to ban implicit conversion from
2105
  /// a floating-point number to an Integer type:
2106
  ///
2107
  /// @code
2108
  /// struct Integer {
2109
  ///   Integer(long); // construct from a long
2110
  ///   Integer(double) = delete; // no construction from float or double
2111
  ///   Integer(long double) = delete; // no construction from long double
2112
  /// };
2113
  /// @endcode
2114
  // If a function is deleted, its first declaration must be.
2115
23.2M
  bool isDeleted() const {
2116
23.2M
    return getCanonicalDecl()->FunctionDeclBits.IsDeleted;
2117
23.2M
  }
2118
2119
16.6M
  bool isDeletedAsWritten() const {
2120
16.6M
    return FunctionDeclBits.IsDeleted && 
!isDefaulted()103k
;
2121
16.6M
  }
2122
2123
8.36M
  void setDeletedAsWritten(bool D = true) { FunctionDeclBits.IsDeleted = D; }
2124
2125
  /// Determines whether this function is "main", which is the
2126
  /// entry point into an executable program.
2127
  bool isMain() const;
2128
2129
  /// Determines whether this function is a MSVCRT user defined entry
2130
  /// point.
2131
  bool isMSVCRTEntryPoint() const;
2132
2133
  /// Determines whether this operator new or delete is one
2134
  /// of the reserved global placement operators:
2135
  ///    void *operator new(size_t, void *);
2136
  ///    void *operator new[](size_t, void *);
2137
  ///    void operator delete(void *, void *);
2138
  ///    void operator delete[](void *, void *);
2139
  /// These functions have special behavior under [new.delete.placement]:
2140
  ///    These functions are reserved, a C++ program may not define
2141
  ///    functions that displace the versions in the Standard C++ library.
2142
  ///    The provisions of [basic.stc.dynamic] do not apply to these
2143
  ///    reserved placement forms of operator new and operator delete.
2144
  ///
2145
  /// This function must be an allocation or deallocation function.
2146
  bool isReservedGlobalPlacementOperator() const;
2147
2148
  /// Determines whether this function is one of the replaceable
2149
  /// global allocation functions:
2150
  ///    void *operator new(size_t);
2151
  ///    void *operator new(size_t, const std::nothrow_t &) noexcept;
2152
  ///    void *operator new[](size_t);
2153
  ///    void *operator new[](size_t, const std::nothrow_t &) noexcept;
2154
  ///    void operator delete(void *) noexcept;
2155
  ///    void operator delete(void *, std::size_t) noexcept;      [C++1y]
2156
  ///    void operator delete(void *, const std::nothrow_t &) noexcept;
2157
  ///    void operator delete[](void *) noexcept;
2158
  ///    void operator delete[](void *, std::size_t) noexcept;    [C++1y]
2159
  ///    void operator delete[](void *, const std::nothrow_t &) noexcept;
2160
  /// These functions have special behavior under C++1y [expr.new]:
2161
  ///    An implementation is allowed to omit a call to a replaceable global
2162
  ///    allocation function. [...]
2163
  ///
2164
  /// If this function is an aligned allocation/deallocation function, return
2165
  /// true through IsAligned.
2166
  bool isReplaceableGlobalAllocationFunction(bool *IsAligned = nullptr) const;
2167
2168
  /// Determine whether this is a destroying operator delete.
2169
  bool isDestroyingOperatorDelete() const;
2170
2171
  /// Compute the language linkage.
2172
  LanguageLinkage getLanguageLinkage() const;
2173
2174
  /// Determines whether this function is a function with
2175
  /// external, C linkage.
2176
  bool isExternC() const;
2177
2178
  /// Determines whether this function's context is, or is nested within,
2179
  /// a C++ extern "C" linkage spec.
2180
  bool isInExternCContext() const;
2181
2182
  /// Determines whether this function's context is, or is nested within,
2183
  /// a C++ extern "C++" linkage spec.
2184
  bool isInExternCXXContext() const;
2185
2186
  /// Determines whether this is a global function.
2187
  bool isGlobal() const;
2188
2189
  /// Determines whether this function is known to be 'noreturn', through
2190
  /// an attribute on its declaration or its type.
2191
  bool isNoReturn() const;
2192
2193
  /// True if the function was a definition but its body was skipped.
2194
8.81M
  bool hasSkippedBody() const { return FunctionDeclBits.HasSkippedBody; }
2195
8.27M
  void setHasSkippedBody(bool Skipped = true) {
2196
8.27M
    FunctionDeclBits.HasSkippedBody = Skipped;
2197
8.27M
  }
2198
2199
  /// True if this function will eventually have a body, once it's fully parsed.
2200
11.8M
  bool willHaveBody() const { return FunctionDeclBits.WillHaveBody; }
2201
15.7M
  void setWillHaveBody(bool V = true) { FunctionDeclBits.WillHaveBody = V; }
2202
2203
  /// True if this function is considered a multiversioned function.
2204
29.7M
  bool isMultiVersion() const {
2205
29.7M
    return getCanonicalDecl()->FunctionDeclBits.IsMultiVersion;
2206
29.7M
  }
2207
2208
  /// Sets the multiversion state for this declaration and all of its
2209
  /// redeclarations.
2210
8.27M
  void setIsMultiVersion(bool V = true) {
2211
8.27M
    getCanonicalDecl()->FunctionDeclBits.IsMultiVersion = V;
2212
8.27M
  }
2213
2214
  /// True if this function is a multiversioned dispatch function as a part of
2215
  /// the cpu_specific/cpu_dispatch functionality.
2216
  bool isCPUDispatchMultiVersion() const;
2217
  /// True if this function is a multiversioned processor specific function as a
2218
  /// part of the cpu_specific/cpu_dispatch functionality.
2219
  bool isCPUSpecificMultiVersion() const;
2220
2221
  void setPreviousDeclaration(FunctionDecl * PrevDecl);
2222
2223
  FunctionDecl *getCanonicalDecl() override;
2224
70.4M
  const FunctionDecl *getCanonicalDecl() const {
2225
70.4M
    return const_cast<FunctionDecl*>(this)->getCanonicalDecl();
2226
70.4M
  }
2227
2228
  unsigned getBuiltinID() const;
2229
2230
  // ArrayRef interface to parameters.
2231
22.9M
  ArrayRef<ParmVarDecl *> parameters() const {
2232
22.9M
    return {ParamInfo, getNumParams()};
2233
22.9M
  }
2234
18.5M
  MutableArrayRef<ParmVarDecl *> parameters() {
2235
18.5M
    return {ParamInfo, getNumParams()};
2236
18.5M
  }
2237
2238
  // Iterator access to formal parameters.
2239
  using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator;
2240
  using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator;
2241
2242
0
  bool param_empty() const { return parameters().empty(); }
2243
963
  param_iterator param_begin() { return parameters().begin(); }
2244
0
  param_iterator param_end() { return parameters().end(); }
2245
977k
  param_const_iterator param_begin() const { return parameters().begin(); }
2246
530k
  param_const_iterator param_end() const { return parameters().end(); }
2247
198k
  size_t param_size() const { return parameters().size(); }
2248
2249
  /// Return the number of parameters this function must have based on its
2250
  /// FunctionType.  This is the length of the ParamInfo array after it has been
2251
  /// created.
2252
  unsigned getNumParams() const;
2253
2254
23.0M
  const ParmVarDecl *getParamDecl(unsigned i) const {
2255
23.0M
    assert(i < getNumParams() && "Illegal param #");
2256
23.0M
    return ParamInfo[i];
2257
23.0M
  }
2258
17.9M
  ParmVarDecl *getParamDecl(unsigned i) {
2259
17.9M
    assert(i < getNumParams() && "Illegal param #");
2260
17.9M
    return ParamInfo[i];
2261
17.9M
  }
2262
8.04M
  void setParams(ArrayRef<ParmVarDecl *> NewParamInfo) {
2263
8.04M
    setParams(getASTContext(), NewParamInfo);
2264
8.04M
  }
2265
2266
  /// Returns the minimum number of arguments needed to call this function. This
2267
  /// may be fewer than the number of function parameters, if some of the
2268
  /// parameters have default arguments (in C++).
2269
  unsigned getMinRequiredArguments() const;
2270
2271
23.5M
  QualType getReturnType() const {
2272
23.5M
    return getType()->castAs<FunctionType>()->getReturnType();
2273
23.5M
  }
2274
2275
  /// Attempt to compute an informative source range covering the
2276
  /// function return type. This may omit qualifiers and other information with
2277
  /// limited representation in the AST.
2278
  SourceRange getReturnTypeSourceRange() const;
2279
2280
  /// Get the declared return type, which may differ from the actual return
2281
  /// type if the return type is deduced.
2282
789k
  QualType getDeclaredReturnType() const {
2283
789k
    auto *TSI = getTypeSourceInfo();
2284
789k
    QualType T = TSI ? 
TSI->getType()787k
:
getType()2.13k
;
2285
789k
    return T->castAs<FunctionType>()->getReturnType();
2286
789k
  }
2287
2288
  /// Attempt to compute an informative source range covering the
2289
  /// function exception specification, if any.
2290
  SourceRange getExceptionSpecSourceRange() const;
2291
2292
  /// Determine the type of an expression that calls this function.
2293
4.26k
  QualType getCallResultType() const {
2294
4.26k
    return getType()->castAs<FunctionType>()->getCallResultType(
2295
4.26k
        getASTContext());
2296
4.26k
  }
2297
2298
  /// Returns the WarnUnusedResultAttr that is either declared on this
2299
  /// function, or its return type declaration.
2300
  const Attr *getUnusedResultAttr() const;
2301
2302
  /// Returns true if this function or its return type has the
2303
  /// warn_unused_result attribute.
2304
778k
  bool hasUnusedResultAttr() const { return getUnusedResultAttr() != nullptr; }
2305
2306
  /// Returns the storage class as written in the source. For the
2307
  /// computed linkage of symbol, see getLinkage.
2308
41.2M
  StorageClass getStorageClass() const {
2309
41.2M
    return static_cast<StorageClass>(FunctionDeclBits.SClass);
2310
41.2M
  }
2311
2312
  /// Sets the storage class as written in the source.
2313
8.27M
  void setStorageClass(StorageClass SClass) {
2314
8.27M
    FunctionDeclBits.SClass = SClass;
2315
8.27M
  }
2316
2317
  /// Determine whether the "inline" keyword was specified for this
2318
  /// function.
2319
3.18M
  bool isInlineSpecified() const { return FunctionDeclBits.IsInlineSpecified; }
2320
2321
  /// Set whether the "inline" keyword was specified for this function.
2322
8.28M
  void setInlineSpecified(bool I) {
2323
8.28M
    FunctionDeclBits.IsInlineSpecified = I;
2324
8.28M
    FunctionDeclBits.IsInline = I;
2325
8.28M
  }
2326
2327
  /// Flag that this function is implicitly inline.
2328
2.71M
  void setImplicitlyInline(bool I = true) { FunctionDeclBits.IsInline = I; }
2329
2330
  /// Determine whether this function should be inlined, because it is
2331
  /// either marked "inline" or "constexpr" or is a member function of a class
2332
  /// that was defined in the class body.
2333
22.2M
  bool isInlined() const { return FunctionDeclBits.IsInline; }
2334
2335
  /// Whether this function is marked as explicit explicitly.
2336
6.15M
  bool isExplicitSpecified() const {
2337
6.15M
    return FunctionDeclBits.IsExplicitSpecified;
2338
6.15M
  }
2339
2340
  /// State that this function is marked as explicit explicitly.
2341
9.18M
  void setExplicitSpecified(bool ExpSpec = true) {
2342
9.18M
    FunctionDeclBits.IsExplicitSpecified = ExpSpec;
2343
9.18M
  }
2344
2345
  bool isInlineDefinitionExternallyVisible() const;
2346
2347
  bool isMSExternInline() const;
2348
2349
  bool doesDeclarationForceExternallyVisibleDefinition() const;
2350
2351
  /// Whether this function declaration represents an C++ overloaded
2352
  /// operator, e.g., "operator+".
2353
10.1M
  bool isOverloadedOperator() const {
2354
10.1M
    return getOverloadedOperator() != OO_None;
2355
10.1M
  }
2356
2357
  OverloadedOperatorKind getOverloadedOperator() const;
2358
2359
  const IdentifierInfo *getLiteralIdentifier() const;
2360
2361
  /// If this function is an instantiation of a member function
2362
  /// of a class template specialization, retrieves the function from
2363
  /// which it was instantiated.
2364
  ///
2365
  /// This routine will return non-NULL for (non-templated) member
2366
  /// functions of class templates and for instantiations of function
2367
  /// templates. For example, given:
2368
  ///
2369
  /// \code
2370
  /// template<typename T>
2371
  /// struct X {
2372
  ///   void f(T);
2373
  /// };
2374
  /// \endcode
2375
  ///
2376
  /// The declaration for X<int>::f is a (non-templated) FunctionDecl
2377
  /// whose parent is the class template specialization X<int>. For
2378
  /// this declaration, getInstantiatedFromFunction() will return
2379
  /// the FunctionDecl X<T>::A. When a complete definition of
2380
  /// X<int>::A is required, it will be instantiated from the
2381
  /// declaration returned by getInstantiatedFromMemberFunction().
2382
  FunctionDecl *getInstantiatedFromMemberFunction() const;
2383
2384
  /// What kind of templated function this is.
2385
  TemplatedKind getTemplatedKind() const;
2386
2387
  /// If this function is an instantiation of a member function of a
2388
  /// class template specialization, retrieves the member specialization
2389
  /// information.
2390
  MemberSpecializationInfo *getMemberSpecializationInfo() const;
2391
2392
  /// Specify that this record is an instantiation of the
2393
  /// member function FD.
2394
  void setInstantiationOfMemberFunction(FunctionDecl *FD,
2395
1.13M
                                        TemplateSpecializationKind TSK) {
2396
1.13M
    setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
2397
1.13M
  }
2398
2399
  /// Retrieves the function template that is described by this
2400
  /// function declaration.
2401
  ///
2402
  /// Every function template is represented as a FunctionTemplateDecl
2403
  /// and a FunctionDecl (or something derived from FunctionDecl). The
2404
  /// former contains template properties (such as the template
2405
  /// parameter lists) while the latter contains the actual
2406
  /// description of the template's
2407
  /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
2408
  /// FunctionDecl that describes the function template,
2409
  /// getDescribedFunctionTemplate() retrieves the
2410
  /// FunctionTemplateDecl from a FunctionDecl.
2411
  FunctionTemplateDecl *getDescribedFunctionTemplate() const;
2412
2413
  void setDescribedFunctionTemplate(FunctionTemplateDecl *Template);
2414
2415
  /// Determine whether this function is a function template
2416
  /// specialization.
2417
17.6M
  bool isFunctionTemplateSpecialization() const {
2418
17.6M
    return getPrimaryTemplate() != nullptr;
2419
17.6M
  }
2420
2421
  /// Retrieve the class scope template pattern that this function
2422
  ///  template specialization is instantiated from.
2423
  FunctionDecl *getClassScopeSpecializationPattern() const;
2424
2425
  /// If this function is actually a function template specialization,
2426
  /// retrieve information about this function template specialization.
2427
  /// Otherwise, returns NULL.
2428
  FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const;
2429
2430
  /// Determines whether this function is a function template
2431
  /// specialization or a member of a class template specialization that can
2432
  /// be implicitly instantiated.
2433
  bool isImplicitlyInstantiable() const;
2434
2435
  /// Determines if the given function was instantiated from a
2436
  /// function template.
2437
  bool isTemplateInstantiation() const;
2438
2439
  /// Retrieve the function declaration from which this function could
2440
  /// be instantiated, if it is an instantiation (rather than a non-template
2441
  /// or a specialization, for example).
2442
  FunctionDecl *getTemplateInstantiationPattern() const;
2443
2444
  /// Retrieve the primary template that this function template
2445
  /// specialization either specializes or was instantiated from.
2446
  ///
2447
  /// If this function declaration is not a function template specialization,
2448
  /// returns NULL.
2449
  FunctionTemplateDecl *getPrimaryTemplate() const;
2450
2451
  /// Retrieve the template arguments used to produce this function
2452
  /// template specialization from the primary template.
2453
  ///
2454
  /// If this function declaration is not a function template specialization,
2455
  /// returns NULL.
2456
  const TemplateArgumentList *getTemplateSpecializationArgs() const;
2457
2458
  /// Retrieve the template argument list as written in the sources,
2459
  /// if any.
2460
  ///
2461
  /// If this function declaration is not a function template specialization
2462
  /// or if it had no explicit template argument list, returns NULL.
2463
  /// Note that it an explicit template argument list may be written empty,
2464
  /// e.g., template<> void foo<>(char* s);
2465
  const ASTTemplateArgumentListInfo*
2466
  getTemplateSpecializationArgsAsWritten() const;
2467
2468
  /// Specify that this function declaration is actually a function
2469
  /// template specialization.
2470
  ///
2471
  /// \param Template the function template that this function template
2472
  /// specialization specializes.
2473
  ///
2474
  /// \param TemplateArgs the template arguments that produced this
2475
  /// function template specialization from the template.
2476
  ///
2477
  /// \param InsertPos If non-NULL, the position in the function template
2478
  /// specialization set where the function template specialization data will
2479
  /// be inserted.
2480
  ///
2481
  /// \param TSK the kind of template specialization this is.
2482
  ///
2483
  /// \param TemplateArgsAsWritten location info of template arguments.
2484
  ///
2485
  /// \param PointOfInstantiation point at which the function template
2486
  /// specialization was first instantiated.
2487
  void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template,
2488
                const TemplateArgumentList *TemplateArgs,
2489
                void *InsertPos,
2490
                TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
2491
                const TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
2492
275k
                SourceLocation PointOfInstantiation = SourceLocation()) {
2493
275k
    setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
2494
275k
                                      InsertPos, TSK, TemplateArgsAsWritten,
2495
275k
                                      PointOfInstantiation);
2496
275k
  }
2497
2498
  /// Specifies that this function declaration is actually a
2499
  /// dependent function template specialization.
2500
  void setDependentTemplateSpecialization(ASTContext &Context,
2501
                             const UnresolvedSetImpl &Templates,
2502
                      const TemplateArgumentListInfo &TemplateArgs);
2503
2504
  DependentFunctionTemplateSpecializationInfo *
2505
  getDependentSpecializationInfo() const;
2506
2507
  /// Determine what kind of template instantiation this function
2508
  /// represents.
2509
  TemplateSpecializationKind getTemplateSpecializationKind() const;
2510
2511
  /// Determine what kind of template instantiation this function
2512
  /// represents.
2513
  void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
2514
                        SourceLocation PointOfInstantiation = SourceLocation());
2515
2516
  /// Retrieve the (first) point of instantiation of a function template
2517
  /// specialization or a member of a class template specialization.
2518
  ///
2519
  /// \returns the first point of instantiation, if this function was
2520
  /// instantiated from a template; otherwise, returns an invalid source
2521
  /// location.
2522
  SourceLocation getPointOfInstantiation() const;
2523
2524
  /// Determine whether this is or was instantiated from an out-of-line
2525
  /// definition of a member function.
2526
  bool isOutOfLine() const override;
2527
2528
  /// Identify a memory copying or setting function.
2529
  /// If the given function is a memory copy or setting function, returns
2530
  /// the corresponding Builtin ID. If the function is not a memory function,
2531
  /// returns 0.
2532
  unsigned getMemoryFunctionKind() const;
2533
2534
  /// Returns ODRHash of the function.  This value is calculated and
2535
  /// stored on first call, then the stored value returned on the other calls.
2536
  unsigned getODRHash();
2537
2538
  /// Returns cached ODRHash of the function.  This must have been previously
2539
  /// computed and stored.
2540
  unsigned getODRHash() const;
2541
2542
  // Implement isa/cast/dyncast/etc.
2543
390M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2544
562M
  static bool classofKind(Kind K) {
2545
562M
    return K >= firstFunction && 
K <= lastFunction329M
;
2546
562M
  }
2547
0
  static DeclContext *castToDeclContext(const FunctionDecl *D) {
2548
0
    return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
2549
0
  }
2550
0
  static FunctionDecl *castFromDeclContext(const DeclContext *DC) {
2551
0
    return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
2552
0
  }
2553
};
2554
2555
/// Represents a member of a struct/union/class.
2556
class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
2557
  unsigned BitField : 1;
2558
  unsigned Mutable : 1;
2559
  mutable unsigned CachedFieldIndex : 30;
2560
2561
  /// The kinds of value we can store in InitializerOrBitWidth.
2562
  ///
2563
  /// Note that this is compatible with InClassInitStyle except for
2564
  /// ISK_CapturedVLAType.
2565
  enum InitStorageKind {
2566
    /// If the pointer is null, there's nothing special.  Otherwise,
2567
    /// this is a bitfield and the pointer is the Expr* storing the
2568
    /// bit-width.
2569
    ISK_NoInit = (unsigned) ICIS_NoInit,
2570
2571
    /// The pointer is an (optional due to delayed parsing) Expr*
2572
    /// holding the copy-initializer.
2573
    ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
2574
2575
    /// The pointer is an (optional due to delayed parsing) Expr*
2576
    /// holding the list-initializer.
2577
    ISK_InClassListInit = (unsigned) ICIS_ListInit,
2578
2579
    /// The pointer is a VariableArrayType* that's been captured;
2580
    /// the enclosing context is a lambda or captured statement.
2581
    ISK_CapturedVLAType,
2582
  };
2583
2584
  /// If this is a bitfield with a default member initializer, this
2585
  /// structure is used to represent the two expressions.
2586
  struct InitAndBitWidth {
2587
    Expr *Init;
2588
    Expr *BitWidth;
2589
  };
2590
2591
  /// Storage for either the bit-width, the in-class initializer, or
2592
  /// both (via InitAndBitWidth), or the captured variable length array bound.
2593
  ///
2594
  /// If the storage kind is ISK_InClassCopyInit or
2595
  /// ISK_InClassListInit, but the initializer is null, then this
2596
  /// field has an in-class initializer that has not yet been parsed
2597
  /// and attached.
2598
  // FIXME: Tail-allocate this to reduce the size of FieldDecl in the
2599
  // overwhelmingly common case that we have none of these things.
2600
  llvm::PointerIntPair<void *, 2, InitStorageKind> InitStorage;
2601
2602
protected:
2603
  FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
2604
            SourceLocation IdLoc, IdentifierInfo *Id,
2605
            QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
2606
            InClassInitStyle InitStyle)
2607
    : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc),
2608
      BitField(false), Mutable(Mutable), CachedFieldIndex(0),
2609
2.86M
      InitStorage(nullptr, (InitStorageKind) InitStyle) {
2610
2.86M
    if (BW)
2611
37.7k
      setBitWidth(BW);
2612
2.86M
  }
2613
2614
public:
2615
  friend class ASTDeclReader;
2616
  friend class ASTDeclWriter;
2617
2618
  static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
2619
                           SourceLocation StartLoc, SourceLocation IdLoc,
2620
                           IdentifierInfo *Id, QualType T,
2621
                           TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
2622
                           InClassInitStyle InitStyle);
2623
2624
  static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2625
2626
  /// Returns the index of this field within its record,
2627
  /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
2628
  unsigned getFieldIndex() const;
2629
2630
  /// Determines whether this field is mutable (C++ only).
2631
6.43M
  bool isMutable() const { return Mutable; }
2632
2633
  /// Determines whether this field is a bitfield.
2634
9.76M
  bool isBitField() const { return BitField; }
2635
2636
  /// Determines whether this is an unnamed bitfield.
2637
4.52M
  bool isUnnamedBitfield() const { return isBitField() && 
!getDeclName()39.4k
; }
2638
2639
  /// Determines whether this field is a
2640
  /// representative for an anonymous struct or union. Such fields are
2641
  /// unnamed and are implicitly generated by the implementation to
2642
  /// store the data for the anonymous union or struct.
2643
  bool isAnonymousStructOrUnion() const;
2644
2645
228k
  Expr *getBitWidth() const {
2646
228k
    if (!BitField)
2647
172k
      return nullptr;
2648
56.5k
    void *Ptr = InitStorage.getPointer();
2649
56.5k
    if (getInClassInitStyle())
2650
76
      return static_cast<InitAndBitWidth*>(Ptr)->BitWidth;
2651
56.5k
    return static_cast<Expr*>(Ptr);
2652
56.5k
  }
2653
2654
  unsigned getBitWidthValue(const ASTContext &Ctx) const;
2655
2656
  /// Set the bit-field width for this member.
2657
  // Note: used by some clients (i.e., do not remove it).
2658
37.9k
  void setBitWidth(Expr *Width) {
2659
37.9k
    assert(!hasCapturedVLAType() && !BitField &&
2660
37.9k
           "bit width or captured type already set");
2661
37.9k
    assert(Width && "no bit width specified");
2662
37.9k
    InitStorage.setPointer(
2663
37.9k
        InitStorage.getInt()
2664
37.9k
            ? new (getASTContext())
2665
9
                  InitAndBitWidth{getInClassInitializer(), Width}
2666
37.9k
            : 
static_cast<void*>(Width)37.9k
);
2667
37.9k
    BitField = true;
2668
37.9k
  }
2669
2670
  /// Remove the bit-field width from this member.
2671
  // Note: used by some clients (i.e., do not remove it).
2672
0
  void removeBitWidth() {
2673
0
    assert(isBitField() && "no bitfield width to remove");
2674
0
    InitStorage.setPointer(getInClassInitializer());
2675
0
    BitField = false;
2676
0
  }
2677
2678
  /// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
2679
  /// at all and instead act as a separator between contiguous runs of other
2680
  /// bit-fields.
2681
  bool isZeroLengthBitField(const ASTContext &Ctx) const;
2682
2683
  /// Get the kind of (C++11) default member initializer that this field has.
2684
6.61M
  InClassInitStyle getInClassInitStyle() const {
2685
6.61M
    InitStorageKind storageKind = InitStorage.getInt();
2686
6.61M
    return (storageKind == ISK_CapturedVLAType
2687
6.61M
              ? 
ICIS_NoInit16.6k
:
(InClassInitStyle) storageKind6.59M
);
2688
6.61M
  }
2689
2690
  /// Determine whether this member has a C++11 default member initializer.
2691
6.41M
  bool hasInClassInitializer() const {
2692
6.41M
    return getInClassInitStyle() != ICIS_NoInit;
2693
6.41M
  }
2694
2695
  /// Get the C++11 default member initializer for this member, or null if one
2696
  /// has not been set. If a valid declaration has a default member initializer,
2697
  /// but this returns null, then we have not parsed and attached it yet.
2698
23.0k
  Expr *getInClassInitializer() const {
2699
23.0k
    if (!hasInClassInitializer())
2700
8.78k
      return nullptr;
2701
14.3k
    void *Ptr = InitStorage.getPointer();
2702
14.3k
    if (BitField)
2703
99
      return static_cast<InitAndBitWidth*>(Ptr)->Init;
2704
14.2k
    return static_cast<Expr*>(Ptr);
2705
14.2k
  }
2706
2707
  /// Set the C++11 in-class initializer for this member.
2708
5.36k
  void setInClassInitializer(Expr *Init) {
2709
5.36k
    assert(hasInClassInitializer() && !getInClassInitializer());
2710
5.36k
    if (BitField)
2711
8
      static_cast<InitAndBitWidth*>(InitStorage.getPointer())->Init = Init;
2712
5.35k
    else
2713
5.35k
      InitStorage.setPointer(Init);
2714
5.36k
  }
2715
2716
  /// Remove the C++11 in-class initializer from this member.
2717
39
  void removeInClassInitializer() {
2718
39
    assert(hasInClassInitializer() && "no initializer to remove");
2719
39
    InitStorage.setPointerAndInt(getBitWidth(), ISK_NoInit);
2720
39
  }
2721
2722
  /// Determine whether this member captures the variable length array
2723
  /// type.
2724
126k
  bool hasCapturedVLAType() const {
2725
126k
    return InitStorage.getInt() == ISK_CapturedVLAType;
2726
126k
  }
2727
2728
  /// Get the captured variable length array type.
2729
24.6k
  const VariableArrayType *getCapturedVLAType() const {
2730
24.6k
    return hasCapturedVLAType() ? static_cast<const VariableArrayType *>(
2731
24.6k
                                      InitStorage.getPointer())
2732
24.6k
                                : 
nullptr0
;
2733
24.6k
  }
2734
2735
  /// Set the captured variable length array type for this field.
2736
  void setCapturedVLAType(const VariableArrayType *VLAType);
2737
2738
  /// Returns the parent of this field declaration, which
2739
  /// is the struct in which this field is defined.
2740
2.30M
  const RecordDecl *getParent() const {
2741
2.30M
    return cast<RecordDecl>(getDeclContext());
2742
2.30M
  }
2743
2744
907k
  RecordDecl *getParent() {
2745
907k
    return cast<RecordDecl>(getDeclContext());
2746
907k
  }
2747
2748
  SourceRange getSourceRange() const override LLVM_READONLY;
2749
2750
  /// Retrieves the canonical declaration of this field.
2751
5.50M
  FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
2752
3.13M
  const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
2753
2754
  // Implement isa/cast/dyncast/etc.
2755
118M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2756
118M
  static bool classofKind(Kind K) { return K >= firstField && 
K <= lastField91.6M
; }
2757
};
2758
2759
/// An instance of this object exists for each enum constant
2760
/// that is defined.  For example, in "enum X {a,b}", each of a/b are
2761
/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
2762
/// TagType for the X EnumDecl.
2763
class EnumConstantDecl : public ValueDecl, public Mergeable<EnumConstantDecl> {
2764
  Stmt *Init; // an integer constant expression
2765
  llvm::APSInt Val; // The value.
2766
2767
protected:
2768
  EnumConstantDecl(DeclContext *DC, SourceLocation L,
2769
                   IdentifierInfo *Id, QualType T, Expr *E,
2770
                   const llvm::APSInt &V)
2771
363k
    : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
2772
2773
public:
2774
  friend class StmtIteratorBase;
2775
2776
  static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC,
2777
                                  SourceLocation L, IdentifierInfo *Id,
2778
                                  QualType T, Expr *E,
2779
                                  const llvm::APSInt &V);
2780
  static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2781
2782
1.58k
  const Expr *getInitExpr() const { return (const Expr*) Init; }
2783
496k
  Expr *getInitExpr() { return (Expr*) Init; }
2784
3.07M
  const llvm::APSInt &getInitVal() const { return Val; }
2785
2786
62.4k
  void setInitExpr(Expr *E) { Init = (Stmt*) E; }
2787
295k
  void setInitVal(const llvm::APSInt &V) { Val = V; }
2788
2789
  SourceRange getSourceRange() const override LLVM_READONLY;
2790
2791
  /// Retrieves the canonical declaration of this enumerator.
2792
641k
  EnumConstantDecl *getCanonicalDecl() override { return getFirstDecl(); }
2793
0
  const EnumConstantDecl *getCanonicalDecl() const { return getFirstDecl(); }
2794
2795
  // Implement isa/cast/dyncast/etc.
2796
50.0M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2797
50.0M
  static bool classofKind(Kind K) { return K == EnumConstant; }
2798
};
2799
2800
/// Represents a field injected from an anonymous union/struct into the parent
2801
/// scope. These are always implicit.
2802
class IndirectFieldDecl : public ValueDecl,
2803
                          public Mergeable<IndirectFieldDecl> {
2804
  NamedDecl **Chaining;
2805
  unsigned ChainingSize;
2806
2807
  IndirectFieldDecl(ASTContext &C, DeclContext *DC, SourceLocation L,
2808
                    DeclarationName N, QualType T,
2809
                    MutableArrayRef<NamedDecl *> CH);
2810
2811
  void anchor() override;
2812
2813
public:
2814
  friend class ASTDeclReader;
2815
2816
  static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC,
2817
                                   SourceLocation L, IdentifierInfo *Id,
2818
                                   QualType T, llvm::MutableArrayRef<NamedDecl *> CH);
2819
2820
  static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2821
2822
  using chain_iterator = ArrayRef<NamedDecl *>::const_iterator;
2823
2824
90.3k
  ArrayRef<NamedDecl *> chain() const {
2825
90.3k
    return llvm::makeArrayRef(Chaining, ChainingSize);
2826
90.3k
  }
2827
12.4k
  chain_iterator chain_begin() const { return chain().begin(); }
2828
12.3k
  chain_iterator chain_end() const { return chain().end(); }
2829
2830
7.40k
  unsigned getChainingSize() const { return ChainingSize; }
2831
2832
34.2k
  FieldDecl *getAnonField() const {
2833
34.2k
    assert(chain().size() >= 2);
2834
34.2k
    return cast<FieldDecl>(chain().back());
2835
34.2k
  }
2836
2837
12.0k
  VarDecl *getVarDecl() const {
2838
12.0k
    assert(chain().size() >= 2);
2839
12.0k
    return dyn_cast<VarDecl>(chain().front());
2840
12.0k
  }
2841
2842
22.2k
  IndirectFieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
2843
0
  const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
2844
2845
  // Implement isa/cast/dyncast/etc.
2846
62.5M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2847
62.5M
  static bool classofKind(Kind K) { return K == IndirectField; }
2848
};
2849
2850
/// Represents a declaration of a type.
2851
class TypeDecl : public NamedDecl {
2852
  friend class ASTContext;
2853
2854
  /// This indicates the Type object that represents
2855
  /// this TypeDecl.  It is a cache maintained by
2856
  /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
2857
  /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
2858
  mutable const Type *TypeForDecl = nullptr;
2859
2860
  /// The start of the source range for this declaration.
2861
  SourceLocation LocStart;
2862
2863
  void anchor() override;
2864
2865
protected:
2866
  TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
2867
           SourceLocation StartL = SourceLocation())
2868
9.11M
    : NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
2869
2870
public:
2871
  // Low-level accessor. If you just want the type defined by this node,
2872
  // check out ASTContext::getTypeDeclType or one of
2873
  // ASTContext::getTypedefType, ASTContext::getRecordType, etc. if you
2874
  // already know the specific kind of node this is.
2875
33.7M
  const Type *getTypeForDecl() const { return TypeForDecl; }
2876
2.40M
  void setTypeForDecl(const Type *TD) { TypeForDecl = TD; }
2877
2878
5.33M
  SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
2879
1.02M
  void setLocStart(SourceLocation L) { LocStart = L; }
2880
1.98k
  SourceRange getSourceRange() const override LLVM_READONLY {
2881
1.98k
    if (LocStart.isValid())
2882
1.98k
      return SourceRange(LocStart, getLocation());
2883
0
    else
2884
0
      return SourceRange(getLocation());
2885
1.98k
  }
2886
2887
  // Implement isa/cast/dyncast/etc.
2888
90.5M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2889
90.8M
  static bool classofKind(Kind K) { return K >= firstType && 
K <= lastType54.9M
; }
2890
};
2891
2892
/// Base class for declarations which introduce a typedef-name.
2893
class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
2894
  struct alignas(8) ModedTInfo {
2895
    TypeSourceInfo *first;
2896
    QualType second;
2897
  };
2898
2899
  /// If int part is 0, we have not computed IsTransparentTag.
2900
  /// Otherwise, IsTransparentTag is (getInt() >> 1).
2901
  mutable llvm::PointerIntPair<
2902
      llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
2903
      MaybeModedTInfo;
2904
2905
  void anchor() override;
2906
2907
protected:
2908
  TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC,
2909
                  SourceLocation StartLoc, SourceLocation IdLoc,
2910
                  IdentifierInfo *Id, TypeSourceInfo *TInfo)
2911
      : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
2912
2.40M
        MaybeModedTInfo(TInfo, 0) {}
2913
2914
  using redeclarable_base = Redeclarable<TypedefNameDecl>;
2915
2916
308k
  TypedefNameDecl *getNextRedeclarationImpl() override {
2917
308k
    return getNextRedeclaration();
2918
308k
  }
2919
2920
12.5k
  TypedefNameDecl *getPreviousDeclImpl() override {
2921
12.5k
    return getPreviousDecl();
2922
12.5k
  }
2923
2924
629k
  TypedefNameDecl *getMostRecentDeclImpl() override {
2925
629k
    return getMostRecentDecl();
2926
629k
  }
2927
2928
public:
2929
  using redecl_range = redeclarable_base::redecl_range;
2930
  using redecl_iterator = redeclarable_base::redecl_iterator;
2931
2932
  using redeclarable_base::redecls_begin;
2933
  using redeclarable_base::redecls_end;
2934
  using redeclarable_base::redecls;
2935
  using redeclarable_base::getPreviousDecl;
2936
  using redeclarable_base::getMostRecentDecl;
2937
  using redeclarable_base::isFirstDecl;
2938
2939
52.1M
  bool isModed() const {
2940
52.1M
    return MaybeModedTInfo.getPointer().is<ModedTInfo *>();
2941
52.1M
  }
2942
2943
2.28M
  TypeSourceInfo *getTypeSourceInfo() const {
2944
2.28M
    return isModed() ? 
MaybeModedTInfo.getPointer().get<ModedTInfo *>()->first2.28k
2945
2.28M
                     : 
MaybeModedTInfo.getPointer().get<TypeSourceInfo *>()2.28M
;
2946
2.28M
  }
2947
2948
49.8M
  QualType getUnderlyingType() const {
2949
49.8M
    return isModed() ? 
MaybeModedTInfo.getPointer().get<ModedTInfo *>()->second26.1k
2950
49.8M
                     : MaybeModedTInfo.getPointer()
2951
49.8M
                           .get<TypeSourceInfo *>()
2952
49.8M
                           ->getType();
2953
49.8M
  }
2954
2955
7.71k
  void setTypeSourceInfo(TypeSourceInfo *newType) {
2956
7.71k
    MaybeModedTInfo.setPointer(newType);
2957
7.71k
  }
2958
2959
2.32k
  void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) {
2960
2.32k
    MaybeModedTInfo.setPointer(new (getASTContext(), 8)
2961
2.32k
                                   ModedTInfo({unmodedTSI, modedTy}));
2962
2.32k
  }
2963
2964
  /// Retrieves the canonical declaration of this typedef-name.
2965
10.9M
  TypedefNameDecl *getCanonicalDecl() override { return getFirstDecl(); }
2966
67
  const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
2967
2968
  /// Retrieves the tag declaration for which this is the typedef name for
2969
  /// linkage purposes, if any.
2970
  ///
2971
  /// \param AnyRedecl Look for the tag declaration in any redeclaration of
2972
  /// this typedef declaration.
2973
  TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
2974
2975
  /// Determines if this typedef shares a name and spelling location with its
2976
  /// underlying tag type, as is the case with the NS_ENUM macro.
2977
  bool isTransparentTag() const {
2978
    if (MaybeModedTInfo.getInt())
2979
      return MaybeModedTInfo.getInt() & 0x2;
2980
    return isTransparentTagSlow();
2981
  }
2982
2983
  // Implement isa/cast/dyncast/etc.
2984
74.3M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2985
74.3M
  static bool classofKind(Kind K) {
2986
74.3M
    return K >= firstTypedefName && 
K <= lastTypedefName58.2M
;
2987
74.3M
  }
2988
2989
private:
2990
  bool isTransparentTagSlow() const;
2991
};
2992
2993
/// Represents the declaration of a typedef-name via the 'typedef'
2994
/// type specifier.
2995
class TypedefDecl : public TypedefNameDecl {
2996
  TypedefDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2997
              SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
2998
2.34M
      : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
2999
3000
public:
3001
  static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
3002
                             SourceLocation StartLoc, SourceLocation IdLoc,
3003
                             IdentifierInfo *Id, TypeSourceInfo *TInfo);
3004
  static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3005
3006
  SourceRange getSourceRange() const override LLVM_READONLY;
3007
3008
  // Implement isa/cast/dyncast/etc.
3009
1.89k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3010
1.89k
  static bool classofKind(Kind K) { return K == Typedef; }
3011
};
3012
3013
/// Represents the declaration of a typedef-name via a C++11
3014
/// alias-declaration.
3015
class TypeAliasDecl : public TypedefNameDecl {
3016
  /// The template for which this is the pattern, if any.
3017
  TypeAliasTemplateDecl *Template;
3018
3019
  TypeAliasDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3020
                SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
3021
      : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
3022
65.1k
        Template(nullptr) {}
3023
3024
public:
3025
  static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
3026
                               SourceLocation StartLoc, SourceLocation IdLoc,
3027
                               IdentifierInfo *Id, TypeSourceInfo *TInfo);
3028
  static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3029
3030
  SourceRange getSourceRange() const override LLVM_READONLY;
3031
3032
2.60k
  TypeAliasTemplateDecl *getDescribedAliasTemplate() const { return Template; }
3033
52.6k
  void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT) { Template = TAT; }
3034
3035
  // Implement isa/cast/dyncast/etc.
3036
1.19M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3037
1.19M
  static bool classofKind(Kind K) { return K == TypeAlias; }
3038
};
3039
3040
/// Represents the declaration of a struct/union/class/enum.
3041
class TagDecl : public TypeDecl,
3042
                public DeclContext,
3043
                public Redeclarable<TagDecl> {
3044
  // This class stores some data in DeclContext::TagDeclBits
3045
  // to save some space. Use the provided accessors to access it.
3046
public:
3047
  // This is really ugly.
3048
  using TagKind = TagTypeKind;
3049
3050
private:
3051
  SourceRange BraceRange;
3052
3053
  // A struct representing syntactic qualifier info,
3054
  // to be used for the (uncommon) case of out-of-line declarations.
3055
  using ExtInfo = QualifierInfo;
3056
3057
  /// If the (out-of-line) tag declaration name
3058
  /// is qualified, it points to the qualifier info (nns and range);
3059
  /// otherwise, if the tag declaration is anonymous and it is part of
3060
  /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
3061
  /// otherwise, if the tag declaration is anonymous and it is used as a
3062
  /// declaration specifier for variables, it points to the first VarDecl (used
3063
  /// for mangling);
3064
  /// otherwise, it is a null (TypedefNameDecl) pointer.
3065
  llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3066
3067
1.88M
  bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo *>(); }
3068
61.3k
  ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo *>(); }
3069
303
  const ExtInfo *getExtInfo() const {
3070
303
    return TypedefNameDeclOrQualifier.get<ExtInfo *>();
3071
303
  }
3072
3073
protected:
3074
  TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3075
          SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3076
          SourceLocation StartL);
3077
3078
  using redeclarable_base = Redeclarable<TagDecl>;
3079
3080
740k
  TagDecl *getNextRedeclarationImpl() override {
3081
740k
    return getNextRedeclaration();
3082
740k
  }
3083
3084
16.3k
  TagDecl *getPreviousDeclImpl() override {
3085
16.3k
    return getPreviousDecl();
3086
16.3k
  }
3087
3088
2.19M
  TagDecl *getMostRecentDeclImpl() override {
3089
2.19M
    return getMostRecentDecl();
3090
2.19M
  }
3091
3092
  /// Completes the definition of this tag declaration.
3093
  ///
3094
  /// This is a helper function for derived classes.
3095
  void completeDefinition();
3096
3097
  /// True if this decl is currently being defined.
3098
9.10M
  void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; }
3099
3100
  /// Indicates whether it is possible for declarations of this kind
3101
  /// to have an out-of-date definition.
3102
  ///
3103
  /// This option is only enabled when modules are enabled.
3104
4.34M
  void setMayHaveOutOfDateDef(bool V = true) {
3105
4.34M
    TagDeclBits.MayHaveOutOfDateDef = V;
3106
4.34M
  }
3107
3108
public:
3109
  friend class ASTDeclReader;
3110
  friend class ASTDeclWriter;
3111
3112
  using redecl_range = redeclarable_base::redecl_range;
3113
  using redecl_iterator = redeclarable_base::redecl_iterator;
3114
3115
  using redeclarable_base::redecls_begin;
3116
  using redeclarable_base::redecls_end;
3117
  using redeclarable_base::redecls;
3118
  using redeclarable_base::getPreviousDecl;
3119
  using redeclarable_base::getMostRecentDecl;
3120
  using redeclarable_base::isFirstDecl;
3121
3122
1.44M
  SourceRange getBraceRange() const { return BraceRange; }
3123
2.03M
  void setBraceRange(SourceRange R) { BraceRange = R; }
3124
3125
  /// Return SourceLocation representing start of source
3126
  /// range ignoring outer template declarations.
3127
1.35M
  SourceLocation getInnerLocStart() const { return getBeginLoc(); }
3128
3129
  /// Return SourceLocation representing start of source
3130
  /// range taking into account any outer template declarations.
3131
  SourceLocation getOuterLocStart() const;
3132
  SourceRange getSourceRange() const override LLVM_READONLY;
3133
3134
  TagDecl *getCanonicalDecl() override;
3135
14.5k
  const TagDecl *getCanonicalDecl() const {
3136
14.5k
    return const_cast<TagDecl*>(this)->getCanonicalDecl();
3137
14.5k
  }
3138
3139
  /// Return true if this declaration is a completion definition of the type.
3140
  /// Provided for consistency.
3141
70.0k
  bool isThisDeclarationADefinition() const {
3142
70.0k
    return isCompleteDefinition();
3143
70.0k
  }
3144
3145
  /// Return true if this decl has its body fully specified.
3146
535M
  bool isCompleteDefinition() const { return TagDeclBits.IsCompleteDefinition; }
3147
3148
  /// True if this decl has its body fully specified.
3149
6.75M
  void setCompleteDefinition(bool V = true) {
3150
6.75M
    TagDeclBits.IsCompleteDefinition = V;
3151
6.75M
  }
3152
3153
  /// Return true if this complete decl is
3154
  /// required to be complete for some existing use.
3155
7.71M
  bool isCompleteDefinitionRequired() const {
3156
7.71M
    return TagDeclBits.IsCompleteDefinitionRequired;
3157
7.71M
  }
3158
3159
  /// True if this complete decl is
3160
  /// required to be complete for some existing use.
3161
5.66M
  void setCompleteDefinitionRequired(bool V = true) {
3162
5.66M
    TagDeclBits.IsCompleteDefinitionRequired = V;
3163
5.66M
  }
3164
3165
  /// Return true if this decl is currently being defined.
3166
54.9M
  bool isBeingDefined() const { return TagDeclBits.IsBeingDefined; }
3167
3168
  /// True if this tag declaration is "embedded" (i.e., defined or declared
3169
  /// for the very first time) in the syntax of a declarator.
3170
36.2k
  bool isEmbeddedInDeclarator() const {
3171
36.2k
    return TagDeclBits.IsEmbeddedInDeclarator;
3172
36.2k
  }
3173
3174
  /// True if this tag declaration is "embedded" (i.e., defined or declared
3175
  /// for the very first time) in the syntax of a declarator.
3176
4.57M
  void setEmbeddedInDeclarator(bool isInDeclarator) {
3177
4.57M
    TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator;
3178
4.57M
  }
3179
3180
  /// True if this tag is free standing, e.g. "struct foo;".
3181
36.3k
  bool isFreeStanding() const { return TagDeclBits.IsFreeStanding; }
3182
3183
  /// True if this tag is free standing, e.g. "struct foo;".
3184
5.32M
  void setFreeStanding(bool isFreeStanding = true) {
3185
5.32M
    TagDeclBits.IsFreeStanding = isFreeStanding;
3186
5.32M
  }
3187
3188
  /// Indicates whether it is possible for declarations of this kind
3189
  /// to have an out-of-date definition.
3190
  ///
3191
  /// This option is only enabled when modules are enabled.
3192
64.6M
  bool mayHaveOutOfDateDef() const { return TagDeclBits.MayHaveOutOfDateDef; }
3193
3194
  /// Whether this declaration declares a type that is
3195
  /// dependent, i.e., a type that somehow depends on template
3196
  /// parameters.
3197
14.2M
  bool isDependentType() const { return isDependentContext(); }
3198
3199
  /// Starts the definition of this tag declaration.
3200
  ///
3201
  /// This method should be invoked at the beginning of the definition
3202
  /// of this tag declaration. It will set the tag type into a state
3203
  /// where it is in the process of being defined.
3204
  void startDefinition();
3205
3206
  /// Returns the TagDecl that actually defines this
3207
  ///  struct/union/class/enum.  When determining whether or not a
3208
  ///  struct/union/class/enum has a definition, one should use this
3209
  ///  method as opposed to 'isDefinition'.  'isDefinition' indicates
3210
  ///  whether or not a specific TagDecl is defining declaration, not
3211
  ///  whether or not the struct/union/class/enum type is defined.
3212
  ///  This method returns NULL if there is no TagDecl that defines
3213
  ///  the struct/union/class/enum.
3214
  TagDecl *getDefinition() const;
3215
3216
141k
  StringRef getKindName() const {
3217
141k
    return TypeWithKeyword::getTagTypeKindName(getTagKind());
3218
141k
  }
3219
3220
30.1M
  TagKind getTagKind() const {
3221
30.1M
    return static_cast<TagKind>(TagDeclBits.TagDeclKind);
3222
30.1M
  }
3223
3224
5.37M
  void setTagKind(TagKind TK) { TagDeclBits.TagDeclKind = TK; }
3225
3226
2.60M
  bool isStruct() const { return getTagKind() == TTK_Struct; }
3227
6.09M
  bool isInterface() const { return getTagKind() == TTK_Interface; }
3228
1.33M
  bool isClass()  const { return getTagKind() == TTK_Class; }
3229
13.7M
  bool isUnion()  const { return getTagKind() == TTK_Union; }
3230
0
  bool isEnum()   const { return getTagKind() == TTK_Enum; }
3231
3232
  /// Is this tag type named, either directly or via being defined in
3233
  /// a typedef of this type?
3234
  ///
3235
  /// C++11 [basic.link]p8:
3236
  ///   A type is said to have linkage if and only if:
3237
  ///     - it is a class or enumeration type that is named (or has a
3238
  ///       name for linkage purposes) and the name has linkage; ...
3239
  /// C++11 [dcl.typedef]p9:
3240
  ///   If the typedef declaration defines an unnamed class (or enum),
3241
  ///   the first typedef-name declared by the declaration to be that
3242
  ///   class type (or enum type) is used to denote the class type (or
3243
  ///   enum type) for linkage purposes only.
3244
  ///
3245
  /// C does not have an analogous rule, but the same concept is
3246
  /// nonetheless useful in some places.
3247
7.15M
  bool hasNameForLinkage() const {
3248
7.15M
    return (getDeclName() || 
getTypedefNameForAnonDecl()144k
);
3249
7.15M
  }
3250
3251
284k
  TypedefNameDecl *getTypedefNameForAnonDecl() const {
3252
284k
    return hasExtInfo() ? 
nullptr255
3253
284k
                        : 
TypedefNameDeclOrQualifier.get<TypedefNameDecl *>()284k
;
3254
284k
  }
3255
3256
  void setTypedefNameForAnonDecl(TypedefNameDecl *TDD);
3257
3258
  /// Retrieve the nested-name-specifier that qualifies the name of this
3259
  /// declaration, if it was present in the source.
3260
0
  NestedNameSpecifier *getQualifier() const {
3261
0
    return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
3262
0
                        : nullptr;
3263
0
  }
3264
3265
  /// Retrieve the nested-name-specifier (with source-location
3266
  /// information) that qualifies the name of this declaration, if it was
3267
  /// present in the source.
3268
1.07M
  NestedNameSpecifierLoc getQualifierLoc() const {
3269
1.07M
    return hasExtInfo() ? 
getExtInfo()->QualifierLoc207
3270
1.07M
                        : 
NestedNameSpecifierLoc()1.07M
;
3271
1.07M
  }
3272
3273
  void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
3274
3275
418k
  unsigned getNumTemplateParameterLists() const {
3276
418k
    return hasExtInfo() ? 
getExtInfo()->NumTemplParamLists72
:
0418k
;
3277
418k
  }
3278
3279
24
  TemplateParameterList *getTemplateParameterList(unsigned i) const {
3280
24
    assert(i < getNumTemplateParameterLists());
3281
24
    return getExtInfo()->TemplParamLists[i];
3282
24
  }
3283
3284
  void setTemplateParameterListsInfo(ASTContext &Context,
3285
                                     ArrayRef<TemplateParameterList *> TPLists);
3286
3287
  // Implement isa/cast/dyncast/etc.
3288
86.3M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3289
92.3M
  static bool classofKind(Kind K) { return K >= firstTag && 
K <= lastTag53.2M
; }
3290
3291
31.9k
  static DeclContext *castToDeclContext(const TagDecl *D) {
3292
31.9k
    return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
3293
31.9k
  }
3294
3295
12
  static TagDecl *castFromDeclContext(const DeclContext *DC) {
3296
12
    return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
3297
12
  }
3298
};
3299
3300
/// Represents an enum.  In C++11, enums can be forward-declared
3301
/// with a fixed underlying type, and in C we allow them to be forward-declared
3302
/// with no underlying type as an extension.
3303
class EnumDecl : public TagDecl {
3304
  // This class stores some data in DeclContext::EnumDeclBits
3305
  // to save some space. Use the provided accessors to access it.
3306
3307
  /// This represent the integer type that the enum corresponds
3308
  /// to for code generation purposes.  Note that the enumerator constants may
3309
  /// have a different type than this does.
3310
  ///
3311
  /// If the underlying integer type was explicitly stated in the source
3312
  /// code, this is a TypeSourceInfo* for that type. Otherwise this type
3313
  /// was automatically deduced somehow, and this is a Type*.
3314
  ///
3315
  /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
3316
  /// some cases it won't.
3317
  ///
3318
  /// The underlying type of an enumeration never has any qualifiers, so
3319
  /// we can get away with just storing a raw Type*, and thus save an
3320
  /// extra pointer when TypeSourceInfo is needed.
3321
  llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
3322
3323
  /// The integer type that values of this type should
3324
  /// promote to.  In C, enumerators are generally of an integer type
3325
  /// directly, but gcc-style large enumerators (and all enumerators
3326
  /// in C++) are of the enum type instead.
3327
  QualType PromotionType;
3328
3329
  /// If this enumeration is an instantiation of a member enumeration
3330
  /// of a class template specialization, this is the member specialization
3331
  /// information.
3332
  MemberSpecializationInfo *SpecializationInfo = nullptr;
3333
3334
  /// Store the ODRHash after first calculation.
3335
  /// The corresponding flag HasODRHash is in EnumDeclBits
3336
  /// and can be accessed with the provided accessors.
3337
  unsigned ODRHash;
3338
3339
  EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3340
           SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
3341
           bool Scoped, bool ScopedUsingClassTag, bool Fixed);
3342
3343
  void anchor() override;
3344
3345
  void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
3346
                                    TemplateSpecializationKind TSK);
3347
3348
  /// Sets the width in bits required to store all the
3349
  /// non-negative enumerators of this enum.
3350
108k
  void setNumPositiveBits(unsigned Num) {
3351
108k
    EnumDeclBits.NumPositiveBits = Num;
3352
108k
    assert(EnumDeclBits.NumPositiveBits == Num && "can't store this bitcount");
3353
108k
  }
3354
3355
  /// Returns the width in bits required to store all the
3356
  /// negative enumerators of this enum. (see getNumNegativeBits)
3357
108k
  void setNumNegativeBits(unsigned Num) { EnumDeclBits.NumNegativeBits = Num; }
3358
3359
  /// True if this tag declaration is a scoped enumeration. Only
3360
  /// possible in C++11 mode.
3361
56.1k
  void setScoped(bool Scoped = true) { EnumDeclBits.IsScoped = Scoped; }
3362
3363
  /// If this tag declaration is a scoped enum,
3364
  /// then this is true if the scoped enum was declared using the class
3365
  /// tag, false if it was declared with the struct tag. No meaning is
3366
  /// associated if this tag declaration is not a scoped enum.
3367
56.1k
  void setScopedUsingClassTag(bool ScopedUCT = true) {
3368
56.1k
    EnumDeclBits.IsScopedUsingClassTag = ScopedUCT;
3369
56.1k
  }
3370
3371
  /// True if this is an Objective-C, C++11, or
3372
  /// Microsoft-style enumeration with a fixed underlying type.
3373
56.1k
  void setFixed(bool Fixed = true) { EnumDeclBits.IsFixed = Fixed; }
3374
3375
  /// True if a valid hash is stored in ODRHash.
3376
420
  bool hasODRHash() const { return EnumDeclBits.HasODRHash; }
3377
56.4k
  void setHasODRHash(bool Hash = true) { EnumDeclBits.HasODRHash = Hash; }
3378
3379
public:
3380
  friend class ASTDeclReader;
3381
3382
478k
  EnumDecl *getCanonicalDecl() override {
3383
478k
    return cast<EnumDecl>(TagDecl::getCanonicalDecl());
3384
478k
  }
3385
0
  const EnumDecl *getCanonicalDecl() const {
3386
0
    return const_cast<EnumDecl*>(this)->getCanonicalDecl();
3387
0
  }
3388
3389
58.5k
  EnumDecl *getPreviousDecl() {
3390
58.5k
    return cast_or_null<EnumDecl>(
3391
58.5k
            static_cast<TagDecl *>(this)->getPreviousDecl());
3392
58.5k
  }
3393
53.2k
  const EnumDecl *getPreviousDecl() const {
3394
53.2k
    return const_cast<EnumDecl*>(this)->getPreviousDecl();
3395
53.2k
  }
3396
3397
393
  EnumDecl *getMostRecentDecl() {
3398
393
    return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3399
393
  }
3400
0
  const EnumDecl *getMostRecentDecl() const {
3401
0
    return const_cast<EnumDecl*>(this)->getMostRecentDecl();
3402
0
  }
3403
3404
90.8k
  EnumDecl *getDefinition() const {
3405
90.8k
    return cast_or_null<EnumDecl>(TagDecl::getDefinition());
3406
90.8k
  }
3407
3408
  static EnumDecl *Create(ASTContext &C, DeclContext *DC,
3409
                          SourceLocation StartLoc, SourceLocation IdLoc,
3410
                          IdentifierInfo *Id, EnumDecl *PrevDecl,
3411
                          bool IsScoped, bool IsScopedUsingClassTag,
3412
                          bool IsFixed);
3413
  static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3414
3415
  /// When created, the EnumDecl corresponds to a
3416
  /// forward-declared enum. This method is used to mark the
3417
  /// declaration as being defined; its enumerators have already been
3418
  /// added (via DeclContext::addDecl). NewType is the new underlying
3419
  /// type of the enumeration type.
3420
  void completeDefinition(QualType NewType,
3421
                          QualType PromotionType,
3422
                          unsigned NumPositiveBits,
3423
                          unsigned NumNegativeBits);
3424
3425
  // Iterates through the enumerators of this enumeration.
3426
  using enumerator_iterator = specific_decl_iterator<EnumConstantDecl>;
3427
  using enumerator_range =
3428
      llvm::iterator_range<specific_decl_iterator<EnumConstantDecl>>;
3429
3430
9.17k
  enumerator_range enumerators() const {
3431
9.17k
    return enumerator_range(enumerator_begin(), enumerator_end());
3432
9.17k
  }
3433
3434
37.7k
  enumerator_iterator enumerator_begin() const {
3435
37.7k
    const EnumDecl *E = getDefinition();
3436
37.7k
    if (!E)
3437
200
      E = this;
3438
37.7k
    return enumerator_iterator(E->decls_begin());
3439
37.7k
  }
3440
3441
37.7k
  enumerator_iterator enumerator_end() const {
3442
37.7k
    const EnumDecl *E = getDefinition();
3443
37.7k
    if (!E)
3444
200
      E = this;
3445
37.7k
    return enumerator_iterator(E->decls_end());
3446
37.7k
  }
3447
3448
  /// Return the integer type that enumerators should promote to.
3449
27.4M
  QualType getPromotionType() const { return PromotionType; }
3450
3451
  /// Set the promotion type.
3452
8.86k
  void setPromotionType(QualType T) { PromotionType = T; }
3453
3454
  /// Return the integer type this enum decl corresponds to.
3455
  /// This returns a null QualType for an enum forward definition with no fixed
3456
  /// underlying type.
3457
1.81M
  QualType getIntegerType() const {
3458
1.81M
    if (!IntegerType)
3459
32
      return QualType();
3460
1.81M
    if (const Type *T = IntegerType.dyn_cast<const Type*>())
3461
1.60M
      return QualType(T, 0);
3462
205k
    return IntegerType.get<TypeSourceInfo*>()->getType().getUnqualifiedType();
3463
205k
  }
3464
3465
  /// Set the underlying integer type.
3466
1.66k
  void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
3467
3468
  /// Set the underlying integer type source info.
3469
7.46k
  void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
3470
3471
  /// Return the type source info for the underlying integer type,
3472
  /// if no type source info exists, return 0.
3473
2.11k
  TypeSourceInfo *getIntegerTypeSourceInfo() const {
3474
2.11k
    return IntegerType.dyn_cast<TypeSourceInfo*>();
3475
2.11k
  }
3476
3477
  /// Retrieve the source range that covers the underlying type if
3478
  /// specified.
3479
  SourceRange getIntegerTypeRange() const LLVM_READONLY;
3480
3481
  /// Returns the width in bits required to store all the
3482
  /// non-negative enumerators of this enum.
3483
82.0k
  unsigned getNumPositiveBits() const { return EnumDeclBits.NumPositiveBits; }
3484
3485
  /// Returns the width in bits required to store all the
3486
  /// negative enumerators of this enum.  These widths include
3487
  /// the rightmost leading 1;  that is:
3488
  ///
3489
  /// MOST NEGATIVE ENUMERATOR     PATTERN     NUM NEGATIVE BITS
3490
  /// ------------------------     -------     -----------------
3491
  ///                       -1     1111111                     1
3492
  ///                      -10     1110110                     5
3493
  ///                     -101     1001011                     8
3494
82.0k
  unsigned getNumNegativeBits() const { return EnumDeclBits.NumNegativeBits; }
3495
3496
  /// Returns true if this is a C++11 scoped enumeration.
3497
52.6M
  bool isScoped() const { return EnumDeclBits.IsScoped; }
3498
3499
  /// Returns true if this is a C++11 scoped enumeration.
3500
5.73k
  bool isScopedUsingClassTag() const {
3501
5.73k
    return EnumDeclBits.IsScopedUsingClassTag;
3502
5.73k
  }
3503
3504
  /// Returns true if this is an Objective-C, C++11, or
3505
  /// Microsoft-style enumeration with a fixed underlying type.
3506
15.8M
  bool isFixed() const { return EnumDeclBits.IsFixed; }
3507
3508
  unsigned getODRHash();
3509
3510
  /// Returns true if this can be considered a complete type.
3511
36.8M
  bool isComplete() const {
3512
36.8M
    // IntegerType is set for fixed type enums and non-fixed but implicitly
3513
36.8M
    // int-sized Microsoft enums.
3514
36.8M
    return isCompleteDefinition() || 
IntegerType207k
;
3515
36.8M
  }
3516
3517
  /// Returns true if this enum is either annotated with
3518
  /// enum_extensibility(closed) or isn't annotated with enum_extensibility.
3519
  bool isClosed() const;
3520
3521
  /// Returns true if this enum is annotated with flag_enum and isn't annotated
3522
  /// with enum_extensibility(open).
3523
  bool isClosedFlag() const;
3524
3525
  /// Returns true if this enum is annotated with neither flag_enum nor
3526
  /// enum_extensibility(open).
3527
  bool isClosedNonFlag() const;
3528
3529
  /// Retrieve the enum definition from which this enumeration could
3530
  /// be instantiated, if it is an instantiation (rather than a non-template).
3531
  EnumDecl *getTemplateInstantiationPattern() const;
3532
3533
  /// Returns the enumeration (declared within the template)
3534
  /// from which this enumeration type was instantiated, or NULL if
3535
  /// this enumeration was not instantiated from any template.
3536
  EnumDecl *getInstantiatedFromMemberEnum() const;
3537
3538
  /// If this enumeration is a member of a specialization of a
3539
  /// templated class, determine what kind of template specialization
3540
  /// or instantiation this is.
3541
  TemplateSpecializationKind getTemplateSpecializationKind() const;
3542
3543
  /// For an enumeration member that was instantiated from a member
3544
  /// enumeration of a templated class, set the template specialiation kind.
3545
  void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
3546
                        SourceLocation PointOfInstantiation = SourceLocation());
3547
3548
  /// If this enumeration is an instantiation of a member enumeration of
3549
  /// a class template specialization, retrieves the member specialization
3550
  /// information.
3551
10.4k
  MemberSpecializationInfo *getMemberSpecializationInfo() const {
3552
10.4k
    return SpecializationInfo;
3553
10.4k
  }
3554
3555
  /// Specify that this enumeration is an instantiation of the
3556
  /// member enumeration ED.
3557
  void setInstantiationOfMemberEnum(EnumDecl *ED,
3558
5.37k
                                    TemplateSpecializationKind TSK) {
3559
5.37k
    setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
3560
5.37k
  }
3561
3562
42.7M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3563
131M
  static bool classofKind(Kind K) { return K == Enum; }
3564
};
3565
3566
/// Represents a struct/union/class.  For example:
3567
///   struct X;                  // Forward declaration, no "body".
3568
///   union Y { int A, B; };     // Has body with members A and B (FieldDecls).
3569
/// This decl will be marked invalid if *any* members are invalid.
3570
class RecordDecl : public TagDecl {
3571
  // This class stores some data in DeclContext::RecordDeclBits
3572
  // to save some space. Use the provided accessors to access it.
3573
public:
3574
  friend class DeclContext;
3575
  /// Enum that represents the different ways arguments are passed to and
3576
  /// returned from function calls. This takes into account the target-specific
3577
  /// and version-specific rules along with the rules determined by the
3578
  /// language.
3579
  enum ArgPassingKind : unsigned {
3580
    /// The argument of this type can be passed directly in registers.
3581
    APK_CanPassInRegs,
3582
3583
    /// The argument of this type cannot be passed directly in registers.
3584
    /// Records containing this type as a subobject are not forced to be passed
3585
    /// indirectly. This value is used only in C++. This value is required by
3586
    /// C++ because, in uncommon situations, it is possible for a class to have
3587
    /// only trivial copy/move constructors even when one of its subobjects has
3588
    /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
3589
    /// constructor in the derived class is deleted).
3590
    APK_CannotPassInRegs,
3591
3592
    /// The argument of this type cannot be passed directly in registers.
3593
    /// Records containing this type as a subobject are forced to be passed
3594
    /// indirectly.
3595
    APK_CanNeverPassInRegs
3596
  };
3597
3598
protected:
3599
  RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3600
             SourceLocation StartLoc, SourceLocation IdLoc,
3601
             IdentifierInfo *Id, RecordDecl *PrevDecl);
3602
3603
public:
3604
  static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
3605
                            SourceLocation StartLoc, SourceLocation IdLoc,
3606
                            IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
3607
  static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
3608
3609
5.03M
  RecordDecl *getPreviousDecl() {
3610
5.03M
    return cast_or_null<RecordDecl>(
3611
5.03M
            static_cast<TagDecl *>(this)->getPreviousDecl());
3612
5.03M
  }
3613
2.08M
  const RecordDecl *getPreviousDecl() const {
3614
2.08M
    return const_cast<RecordDecl*>(this)->getPreviousDecl();
3615
2.08M
  }
3616
3617
319M
  RecordDecl *getMostRecentDecl() {
3618
319M
    return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3619
319M
  }
3620
0
  const RecordDecl *getMostRecentDecl() const {
3621
0
    return const_cast<RecordDecl*>(this)->getMostRecentDecl();
3622
0
  }
3623
3624
3.77M
  bool hasFlexibleArrayMember() const {
3625
3.77M
    return RecordDeclBits.HasFlexibleArrayMember;
3626
3.77M
  }
3627
3628
4.32M
  void setHasFlexibleArrayMember(bool V) {
3629
4.32M
    RecordDeclBits.HasFlexibleArrayMember = V;
3630
4.32M
  }
3631
3632
  /// Whether this is an anonymous struct or union. To be an anonymous
3633
  /// struct or union, it must have been declared without a name and
3634
  /// there must be no objects of this type declared, e.g.,
3635
  /// @code
3636
  ///   union { int i; float f; };
3637
  /// @endcode
3638
  /// is an anonymous union but neither of the following are:
3639
  /// @code
3640
  ///  union X { int i; float f; };
3641
  ///  union { int i; float f; } obj;
3642
  /// @endcode
3643
6.86M
  bool isAnonymousStructOrUnion() const {
3644
6.86M
    return RecordDeclBits.AnonymousStructOrUnion;
3645
6.86M
  }
3646
3647
4.33M
  void setAnonymousStructOrUnion(bool Anon) {
3648
4.33M
    RecordDeclBits.AnonymousStructOrUnion = Anon;
3649
4.33M
  }
3650
3651
1.43M
  bool hasObjectMember() const { return RecordDeclBits.HasObjectMember; }
3652
4.32M
  void setHasObjectMember(bool val) { RecordDeclBits.HasObjectMember = val; }
3653
3654
1.44M
  bool hasVolatileMember() const { return RecordDeclBits.HasVolatileMember; }
3655
3656
4.38M
  void setHasVolatileMember(bool val) {
3657
4.38M
    RecordDeclBits.HasVolatileMember = val;
3658
4.38M
  }
3659
3660
30.4k
  bool hasLoadedFieldsFromExternalStorage() const {
3661
30.4k
    return RecordDeclBits.LoadedFieldsFromExternalStorage;
3662
30.4k
  }
3663
3664
4.29M
  void setHasLoadedFieldsFromExternalStorage(bool val) const {
3665
4.29M
    RecordDeclBits.LoadedFieldsFromExternalStorage = val;
3666
4.29M
  }
3667
3668
  /// Functions to query basic properties of non-trivial C structs.
3669
107k
  bool isNonTrivialToPrimitiveDefaultInitialize() const {
3670
107k
    return RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize;
3671
107k
  }
3672
3673
4.32M
  void setNonTrivialToPrimitiveDefaultInitialize(bool V) {
3674
4.32M
    RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize = V;
3675
4.32M
  }
3676
3677
107k
  bool isNonTrivialToPrimitiveCopy() const {
3678
107k
    return RecordDeclBits.NonTrivialToPrimitiveCopy;
3679
107k
  }
3680
3681
4.32M
  void setNonTrivialToPrimitiveCopy(bool V) {
3682
4.32M
    RecordDeclBits.NonTrivialToPrimitiveCopy = V;
3683
4.32M
  }
3684
3685
139k
  bool isNonTrivialToPrimitiveDestroy() const {
3686
139k
    return RecordDeclBits.NonTrivialToPrimitiveDestroy;
3687
139k
  }
3688
3689
4.32M
  void setNonTrivialToPrimitiveDestroy(bool V) {
3690
4.32M
    RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
3691
4.32M
  }
3692
3693
  /// Determine whether this class can be passed in registers. In C++ mode,
3694
  /// it must have at least one trivial, non-deleted copy or move constructor.
3695
  /// FIXME: This should be set as part of completeDefinition.
3696
24.9k
  bool canPassInRegisters() const {
3697
24.9k
    return getArgPassingRestrictions() == APK_CanPassInRegs;
3698
24.9k
  }
3699
3700
2.91M
  ArgPassingKind getArgPassingRestrictions() const {
3701
2.91M
    return static_cast<ArgPassingKind>(RecordDeclBits.ArgPassingRestrictions);
3702
2.91M
  }
3703
3704
6.12M
  void setArgPassingRestrictions(ArgPassingKind Kind) {
3705
6.12M
    RecordDeclBits.ArgPassingRestrictions = Kind;
3706
6.12M
  }
3707
3708
66.9k
  bool isParamDestroyedInCallee() const {
3709
66.9k
    return RecordDeclBits.ParamDestroyedInCallee;
3710
66.9k
  }
3711
3712
4.43M
  void setParamDestroyedInCallee(bool V) {
3713
4.43M
    RecordDeclBits.ParamDestroyedInCallee = V;
3714
4.43M
  }
3715
3716
  /// Determines whether this declaration represents the
3717
  /// injected class name.
3718
  ///
3719
  /// The injected class name in C++ is the name of the class that
3720
  /// appears inside the class itself. For example:
3721
  ///
3722
  /// \code
3723
  /// struct C {
3724
  ///   // C is implicitly declared here as a synonym for the class name.
3725
  /// };
3726
  ///
3727
  /// C::C c; // same as "C c;"
3728
  /// \endcode
3729
  bool isInjectedClassName() const;
3730
3731
  /// Determine whether this record is a class describing a lambda
3732
  /// function object.
3733
  bool isLambda() const;
3734
3735
  /// Determine whether this record is a record for captured variables in
3736
  /// CapturedStmt construct.
3737
  bool isCapturedRecord() const;
3738
3739
  /// Mark the record as a record for captured variables in CapturedStmt
3740
  /// construct.
3741
  void setCapturedRecord();
3742
3743
  /// Returns the RecordDecl that actually defines
3744
  ///  this struct/union/class.  When determining whether or not a
3745
  ///  struct/union/class is completely defined, one should use this
3746
  ///  method as opposed to 'isCompleteDefinition'.
3747
  ///  'isCompleteDefinition' indicates whether or not a specific
3748
  ///  RecordDecl is a completed definition, not whether or not the
3749
  ///  record type is defined.  This method returns NULL if there is
3750
  ///  no RecordDecl that defines the struct/union/tag.
3751
8.41M
  RecordDecl *getDefinition() const {
3752
8.41M
    return cast_or_null<RecordDecl>(TagDecl::getDefinition());
3753
8.41M
  }
3754
3755
  // Iterator access to field members. The field iterator only visits
3756
  // the non-static data members of this class, ignoring any static
3757
  // data members, functions, constructors, destructors, etc.
3758
  using field_iterator = specific_decl_iterator<FieldDecl>;
3759
  using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
3760
3761
3.23M
  field_range fields() const { return field_range(field_begin(), field_end()); }
3762
  field_iterator field_begin() const;
3763
3764
5.80M
  field_iterator field_end() const {
3765
5.80M
    return field_iterator(decl_iterator());
3766
5.80M
  }
3767
3768
  // Whether there are any fields (non-static data members) in this record.
3769
666k
  bool field_empty() const {
3770
666k
    return field_begin() == field_end();
3771
666k
  }
3772
3773
  /// Note that the definition of this type is now complete.
3774
  virtual void completeDefinition();
3775
3776
33.8M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3777
61.2M
  static bool classofKind(Kind K) {
3778
61.2M
    return K >= firstRecord && 
K <= lastRecord53.8M
;
3779
61.2M
  }
3780
3781
  /// Get whether or not this is an ms_struct which can
3782
  /// be turned on with an attribute, pragma, or -mms-bitfields
3783
  /// commandline option.
3784
  bool isMsStruct(const ASTContext &C) const;
3785
3786
  /// Whether we are allowed to insert extra padding between fields.
3787
  /// These padding are added to help AddressSanitizer detect
3788
  /// intra-object-overflow bugs.
3789
  bool mayInsertExtraPadding(bool EmitRemark = false) const;
3790
3791
  /// Finds the first data member which has a name.
3792
  /// nullptr is returned if no named data member exists.
3793
  const FieldDecl *findFirstNamedDataMember() const;
3794
3795
private:
3796
  /// Deserialize just the fields.
3797
  void LoadFieldsFromExternalStorage() const;
3798
};
3799
3800
class FileScopeAsmDecl : public Decl {
3801
  StringLiteral *AsmString;
3802
  SourceLocation RParenLoc;
3803
3804
  FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring,
3805
                   SourceLocation StartL, SourceLocation EndL)
3806
1.17k
    : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
3807
3808
  virtual void anchor();
3809
3810
public:
3811
  static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC,
3812
                                  StringLiteral *Str, SourceLocation AsmLoc,
3813
                                  SourceLocation RParenLoc);
3814
3815
  static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3816
3817
3
  SourceLocation getAsmLoc() const { return getLocation(); }
3818
62
  SourceLocation getRParenLoc() const { return RParenLoc; }
3819
113
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3820
3
  SourceRange getSourceRange() const override LLVM_READONLY {
3821
3
    return SourceRange(getAsmLoc(), getRParenLoc());
3822
3
  }
3823
3824
3
  const StringLiteral *getAsmString() const { return AsmString; }
3825
1.05k
  StringLiteral *getAsmString() { return AsmString; }
3826
113
  void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
3827
3828
715k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3829
715k
  static bool classofKind(Kind K) { return K == FileScopeAsm; }
3830
};
3831
3832
/// Pepresents a block literal declaration, which is like an
3833
/// unnamed FunctionDecl.  For example:
3834
/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
3835
class BlockDecl : public Decl, public DeclContext {
3836
  // This class stores some data in DeclContext::BlockDeclBits
3837
  // to save some space. Use the provided accessors to access it.
3838
public:
3839
  /// A class which contains all the information about a particular
3840
  /// captured value.
3841
  class Capture {
3842
    enum {
3843
      flag_isByRef = 0x1,
3844
      flag_isNested = 0x2
3845
    };
3846
3847
    /// The variable being captured.
3848
    llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
3849
3850
    /// The copy expression, expressed in terms of a DeclRef (or
3851
    /// BlockDeclRef) to the captured variable.  Only required if the
3852
    /// variable has a C++ class type.
3853
    Expr *CopyExpr;
3854
3855
  public:
3856
    Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
3857
      : VariableAndFlags(variable,
3858
                  (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
3859
2.76k
        CopyExpr(copy) {}
3860
3861
    /// The variable being captured.
3862
24.8k
    VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
3863
3864
    /// Whether this is a "by ref" capture, i.e. a capture of a __block
3865
    /// variable.
3866
18.4k
    bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
3867
3868
    /// Whether this is a nested capture, i.e. the variable captured
3869
    /// is not from outside the immediately enclosing function/block.
3870
3.39k
    bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
3871
3872
1.59k
    bool hasCopyExpr() const { return CopyExpr != nullptr; }
3873
6.10k
    Expr *getCopyExpr() const { return CopyExpr; }
3874
0
    void setCopyExpr(Expr *e) { CopyExpr = e; }
3875
  };
3876
3877
private:
3878
  /// A new[]'d array of pointers to ParmVarDecls for the formal
3879
  /// parameters of this function.  This is null if a prototype or if there are
3880
  /// no formals.
3881
  ParmVarDecl **ParamInfo = nullptr;
3882
  unsigned NumParams = 0;
3883
3884
  Stmt *Body = nullptr;
3885
  TypeSourceInfo *SignatureAsWritten = nullptr;
3886
3887
  const Capture *Captures = nullptr;
3888
  unsigned NumCaptures = 0;
3889
3890
  unsigned ManglingNumber = 0;
3891
  Decl *ManglingContextDecl = nullptr;
3892
3893
protected:
3894
  BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
3895
3896
public:
3897
  static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L);
3898
  static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3899
3900
20.2k
  SourceLocation getCaretLocation() const { return getLocation(); }
3901
3902
198
  bool isVariadic() const { return BlockDeclBits.IsVariadic; }
3903
5.20k
  void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; }
3904
3905
0
  CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
3906
21.7k
  Stmt *getBody() const override { return (Stmt*) Body; }
3907
2.59k
  void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
3908
3909
2.56k
  void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
3910
967
  TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
3911
3912
  // ArrayRef access to formal parameters.
3913
5.46k
  ArrayRef<ParmVarDecl *> parameters() const {
3914
5.46k
    return {ParamInfo, getNumParams()};
3915
5.46k
  }
3916
5.75k
  MutableArrayRef<ParmVarDecl *> parameters() {
3917
5.75k
    return {ParamInfo, getNumParams()};
3918
5.75k
  }
3919
3920
  // Iterator access to formal parameters.
3921
  using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator;
3922
  using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator;
3923
3924
157
  bool param_empty() const { return parameters().empty(); }
3925
55
  param_iterator param_begin() { return parameters().begin(); }
3926
23
  param_iterator param_end() { return parameters().end(); }
3927
1.11k
  param_const_iterator param_begin() const { return parameters().begin(); }
3928
1.11k
  param_const_iterator param_end() const { return parameters().end(); }
3929
16
  size_t param_size() const { return parameters().size(); }
3930
3931
11.2k
  unsigned getNumParams() const { return NumParams; }
3932
3933
10
  const ParmVarDecl *getParamDecl(unsigned i) const {
3934
10
    assert(i < getNumParams() && "Illegal param #");
3935
10
    return ParamInfo[i];
3936
10
  }
3937
16
  ParmVarDecl *getParamDecl(unsigned i) {
3938
16
    assert(i < getNumParams() && "Illegal param #");
3939
16
    return ParamInfo[i];
3940
16
  }
3941
3942
  void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
3943
3944
  /// True if this block (or its nested blocks) captures
3945
  /// anything of local storage from its enclosing scopes.
3946
6.69k
  bool hasCaptures() const { return NumCaptures || 
capturesCXXThis()2.58k
; }
3947
3948
  /// Returns the number of captured variables.
3949
  /// Does not include an entry for 'this'.
3950
16
  unsigned getNumCaptures() const { return NumCaptures; }
3951
3952
  using capture_const_iterator = ArrayRef<Capture>::const_iterator;
3953
3954
12.5k
  ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; }
3955
3956
1.18k
  capture_const_iterator capture_begin() const { return captures().begin(); }
3957
1.18k
  capture_const_iterator capture_end() const { return captures().end(); }
3958
3959
6.19k
  bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
3960
5.20k
  void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
3961
3962
96
  bool blockMissingReturnType() const {
3963
96
    return BlockDeclBits.BlockMissingReturnType;
3964
96
  }
3965
3966
2.81k
  void setBlockMissingReturnType(bool val = true) {
3967
2.81k
    BlockDeclBits.BlockMissingReturnType = val;
3968
2.81k
  }
3969
3970
3.29k
  bool isConversionFromLambda() const {
3971
3.29k
    return BlockDeclBits.IsConversionFromLambda;
3972
3.29k
  }
3973
3974
2.64k
  void setIsConversionFromLambda(bool val = true) {
3975
2.64k
    BlockDeclBits.IsConversionFromLambda = val;
3976
2.64k
  }
3977
3978
3.00k
  bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
3979
2.63k
  void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
3980
3981
  bool capturesVariable(const VarDecl *var) const;
3982
3983
  void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
3984
                   bool CapturesCXXThis);
3985
3986
144
   unsigned getBlockManglingNumber() const {
3987
144
     return ManglingNumber;
3988
144
   }
3989
3990
468
   Decl *getBlockManglingContextDecl() const {
3991
468
     return ManglingContextDecl;
3992
468
   }
3993
3994
201
  void setBlockMangling(unsigned Number, Decl *Ctx) {
3995
201
    ManglingNumber = Number;
3996
201
    ManglingContextDecl = Ctx;
3997
201
  }
3998
3999
  SourceRange getSourceRange() const override LLVM_READONLY;
4000
4001
  // Implement isa/cast/dyncast/etc.
4002
24.8M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4003
85.5M
  static bool classofKind(Kind K) { return K == Block; }
4004
36
  static DeclContext *castToDeclContext(const BlockDecl *D) {
4005
36
    return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
4006
36
  }
4007
0
  static BlockDecl *castFromDeclContext(const DeclContext *DC) {
4008
0
    return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
4009
0
  }
4010
};
4011
4012
/// Represents the body of a CapturedStmt, and serves as its DeclContext.
4013
class CapturedDecl final
4014
    : public Decl,
4015
      public DeclContext,
4016
      private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
4017
protected:
4018
0
  size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
4019
0
    return NumParams;
4020
0
  }
4021
4022
private:
4023
  /// The number of parameters to the outlined function.
4024
  unsigned NumParams;
4025
4026
  /// The position of context parameter in list of parameters.
4027
  unsigned ContextParam;
4028
4029
  /// The body of the outlined function.
4030
  llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4031
4032
  explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
4033
4034
506k
  ImplicitParamDecl *const *getParams() const {
4035
506k
    return getTrailingObjects<ImplicitParamDecl *>();
4036
506k
  }
4037
4038
1.07M
  ImplicitParamDecl **getParams() {
4039
1.07M
    return getTrailingObjects<ImplicitParamDecl *>();
4040
1.07M
  }
4041
4042
public:
4043
  friend class ASTDeclReader;
4044
  friend class ASTDeclWriter;
4045
  friend TrailingObjects;
4046
4047
  static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
4048
                              unsigned NumParams);
4049
  static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID,
4050
                                          unsigned NumParams);
4051
4052
  Stmt *getBody() const override;
4053
  void setBody(Stmt *B);
4054
4055
  bool isNothrow() const;
4056
  void setNothrow(bool Nothrow = true);
4057
4058
106k
  unsigned getNumParams() const { return NumParams; }
4059
4060
390k
  ImplicitParamDecl *getParam(unsigned i) const {
4061
390k
    assert(i < NumParams);
4062
390k
    return getParams()[i];
4063
390k
  }
4064
1.07M
  void setParam(unsigned i, ImplicitParamDecl *P) {
4065
1.07M
    assert(i < NumParams);
4066
1.07M
    getParams()[i] = P;
4067
1.07M
  }
4068
4069
  // ArrayRef interface to parameters.
4070
0
  ArrayRef<ImplicitParamDecl *> parameters() const {
4071
0
    return {getParams(), getNumParams()};
4072
0
  }
4073
0
  MutableArrayRef<ImplicitParamDecl *> parameters() {
4074
0
    return {getParams(), getNumParams()};
4075
0
  }
4076
4077
  /// Retrieve the parameter containing captured variables.
4078
292k
  ImplicitParamDecl *getContextParam() const {
4079
292k
    assert(ContextParam < NumParams);
4080
292k
    return getParam(ContextParam);
4081
292k
  }
4082
310k
  void setContextParam(unsigned i, ImplicitParamDecl *P) {
4083
310k
    assert(i < NumParams);
4084
310k
    ContextParam = i;
4085
310k
    setParam(i, P);
4086
310k
  }
4087
86.8k
  unsigned getContextParamPosition() const { return ContextParam; }
4088
4089
  using param_iterator = ImplicitParamDecl *const *;
4090
  using param_range = llvm::iterator_range<param_iterator>;
4091
4092
  /// Retrieve an iterator pointing to the first parameter decl.
4093
88.8k
  param_iterator param_begin() const { return getParams(); }
4094
  /// Retrieve an iterator one past the last parameter decl.
4095
27.3k
  param_iterator param_end() const { return getParams() + NumParams; }
4096
4097
  // Implement isa/cast/dyncast/etc.
4098
261k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4099
85.2M
  static bool classofKind(Kind K) { return K == Captured; }
4100
291k
  static DeclContext *castToDeclContext(const CapturedDecl *D) {
4101
291k
    return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
4102
291k
  }
4103
0
  static CapturedDecl *castFromDeclContext(const DeclContext *DC) {
4104
0
    return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
4105
0
  }
4106
};
4107
4108
/// Describes a module import declaration, which makes the contents
4109
/// of the named module visible in the current translation unit.
4110
///
4111
/// An import declaration imports the named module (or submodule). For example:
4112
/// \code
4113
///   @import std.vector;
4114
/// \endcode
4115
///
4116
/// Import declarations can also be implicitly generated from
4117
/// \#include/\#import directives.
4118
class ImportDecl final : public Decl,
4119
                         llvm::TrailingObjects<ImportDecl, SourceLocation> {
4120
  friend class ASTContext;
4121
  friend class ASTDeclReader;
4122
  friend class ASTReader;
4123
  friend TrailingObjects;
4124
4125
  /// The imported module, along with a bit that indicates whether
4126
  /// we have source-location information for each identifier in the module
4127
  /// name.
4128
  ///
4129
  /// When the bit is false, we only have a single source location for the
4130
  /// end of the import declaration.
4131
  llvm::PointerIntPair<Module *, 1, bool> ImportedAndComplete;
4132
4133
  /// The next import in the list of imports local to the translation
4134
  /// unit being parsed (not loaded from an AST file).
4135
  ImportDecl *NextLocalImport = nullptr;
4136
4137
  ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4138
             ArrayRef<SourceLocation> IdentifierLocs);
4139
4140
  ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4141
             SourceLocation EndLoc);
4142
4143
152
  ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
4144
4145
public:
4146
  /// Create a new module import declaration.
4147
  static ImportDecl *Create(ASTContext &C, DeclContext *DC,
4148
                            SourceLocation StartLoc, Module *Imported,
4149
                            ArrayRef<SourceLocation> IdentifierLocs);
4150
4151
  /// Create a new module import declaration for an implicitly-generated
4152
  /// import.
4153
  static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
4154
                                    SourceLocation StartLoc, Module *Imported,
4155
                                    SourceLocation EndLoc);
4156
4157
  /// Create a new, deserialized module import declaration.
4158
  static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID,
4159
                                        unsigned NumLocations);
4160
4161
  /// Retrieve the module that was imported by the import declaration.
4162
5.09k
  Module *getImportedModule() const { return ImportedAndComplete.getPointer(); }
4163
4164
  /// Retrieves the locations of each of the identifiers that make up
4165
  /// the complete module name in the import declaration.
4166
  ///
4167
  /// This will return an empty array if the locations of the individual
4168
  /// identifiers aren't available.
4169
  ArrayRef<SourceLocation> getIdentifierLocs() const;
4170
4171
  SourceRange getSourceRange() const override LLVM_READONLY;
4172
4173
27.1M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4174
27.1M
  static bool classofKind(Kind K) { return K == Import; }
4175
};
4176
4177
/// Represents a C++ Modules TS module export declaration.
4178
///
4179
/// For example:
4180
/// \code
4181
///   export void foo();
4182
/// \endcode
4183
class ExportDecl final : public Decl, public DeclContext {
4184
  virtual void anchor();
4185
4186
private:
4187
  friend class ASTDeclReader;
4188
4189
  /// The source location for the right brace (if valid).
4190
  SourceLocation RBraceLoc;
4191
4192
  ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
4193
      : Decl(Export, DC, ExportLoc), DeclContext(Export),
4194
82
        RBraceLoc(SourceLocation()) {}
4195
4196
public:
4197
  static ExportDecl *Create(ASTContext &C, DeclContext *DC,
4198
                            SourceLocation ExportLoc);
4199
  static ExportDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4200
4201
0
  SourceLocation getExportLoc() const { return getLocation(); }
4202
29
  SourceLocation getRBraceLoc() const { return RBraceLoc; }
4203
16
  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
4204
4205
0
  SourceLocation getEndLoc() const LLVM_READONLY {
4206
0
    if (RBraceLoc.isValid())
4207
0
      return RBraceLoc;
4208
0
    // No braces: get the end location of the (only) declaration in context
4209
0
    // (if present).
4210
0
    return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
4211
0
  }
4212
4213
0
  SourceRange getSourceRange() const override LLVM_READONLY {
4214
0
    return SourceRange(getLocation(), getEndLoc());
4215
0
  }
4216
4217
0
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4218
7.19k
  static bool classofKind(Kind K) { return K == Export; }
4219
0
  static DeclContext *castToDeclContext(const ExportDecl *D) {
4220
0
    return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
4221
0
  }
4222
0
  static ExportDecl *castFromDeclContext(const DeclContext *DC) {
4223
0
    return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
4224
0
  }
4225
};
4226
4227
/// Represents an empty-declaration.
4228
class EmptyDecl : public Decl {
4229
2.17k
  EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {}
4230
4231
  virtual void anchor();
4232
4233
public:
4234
  static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
4235
                           SourceLocation L);
4236
  static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4237
4238
0
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4239
0
  static bool classofKind(Kind K) { return K == Empty; }
4240
};
4241
4242
/// Insertion operator for diagnostics.  This allows sending NamedDecl's
4243
/// into a diagnostic with <<.
4244
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
4245
158k
                                           const NamedDecl* ND) {
4246
158k
  DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
4247
158k
                  DiagnosticsEngine::ak_nameddecl);
4248
158k
  return DB;
4249
158k
}
4250
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
4251
850k
                                           const NamedDecl* ND) {
4252
850k
  PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
4253
850k
                  DiagnosticsEngine::ak_nameddecl);
4254
850k
  return PD;
4255
850k
}
4256
4257
template<typename decl_type>
4258
5.62M
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4259
5.62M
  // Note: This routine is implemented here because we need both NamedDecl
4260
5.62M
  // and Redeclarable to be defined.
4261
5.62M
  assert(RedeclLink.isFirst() &&
4262
5.62M
         "setPreviousDecl on a decl already in a redeclaration chain");
4263
5.62M
4264
5.62M
  if (PrevDecl) {
4265
1.83M
    // Point to previous. Make sure that this is actually the most recent
4266
1.83M
    // redeclaration, or we can build invalid chains. If the most recent
4267
1.83M
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4268
1.83M
    First = PrevDecl->getFirstDecl();
4269
1.83M
    assert(First->RedeclLink.isFirst() && "Expected first");
4270
1.83M
    decl_type *MostRecent = First->getNextRedeclaration();
4271
1.83M
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4272
1.83M
4273
1.83M
    // If the declaration was previously visible, a redeclaration of it remains
4274
1.83M
    // visible even if it wouldn't be visible by itself.
4275
1.83M
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4276
1.83M
      MostRecent->getIdentifierNamespace() &
4277
1.83M
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4278
3.79M
  } else {
4279
3.79M
    // Make this first.
4280
3.79M
    First = static_cast<decl_type*>(this);
4281
3.79M
  }
4282
5.62M
4283
5.62M
  // First one will point to this one as latest.
4284
5.62M
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4285
5.62M
4286
5.62M
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4287
5.62M
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4288
5.62M
}
clang::Redeclarable<clang::TypedefNameDecl>::setPreviousDecl(clang::TypedefNameDecl*)
Line
Count
Source
4258
6.78k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4259
6.78k
  // Note: This routine is implemented here because we need both NamedDecl
4260
6.78k
  // and Redeclarable to be defined.
4261
6.78k
  assert(RedeclLink.isFirst() &&
4262
6.78k
         "setPreviousDecl on a decl already in a redeclaration chain");
4263
6.78k
4264
6.78k
  if (PrevDecl) {
4265
6.78k
    // Point to previous. Make sure that this is actually the most recent
4266
6.78k
    // redeclaration, or we can build invalid chains. If the most recent
4267
6.78k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4268
6.78k
    First = PrevDecl->getFirstDecl();
4269
6.78k
    assert(First->RedeclLink.isFirst() && "Expected first");
4270
6.78k
    decl_type *MostRecent = First->getNextRedeclaration();
4271
6.78k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4272
6.78k
4273
6.78k
    // If the declaration was previously visible, a redeclaration of it remains
4274
6.78k
    // visible even if it wouldn't be visible by itself.
4275
6.78k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4276
6.78k
      MostRecent->getIdentifierNamespace() &
4277
6.78k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4278
6.78k
  } else {
4279
0
    // Make this first.
4280
0
    First = static_cast<decl_type*>(this);
4281
0
  }
4282
6.78k
4283
6.78k
  // First one will point to this one as latest.
4284
6.78k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4285
6.78k
4286
6.78k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4287
6.78k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4288
6.78k
}
clang::Redeclarable<clang::VarDecl>::setPreviousDecl(clang::VarDecl*)
Line
Count
Source
4258
75.7k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4259
75.7k
  // Note: This routine is implemented here because we need both NamedDecl
4260
75.7k
  // and Redeclarable to be defined.
4261
75.7k
  assert(RedeclLink.isFirst() &&
4262
75.7k
         "setPreviousDecl on a decl already in a redeclaration chain");
4263
75.7k
4264
75.7k
  if (PrevDecl) {
4265
75.7k
    // Point to previous. Make sure that this is actually the most recent
4266
75.7k
    // redeclaration, or we can build invalid chains. If the most recent
4267
75.7k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4268
75.7k
    First = PrevDecl->getFirstDecl();
4269
75.7k
    assert(First->RedeclLink.isFirst() && "Expected first");
4270
75.7k
    decl_type *MostRecent = First->getNextRedeclaration();
4271
75.7k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4272
75.7k
4273
75.7k
    // If the declaration was previously visible, a redeclaration of it remains
4274
75.7k
    // visible even if it wouldn't be visible by itself.
4275
75.7k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4276
75.7k
      MostRecent->getIdentifierNamespace() &
4277
75.7k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4278
75.7k
  } else {
4279
0
    // Make this first.
4280
0
    First = static_cast<decl_type*>(this);
4281
0
  }
4282
75.7k
4283
75.7k
  // First one will point to this one as latest.
4284
75.7k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4285
75.7k
4286
75.7k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4287
75.7k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4288
75.7k
}
clang::Redeclarable<clang::RedeclarableTemplateDecl>::setPreviousDecl(clang::RedeclarableTemplateDecl*)
Line
Count
Source
4258
344k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4259
344k
  // Note: This routine is implemented here because we need both NamedDecl
4260
344k
  // and Redeclarable to be defined.
4261
344k
  assert(RedeclLink.isFirst() &&
4262
344k
         "setPreviousDecl on a decl already in a redeclaration chain");
4263
344k
4264
344k
  if (PrevDecl) {
4265
88.0k
    // Point to previous. Make sure that this is actually the most recent
4266
88.0k
    // redeclaration, or we can build invalid chains. If the most recent
4267
88.0k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4268
88.0k
    First = PrevDecl->getFirstDecl();
4269
88.0k
    assert(First->RedeclLink.isFirst() && "Expected first");
4270
88.0k
    decl_type *MostRecent = First->getNextRedeclaration();
4271
88.0k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4272
88.0k
4273
88.0k
    // If the declaration was previously visible, a redeclaration of it remains
4274
88.0k
    // visible even if it wouldn't be visible by itself.
4275
88.0k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4276
88.0k
      MostRecent->getIdentifierNamespace() &
4277
88.0k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4278
256k
  } else {
4279
256k
    // Make this first.
4280
256k
    First = static_cast<decl_type*>(this);
4281
256k
  }
4282
344k
4283
344k
  // First one will point to this one as latest.
4284
344k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4285
344k
4286
344k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4287
344k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4288
344k
}
clang::Redeclarable<clang::UsingShadowDecl>::setPreviousDecl(clang::UsingShadowDecl*)
Line
Count
Source
4258
160k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4259
160k
  // Note: This routine is implemented here because we need both NamedDecl
4260
160k
  // and Redeclarable to be defined.
4261
160k
  assert(RedeclLink.isFirst() &&
4262
160k
         "setPreviousDecl on a decl already in a redeclaration chain");
4263
160k
4264
160k
  if (PrevDecl) {
4265
3.11k
    // Point to previous. Make sure that this is actually the most recent
4266
3.11k
    // redeclaration, or we can build invalid chains. If the most recent
4267
3.11k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4268
3.11k
    First = PrevDecl->getFirstDecl();
4269
3.11k
    assert(First->RedeclLink.isFirst() && "Expected first");
4270
3.11k
    decl_type *MostRecent = First->getNextRedeclaration();
4271
3.11k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4272
3.11k
4273
3.11k
    // If the declaration was previously visible, a redeclaration of it remains
4274
3.11k
    // visible even if it wouldn't be visible by itself.
4275
3.11k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4276
3.11k
      MostRecent->getIdentifierNamespace() &
4277
3.11k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4278
157k
  } else {
4279
157k
    // Make this first.
4280
157k
    First = static_cast<decl_type*>(this);
4281
157k
  }
4282
160k
4283
160k
  // First one will point to this one as latest.
4284
160k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4285
160k
4286
160k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4287
160k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4288
160k
}
clang::Redeclarable<clang::NamespaceAliasDecl>::setPreviousDecl(clang::NamespaceAliasDecl*)
Line
Count
Source
4258
12
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4259
12
  // Note: This routine is implemented here because we need both NamedDecl
4260
12
  // and Redeclarable to be defined.
4261
12
  assert(RedeclLink.isFirst() &&
4262
12
         "setPreviousDecl on a decl already in a redeclaration chain");
4263
12
4264
12
  if (PrevDecl) {
4265
12
    // Point to previous. Make sure that this is actually the most recent
4266
12
    // redeclaration, or we can build invalid chains. If the most recent
4267
12
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4268
12
    First = PrevDecl->getFirstDecl();
4269
12
    assert(First->RedeclLink.isFirst() && "Expected first");
4270
12
    decl_type *MostRecent = First->getNextRedeclaration();
4271
12
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4272
12
4273
12
    // If the declaration was previously visible, a redeclaration of it remains
4274
12
    // visible even if it wouldn't be visible by itself.
4275
12
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4276
12
      MostRecent->getIdentifierNamespace() &
4277
12
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4278
12
  } else {
4279
0
    // Make this first.
4280
0
    First = static_cast<decl_type*>(this);
4281
0
  }
4282
12
4283
12
  // First one will point to this one as latest.
4284
12
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4285
12
4286
12
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4287
12
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4288
12
}
clang::Redeclarable<clang::FunctionDecl>::setPreviousDecl(clang::FunctionDecl*)
Line
Count
Source
4258
537k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4259
537k
  // Note: This routine is implemented here because we need both NamedDecl
4260
537k
  // and Redeclarable to be defined.
4261
537k
  assert(RedeclLink.isFirst() &&
4262
537k
         "setPreviousDecl on a decl already in a redeclaration chain");
4263
537k
4264
537k
  if (PrevDecl) {
4265
537k
    // Point to previous. Make sure that this is actually the most recent
4266
537k
    // redeclaration, or we can build invalid chains. If the most recent
4267
537k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4268
537k
    First = PrevDecl->getFirstDecl();
4269
537k
    assert(First->RedeclLink.isFirst() && "Expected first");
4270
537k
    decl_type *MostRecent = First->getNextRedeclaration();
4271
537k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4272
537k
4273
537k
    // If the declaration was previously visible, a redeclaration of it remains
4274
537k
    // visible even if it wouldn't be visible by itself.
4275
537k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4276
537k
      MostRecent->getIdentifierNamespace() &
4277
537k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4278
537k
  } else {
4279
0
    // Make this first.
4280
0
    First = static_cast<decl_type*>(this);
4281
0
  }
4282
537k
4283
537k
  // First one will point to this one as latest.
4284
537k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4285
537k
4286
537k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4287
537k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4288
537k
}
clang::Redeclarable<clang::TagDecl>::setPreviousDecl(clang::TagDecl*)
Line
Count
Source
4258
4.34M
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4259
4.34M
  // Note: This routine is implemented here because we need both NamedDecl
4260
4.34M
  // and Redeclarable to be defined.
4261
4.34M
  assert(RedeclLink.isFirst() &&
4262
4.34M
         "setPreviousDecl on a decl already in a redeclaration chain");
4263
4.34M
4264
4.34M
  if (PrevDecl) {
4265
1.04M
    // Point to previous. Make sure that this is actually the most recent
4266
1.04M
    // redeclaration, or we can build invalid chains. If the most recent
4267
1.04M
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4268
1.04M
    First = PrevDecl->getFirstDecl();
4269
1.04M
    assert(First->RedeclLink.isFirst() && "Expected first");
4270
1.04M
    decl_type *MostRecent = First->getNextRedeclaration();
4271
1.04M
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4272
1.04M
4273
1.04M
    // If the declaration was previously visible, a redeclaration of it remains
4274
1.04M
    // visible even if it wouldn't be visible by itself.
4275
1.04M
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4276
1.04M
      MostRecent->getIdentifierNamespace() &
4277
1.04M
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4278
3.30M
  } else {
4279
3.30M
    // Make this first.
4280
3.30M
    First = static_cast<decl_type*>(this);
4281
3.30M
  }
4282
4.34M
4283
4.34M
  // First one will point to this one as latest.
4284
4.34M
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4285
4.34M
4286
4.34M
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4287
4.34M
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4288
4.34M
}
clang::Redeclarable<clang::NamespaceDecl>::setPreviousDecl(clang::NamespaceDecl*)
Line
Count
Source
4258
120k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4259
120k
  // Note: This routine is implemented here because we need both NamedDecl
4260
120k
  // and Redeclarable to be defined.
4261
120k
  assert(RedeclLink.isFirst() &&
4262
120k
         "setPreviousDecl on a decl already in a redeclaration chain");
4263
120k
4264
120k
  if (PrevDecl) {
4265
73.8k
    // Point to previous. Make sure that this is actually the most recent
4266
73.8k
    // redeclaration, or we can build invalid chains. If the most recent
4267
73.8k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4268
73.8k
    First = PrevDecl->getFirstDecl();
4269
73.8k
    assert(First->RedeclLink.isFirst() && "Expected first");
4270
73.8k
    decl_type *MostRecent = First->getNextRedeclaration();
4271
73.8k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4272
73.8k
4273
73.8k
    // If the declaration was previously visible, a redeclaration of it remains
4274
73.8k
    // visible even if it wouldn't be visible by itself.
4275
73.8k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4276
73.8k
      MostRecent->getIdentifierNamespace() &
4277
73.8k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4278
73.8k
  } else {
4279
46.4k
    // Make this first.
4280
46.4k
    First = static_cast<decl_type*>(this);
4281
46.4k
  }
4282
120k
4283
120k
  // First one will point to this one as latest.
4284
120k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4285
120k
4286
120k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4287
120k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4288
120k
}
clang::Redeclarable<clang::ObjCInterfaceDecl>::setPreviousDecl(clang::ObjCInterfaceDecl*)
Line
Count
Source
4258
29.9k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4259
29.9k
  // Note: This routine is implemented here because we need both NamedDecl
4260
29.9k
  // and Redeclarable to be defined.
4261
29.9k
  assert(RedeclLink.isFirst() &&
4262
29.9k
         "setPreviousDecl on a decl already in a redeclaration chain");
4263
29.9k
4264
29.9k
  if (PrevDecl) {
4265
6.74k
    // Point to previous. Make sure that this is actually the most recent
4266
6.74k
    // redeclaration, or we can build invalid chains. If the most recent
4267
6.74k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4268
6.74k
    First = PrevDecl->getFirstDecl();
4269
6.74k
    assert(First->RedeclLink.isFirst() && "Expected first");
4270
6.74k
    decl_type *MostRecent = First->getNextRedeclaration();
4271
6.74k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4272
6.74k
4273
6.74k
    // If the declaration was previously visible, a redeclaration of it remains
4274
6.74k
    // visible even if it wouldn't be visible by itself.
4275
6.74k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4276
6.74k
      MostRecent->getIdentifierNamespace() &
4277
6.74k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4278
23.1k
  } else {
4279
23.1k
    // Make this first.
4280
23.1k
    First = static_cast<decl_type*>(this);
4281
23.1k
  }
4282
29.9k
4283
29.9k
  // First one will point to this one as latest.
4284
29.9k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4285
29.9k
4286
29.9k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4287
29.9k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4288
29.9k
}
clang::Redeclarable<clang::ObjCProtocolDecl>::setPreviousDecl(clang::ObjCProtocolDecl*)
Line
Count
Source
4258
3.82k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4259
3.82k
  // Note: This routine is implemented here because we need both NamedDecl
4260
3.82k
  // and Redeclarable to be defined.
4261
3.82k
  assert(RedeclLink.isFirst() &&
4262
3.82k
         "setPreviousDecl on a decl already in a redeclaration chain");
4263
3.82k
4264
3.82k
  if (PrevDecl) {
4265
386
    // Point to previous. Make sure that this is actually the most recent
4266
386
    // redeclaration, or we can build invalid chains. If the most recent
4267
386
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4268
386
    First = PrevDecl->getFirstDecl();
4269
386
    assert(First->RedeclLink.isFirst() && "Expected first");
4270
386
    decl_type *MostRecent = First->getNextRedeclaration();
4271
386
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4272
386
4273
386
    // If the declaration was previously visible, a redeclaration of it remains
4274
386
    // visible even if it wouldn't be visible by itself.
4275
386
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4276
386
      MostRecent->getIdentifierNamespace() &
4277
386
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4278
3.44k
  } else {
4279
3.44k
    // Make this first.
4280
3.44k
    First = static_cast<decl_type*>(this);
4281
3.44k
  }
4282
3.82k
4283
3.82k
  // First one will point to this one as latest.
4284
3.82k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4285
3.82k
4286
3.82k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4287
3.82k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4288
3.82k
}
4289
4290
// Inline function definitions.
4291
4292
/// Check if the given decl is complete.
4293
///
4294
/// We use this function to break a cycle between the inline definitions in
4295
/// Type.h and Decl.h.
4296
1.75M
inline bool IsEnumDeclComplete(EnumDecl *ED) {
4297
1.75M
  return ED->isComplete();
4298
1.75M
}
4299
4300
/// Check if the given decl is scoped.
4301
///
4302
/// We use this function to break a cycle between the inline definitions in
4303
/// Type.h and Decl.h.
4304
609k
inline bool IsEnumDeclScoped(EnumDecl *ED) {
4305
609k
  return ED->isScoped();
4306
609k
}
4307
4308
} // namespace clang
4309
4310
#endif // LLVM_CLANG_AST_DECL_H