Coverage Report

Created: 2018-07-22 10:17

/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.getStartLoc().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
44.7M
  TypeSourceInfo(QualType ty) : Ty(ty) {}
94
95
public:
96
  /// Return the type wrapped by this type source info.
97
174M
  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
41.6k
  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
635M
  ASTContext &getASTContext() const { return Ctx; }
120
121
3.89k
  NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
122
441
  void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; }
123
124
  static TranslationUnitDecl *Create(ASTContext &C);
125
126
  // Implement isa/cast/dyncast/etc.
127
615M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
128
670M
  static bool classofKind(Kind K) { return K == TranslationUnit; }
129
9.78k
  static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
130
9.78k
    return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
131
9.78k
  }
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
342k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
168
342k
  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
342k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
201
342k
  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.0k
      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
37.9M
      : 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
160M
  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.22M
  StringRef getName() const {
276
3.22M
    assert(Name.isIdentifier() && "Name is not a simple identifier");
277
3.22M
    return getIdentifier() ? 
getIdentifier()->getName()3.12M
:
""94.5k
;
278
3.22M
  }
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
30.1k
  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
432M
  DeclarationName getDeclName() const { return Name; }
298
299
  /// Set the name of this declaration.
300
472k
  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
29.6M
  bool isCXXClassMember() const {
346
29.6M
    const DeclContext *DC = getDeclContext();
347
29.6M
348
29.6M
    // C++0x [class.mem]p1:
349
29.6M
    //   The enumerators of an unscoped enumeration defined in
350
29.6M
    //   the class are members of the class.
351
29.6M
    if (isa<EnumDecl>(DC))
352
297k
      DC = DC->getRedeclContext();
353
29.6M
354
29.6M
    return DC->isRecord();
355
29.6M
  }
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
6.50M
  Linkage getFormalLinkage() const {
371
6.50M
    return clang::getFormalLinkage(getLinkageInternal());
372
6.50M
  }
373
374
  /// True if this decl has external linkage.
375
19.1M
  bool hasExternalFormalLinkage() const {
376
19.1M
    return isExternalFormalLinkage(getLinkageInternal());
377
19.1M
  }
378
379
22.0M
  bool isExternallyVisible() const {
380
22.0M
    return clang::isExternallyVisible(getLinkageInternal());
381
22.0M
  }
382
383
  /// Determine whether this declaration can be redeclared in a
384
  /// different translation unit.
385
2.21k
  bool isExternallyDeclarable() const {
386
2.21k
    return isExternallyVisible() && 
!getOwningModuleForLinkage()2.11k
;
387
2.21k
  }
388
389
  /// Determines the visibility of this entity.
390
27.9k
  Visibility getVisibility() const {
391
27.9k
    return getLinkageAndVisibility().getVisibility();
392
27.9k
  }
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
227M
  NamedDecl *getUnderlyingDecl() {
432
227M
    // Fast-path the common case.
433
227M
    if (this->getKind() != UsingShadow &&
434
227M
        
this->getKind() != ConstructorUsingShadow225M
&&
435
227M
        
this->getKind() != ObjCCompatibleAlias225M
&&
436
227M
        
this->getKind() != NamespaceAlias225M
)
437
225M
      return this;
438
2.28M
439
2.28M
    return getUnderlyingDeclImpl();
440
2.28M
  }
441
2.04M
  const NamedDecl *getUnderlyingDecl() const {
442
2.04M
    return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
443
2.04M
  }
444
445
22.7M
  NamedDecl *getMostRecentDecl() {
446
22.7M
    return cast<NamedDecl>(static_cast<Decl *>(this)->getMostRecentDecl());
447
22.7M
  }
448
17.2M
  const NamedDecl *getMostRecentDecl() const {
449
17.2M
    return const_cast<NamedDecl*>(this)->getMostRecentDecl();
450
17.2M
  }
451
452
  ObjCStringFormatFamily getObjCFStringFormattingFamily() const;
453
454
45.9M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
455
48.2M
  static bool classofKind(Kind K) { return K >= firstNamed && 
K <= lastNamed46.9M
; }
456
};
457
458
378k
inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) {
459
378k
  ND.printName(OS);
460
378k
  return OS;
461
378k
}
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.16k
      : 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
20.6k
  LabelStmt *getStmt() const { return TheStmt; }
493
3.90k
  void setStmt(LabelStmt *T) { TheStmt = T; }
494
495
7.76k
  bool isGnuLocal() const { return LocStart != getLocation(); }
496
3.88k
  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.2k
  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
53.3M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
510
53.3M
  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.49M
  bool isAnonymousNamespace() const {
571
4.49M
    return !getIdentifier();
572
4.49M
  }
573
574
  /// Returns true if this is an inline namespace declaration.
575
3.64M
  bool isInline() const {
576
3.64M
    return AnonOrFirstNamespaceAndInline.getInt();
577
3.64M
  }
578
579
  /// Set whether this is an inline namespace declaration.
580
875
  void setInline(bool Inline) {
581
875
    AnonOrFirstNamespaceAndInline.setInt(Inline);
582
875
  }
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.09k
  NamespaceDecl *getAnonymousNamespace() const {
598
1.09k
    return getOriginalNamespace()->AnonOrFirstNamespaceAndInline.getPointer();
599
1.09k
  }
600
601
590
  void setAnonymousNamespace(NamespaceDecl *D) {
602
590
    getOriginalNamespace()->AnonOrFirstNamespaceAndInline.setPointer(D);
603
590
  }
604
605
  /// Retrieves the canonical declaration of this namespace.
606
8.36M
  NamespaceDecl *getCanonicalDecl() override {
607
8.36M
    return getOriginalNamespace();
608
8.36M
  }
609
0
  const NamespaceDecl *getCanonicalDecl() const {
610
0
    return getOriginalNamespace();
611
0
  }
612
613
709
  SourceRange getSourceRange() const override LLVM_READONLY {
614
709
    return SourceRange(LocStart, RBraceLoc);
615
709
  }
616
617
687
  SourceLocation getLocStart() const LLVM_READONLY { return LocStart; }
618
642
  SourceLocation getRBraceLoc() const { return RBraceLoc; }
619
0
  void setLocStart(SourceLocation L) { LocStart = L; }
620
112k
  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
621
622
  // Implement isa/cast/dyncast/etc.
623
60.1M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
624
73.7M
  static bool classofKind(Kind K) { return K == Namespace; }
625
4.17k
  static DeclContext *castToDeclContext(const NamespaceDecl *D) {
626
4.17k
    return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
627
4.17k
  }
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
28.1M
    : NamedDecl(DK, DC, L, N), DeclType(T) {}
645
646
public:
647
496M
  QualType getType() const { return DeclType; }
648
1.98M
  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
21.0M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
656
21.0M
  static bool classofKind(Kind K) { return K >= firstValue && 
K <= lastValue20.7M
; }
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
343k
  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
40.0M
  bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); }
702
799k
  ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); }
703
1.24M
  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
27.7M
      : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {}
710
711
public:
712
  friend class ASTDeclReader;
713
  friend class ASTDeclWriter;
714
715
28.9M
  TypeSourceInfo *getTypeSourceInfo() const {
716
28.9M
    return hasExtInfo()
717
28.9M
      ? 
getExtInfo()->TInfo583k
718
28.9M
      : 
DeclInfo.get<TypeSourceInfo*>()28.4M
;
719
28.9M
  }
720
721
172k
  void setTypeSourceInfo(TypeSourceInfo *TI) {
722
172k
    if (hasExtInfo())
723
401
      getExtInfo()->TInfo = TI;
724
172k
    else
725
172k
      DeclInfo = TI;
726
172k
  }
727
728
  /// Return start of source range ignoring outer template declarations.
729
10.2M
  SourceLocation getInnerLocStart() const { return InnerLocStart; }
730
422k
  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
83.4k
  SourceLocation getLocStart() const LLVM_READONLY {
739
83.4k
    return getOuterLocStart();
740
83.4k
  }
741
742
  /// Retrieve the nested-name-specifier that qualifies the name of this
743
  /// declaration, if it was present in the source.
744
1.08M
  NestedNameSpecifier *getQualifier() const {
745
1.08M
    return hasExtInfo() ? 
getExtInfo()->QualifierLoc.getNestedNameSpecifier()465k
746
1.08M
                        : 
nullptr616k
;
747
1.08M
  }
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.21M
  NestedNameSpecifierLoc getQualifierLoc() const {
753
2.21M
    return hasExtInfo() ? 
getExtInfo()->QualifierLoc53.2k
754
2.21M
                        : 
NestedNameSpecifierLoc()2.15M
;
755
2.21M
  }
756
757
  void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
758
759
6.05M
  unsigned getNumTemplateParameterLists() const {
760
6.05M
    return hasExtInfo() ? 
getExtInfo()->NumTemplParamLists126k
:
05.92M
;
761
6.05M
  }
762
763
19.3k
  TemplateParameterList *getTemplateParameterList(unsigned index) const {
764
19.3k
    assert(index < getNumTemplateParameterLists());
765
19.3k
    return getExtInfo()->TemplParamLists[index];
766
19.3k
  }
767
768
  void setTemplateParameterListsInfo(ASTContext &Context,
769
                                     ArrayRef<TemplateParameterList *> TPLists);
770
771
  SourceLocation getTypeSpecStartLoc() const;
772
773
  // Implement isa/cast/dyncast/etc.
774
8.46M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
775
8.46M
  static bool classofKind(Kind K) {
776
8.46M
    return K >= firstDeclarator && 
K <= lastDeclarator6.85M
;
777
8.46M
  }
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
445k
                    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
10.3M
  VarDecl *getNextRedeclarationImpl() override {
984
10.3M
    return getNextRedeclaration();
985
10.3M
  }
986
987
20.8k
  VarDecl *getPreviousDeclImpl() override {
988
20.8k
    return getPreviousDecl();
989
20.8k
  }
990
991
36.2M
  VarDecl *getMostRecentDeclImpl() override {
992
36.2M
    return getMostRecentDecl();
993
36.2M
  }
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
116M
  StorageClass getStorageClass() const {
1018
116M
    return (StorageClass) VarDeclBits.SClass;
1019
116M
  }
1020
  void setStorageClass(StorageClass SC);
1021
1022
311k
  void setTSCSpec(ThreadStorageClassSpecifier TSC) {
1023
311k
    VarDeclBits.TSCSpec = TSC;
1024
311k
    assert(VarDeclBits.TSCSpec == TSC && "truncation");
1025
311k
  }
1026
39.8M
  ThreadStorageClassSpecifier getTSCSpec() const {
1027
39.8M
    return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec);
1028
39.8M
  }
1029
  TLSKind getTLSKind() const;
1030
1031
  /// Returns true if a variable with function scope is a non-static local
1032
  /// variable.
1033
44.6M
  bool hasLocalStorage() const {
1034
44.6M
    if (getStorageClass() == SC_None) {
1035
37.1M
      // OpenCL v1.2 s6.5.3: The __constant or constant address space name is
1036
37.1M
      // used to describe variables allocated in global memory and which are
1037
37.1M
      // accessed inside a kernel(s) as read-only variables. As such, variables
1038
37.1M
      // in constant address space cannot have local storage.
1039
37.1M
      if (getType().getAddressSpace() == LangAS::opencl_constant)
1040
1.12k
        return false;
1041
37.1M
      // Second check is for C++11 [dcl.stc]p4.
1042
37.1M
      return !isFileVarDecl() && 
getTSCSpec() == TSCS_unspecified33.3M
;
1043
37.1M
    }
1044
7.46M
1045
7.46M
    // Global Named Register (GNU extension)
1046
7.46M
    if (getStorageClass() == SC_Register && 
!isLocalVarDeclOrParm()103k
)
1047
808
      return false;
1048
7.46M
1049
7.46M
    // Return true for:  Auto, Register.
1050
7.46M
    // Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal.
1051
7.46M
1052
7.46M
    return getStorageClass() >= SC_Auto;
1053
7.46M
  }
1054
1055
  /// Returns true if a variable with function scope is a static local
1056
  /// variable.
1057
7.22M
  bool isStaticLocal() const {
1058
7.22M
    return (getStorageClass() == SC_Static ||
1059
7.22M
            // C++11 [dcl.stc]p4
1060
7.22M
            
(6.17M
getStorageClass() == SC_None6.17M
&&
getTSCSpec() == TSCS_thread_local5.84M
))
1061
7.22M
      && 
!isFileVarDecl()1.04M
;
1062
7.22M
  }
1063
1064
  /// Returns true if a variable has extern or __private_extern__
1065
  /// storage.
1066
17.1M
  bool hasExternalStorage() const {
1067
17.1M
    return getStorageClass() == SC_Extern ||
1068
17.1M
           
getStorageClass() == SC_PrivateExtern16.2M
;
1069
17.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
11.6M
  bool hasGlobalStorage() const { return !hasLocalStorage(); }
1076
1077
  /// Get the storage duration of this variable, per C++ [basic.stc].
1078
819k
  StorageDuration getStorageDuration() const {
1079
819k
    return hasLocalStorage() ? 
SD_Automatic799k
:
1080
819k
           
getTSCSpec() 19.7k
?
SD_Thread154
:
SD_Static19.5k
;
1081
819k
  }
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.20M
  bool isLocalVarDecl() const {
1103
9.20M
    if (getKind() != Decl::Var && 
getKind() != Decl::Decomposition998k
)
1104
997k
      return false;
1105
8.21M
    if (const DeclContext *DC = getLexicalDeclContext())
1106
8.21M
      return DC->getRedeclContext()->isFunctionOrMethod();
1107
0
    return false;
1108
0
  }
1109
1110
  /// Similar to isLocalVarDecl but also includes parameters.
1111
184k
  bool isLocalVarDeclOrParm() const {
1112
184k
    return isLocalVarDecl() || 
getKind() == Decl::ParmVar86.0k
;
1113
184k
  }
1114
1115
  /// Similar to isLocalVarDecl, but excludes variables declared in blocks.
1116
192k
  bool isFunctionOrMethodVarDecl() const {
1117
192k
    if (getKind() != Decl::Var && 
getKind() != Decl::Decomposition67.9k
)
1118
67.9k
      return false;
1119
124k
    const DeclContext *DC = getLexicalDeclContext()->getRedeclContext();
1120
124k
    return DC->isFunctionOrMethod() && 
DC->getDeclKind() != Decl::Block110k
;
1121
124k
  }
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
180M
  bool isStaticDataMember() const {
1133
180M
    // If it wasn't static, it would be a FieldDecl.
1134
180M
    return getKind() != Decl::ParmVar && 
getDeclContext()->isRecord()160M
;
1135
180M
  }
1136
1137
  VarDecl *getCanonicalDecl() override;
1138
11.2M
  const VarDecl *getCanonicalDecl() const {
1139
11.2M
    return const_cast<VarDecl*>(this)->getCanonicalDecl();
1140
11.2M
  }
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
11.8M
  DefinitionKind isThisDeclarationADefinition() const {
1158
11.8M
    return isThisDeclarationADefinition(getASTContext());
1159
11.8M
  }
1160
1161
  /// Check whether this variable is defined in this translation unit.
1162
  DefinitionKind hasDefinition(ASTContext &) const;
1163
39.4k
  DefinitionKind hasDefinition() const {
1164
39.4k
    return hasDefinition(getASTContext());
1165
39.4k
  }
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.54M
  const VarDecl *getDefinition(ASTContext &C) const {
1177
6.54M
    return const_cast<VarDecl*>(this)->getDefinition(C);
1178
6.54M
  }
1179
3.95M
  VarDecl *getDefinition() {
1180
3.95M
    return getDefinition(getASTContext());
1181
3.95M
  }
1182
4.37k
  const VarDecl *getDefinition() const {
1183
4.37k
    return const_cast<VarDecl*>(this)->getDefinition();
1184
4.37k
  }
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
49.4M
  bool isFileVarDecl() const {
1192
49.4M
    Kind K = getKind();
1193
49.4M
    if (K == ParmVar || 
K == ImplicitParam41.5M
)
1194
8.46M
      return false;
1195
40.9M
1196
40.9M
    if (getLexicalDeclContext()->getRedeclContext()->isFileContext())
1197
6.14M
      return true;
1198
34.8M
1199
34.8M
    if (isStaticDataMember())
1200
1.60M
      return true;
1201
33.2M
1202
33.2M
    return false;
1203
33.2M
  }
1204
1205
  /// Get the initializer for this variable, no matter which
1206
  /// declaration it is attached to.
1207
1.80M
  const Expr *getAnyInitializer() const {
1208
1.80M
    const VarDecl *D;
1209
1.80M
    return getAnyInitializer(D);
1210
1.80M
  }
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
2.96M
  const Expr *getInit() const {
1218
2.96M
    return const_cast<VarDecl *>(this)->getInit();
1219
2.96M
  }
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
464k
  void setInitStyle(InitializationStyle Style) {
1263
464k
    VarDeclBits.InitStyle = Style;
1264
464k
  }
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.40M
  InitializationStyle getInitStyle() const {
1277
1.40M
    return static_cast<InitializationStyle>(VarDeclBits.InitStyle);
1278
1.40M
  }
1279
1280
  /// Whether the initializer is a direct-initializer (list or call).
1281
281k
  bool isDirectInit() const {
1282
281k
    return getInitStyle() != CInit;
1283
281k
  }
1284
1285
  /// If this definition should pretend to be a declaration.
1286
31.7M
  bool isThisDeclarationADemotedDefinition() const {
1287
31.7M
    return isa<ParmVarDecl>(this) ? 
false5.61M
:
1288
31.7M
      
NonParmVarDeclBits.IsThisDeclarationADemotedDefinition26.1M
;
1289
31.7M
  }
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
27
  void demoteThisDefinitionToDeclaration() {
1297
27
    assert(isThisDeclarationADefinition() && "Not a definition!");
1298
27
    assert(!isa<ParmVarDecl>(this) && "Cannot demote ParmVarDecls!");
1299
27
    NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = 1;
1300
27
  }
1301
1302
  /// Determine whether this variable is the exception variable in a
1303
  /// C++ catch statememt or an Objective-C \@catch statement.
1304
2.27M
  bool isExceptionVariable() const {
1305
2.27M
    return isa<ParmVarDecl>(this) ? 
false2.83k
:
NonParmVarDeclBits.ExceptionVar2.27M
;
1306
2.27M
  }
1307
908
  void setExceptionVariable(bool EV) {
1308
908
    assert(!isa<ParmVarDecl>(this));
1309
908
    NonParmVarDeclBits.ExceptionVar = EV;
1310
908
  }
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
862k
  bool isNRVOVariable() const {
1323
862k
    return isa<ParmVarDecl>(this) ? 
false856
:
NonParmVarDeclBits.NRVOVariable861k
;
1324
862k
  }
1325
34.2k
  void setNRVOVariable(bool NRVO) {
1326
34.2k
    assert(!isa<ParmVarDecl>(this));
1327
34.2k
    NonParmVarDeclBits.NRVOVariable = NRVO;
1328
34.2k
  }
1329
1330
  /// Determine whether this variable is the for-range-declaration in
1331
  /// a C++0x for-range statement.
1332
478k
  bool isCXXForRangeDecl() const {
1333
478k
    return isa<ParmVarDecl>(this) ? 
false0
: NonParmVarDeclBits.CXXForRangeDecl;
1334
478k
  }
1335
313k
  void setCXXForRangeDecl(bool FRD) {
1336
313k
    assert(!isa<ParmVarDecl>(this));
1337
313k
    NonParmVarDeclBits.CXXForRangeDecl = FRD;
1338
313k
  }
1339
1340
  /// Determine whether this variable is a for-loop declaration for a
1341
  /// for-in statement in Objective-C.
1342
452k
  bool isObjCForDecl() const {
1343
452k
    return NonParmVarDeclBits.ObjCForDecl;
1344
452k
  }
1345
1346
310k
  void setObjCForDecl(bool FRD) {
1347
310k
    NonParmVarDeclBits.ObjCForDecl = FRD;
1348
310k
  }
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
124k
  bool isARCPseudoStrong() const {
1355
124k
    return isa<ParmVarDecl>(this) ? 
false181
:
NonParmVarDeclBits.ARCPseudoStrong124k
;
1356
124k
  }
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
15.6M
  bool isInline() const {
1364
15.6M
    return isa<ParmVarDecl>(this) ? 
false856
:
NonParmVarDeclBits.IsInline15.6M
;
1365
15.6M
  }
1366
434k
  bool isInlineSpecified() const {
1367
434k
    return isa<ParmVarDecl>(this) ? 
false0
1368
434k
                                  : NonParmVarDeclBits.IsInlineSpecified;
1369
434k
  }
1370
142
  void setInlineSpecified() {
1371
142
    assert(!isa<ParmVarDecl>(this));
1372
142
    NonParmVarDeclBits.IsInline = true;
1373
142
    NonParmVarDeclBits.IsInlineSpecified = true;
1374
142
  }
1375
180
  void setImplicitlyInline() {
1376
180
    assert(!isa<ParmVarDecl>(this));
1377
180
    NonParmVarDeclBits.IsInline = true;
1378
180
  }
1379
1380
  /// Whether this variable is (C++11) constexpr.
1381
17.6M
  bool isConstexpr() const {
1382
17.6M
    return isa<ParmVarDecl>(this) ? 
false1.71M
:
NonParmVarDeclBits.IsConstexpr15.9M
;
1383
17.6M
  }
1384
480k
  void setConstexpr(bool IC) {
1385
480k
    assert(!isa<ParmVarDecl>(this));
1386
480k
    NonParmVarDeclBits.IsConstexpr = IC;
1387
480k
  }
1388
1389
  /// Whether this variable is the implicit variable for a lambda init-capture.
1390
35.6M
  bool isInitCapture() const {
1391
35.6M
    return isa<ParmVarDecl>(this) ? 
false17.4M
:
NonParmVarDeclBits.IsInitCapture18.2M
;
1392
35.6M
  }
1393
310k
  void setInitCapture(bool IC) {
1394
310k
    assert(!isa<ParmVarDecl>(this));
1395
310k
    NonParmVarDeclBits.IsInitCapture = IC;
1396
310k
  }
1397
1398
  /// Whether this local extern variable declaration's previous declaration
1399
  /// was declared in the same block scope. Only correct in C++.
1400
508k
  bool isPreviousDeclInSameBlockScope() const {
1401
508k
    return isa<ParmVarDecl>(this)
1402
508k
               ? 
false0
1403
508k
               : NonParmVarDeclBits.PreviousDeclInSameBlockScope;
1404
508k
  }
1405
310k
  void setPreviousDeclInSameBlockScope(bool Same) {
1406
310k
    assert(!isa<ParmVarDecl>(this));
1407
310k
    NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
1408
310k
  }
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
  // Implement isa/cast/dyncast/etc.
1465
214M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1466
214M
  static bool classofKind(Kind K) { return K >= firstVar && 
K <= lastVar108M
; }
1467
};
1468
1469
class ImplicitParamDecl : public VarDecl {
1470
  void anchor() override;
1471
1472
public:
1473
  /// Defines the kind of the implicit parameter: is this an implicit parameter
1474
  /// with pointer to 'this', 'self', '_cmd', virtual table pointers, captured
1475
  /// context or something else.
1476
  enum ImplicitParamKind : unsigned {
1477
    /// Parameter for Objective-C 'self' argument
1478
    ObjCSelf,
1479
1480
    /// Parameter for Objective-C '_cmd' argument
1481
    ObjCCmd,
1482
1483
    /// Parameter for C++ 'this' argument
1484
    CXXThis,
1485
1486
    /// Parameter for C++ virtual table pointers
1487
    CXXVTT,
1488
1489
    /// Parameter for captured context
1490
    CapturedContext,
1491
1492
    /// Other implicit parameter
1493
    Other,
1494
  };
1495
1496
  /// Create implicit parameter.
1497
  static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC,
1498
                                   SourceLocation IdLoc, IdentifierInfo *Id,
1499
                                   QualType T, ImplicitParamKind ParamKind);
1500
  static ImplicitParamDecl *Create(ASTContext &C, QualType T,
1501
                                   ImplicitParamKind ParamKind);
1502
1503
  static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1504
1505
  ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc,
1506
                    IdentifierInfo *Id, QualType Type,
1507
                    ImplicitParamKind ParamKind)
1508
      : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
1509
1.21M
                /*TInfo=*/nullptr, SC_None) {
1510
1.21M
    NonParmVarDeclBits.ImplicitParamKind = ParamKind;
1511
1.21M
    setImplicit();
1512
1.21M
  }
1513
1514
  ImplicitParamDecl(ASTContext &C, QualType Type, ImplicitParamKind ParamKind)
1515
      : VarDecl(ImplicitParam, C, /*DC=*/nullptr, SourceLocation(),
1516
                SourceLocation(), /*Id=*/nullptr, Type,
1517
68.6k
                /*TInfo=*/nullptr, SC_None) {
1518
68.6k
    NonParmVarDeclBits.ImplicitParamKind = ParamKind;
1519
68.6k
    setImplicit();
1520
68.6k
  }
1521
1522
  /// Returns the implicit parameter kind.
1523
68.8k
  ImplicitParamKind getParameterKind() const {
1524
68.8k
    return static_cast<ImplicitParamKind>(NonParmVarDeclBits.ImplicitParamKind);
1525
68.8k
  }
1526
1527
  // Implement isa/cast/dyncast/etc.
1528
1.00M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1529
1.00M
  static bool classofKind(Kind K) { return K == ImplicitParam; }
1530
};
1531
1532
/// Represents a parameter to a function.
1533
class ParmVarDecl : public VarDecl {
1534
public:
1535
  enum { MaxFunctionScopeDepth = 255 };
1536
  enum { MaxFunctionScopeIndex = 255 };
1537
1538
protected:
1539
  ParmVarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1540
              SourceLocation IdLoc, IdentifierInfo *Id, QualType T,
1541
              TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
1542
12.5M
      : VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) {
1543
12.5M
    assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
1544
12.5M
    assert(ParmVarDeclBits.DefaultArgKind == DAK_None);
1545
12.5M
    assert(ParmVarDeclBits.IsKNRPromoted == false);
1546
12.5M
    assert(ParmVarDeclBits.IsObjCMethodParam == false);
1547
12.5M
    setDefaultArg(DefArg);
1548
12.5M
  }
1549
1550
public:
1551
  static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
1552
                             SourceLocation StartLoc,
1553
                             SourceLocation IdLoc, IdentifierInfo *Id,
1554
                             QualType T, TypeSourceInfo *TInfo,
1555
                             StorageClass S, Expr *DefArg);
1556
1557
  static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1558
1559
  SourceRange getSourceRange() const override LLVM_READONLY;
1560
1561
65.1k
  void setObjCMethodScopeInfo(unsigned parameterIndex) {
1562
65.1k
    ParmVarDeclBits.IsObjCMethodParam = true;
1563
65.1k
    setParameterIndex(parameterIndex);
1564
65.1k
  }
1565
1566
12.0M
  void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) {
1567
12.0M
    assert(!ParmVarDeclBits.IsObjCMethodParam);
1568
12.0M
1569
12.0M
    ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth;
1570
12.0M
    assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth
1571
12.0M
           && "truncation!");
1572
12.0M
1573
12.0M
    setParameterIndex(parameterIndex);
1574
12.0M
  }
1575
1576
145k
  bool isObjCMethodParameter() const {
1577
145k
    return ParmVarDeclBits.IsObjCMethodParam;
1578
145k
  }
1579
1580
2.27M
  unsigned getFunctionScopeDepth() const {
1581
2.27M
    if (ParmVarDeclBits.IsObjCMethodParam) 
return 0263
;
1582
2.27M
    return ParmVarDeclBits.ScopeDepthOrObjCQuals;
1583
2.27M
  }
1584
1585
  /// Returns the index of this parameter in its prototype or method scope.
1586
7.09M
  unsigned getFunctionScopeIndex() const {
1587
7.09M
    return getParameterIndex();
1588
7.09M
  }
1589
1590
246k
  ObjCDeclQualifier getObjCDeclQualifier() const {
1591
246k
    if (!ParmVarDeclBits.IsObjCMethodParam) 
return OBJC_TQ_None239k
;
1592
7.31k
    return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals);
1593
7.31k
  }
1594
65.0k
  void setObjCDeclQualifier(ObjCDeclQualifier QTVal) {
1595
65.0k
    assert(ParmVarDeclBits.IsObjCMethodParam);
1596
65.0k
    ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal;
1597
65.0k
  }
1598
1599
  /// True if the value passed to this parameter must undergo
1600
  /// K&R-style default argument promotion:
1601
  ///
1602
  /// C99 6.5.2.2.
1603
  ///   If the expression that denotes the called function has a type
1604
  ///   that does not include a prototype, the integer promotions are
1605
  ///   performed on each argument, and arguments that have type float
1606
  ///   are promoted to double.
1607
607k
  bool isKNRPromoted() const {
1608
607k
    return ParmVarDeclBits.IsKNRPromoted;
1609
607k
  }
1610
399
  void setKNRPromoted(bool promoted) {
1611
399
    ParmVarDeclBits.IsKNRPromoted = promoted;
1612
399
  }
1613
1614
  Expr *getDefaultArg();
1615
2.38k
  const Expr *getDefaultArg() const {
1616
2.38k
    return const_cast<ParmVarDecl *>(this)->getDefaultArg();
1617
2.38k
  }
1618
1619
  void setDefaultArg(Expr *defarg);
1620
1621
  /// Retrieve the source range that covers the entire default
1622
  /// argument.
1623
  SourceRange getDefaultArgRange() const;
1624
  void setUninstantiatedDefaultArg(Expr *arg);
1625
  Expr *getUninstantiatedDefaultArg();
1626
1
  const Expr *getUninstantiatedDefaultArg() const {
1627
1
    return const_cast<ParmVarDecl *>(this)->getUninstantiatedDefaultArg();
1628
1
  }
1629
1630
  /// Determines whether this parameter has a default argument,
1631
  /// either parsed or not.
1632
  bool hasDefaultArg() const;
1633
1634
  /// Determines whether this parameter has a default argument that has not
1635
  /// yet been parsed. This will occur during the processing of a C++ class
1636
  /// whose member functions have default arguments, e.g.,
1637
  /// @code
1638
  ///   class X {
1639
  ///   public:
1640
  ///     void f(int x = 17); // x has an unparsed default argument now
1641
  ///   }; // x has a regular default argument now
1642
  /// @endcode
1643
40.4M
  bool hasUnparsedDefaultArg() const {
1644
40.4M
    return ParmVarDeclBits.DefaultArgKind == DAK_Unparsed;
1645
40.4M
  }
1646
1647
38.6M
  bool hasUninstantiatedDefaultArg() const {
1648
38.6M
    return ParmVarDeclBits.DefaultArgKind == DAK_Uninstantiated;
1649
38.6M
  }
1650
1651
  /// Specify that this parameter has an unparsed default argument.
1652
  /// The argument will be replaced with a real default argument via
1653
  /// setDefaultArg when the class definition enclosing the function
1654
  /// declaration that owns this default argument is completed.
1655
77.6k
  void setUnparsedDefaultArg() {
1656
77.6k
    ParmVarDeclBits.DefaultArgKind = DAK_Unparsed;
1657
77.6k
  }
1658
1659
2.22M
  bool hasInheritedDefaultArg() const {
1660
2.22M
    return ParmVarDeclBits.HasInheritedDefaultArg;
1661
2.22M
  }
1662
1663
1.97M
  void setHasInheritedDefaultArg(bool I = true) {
1664
1.97M
    ParmVarDeclBits.HasInheritedDefaultArg = I;
1665
1.97M
  }
1666
1667
  QualType getOriginalType() const;
1668
1669
  /// Determine whether this parameter is actually a function
1670
  /// parameter pack.
1671
  bool isParameterPack() const;
1672
1673
  /// Sets the function declaration that owns this
1674
  /// ParmVarDecl. Since ParmVarDecls are often created before the
1675
  /// FunctionDecls that own them, this routine is required to update
1676
  /// the DeclContext appropriately.
1677
6.14M
  void setOwningFunction(DeclContext *FD) { setDeclContext(FD); }
1678
1679
  // Implement isa/cast/dyncast/etc.
1680
234M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1681
234M
  static bool classofKind(Kind K) { return K == ParmVar; }
1682
1683
private:
1684
  enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };
1685
1686
12.1M
  void setParameterIndex(unsigned parameterIndex) {
1687
12.1M
    if (parameterIndex >= ParameterIndexSentinel) {
1688
47
      setParameterIndexLarge(parameterIndex);
1689
47
      return;
1690
47
    }
1691
12.1M
1692
12.1M
    ParmVarDeclBits.ParameterIndex = parameterIndex;
1693
12.1M
    assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
1694
12.1M
  }
1695
7.09M
  unsigned getParameterIndex() const {
1696
7.09M
    unsigned d = ParmVarDeclBits.ParameterIndex;
1697
7.09M
    return d == ParameterIndexSentinel ? 
getParameterIndexLarge()2
:
d7.09M
;
1698
7.09M
  }
1699
1700
  void setParameterIndexLarge(unsigned parameterIndex);
1701
  unsigned getParameterIndexLarge() const;
1702
};
1703
1704
/// Represents a function declaration or definition.
1705
///
1706
/// Since a given function can be declared several times in a program,
1707
/// there may be several FunctionDecls that correspond to that
1708
/// function. Only one of those FunctionDecls will be found when
1709
/// traversing the list of declarations in the context of the
1710
/// FunctionDecl (e.g., the translation unit); this FunctionDecl
1711
/// contains all of the information known about the function. Other,
1712
/// previous declarations of the function are available via the
1713
/// getPreviousDecl() chain.
1714
class FunctionDecl : public DeclaratorDecl, public DeclContext,
1715
                     public Redeclarable<FunctionDecl> {
1716
public:
1717
  /// The kind of templated function a FunctionDecl can be.
1718
  enum TemplatedKind {
1719
    TK_NonTemplate,
1720
    TK_FunctionTemplate,
1721
    TK_MemberSpecialization,
1722
    TK_FunctionTemplateSpecialization,
1723
    TK_DependentFunctionTemplateSpecialization
1724
  };
1725
1726
private:
1727
  /// A new[]'d array of pointers to VarDecls for the formal
1728
  /// parameters of this function.  This is null if a prototype or if there are
1729
  /// no formals.
1730
  ParmVarDecl **ParamInfo = nullptr;
1731
1732
  LazyDeclStmtPtr Body;
1733
1734
  // FIXME: This can be packed into the bitfields in DeclContext.
1735
  // NOTE: VC++ packs bitfields poorly if the types differ.
1736
  unsigned SClass : 3;
1737
  unsigned IsInline : 1;
1738
  unsigned IsInlineSpecified : 1;
1739
1740
protected:
1741
  // This is shared by CXXConstructorDecl, CXXConversionDecl, and
1742
  // CXXDeductionGuideDecl.
1743
  unsigned IsExplicitSpecified : 1;
1744
1745
private:
1746
  unsigned IsVirtualAsWritten : 1;
1747
  unsigned IsPure : 1;
1748
  unsigned HasInheritedPrototype : 1;
1749
  unsigned HasWrittenPrototype : 1;
1750
  unsigned IsDeleted : 1;
1751
  unsigned IsTrivial : 1; // sunk from CXXMethodDecl
1752
1753
  /// This flag indicates whether this function is trivial for the purpose of
1754
  /// calls. This is meaningful only when this function is a copy/move
1755
  /// constructor or a destructor.
1756
  unsigned IsTrivialForCall : 1;
1757
1758
  unsigned IsDefaulted : 1; // sunk from CXXMethoDecl
1759
  unsigned IsExplicitlyDefaulted : 1; //sunk from CXXMethodDecl
1760
  unsigned HasImplicitReturnZero : 1;
1761
  unsigned IsLateTemplateParsed : 1;
1762
  unsigned IsConstexpr : 1;
1763
  unsigned InstantiationIsPending : 1;
1764
1765
  /// Indicates if the function uses __try.
1766
  unsigned UsesSEHTry : 1;
1767
1768
  /// Indicates if the function was a definition but its body was
1769
  /// skipped.
1770
  unsigned HasSkippedBody : 1;
1771
1772
  /// Indicates if the function declaration will have a body, once we're done
1773
  /// parsing it.
1774
  unsigned WillHaveBody : 1;
1775
1776
  /// Indicates that this function is a multiversioned function using attribute
1777
  /// 'target'.
1778
  unsigned IsMultiVersion : 1;
1779
1780
protected:
1781
  /// [C++17] Only used by CXXDeductionGuideDecl. Declared here to avoid
1782
  /// increasing the size of CXXDeductionGuideDecl by the size of an unsigned
1783
  /// int as opposed to adding a single bit to FunctionDecl.
1784
  /// Indicates that the Deduction Guide is the implicitly generated 'copy
1785
  /// deduction candidate' (is used during overload resolution).
1786
  unsigned IsCopyDeductionCandidate : 1;
1787
1788
private:
1789
1790
  /// Store the ODRHash after first calculation.
1791
  unsigned HasODRHash : 1;
1792
  unsigned ODRHash;
1793
1794
  /// End part of this FunctionDecl's source range.
1795
  ///
1796
  /// We could compute the full range in getSourceRange(). However, when we're
1797
  /// dealing with a function definition deserialized from a PCH/AST file,
1798
  /// we can only compute the full range once the function body has been
1799
  /// de-serialized, so it's far better to have the (sometimes-redundant)
1800
  /// EndRangeLoc.
1801
  SourceLocation EndRangeLoc;
1802
1803
  /// The template or declaration that this declaration
1804
  /// describes or was instantiated from, respectively.
1805
  ///
1806
  /// For non-templates, this value will be NULL. For function
1807
  /// declarations that describe a function template, this will be a
1808
  /// pointer to a FunctionTemplateDecl. For member functions
1809
  /// of class template specializations, this will be a MemberSpecializationInfo
1810
  /// pointer containing information about the specialization.
1811
  /// For function template specializations, this will be a
1812
  /// FunctionTemplateSpecializationInfo, which contains information about
1813
  /// the template being specialized and the template arguments involved in
1814
  /// that specialization.
1815
  llvm::PointerUnion4<FunctionTemplateDecl *,
1816
                      MemberSpecializationInfo *,
1817
                      FunctionTemplateSpecializationInfo *,
1818
                      DependentFunctionTemplateSpecializationInfo *>
1819
    TemplateOrSpecialization;
1820
1821
  /// Provides source/type location info for the declaration name embedded in
1822
  /// the DeclaratorDecl base class.
1823
  DeclarationNameLoc DNLoc;
1824
1825
  /// Specify that this function declaration is actually a function
1826
  /// template specialization.
1827
  ///
1828
  /// \param C the ASTContext.
1829
  ///
1830
  /// \param Template the function template that this function template
1831
  /// specialization specializes.
1832
  ///
1833
  /// \param TemplateArgs the template arguments that produced this
1834
  /// function template specialization from the template.
1835
  ///
1836
  /// \param InsertPos If non-NULL, the position in the function template
1837
  /// specialization set where the function template specialization data will
1838
  /// be inserted.
1839
  ///
1840
  /// \param TSK the kind of template specialization this is.
1841
  ///
1842
  /// \param TemplateArgsAsWritten location info of template arguments.
1843
  ///
1844
  /// \param PointOfInstantiation point at which the function template
1845
  /// specialization was first instantiated.
1846
  void setFunctionTemplateSpecialization(ASTContext &C,
1847
                                         FunctionTemplateDecl *Template,
1848
                                       const TemplateArgumentList *TemplateArgs,
1849
                                         void *InsertPos,
1850
                                         TemplateSpecializationKind TSK,
1851
                          const TemplateArgumentListInfo *TemplateArgsAsWritten,
1852
                                         SourceLocation PointOfInstantiation);
1853
1854
  /// Specify that this record is an instantiation of the
1855
  /// member function FD.
1856
  void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD,
1857
                                        TemplateSpecializationKind TSK);
1858
1859
  void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo);
1860
1861
protected:
1862
  FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1863
               const DeclarationNameInfo &NameInfo, QualType T,
1864
               TypeSourceInfo *TInfo, StorageClass S, bool isInlineSpecified,
1865
               bool isConstexprSpecified)
1866
      : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo,
1867
                       StartLoc),
1868
        DeclContext(DK), redeclarable_base(C), SClass(S),
1869
        IsInline(isInlineSpecified), IsInlineSpecified(isInlineSpecified),
1870
        IsExplicitSpecified(false), IsVirtualAsWritten(false), IsPure(false),
1871
        HasInheritedPrototype(false), HasWrittenPrototype(true),
1872
        IsDeleted(false), IsTrivial(false), IsTrivialForCall(false),
1873
        IsDefaulted(false),
1874
        IsExplicitlyDefaulted(false), HasImplicitReturnZero(false),
1875
        IsLateTemplateParsed(false), IsConstexpr(isConstexprSpecified),
1876
        InstantiationIsPending(false), UsesSEHTry(false), HasSkippedBody(false),
1877
        WillHaveBody(false), IsMultiVersion(false),
1878
        IsCopyDeductionCandidate(false), HasODRHash(false), ODRHash(0),
1879
7.76M
        EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) {}
1880
1881
  using redeclarable_base = Redeclarable<FunctionDecl>;
1882
1883
1.90M
  FunctionDecl *getNextRedeclarationImpl() override {
1884
1.90M
    return getNextRedeclaration();
1885
1.90M
  }
1886
1887
3.63M
  FunctionDecl *getPreviousDeclImpl() override {
1888
3.63M
    return getPreviousDecl();
1889
3.63M
  }
1890
1891
23.7M
  FunctionDecl *getMostRecentDeclImpl() override {
1892
23.7M
    return getMostRecentDecl();
1893
23.7M
  }
1894
1895
public:
1896
  friend class ASTDeclReader;
1897
  friend class ASTDeclWriter;
1898
1899
  using redecl_range = redeclarable_base::redecl_range;
1900
  using redecl_iterator = redeclarable_base::redecl_iterator;
1901
1902
  using redeclarable_base::redecls_begin;
1903
  using redeclarable_base::redecls_end;
1904
  using redeclarable_base::redecls;
1905
  using redeclarable_base::getPreviousDecl;
1906
  using redeclarable_base::getMostRecentDecl;
1907
  using redeclarable_base::isFirstDecl;
1908
1909
  static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
1910
                              SourceLocation StartLoc, SourceLocation NLoc,
1911
                              DeclarationName N, QualType T,
1912
                              TypeSourceInfo *TInfo,
1913
                              StorageClass SC,
1914
                              bool isInlineSpecified = false,
1915
                              bool hasWrittenPrototype = true,
1916
496k
                              bool isConstexprSpecified = false) {
1917
496k
    DeclarationNameInfo NameInfo(N, NLoc);
1918
496k
    return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo,
1919
496k
                                SC,
1920
496k
                                isInlineSpecified, hasWrittenPrototype,
1921
496k
                                isConstexprSpecified);
1922
496k
  }
1923
1924
  static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
1925
                              SourceLocation StartLoc,
1926
                              const DeclarationNameInfo &NameInfo,
1927
                              QualType T, TypeSourceInfo *TInfo,
1928
                              StorageClass SC,
1929
                              bool isInlineSpecified,
1930
                              bool hasWrittenPrototype,
1931
                              bool isConstexprSpecified = false);
1932
1933
  static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1934
                       
1935
1.51M
  DeclarationNameInfo getNameInfo() const {
1936
1.51M
    return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
1937
1.51M
  }
1938
1939
  void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
1940
                            bool Qualified) const override;
1941
1942
6.76M
  void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
1943
1944
  SourceRange getSourceRange() const override LLVM_READONLY;
1945
1946
  // Function definitions.
1947
  //
1948
  // A function declaration may be:
1949
  // - a non defining declaration,
1950
  // - a definition. A function may be defined because:
1951
  //   - it has a body, or will have it in the case of late parsing.
1952
  //   - it has an uninstantiated body. The body does not exist because the
1953
  //     function is not used yet, but the declaration is considered a
1954
  //     definition and does not allow other definition of this function.
1955
  //   - it does not have a user specified body, but it does not allow
1956
  //     redefinition, because it is deleted/defaulted or is defined through
1957
  //     some other mechanism (alias, ifunc).
1958
1959
  /// Returns true if the function has a body.
1960
  ///
1961
  /// The function body might be in any of the (re-)declarations of this
1962
  /// function. The variant that accepts a FunctionDecl pointer will set that
1963
  /// function declaration to the actual declaration containing the body (if
1964
  /// there is one).
1965
  bool hasBody(const FunctionDecl *&Definition) const;
1966
1967
816k
  bool hasBody() const override {
1968
816k
    const FunctionDecl* Definition;
1969
816k
    return hasBody(Definition);
1970
816k
  }
1971
1972
  /// Returns whether the function has a trivial body that does not require any
1973
  /// specific codegen.
1974
  bool hasTrivialBody() const;
1975
1976
  /// Returns true if the function has a definition that does not need to be
1977
  /// instantiated.
1978
  ///
1979
  /// The variant that accepts a FunctionDecl pointer will set that function
1980
  /// declaration to the declaration that is a definition (if there is one).
1981
  bool isDefined(const FunctionDecl *&Definition) const;
1982
1983
3.18M
  virtual bool isDefined() const {
1984
3.18M
    const FunctionDecl* Definition;
1985
3.18M
    return isDefined(Definition);
1986
3.18M
  }
1987
1988
  /// Get the definition for this declaration.
1989
3.92M
  FunctionDecl *getDefinition() {
1990
3.92M
    const FunctionDecl *Definition;
1991
3.92M
    if (isDefined(Definition))
1992
3.69M
      return const_cast<FunctionDecl *>(Definition);
1993
231k
    return nullptr;
1994
231k
  }
1995
384k
  const FunctionDecl *getDefinition() const {
1996
384k
    return const_cast<FunctionDecl *>(this)->getDefinition();
1997
384k
  }
1998
1999
  /// Retrieve the body (definition) of the function. The function body might be
2000
  /// in any of the (re-)declarations of this function. The variant that accepts
2001
  /// a FunctionDecl pointer will set that function declaration to the actual
2002
  /// declaration containing the body (if there is one).
2003
  /// NOTE: For checking if there is a body, use hasBody() instead, to avoid
2004
  /// unnecessary AST de-serialization of the body.
2005
  Stmt *getBody(const FunctionDecl *&Definition) const;
2006
2007
5.10M
  Stmt *getBody() const override {
2008
5.10M
    const FunctionDecl* Definition;
2009
5.10M
    return getBody(Definition);
2010
5.10M
  }
2011
2012
  /// Returns whether this specific declaration of the function is also a
2013
  /// definition that does not contain uninstantiated body.
2014
  ///
2015
  /// This does not determine whether the function has been defined (e.g., in a
2016
  /// previous definition); for that information, use isDefined.
2017
13.6M
  bool isThisDeclarationADefinition() const {
2018
13.6M
    return IsDeleted || 
IsDefaulted13.5M
||
Body13.4M
||
HasSkippedBody7.73M
||
2019
13.6M
           
IsLateTemplateParsed7.73M
||
WillHaveBody7.73M
||
hasDefiningAttr()7.70M
;
2020
13.6M
  }
2021
2022
  /// Returns whether this specific declaration of the function has a body.
2023
18.8M
  bool doesThisDeclarationHaveABody() const {
2024
18.8M
    return Body || 
IsLateTemplateParsed7.90M
;
2025
18.8M
  }
2026
2027
  void setBody(Stmt *B);
2028
10.2k
  void setLazyBody(uint64_t Offset) { Body = Offset; }
2029
2030
  /// Whether this function is variadic.
2031
  bool isVariadic() const;
2032
2033
  /// Whether this function is marked as virtual explicitly.
2034
10.0M
  bool isVirtualAsWritten() const { return IsVirtualAsWritten; }
2035
129k
  void setVirtualAsWritten(bool V) { IsVirtualAsWritten = V; }
2036
2037
  /// Whether this virtual function is pure, i.e. makes the containing class
2038
  /// abstract.
2039
10.9M
  bool isPure() const { return IsPure; }
2040
  void setPure(bool P = true);
2041
2042
  /// Whether this templated function will be late parsed.
2043
2.23M
  bool isLateTemplateParsed() const { return IsLateTemplateParsed; }
2044
497
  void setLateTemplateParsed(bool ILT = true) { IsLateTemplateParsed = ILT; }
2045
2046
  /// Whether this function is "trivial" in some specialized C++ senses.
2047
  /// Can only be true for default constructors, copy constructors,
2048
  /// copy assignment operators, and destructors.  Not meaningful until
2049
  /// the class has been fully built by Sema.
2050
2.06M
  bool isTrivial() const { return IsTrivial; }
2051
755k
  void setTrivial(bool IT) { IsTrivial = IT; }
2052
2053
650k
  bool isTrivialForCall() const { return IsTrivialForCall; }
2054
468k
  void setTrivialForCall(bool IT) { IsTrivialForCall = IT; }
2055
2056
  /// Whether this function is defaulted per C++0x. Only valid for
2057
  /// special member functions.
2058
18.8M
  bool isDefaulted() const { return IsDefaulted; }
2059
551k
  void setDefaulted(bool D = true) { IsDefaulted = D; }
2060
2061
  /// Whether this function is explicitly defaulted per C++0x. Only valid
2062
  /// for special member functions.
2063
5.12M
  bool isExplicitlyDefaulted() const { return IsExplicitlyDefaulted; }
2064
17.4k
  void setExplicitlyDefaulted(bool ED = true) { IsExplicitlyDefaulted = ED; }
2065
2066
  /// Whether falling off this function implicitly returns null/zero.
2067
  /// If a more specific implicit return value is required, front-ends
2068
  /// should synthesize the appropriate return statements.
2069
3.43M
  bool hasImplicitReturnZero() const { return HasImplicitReturnZero; }
2070
5.11k
  void setHasImplicitReturnZero(bool IRZ) { HasImplicitReturnZero = IRZ; }
2071
2072
  /// Whether this function has a prototype, either because one
2073
  /// was explicitly written or because it was "inherited" by merging
2074
  /// a declaration without a prototype with a declaration that has a
2075
  /// prototype.
2076
1.30M
  bool hasPrototype() const {
2077
1.30M
    return HasWrittenPrototype || 
HasInheritedPrototype102k
;
2078
1.30M
  }
2079
2080
256k
  bool hasWrittenPrototype() const { return HasWrittenPrototype; }
2081
2082
  /// Whether this function inherited its prototype from a
2083
  /// previous declaration.
2084
1.94k
  bool hasInheritedPrototype() const { return HasInheritedPrototype; }
2085
652
  void setHasInheritedPrototype(bool P = true) { HasInheritedPrototype = P; }
2086
2087
  /// Whether this is a (C++11) constexpr function or constexpr constructor.
2088
10.3M
  bool isConstexpr() const { return IsConstexpr; }
2089
17.1k
  void setConstexpr(bool IC) { IsConstexpr = IC; }
2090
2091
  /// Whether the instantiation of this function is pending.
2092
  /// This bit is set when the decision to instantiate this function is made
2093
  /// and unset if and when the function body is created. That leaves out
2094
  /// cases where instantiation did not happen because the template definition
2095
  /// was not seen in this TU. This bit remains set in those cases, under the
2096
  /// assumption that the instantiation will happen in some other TU.
2097
0
  bool instantiationIsPending() const { return InstantiationIsPending; }
2098
487k
  void setInstantiationIsPending(bool IC) { InstantiationIsPending = IC; }
2099
2100
  /// Indicates the function uses __try.
2101
408k
  bool usesSEHTry() const { return UsesSEHTry; }
2102
226
  void setUsesSEHTry(bool UST) { UsesSEHTry = UST; }
2103
2104
  /// Whether this function has been deleted.
2105
  ///
2106
  /// A function that is "deleted" (via the C++0x "= delete" syntax)
2107
  /// acts like a normal function, except that it cannot actually be
2108
  /// called or have its address taken. Deleted functions are
2109
  /// typically used in C++ overload resolution to attract arguments
2110
  /// whose type or lvalue/rvalue-ness would permit the use of a
2111
  /// different overload that would behave incorrectly. For example,
2112
  /// one might use deleted functions to ban implicit conversion from
2113
  /// a floating-point number to an Integer type:
2114
  ///
2115
  /// @code
2116
  /// struct Integer {
2117
  ///   Integer(long); // construct from a long
2118
  ///   Integer(double) = delete; // no construction from float or double
2119
  ///   Integer(long double) = delete; // no construction from long double
2120
  /// };
2121
  /// @endcode
2122
  // If a function is deleted, its first declaration must be.
2123
21.2M
  bool isDeleted() const { return getCanonicalDecl()->IsDeleted; }
2124
1.36M
  bool isDeletedAsWritten() const { return IsDeleted && 
!IsDefaulted16.9k
; }
2125
84.7k
  void setDeletedAsWritten(bool D = true) { IsDeleted = D; }
2126
2127
  /// Determines whether this function is "main", which is the
2128
  /// entry point into an executable program.
2129
  bool isMain() const;
2130
2131
  /// Determines whether this function is a MSVCRT user defined entry
2132
  /// point.
2133
  bool isMSVCRTEntryPoint() const;
2134
2135
  /// Determines whether this operator new or delete is one
2136
  /// of the reserved global placement operators:
2137
  ///    void *operator new(size_t, void *);
2138
  ///    void *operator new[](size_t, void *);
2139
  ///    void operator delete(void *, void *);
2140
  ///    void operator delete[](void *, void *);
2141
  /// These functions have special behavior under [new.delete.placement]:
2142
  ///    These functions are reserved, a C++ program may not define
2143
  ///    functions that displace the versions in the Standard C++ library.
2144
  ///    The provisions of [basic.stc.dynamic] do not apply to these
2145
  ///    reserved placement forms of operator new and operator delete.
2146
  ///
2147
  /// This function must be an allocation or deallocation function.
2148
  bool isReservedGlobalPlacementOperator() const;
2149
2150
  /// Determines whether this function is one of the replaceable
2151
  /// global allocation functions:
2152
  ///    void *operator new(size_t);
2153
  ///    void *operator new(size_t, const std::nothrow_t &) noexcept;
2154
  ///    void *operator new[](size_t);
2155
  ///    void *operator new[](size_t, const std::nothrow_t &) noexcept;
2156
  ///    void operator delete(void *) noexcept;
2157
  ///    void operator delete(void *, std::size_t) noexcept;      [C++1y]
2158
  ///    void operator delete(void *, const std::nothrow_t &) noexcept;
2159
  ///    void operator delete[](void *) noexcept;
2160
  ///    void operator delete[](void *, std::size_t) noexcept;    [C++1y]
2161
  ///    void operator delete[](void *, const std::nothrow_t &) noexcept;
2162
  /// These functions have special behavior under C++1y [expr.new]:
2163
  ///    An implementation is allowed to omit a call to a replaceable global
2164
  ///    allocation function. [...]
2165
  ///
2166
  /// If this function is an aligned allocation/deallocation function, return
2167
  /// true through IsAligned.
2168
  bool isReplaceableGlobalAllocationFunction(bool *IsAligned = nullptr) const;
2169
2170
  /// Determine whether this is a destroying operator delete.
2171
  bool isDestroyingOperatorDelete() const;
2172
2173
  /// Compute the language linkage.
2174
  LanguageLinkage getLanguageLinkage() const;
2175
2176
  /// Determines whether this function is a function with
2177
  /// external, C linkage.
2178
  bool isExternC() const;
2179
2180
  /// Determines whether this function's context is, or is nested within,
2181
  /// a C++ extern "C" linkage spec.
2182
  bool isInExternCContext() const;
2183
2184
  /// Determines whether this function's context is, or is nested within,
2185
  /// a C++ extern "C++" linkage spec.
2186
  bool isInExternCXXContext() const;
2187
2188
  /// Determines whether this is a global function.
2189
  bool isGlobal() const;
2190
2191
  /// Determines whether this function is known to be 'noreturn', through
2192
  /// an attribute on its declaration or its type.
2193
  bool isNoReturn() const;
2194
2195
  /// True if the function was a definition but its body was skipped.
2196
257k
  bool hasSkippedBody() const { return HasSkippedBody; }
2197
757
  void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; }
2198
2199
  /// True if this function will eventually have a body, once it's fully parsed.
2200
3.22M
  bool willHaveBody() const { return WillHaveBody; }
2201
6.97M
  void setWillHaveBody(bool V = true) { WillHaveBody = V; }
2202
2203
  /// True if this function is considered a multiversioned function.
2204
27.8M
  bool isMultiVersion() const { return getCanonicalDecl()->IsMultiVersion; }
2205
2206
  /// Sets the multiversion state for this declaration and all of its
2207
  /// redeclarations.
2208
268
  void setIsMultiVersion(bool V = true) {
2209
268
    getCanonicalDecl()->IsMultiVersion = V;
2210
268
  }
2211
2212
  /// True if this function is a multiversioned dispatch function as a part of
2213
  /// the cpu_specific/cpu_dispatch functionality.
2214
  bool isCPUDispatchMultiVersion() const;
2215
  /// True if this function is a multiversioned processor specific function as a
2216
  /// part of the cpu_specific/cpu_dispatch functionality.
2217
  bool isCPUSpecificMultiVersion() const;
2218
2219
  void setPreviousDeclaration(FunctionDecl * PrevDecl);
2220
2221
  FunctionDecl *getCanonicalDecl() override;
2222
65.4M
  const FunctionDecl *getCanonicalDecl() const {
2223
65.4M
    return const_cast<FunctionDecl*>(this)->getCanonicalDecl();
2224
65.4M
  }
2225
2226
  unsigned getBuiltinID() const;
2227
2228
  // ArrayRef interface to parameters.
2229
20.9M
  ArrayRef<ParmVarDecl *> parameters() const {
2230
20.9M
    return {ParamInfo, getNumParams()};
2231
20.9M
  }
2232
17.3M
  MutableArrayRef<ParmVarDecl *> parameters() {
2233
17.3M
    return {ParamInfo, getNumParams()};
2234
17.3M
  }
2235
2236
  // Iterator access to formal parameters.
2237
  using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator;
2238
  using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator;
2239
2240
0
  bool param_empty() const { return parameters().empty(); }
2241
809
  param_iterator param_begin() { return parameters().begin(); }
2242
0
  param_iterator param_end() { return parameters().end(); }
2243
931k
  param_const_iterator param_begin() const { return parameters().begin(); }
2244
504k
  param_const_iterator param_end() const { return parameters().end(); }
2245
196k
  size_t param_size() const { return parameters().size(); }
2246
2247
  /// Return the number of parameters this function must have based on its
2248
  /// FunctionType.  This is the length of the ParamInfo array after it has been
2249
  /// created.
2250
  unsigned getNumParams() const;
2251
2252
18.0M
  const ParmVarDecl *getParamDecl(unsigned i) const {
2253
18.0M
    assert(i < getNumParams() && "Illegal param #");
2254
18.0M
    return ParamInfo[i];
2255
18.0M
  }
2256
16.3M
  ParmVarDecl *getParamDecl(unsigned i) {
2257
16.3M
    assert(i < getNumParams() && "Illegal param #");
2258
16.3M
    return ParamInfo[i];
2259
16.3M
  }
2260
7.57M
  void setParams(ArrayRef<ParmVarDecl *> NewParamInfo) {
2261
7.57M
    setParams(getASTContext(), NewParamInfo);
2262
7.57M
  }
2263
2264
  /// Returns the minimum number of arguments needed to call this function. This
2265
  /// may be fewer than the number of function parameters, if some of the
2266
  /// parameters have default arguments (in C++).
2267
  unsigned getMinRequiredArguments() const;
2268
2269
21.8M
  QualType getReturnType() const {
2270
21.8M
    assert(getType()->getAs<FunctionType>() && "Expected a FunctionType!");
2271
21.8M
    return getType()->getAs<FunctionType>()->getReturnType();
2272
21.8M
  }
2273
2274
  /// Attempt to compute an informative source range covering the
2275
  /// function return type. This may omit qualifiers and other information with
2276
  /// limited representation in the AST.
2277
  SourceRange getReturnTypeSourceRange() const;
2278
2279
  /// Attempt to compute an informative source range covering the
2280
  /// function exception specification, if any.
2281
  SourceRange getExceptionSpecSourceRange() const;
2282
2283
  /// Determine the type of an expression that calls this function.
2284
3.96k
  QualType getCallResultType() const {
2285
3.96k
    assert(getType()->getAs<FunctionType>() && "Expected a FunctionType!");
2286
3.96k
    return getType()->getAs<FunctionType>()->getCallResultType(getASTContext());
2287
3.96k
  }
2288
2289
  /// Returns the WarnUnusedResultAttr that is either declared on this
2290
  /// function, or its return type declaration.
2291
  const Attr *getUnusedResultAttr() const;
2292
2293
  /// Returns true if this function or its return type has the
2294
  /// warn_unused_result attribute.
2295
744k
  bool hasUnusedResultAttr() const { return getUnusedResultAttr() != nullptr; }
2296
2297
  /// Returns the storage class as written in the source. For the
2298
  /// computed linkage of symbol, see getLinkage.
2299
38.2M
  StorageClass getStorageClass() const { return StorageClass(SClass); }
2300
2301
  /// Determine whether the "inline" keyword was specified for this
2302
  /// function.
2303
2.86M
  bool isInlineSpecified() const { return IsInlineSpecified; }
2304
2305
  /// Set whether the "inline" keyword was specified for this function.
2306
7.16k
  void setInlineSpecified(bool I) {
2307
7.16k
    IsInlineSpecified = I;
2308
7.16k
    IsInline = I;
2309
7.16k
  }
2310
2311
  /// Flag that this function is implicitly inline.
2312
2.37M
  void setImplicitlyInline() {
2313
2.37M
    IsInline = true;
2314
2.37M
  }
2315
2316
  /// Determine whether this function should be inlined, because it is
2317
  /// either marked "inline" or "constexpr" or is a member function of a class
2318
  /// that was defined in the class body.
2319
20.4M
  bool isInlined() const { return IsInline; }
2320
2321
  bool isInlineDefinitionExternallyVisible() const;
2322
2323
  bool isMSExternInline() const;
2324
2325
  bool doesDeclarationForceExternallyVisibleDefinition() const;
2326
2327
  /// Whether this function declaration represents an C++ overloaded
2328
  /// operator, e.g., "operator+".
2329
9.36M
  bool isOverloadedOperator() const {
2330
9.36M
    return getOverloadedOperator() != OO_None;
2331
9.36M
  }
2332
2333
  OverloadedOperatorKind getOverloadedOperator() const;
2334
2335
  const IdentifierInfo *getLiteralIdentifier() const;
2336
2337
  /// If this function is an instantiation of a member function
2338
  /// of a class template specialization, retrieves the function from
2339
  /// which it was instantiated.
2340
  ///
2341
  /// This routine will return non-NULL for (non-templated) member
2342
  /// functions of class templates and for instantiations of function
2343
  /// templates. For example, given:
2344
  ///
2345
  /// \code
2346
  /// template<typename T>
2347
  /// struct X {
2348
  ///   void f(T);
2349
  /// };
2350
  /// \endcode
2351
  ///
2352
  /// The declaration for X<int>::f is a (non-templated) FunctionDecl
2353
  /// whose parent is the class template specialization X<int>. For
2354
  /// this declaration, getInstantiatedFromFunction() will return
2355
  /// the FunctionDecl X<T>::A. When a complete definition of
2356
  /// X<int>::A is required, it will be instantiated from the
2357
  /// declaration returned by getInstantiatedFromMemberFunction().
2358
  FunctionDecl *getInstantiatedFromMemberFunction() const;
2359
2360
  /// What kind of templated function this is.
2361
  TemplatedKind getTemplatedKind() const;
2362
2363
  /// If this function is an instantiation of a member function of a
2364
  /// class template specialization, retrieves the member specialization
2365
  /// information.
2366
  MemberSpecializationInfo *getMemberSpecializationInfo() const;
2367
2368
  /// Specify that this record is an instantiation of the
2369
  /// member function FD.
2370
  void setInstantiationOfMemberFunction(FunctionDecl *FD,
2371
1.02M
                                        TemplateSpecializationKind TSK) {
2372
1.02M
    setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
2373
1.02M
  }
2374
2375
  /// Retrieves the function template that is described by this
2376
  /// function declaration.
2377
  ///
2378
  /// Every function template is represented as a FunctionTemplateDecl
2379
  /// and a FunctionDecl (or something derived from FunctionDecl). The
2380
  /// former contains template properties (such as the template
2381
  /// parameter lists) while the latter contains the actual
2382
  /// description of the template's
2383
  /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
2384
  /// FunctionDecl that describes the function template,
2385
  /// getDescribedFunctionTemplate() retrieves the
2386
  /// FunctionTemplateDecl from a FunctionDecl.
2387
  FunctionTemplateDecl *getDescribedFunctionTemplate() const;
2388
2389
  void setDescribedFunctionTemplate(FunctionTemplateDecl *Template);
2390
2391
  /// Determine whether this function is a function template
2392
  /// specialization.
2393
16.7M
  bool isFunctionTemplateSpecialization() const {
2394
16.7M
    return getPrimaryTemplate() != nullptr;
2395
16.7M
  }
2396
2397
  /// Retrieve the class scope template pattern that this function
2398
  ///  template specialization is instantiated from.
2399
  FunctionDecl *getClassScopeSpecializationPattern() const;
2400
2401
  /// If this function is actually a function template specialization,
2402
  /// retrieve information about this function template specialization.
2403
  /// Otherwise, returns NULL.
2404
  FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const;
2405
2406
  /// Determines whether this function is a function template
2407
  /// specialization or a member of a class template specialization that can
2408
  /// be implicitly instantiated.
2409
  bool isImplicitlyInstantiable() const;
2410
2411
  /// Determines if the given function was instantiated from a
2412
  /// function template.
2413
  bool isTemplateInstantiation() const;
2414
2415
  /// Retrieve the function declaration from which this function could
2416
  /// be instantiated, if it is an instantiation (rather than a non-template
2417
  /// or a specialization, for example).
2418
  FunctionDecl *getTemplateInstantiationPattern() const;
2419
2420
  /// Retrieve the primary template that this function template
2421
  /// specialization either specializes or was instantiated from.
2422
  ///
2423
  /// If this function declaration is not a function template specialization,
2424
  /// returns NULL.
2425
  FunctionTemplateDecl *getPrimaryTemplate() const;
2426
2427
  /// Retrieve the template arguments used to produce this function
2428
  /// template specialization from the primary template.
2429
  ///
2430
  /// If this function declaration is not a function template specialization,
2431
  /// returns NULL.
2432
  const TemplateArgumentList *getTemplateSpecializationArgs() const;
2433
2434
  /// Retrieve the template argument list as written in the sources,
2435
  /// if any.
2436
  ///
2437
  /// If this function declaration is not a function template specialization
2438
  /// or if it had no explicit template argument list, returns NULL.
2439
  /// Note that it an explicit template argument list may be written empty,
2440
  /// e.g., template<> void foo<>(char* s);
2441
  const ASTTemplateArgumentListInfo*
2442
  getTemplateSpecializationArgsAsWritten() const;
2443
2444
  /// Specify that this function declaration is actually a function
2445
  /// template specialization.
2446
  ///
2447
  /// \param Template the function template that this function template
2448
  /// specialization specializes.
2449
  ///
2450
  /// \param TemplateArgs the template arguments that produced this
2451
  /// function template specialization from the template.
2452
  ///
2453
  /// \param InsertPos If non-NULL, the position in the function template
2454
  /// specialization set where the function template specialization data will
2455
  /// be inserted.
2456
  ///
2457
  /// \param TSK the kind of template specialization this is.
2458
  ///
2459
  /// \param TemplateArgsAsWritten location info of template arguments.
2460
  ///
2461
  /// \param PointOfInstantiation point at which the function template
2462
  /// specialization was first instantiated.
2463
  void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template,
2464
                const TemplateArgumentList *TemplateArgs,
2465
                void *InsertPos,
2466
                TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
2467
                const TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
2468
229k
                SourceLocation PointOfInstantiation = SourceLocation()) {
2469
229k
    setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
2470
229k
                                      InsertPos, TSK, TemplateArgsAsWritten,
2471
229k
                                      PointOfInstantiation);
2472
229k
  }
2473
2474
  /// Specifies that this function declaration is actually a
2475
  /// dependent function template specialization.
2476
  void setDependentTemplateSpecialization(ASTContext &Context,
2477
                             const UnresolvedSetImpl &Templates,
2478
                      const TemplateArgumentListInfo &TemplateArgs);
2479
2480
  DependentFunctionTemplateSpecializationInfo *
2481
  getDependentSpecializationInfo() const;
2482
2483
  /// Determine what kind of template instantiation this function
2484
  /// represents.
2485
  TemplateSpecializationKind getTemplateSpecializationKind() const;
2486
2487
  /// Determine what kind of template instantiation this function
2488
  /// represents.
2489
  void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
2490
                        SourceLocation PointOfInstantiation = SourceLocation());
2491
2492
  /// Retrieve the (first) point of instantiation of a function template
2493
  /// specialization or a member of a class template specialization.
2494
  ///
2495
  /// \returns the first point of instantiation, if this function was
2496
  /// instantiated from a template; otherwise, returns an invalid source
2497
  /// location.
2498
  SourceLocation getPointOfInstantiation() const;
2499
2500
  /// Determine whether this is or was instantiated from an out-of-line
2501
  /// definition of a member function.
2502
  bool isOutOfLine() const override;
2503
2504
  /// Identify a memory copying or setting function.
2505
  /// If the given function is a memory copy or setting function, returns
2506
  /// the corresponding Builtin ID. If the function is not a memory function,
2507
  /// returns 0.
2508
  unsigned getMemoryFunctionKind() const;
2509
2510
  /// Returns ODRHash of the function.  This value is calculated and
2511
  /// stored on first call, then the stored value returned on the other calls.
2512
  unsigned getODRHash();
2513
2514
  /// Returns cached ODRHash of the function.  This must have been previously
2515
  /// computed and stored.
2516
  unsigned getODRHash() const;
2517
2518
  // Implement isa/cast/dyncast/etc.
2519
352M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2520
510M
  static bool classofKind(Kind K) {
2521
510M
    return K >= firstFunction && 
K <= lastFunction300M
;
2522
510M
  }
2523
0
  static DeclContext *castToDeclContext(const FunctionDecl *D) {
2524
0
    return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
2525
0
  }
2526
0
  static FunctionDecl *castFromDeclContext(const DeclContext *DC) {
2527
0
    return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
2528
0
  }
2529
};
2530
2531
/// Represents a member of a struct/union/class.
2532
class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
2533
  unsigned BitField : 1;
2534
  unsigned Mutable : 1;
2535
  mutable unsigned CachedFieldIndex : 30;
2536
2537
  /// The kinds of value we can store in InitializerOrBitWidth.
2538
  ///
2539
  /// Note that this is compatible with InClassInitStyle except for
2540
  /// ISK_CapturedVLAType.
2541
  enum InitStorageKind {
2542
    /// If the pointer is null, there's nothing special.  Otherwise,
2543
    /// this is a bitfield and the pointer is the Expr* storing the
2544
    /// bit-width.
2545
    ISK_NoInit = (unsigned) ICIS_NoInit,
2546
2547
    /// The pointer is an (optional due to delayed parsing) Expr*
2548
    /// holding the copy-initializer.
2549
    ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
2550
2551
    /// The pointer is an (optional due to delayed parsing) Expr*
2552
    /// holding the list-initializer.
2553
    ISK_InClassListInit = (unsigned) ICIS_ListInit,
2554
2555
    /// The pointer is a VariableArrayType* that's been captured;
2556
    /// the enclosing context is a lambda or captured statement.
2557
    ISK_CapturedVLAType,
2558
  };
2559
2560
  /// If this is a bitfield with a default member initializer, this
2561
  /// structure is used to represent the two expressions.
2562
  struct InitAndBitWidth {
2563
    Expr *Init;
2564
    Expr *BitWidth;
2565
  };
2566
2567
  /// Storage for either the bit-width, the in-class initializer, or
2568
  /// both (via InitAndBitWidth), or the captured variable length array bound.
2569
  ///
2570
  /// If the storage kind is ISK_InClassCopyInit or
2571
  /// ISK_InClassListInit, but the initializer is null, then this
2572
  /// field has an in-class initializer that has not yet been parsed
2573
  /// and attached.
2574
  // FIXME: Tail-allocate this to reduce the size of FieldDecl in the
2575
  // overwhelmingly common case that we have none of these things.
2576
  llvm::PointerIntPair<void *, 2, InitStorageKind> InitStorage;
2577
2578
protected:
2579
  FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
2580
            SourceLocation IdLoc, IdentifierInfo *Id,
2581
            QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
2582
            InClassInitStyle InitStyle)
2583
    : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc),
2584
      BitField(false), Mutable(Mutable), CachedFieldIndex(0),
2585
2.81M
      InitStorage(nullptr, (InitStorageKind) InitStyle) {
2586
2.81M
    if (BW)
2587
37.4k
      setBitWidth(BW);
2588
2.81M
  }
2589
2590
public:
2591
  friend class ASTDeclReader;
2592
  friend class ASTDeclWriter;
2593
2594
  static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
2595
                           SourceLocation StartLoc, SourceLocation IdLoc,
2596
                           IdentifierInfo *Id, QualType T,
2597
                           TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
2598
                           InClassInitStyle InitStyle);
2599
2600
  static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2601
  
2602
  /// Returns the index of this field within its record,
2603
  /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
2604
  unsigned getFieldIndex() const;
2605
2606
  /// Determines whether this field is mutable (C++ only).
2607
6.21M
  bool isMutable() const { return Mutable; }
2608
2609
  /// Determines whether this field is a bitfield.
2610
9.35M
  bool isBitField() const { return BitField; }
2611
2612
  /// Determines whether this is an unnamed bitfield.
2613
4.37M
  bool isUnnamedBitfield() const { return isBitField() && 
!getDeclName()39.0k
; }
2614
2615
  /// Determines whether this field is a
2616
  /// representative for an anonymous struct or union. Such fields are
2617
  /// unnamed and are implicitly generated by the implementation to
2618
  /// store the data for the anonymous union or struct.
2619
  bool isAnonymousStructOrUnion() const;
2620
2621
216k
  Expr *getBitWidth() const {
2622
216k
    if (!BitField)
2623
159k
      return nullptr;
2624
56.4k
    void *Ptr = InitStorage.getPointer();
2625
56.4k
    if (getInClassInitStyle())
2626
76
      return static_cast<InitAndBitWidth*>(Ptr)->BitWidth;
2627
56.4k
    return static_cast<Expr*>(Ptr);
2628
56.4k
  }
2629
2630
  unsigned getBitWidthValue(const ASTContext &Ctx) const;
2631
2632
  /// Set the bit-field width for this member.
2633
  // Note: used by some clients (i.e., do not remove it).
2634
37.7k
  void setBitWidth(Expr *Width) {
2635
37.7k
    assert(!hasCapturedVLAType() && !BitField &&
2636
37.7k
           "bit width or captured type already set");
2637
37.7k
    assert(Width && "no bit width specified");
2638
37.7k
    InitStorage.setPointer(
2639
37.7k
        InitStorage.getInt()
2640
37.7k
            ? new (getASTContext())
2641
9
                  InitAndBitWidth{getInClassInitializer(), Width}
2642
37.7k
            : 
static_cast<void*>(Width)37.7k
);
2643
37.7k
    BitField = true;
2644
37.7k
  }
2645
2646
  /// Remove the bit-field width from this member.
2647
  // Note: used by some clients (i.e., do not remove it).
2648
0
  void removeBitWidth() {
2649
0
    assert(isBitField() && "no bitfield width to remove");
2650
0
    InitStorage.setPointer(getInClassInitializer());
2651
0
    BitField = false;
2652
0
  }
2653
2654
  /// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
2655
  /// at all and instead act as a separator between contiguous runs of other
2656
  /// bit-fields.
2657
  bool isZeroLengthBitField(const ASTContext &Ctx) const;
2658
2659
  /// Get the kind of (C++11) default member initializer that this field has.
2660
6.46M
  InClassInitStyle getInClassInitStyle() const {
2661
6.46M
    InitStorageKind storageKind = InitStorage.getInt();
2662
6.46M
    return (storageKind == ISK_CapturedVLAType
2663
6.46M
              ? 
ICIS_NoInit16.6k
:
(InClassInitStyle) storageKind6.44M
);
2664
6.46M
  }
2665
2666
  /// Determine whether this member has a C++11 default member initializer.
2667
6.28M
  bool hasInClassInitializer() const {
2668
6.28M
    return getInClassInitStyle() != ICIS_NoInit;
2669
6.28M
  }
2670
2671
  /// Get the C++11 default member initializer for this member, or null if one
2672
  /// has not been set. If a valid declaration has a default member initializer,
2673
  /// but this returns null, then we have not parsed and attached it yet.
2674
22.1k
  Expr *getInClassInitializer() const {
2675
22.1k
    if (!hasInClassInitializer())
2676
8.56k
      return nullptr;
2677
13.5k
    void *Ptr = InitStorage.getPointer();
2678
13.5k
    if (BitField)
2679
99
      return static_cast<InitAndBitWidth*>(Ptr)->Init;
2680
13.4k
    return static_cast<Expr*>(Ptr);
2681
13.4k
  }
2682
2683
  /// Set the C++11 in-class initializer for this member.
2684
5.22k
  void setInClassInitializer(Expr *Init) {
2685
5.22k
    assert(hasInClassInitializer() && !getInClassInitializer());
2686
5.22k
    if (BitField)
2687
8
      static_cast<InitAndBitWidth*>(InitStorage.getPointer())->Init = Init;
2688
5.21k
    else
2689
5.21k
      InitStorage.setPointer(Init);
2690
5.22k
  }
2691
2692
  /// Remove the C++11 in-class initializer from this member.
2693
39
  void removeInClassInitializer() {
2694
39
    assert(hasInClassInitializer() && "no initializer to remove");
2695
39
    InitStorage.setPointerAndInt(getBitWidth(), ISK_NoInit);
2696
39
  }
2697
2698
  /// Determine whether this member captures the variable length array
2699
  /// type.
2700
126k
  bool hasCapturedVLAType() const {
2701
126k
    return InitStorage.getInt() == ISK_CapturedVLAType;
2702
126k
  }
2703
2704
  /// Get the captured variable length array type.
2705
24.6k
  const VariableArrayType *getCapturedVLAType() const {
2706
24.6k
    return hasCapturedVLAType() ? static_cast<const VariableArrayType *>(
2707
24.6k
                                      InitStorage.getPointer())
2708
24.6k
                                : 
nullptr0
;
2709
24.6k
  }
2710
2711
  /// Set the captured variable length array type for this field.
2712
  void setCapturedVLAType(const VariableArrayType *VLAType);
2713
2714
  /// Returns the parent of this field declaration, which
2715
  /// is the struct in which this field is defined.
2716
2.20M
  const RecordDecl *getParent() const {
2717
2.20M
    return cast<RecordDecl>(getDeclContext());
2718
2.20M
  }
2719
2720
849k
  RecordDecl *getParent() {
2721
849k
    return cast<RecordDecl>(getDeclContext());
2722
849k
  }
2723
2724
  SourceRange getSourceRange() const override LLVM_READONLY;
2725
2726
  /// Retrieves the canonical declaration of this field.
2727
5.39M
  FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
2728
3.03M
  const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
2729
2730
  // Implement isa/cast/dyncast/etc.
2731
106M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2732
106M
  static bool classofKind(Kind K) { return K >= firstField && 
K <= lastField84.8M
; }
2733
};
2734
2735
/// An instance of this object exists for each enum constant
2736
/// that is defined.  For example, in "enum X {a,b}", each of a/b are
2737
/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
2738
/// TagType for the X EnumDecl.
2739
class EnumConstantDecl : public ValueDecl, public Mergeable<EnumConstantDecl> {
2740
  Stmt *Init; // an integer constant expression
2741
  llvm::APSInt Val; // The value.
2742
2743
protected:
2744
  EnumConstantDecl(DeclContext *DC, SourceLocation L,
2745
                   IdentifierInfo *Id, QualType T, Expr *E,
2746
                   const llvm::APSInt &V)
2747
351k
    : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
2748
2749
public:
2750
  friend class StmtIteratorBase;
2751
2752
  static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC,
2753
                                  SourceLocation L, IdentifierInfo *Id,
2754
                                  QualType T, Expr *E,
2755
                                  const llvm::APSInt &V);
2756
  static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2757
  
2758
91
  const Expr *getInitExpr() const { return (const Expr*) Init; }
2759
482k
  Expr *getInitExpr() { return (Expr*) Init; }
2760
2.49M
  const llvm::APSInt &getInitVal() const { return Val; }
2761
2762
59.4k
  void setInitExpr(Expr *E) { Init = (Stmt*) E; }
2763
288k
  void setInitVal(const llvm::APSInt &V) { Val = V; }
2764
2765
  SourceRange getSourceRange() const override LLVM_READONLY;
2766
2767
  /// Retrieves the canonical declaration of this enumerator.
2768
610k
  EnumConstantDecl *getCanonicalDecl() override { return getFirstDecl(); }
2769
0
  const EnumConstantDecl *getCanonicalDecl() const { return getFirstDecl(); }
2770
2771
  // Implement isa/cast/dyncast/etc.
2772
46.8M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2773
46.8M
  static bool classofKind(Kind K) { return K == EnumConstant; }
2774
};
2775
2776
/// Represents a field injected from an anonymous union/struct into the parent
2777
/// scope. These are always implicit.
2778
class IndirectFieldDecl : public ValueDecl,
2779
                          public Mergeable<IndirectFieldDecl> {
2780
  NamedDecl **Chaining;
2781
  unsigned ChainingSize;
2782
2783
  IndirectFieldDecl(ASTContext &C, DeclContext *DC, SourceLocation L,
2784
                    DeclarationName N, QualType T,
2785
                    MutableArrayRef<NamedDecl *> CH);
2786
2787
  void anchor() override;
2788
2789
public:
2790
  friend class ASTDeclReader;
2791
2792
  static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC,
2793
                                   SourceLocation L, IdentifierInfo *Id,
2794
                                   QualType T, llvm::MutableArrayRef<NamedDecl *> CH);
2795
2796
  static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2797
2798
  using chain_iterator = ArrayRef<NamedDecl *>::const_iterator;
2799
2800
84.3k
  ArrayRef<NamedDecl *> chain() const {
2801
84.3k
    return llvm::makeArrayRef(Chaining, ChainingSize);
2802
84.3k
  }
2803
10.5k
  chain_iterator chain_begin() const { return chain().begin(); }
2804
10.5k
  chain_iterator chain_end() const { return chain().end(); }
2805
2806
6.33k
  unsigned getChainingSize() const { return ChainingSize; }
2807
2808
34.2k
  FieldDecl *getAnonField() const {
2809
34.2k
    assert(chain().size() >= 2);
2810
34.2k
    return cast<FieldDecl>(chain().back());
2811
34.2k
  }
2812
2813
10.2k
  VarDecl *getVarDecl() const {
2814
10.2k
    assert(chain().size() >= 2);
2815
10.2k
    return dyn_cast<VarDecl>(chain().front());
2816
10.2k
  }
2817
2818
21.9k
  IndirectFieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
2819
0
  const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
2820
2821
  // Implement isa/cast/dyncast/etc.
2822
57.2M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2823
57.2M
  static bool classofKind(Kind K) { return K == IndirectField; }
2824
};
2825
2826
/// Represents a declaration of a type.
2827
class TypeDecl : public NamedDecl {
2828
  friend class ASTContext;
2829
2830
  /// This indicates the Type object that represents
2831
  /// this TypeDecl.  It is a cache maintained by
2832
  /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
2833
  /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
2834
  mutable const Type *TypeForDecl = nullptr;
2835
2836
  /// The start of the source range for this declaration.
2837
  SourceLocation LocStart;
2838
2839
  void anchor() override;
2840
2841
protected:
2842
  TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
2843
           SourceLocation StartL = SourceLocation())
2844
8.27M
    : NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
2845
2846
public:
2847
  // Low-level accessor. If you just want the type defined by this node,
2848
  // check out ASTContext::getTypeDeclType or one of
2849
  // ASTContext::getTypedefType, ASTContext::getRecordType, etc. if you
2850
  // already know the specific kind of node this is.
2851
28.7M
  const Type *getTypeForDecl() const { return TypeForDecl; }
2852
2.16M
  void setTypeForDecl(const Type *TD) { TypeForDecl = TD; }
2853
2854
4.54M
  SourceLocation getLocStart() const LLVM_READONLY { return LocStart; }
2855
854k
  void setLocStart(SourceLocation L) { LocStart = L; }
2856
1.97k
  SourceRange getSourceRange() const override LLVM_READONLY {
2857
1.97k
    if (LocStart.isValid())
2858
1.97k
      return SourceRange(LocStart, getLocation());
2859
0
    else
2860
0
      return SourceRange(getLocation());
2861
1.97k
  }
2862
2863
  // Implement isa/cast/dyncast/etc.
2864
82.3M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2865
82.5M
  static bool classofKind(Kind K) { return K >= firstType && 
K <= lastType51.4M
; }
2866
};
2867
2868
/// Base class for declarations which introduce a typedef-name.
2869
class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
2870
  struct alignas(8) ModedTInfo {
2871
    TypeSourceInfo *first;
2872
    QualType second;
2873
  };
2874
2875
  /// If int part is 0, we have not computed IsTransparentTag.
2876
  /// Otherwise, IsTransparentTag is (getInt() >> 1).
2877
  mutable llvm::PointerIntPair<
2878
      llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
2879
      MaybeModedTInfo;
2880
2881
  void anchor() override;
2882
2883
protected:
2884
  TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC,
2885
                  SourceLocation StartLoc, SourceLocation IdLoc,
2886
                  IdentifierInfo *Id, TypeSourceInfo *TInfo)
2887
      : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
2888
2.24M
        MaybeModedTInfo(TInfo, 0) {}
2889
2890
  using redeclarable_base = Redeclarable<TypedefNameDecl>;
2891
2892
292k
  TypedefNameDecl *getNextRedeclarationImpl() override {
2893
292k
    return getNextRedeclaration();
2894
292k
  }
2895
2896
12.5k
  TypedefNameDecl *getPreviousDeclImpl() override {
2897
12.5k
    return getPreviousDecl();
2898
12.5k
  }
2899
2900
597k
  TypedefNameDecl *getMostRecentDeclImpl() override {
2901
597k
    return getMostRecentDecl();
2902
597k
  }
2903
2904
public:
2905
  using redecl_range = redeclarable_base::redecl_range;
2906
  using redecl_iterator = redeclarable_base::redecl_iterator;
2907
2908
  using redeclarable_base::redecls_begin;
2909
  using redeclarable_base::redecls_end;
2910
  using redeclarable_base::redecls;
2911
  using redeclarable_base::getPreviousDecl;
2912
  using redeclarable_base::getMostRecentDecl;
2913
  using redeclarable_base::isFirstDecl;
2914
2915
48.4M
  bool isModed() const {
2916
48.4M
    return MaybeModedTInfo.getPointer().is<ModedTInfo *>();
2917
48.4M
  }
2918
2919
2.11M
  TypeSourceInfo *getTypeSourceInfo() const {
2920
2.11M
    return isModed() ? 
MaybeModedTInfo.getPointer().get<ModedTInfo *>()->first2.30k
2921
2.11M
                     : 
MaybeModedTInfo.getPointer().get<TypeSourceInfo *>()2.11M
;
2922
2.11M
  }
2923
2924
46.3M
  QualType getUnderlyingType() const {
2925
46.3M
    return isModed() ? 
MaybeModedTInfo.getPointer().get<ModedTInfo *>()->second26.2k
2926
46.3M
                     : MaybeModedTInfo.getPointer()
2927
46.2M
                           .get<TypeSourceInfo *>()
2928
46.2M
                           ->getType();
2929
46.3M
  }
2930
2931
7.66k
  void setTypeSourceInfo(TypeSourceInfo *newType) {
2932
7.66k
    MaybeModedTInfo.setPointer(newType);
2933
7.66k
  }
2934
2935
2.34k
  void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) {
2936
2.34k
    MaybeModedTInfo.setPointer(new (getASTContext(), 8)
2937
2.34k
                                   ModedTInfo({unmodedTSI, modedTy}));
2938
2.34k
  }
2939
2940
  /// Retrieves the canonical declaration of this typedef-name.
2941
10.1M
  TypedefNameDecl *getCanonicalDecl() override { return getFirstDecl(); }
2942
67
  const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
2943
2944
  /// Retrieves the tag declaration for which this is the typedef name for
2945
  /// linkage purposes, if any.
2946
  ///
2947
  /// \param AnyRedecl Look for the tag declaration in any redeclaration of
2948
  /// this typedef declaration.
2949
  TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
2950
2951
  /// Determines if this typedef shares a name and spelling location with its
2952
  /// underlying tag type, as is the case with the NS_ENUM macro.
2953
  bool isTransparentTag() const {
2954
    if (MaybeModedTInfo.getInt())
2955
      return MaybeModedTInfo.getInt() & 0x2;
2956
    return isTransparentTagSlow();
2957
  }
2958
2959
  // Implement isa/cast/dyncast/etc.
2960
69.4M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2961
69.4M
  static bool classofKind(Kind K) {
2962
69.4M
    return K >= firstTypedefName && 
K <= lastTypedefName54.7M
;
2963
69.4M
  }
2964
2965
private:
2966
  bool isTransparentTagSlow() const;
2967
};
2968
2969
/// Represents the declaration of a typedef-name via the 'typedef'
2970
/// type specifier.
2971
class TypedefDecl : public TypedefNameDecl {
2972
  TypedefDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2973
              SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
2974
2.18M
      : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
2975
2976
public:
2977
  static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
2978
                             SourceLocation StartLoc, SourceLocation IdLoc,
2979
                             IdentifierInfo *Id, TypeSourceInfo *TInfo);
2980
  static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2981
2982
  SourceRange getSourceRange() const override LLVM_READONLY;
2983
2984
  // Implement isa/cast/dyncast/etc.
2985
1.89k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2986
1.89k
  static bool classofKind(Kind K) { return K == Typedef; }
2987
};
2988
2989
/// Represents the declaration of a typedef-name via a C++11
2990
/// alias-declaration.
2991
class TypeAliasDecl : public TypedefNameDecl {
2992
  /// The template for which this is the pattern, if any.
2993
  TypeAliasTemplateDecl *Template;
2994
2995
  TypeAliasDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2996
                SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
2997
      : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
2998
56.0k
        Template(nullptr) {}
2999
3000
public:
3001
  static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
3002
                               SourceLocation StartLoc, SourceLocation IdLoc,
3003
                               IdentifierInfo *Id, TypeSourceInfo *TInfo);
3004
  static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3005
3006
  SourceRange getSourceRange() const override LLVM_READONLY;
3007
3008
2.37k
  TypeAliasTemplateDecl *getDescribedAliasTemplate() const { return Template; }
3009
47.5k
  void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT) { Template = TAT; }
3010
3011
  // Implement isa/cast/dyncast/etc.
3012
1.17M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3013
1.17M
  static bool classofKind(Kind K) { return K == TypeAlias; }
3014
};
3015
3016
/// Represents the declaration of a struct/union/class/enum.
3017
class TagDecl
3018
  : public TypeDecl, public DeclContext, public Redeclarable<TagDecl> {
3019
public:
3020
  // This is really ugly.
3021
  using TagKind = TagTypeKind;
3022
3023
private:
3024
  // FIXME: This can be packed into the bitfields in Decl.
3025
  /// The TagKind enum.
3026
  unsigned TagDeclKind : 3;
3027
3028
  /// True if this is a definition ("struct foo {};"), false if it is a
3029
  /// declaration ("struct foo;").  It is not considered a definition
3030
  /// until the definition has been fully processed.
3031
  unsigned IsCompleteDefinition : 1;
3032
3033
protected:
3034
  /// True if this is currently being defined.
3035
  unsigned IsBeingDefined : 1;
3036
3037
private:
3038
  /// True if this tag declaration is "embedded" (i.e., defined or declared
3039
  /// for the very first time) in the syntax of a declarator.
3040
  unsigned IsEmbeddedInDeclarator : 1;
3041
3042
  /// True if this tag is free standing, e.g. "struct foo;".
3043
  unsigned IsFreeStanding : 1;
3044
3045
protected:
3046
  // These are used by (and only defined for) EnumDecl.
3047
  unsigned NumPositiveBits : 8;
3048
  unsigned NumNegativeBits : 8;
3049
3050
  /// True if this tag declaration is a scoped enumeration. Only
3051
  /// possible in C++11 mode.
3052
  unsigned IsScoped : 1;
3053
3054
  /// If this tag declaration is a scoped enum,
3055
  /// then this is true if the scoped enum was declared using the class
3056
  /// tag, false if it was declared with the struct tag. No meaning is
3057
  /// associated if this tag declaration is not a scoped enum.
3058
  unsigned IsScopedUsingClassTag : 1;
3059
3060
  /// True if this is an enumeration with fixed underlying type. Only
3061
  /// possible in C++11, Microsoft extensions, or Objective C mode.
3062
  unsigned IsFixed : 1;
3063
3064
  /// Indicates whether it is possible for declarations of this kind
3065
  /// to have an out-of-date definition.
3066
  ///
3067
  /// This option is only enabled when modules are enabled.
3068
  unsigned MayHaveOutOfDateDef : 1;
3069
3070
  /// Has the full definition of this type been required by a use somewhere in
3071
  /// the TU.
3072
  unsigned IsCompleteDefinitionRequired : 1;
3073
3074
private:
3075
  SourceRange BraceRange;
3076
3077
  // A struct representing syntactic qualifier info,
3078
  // to be used for the (uncommon) case of out-of-line declarations.
3079
  using ExtInfo = QualifierInfo;
3080
3081
  /// If the (out-of-line) tag declaration name
3082
  /// is qualified, it points to the qualifier info (nns and range);
3083
  /// otherwise, if the tag declaration is anonymous and it is part of
3084
  /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
3085
  /// otherwise, if the tag declaration is anonymous and it is used as a
3086
  /// declaration specifier for variables, it points to the first VarDecl (used
3087
  /// for mangling);
3088
  /// otherwise, it is a null (TypedefNameDecl) pointer.
3089
  llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3090
3091
1.65M
  bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo *>(); }
3092
57.5k
  ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo *>(); }
3093
268
  const ExtInfo *getExtInfo() const {
3094
268
    return TypedefNameDeclOrQualifier.get<ExtInfo *>();
3095
268
  }
3096
3097
protected:
3098
  TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3099
          SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3100
          SourceLocation StartL)
3101
      : TypeDecl(DK, DC, L, Id, StartL), DeclContext(DK), redeclarable_base(C),
3102
        TagDeclKind(TK), IsCompleteDefinition(false), IsBeingDefined(false),
3103
        IsEmbeddedInDeclarator(false), IsFreeStanding(false),
3104
        IsCompleteDefinitionRequired(false),
3105
3.91M
        TypedefNameDeclOrQualifier((TypedefNameDecl *)nullptr) {
3106
3.91M
    assert((DK != Enum || TK == TTK_Enum) &&
3107
3.91M
           "EnumDecl not matched with TTK_Enum");
3108
3.91M
    setPreviousDecl(PrevDecl);
3109
3.91M
  }
3110
3111
  using redeclarable_base = Redeclarable<TagDecl>;
3112
3113
711k
  TagDecl *getNextRedeclarationImpl() override {
3114
711k
    return getNextRedeclaration();
3115
711k
  }
3116
3117
14.1k
  TagDecl *getPreviousDeclImpl() override {
3118
14.1k
    return getPreviousDecl();
3119
14.1k
  }
3120
3121
1.99M
  TagDecl *getMostRecentDeclImpl() override {
3122
1.99M
    return getMostRecentDecl();
3123
1.99M
  }
3124
3125
  /// Completes the definition of this tag declaration.
3126
  ///
3127
  /// This is a helper function for derived classes.
3128
  void completeDefinition();
3129
3130
public:
3131
  friend class ASTDeclReader;
3132
  friend class ASTDeclWriter;
3133
3134
  using redecl_range = redeclarable_base::redecl_range;
3135
  using redecl_iterator = redeclarable_base::redecl_iterator;
3136
3137
  using redeclarable_base::redecls_begin;
3138
  using redeclarable_base::redecls_end;
3139
  using redeclarable_base::redecls;
3140
  using redeclarable_base::getPreviousDecl;
3141
  using redeclarable_base::getMostRecentDecl;
3142
  using redeclarable_base::isFirstDecl;
3143
3144
1.18M
  SourceRange getBraceRange() const { return BraceRange; }
3145
1.82M
  void setBraceRange(SourceRange R) { BraceRange = R; }
3146
3147
  /// Return SourceLocation representing start of source
3148
  /// range ignoring outer template declarations.
3149
1.15M
  SourceLocation getInnerLocStart() const { return getLocStart(); }
3150
3151
  /// Return SourceLocation representing start of source
3152
  /// range taking into account any outer template declarations.
3153
  SourceLocation getOuterLocStart() const;
3154
  SourceRange getSourceRange() const override LLVM_READONLY;
3155
3156
  TagDecl *getCanonicalDecl() override;
3157
14.5k
  const TagDecl *getCanonicalDecl() const {
3158
14.5k
    return const_cast<TagDecl*>(this)->getCanonicalDecl();
3159
14.5k
  }
3160
3161
  /// Return true if this declaration is a completion definition of the type.
3162
  /// Provided for consistency.
3163
69.1k
  bool isThisDeclarationADefinition() const {
3164
69.1k
    return isCompleteDefinition();
3165
69.1k
  }
3166
3167
  /// Return true if this decl has its body fully specified.
3168
476M
  bool isCompleteDefinition() const {
3169
476M
    return IsCompleteDefinition;
3170
476M
  }
3171
3172
  /// Return true if this complete decl is
3173
  /// required to be complete for some existing use.
3174
6.65M
  bool isCompleteDefinitionRequired() const {
3175
6.65M
    return IsCompleteDefinitionRequired;
3176
6.65M
  }
3177
3178
  /// Return true if this decl is currently being defined.
3179
51.0M
  bool isBeingDefined() const {
3180
51.0M
    return IsBeingDefined;
3181
51.0M
  }
3182
3183
35.7k
  bool isEmbeddedInDeclarator() const {
3184
35.7k
    return IsEmbeddedInDeclarator;
3185
35.7k
  }
3186
224k
  void setEmbeddedInDeclarator(bool isInDeclarator) {
3187
224k
    IsEmbeddedInDeclarator = isInDeclarator;
3188
224k
  }
3189
3190
35.8k
  bool isFreeStanding() const { return IsFreeStanding; }
3191
937k
  void setFreeStanding(bool isFreeStanding = true) {
3192
937k
    IsFreeStanding = isFreeStanding;
3193
937k
  }
3194
3195
  /// Whether this declaration declares a type that is
3196
  /// dependent, i.e., a type that somehow depends on template
3197
  /// parameters.
3198
12.8M
  bool isDependentType() const { return isDependentContext(); }
3199
3200
  /// Starts the definition of this tag declaration.
3201
  ///
3202
  /// This method should be invoked at the beginning of the definition
3203
  /// of this tag declaration. It will set the tag type into a state
3204
  /// where it is in the process of being defined.
3205
  void startDefinition();
3206
3207
  /// Returns the TagDecl that actually defines this
3208
  ///  struct/union/class/enum.  When determining whether or not a
3209
  ///  struct/union/class/enum has a definition, one should use this
3210
  ///  method as opposed to 'isDefinition'.  'isDefinition' indicates
3211
  ///  whether or not a specific TagDecl is defining declaration, not
3212
  ///  whether or not the struct/union/class/enum type is defined.
3213
  ///  This method returns NULL if there is no TagDecl that defines
3214
  ///  the struct/union/class/enum.
3215
  TagDecl *getDefinition() const;
3216
3217
1.25k
  void setCompleteDefinition(bool V) { IsCompleteDefinition = V; }
3218
3219
1.12M
  void setCompleteDefinitionRequired(bool V = true) {
3220
1.12M
    IsCompleteDefinitionRequired = V;
3221
1.12M
  }
3222
3223
136k
  StringRef getKindName() const {
3224
136k
    return TypeWithKeyword::getTagTypeKindName(getTagKind());
3225
136k
  }
3226
3227
27.8M
  TagKind getTagKind() const {
3228
27.8M
    return TagKind(TagDeclKind);
3229
27.8M
  }
3230
3231
855k
  void setTagKind(TagKind TK) { TagDeclKind = TK; }
3232
3233
2.36M
  bool isStruct() const { return getTagKind() == TTK_Struct; }
3234
5.73M
  bool isInterface() const { return getTagKind() == TTK_Interface; }
3235
1.14M
  bool isClass()  const { return getTagKind() == TTK_Class; }
3236
12.9M
  bool isUnion()  const { return getTagKind() == TTK_Union; }
3237
0
  bool isEnum()   const { return getTagKind() == TTK_Enum; }
3238
3239
  /// Is this tag type named, either directly or via being defined in
3240
  /// a typedef of this type?
3241
  ///
3242
  /// C++11 [basic.link]p8:
3243
  ///   A type is said to have linkage if and only if:
3244
  ///     - it is a class or enumeration type that is named (or has a
3245
  ///       name for linkage purposes) and the name has linkage; ...
3246
  /// C++11 [dcl.typedef]p9:
3247
  ///   If the typedef declaration defines an unnamed class (or enum),
3248
  ///   the first typedef-name declared by the declaration to be that
3249
  ///   class type (or enum type) is used to denote the class type (or
3250
  ///   enum type) for linkage purposes only.
3251
  ///
3252
  /// C does not have an analogous rule, but the same concept is
3253
  /// nonetheless useful in some places.
3254
5.76M
  bool hasNameForLinkage() const {
3255
5.76M
    return (getDeclName() || 
getTypedefNameForAnonDecl()142k
);
3256
5.76M
  }
3257
3258
275k
  TypedefNameDecl *getTypedefNameForAnonDecl() const {
3259
275k
    return hasExtInfo() ? 
nullptr29
3260
275k
                        : 
TypedefNameDeclOrQualifier.get<TypedefNameDecl *>()275k
;
3261
275k
  }
3262
3263
  void setTypedefNameForAnonDecl(TypedefNameDecl *TDD);
3264
3265
  /// Retrieve the nested-name-specifier that qualifies the name of this
3266
  /// declaration, if it was present in the source.
3267
0
  NestedNameSpecifier *getQualifier() const {
3268
0
    return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
3269
0
                        : nullptr;
3270
0
  }
3271
3272
  /// Retrieve the nested-name-specifier (with source-location
3273
  /// information) that qualifies the name of this declaration, if it was
3274
  /// present in the source.
3275
892k
  NestedNameSpecifierLoc getQualifierLoc() const {
3276
892k
    return hasExtInfo() ? 
getExtInfo()->QualifierLoc172
3277
892k
                        : 
NestedNameSpecifierLoc()892k
;
3278
892k
  }
3279
3280
  void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
3281
3282
389k
  unsigned getNumTemplateParameterLists() const {
3283
389k
    return hasExtInfo() ? 
getExtInfo()->NumTemplParamLists72
:
0389k
;
3284
389k
  }
3285
3286
24
  TemplateParameterList *getTemplateParameterList(unsigned i) const {
3287
24
    assert(i < getNumTemplateParameterLists());
3288
24
    return getExtInfo()->TemplParamLists[i];
3289
24
  }
3290
3291
  void setTemplateParameterListsInfo(ASTContext &Context,
3292
                                     ArrayRef<TemplateParameterList *> TPLists);
3293
3294
  // Implement isa/cast/dyncast/etc.
3295
77.5M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3296
82.7M
  static bool classofKind(Kind K) { return K >= firstTag && 
K <= lastTag48.3M
; }
3297
3298
28.4k
  static DeclContext *castToDeclContext(const TagDecl *D) {
3299
28.4k
    return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
3300
28.4k
  }
3301
3302
12
  static TagDecl *castFromDeclContext(const DeclContext *DC) {
3303
12
    return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
3304
12
  }
3305
};
3306
3307
/// Represents an enum.  In C++11, enums can be forward-declared
3308
/// with a fixed underlying type, and in C we allow them to be forward-declared
3309
/// with no underlying type as an extension.
3310
class EnumDecl : public TagDecl {
3311
  /// This represent the integer type that the enum corresponds
3312
  /// to for code generation purposes.  Note that the enumerator constants may
3313
  /// have a different type than this does.
3314
  ///
3315
  /// If the underlying integer type was explicitly stated in the source
3316
  /// code, this is a TypeSourceInfo* for that type. Otherwise this type
3317
  /// was automatically deduced somehow, and this is a Type*.
3318
  ///
3319
  /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
3320
  /// some cases it won't.
3321
  ///
3322
  /// The underlying type of an enumeration never has any qualifiers, so
3323
  /// we can get away with just storing a raw Type*, and thus save an
3324
  /// extra pointer when TypeSourceInfo is needed.
3325
  llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
3326
3327
  /// The integer type that values of this type should
3328
  /// promote to.  In C, enumerators are generally of an integer type
3329
  /// directly, but gcc-style large enumerators (and all enumerators
3330
  /// in C++) are of the enum type instead.
3331
  QualType PromotionType;
3332
3333
  /// If this enumeration is an instantiation of a member enumeration
3334
  /// of a class template specialization, this is the member specialization
3335
  /// information.
3336
  MemberSpecializationInfo *SpecializationInfo = nullptr;
3337
3338
  EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3339
           SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
3340
           bool Scoped, bool ScopedUsingClassTag, bool Fixed)
3341
51.7k
      : TagDecl(Enum, TTK_Enum, C, DC, IdLoc, Id, PrevDecl, StartLoc) {
3342
51.7k
    assert(Scoped || !ScopedUsingClassTag);
3343
51.7k
    IntegerType = (const Type *)nullptr;
3344
51.7k
    NumNegativeBits = 0;
3345
51.7k
    NumPositiveBits = 0;
3346
51.7k
    IsScoped = Scoped;
3347
51.7k
    IsScopedUsingClassTag = ScopedUsingClassTag;
3348
51.7k
    IsFixed = Fixed;
3349
51.7k
  }
3350
3351
  void anchor() override;
3352
3353
  void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
3354
                                    TemplateSpecializationKind TSK);
3355
public:
3356
  friend class ASTDeclReader;
3357
3358
405k
  EnumDecl *getCanonicalDecl() override {
3359
405k
    return cast<EnumDecl>(TagDecl::getCanonicalDecl());
3360
405k
  }
3361
0
  const EnumDecl *getCanonicalDecl() const {
3362
0
    return const_cast<EnumDecl*>(this)->getCanonicalDecl();
3363
0
  }
3364
3365
52.2k
  EnumDecl *getPreviousDecl() {
3366
52.2k
    return cast_or_null<EnumDecl>(
3367
52.2k
            static_cast<TagDecl *>(this)->getPreviousDecl());
3368
52.2k
  }
3369
49.2k
  const EnumDecl *getPreviousDecl() const {
3370
49.2k
    return const_cast<EnumDecl*>(this)->getPreviousDecl();
3371
49.2k
  }
3372
3373
311
  EnumDecl *getMostRecentDecl() {
3374
311
    return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3375
311
  }
3376
0
  const EnumDecl *getMostRecentDecl() const {
3377
0
    return const_cast<EnumDecl*>(this)->getMostRecentDecl();
3378
0
  }
3379
3380
79.2k
  EnumDecl *getDefinition() const {
3381
79.2k
    return cast_or_null<EnumDecl>(TagDecl::getDefinition());
3382
79.2k
  }
3383
3384
  static EnumDecl *Create(ASTContext &C, DeclContext *DC,
3385
                          SourceLocation StartLoc, SourceLocation IdLoc,
3386
                          IdentifierInfo *Id, EnumDecl *PrevDecl,
3387
                          bool IsScoped, bool IsScopedUsingClassTag,
3388
                          bool IsFixed);
3389
  static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3390
3391
  /// When created, the EnumDecl corresponds to a
3392
  /// forward-declared enum. This method is used to mark the
3393
  /// declaration as being defined; its enumerators have already been
3394
  /// added (via DeclContext::addDecl). NewType is the new underlying
3395
  /// type of the enumeration type.
3396
  void completeDefinition(QualType NewType,
3397
                          QualType PromotionType,
3398
                          unsigned NumPositiveBits,
3399
                          unsigned NumNegativeBits);
3400
3401
  // Iterates through the enumerators of this enumeration.
3402
  using enumerator_iterator = specific_decl_iterator<EnumConstantDecl>;
3403
  using enumerator_range =
3404
      llvm::iterator_range<specific_decl_iterator<EnumConstantDecl>>;
3405
3406
6.22k
  enumerator_range enumerators() const {
3407
6.22k
    return enumerator_range(enumerator_begin(), enumerator_end());
3408
6.22k
  }
3409
3410
33.2k
  enumerator_iterator enumerator_begin() const {
3411
33.2k
    const EnumDecl *E = getDefinition();
3412
33.2k
    if (!E)
3413
195
      E = this;
3414
33.2k
    return enumerator_iterator(E->decls_begin());
3415
33.2k
  }
3416
3417
33.1k
  enumerator_iterator enumerator_end() const {
3418
33.1k
    const EnumDecl *E = getDefinition();
3419
33.1k
    if (!E)
3420
195
      E = this;
3421
33.1k
    return enumerator_iterator(E->decls_end());
3422
33.1k
  }
3423
3424
  /// Return the integer type that enumerators should promote to.
3425
25.9M
  QualType getPromotionType() const { return PromotionType; }
3426
3427
  /// Set the promotion type.
3428
8.22k
  void setPromotionType(QualType T) { PromotionType = T; }
3429
3430
  /// Return the integer type this enum decl corresponds to.
3431
  /// This returns a null QualType for an enum forward definition with no fixed
3432
  /// underlying type.
3433
1.35M
  QualType getIntegerType() const {
3434
1.35M
    if (!IntegerType)
3435
26
      return QualType();
3436
1.35M
    if (const Type *T = IntegerType.dyn_cast<const Type*>())
3437
1.18M
      return QualType(T, 0);
3438
174k
    return IntegerType.get<TypeSourceInfo*>()->getType().getUnqualifiedType();
3439
174k
  }
3440
3441
  /// Set the underlying integer type.
3442
1.53k
  void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
3443
3444
  /// Set the underlying integer type source info.
3445
6.94k
  void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
3446
3447
  /// Return the type source info for the underlying integer type,
3448
  /// if no type source info exists, return 0.
3449
1.63k
  TypeSourceInfo *getIntegerTypeSourceInfo() const {
3450
1.63k
    return IntegerType.dyn_cast<TypeSourceInfo*>();
3451
1.63k
  }
3452
3453
  /// Retrieve the source range that covers the underlying type if
3454
  /// specified.
3455
  SourceRange getIntegerTypeRange() const LLVM_READONLY;
3456
3457
  /// Returns the width in bits required to store all the
3458
  /// non-negative enumerators of this enum.
3459
79.5k
  unsigned getNumPositiveBits() const {
3460
79.5k
    return NumPositiveBits;
3461
79.5k
  }
3462
49.0k
  void setNumPositiveBits(unsigned Num) {
3463
49.0k
    NumPositiveBits = Num;
3464
49.0k
    assert(NumPositiveBits == Num && "can't store this bitcount");
3465
49.0k
  }
3466
3467
  /// Returns the width in bits required to store all the
3468
  /// negative enumerators of this enum.  These widths include
3469
  /// the rightmost leading 1;  that is:
3470
  ///
3471
  /// MOST NEGATIVE ENUMERATOR     PATTERN     NUM NEGATIVE BITS
3472
  /// ------------------------     -------     -----------------
3473
  ///                       -1     1111111                     1
3474
  ///                      -10     1110110                     5
3475
  ///                     -101     1001011                     8
3476
79.5k
  unsigned getNumNegativeBits() const {
3477
79.5k
    return NumNegativeBits;
3478
79.5k
  }
3479
49.0k
  void setNumNegativeBits(unsigned Num) {
3480
49.0k
    NumNegativeBits = Num;
3481
49.0k
  }
3482
3483
  /// Returns true if this is a C++11 scoped enumeration.
3484
49.2M
  bool isScoped() const {
3485
49.2M
    return IsScoped;
3486
49.2M
  }
3487
3488
  /// Returns true if this is a C++11 scoped enumeration.
3489
3.25k
  bool isScopedUsingClassTag() const {
3490
3.25k
    return IsScopedUsingClassTag;
3491
3.25k
  }
3492
3493
  /// Returns true if this is an Objective-C, C++11, or
3494
  /// Microsoft-style enumeration with a fixed underlying type.
3495
15.1M
  bool isFixed() const {
3496
15.1M
    return IsFixed;
3497
15.1M
  }
3498
3499
  /// Returns true if this can be considered a complete type.
3500
33.2M
  bool isComplete() const {
3501
33.2M
    // IntegerType is set for fixed type enums and non-fixed but implicitly
3502
33.2M
    // int-sized Microsoft enums.
3503
33.2M
    return isCompleteDefinition() || 
IntegerType201k
;
3504
33.2M
  }
3505
3506
  /// Returns true if this enum is either annotated with
3507
  /// enum_extensibility(closed) or isn't annotated with enum_extensibility.
3508
  bool isClosed() const;
3509
3510
  /// Returns true if this enum is annotated with flag_enum and isn't annotated
3511
  /// with enum_extensibility(open).
3512
  bool isClosedFlag() const;
3513
3514
  /// Returns true if this enum is annotated with neither flag_enum nor
3515
  /// enum_extensibility(open).
3516
  bool isClosedNonFlag() const;
3517
3518
  /// Retrieve the enum definition from which this enumeration could
3519
  /// be instantiated, if it is an instantiation (rather than a non-template).
3520
  EnumDecl *getTemplateInstantiationPattern() const;
3521
3522
  /// Returns the enumeration (declared within the template)
3523
  /// from which this enumeration type was instantiated, or NULL if
3524
  /// this enumeration was not instantiated from any template.
3525
  EnumDecl *getInstantiatedFromMemberEnum() const;
3526
3527
  /// If this enumeration is a member of a specialization of a
3528
  /// templated class, determine what kind of template specialization
3529
  /// or instantiation this is.
3530
  TemplateSpecializationKind getTemplateSpecializationKind() const;
3531
3532
  /// For an enumeration member that was instantiated from a member
3533
  /// enumeration of a templated class, set the template specialiation kind.
3534
  void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
3535
                        SourceLocation PointOfInstantiation = SourceLocation());
3536
3537
  /// If this enumeration is an instantiation of a member enumeration of
3538
  /// a class template specialization, retrieves the member specialization
3539
  /// information.
3540
7.99k
  MemberSpecializationInfo *getMemberSpecializationInfo() const {
3541
7.99k
    return SpecializationInfo;
3542
7.99k
  }
3543
3544
  /// Specify that this enumeration is an instantiation of the
3545
  /// member enumeration ED.
3546
  void setInstantiationOfMemberEnum(EnumDecl *ED,
3547
3.00k
                                    TemplateSpecializationKind TSK) {
3548
3.00k
    setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
3549
3.00k
  }
3550
3551
35.3M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3552
118M
  static bool classofKind(Kind K) { return K == Enum; }
3553
};
3554
3555
/// Represents a struct/union/class.  For example:
3556
///   struct X;                  // Forward declaration, no "body".
3557
///   union Y { int A, B; };     // Has body with members A and B (FieldDecls).
3558
/// This decl will be marked invalid if *any* members are invalid.
3559
class RecordDecl : public TagDecl {
3560
public:
3561
  /// Enum that represents the different ways arguments are passed to and
3562
  /// returned from function calls. This takes into account the target-specific
3563
  /// and version-specific rules along with the rules determined by the
3564
  /// language.
3565
  enum ArgPassingKind : unsigned {
3566
    /// The argument of this type can be passed directly in registers.
3567
    APK_CanPassInRegs,
3568
3569
    /// The argument of this type cannot be passed directly in registers.
3570
    /// Records containing this type as a subobject are not forced to be passed
3571
    /// indirectly. This value is used only in C++. This value is required by
3572
    /// C++ because, in uncommon situations, it is possible for a class to have
3573
    /// only trivial copy/move constructors even when one of its subobjects has
3574
    /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
3575
    /// constructor in the derived class is deleted).
3576
    APK_CannotPassInRegs,
3577
3578
    /// The argument of this type cannot be passed directly in registers.
3579
    /// Records containing this type as a subobject are forced to be passed
3580
    /// indirectly.
3581
    APK_CanNeverPassInRegs
3582
  };
3583
3584
private:
3585
  friend class DeclContext;
3586
3587
  // FIXME: This can be packed into the bitfields in Decl.
3588
  /// This is true if this struct ends with a flexible
3589
  /// array member (e.g. int X[]) or if this union contains a struct that does.
3590
  /// If so, this cannot be contained in arrays or other structs as a member.
3591
  unsigned HasFlexibleArrayMember : 1;
3592
3593
  /// Whether this is the type of an anonymous struct or union.
3594
  unsigned AnonymousStructOrUnion : 1;
3595
3596
  /// This is true if this struct has at least one member
3597
  /// containing an Objective-C object pointer type.
3598
  unsigned HasObjectMember : 1;
3599
3600
  /// This is true if struct has at least one member of
3601
  /// 'volatile' type.
3602
  unsigned HasVolatileMember : 1;
3603
3604
  /// Whether the field declarations of this record have been loaded
3605
  /// from external storage. To avoid unnecessary deserialization of
3606
  /// methods/nested types we allow deserialization of just the fields
3607
  /// when needed.
3608
  mutable unsigned LoadedFieldsFromExternalStorage : 1;
3609
3610
  /// Basic properties of non-trivial C structs.
3611
  unsigned NonTrivialToPrimitiveDefaultInitialize : 1;
3612
  unsigned NonTrivialToPrimitiveCopy : 1;
3613
  unsigned NonTrivialToPrimitiveDestroy : 1;
3614
3615
  /// Indicates whether this struct is destroyed in the callee.
3616
  ///
3617
  /// Please note that MSVC won't merge adjacent bitfields if they don't have
3618
  /// the same type.
3619
  unsigned ParamDestroyedInCallee : 1;
3620
3621
  /// Represents the way this type is passed to a function.
3622
  unsigned ArgPassingRestrictions : 2;
3623
3624
protected:
3625
  RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3626
             SourceLocation StartLoc, SourceLocation IdLoc,
3627
             IdentifierInfo *Id, RecordDecl *PrevDecl);
3628
3629
public:
3630
  static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
3631
                            SourceLocation StartLoc, SourceLocation IdLoc,
3632
                            IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
3633
  static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
3634
3635
3.77M
  RecordDecl *getPreviousDecl() {
3636
3.77M
    return cast_or_null<RecordDecl>(
3637
3.77M
            static_cast<TagDecl *>(this)->getPreviousDecl());
3638
3.77M
  }
3639
1.88M
  const RecordDecl *getPreviousDecl() const {
3640
1.88M
    return const_cast<RecordDecl*>(this)->getPreviousDecl();
3641
1.88M
  }
3642
3643
283M
  RecordDecl *getMostRecentDecl() {
3644
283M
    return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3645
283M
  }
3646
0
  const RecordDecl *getMostRecentDecl() const {
3647
0
    return const_cast<RecordDecl*>(this)->getMostRecentDecl();
3648
0
  }
3649
3650
3.45M
  bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
3651
32.6k
  void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; }
3652
3653
  /// Whether this is an anonymous struct or union. To be an anonymous
3654
  /// struct or union, it must have been declared without a name and
3655
  /// there must be no objects of this type declared, e.g.,
3656
  /// @code
3657
  ///   union { int i; float f; };
3658
  /// @endcode
3659
  /// is an anonymous union but neither of the following are:
3660
  /// @code
3661
  ///  union X { int i; float f; };
3662
  ///  union { int i; float f; } obj;
3663
  /// @endcode
3664
6.33M
  bool isAnonymousStructOrUnion() const { return AnonymousStructOrUnion; }
3665
38.0k
  void setAnonymousStructOrUnion(bool Anon) {
3666
38.0k
    AnonymousStructOrUnion = Anon;
3667
38.0k
  }
3668
3669
1.32M
  bool hasObjectMember() const { return HasObjectMember; }
3670
32.6k
  void setHasObjectMember (bool val) { HasObjectMember = val; }
3671
3672
1.32M
  bool hasVolatileMember() const { return HasVolatileMember; }
3673
87.8k
  void setHasVolatileMember (bool val) { HasVolatileMember = val; }
3674
3675
0
  bool hasLoadedFieldsFromExternalStorage() const {
3676
0
    return LoadedFieldsFromExternalStorage;
3677
0
  }
3678
0
  void setHasLoadedFieldsFromExternalStorage(bool val) {
3679
0
    LoadedFieldsFromExternalStorage = val;
3680
0
  }
3681
3682
  /// Functions to query basic properties of non-trivial C structs.
3683
108k
  bool isNonTrivialToPrimitiveDefaultInitialize() const {
3684
108k
    return NonTrivialToPrimitiveDefaultInitialize;
3685
108k
  }
3686
3687
32.4k
  void setNonTrivialToPrimitiveDefaultInitialize(bool V) {
3688
32.4k
    NonTrivialToPrimitiveDefaultInitialize = V;
3689
32.4k
  }
3690
3691
107k
  bool isNonTrivialToPrimitiveCopy() const {
3692
107k
    return NonTrivialToPrimitiveCopy;
3693
107k
  }
3694
3695
32.4k
  void setNonTrivialToPrimitiveCopy(bool V) {
3696
32.4k
    NonTrivialToPrimitiveCopy = V;
3697
32.4k
  }
3698
3699
139k
  bool isNonTrivialToPrimitiveDestroy() const {
3700
139k
    return NonTrivialToPrimitiveDestroy;
3701
139k
  }
3702
3703
32.4k
  void setNonTrivialToPrimitiveDestroy(bool V) {
3704
32.4k
    NonTrivialToPrimitiveDestroy = V;
3705
32.4k
  }
3706
3707
  /// Determine whether this class can be passed in registers. In C++ mode,
3708
  /// it must have at least one trivial, non-deleted copy or move constructor.
3709
  /// FIXME: This should be set as part of completeDefinition.
3710
22.3k
  bool canPassInRegisters() const {
3711
22.3k
    return getArgPassingRestrictions() == APK_CanPassInRegs;
3712
22.3k
  }
3713
3714
2.60M
  ArgPassingKind getArgPassingRestrictions() const {
3715
2.60M
    return static_cast<ArgPassingKind>(ArgPassingRestrictions);
3716
2.60M
  }
3717
3718
1.62M
  void setArgPassingRestrictions(ArgPassingKind Kind) {
3719
1.62M
    ArgPassingRestrictions = static_cast<uint8_t>(Kind);
3720
1.62M
  }
3721
3722
61.7k
  bool isParamDestroyedInCallee() const {
3723
61.7k
    return ParamDestroyedInCallee;
3724
61.7k
  }
3725
3726
133k
  void setParamDestroyedInCallee(bool V) {
3727
133k
    ParamDestroyedInCallee = V;
3728
133k
  }
3729
3730
  /// Determines whether this declaration represents the
3731
  /// injected class name.
3732
  ///
3733
  /// The injected class name in C++ is the name of the class that
3734
  /// appears inside the class itself. For example:
3735
  ///
3736
  /// \code
3737
  /// struct C {
3738
  ///   // C is implicitly declared here as a synonym for the class name.
3739
  /// };
3740
  ///
3741
  /// C::C c; // same as "C c;"
3742
  /// \endcode
3743
  bool isInjectedClassName() const;
3744
3745
  /// Determine whether this record is a class describing a lambda
3746
  /// function object.
3747
  bool isLambda() const;
3748
3749
  /// Determine whether this record is a record for captured variables in
3750
  /// CapturedStmt construct.
3751
  bool isCapturedRecord() const;
3752
3753
  /// Mark the record as a record for captured variables in CapturedStmt
3754
  /// construct.
3755
  void setCapturedRecord();
3756
3757
  /// Returns the RecordDecl that actually defines
3758
  ///  this struct/union/class.  When determining whether or not a
3759
  ///  struct/union/class is completely defined, one should use this
3760
  ///  method as opposed to 'isCompleteDefinition'.
3761
  ///  'isCompleteDefinition' indicates whether or not a specific
3762
  ///  RecordDecl is a completed definition, not whether or not the
3763
  ///  record type is defined.  This method returns NULL if there is
3764
  ///  no RecordDecl that defines the struct/union/tag.
3765
6.75M
  RecordDecl *getDefinition() const {
3766
6.75M
    return cast_or_null<RecordDecl>(TagDecl::getDefinition());
3767
6.75M
  }
3768
3769
  // Iterator access to field members. The field iterator only visits
3770
  // the non-static data members of this class, ignoring any static
3771
  // data members, functions, constructors, destructors, etc.
3772
  using field_iterator = specific_decl_iterator<FieldDecl>;
3773
  using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
3774
3775
2.47M
  field_range fields() const { return field_range(field_begin(), field_end()); }
3776
  field_iterator field_begin() const;
3777
3778
3.81M
  field_iterator field_end() const {
3779
3.81M
    return field_iterator(decl_iterator());
3780
3.81M
  }
3781
3782
  // Whether there are any fields (non-static data members) in this record.
3783
566k
  bool field_empty() const {
3784
566k
    return field_begin() == field_end();
3785
566k
  }
3786
3787
  /// Note that the definition of this type is now complete.
3788
  virtual void completeDefinition();
3789
3790
32.0M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3791
57.6M
  static bool classofKind(Kind K) {
3792
57.6M
    return K >= firstRecord && 
K <= lastRecord50.8M
;
3793
57.6M
  }
3794
3795
  /// Get whether or not this is an ms_struct which can
3796
  /// be turned on with an attribute, pragma, or -mms-bitfields
3797
  /// commandline option.
3798
  bool isMsStruct(const ASTContext &C) const;
3799
3800
  /// Whether we are allowed to insert extra padding between fields.
3801
  /// These padding are added to help AddressSanitizer detect
3802
  /// intra-object-overflow bugs.
3803
  bool mayInsertExtraPadding(bool EmitRemark = false) const;
3804
3805
  /// Finds the first data member which has a name.
3806
  /// nullptr is returned if no named data member exists.
3807
  const FieldDecl *findFirstNamedDataMember() const;  
3808
3809
private:
3810
  /// Deserialize just the fields.
3811
  void LoadFieldsFromExternalStorage() const;
3812
};
3813
3814
class FileScopeAsmDecl : public Decl {
3815
  StringLiteral *AsmString;
3816
  SourceLocation RParenLoc;
3817
3818
  FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring,
3819
                   SourceLocation StartL, SourceLocation EndL)
3820
1.17k
    : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
3821
3822
  virtual void anchor();
3823
3824
public:
3825
  static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC,
3826
                                  StringLiteral *Str, SourceLocation AsmLoc,
3827
                                  SourceLocation RParenLoc);
3828
3829
  static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3830
  
3831
3
  SourceLocation getAsmLoc() const { return getLocation(); }
3832
62
  SourceLocation getRParenLoc() const { return RParenLoc; }
3833
113
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3834
3
  SourceRange getSourceRange() const override LLVM_READONLY {
3835
3
    return SourceRange(getAsmLoc(), getRParenLoc());
3836
3
  }
3837
3838
3
  const StringLiteral *getAsmString() const { return AsmString; }
3839
1.05k
  StringLiteral *getAsmString() { return AsmString; }
3840
113
  void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
3841
3842
708k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3843
708k
  static bool classofKind(Kind K) { return K == FileScopeAsm; }
3844
};
3845
3846
/// Pepresents a block literal declaration, which is like an
3847
/// unnamed FunctionDecl.  For example:
3848
/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
3849
class BlockDecl : public Decl, public DeclContext {
3850
public:
3851
  /// A class which contains all the information about a particular
3852
  /// captured value.
3853
  class Capture {
3854
    enum {
3855
      flag_isByRef = 0x1,
3856
      flag_isNested = 0x2
3857
    };
3858
3859
    /// The variable being captured.
3860
    llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
3861
3862
    /// The copy expression, expressed in terms of a DeclRef (or
3863
    /// BlockDeclRef) to the captured variable.  Only required if the
3864
    /// variable has a C++ class type.
3865
    Expr *CopyExpr;
3866
3867
  public:
3868
    Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
3869
      : VariableAndFlags(variable,
3870
                  (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
3871
2.71k
        CopyExpr(copy) {}
3872
3873
    /// The variable being captured.
3874
18.3k
    VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
3875
3876
    /// Whether this is a "by ref" capture, i.e. a capture of a __block
3877
    /// variable.
3878
14.0k
    bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
3879
3880
    /// Whether this is a nested capture, i.e. the variable captured
3881
    /// is not from outside the immediately enclosing function/block.
3882
3.33k
    bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
3883
3884
1.56k
    bool hasCopyExpr() const { return CopyExpr != nullptr; }
3885
5.30k
    Expr *getCopyExpr() const { return CopyExpr; }
3886
0
    void setCopyExpr(Expr *e) { CopyExpr = e; }
3887
  };
3888
3889
private:
3890
  // FIXME: This can be packed into the bitfields in Decl.
3891
  bool IsVariadic : 1;
3892
  bool CapturesCXXThis : 1;
3893
  bool BlockMissingReturnType : 1;
3894
  bool IsConversionFromLambda : 1;
3895
3896
  /// A bit that indicates this block is passed directly to a function as a
3897
  /// non-escaping parameter.
3898
  bool DoesNotEscape : 1;
3899
3900
  /// A new[]'d array of pointers to ParmVarDecls for the formal
3901
  /// parameters of this function.  This is null if a prototype or if there are
3902
  /// no formals.
3903
  ParmVarDecl **ParamInfo = nullptr;
3904
  unsigned NumParams = 0;
3905
3906
  Stmt *Body = nullptr;
3907
  TypeSourceInfo *SignatureAsWritten = nullptr;
3908
3909
  const Capture *Captures = nullptr;
3910
  unsigned NumCaptures = 0;
3911
3912
  unsigned ManglingNumber = 0;
3913
  Decl *ManglingContextDecl = nullptr;
3914
3915
protected:
3916
  BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
3917
      : Decl(Block, DC, CaretLoc), DeclContext(Block), IsVariadic(false),
3918
        CapturesCXXThis(false), BlockMissingReturnType(true),
3919
2.56k
        IsConversionFromLambda(false), DoesNotEscape(false) {}
3920
3921
public:
3922
  static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L); 
3923
  static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3924
  
3925
20.2k
  SourceLocation getCaretLocation() const { return getLocation(); }
3926
3927
193
  bool isVariadic() const { return IsVariadic; }
3928
2.56k
  void setIsVariadic(bool value) { IsVariadic = value; }
3929
3930
0
  CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
3931
21.2k
  Stmt *getBody() const override { return (Stmt*) Body; }
3932
2.55k
  void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
3933
3934
2.52k
  void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
3935
969
  TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
3936
3937
  // ArrayRef access to formal parameters.
3938
4.88k
  ArrayRef<ParmVarDecl *> parameters() const {
3939
4.88k
    return {ParamInfo, getNumParams()};
3940
4.88k
  }
3941
5.66k
  MutableArrayRef<ParmVarDecl *> parameters() {
3942
5.66k
    return {ParamInfo, getNumParams()};
3943
5.66k
  }
3944
3945
  // Iterator access to formal parameters.
3946
  using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator;
3947
  using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator;
3948
3949
157
  bool param_empty() const { return parameters().empty(); }
3950
55
  param_iterator param_begin() { return parameters().begin(); }
3951
23
  param_iterator param_end() { return parameters().end(); }
3952
1.07k
  param_const_iterator param_begin() const { return parameters().begin(); }
3953
1.07k
  param_const_iterator param_end() const { return parameters().end(); }
3954
14
  size_t param_size() const { return parameters().size(); }
3955
3956
10.5k
  unsigned getNumParams() const { return NumParams; }
3957
3958
10
  const ParmVarDecl *getParamDecl(unsigned i) const {
3959
10
    assert(i < getNumParams() && "Illegal param #");
3960
10
    return ParamInfo[i];
3961
10
  }
3962
16
  ParmVarDecl *getParamDecl(unsigned i) {
3963
16
    assert(i < getNumParams() && "Illegal param #");
3964
16
    return ParamInfo[i];
3965
16
  }
3966
3967
  void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
3968
3969
  /// True if this block (or its nested blocks) captures
3970
  /// anything of local storage from its enclosing scopes.
3971
5.96k
  bool hasCaptures() const { return NumCaptures != 0 || 
CapturesCXXThis2.21k
; }
3972
3973
  /// Returns the number of captured variables.
3974
  /// Does not include an entry for 'this'.
3975
14
  unsigned getNumCaptures() const { return NumCaptures; }
3976
3977
  using capture_const_iterator = ArrayRef<Capture>::const_iterator;
3978
3979
12.0k
  ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; }
3980
3981
1.16k
  capture_const_iterator capture_begin() const { return captures().begin(); }
3982
1.15k
  capture_const_iterator capture_end() const { return captures().end(); }
3983
3984
3.52k
  bool capturesCXXThis() const { return CapturesCXXThis; }
3985
88
  bool blockMissingReturnType() const { return BlockMissingReturnType; }
3986
209
  void setBlockMissingReturnType(bool val) { BlockMissingReturnType = val; }
3987
3988
3.18k
  bool isConversionFromLambda() const { return IsConversionFromLambda; }
3989
36
  void setIsConversionFromLambda(bool val) { IsConversionFromLambda = val; }
3990
3991
2.64k
  bool doesNotEscape() const { return DoesNotEscape; }
3992
24
  void setDoesNotEscape() { DoesNotEscape = true; }
3993
3994
  bool capturesVariable(const VarDecl *var) const;
3995
3996
  void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
3997
                   bool CapturesCXXThis);
3998
3999
144
   unsigned getBlockManglingNumber() const {
4000
144
     return ManglingNumber;
4001
144
   }
4002
4003
468
   Decl *getBlockManglingContextDecl() const {
4004
468
     return ManglingContextDecl;    
4005
468
   }
4006
4007
190
  void setBlockMangling(unsigned Number, Decl *Ctx) {
4008
190
    ManglingNumber = Number;
4009
190
    ManglingContextDecl = Ctx;
4010
190
  }
4011
4012
  SourceRange getSourceRange() const override LLVM_READONLY;
4013
4014
  // Implement isa/cast/dyncast/etc.
4015
15.8M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4016
72.8M
  static bool classofKind(Kind K) { return K == Block; }
4017
36
  static DeclContext *castToDeclContext(const BlockDecl *D) {
4018
36
    return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
4019
36
  }
4020
0
  static BlockDecl *castFromDeclContext(const DeclContext *DC) {
4021
0
    return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
4022
0
  }
4023
};
4024
4025
/// Represents the body of a CapturedStmt, and serves as its DeclContext.
4026
class CapturedDecl final
4027
    : public Decl,
4028
      public DeclContext,
4029
      private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
4030
protected:
4031
0
  size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
4032
0
    return NumParams;
4033
0
  }
4034
4035
private:
4036
  /// The number of parameters to the outlined function.
4037
  unsigned NumParams;
4038
4039
  /// The position of context parameter in list of parameters.
4040
  unsigned ContextParam;
4041
4042
  /// The body of the outlined function.
4043
  llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4044
4045
  explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
4046
4047
489k
  ImplicitParamDecl *const *getParams() const {
4048
489k
    return getTrailingObjects<ImplicitParamDecl *>();
4049
489k
  }
4050
4051
1.07M
  ImplicitParamDecl **getParams() {
4052
1.07M
    return getTrailingObjects<ImplicitParamDecl *>();
4053
1.07M
  }
4054
4055
public:
4056
  friend class ASTDeclReader;
4057
  friend class ASTDeclWriter;
4058
  friend TrailingObjects;
4059
4060
  static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
4061
                              unsigned NumParams);
4062
  static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID,
4063
                                          unsigned NumParams);
4064
4065
  Stmt *getBody() const override;
4066
  void setBody(Stmt *B);
4067
4068
  bool isNothrow() const;
4069
  void setNothrow(bool Nothrow = true);
4070
4071
106k
  unsigned getNumParams() const { return NumParams; }
4072
4073
387k
  ImplicitParamDecl *getParam(unsigned i) const {
4074
387k
    assert(i < NumParams);
4075
387k
    return getParams()[i];
4076
387k
  }
4077
1.07M
  void setParam(unsigned i, ImplicitParamDecl *P) {
4078
1.07M
    assert(i < NumParams);
4079
1.07M
    getParams()[i] = P;
4080
1.07M
  }
4081
4082
  // ArrayRef interface to parameters.
4083
0
  ArrayRef<ImplicitParamDecl *> parameters() const {
4084
0
    return {getParams(), getNumParams()};
4085
0
  }
4086
0
  MutableArrayRef<ImplicitParamDecl *> parameters() {
4087
0
    return {getParams(), getNumParams()};
4088
0
  }
4089
4090
  /// Retrieve the parameter containing captured variables.
4091
289k
  ImplicitParamDecl *getContextParam() const {
4092
289k
    assert(ContextParam < NumParams);
4093
289k
    return getParam(ContextParam);
4094
289k
  }
4095
308k
  void setContextParam(unsigned i, ImplicitParamDecl *P) {
4096
308k
    assert(i < NumParams);
4097
308k
    ContextParam = i;
4098
308k
    setParam(i, P);
4099
308k
  }
4100
78.7k
  unsigned getContextParamPosition() const { return ContextParam; }
4101
4102
  using param_iterator = ImplicitParamDecl *const *;
4103
  using param_range = llvm::iterator_range<param_iterator>;
4104
4105
  /// Retrieve an iterator pointing to the first parameter decl.
4106
78.1k
  param_iterator param_begin() const { return getParams(); }
4107
  /// Retrieve an iterator one past the last parameter decl.
4108
24.1k
  param_iterator param_end() const { return getParams() + NumParams; }
4109
4110
  // Implement isa/cast/dyncast/etc.
4111
231k
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4112
78.9M
  static bool classofKind(Kind K) { return K == Captured; }
4113
289k
  static DeclContext *castToDeclContext(const CapturedDecl *D) {
4114
289k
    return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
4115
289k
  }
4116
0
  static CapturedDecl *castFromDeclContext(const DeclContext *DC) {
4117
0
    return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
4118
0
  }
4119
};
4120
4121
/// Describes a module import declaration, which makes the contents
4122
/// of the named module visible in the current translation unit.
4123
///
4124
/// An import declaration imports the named module (or submodule). For example:
4125
/// \code
4126
///   @import std.vector;
4127
/// \endcode
4128
///
4129
/// Import declarations can also be implicitly generated from
4130
/// \#include/\#import directives.
4131
class ImportDecl final : public Decl,
4132
                         llvm::TrailingObjects<ImportDecl, SourceLocation> {
4133
  friend class ASTContext;
4134
  friend class ASTDeclReader;
4135
  friend class ASTReader;
4136
  friend TrailingObjects;
4137
4138
  /// The imported module, along with a bit that indicates whether
4139
  /// we have source-location information for each identifier in the module
4140
  /// name. 
4141
  ///
4142
  /// When the bit is false, we only have a single source location for the
4143
  /// end of the import declaration.
4144
  llvm::PointerIntPair<Module *, 1, bool> ImportedAndComplete;
4145
  
4146
  /// The next import in the list of imports local to the translation
4147
  /// unit being parsed (not loaded from an AST file).
4148
  ImportDecl *NextLocalImport = nullptr;
4149
  
4150
  ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4151
             ArrayRef<SourceLocation> IdentifierLocs);
4152
4153
  ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4154
             SourceLocation EndLoc);
4155
4156
149
  ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
4157
  
4158
public:
4159
  /// Create a new module import declaration.
4160
  static ImportDecl *Create(ASTContext &C, DeclContext *DC, 
4161
                            SourceLocation StartLoc, Module *Imported,
4162
                            ArrayRef<SourceLocation> IdentifierLocs);
4163
  
4164
  /// Create a new module import declaration for an implicitly-generated
4165
  /// import.
4166
  static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC, 
4167
                                    SourceLocation StartLoc, Module *Imported, 
4168
                                    SourceLocation EndLoc);
4169
  
4170
  /// Create a new, deserialized module import declaration.
4171
  static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID, 
4172
                                        unsigned NumLocations);
4173
  
4174
  /// Retrieve the module that was imported by the import declaration.
4175
5.02k
  Module *getImportedModule() const { return ImportedAndComplete.getPointer(); }
4176
  
4177
  /// Retrieves the locations of each of the identifiers that make up
4178
  /// the complete module name in the import declaration.
4179
  ///
4180
  /// This will return an empty array if the locations of the individual
4181
  /// identifiers aren't available.
4182
  ArrayRef<SourceLocation> getIdentifierLocs() const;
4183
4184
  SourceRange getSourceRange() const override LLVM_READONLY;
4185
4186
25.7M
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4187
25.7M
  static bool classofKind(Kind K) { return K == Import; }
4188
};
4189
4190
/// Represents a C++ Modules TS module export declaration.
4191
///
4192
/// For example:
4193
/// \code
4194
///   export void foo();
4195
/// \endcode
4196
class ExportDecl final : public Decl, public DeclContext {
4197
  virtual void anchor();
4198
4199
private:
4200
  friend class ASTDeclReader;
4201
4202
  /// The source location for the right brace (if valid).
4203
  SourceLocation RBraceLoc;
4204
4205
  ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
4206
      : Decl(Export, DC, ExportLoc), DeclContext(Export),
4207
82
        RBraceLoc(SourceLocation()) {}
4208
4209
public:
4210
  static ExportDecl *Create(ASTContext &C, DeclContext *DC,
4211
                            SourceLocation ExportLoc);
4212
  static ExportDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4213
  
4214
0
  SourceLocation getExportLoc() const { return getLocation(); }
4215
29
  SourceLocation getRBraceLoc() const { return RBraceLoc; }
4216
16
  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
4217
4218
0
  SourceLocation getLocEnd() const LLVM_READONLY {
4219
0
    if (RBraceLoc.isValid())
4220
0
      return RBraceLoc;
4221
0
    // No braces: get the end location of the (only) declaration in context
4222
0
    // (if present).
4223
0
    return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
4224
0
  }
4225
4226
0
  SourceRange getSourceRange() const override LLVM_READONLY {
4227
0
    return SourceRange(getLocation(), getLocEnd());
4228
0
  }
4229
4230
0
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4231
7.34k
  static bool classofKind(Kind K) { return K == Export; }
4232
0
  static DeclContext *castToDeclContext(const ExportDecl *D) {
4233
0
    return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
4234
0
  }
4235
0
  static ExportDecl *castFromDeclContext(const DeclContext *DC) {
4236
0
    return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
4237
0
  }
4238
};
4239
4240
/// Represents an empty-declaration.
4241
class EmptyDecl : public Decl {
4242
2.03k
  EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {}
4243
4244
  virtual void anchor();
4245
4246
public:
4247
  static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
4248
                           SourceLocation L);
4249
  static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
4250
4251
0
  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4252
0
  static bool classofKind(Kind K) { return K == Empty; }
4253
};
4254
4255
/// Insertion operator for diagnostics.  This allows sending NamedDecl's
4256
/// into a diagnostic with <<.
4257
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
4258
154k
                                           const NamedDecl* ND) {
4259
154k
  DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
4260
154k
                  DiagnosticsEngine::ak_nameddecl);
4261
154k
  return DB;
4262
154k
}
4263
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
4264
833k
                                           const NamedDecl* ND) {
4265
833k
  PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
4266
833k
                  DiagnosticsEngine::ak_nameddecl);
4267
833k
  return PD;
4268
833k
}
4269
4270
template<typename decl_type>
4271
5.11M
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4272
5.11M
  // Note: This routine is implemented here because we need both NamedDecl
4273
5.11M
  // and Redeclarable to be defined.
4274
5.11M
  assert(RedeclLink.isFirst() &&
4275
5.11M
         "setPreviousDecl on a decl already in a redeclaration chain");
4276
5.11M
4277
5.11M
  if (PrevDecl) {
4278
1.61M
    // Point to previous. Make sure that this is actually the most recent
4279
1.61M
    // redeclaration, or we can build invalid chains. If the most recent
4280
1.61M
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4281
1.61M
    First = PrevDecl->getFirstDecl();
4282
1.61M
    assert(First->RedeclLink.isFirst() && "Expected first");
4283
1.61M
    decl_type *MostRecent = First->getNextRedeclaration();
4284
1.61M
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4285
1.61M
4286
1.61M
    // If the declaration was previously visible, a redeclaration of it remains
4287
1.61M
    // visible even if it wouldn't be visible by itself.
4288
1.61M
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4289
1.61M
      MostRecent->getIdentifierNamespace() &
4290
1.61M
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4291
3.50M
  } else {
4292
3.50M
    // Make this first.
4293
3.50M
    First = static_cast<decl_type*>(this);
4294
3.50M
  }
4295
5.11M
4296
5.11M
  // First one will point to this one as latest.
4297
5.11M
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4298
5.11M
4299
5.11M
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4300
5.11M
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4301
5.11M
}
clang::Redeclarable<clang::TypedefNameDecl>::setPreviousDecl(clang::TypedefNameDecl*)
Line
Count
Source
4271
6.67k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4272
6.67k
  // Note: This routine is implemented here because we need both NamedDecl
4273
6.67k
  // and Redeclarable to be defined.
4274
6.67k
  assert(RedeclLink.isFirst() &&
4275
6.67k
         "setPreviousDecl on a decl already in a redeclaration chain");
4276
6.67k
4277
6.67k
  if (PrevDecl) {
4278
6.67k
    // Point to previous. Make sure that this is actually the most recent
4279
6.67k
    // redeclaration, or we can build invalid chains. If the most recent
4280
6.67k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4281
6.67k
    First = PrevDecl->getFirstDecl();
4282
6.67k
    assert(First->RedeclLink.isFirst() && "Expected first");
4283
6.67k
    decl_type *MostRecent = First->getNextRedeclaration();
4284
6.67k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4285
6.67k
4286
6.67k
    // If the declaration was previously visible, a redeclaration of it remains
4287
6.67k
    // visible even if it wouldn't be visible by itself.
4288
6.67k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4289
6.67k
      MostRecent->getIdentifierNamespace() &
4290
6.67k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4291
6.67k
  } else {
4292
0
    // Make this first.
4293
0
    First = static_cast<decl_type*>(this);
4294
0
  }
4295
6.67k
4296
6.67k
  // First one will point to this one as latest.
4297
6.67k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4298
6.67k
4299
6.67k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4300
6.67k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4301
6.67k
}
clang::Redeclarable<clang::VarDecl>::setPreviousDecl(clang::VarDecl*)
Line
Count
Source
4271
72.7k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4272
72.7k
  // Note: This routine is implemented here because we need both NamedDecl
4273
72.7k
  // and Redeclarable to be defined.
4274
72.7k
  assert(RedeclLink.isFirst() &&
4275
72.7k
         "setPreviousDecl on a decl already in a redeclaration chain");
4276
72.7k
4277
72.7k
  if (PrevDecl) {
4278
72.7k
    // Point to previous. Make sure that this is actually the most recent
4279
72.7k
    // redeclaration, or we can build invalid chains. If the most recent
4280
72.7k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4281
72.7k
    First = PrevDecl->getFirstDecl();
4282
72.7k
    assert(First->RedeclLink.isFirst() && "Expected first");
4283
72.7k
    decl_type *MostRecent = First->getNextRedeclaration();
4284
72.7k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4285
72.7k
4286
72.7k
    // If the declaration was previously visible, a redeclaration of it remains
4287
72.7k
    // visible even if it wouldn't be visible by itself.
4288
72.7k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4289
72.7k
      MostRecent->getIdentifierNamespace() &
4290
72.7k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4291
72.7k
  } else {
4292
0
    // Make this first.
4293
0
    First = static_cast<decl_type*>(this);
4294
0
  }
4295
72.7k
4296
72.7k
  // First one will point to this one as latest.
4297
72.7k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4298
72.7k
4299
72.7k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4300
72.7k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4301
72.7k
}
clang::Redeclarable<clang::RedeclarableTemplateDecl>::setPreviousDecl(clang::RedeclarableTemplateDecl*)
Line
Count
Source
4271
320k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4272
320k
  // Note: This routine is implemented here because we need both NamedDecl
4273
320k
  // and Redeclarable to be defined.
4274
320k
  assert(RedeclLink.isFirst() &&
4275
320k
         "setPreviousDecl on a decl already in a redeclaration chain");
4276
320k
4277
320k
  if (PrevDecl) {
4278
77.8k
    // Point to previous. Make sure that this is actually the most recent
4279
77.8k
    // redeclaration, or we can build invalid chains. If the most recent
4280
77.8k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4281
77.8k
    First = PrevDecl->getFirstDecl();
4282
77.8k
    assert(First->RedeclLink.isFirst() && "Expected first");
4283
77.8k
    decl_type *MostRecent = First->getNextRedeclaration();
4284
77.8k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4285
77.8k
4286
77.8k
    // If the declaration was previously visible, a redeclaration of it remains
4287
77.8k
    // visible even if it wouldn't be visible by itself.
4288
77.8k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4289
77.8k
      MostRecent->getIdentifierNamespace() &
4290
77.8k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4291
242k
  } else {
4292
242k
    // Make this first.
4293
242k
    First = static_cast<decl_type*>(this);
4294
242k
  }
4295
320k
4296
320k
  // First one will point to this one as latest.
4297
320k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4298
320k
4299
320k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4300
320k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4301
320k
}
clang::Redeclarable<clang::UsingShadowDecl>::setPreviousDecl(clang::UsingShadowDecl*)
Line
Count
Source
4271
150k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4272
150k
  // Note: This routine is implemented here because we need both NamedDecl
4273
150k
  // and Redeclarable to be defined.
4274
150k
  assert(RedeclLink.isFirst() &&
4275
150k
         "setPreviousDecl on a decl already in a redeclaration chain");
4276
150k
4277
150k
  if (PrevDecl) {
4278
2.83k
    // Point to previous. Make sure that this is actually the most recent
4279
2.83k
    // redeclaration, or we can build invalid chains. If the most recent
4280
2.83k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4281
2.83k
    First = PrevDecl->getFirstDecl();
4282
2.83k
    assert(First->RedeclLink.isFirst() && "Expected first");
4283
2.83k
    decl_type *MostRecent = First->getNextRedeclaration();
4284
2.83k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4285
2.83k
4286
2.83k
    // If the declaration was previously visible, a redeclaration of it remains
4287
2.83k
    // visible even if it wouldn't be visible by itself.
4288
2.83k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4289
2.83k
      MostRecent->getIdentifierNamespace() &
4290
2.83k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4291
147k
  } else {
4292
147k
    // Make this first.
4293
147k
    First = static_cast<decl_type*>(this);
4294
147k
  }
4295
150k
4296
150k
  // First one will point to this one as latest.
4297
150k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4298
150k
4299
150k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4300
150k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4301
150k
}
clang::Redeclarable<clang::NamespaceAliasDecl>::setPreviousDecl(clang::NamespaceAliasDecl*)
Line
Count
Source
4271
12
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4272
12
  // Note: This routine is implemented here because we need both NamedDecl
4273
12
  // and Redeclarable to be defined.
4274
12
  assert(RedeclLink.isFirst() &&
4275
12
         "setPreviousDecl on a decl already in a redeclaration chain");
4276
12
4277
12
  if (PrevDecl) {
4278
12
    // Point to previous. Make sure that this is actually the most recent
4279
12
    // redeclaration, or we can build invalid chains. If the most recent
4280
12
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4281
12
    First = PrevDecl->getFirstDecl();
4282
12
    assert(First->RedeclLink.isFirst() && "Expected first");
4283
12
    decl_type *MostRecent = First->getNextRedeclaration();
4284
12
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4285
12
4286
12
    // If the declaration was previously visible, a redeclaration of it remains
4287
12
    // visible even if it wouldn't be visible by itself.
4288
12
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4289
12
      MostRecent->getIdentifierNamespace() &
4290
12
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4291
12
  } else {
4292
0
    // Make this first.
4293
0
    First = static_cast<decl_type*>(this);
4294
0
  }
4295
12
4296
12
  // First one will point to this one as latest.
4297
12
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4298
12
4299
12
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4300
12
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4301
12
}
clang::Redeclarable<clang::FunctionDecl>::setPreviousDecl(clang::FunctionDecl*)
Line
Count
Source
4271
510k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4272
510k
  // Note: This routine is implemented here because we need both NamedDecl
4273
510k
  // and Redeclarable to be defined.
4274
510k
  assert(RedeclLink.isFirst() &&
4275
510k
         "setPreviousDecl on a decl already in a redeclaration chain");
4276
510k
4277
510k
  if (PrevDecl) {
4278
510k
    // Point to previous. Make sure that this is actually the most recent
4279
510k
    // redeclaration, or we can build invalid chains. If the most recent
4280
510k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4281
510k
    First = PrevDecl->getFirstDecl();
4282
510k
    assert(First->RedeclLink.isFirst() && "Expected first");
4283
510k
    decl_type *MostRecent = First->getNextRedeclaration();
4284
510k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4285
510k
4286
510k
    // If the declaration was previously visible, a redeclaration of it remains
4287
510k
    // visible even if it wouldn't be visible by itself.
4288
510k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4289
510k
      MostRecent->getIdentifierNamespace() &
4290
510k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4291
510k
  } else {
4292
0
    // Make this first.
4293
0
    First = static_cast<decl_type*>(this);
4294
0
  }
4295
510k
4296
510k
  // First one will point to this one as latest.
4297
510k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4298
510k
4299
510k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4300
510k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4301
510k
}
clang::Redeclarable<clang::TagDecl>::setPreviousDecl(clang::TagDecl*)
Line
Count
Source
4271
3.91M
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4272
3.91M
  // Note: This routine is implemented here because we need both NamedDecl
4273
3.91M
  // and Redeclarable to be defined.
4274
3.91M
  assert(RedeclLink.isFirst() &&
4275
3.91M
         "setPreviousDecl on a decl already in a redeclaration chain");
4276
3.91M
4277
3.91M
  if (PrevDecl) {
4278
867k
    // Point to previous. Make sure that this is actually the most recent
4279
867k
    // redeclaration, or we can build invalid chains. If the most recent
4280
867k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4281
867k
    First = PrevDecl->getFirstDecl();
4282
867k
    assert(First->RedeclLink.isFirst() && "Expected first");
4283
867k
    decl_type *MostRecent = First->getNextRedeclaration();
4284
867k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4285
867k
4286
867k
    // If the declaration was previously visible, a redeclaration of it remains
4287
867k
    // visible even if it wouldn't be visible by itself.
4288
867k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4289
867k
      MostRecent->getIdentifierNamespace() &
4290
867k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4291
3.04M
  } else {
4292
3.04M
    // Make this first.
4293
3.04M
    First = static_cast<decl_type*>(this);
4294
3.04M
  }
4295
3.91M
4296
3.91M
  // First one will point to this one as latest.
4297
3.91M
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4298
3.91M
4299
3.91M
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4300
3.91M
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4301
3.91M
}
clang::Redeclarable<clang::NamespaceDecl>::setPreviousDecl(clang::NamespaceDecl*)
Line
Count
Source
4271
113k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4272
113k
  // Note: This routine is implemented here because we need both NamedDecl
4273
113k
  // and Redeclarable to be defined.
4274
113k
  assert(RedeclLink.isFirst() &&
4275
113k
         "setPreviousDecl on a decl already in a redeclaration chain");
4276
113k
4277
113k
  if (PrevDecl) {
4278
68.1k
    // Point to previous. Make sure that this is actually the most recent
4279
68.1k
    // redeclaration, or we can build invalid chains. If the most recent
4280
68.1k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4281
68.1k
    First = PrevDecl->getFirstDecl();
4282
68.1k
    assert(First->RedeclLink.isFirst() && "Expected first");
4283
68.1k
    decl_type *MostRecent = First->getNextRedeclaration();
4284
68.1k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4285
68.1k
4286
68.1k
    // If the declaration was previously visible, a redeclaration of it remains
4287
68.1k
    // visible even if it wouldn't be visible by itself.
4288
68.1k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4289
68.1k
      MostRecent->getIdentifierNamespace() &
4290
68.1k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4291
68.1k
  } else {
4292
45.4k
    // Make this first.
4293
45.4k
    First = static_cast<decl_type*>(this);
4294
45.4k
  }
4295
113k
4296
113k
  // First one will point to this one as latest.
4297
113k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4298
113k
4299
113k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4300
113k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4301
113k
}
clang::Redeclarable<clang::ObjCInterfaceDecl>::setPreviousDecl(clang::ObjCInterfaceDecl*)
Line
Count
Source
4271
29.7k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4272
29.7k
  // Note: This routine is implemented here because we need both NamedDecl
4273
29.7k
  // and Redeclarable to be defined.
4274
29.7k
  assert(RedeclLink.isFirst() &&
4275
29.7k
         "setPreviousDecl on a decl already in a redeclaration chain");
4276
29.7k
4277
29.7k
  if (PrevDecl) {
4278
6.76k
    // Point to previous. Make sure that this is actually the most recent
4279
6.76k
    // redeclaration, or we can build invalid chains. If the most recent
4280
6.76k
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4281
6.76k
    First = PrevDecl->getFirstDecl();
4282
6.76k
    assert(First->RedeclLink.isFirst() && "Expected first");
4283
6.76k
    decl_type *MostRecent = First->getNextRedeclaration();
4284
6.76k
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4285
6.76k
4286
6.76k
    // If the declaration was previously visible, a redeclaration of it remains
4287
6.76k
    // visible even if it wouldn't be visible by itself.
4288
6.76k
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4289
6.76k
      MostRecent->getIdentifierNamespace() &
4290
6.76k
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4291
22.9k
  } else {
4292
22.9k
    // Make this first.
4293
22.9k
    First = static_cast<decl_type*>(this);
4294
22.9k
  }
4295
29.7k
4296
29.7k
  // First one will point to this one as latest.
4297
29.7k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4298
29.7k
4299
29.7k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4300
29.7k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4301
29.7k
}
clang::Redeclarable<clang::ObjCProtocolDecl>::setPreviousDecl(clang::ObjCProtocolDecl*)
Line
Count
Source
4271
3.79k
void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
4272
3.79k
  // Note: This routine is implemented here because we need both NamedDecl
4273
3.79k
  // and Redeclarable to be defined.
4274
3.79k
  assert(RedeclLink.isFirst() &&
4275
3.79k
         "setPreviousDecl on a decl already in a redeclaration chain");
4276
3.79k
4277
3.79k
  if (PrevDecl) {
4278
386
    // Point to previous. Make sure that this is actually the most recent
4279
386
    // redeclaration, or we can build invalid chains. If the most recent
4280
386
    // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4281
386
    First = PrevDecl->getFirstDecl();
4282
386
    assert(First->RedeclLink.isFirst() && "Expected first");
4283
386
    decl_type *MostRecent = First->getNextRedeclaration();
4284
386
    RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4285
386
4286
386
    // If the declaration was previously visible, a redeclaration of it remains
4287
386
    // visible even if it wouldn't be visible by itself.
4288
386
    static_cast<decl_type*>(this)->IdentifierNamespace |=
4289
386
      MostRecent->getIdentifierNamespace() &
4290
386
      (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
4291
3.40k
  } else {
4292
3.40k
    // Make this first.
4293
3.40k
    First = static_cast<decl_type*>(this);
4294
3.40k
  }
4295
3.79k
4296
3.79k
  // First one will point to this one as latest.
4297
3.79k
  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
4298
3.79k
4299
3.79k
  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
4300
3.79k
         cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
4301
3.79k
}
4302
4303
// Inline function definitions.
4304
4305
/// Check if the given decl is complete.
4306
///
4307
/// We use this function to break a cycle between the inline definitions in
4308
/// Type.h and Decl.h.
4309
1.23M
inline bool IsEnumDeclComplete(EnumDecl *ED) {
4310
1.23M
  return ED->isComplete();
4311
1.23M
}
4312
4313
/// Check if the given decl is scoped.
4314
///
4315
/// We use this function to break a cycle between the inline definitions in
4316
/// Type.h and Decl.h.
4317
439k
inline bool IsEnumDeclScoped(EnumDecl *ED) {
4318
439k
  return ED->isScoped();
4319
439k
}
4320
4321
} // namespace clang
4322
4323
#endif // LLVM_CLANG_AST_DECL_H