Coverage Report

Created: 2020-02-15 09:57

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