Coverage Report

Created: 2019-07-24 05:18

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