clang 24.0.0git
Decl.h
Go to the documentation of this file.
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
17#include "clang/AST/APValue.h"
20#include "clang/AST/DeclBase.h"
25#include "clang/AST/TypeBase.h"
29#include "clang/Basic/LLVM.h"
30#include "clang/Basic/Linkage.h"
38#include "llvm/ADT/APSInt.h"
39#include "llvm/ADT/ArrayRef.h"
40#include "llvm/ADT/FoldingSet.h"
41#include "llvm/ADT/PointerIntPair.h"
42#include "llvm/ADT/PointerUnion.h"
43#include "llvm/ADT/StringRef.h"
44#include "llvm/ADT/iterator_range.h"
45#include "llvm/BinaryFormat/DXContainer.h"
46#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
47#include "llvm/Support/Casting.h"
48#include "llvm/Support/Compiler.h"
49#include "llvm/Support/TrailingObjects.h"
50#include <cassert>
51#include <cstddef>
52#include <cstdint>
53#include <optional>
54#include <string>
55#include <utility>
56
57namespace clang {
58
59class ASTContext;
61class CompoundStmt;
63class EnumDecl;
64class Expr;
67class FunctionTypeLoc;
68class LabelStmt;
70class Module;
71class NamespaceDecl;
72class ParmVarDecl;
73class RecordDecl;
74class Stmt;
75class StringLiteral;
76class TagDecl;
82class VarTemplateDecl;
83enum class ImplicitParamKind;
85
86// Holds a constraint expression along with a pack expansion index, if
87// expanded.
89 const Expr *ConstraintExpr = nullptr;
91
92 constexpr AssociatedConstraint() = default;
93
97
98 explicit operator bool() const { return ConstraintExpr != nullptr; }
99
100 bool isNull() const { return !operator bool(); }
101};
102
103/// The top declaration context.
104class TranslationUnitDecl : public Decl,
105 public DeclContext,
106 public Redeclarable<TranslationUnitDecl> {
107 using redeclarable_base = Redeclarable<TranslationUnitDecl>;
108
109 TranslationUnitDecl *getNextRedeclarationImpl() override {
110 return getNextRedeclaration();
111 }
112
113 TranslationUnitDecl *getPreviousDeclImpl() override {
114 return getPreviousDecl();
115 }
116
117 TranslationUnitDecl *getMostRecentDeclImpl() override {
118 return getMostRecentDecl();
119 }
120
121 ASTContext &Ctx;
122
123 /// The (most recently entered) anonymous namespace for this
124 /// translation unit, if one has been created.
125 NamespaceDecl *AnonymousNamespace = nullptr;
126
127 explicit TranslationUnitDecl(ASTContext &ctx);
128
129 virtual void anchor();
130
131public:
133 using redecl_iterator = redeclarable_base::redecl_iterator;
134
141
142 ASTContext &getASTContext() const { return Ctx; }
143
144 NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
146
148
149 // Implement isa/cast/dyncast/etc.
150 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
151 static bool classofKind(Kind K) { return K == TranslationUnit; }
152 static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
153 return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
154 }
155 static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) {
156 return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
157 }
158
159 /// Retrieves the canonical declaration of this translation unit.
160 TranslationUnitDecl *getCanonicalDecl() override { return getFirstDecl(); }
161 const TranslationUnitDecl *getCanonicalDecl() const { return getFirstDecl(); }
162};
163
164/// Represents a `#pragma comment` line. Always a child of
165/// TranslationUnitDecl.
166class PragmaCommentDecl final
167 : public Decl,
168 private llvm::TrailingObjects<PragmaCommentDecl, char> {
169 friend class ASTDeclReader;
170 friend class ASTDeclWriter;
171 friend TrailingObjects;
172
173 PragmaMSCommentKind CommentKind;
174
175 PragmaCommentDecl(TranslationUnitDecl *TU, SourceLocation CommentLoc,
176 PragmaMSCommentKind CommentKind)
177 : Decl(PragmaComment, TU, CommentLoc), CommentKind(CommentKind) {}
178
179 LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
180
181public:
183 SourceLocation CommentLoc,
184 PragmaMSCommentKind CommentKind,
185 StringRef Arg);
187 unsigned ArgSize);
188
189 PragmaMSCommentKind getCommentKind() const { return CommentKind; }
190
191 StringRef getArg() const { return getTrailingObjects(); }
192
193 // Implement isa/cast/dyncast/etc.
194 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
195 static bool classofKind(Kind K) { return K == PragmaComment; }
196};
197
198/// Represents a `#pragma detect_mismatch` line. Always a child of
199/// TranslationUnitDecl.
200class PragmaDetectMismatchDecl final
201 : public Decl,
202 private llvm::TrailingObjects<PragmaDetectMismatchDecl, char> {
203 friend class ASTDeclReader;
204 friend class ASTDeclWriter;
205 friend TrailingObjects;
206
207 size_t ValueStart;
208
209 PragmaDetectMismatchDecl(TranslationUnitDecl *TU, SourceLocation Loc,
210 size_t ValueStart)
211 : Decl(PragmaDetectMismatch, TU, Loc), ValueStart(ValueStart) {}
212
213 LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
214
215public:
218 SourceLocation Loc, StringRef Name,
219 StringRef Value);
221 CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NameValueSize);
222
223 StringRef getName() const { return getTrailingObjects(); }
224 StringRef getValue() const { return getTrailingObjects() + ValueStart; }
225
226 // Implement isa/cast/dyncast/etc.
227 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
228 static bool classofKind(Kind K) { return K == PragmaDetectMismatch; }
229};
230
231/// Declaration context for names declared as extern "C" in C++. This
232/// is neither the semantic nor lexical context for such declarations, but is
233/// used to check for conflicts with other extern "C" declarations. Example:
234///
235/// \code
236/// namespace N { extern "C" void f(); } // #1
237/// void N::f() {} // #2
238/// namespace M { extern "C" void f(); } // #3
239/// \endcode
240///
241/// The semantic context of #1 is namespace N and its lexical context is the
242/// LinkageSpecDecl; the semantic context of #2 is namespace N and its lexical
243/// context is the TU. However, both declarations are also visible in the
244/// extern "C" context.
245///
246/// The declaration at #3 finds it is a redeclaration of \c N::f through
247/// lookup in the extern "C" context.
248class ExternCContextDecl : public Decl, public DeclContext {
249 explicit ExternCContextDecl(TranslationUnitDecl *TU)
250 : Decl(ExternCContext, TU, SourceLocation()),
251 DeclContext(ExternCContext) {}
252
253 virtual void anchor();
254
255public:
256 static ExternCContextDecl *Create(const ASTContext &C,
258
259 // Implement isa/cast/dyncast/etc.
260 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
261 static bool classofKind(Kind K) { return K == ExternCContext; }
262 static DeclContext *castToDeclContext(const ExternCContextDecl *D) {
263 return static_cast<DeclContext *>(const_cast<ExternCContextDecl*>(D));
264 }
265 static ExternCContextDecl *castFromDeclContext(const DeclContext *DC) {
266 return static_cast<ExternCContextDecl *>(const_cast<DeclContext*>(DC));
267 }
268};
269
270/// This represents a decl that may have a name. Many decls have names such
271/// as ObjCMethodDecl, but not \@class, etc.
272///
273/// Note that not every NamedDecl is actually named (e.g., a struct might
274/// be anonymous), and not every name is an identifier.
275class NamedDecl : public Decl {
276 /// The name of this declaration, which is typically a normal
277 /// identifier but may also be a special kind of name (C++
278 /// constructor, Objective-C selector, etc.)
279 DeclarationName Name;
280
281 virtual void anchor();
282
283private:
284 NamedDecl *getUnderlyingDeclImpl() LLVM_READONLY;
285
286protected:
288 : Decl(DK, DC, L), Name(N) {}
289
290public:
291 /// Get the identifier that names this declaration, if there is one.
292 ///
293 /// This will return NULL if this declaration has no name (e.g., for
294 /// an unnamed class) or if the name is a special name (C++ constructor,
295 /// Objective-C selector, etc.).
296 IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); }
297
298 /// Get the name of identifier for this declaration as a StringRef.
299 ///
300 /// This requires that the declaration have a name and that it be a simple
301 /// identifier.
302 StringRef getName() const {
303 assert(Name.isIdentifier() && "Name is not a simple identifier");
304 return getIdentifier() ? getIdentifier()->getName() : "";
305 }
306
307 /// Get a human-readable name for the declaration, even if it is one of the
308 /// special kinds of names (C++ constructor, Objective-C selector, etc).
309 ///
310 /// Creating this name requires expensive string manipulation, so it should
311 /// be called only when performance doesn't matter. For simple declarations,
312 /// getNameAsCString() should suffice.
313 //
314 // FIXME: This function should be renamed to indicate that it is not just an
315 // alternate form of getName(), and clients should move as appropriate.
316 //
317 // FIXME: Deprecated, move clients to getName().
318 std::string getNameAsString() const { return Name.getAsString(); }
319
320 /// Pretty-print the unqualified name of this declaration. Can be overloaded
321 /// by derived classes to provide a more user-friendly name when appropriate.
322 virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const;
323 /// Calls printName() with the ASTContext printing policy from the decl.
324 void printName(raw_ostream &OS) const;
325
326 /// Get the actual, stored name of the declaration, which may be a special
327 /// name.
328 ///
329 /// Note that generally in diagnostics, the non-null \p NamedDecl* itself
330 /// should be sent into the diagnostic instead of using the result of
331 /// \p getDeclName().
332 ///
333 /// A \p DeclarationName in a diagnostic will just be streamed to the output,
334 /// which will directly result in a call to \p DeclarationName::print.
335 ///
336 /// A \p NamedDecl* in a diagnostic will also ultimately result in a call to
337 /// \p DeclarationName::print, but with two customisation points along the
338 /// way (\p getNameForDiagnostic and \p printName). These are used to print
339 /// the template arguments if any, and to provide a user-friendly name for
340 /// some entities (such as unnamed variables and anonymous records).
341 DeclarationName getDeclName() const { return Name; }
342
343 /// Set the name of this declaration.
344 void setDeclName(DeclarationName N) { Name = N; }
345
346 /// Returns a human-readable qualified name for this declaration, like
347 /// A::B::i, for i being member of namespace A::B.
348 ///
349 /// If the declaration is not a member of context which can be named (record,
350 /// namespace), it will return the same result as printName().
351 ///
352 /// Creating this name is expensive, so it should be called only when
353 /// performance doesn't matter.
354 void printQualifiedName(raw_ostream &OS) const;
355 void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const;
356
357 /// Print only the nested name specifier part of a fully-qualified name,
358 /// including the '::' at the end. E.g.
359 /// when `printQualifiedName(D)` prints "A::B::i",
360 /// this function prints "A::B::".
361 void printNestedNameSpecifier(raw_ostream &OS) const;
362 void printNestedNameSpecifier(raw_ostream &OS,
363 const PrintingPolicy &Policy) const;
364
365 // FIXME: Remove string version.
366 std::string getQualifiedNameAsString() const;
367
368 /// Appends a human-readable name for this declaration into the given stream.
369 ///
370 /// This is the method invoked by Sema when displaying a NamedDecl
371 /// in a diagnostic. It does not necessarily produce the same
372 /// result as printName(); for example, class template
373 /// specializations are printed with their template arguments.
374 virtual void getNameForDiagnostic(raw_ostream &OS,
375 const PrintingPolicy &Policy,
376 bool Qualified) const;
377
378 /// Determine whether this declaration, if known to be well-formed within
379 /// its context, will replace the declaration OldD if introduced into scope.
380 ///
381 /// A declaration will replace another declaration if, for example, it is
382 /// a redeclaration of the same variable or function, but not if it is a
383 /// declaration of a different kind (function vs. class) or an overloaded
384 /// function.
385 ///
386 /// \param IsKnownNewer \c true if this declaration is known to be newer
387 /// than \p OldD (for instance, if this declaration is newly-created).
388 bool declarationReplaces(const NamedDecl *OldD,
389 bool IsKnownNewer = true) const;
390
391 /// Determine whether this declaration has linkage.
392 bool hasLinkage() const;
393
396
397 /// Determine whether this declaration is a C++ class member.
398 bool isCXXClassMember() const {
399 const DeclContext *DC = getDeclContext();
400
401 // C++0x [class.mem]p1:
402 // The enumerators of an unscoped enumeration defined in
403 // the class are members of the class.
404 if (isa<EnumDecl>(DC))
405 DC = DC->getRedeclContext();
406
407 return DC->isRecord();
408 }
409
410 /// Determine whether the given declaration is an instance member of
411 /// a C++ class.
412 bool isCXXInstanceMember() const;
413
414 /// Determine if the declaration obeys the reserved identifier rules of the
415 /// given language.
416 ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const;
417
418 /// Determine what kind of linkage this entity has.
419 ///
420 /// This is not the linkage as defined by the standard or the codegen notion
421 /// of linkage. It is just an implementation detail that is used to compute
422 /// those.
424
425 /// Get the linkage from a semantic point of view. Entities in
426 /// anonymous namespaces are external (in c++98).
428
429 /// True if this decl has external linkage.
433
437
438 /// Determine whether this declaration can be redeclared in a
439 /// different translation unit.
443
444 /// Determines the visibility of this entity.
448
449 /// Determines the linkage and visibility of this entity.
451
452 /// Kinds of explicit visibility.
454 /// Do an LV computation for, ultimately, a type.
455 /// Visibility may be restricted by type visibility settings and
456 /// the visibility of template arguments.
458
459 /// Do an LV computation for, ultimately, a non-type declaration.
460 /// Visibility may be restricted by value visibility settings and
461 /// the visibility of template arguments.
463 };
464
465 /// If visibility was explicitly specified for this
466 /// declaration, return that visibility.
467 std::optional<Visibility>
469
470 /// True if the computed linkage is valid. Used for consistency
471 /// checking. Should always return true.
472 bool isLinkageValid() const;
473
474 /// True if something has required us to compute the linkage
475 /// of this declaration.
476 ///
477 /// Language features which can retroactively change linkage (like a
478 /// typedef name for linkage purposes) may need to consider this,
479 /// but hopefully only in transitory ways during parsing.
481 return hasCachedLinkage();
482 }
483
484 bool isPlaceholderVar(const LangOptions &LangOpts) const;
485
486 /// Looks through UsingDecls and ObjCCompatibleAliasDecls for
487 /// the underlying named decl.
489 // Fast-path the common case.
490 if (this->getKind() != UsingShadow &&
491 this->getKind() != ConstructorUsingShadow &&
492 this->getKind() != ObjCCompatibleAlias &&
493 this->getKind() != NamespaceAlias)
494 return this;
495
496 return getUnderlyingDeclImpl();
497 }
499 return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
500 }
501
503 return cast<NamedDecl>(static_cast<Decl *>(this)->getMostRecentDecl());
504 }
506 return const_cast<NamedDecl*>(this)->getMostRecentDecl();
507 }
508
510
511 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
512 static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; }
513};
514
515inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) {
516 ND.printName(OS);
517 return OS;
518}
519
520/// Represents the declaration of a label. Labels also have a
521/// corresponding LabelStmt, which indicates the position that the label was
522/// defined at. For normal labels, the location of the decl is the same as the
523/// location of the statement. For GNU local labels (__label__), the decl
524/// location is where the __label__ is.
525class LabelDecl : public NamedDecl {
526 LabelStmt *TheStmt;
527 StringRef MSAsmName;
528 bool MSAsmNameResolved = false;
529
530 /// For normal labels, this is the same as the main declaration
531 /// label, i.e., the location of the identifier; for GNU local labels,
532 /// this is the location of the __label__ keyword.
533 SourceLocation LocStart;
534
535 LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II,
536 LabelStmt *S, SourceLocation StartL)
537 : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {}
538
539 void anchor() override;
540
541public:
542 static LabelDecl *Create(ASTContext &C, DeclContext *DC,
543 SourceLocation IdentL, IdentifierInfo *II);
544 static LabelDecl *Create(ASTContext &C, DeclContext *DC,
545 SourceLocation IdentL, IdentifierInfo *II,
546 SourceLocation GnuLabelL);
547 static LabelDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
548
549 LabelStmt *getStmt() const { return TheStmt; }
550 void setStmt(LabelStmt *T) { TheStmt = T; }
551
552 bool isGnuLocal() const { return LocStart != getLocation(); }
553 void setLocStart(SourceLocation L) { LocStart = L; }
554
555 SourceRange getSourceRange() const override LLVM_READONLY {
556 return SourceRange(LocStart, getLocation());
557 }
558
559 bool isMSAsmLabel() const { return !MSAsmName.empty(); }
560 bool isResolvedMSAsmLabel() const { return isMSAsmLabel() && MSAsmNameResolved; }
561 void setMSAsmLabel(StringRef Name);
562 StringRef getMSAsmLabel() const { return MSAsmName; }
563 void setMSAsmLabelResolved() { MSAsmNameResolved = true; }
564
565 // Implement isa/cast/dyncast/etc.
566 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
567 static bool classofKind(Kind K) { return K == Label; }
568};
569
570/// Represents C++ namespaces and their aliases.
571///
572/// FIXME: Move `NamespaceBaseDecl` and `NamespaceDecl` to "DeclCXX.h" or
573/// explain why not moving.
575protected:
577
578public:
581 return const_cast<NamespaceBaseDecl *>(this)->getNamespace();
582 }
583
584 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
585 static bool classofKind(Kind K) {
586 return K >= firstNamespaceBase && K <= lastNamespaceBase;
587 }
588};
589
590/// Represent a C++ namespace.
591class NamespaceDecl : public NamespaceBaseDecl,
592 public DeclContext,
593 public Redeclarable<NamespaceDecl> {
594 /// The starting location of the source range, pointing
595 /// to either the namespace or the inline keyword.
596 SourceLocation LocStart;
597
598 /// The ending location of the source range.
599 SourceLocation RBraceLoc;
600
601 /// The unnamed namespace that inhabits this namespace, if any.
602 NamespaceDecl *AnonymousNamespace = nullptr;
603
604 NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
605 SourceLocation StartLoc, SourceLocation IdLoc,
606 IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested);
607
608 using redeclarable_base = Redeclarable<NamespaceDecl>;
609
610 NamespaceDecl *getNextRedeclarationImpl() override;
611 NamespaceDecl *getPreviousDeclImpl() override;
612 NamespaceDecl *getMostRecentDeclImpl() override;
613
614public:
615 friend class ASTDeclReader;
616 friend class ASTDeclWriter;
617
618 static NamespaceDecl *Create(ASTContext &C, DeclContext *DC, bool Inline,
619 SourceLocation StartLoc, SourceLocation IdLoc,
620 IdentifierInfo *Id, NamespaceDecl *PrevDecl,
621 bool Nested);
622
623 static NamespaceDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
624
626 using redecl_iterator = redeclarable_base::redecl_iterator;
627
634
635 /// Returns true if this is an anonymous namespace declaration.
636 ///
637 /// For example:
638 /// \code
639 /// namespace {
640 /// ...
641 /// };
642 /// \endcode
643 /// q.v. C++ [namespace.unnamed]
644 bool isAnonymousNamespace() const {
645 return !getIdentifier();
646 }
647
648 /// Returns true if this is an inline namespace declaration.
649 bool isInline() const { return NamespaceDeclBits.IsInline; }
650
651 /// Set whether this is an inline namespace declaration.
652 void setInline(bool Inline) { NamespaceDeclBits.IsInline = Inline; }
653
654 /// Returns true if this is a nested namespace declaration.
655 /// \code
656 /// namespace outer::nested { }
657 /// \endcode
658 bool isNested() const { return NamespaceDeclBits.IsNested; }
659
660 /// Set whether this is a nested namespace declaration.
661 void setNested(bool Nested) { NamespaceDeclBits.IsNested = Nested; }
662
663 /// Returns true if the inline qualifier for \c Name is redundant.
665 if (!isInline())
666 return false;
667 auto X = lookup(Name);
668 // We should not perform a lookup within a transparent context, so find a
669 // non-transparent parent context.
670 auto Y = getParent()->getNonTransparentContext()->lookup(Name);
671 return std::distance(X.begin(), X.end()) ==
672 std::distance(Y.begin(), Y.end());
673 }
674
675 /// Retrieve the anonymous namespace that inhabits this namespace, if any.
676 NamespaceDecl *getAnonymousNamespace() const {
677 return getFirstDecl()->AnonymousNamespace;
678 }
679
680 void setAnonymousNamespace(NamespaceDecl *D) {
681 getFirstDecl()->AnonymousNamespace = D;
682 }
683
684 /// Retrieves the canonical declaration of this namespace.
685 NamespaceDecl *getCanonicalDecl() override { return getFirstDecl(); }
686 const NamespaceDecl *getCanonicalDecl() const { return getFirstDecl(); }
687
688 SourceRange getSourceRange() const override LLVM_READONLY {
689 return SourceRange(LocStart, RBraceLoc);
690 }
691
692 SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
693 SourceLocation getRBraceLoc() const { return RBraceLoc; }
694 void setLocStart(SourceLocation L) { LocStart = L; }
695 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
696
697 // Implement isa/cast/dyncast/etc.
698 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
699 static bool classofKind(Kind K) { return K == Namespace; }
700 static DeclContext *castToDeclContext(const NamespaceDecl *D) {
701 return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
702 }
703 static NamespaceDecl *castFromDeclContext(const DeclContext *DC) {
704 return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
705 }
706};
707
708class VarDecl;
709
710/// Represent the declaration of a variable (in which case it is
711/// an lvalue) a function (in which case it is a function designator) or
712/// an enum constant.
713class ValueDecl : public NamedDecl {
714 QualType DeclType;
715
716 void anchor() override;
717
718protected:
721 : NamedDecl(DK, DC, L, N), DeclType(T) {}
722
723public:
724 QualType getType() const { return DeclType; }
725 void setType(QualType newType) { DeclType = newType; }
726
727 /// Determine whether this symbol is weakly-imported,
728 /// or declared with the weak or weak-ref attr.
729 bool isWeak() const;
730
731 /// Whether this variable is the implicit variable for a lambda init-capture.
732 /// Only VarDecl can be init captures, but both VarDecl and BindingDecl
733 /// can be captured.
734 bool isInitCapture() const;
735
736 // If this is a VarDecl, or a BindindDecl with an
737 // associated decomposed VarDecl, return that VarDecl.
740 return const_cast<ValueDecl *>(this)->getPotentiallyDecomposedVarDecl();
741 }
742
743 /// Determine whether this value is actually a function parameter pack,
744 /// init-capture pack, or structured binding pack
745 bool isParameterPack() const;
746
747 // Implement isa/cast/dyncast/etc.
748 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
749 static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }
750};
751
752/// A struct with extended info about a syntactic
753/// name qualifier, to be used for the case of out-of-line declarations.
756
757 /// The number of "outer" template parameter lists.
758 /// The count includes all of the template parameter lists that were matched
759 /// against the template-ids occurring into the NNS and possibly (in the
760 /// case of an explicit specialization) a final "template <>".
761 unsigned NumTemplParamLists = 0;
762
763 /// A new-allocated array of size NumTemplParamLists,
764 /// containing pointers to the "outer" template parameter lists.
765 /// It includes all of the template parameter lists that were matched
766 /// against the template-ids occurring into the NNS and possibly (in the
767 /// case of an explicit specialization) a final "template <>".
769
770 QualifierInfo() = default;
771 QualifierInfo(const QualifierInfo &) = delete;
773
774 /// Sets info about "outer" template parameter lists.
777};
778
779/// Represents a ValueDecl that came out of a declarator.
780/// Contains type source information through TypeSourceInfo.
781class DeclaratorDecl : public ValueDecl {
782 // A struct representing a TInfo, a trailing requires-clause and a syntactic
783 // qualifier, to be used for the (uncommon) case of out-of-line declarations
784 // and constrained function decls.
785 struct ExtInfo : public QualifierInfo {
786 TypeSourceInfo *TInfo = nullptr;
787 AssociatedConstraint TrailingRequiresClause;
788 };
789
790 llvm::PointerUnion<TypeSourceInfo *, ExtInfo *> DeclInfo;
791
792 /// The start of the source range for this declaration,
793 /// ignoring outer template declarations.
794 SourceLocation InnerLocStart;
795
796 bool hasExtInfo() const { return isa<ExtInfo *>(DeclInfo); }
797 ExtInfo *getExtInfo() { return cast<ExtInfo *>(DeclInfo); }
798 const ExtInfo *getExtInfo() const { return cast<ExtInfo *>(DeclInfo); }
799
800protected:
803 SourceLocation StartL)
804 : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {}
805
806public:
807 friend class ASTDeclReader;
808 friend class ASTDeclWriter;
809
811 return hasExtInfo() ? getExtInfo()->TInfo
812 : cast<TypeSourceInfo *>(DeclInfo);
813 }
814
816 if (hasExtInfo())
817 getExtInfo()->TInfo = TI;
818 else
819 DeclInfo = TI;
820 }
821
822 /// Return start of source range ignoring outer template declarations.
823 SourceLocation getInnerLocStart() const { return InnerLocStart; }
824 void setInnerLocStart(SourceLocation L) { InnerLocStart = L; }
825
826 /// Return start of source range taking into account any outer template
827 /// declarations.
829
830 SourceRange getSourceRange() const override LLVM_READONLY;
831
832 SourceLocation getBeginLoc() const LLVM_READONLY {
833 return getOuterLocStart();
834 }
835
836 /// Retrieve the nested-name-specifier that qualifies the name of this
837 /// declaration, if it was present in the source.
839 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
840 : std::nullopt;
841 }
842
843 /// Retrieve the nested-name-specifier (with source-location
844 /// information) that qualifies the name of this declaration, if it was
845 /// present in the source.
847 return hasExtInfo() ? getExtInfo()->QualifierLoc
849 }
850
851 void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
852
853 /// \brief Get the constraint-expression introduced by the trailing
854 /// requires-clause in the function/member declaration, or null if no
855 /// requires-clause was provided.
857 static constexpr AssociatedConstraint Null;
858 return hasExtInfo() ? getExtInfo()->TrailingRequiresClause : Null;
859 }
860
862
864 if (!hasExtInfo())
865 return {};
866 return {/*data=*/getExtInfo()->TemplParamLists,
867 /*length=*/getExtInfo()->NumTemplParamLists};
868 }
869
872
875
876 // Implement isa/cast/dyncast/etc.
877 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
878 static bool classofKind(Kind K) {
879 return K >= firstDeclarator && K <= lastDeclarator;
880 }
881};
882
883/// Structure used to store a statement, the constant value to
884/// which it was evaluated (if any), and whether or not the statement
885/// is an integral constant expression (if known).
887 /// Whether this statement was already evaluated.
888 LLVM_PREFERRED_TYPE(bool)
890
891 /// Whether this statement is being evaluated.
892 LLVM_PREFERRED_TYPE(bool)
893 unsigned IsEvaluating : 1;
894
895 /// Whether this variable is known to have constant initialization. This is
896 /// currently only computed in C++, for static / thread storage duration
897 /// variables that might have constant initialization and for variables that
898 /// are usable in constant expressions.
899 LLVM_PREFERRED_TYPE(bool)
901
902 /// Whether this variable is known to have constant destruction. That is,
903 /// whether running the destructor on the initial value is a side-effect
904 /// (and doesn't inspect any state that might have changed during program
905 /// execution). This is currently only computed if the destructor is
906 /// non-trivial.
907 LLVM_PREFERRED_TYPE(bool)
909
910 /// In C++98, whether the initializer is an ICE. This affects whether the
911 /// variable is usable in constant expressions.
912 LLVM_PREFERRED_TYPE(bool)
913 unsigned HasICEInit : 1;
914 LLVM_PREFERRED_TYPE(bool)
915 unsigned CheckedForICEInit : 1;
916
917 LLVM_PREFERRED_TYPE(bool)
918 unsigned HasSideEffects : 1;
919 LLVM_PREFERRED_TYPE(bool)
921
924
930};
931
932/// Represents a variable declaration or definition.
933class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
934public:
935 /// Initialization styles.
937 /// C-style initialization with assignment
939
940 /// Call-style initialization (C++98)
942
943 /// Direct list-initialization (C++11)
945
946 /// Parenthesized list-initialization (C++20)
948 };
949
950 /// Kinds of thread-local storage.
951 enum TLSKind {
952 /// Not a TLS variable.
954
955 /// TLS with a known-constant initializer.
957
958 /// TLS with a dynamic initializer.
960 };
961
962 /// Return the string used to specify the storage class \p SC.
963 ///
964 /// It is illegal to call this function with SC == None.
965 static const char *getStorageClassSpecifierString(StorageClass SC);
966
967protected:
968 // A pointer union of Stmt * and EvaluatedStmt *. When an EvaluatedStmt, we
969 // have allocated the auxiliary struct of information there.
970 //
971 // TODO: It is a bit unfortunate to use a PointerUnion inside the VarDecl for
972 // this as *many* VarDecls are ParmVarDecls that don't have default
973 // arguments. We could save some space by moving this pointer union to be
974 // allocated in trailing space when necessary.
975 using InitType = llvm::PointerUnion<Stmt *, EvaluatedStmt *>;
976
977 /// The initializer for this variable or, for a ParmVarDecl, the
978 /// C++ default argument.
979 mutable InitType Init;
980
981private:
982 friend class ASTDeclReader;
983 friend class ASTNodeImporter;
984 friend class StmtIteratorBase;
985
986 class VarDeclBitfields {
987 friend class ASTDeclReader;
988 friend class VarDecl;
989
990 LLVM_PREFERRED_TYPE(StorageClass)
991 unsigned SClass : 3;
992 LLVM_PREFERRED_TYPE(ThreadStorageClassSpecifier)
993 unsigned TSCSpec : 2;
994 LLVM_PREFERRED_TYPE(InitializationStyle)
995 unsigned InitStyle : 2;
996
997 /// Whether this variable is an ARC pseudo-__strong variable; see
998 /// isARCPseudoStrong() for details.
999 LLVM_PREFERRED_TYPE(bool)
1000 unsigned ARCPseudoStrong : 1;
1001 };
1002 enum { NumVarDeclBits = 8 };
1003
1004protected:
1006
1013
1015
1017 friend class ASTDeclReader;
1018 friend class ParmVarDecl;
1019
1020 LLVM_PREFERRED_TYPE(VarDeclBitfields)
1021 unsigned : NumVarDeclBits;
1022
1023 /// Whether this parameter inherits a default argument from a
1024 /// prior declaration.
1025 LLVM_PREFERRED_TYPE(bool)
1026 unsigned HasInheritedDefaultArg : 1;
1027
1028 /// Describes the kind of default argument for this parameter. By default
1029 /// this is none. If this is normal, then the default argument is stored in
1030 /// the \c VarDecl initializer expression unless we were unable to parse
1031 /// (even an invalid) expression for the default argument.
1032 LLVM_PREFERRED_TYPE(DefaultArgKind)
1033 unsigned DefaultArgKind : 2;
1034
1035 /// Whether this parameter undergoes K&R argument promotion.
1036 LLVM_PREFERRED_TYPE(bool)
1037 unsigned IsKNRPromoted : 1;
1038
1039 /// Whether this parameter is an ObjC method parameter or not.
1040 LLVM_PREFERRED_TYPE(bool)
1041 unsigned IsObjCMethodParam : 1;
1042
1043 /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier.
1044 /// Otherwise, the number of function parameter scopes enclosing
1045 /// the function parameter scope in which this parameter was
1046 /// declared.
1047 unsigned ScopeDepthOrObjCQuals : NumScopeDepthOrObjCQualsBits;
1048
1049 /// The number of parameters preceding this parameter in the
1050 /// function parameter scope in which it was declared.
1051 unsigned ParameterIndex : NumParameterIndexBits;
1052 };
1053
1055 friend class ASTDeclReader;
1056 friend class ImplicitParamDecl;
1057 friend class VarDecl;
1058
1059 LLVM_PREFERRED_TYPE(VarDeclBitfields)
1060 unsigned : NumVarDeclBits;
1061
1062 // FIXME: We need something similar to CXXRecordDecl::DefinitionData.
1063 /// Whether this variable is a definition which was demoted due to
1064 /// module merge.
1065 LLVM_PREFERRED_TYPE(bool)
1066 unsigned IsThisDeclarationADemotedDefinition : 1;
1067
1068 /// Whether this variable is the exception variable in a C++ catch
1069 /// or an Objective-C @catch statement.
1070 LLVM_PREFERRED_TYPE(bool)
1071 unsigned ExceptionVar : 1;
1072
1073 /// Whether this local variable could be allocated in the return
1074 /// slot of its function, enabling the named return value optimization
1075 /// (NRVO).
1076 LLVM_PREFERRED_TYPE(bool)
1077 unsigned NRVOVariable : 1;
1078
1079 /// Whether this variable is the for-range-declaration in a C++0x
1080 /// for-range statement.
1081 LLVM_PREFERRED_TYPE(bool)
1082 unsigned CXXForRangeDecl : 1;
1083
1084 /// Whether this variable is the for-in loop declaration in Objective-C.
1085 LLVM_PREFERRED_TYPE(bool)
1086 unsigned ObjCForDecl : 1;
1087
1088 /// Whether this variable is (C++1z) inline.
1089 LLVM_PREFERRED_TYPE(bool)
1090 unsigned IsInline : 1;
1091
1092 /// Whether this variable has (C++1z) inline explicitly specified.
1093 LLVM_PREFERRED_TYPE(bool)
1094 unsigned IsInlineSpecified : 1;
1095
1096 /// Whether this variable is (C++0x) constexpr.
1097 LLVM_PREFERRED_TYPE(bool)
1098 unsigned IsConstexpr : 1;
1099
1100 /// Whether this variable is the implicit variable for a lambda
1101 /// init-capture.
1102 LLVM_PREFERRED_TYPE(bool)
1103 unsigned IsInitCapture : 1;
1104
1105 /// Whether this local extern variable's previous declaration was
1106 /// declared in the same block scope. This controls whether we should merge
1107 /// the type of this declaration with its previous declaration.
1108 LLVM_PREFERRED_TYPE(bool)
1109 unsigned PreviousDeclInSameBlockScope : 1;
1110
1111 /// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or
1112 /// something else.
1113 LLVM_PREFERRED_TYPE(ImplicitParamKind)
1114 unsigned ImplicitParamKind : 3;
1115
1116 LLVM_PREFERRED_TYPE(bool)
1117 unsigned EscapingByref : 1;
1118
1119 LLVM_PREFERRED_TYPE(bool)
1120 unsigned IsCXXCondDecl : 1;
1121
1122 /// Whether this variable is the implicit __range variable in a for-range
1123 /// loop.
1124 LLVM_PREFERRED_TYPE(bool)
1125 unsigned IsCXXForRangeImplicitVar : 1;
1126 };
1127
1128 union {
1129 unsigned AllBits;
1130 VarDeclBitfields VarDeclBits;
1133 };
1134
1135 VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1136 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
1137 TypeSourceInfo *TInfo, StorageClass SC);
1138
1140
1142 return getNextRedeclaration();
1143 }
1144
1146 return getPreviousDecl();
1147 }
1148
1150 return getMostRecentDecl();
1151 }
1152
1153public:
1155 using redecl_iterator = redeclarable_base::redecl_iterator;
1156
1163
1164 static VarDecl *Create(ASTContext &C, DeclContext *DC,
1165 SourceLocation StartLoc, SourceLocation IdLoc,
1166 const IdentifierInfo *Id, QualType T,
1167 TypeSourceInfo *TInfo, StorageClass S);
1168
1170
1171 SourceRange getSourceRange() const override LLVM_READONLY;
1172
1173 /// Returns the storage class as written in the source. For the
1174 /// computed linkage of symbol, see getLinkage.
1176 return (StorageClass) VarDeclBits.SClass;
1177 }
1179
1181 VarDeclBits.TSCSpec = TSC;
1182 assert(VarDeclBits.TSCSpec == TSC && "truncation");
1183 }
1185 return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec);
1186 }
1187 TLSKind getTLSKind() const;
1188
1189 /// Returns true if a variable with function scope is a non-static local
1190 /// variable.
1191 bool hasLocalStorage() const {
1192 if (getStorageClass() == SC_None) {
1193 // OpenCL v1.2 s6.5.3: The __constant or constant address space name is
1194 // used to describe variables allocated in global memory and which are
1195 // accessed inside a kernel(s) as read-only variables. As such, variables
1196 // in constant address space cannot have local storage.
1197 if (getType().getAddressSpace() == LangAS::opencl_constant)
1198 return false;
1199 // Second check is for C++11 [dcl.stc]p4.
1200 return !isFileVarDecl() && getTSCSpec() == TSCS_unspecified;
1201 }
1202
1203 // Global Named Register (GNU extension)
1205 return false;
1206
1207 // Return true for: Auto, Register.
1208 // Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal.
1209
1210 return getStorageClass() >= SC_Auto;
1211 }
1212
1213 /// Returns true if a variable with function scope is a static local
1214 /// variable.
1215 bool isStaticLocal() const {
1216 return (getStorageClass() == SC_Static ||
1217 // C++11 [dcl.stc]p4
1219 && !isFileVarDecl();
1220 }
1221
1222 /// Returns true if this is a file-scope variable with internal linkage.
1224 // Calling isExternallyVisible() can trigger linkage computation/caching,
1225 // which may produce stale results when a decl's DeclContext changes after
1226 // creation (e.g., OpenMP declare mapper variables), so here we determine
1227 // it syntactically instead.
1228 if (!isFileVarDecl())
1229 return false;
1230 // Linkage is determined by enclosing class/namespace for static data
1231 // members.
1233 return true;
1234 return isInAnonymousNamespace();
1235 }
1236
1237 /// Returns true if a variable has extern or __private_extern__
1238 /// storage.
1239 bool hasExternalStorage() const {
1240 return getStorageClass() == SC_Extern ||
1242 }
1243
1244 /// Returns true for all variables that do not have local storage.
1245 ///
1246 /// This includes all global variables as well as static variables declared
1247 /// within a function.
1248 bool hasGlobalStorage() const { return !hasLocalStorage(); }
1249
1250 /// Get the storage duration of this variable, per C++ [basic.stc].
1255
1256 /// Compute the language linkage.
1258
1259 /// Determines whether this variable is a variable with external, C linkage.
1260 bool isExternC() const;
1261
1262 /// Determines whether this variable's context is, or is nested within,
1263 /// a C++ extern "C" linkage spec.
1264 bool isInExternCContext() const;
1265
1266 /// Determines whether this variable's context is, or is nested within,
1267 /// a C++ extern "C++" linkage spec.
1268 bool isInExternCXXContext() const;
1269
1270 /// Returns true for local variable declarations other than parameters.
1271 /// Note that this includes static variables inside of functions. It also
1272 /// includes variables inside blocks and expansion statements.
1273 ///
1274 /// void foo() { int x; static int y; extern int z; }
1275 bool isLocalVarDecl() const {
1276 if (getKind() != Decl::Var && getKind() != Decl::Decomposition)
1277 return false;
1278 if (const DeclContext *DC = getLexicalDeclContext())
1279 return DC->getEnclosingNonExpansionStatementContext()
1280 ->getRedeclContext()
1281 ->isFunctionOrMethod();
1282 return false;
1283 }
1284
1285 /// Similar to isLocalVarDecl but also includes parameters.
1287 return isLocalVarDecl() || getKind() == Decl::ParmVar;
1288 }
1289
1290 /// Similar to isLocalVarDecl, but excludes variables declared in blocks.
1292 if (getKind() != Decl::Var && getKind() != Decl::Decomposition)
1293 return false;
1295 return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block;
1296 }
1297
1298 /// Determines whether this is a static data member.
1299 ///
1300 /// This will only be true in C++, and applies to, e.g., the
1301 /// variable 'x' in:
1302 /// \code
1303 /// struct S {
1304 /// static int x;
1305 /// };
1306 /// \endcode
1307 bool isStaticDataMember() const {
1308 // If it wasn't static, it would be a FieldDecl.
1309 return getKind() != Decl::ParmVar && getDeclContext()->isRecord();
1310 }
1311
1312 VarDecl *getCanonicalDecl() override;
1313 const VarDecl *getCanonicalDecl() const {
1314 return const_cast<VarDecl*>(this)->getCanonicalDecl();
1315 }
1316
1318 /// This declaration is only a declaration.
1320
1321 /// This declaration is a tentative definition.
1323
1324 /// This declaration is definitely a definition.
1326 };
1327
1328 /// Check whether this declaration is a definition. If this could be
1329 /// a tentative definition (in C), don't check whether there's an overriding
1330 /// definition.
1335
1336 /// Check whether this variable is defined in this translation unit.
1341
1342 /// Get the tentative definition that acts as the real definition in a TU.
1343 /// Returns null if there is a proper definition available.
1346 return const_cast<VarDecl*>(this)->getActingDefinition();
1347 }
1348
1349 /// Get the real (not just tentative) definition for this declaration.
1352 return const_cast<VarDecl*>(this)->getDefinition(C);
1353 }
1357 const VarDecl *getDefinition() const {
1358 return const_cast<VarDecl*>(this)->getDefinition();
1359 }
1360
1361 /// Determine whether this is or was instantiated from an out-of-line
1362 /// definition of a static data member.
1363 bool isOutOfLine() const override;
1364
1365 /// Returns true for file scoped variable declaration.
1366 bool isFileVarDecl() const {
1367 Kind K = getKind();
1368 if (K == ParmVar || K == ImplicitParam)
1369 return false;
1370
1371 if (getLexicalDeclContext()->getRedeclContext()->isFileContext())
1372 return true;
1373
1374 if (isStaticDataMember())
1375 return true;
1376
1377 return false;
1378 }
1379
1380 /// Get the initializer for this variable, no matter which
1381 /// declaration it is attached to.
1382 const Expr *getAnyInitializer() const {
1383 const VarDecl *D;
1384 return getAnyInitializer(D);
1385 }
1386
1387 /// Get the initializer for this variable, no matter which
1388 /// declaration it is attached to. Also get that declaration.
1389 const Expr *getAnyInitializer(const VarDecl *&D) const;
1390
1391 bool hasInit() const;
1392 const Expr *getInit() const {
1393 return const_cast<VarDecl *>(this)->getInit();
1394 }
1395 Expr *getInit();
1396
1397 /// Retrieve the address of the initializer expression.
1398 Stmt **getInitAddress();
1399
1400 void setInit(Expr *I);
1401
1402 /// Get the initializing declaration of this variable, if any. This is
1403 /// usually the definition, except that for a static data member it can be
1404 /// the in-class declaration.
1407 return const_cast<VarDecl *>(this)->getInitializingDeclaration();
1408 }
1409
1410 /// Checks whether this declaration has an initializer with side effects.
1411 /// The result is cached. If the result hasn't been computed this can trigger
1412 /// deserialization and constant evaluation. By running this during
1413 /// serialization and serializing the result all clients can safely call this
1414 /// without triggering further deserialization.
1415 bool hasInitWithSideEffects() const;
1416
1417 /// Determine whether this variable's value might be usable in a
1418 /// constant expression, according to the relevant language standard.
1419 /// This only checks properties of the declaration, and does not check
1420 /// whether the initializer is in fact a constant expression.
1421 ///
1422 /// This corresponds to C++20 [expr.const]p3's notion of a
1423 /// "potentially-constant" variable.
1425
1426 /// Determine whether this variable's value can be used in a
1427 /// constant expression, according to the relevant language standard,
1428 /// including checking whether it was initialized by a constant expression.
1429 bool isUsableInConstantExpressions(const ASTContext &C) const;
1430
1433
1434 /// Attempt to evaluate the value of the initializer attached to this
1435 /// declaration, and produce notes explaining why it cannot be evaluated.
1436 /// Returns a pointer to the value if evaluation succeeded, \c nullptr
1437 /// otherwise.
1438 const APValue *evaluateValue() const;
1439
1440private:
1441 const APValue *evaluateValueImpl(SmallVectorImpl<PartialDiagnosticAt> *Notes,
1442 bool IsConstantInitialization) const;
1443
1444public:
1445 /// Return the already-evaluated value of this variable's
1446 /// initializer, or \c nullptr if the value is not yet known or couldn't be
1447 /// evaluated.
1448 const APValue *getEvaluatedValue() const;
1449
1450 /// Evaluate the destruction of this variable to determine if it constitutes
1451 /// constant destruction.
1452 ///
1453 /// \pre hasConstantInitialization()
1454 /// \return \c true if this variable has constant destruction, \c false if
1455 /// not.
1457
1458 /// Determine whether this variable has constant initialization.
1459 ///
1460 /// This is only set in two cases: when the language semantics require
1461 /// constant initialization (globals in C and some globals in C++), and when
1462 /// the variable is usable in constant expressions (constexpr, const int, and
1463 /// reference variables in C++).
1464 bool hasConstantInitialization() const;
1465
1466 /// Determine whether the initializer of this variable is an integer constant
1467 /// expression. For use in C++98, where this affects whether the variable is
1468 /// usable in constant expressions.
1469 bool hasICEInitializer(const ASTContext &Context) const;
1470
1471 /// Evaluate the initializer of this variable to determine whether it's a
1472 /// constant initializer. Should only be called once, after completing the
1473 /// definition of the variable.
1476
1478 VarDeclBits.InitStyle = Style;
1479 }
1480
1481 /// The style of initialization for this declaration.
1482 ///
1483 /// C-style initialization is "int x = 1;". Call-style initialization is
1484 /// a C++98 direct-initializer, e.g. "int x(1);". The Init expression will be
1485 /// the expression inside the parens or a "ClassType(a,b,c)" class constructor
1486 /// expression for class types. List-style initialization is C++11 syntax,
1487 /// e.g. "int x{1};". Clients can distinguish between different forms of
1488 /// initialization by checking this value. In particular, "int x = {1};" is
1489 /// C-style, "int x({1})" is call-style, and "int x{1};" is list-style; the
1490 /// Init expression in all three cases is an InitListExpr.
1492 return static_cast<InitializationStyle>(VarDeclBits.InitStyle);
1493 }
1494
1495 /// Whether the initializer is a direct-initializer (list or call).
1496 bool isDirectInit() const {
1497 return getInitStyle() != CInit;
1498 }
1499
1500 /// If this definition should pretend to be a declaration.
1502 return isa<ParmVarDecl>(this) ? false :
1503 NonParmVarDeclBits.IsThisDeclarationADemotedDefinition;
1504 }
1505
1506 /// This is a definition which should be demoted to a declaration.
1507 ///
1508 /// In some cases (mostly module merging) we can end up with two visible
1509 /// definitions one of which needs to be demoted to a declaration to keep
1510 /// the AST invariants.
1512 assert(isThisDeclarationADefinition() && "Not a definition!");
1513 assert(!isa<ParmVarDecl>(this) && "Cannot demote ParmVarDecls!");
1514 NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = 1;
1515 }
1516
1517 /// Determine whether this variable is the exception variable in a
1518 /// C++ catch statememt or an Objective-C \@catch statement.
1519 bool isExceptionVariable() const {
1520 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.ExceptionVar;
1521 }
1522 void setExceptionVariable(bool EV) {
1523 assert(!isa<ParmVarDecl>(this));
1524 NonParmVarDeclBits.ExceptionVar = EV;
1525 }
1526
1527 /// Determine whether this local variable can be used with the named
1528 /// return value optimization (NRVO).
1529 ///
1530 /// The named return value optimization (NRVO) works by marking certain
1531 /// non-volatile local variables of class type as NRVO objects. These
1532 /// locals can be allocated within the return slot of their containing
1533 /// function, in which case there is no need to copy the object to the
1534 /// return slot when returning from the function. Within the function body,
1535 /// each return that returns the NRVO object will have this variable as its
1536 /// NRVO candidate.
1537 bool isNRVOVariable() const {
1538 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.NRVOVariable;
1539 }
1540 void setNRVOVariable(bool NRVO) {
1541 assert(!isa<ParmVarDecl>(this));
1542 NonParmVarDeclBits.NRVOVariable = NRVO;
1543 }
1544
1545 /// Determine whether this variable is the for-range-declaration in
1546 /// a C++0x for-range statement.
1547 bool isCXXForRangeDecl() const {
1548 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.CXXForRangeDecl;
1549 }
1550 void setCXXForRangeDecl(bool FRD) {
1551 assert(!isa<ParmVarDecl>(this));
1552 NonParmVarDeclBits.CXXForRangeDecl = FRD;
1553 }
1554
1555 /// Determine whether this variable is a for-loop declaration for a
1556 /// for-in statement in Objective-C.
1557 bool isObjCForDecl() const {
1558 return NonParmVarDeclBits.ObjCForDecl;
1559 }
1560
1561 void setObjCForDecl(bool FRD) {
1562 NonParmVarDeclBits.ObjCForDecl = FRD;
1563 }
1564
1565 /// Determine whether this variable is an ARC pseudo-__strong variable. A
1566 /// pseudo-__strong variable has a __strong-qualified type but does not
1567 /// actually retain the object written into it. Generally such variables are
1568 /// also 'const' for safety. There are 3 cases where this will be set, 1) if
1569 /// the variable is annotated with the objc_externally_retained attribute, 2)
1570 /// if its 'self' in a non-init method, or 3) if its the variable in an for-in
1571 /// loop.
1572 bool isARCPseudoStrong() const { return VarDeclBits.ARCPseudoStrong; }
1573 void setARCPseudoStrong(bool PS) { VarDeclBits.ARCPseudoStrong = PS; }
1574
1575 /// Whether this variable is (C++1z) inline.
1576 bool isInline() const {
1577 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInline;
1578 }
1579 bool isInlineSpecified() const {
1580 return isa<ParmVarDecl>(this) ? false
1581 : NonParmVarDeclBits.IsInlineSpecified;
1582 }
1584 assert(!isa<ParmVarDecl>(this));
1585 NonParmVarDeclBits.IsInline = true;
1586 NonParmVarDeclBits.IsInlineSpecified = true;
1587 }
1589 assert(!isa<ParmVarDecl>(this));
1590 NonParmVarDeclBits.IsInline = true;
1591 }
1592
1593 /// Whether this variable is (C++11) constexpr.
1594 bool isConstexpr() const {
1595 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsConstexpr;
1596 }
1597 void setConstexpr(bool IC) {
1598 assert(!isa<ParmVarDecl>(this));
1599 NonParmVarDeclBits.IsConstexpr = IC;
1600 }
1601
1602 /// Whether this variable is the implicit variable for a lambda init-capture.
1603 bool isInitCapture() const {
1604 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInitCapture;
1605 }
1606 void setInitCapture(bool IC) {
1607 assert(!isa<ParmVarDecl>(this));
1608 NonParmVarDeclBits.IsInitCapture = IC;
1609 }
1610
1611 /// Whether this local extern variable declaration's previous declaration
1612 /// was declared in the same block scope. Only correct in C++.
1614 return isa<ParmVarDecl>(this)
1615 ? false
1616 : NonParmVarDeclBits.PreviousDeclInSameBlockScope;
1617 }
1619 assert(!isa<ParmVarDecl>(this));
1620 NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
1621 }
1622
1623 /// Indicates the capture is a __block variable that is captured by a block
1624 /// that can potentially escape (a block for which BlockDecl::doesNotEscape
1625 /// returns false).
1626 bool isEscapingByref() const;
1627
1628 /// Indicates the capture is a __block variable that is never captured by an
1629 /// escaping block.
1630 bool isNonEscapingByref() const;
1631
1633 NonParmVarDeclBits.EscapingByref = true;
1634 }
1635
1636 bool isCXXCondDecl() const {
1637 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsCXXCondDecl;
1638 }
1639
1641 assert(!isa<ParmVarDecl>(this));
1642 NonParmVarDeclBits.IsCXXCondDecl = true;
1643 }
1644
1645 /// Whether this variable is the implicit '__range' variable in C++
1646 /// range-based for loops.
1648 return isa<ParmVarDecl>(this) ? false
1649 : NonParmVarDeclBits.IsCXXForRangeImplicitVar;
1650 }
1651
1653 assert(!isa<ParmVarDecl>(this) &&
1654 "Cannot set IsCXXForRangeImplicitVar on ParmVarDecl");
1655 NonParmVarDeclBits.IsCXXForRangeImplicitVar = FRV;
1656 }
1657
1658 /// Determines if this variable's alignment is dependent.
1659 bool hasDependentAlignment() const;
1660
1661 /// Retrieve the variable declaration from which this variable could
1662 /// be instantiated, if it is an instantiation (rather than a non-template).
1664
1665 /// If this variable is an instantiated static data member of a
1666 /// class template specialization, returns the templated static data member
1667 /// from which it was instantiated.
1669
1670 /// If this variable is an instantiation of a variable template or a
1671 /// static data member of a class template, determine what kind of
1672 /// template specialization or instantiation this is.
1674
1675 /// Get the template specialization kind of this variable for the purposes of
1676 /// template instantiation. This differs from getTemplateSpecializationKind()
1677 /// for an instantiation of a class-scope explicit specialization.
1680
1681 /// If this variable is an instantiation of a variable template or a
1682 /// static data member of a class template, determine its point of
1683 /// instantiation.
1685
1686 /// If this variable is an instantiation of a static data member of a
1687 /// class template specialization, retrieves the member specialization
1688 /// information.
1690
1691 /// For a static data member that was instantiated from a static
1692 /// data member of a class template, set the template specialiation kind.
1694 SourceLocation PointOfInstantiation = SourceLocation());
1695
1696 /// Specify that this variable is an instantiation of the
1697 /// static data member VD.
1700
1701 /// Retrieves the variable template that is described by this
1702 /// variable declaration.
1703 ///
1704 /// Every variable template is represented as a VarTemplateDecl and a
1705 /// VarDecl. The former contains template properties (such as
1706 /// the template parameter lists) while the latter contains the
1707 /// actual description of the template's
1708 /// contents. VarTemplateDecl::getTemplatedDecl() retrieves the
1709 /// VarDecl that from a VarTemplateDecl, while
1710 /// getDescribedVarTemplate() retrieves the VarTemplateDecl from
1711 /// a VarDecl.
1713
1715
1716 // Is this variable known to have a definition somewhere in the complete
1717 // program? This may be true even if the declaration has internal linkage and
1718 // has no definition within this source file.
1719 bool isKnownToBeDefined() const;
1720
1721 /// Is destruction of this variable entirely suppressed? If so, the variable
1722 /// need not have a usable destructor at all.
1723 bool isNoDestroy(const ASTContext &) const;
1724
1725 /// Would the destruction of this variable have any effect, and if so, what
1726 /// kind?
1728
1729 /// Whether this variable has a flexible array member initialized with one
1730 /// or more elements. This can only be called for declarations where
1731 /// hasInit() is true.
1732 ///
1733 /// (The standard doesn't allow initializing flexible array members; this is
1734 /// a gcc/msvc extension.)
1735 bool hasFlexibleArrayInit(const ASTContext &Ctx) const;
1736
1737 /// If hasFlexibleArrayInit is true, compute the number of additional bytes
1738 /// necessary to store those elements. Otherwise, returns zero.
1739 ///
1740 /// This can only be called for declarations where hasInit() is true.
1742
1743 /// Apply a deduced address space, if one isn't already set.
1744 void assignAddressSpace(const ASTContext &Ctxt, LangAS AS);
1745 void deduceParmAddressSpace(const ASTContext &Ctxt);
1746
1747 // Implement isa/cast/dyncast/etc.
1748 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1749 static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; }
1750};
1751
1752/// Defines the kind of the implicit parameter: is this an implicit parameter
1753/// with pointer to 'this', 'self', '_cmd', virtual table pointers, captured
1754/// context or something else.
1756 /// Parameter for Objective-C 'self' argument
1758
1759 /// Parameter for Objective-C '_cmd' argument
1761
1762 /// Parameter for C++ 'this' argument
1764
1765 /// Parameter for C++ virtual table pointers
1767
1768 /// Parameter for captured context
1770
1771 /// Parameter for Thread private variable
1773
1774 /// Other implicit parameter
1776};
1777
1779 void anchor() override;
1780
1781protected:
1783 const IdentifierInfo *Id, QualType Type,
1784 ImplicitParamKind ParamKind)
1785 : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
1786 /*TInfo=*/nullptr, SC_None) {
1787 NonParmVarDeclBits.ImplicitParamKind = llvm::to_underlying(ParamKind);
1788 setImplicit();
1789 }
1790
1792 : VarDecl(ImplicitParam, C, /*DC=*/nullptr, SourceLocation(),
1793 SourceLocation(), /*Id=*/nullptr, Type,
1794 /*TInfo=*/nullptr, SC_None) {
1795 NonParmVarDeclBits.ImplicitParamKind = llvm::to_underlying(ParamKind);
1796 setImplicit();
1797 }
1798
1799public:
1800 /// Create implicit parameter.
1802 SourceLocation IdLoc,
1803 const IdentifierInfo *Id, QualType T,
1804 ImplicitParamKind ParamKind);
1806 ImplicitParamKind ParamKind);
1807
1809 /// Returns the implicit parameter kind.
1811 return static_cast<ImplicitParamKind>(NonParmVarDeclBits.ImplicitParamKind);
1812 }
1813
1814 // Implement isa/cast/dyncast/etc.
1815 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1816 static bool classofKind(Kind K) { return K == ImplicitParam; }
1817};
1818
1819/// Represents a parameter to a function.
1820class ParmVarDecl : public VarDecl {
1821public:
1824
1825protected:
1827 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
1828 TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
1829 : VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) {
1830 assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
1831 assert(ParmVarDeclBits.DefaultArgKind == DAK_None);
1832 assert(ParmVarDeclBits.IsKNRPromoted == false);
1833 assert(ParmVarDeclBits.IsObjCMethodParam == false);
1834 setDefaultArg(DefArg);
1835 }
1836
1837public:
1839 SourceLocation StartLoc, SourceLocation IdLoc,
1840 const IdentifierInfo *Id, QualType T,
1841 TypeSourceInfo *TInfo, StorageClass S,
1842 Expr *DefArg);
1843
1845
1846 SourceRange getSourceRange() const override LLVM_READONLY;
1847
1848 void setObjCMethodScopeInfo(unsigned parameterIndex) {
1849 ParmVarDeclBits.IsObjCMethodParam = true;
1850 setParameterIndex(parameterIndex);
1851 }
1852
1853 void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) {
1854 assert(!ParmVarDeclBits.IsObjCMethodParam);
1855
1856 ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth;
1857 assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth
1858 && "truncation!");
1859
1860 setParameterIndex(parameterIndex);
1861 }
1862
1864 return ParmVarDeclBits.IsObjCMethodParam;
1865 }
1866
1867 /// Determines whether this parameter is destroyed in the callee function.
1868 bool isDestroyedInCallee() const;
1869
1870 unsigned getFunctionScopeDepth() const {
1871 if (ParmVarDeclBits.IsObjCMethodParam) return 0;
1872 return ParmVarDeclBits.ScopeDepthOrObjCQuals;
1873 }
1874
1875 static constexpr unsigned getMaxFunctionScopeDepth() {
1876 return (1u << NumScopeDepthOrObjCQualsBits) - 1;
1877 }
1878
1879 /// Returns the index of this parameter in its prototype or method scope.
1880 unsigned getFunctionScopeIndex() const {
1881 return getParameterIndex();
1882 }
1883
1885 if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None;
1886 return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals);
1887 }
1889 assert(ParmVarDeclBits.IsObjCMethodParam);
1890 ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal;
1891 }
1892
1893 /// True if the value passed to this parameter must undergo
1894 /// K&R-style default argument promotion:
1895 ///
1896 /// C99 6.5.2.2.
1897 /// If the expression that denotes the called function has a type
1898 /// that does not include a prototype, the integer promotions are
1899 /// performed on each argument, and arguments that have type float
1900 /// are promoted to double.
1901 bool isKNRPromoted() const {
1902 return ParmVarDeclBits.IsKNRPromoted;
1903 }
1904 void setKNRPromoted(bool promoted) {
1905 ParmVarDeclBits.IsKNRPromoted = promoted;
1906 }
1907
1909 return ExplicitObjectParameterIntroducerLoc.isValid();
1910 }
1911
1913 ExplicitObjectParameterIntroducerLoc = Loc;
1914 }
1915
1917 return ExplicitObjectParameterIntroducerLoc;
1918 }
1919
1921 const Expr *getDefaultArg() const {
1922 return const_cast<ParmVarDecl *>(this)->getDefaultArg();
1923 }
1924
1925 void setDefaultArg(Expr *defarg);
1926
1927 /// Retrieve the source range that covers the entire default
1928 /// argument.
1933 return const_cast<ParmVarDecl *>(this)->getUninstantiatedDefaultArg();
1934 }
1935
1936 /// Determines whether this parameter has a default argument,
1937 /// either parsed or not.
1938 bool hasDefaultArg() const;
1939
1940 /// Determines whether this parameter has a default argument that has not
1941 /// yet been parsed. This will occur during the processing of a C++ class
1942 /// whose member functions have default arguments, e.g.,
1943 /// @code
1944 /// class X {
1945 /// public:
1946 /// void f(int x = 17); // x has an unparsed default argument now
1947 /// }; // x has a regular default argument now
1948 /// @endcode
1950 return ParmVarDeclBits.DefaultArgKind == DAK_Unparsed;
1951 }
1952
1954 return ParmVarDeclBits.DefaultArgKind == DAK_Uninstantiated;
1955 }
1956
1957 /// Specify that this parameter has an unparsed default argument.
1958 /// The argument will be replaced with a real default argument via
1959 /// setDefaultArg when the class definition enclosing the function
1960 /// declaration that owns this default argument is completed.
1962 ParmVarDeclBits.DefaultArgKind = DAK_Unparsed;
1963 }
1964
1966 return ParmVarDeclBits.HasInheritedDefaultArg;
1967 }
1968
1969 void setHasInheritedDefaultArg(bool I = true) {
1970 ParmVarDeclBits.HasInheritedDefaultArg = I;
1971 }
1972
1973 QualType getOriginalType() const;
1974
1975 /// Sets the function declaration that owns this
1976 /// ParmVarDecl. Since ParmVarDecls are often created before the
1977 /// FunctionDecls that own them, this routine is required to update
1978 /// the DeclContext appropriately.
1980
1981 // Implement isa/cast/dyncast/etc.
1982 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1983 static bool classofKind(Kind K) { return K == ParmVar; }
1984
1985private:
1986 friend class ASTDeclReader;
1987
1988 enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };
1989 SourceLocation ExplicitObjectParameterIntroducerLoc;
1990
1991 void setParameterIndex(unsigned parameterIndex) {
1992 if (parameterIndex >= ParameterIndexSentinel) {
1993 setParameterIndexLarge(parameterIndex);
1994 return;
1995 }
1996
1997 ParmVarDeclBits.ParameterIndex = parameterIndex;
1998 assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
1999 }
2000 unsigned getParameterIndex() const {
2001 unsigned d = ParmVarDeclBits.ParameterIndex;
2002 return d == ParameterIndexSentinel ? getParameterIndexLarge() : d;
2003 }
2004
2005 void setParameterIndexLarge(unsigned parameterIndex);
2006 unsigned getParameterIndexLarge() const;
2007};
2008
2017
2018/// Kinds of C++ special members.
2028
2029/// Kinds of defaulted comparison operator functions.
2030enum class DefaultedComparisonKind : unsigned char {
2031 /// This is not a defaultable comparison operator.
2033 /// This is an operator== that should be implemented as a series of
2034 /// subobject comparisons.
2036 /// This is an operator<=> that should be implemented as a series of
2037 /// subobject comparisons.
2039 /// This is an operator!= that should be implemented as a rewrite in terms
2040 /// of a == comparison.
2042 /// This is an <, <=, >, or >= that should be implemented as a rewrite in
2043 /// terms of a <=> comparison.
2045};
2046
2047/// Represents a function declaration or definition.
2048///
2049/// Since a given function can be declared several times in a program,
2050/// there may be several FunctionDecls that correspond to that
2051/// function. Only one of those FunctionDecls will be found when
2052/// traversing the list of declarations in the context of the
2053/// FunctionDecl (e.g., the translation unit); this FunctionDecl
2054/// contains all of the information known about the function. Other,
2055/// previous declarations of the function are available via the
2056/// getPreviousDecl() chain.
2058 public DeclContext,
2059 public Redeclarable<FunctionDecl> {
2060 // This class stores some data in DeclContext::FunctionDeclBits
2061 // to save some space. Use the provided accessors to access it.
2062public:
2063 /// The kind of templated function a FunctionDecl can be.
2065 // Not templated.
2067 // The pattern in a function template declaration.
2069 // A non-template function that is an instantiation or explicit
2070 // specialization of a member of a templated class.
2072 // An instantiation or explicit specialization of a function template.
2073 // Note: this might have been instantiated from a templated class if it
2074 // is a class-scope explicit specialization.
2076 // A function template specialization that hasn't yet been resolved to a
2077 // particular specialized function template.
2079 // A non-template function which is in a dependent scope.
2081
2082 };
2083
2084 /// Stashed information about a defaulted/deleted function body, including
2085 /// the active FP pragma overrides (FPOptionsOverride) from the declaration
2086 /// site. These overrides are required to correctly synthesize the function
2087 /// body.
2089 : llvm::TrailingObjects<DefaultedOrDeletedFunctionInfo, DeclAccessPair,
2090 StringLiteral *> {
2091 friend TrailingObjects;
2092 unsigned NumLookups;
2093 bool HasDeletedMessage;
2094 FPOptionsOverride FPFeatures;
2095
2096 size_t numTrailingObjects(OverloadToken<DeclAccessPair>) const {
2097 return NumLookups;
2098 }
2099
2100 public:
2102 Create(ASTContext &Context, ArrayRef<DeclAccessPair> Lookups,
2103 FPOptionsOverride FPFeatures,
2104 StringLiteral *DeletedMessage = nullptr);
2105
2106 FPOptionsOverride getFPFeatures() const { return FPFeatures; }
2107
2108 /// Get the unqualified lookup results that should be used in this
2109 /// defaulted function definition.
2111 return getTrailingObjects<DeclAccessPair>(NumLookups);
2112 }
2113
2115 return HasDeletedMessage ? *getTrailingObjects<StringLiteral *>()
2116 : nullptr;
2117 }
2118
2119 void setDeletedMessage(StringLiteral *Message);
2120 };
2121
2122 /// For a defaulted function, the kind of defaulted function that it is.
2124 LLVM_PREFERRED_TYPE(CXXSpecialMemberKind)
2125 unsigned SpecialMember : 8;
2126 unsigned Comparison : 8;
2127
2128 public:
2130 : SpecialMember(llvm::to_underlying(CXXSpecialMemberKind::Invalid)),
2131 Comparison(llvm::to_underlying(DefaultedComparisonKind::None)) {}
2133 : SpecialMember(llvm::to_underlying(CSM)),
2134 Comparison(llvm::to_underlying(DefaultedComparisonKind::None)) {}
2136 : SpecialMember(llvm::to_underlying(CXXSpecialMemberKind::Invalid)),
2137 Comparison(llvm::to_underlying(Comp)) {}
2138
2139 bool isSpecialMember() const {
2140 return static_cast<CXXSpecialMemberKind>(SpecialMember) !=
2142 }
2143 bool isComparison() const {
2144 return static_cast<DefaultedComparisonKind>(Comparison) !=
2146 }
2147
2148 explicit operator bool() const {
2149 return isSpecialMember() || isComparison();
2150 }
2151
2153 return static_cast<CXXSpecialMemberKind>(SpecialMember);
2154 }
2156 return static_cast<DefaultedComparisonKind>(Comparison);
2157 }
2158
2159 /// Get the index of this function kind for use in diagnostics.
2160 unsigned getDiagnosticIndex() const {
2161 static_assert(llvm::to_underlying(CXXSpecialMemberKind::Invalid) >
2162 llvm::to_underlying(CXXSpecialMemberKind::Destructor),
2163 "invalid should have highest index");
2164 static_assert((unsigned)DefaultedComparisonKind::None == 0,
2165 "none should be equal to zero");
2166 return SpecialMember + Comparison;
2167 }
2168 };
2169
2170private:
2171 /// A new[]'d array of pointers to VarDecls for the formal
2172 /// parameters of this function. This is null if a prototype or if there are
2173 /// no formals.
2174 ParmVarDecl **ParamInfo = nullptr;
2175
2176 /// The active member of this union is determined by
2177 /// FunctionDeclBits.HasDefaultedOrDeletedInfo.
2178 union {
2179 /// The body of the function.
2181 /// Information about a future defaulted function definition.
2183 };
2184
2185 unsigned ODRHash;
2186
2187 /// End part of this FunctionDecl's source range.
2188 ///
2189 /// We could compute the full range in getSourceRange(). However, when we're
2190 /// dealing with a function definition deserialized from a PCH/AST file,
2191 /// we can only compute the full range once the function body has been
2192 /// de-serialized, so it's far better to have the (sometimes-redundant)
2193 /// EndRangeLoc.
2194 SourceLocation EndRangeLoc;
2195
2196 SourceLocation DefaultKWLoc;
2197
2198 /// The template or declaration that this declaration
2199 /// describes or was instantiated from, respectively.
2200 ///
2201 /// For non-templates this value will be NULL, unless this declaration was
2202 /// declared directly inside of a function template, in which case it will
2203 /// have a pointer to a FunctionDecl, stored in the NamedDecl. For function
2204 /// declarations that describe a function template, this will be a pointer to
2205 /// a FunctionTemplateDecl, stored in the NamedDecl. For member functions of
2206 /// class template specializations, this will be a MemberSpecializationInfo
2207 /// pointer containing information about the specialization.
2208 /// For function template specializations, this will be a
2209 /// FunctionTemplateSpecializationInfo, which contains information about
2210 /// the template being specialized and the template arguments involved in
2211 /// that specialization.
2212 llvm::PointerUnion<NamedDecl *, MemberSpecializationInfo *,
2215 TemplateOrSpecialization;
2216
2217 /// Provides source/type location info for the declaration name embedded in
2218 /// the DeclaratorDecl base class.
2219 DeclarationNameLoc DNLoc;
2220
2221 /// Specify that this function declaration is actually a function
2222 /// template specialization.
2223 ///
2224 /// \param C the ASTContext.
2225 ///
2226 /// \param Template the function template that this function template
2227 /// specialization specializes.
2228 ///
2229 /// \param TemplateArgs the template arguments that produced this
2230 /// function template specialization from the template.
2231 ///
2232 /// \param InsertToken If set, the insert token in the function template
2233 /// specialization set where the function template specialization data will
2234 /// be inserted.
2235 ///
2236 /// \param TSK the kind of template specialization this is.
2237 ///
2238 /// \param TemplateArgsAsWritten location info of template arguments.
2239 ///
2240 /// \param PointOfInstantiation point at which the function template
2241 /// specialization was first instantiated.
2242 void setFunctionTemplateSpecialization(
2244 TemplateArgumentList *TemplateArgs,
2245 llvm::FoldingSetInsertToken InsertToken, TemplateSpecializationKind TSK,
2246 const TemplateArgumentListInfo *TemplateArgsAsWritten,
2247 SourceLocation PointOfInstantiation);
2248
2249 /// Specify that this record is an instantiation of the
2250 /// member function FD.
2251 void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD,
2253
2254 void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo);
2255
2256 // This is unfortunately needed because ASTDeclWriter::VisitFunctionDecl
2257 // need to access this bit but we want to avoid making ASTDeclWriter
2258 // a friend of FunctionDeclBitfields just for this.
2259 bool isDeletedBit() const { return FunctionDeclBits.IsDeleted; }
2260
2261 /// Whether an ODRHash has been stored.
2262 bool hasODRHash() const { return FunctionDeclBits.HasODRHash; }
2263
2264 /// State that an ODRHash has been stored.
2265 void setHasODRHash(bool B = true) { FunctionDeclBits.HasODRHash = B; }
2266
2267protected:
2268 FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2269 const DeclarationNameInfo &NameInfo, QualType T,
2270 TypeSourceInfo *TInfo, StorageClass S, bool UsesFPIntrin,
2271 bool isInlineSpecified, ConstexprSpecKind ConstexprKind,
2272 const AssociatedConstraint &TrailingRequiresClause);
2273
2275
2279
2281 return getPreviousDecl();
2282 }
2283
2285 return getMostRecentDecl();
2286 }
2287
2288public:
2289 friend class ASTDeclReader;
2290 friend class ASTDeclWriter;
2291
2293 using redecl_iterator = redeclarable_base::redecl_iterator;
2294
2301
2302 static FunctionDecl *
2305 TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin = false,
2306 bool isInlineSpecified = false, bool hasWrittenPrototype = true,
2308 const AssociatedConstraint &TrailingRequiresClause = {}) {
2309 DeclarationNameInfo NameInfo(N, NLoc);
2310 return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, SC,
2312 hasWrittenPrototype, ConstexprKind,
2313 TrailingRequiresClause);
2314 }
2315
2316 static FunctionDecl *
2317 Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2318 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2319 StorageClass SC, bool UsesFPIntrin, bool isInlineSpecified,
2320 bool hasWrittenPrototype, ConstexprSpecKind ConstexprKind,
2321 const AssociatedConstraint &TrailingRequiresClause);
2322
2323 static FunctionDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
2324
2328
2329 void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
2330 bool Qualified) const override;
2331
2332 void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
2333
2335
2336 /// Returns the location of the ellipsis of a variadic function.
2338 const auto *FPT = getType()->getAs<FunctionProtoType>();
2339 if (FPT && FPT->isVariadic())
2340 return FPT->getEllipsisLoc();
2341 return SourceLocation();
2342 }
2343
2344 SourceRange getSourceRange() const override LLVM_READONLY;
2345
2346 // Function definitions.
2347 //
2348 // A function declaration may be:
2349 // - a non defining declaration,
2350 // - a definition. A function may be defined because:
2351 // - it has a body, or will have it in the case of late parsing.
2352 // - it has an uninstantiated body. The body does not exist because the
2353 // function is not used yet, but the declaration is considered a
2354 // definition and does not allow other definition of this function.
2355 // - it does not have a user specified body, but it does not allow
2356 // redefinition, because it is deleted/defaulted or is defined through
2357 // some other mechanism (alias, ifunc).
2358
2359 /// Returns true if the function has a body.
2360 ///
2361 /// The function body might be in any of the (re-)declarations of this
2362 /// function. The variant that accepts a FunctionDecl pointer will set that
2363 /// function declaration to the actual declaration containing the body (if
2364 /// there is one).
2365 bool hasBody(const FunctionDecl *&Definition) const;
2366
2367 bool hasBody() const override {
2368 const FunctionDecl* Definition;
2369 return hasBody(Definition);
2370 }
2371
2372 /// Returns whether the function has a trivial body that does not require any
2373 /// specific codegen.
2374 bool hasTrivialBody() const;
2375
2376 /// Returns true if the function has a definition that does not need to be
2377 /// instantiated.
2378 ///
2379 /// The variant that accepts a FunctionDecl pointer will set that function
2380 /// declaration to the declaration that is a definition (if there is one).
2381 ///
2382 /// \param CheckForPendingFriendDefinition If \c true, also check for friend
2383 /// declarations that were instantiated from function definitions.
2384 /// Such a declaration behaves as if it is a definition for the
2385 /// purpose of redefinition checking, but isn't actually a "real"
2386 /// definition until its body is instantiated.
2387 bool isDefined(const FunctionDecl *&Definition,
2388 bool CheckForPendingFriendDefinition = false) const;
2389
2390 bool isDefined() const {
2391 const FunctionDecl* Definition;
2392 return isDefined(Definition);
2393 }
2394
2395 /// Get the definition for this declaration.
2397 const FunctionDecl *Definition;
2398 if (isDefined(Definition))
2399 return const_cast<FunctionDecl *>(Definition);
2400 return nullptr;
2401 }
2403 return const_cast<FunctionDecl *>(this)->getDefinition();
2404 }
2405
2406 /// Retrieve the body (definition) of the function. The function body might be
2407 /// in any of the (re-)declarations of this function. The variant that accepts
2408 /// a FunctionDecl pointer will set that function declaration to the actual
2409 /// declaration containing the body (if there is one).
2410 /// NOTE: For checking if there is a body, use hasBody() instead, to avoid
2411 /// unnecessary AST de-serialization of the body.
2412 Stmt *getBody(const FunctionDecl *&Definition) const;
2413
2414 Stmt *getBody() const override {
2415 const FunctionDecl* Definition;
2416 return getBody(Definition);
2417 }
2418
2419 /// Returns whether this specific declaration of the function is also a
2420 /// definition that does not contain uninstantiated body.
2421 ///
2422 /// This does not determine whether the function has been defined (e.g., in a
2423 /// previous definition); for that information, use isDefined.
2424 ///
2425 /// Note: the function declaration does not become a definition until the
2426 /// parser reaches the definition, if called before, this function will return
2427 /// `false`.
2433
2434 /// Determine whether this specific declaration of the function is a friend
2435 /// declaration that was instantiated from a function definition. Such
2436 /// declarations behave like definitions in some contexts.
2438
2439 /// Returns whether this specific declaration of the function has a body.
2441 return (!FunctionDeclBits.HasDefaultedOrDeletedInfo && Body) ||
2443 }
2444
2445 void setBody(Stmt *B);
2446 void setLazyBody(uint64_t Offset) {
2447 FunctionDeclBits.HasDefaultedOrDeletedInfo = false;
2448 Body = LazyDeclStmtPtr(Offset);
2449 }
2450
2451 void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info);
2452 DefaultedOrDeletedFunctionInfo *getDefaultedOrDeletedInfo() const;
2453
2454 /// Determine the kind of defaulting that would be done for a given function.
2455 ///
2456 /// If the function is both a default constructor and a copy / move
2457 /// constructor (due to having a default argument for the first parameter),
2458 /// this picks CXXSpecialMemberKind::DefaultConstructor.
2459 ///
2460 /// FIXME: Check that case is properly handled by all callers.
2461 DefaultedFunctionKind getDefaultedFunctionKind() const;
2462
2466
2467 /// Whether this function is variadic.
2468 bool isVariadic() const;
2469
2470 /// Whether this function is marked as virtual explicitly.
2471 bool isVirtualAsWritten() const {
2472 return FunctionDeclBits.IsVirtualAsWritten;
2473 }
2474
2475 /// State that this function is marked as virtual explicitly.
2476 void setVirtualAsWritten(bool V) { FunctionDeclBits.IsVirtualAsWritten = V; }
2477
2478 /// Whether this virtual function is pure, i.e. makes the containing class
2479 /// abstract.
2480 bool isPureVirtual() const { return FunctionDeclBits.IsPureVirtual; }
2481 void setIsPureVirtual(bool P = true);
2482
2483 /// Whether this templated function will be late parsed.
2485 return FunctionDeclBits.IsLateTemplateParsed;
2486 }
2487
2488 /// State that this templated function will be late parsed.
2489 void setLateTemplateParsed(bool ILT = true) {
2490 FunctionDeclBits.IsLateTemplateParsed = ILT;
2491 }
2492
2494 return FunctionDeclBits.IsInstantiatedFromMemberTemplate;
2495 }
2497 FunctionDeclBits.IsInstantiatedFromMemberTemplate = Val;
2498 }
2499
2500 /// Whether this function is "trivial" in some specialized C++ senses.
2501 /// Can only be true for default constructors, copy constructors,
2502 /// copy assignment operators, and destructors. Not meaningful until
2503 /// the class has been fully built by Sema.
2504 bool isTrivial() const { return FunctionDeclBits.IsTrivial; }
2505 void setTrivial(bool IT) { FunctionDeclBits.IsTrivial = IT; }
2506
2507 bool isTrivialForCall() const { return FunctionDeclBits.IsTrivialForCall; }
2508 void setTrivialForCall(bool IT) { FunctionDeclBits.IsTrivialForCall = IT; }
2509
2510 /// Whether this function is defaulted. Valid for e.g.
2511 /// special member functions, defaulted comparisions (not methods!).
2512 bool isDefaulted() const { return FunctionDeclBits.IsDefaulted; }
2513 void setDefaulted(bool D = true) { FunctionDeclBits.IsDefaulted = D; }
2514
2515 /// Whether this function is explicitly defaulted.
2517 return FunctionDeclBits.IsExplicitlyDefaulted;
2518 }
2519
2520 /// State that this function is explicitly defaulted.
2521 void setExplicitlyDefaulted(bool ED = true) {
2522 FunctionDeclBits.IsExplicitlyDefaulted = ED;
2523 }
2524
2526 return isExplicitlyDefaulted() ? DefaultKWLoc : SourceLocation();
2527 }
2528
2530 assert((NewLoc.isInvalid() || isExplicitlyDefaulted()) &&
2531 "Can't set default loc is function isn't explicitly defaulted");
2532 DefaultKWLoc = NewLoc;
2533 }
2534
2535 /// True if this method is user-declared and was not
2536 /// deleted or defaulted on its first declaration.
2537 bool isUserProvided() const {
2538 auto *DeclAsWritten = this;
2540 DeclAsWritten = Pattern;
2541 return !(DeclAsWritten->isDeleted() ||
2542 DeclAsWritten->getCanonicalDecl()->isDefaulted());
2543 }
2544
2546 return FunctionDeclBits.IsIneligibleOrNotSelected;
2547 }
2549 FunctionDeclBits.IsIneligibleOrNotSelected = II;
2550 }
2551
2552 /// Whether falling off this function implicitly returns null/zero.
2553 /// If a more specific implicit return value is required, front-ends
2554 /// should synthesize the appropriate return statements.
2556 return FunctionDeclBits.HasImplicitReturnZero;
2557 }
2558
2559 /// State that falling off this function implicitly returns null/zero.
2560 /// If a more specific implicit return value is required, front-ends
2561 /// should synthesize the appropriate return statements.
2563 FunctionDeclBits.HasImplicitReturnZero = IRZ;
2564 }
2565
2566 /// Whether this function has a prototype, either because one
2567 /// was explicitly written or because it was "inherited" by merging
2568 /// a declaration without a prototype with a declaration that has a
2569 /// prototype.
2570 bool hasPrototype() const {
2572 }
2573
2574 /// Whether this function has a written prototype.
2575 bool hasWrittenPrototype() const {
2576 return FunctionDeclBits.HasWrittenPrototype;
2577 }
2578
2579 /// State that this function has a written prototype.
2580 void setHasWrittenPrototype(bool P = true) {
2581 FunctionDeclBits.HasWrittenPrototype = P;
2582 }
2583
2584 /// Whether this function inherited its prototype from a
2585 /// previous declaration.
2587 return FunctionDeclBits.HasInheritedPrototype;
2588 }
2589
2590 /// State that this function inherited its prototype from a
2591 /// previous declaration.
2592 void setHasInheritedPrototype(bool P = true) {
2593 FunctionDeclBits.HasInheritedPrototype = P;
2594 }
2595
2596 /// Whether this is a (C++11) constexpr function or constexpr constructor.
2597 bool isConstexpr() const {
2599 }
2601 FunctionDeclBits.ConstexprKind = static_cast<uint64_t>(CSK);
2602 }
2604 return static_cast<ConstexprSpecKind>(FunctionDeclBits.ConstexprKind);
2605 }
2609 bool isConsteval() const {
2611 }
2612
2614 FunctionDeclBits.BodyContainsImmediateEscalatingExpression = Set;
2615 }
2616
2618 return FunctionDeclBits.BodyContainsImmediateEscalatingExpression;
2619 }
2620
2621 bool isImmediateEscalating() const;
2622
2623 // The function is a C++ immediate function.
2624 // This can be either a consteval function, or an immediate escalating
2625 // function containing an immediate escalating expression.
2626 bool isImmediateFunction() const;
2627
2628 /// Whether the instantiation of this function is pending.
2629 /// This bit is set when the decision to instantiate this function is made
2630 /// and unset if and when the function body is created. That leaves out
2631 /// cases where instantiation did not happen because the template definition
2632 /// was not seen in this TU. This bit remains set in those cases, under the
2633 /// assumption that the instantiation will happen in some other TU.
2635 return FunctionDeclBits.InstantiationIsPending;
2636 }
2637
2638 /// State that the instantiation of this function is pending.
2639 /// (see instantiationIsPending)
2641 FunctionDeclBits.InstantiationIsPending = IC;
2642 }
2643
2644 /// Indicates the function uses __try.
2645 bool usesSEHTry() const { return FunctionDeclBits.UsesSEHTry; }
2646 void setUsesSEHTry(bool UST) { FunctionDeclBits.UsesSEHTry = UST; }
2647
2648 /// Whether this function has been deleted.
2649 ///
2650 /// A function that is "deleted" (via the C++0x "= delete" syntax)
2651 /// acts like a normal function, except that it cannot actually be
2652 /// called or have its address taken. Deleted functions are
2653 /// typically used in C++ overload resolution to attract arguments
2654 /// whose type or lvalue/rvalue-ness would permit the use of a
2655 /// different overload that would behave incorrectly. For example,
2656 /// one might use deleted functions to ban implicit conversion from
2657 /// a floating-point number to an Integer type:
2658 ///
2659 /// @code
2660 /// struct Integer {
2661 /// Integer(long); // construct from a long
2662 /// Integer(double) = delete; // no construction from float or double
2663 /// Integer(long double) = delete; // no construction from long double
2664 /// };
2665 /// @endcode
2666 // If a function is deleted, its first declaration must be.
2667 bool isDeleted() const {
2668 return getCanonicalDecl()->FunctionDeclBits.IsDeleted;
2669 }
2670
2671 bool isDeletedAsWritten() const {
2672 return FunctionDeclBits.IsDeleted && !isDefaulted();
2673 }
2674
2675 void setDeletedAsWritten(bool D = true, StringLiteral *Message = nullptr);
2676
2677 /// Determines whether this function is "main", which is the
2678 /// entry point into an executable program.
2679 bool isMain() const;
2680
2681 /// Determines whether this function is a MSVCRT user defined entry
2682 /// point.
2683 bool isMSVCRTEntryPoint() const;
2684
2685 /// Determines whether this operator new or delete is one
2686 /// of the reserved global placement operators:
2687 /// void *operator new(size_t, void *);
2688 /// void *operator new[](size_t, void *);
2689 /// void operator delete(void *, void *);
2690 /// void operator delete[](void *, void *);
2691 /// These functions have special behavior under [new.delete.placement]:
2692 /// These functions are reserved, a C++ program may not define
2693 /// functions that displace the versions in the Standard C++ library.
2694 /// The provisions of [basic.stc.dynamic] do not apply to these
2695 /// reserved placement forms of operator new and operator delete.
2696 ///
2697 /// This function must be an allocation or deallocation function.
2699
2700 /// Determines whether this function is one of the replaceable
2701 /// global allocation functions:
2702 /// \code
2703 /// void *operator new(size_t);
2704 /// void *operator new(size_t, const std::nothrow_t &) noexcept;
2705 /// void *operator new[](size_t);
2706 /// void *operator new[](size_t, const std::nothrow_t &) noexcept;
2707 /// void operator delete(void *) noexcept;
2708 /// void operator delete(void *, std::size_t) noexcept; [C++1y]
2709 /// void operator delete(void *, const std::nothrow_t &) noexcept;
2710 /// void operator delete[](void *) noexcept;
2711 /// void operator delete[](void *, std::size_t) noexcept; [C++1y]
2712 /// void operator delete[](void *, const std::nothrow_t &) noexcept;
2713 /// \endcode
2714 /// These functions have special behavior under C++1y [expr.new]:
2715 /// An implementation is allowed to omit a call to a replaceable global
2716 /// allocation function. [...]
2717 ///
2718 /// If this function is an aligned allocation/deallocation function, return
2719 /// the parameter number of the requested alignment through AlignmentParam.
2720 ///
2721 /// If this function is an allocation/deallocation function that takes
2722 /// the `std::nothrow_t` tag, return true through IsNothrow,
2724 UnsignedOrNone *AlignmentParam = nullptr,
2725 bool *IsNothrow = nullptr) const {
2727 return false;
2729 AlignmentParam, IsNothrow);
2730 }
2731
2732 /// Determines whether this function is one of the replaceable global
2733 /// allocation functions described in isReplaceableGlobalAllocationFunction,
2734 /// or is a function that may be treated as such during constant evaluation.
2735 /// This adds support for potentially templated type aware global allocation
2736 /// functions of the form:
2737 /// \code
2738 /// void *operator new(type-identity, std::size_t, std::align_val_t)
2739 /// void *operator new(type-identity, std::size_t, std::align_val_t,
2740 /// const std::nothrow_t &) noexcept;
2741 /// void *operator new[](type-identity, std::size_t, std::align_val_t)
2742 /// void *operator new[](type-identity, std::size_t, std::align_val_t,
2743 /// const std::nothrow_t &) noexcept;
2744 /// void operator delete(type-identity, void*, std::size_t,
2745 /// std::align_val_t) noexcept;
2746 /// void operator delete(type-identity, void*, std::size_t,
2747 /// std::align_val_t, const std::nothrow_t&) noexcept;
2748 /// void operator delete[](type-identity, void*, std::size_t,
2749 /// std::align_val_t) noexcept;
2750 /// void operator delete[](type-identity, void*, std::size_t,
2751 /// std::align_val_t, const std::nothrow_t&) noexcept;
2752 /// \endcode
2753 /// Where `type-identity` is a specialization of std::type_identity. If the
2754 /// declaration is a templated function, it may not include a parameter pack
2755 /// in the argument list, the type-identity parameter is required to be
2756 /// dependent, and is the only permitted dependent parameter.
2758 UnsignedOrNone *AlignmentParam = nullptr,
2759 bool *IsNothrow = nullptr) const;
2760
2761 /// Determine if this function provides an inline implementation of a builtin.
2762 bool isInlineBuiltinDeclaration() const;
2763
2764 /// Determine whether this is a destroying operator delete.
2765 bool isDestroyingOperatorDelete() const;
2766 void setIsDestroyingOperatorDelete(bool IsDestroyingDelete);
2767
2768 /// Count of mandatory parameters for type aware operator new
2769 static constexpr unsigned RequiredTypeAwareNewParameterCount =
2770 /* type-identity */ 1 + /* size */ 1 + /* alignment */ 1;
2771
2772 /// Count of mandatory parameters for type aware operator delete
2773 static constexpr unsigned RequiredTypeAwareDeleteParameterCount =
2774 /* type-identity */ 1 + /* address */ 1 + /* size */ 1 +
2775 /* alignment */ 1;
2776
2777 /// Determine whether this is a type aware operator new or delete.
2778 bool isTypeAwareOperatorNewOrDelete() const;
2779 void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator = true);
2780
2782
2783 /// Compute the language linkage.
2785
2786 /// Determines whether this function is a function with
2787 /// external, C linkage.
2788 bool isExternC() const;
2789
2790 /// Determines whether this function's context is, or is nested within,
2791 /// a C++ extern "C" linkage spec.
2792 bool isInExternCContext() const;
2793
2794 /// Determines whether this function's context is, or is nested within,
2795 /// a C++ extern "C++" linkage spec.
2796 bool isInExternCXXContext() const;
2797
2798 /// Determines whether this is a global function.
2799 bool isGlobal() const;
2800
2801 /// Determines whether this function is known to be 'noreturn', through
2802 /// an attribute on its declaration or its type.
2803 bool isNoReturn() const;
2804
2805 /// Determines whether this function is known to be 'noreturn' for analyzer,
2806 /// through an `analyzer_noreturn` attribute on its declaration.
2807 bool isAnalyzerNoReturn() const;
2808
2809 /// True if the function was a definition but its body was skipped.
2810 bool hasSkippedBody() const { return FunctionDeclBits.HasSkippedBody; }
2811 void setHasSkippedBody(bool Skipped = true) {
2812 FunctionDeclBits.HasSkippedBody = Skipped;
2813 }
2814
2815 /// True if this function will eventually have a body, once it's fully parsed.
2816 bool willHaveBody() const { return FunctionDeclBits.WillHaveBody; }
2817 void setWillHaveBody(bool V = true) { FunctionDeclBits.WillHaveBody = V; }
2818
2819 /// True if this function is considered a multiversioned function.
2820 bool isMultiVersion() const {
2821 return getCanonicalDecl()->FunctionDeclBits.IsMultiVersion;
2822 }
2823
2824 /// Sets the multiversion state for this declaration and all of its
2825 /// redeclarations.
2826 void setIsMultiVersion(bool V = true) {
2827 getCanonicalDecl()->FunctionDeclBits.IsMultiVersion = V;
2828 }
2829
2830 // Sets that this is a constrained friend where the constraint refers to an
2831 // enclosing template.
2834 ->FunctionDeclBits.FriendConstraintRefersToEnclosingTemplate = V;
2835 }
2836 // Indicates this function is a constrained friend, where the constraint
2837 // refers to an enclosing template for hte purposes of [temp.friend]p9.
2839 return getCanonicalDecl()
2840 ->FunctionDeclBits.FriendConstraintRefersToEnclosingTemplate;
2841 }
2842
2843 /// Determine whether a function is a friend function that cannot be
2844 /// redeclared outside of its class, per C++ [temp.friend]p9.
2845 bool isMemberLikeConstrainedFriend() const;
2846
2847 /// Gets the kind of multiversioning attribute this declaration has. Note that
2848 /// this can return a value even if the function is not multiversion, such as
2849 /// the case of 'target'.
2851
2852
2853 /// True if this function is a multiversioned dispatch function as a part of
2854 /// the cpu_specific/cpu_dispatch functionality.
2855 bool isCPUDispatchMultiVersion() const;
2856 /// True if this function is a multiversioned processor specific function as a
2857 /// part of the cpu_specific/cpu_dispatch functionality.
2858 bool isCPUSpecificMultiVersion() const;
2859
2860 /// True if this function is a multiversioned dispatch function as a part of
2861 /// the target functionality.
2862 bool isTargetMultiVersion() const;
2863
2864 /// True if this function is the default version of a multiversioned dispatch
2865 /// function as a part of the target functionality.
2866 bool isTargetMultiVersionDefault() const;
2867
2868 /// True if this function is a multiversioned dispatch function as a part of
2869 /// the target-clones functionality.
2870 bool isTargetClonesMultiVersion() const;
2871
2872 /// True if this function is a multiversioned dispatch function as a part of
2873 /// the target-version functionality.
2874 bool isTargetVersionMultiVersion() const;
2875
2876 /// \brief Get the associated-constraints of this function declaration.
2877 /// Currently, this will either be a vector of size 1 containing the
2878 /// trailing-requires-clause or an empty vector.
2879 ///
2880 /// Use this instead of getTrailingRequiresClause for concepts APIs that
2881 /// accept an ArrayRef of constraint expressions.
2882 void
2885 ACs.emplace_back(AC);
2886 }
2887
2888 /// Get the message that indicates why this function was deleted.
2890 return FunctionDeclBits.HasDefaultedOrDeletedInfo
2891 ? DefaultedOrDeletedInfo->getDeletedMessage()
2892 : nullptr;
2893 }
2894
2895 void setPreviousDeclaration(FunctionDecl * PrevDecl);
2896
2897 FunctionDecl *getCanonicalDecl() override;
2899 return const_cast<FunctionDecl*>(this)->getCanonicalDecl();
2900 }
2901
2902 unsigned getBuiltinID(bool ConsiderWrapperFunctions = false) const;
2903
2904 // ArrayRef interface to parameters.
2906 return {ParamInfo, getNumParams()};
2907 }
2909 return {ParamInfo, getNumParams()};
2910 }
2911
2912 // Iterator access to formal parameters.
2915
2916 bool param_empty() const { return parameters().empty(); }
2917 param_iterator param_begin() { return parameters().begin(); }
2919 param_const_iterator param_begin() const { return parameters().begin(); }
2920 param_const_iterator param_end() const { return parameters().end(); }
2921 size_t param_size() const { return parameters().size(); }
2922
2923 /// Return the number of parameters this function must have based on its
2924 /// FunctionType. This is the length of the ParamInfo array after it has been
2925 /// created.
2926 unsigned getNumParams() const;
2927
2928 /// Return the number of parameters, including the implicit 'this' parameter
2929 /// if this function has one.
2930 unsigned getNumParamsIncludingThis() const;
2931
2932 const ParmVarDecl *getParamDecl(unsigned i) const {
2933 assert(i < getNumParams() && "Illegal param #");
2934 return ParamInfo[i];
2935 }
2937 assert(i < getNumParams() && "Illegal param #");
2938 return ParamInfo[i];
2939 }
2941 setParams(getASTContext(), NewParamInfo);
2942 }
2943
2944 /// Returns the minimum number of arguments needed to call this function. This
2945 /// may be fewer than the number of function parameters, if some of the
2946 /// parameters have default arguments (in C++).
2947 unsigned getMinRequiredArguments() const;
2948
2949 /// Returns the minimum number of non-object arguments needed to call this
2950 /// function. This produces the same value as getMinRequiredArguments except
2951 /// it does not count the explicit object argument, if any.
2952 unsigned getMinRequiredExplicitArguments() const;
2953
2955
2956 unsigned getNumNonObjectParams() const;
2957
2958 const ParmVarDecl *getNonObjectParameter(unsigned I) const {
2960 }
2961
2965
2966 /// Determine whether this function has a single parameter, or multiple
2967 /// parameters where all but the first have default arguments.
2968 ///
2969 /// This notion is used in the definition of copy/move constructors and
2970 /// initializer list constructors. Note that, unlike getMinRequiredArguments,
2971 /// parameter packs are not treated specially here.
2972 bool hasOneParamOrDefaultArgs() const;
2973
2974 /// Find the source location information for how the type of this function
2975 /// was written. May be absent (for example if the function was declared via
2976 /// a typedef) and may contain a different type from that of the function
2977 /// (for example if the function type was adjusted by an attribute).
2979
2981 return getType()->castAs<FunctionType>()->getReturnType();
2982 }
2983
2984 /// Attempt to compute an informative source range covering the
2985 /// function return type. This may omit qualifiers and other information with
2986 /// limited representation in the AST.
2988
2989 /// Attempt to compute an informative source range covering the
2990 /// function parameters, including the ellipsis of a variadic function.
2991 /// The source range excludes the parentheses, and is invalid if there are
2992 /// no parameters and no ellipsis.
2994
2995 /// Get the declared return type, which may differ from the actual return
2996 /// type if the return type is deduced.
2998 auto *TSI = getTypeSourceInfo();
2999 QualType T = TSI ? TSI->getType() : getType();
3000 return T->castAs<FunctionType>()->getReturnType();
3001 }
3002
3003 /// Gets the ExceptionSpecificationType as declared.
3005 auto *TSI = getTypeSourceInfo();
3006 QualType T = TSI ? TSI->getType() : getType();
3007 const auto *FPT = T->getAs<FunctionProtoType>();
3008 return FPT ? FPT->getExceptionSpecType() : EST_None;
3009 }
3010
3011 /// Attempt to compute an informative source range covering the
3012 /// function exception specification, if any.
3014
3015 /// Determine the type of an expression that calls this function.
3020
3021 /// Returns the storage class as written in the source. For the
3022 /// computed linkage of symbol, see getLinkage.
3024 return static_cast<StorageClass>(FunctionDeclBits.SClass);
3025 }
3026
3027 /// Sets the storage class as written in the source.
3029 FunctionDeclBits.SClass = SClass;
3030 }
3031
3032 /// Determine whether the "inline" keyword was specified for this
3033 /// function.
3034 bool isInlineSpecified() const { return FunctionDeclBits.IsInlineSpecified; }
3035
3036 /// Set whether the "inline" keyword was specified for this function.
3037 void setInlineSpecified(bool I) {
3038 FunctionDeclBits.IsInlineSpecified = I;
3039 FunctionDeclBits.IsInline = I;
3040 }
3041
3042 /// Determine whether the function was declared in source context
3043 /// that requires constrained FP intrinsics
3044 bool UsesFPIntrin() const { return FunctionDeclBits.UsesFPIntrin; }
3045
3046 /// Set whether the function was declared in source context
3047 /// that requires constrained FP intrinsics
3048 void setUsesFPIntrin(bool I) { FunctionDeclBits.UsesFPIntrin = I; }
3049
3050 /// Flag that this function is implicitly inline.
3051 void setImplicitlyInline(bool I = true) { FunctionDeclBits.IsInline = I; }
3052
3053 /// Determine whether this function should be inlined, because it is
3054 /// either marked "inline" or "constexpr" or is a member function of a class
3055 /// that was defined in the class body.
3056 bool isInlined() const { return FunctionDeclBits.IsInline; }
3057
3059
3060 bool isMSExternInline() const;
3061
3063
3064 bool isStatic() const { return getStorageClass() == SC_Static; }
3065
3066 /// Whether this function declaration represents an C++ overloaded
3067 /// operator, e.g., "operator+".
3069 return getOverloadedOperator() != OO_None;
3070 }
3071
3073
3074 const IdentifierInfo *getLiteralIdentifier() const;
3075
3076 /// If this function is an instantiation of a member function
3077 /// of a class template specialization, retrieves the function from
3078 /// which it was instantiated.
3079 ///
3080 /// This routine will return non-NULL for (non-templated) member
3081 /// functions of class templates and for instantiations of function
3082 /// templates. For example, given:
3083 ///
3084 /// \code
3085 /// template<typename T>
3086 /// struct X {
3087 /// void f(T);
3088 /// };
3089 /// \endcode
3090 ///
3091 /// The declaration for X<int>::f is a (non-templated) FunctionDecl
3092 /// whose parent is the class template specialization X<int>. For
3093 /// this declaration, getInstantiatedFromFunction() will return
3094 /// the FunctionDecl X<T>::A. When a complete definition of
3095 /// X<int>::A is required, it will be instantiated from the
3096 /// declaration returned by getInstantiatedFromMemberFunction().
3098
3099 /// What kind of templated function this is.
3101
3102 /// If this function is an instantiation of a member function of a
3103 /// class template specialization, retrieves the member specialization
3104 /// information.
3106
3107 /// Specify that this record is an instantiation of the
3108 /// member function FD.
3111 setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
3112 }
3113
3114 /// Specify that this function declaration was instantiated from a
3115 /// FunctionDecl FD. This is only used if this is a function declaration
3116 /// declared locally inside of a function template.
3118
3120
3121 /// Retrieves the function template that is described by this
3122 /// function declaration.
3123 ///
3124 /// Every function template is represented as a FunctionTemplateDecl
3125 /// and a FunctionDecl (or something derived from FunctionDecl). The
3126 /// former contains template properties (such as the template
3127 /// parameter lists) while the latter contains the actual
3128 /// description of the template's
3129 /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
3130 /// FunctionDecl that describes the function template,
3131 /// getDescribedFunctionTemplate() retrieves the
3132 /// FunctionTemplateDecl from a FunctionDecl.
3134
3136
3137 /// Determine whether this function is a function template
3138 /// specialization.
3140
3141 /// If this function is actually a function template specialization,
3142 /// retrieve information about this function template specialization.
3143 /// Otherwise, returns NULL.
3145
3146 /// Determines whether this function is a function template
3147 /// specialization or a member of a class template specialization that can
3148 /// be implicitly instantiated.
3149 bool isImplicitlyInstantiable() const;
3150
3151 /// Determines if the given function was instantiated from a
3152 /// function template.
3153 bool isTemplateInstantiation() const;
3154
3155 /// Retrieve the function declaration from which this function could
3156 /// be instantiated, if it is an instantiation (rather than a non-template
3157 /// or a specialization, for example).
3158 ///
3159 /// If \p ForDefinition is \c false, explicit specializations will be treated
3160 /// as if they were implicit instantiations. This will then find the pattern
3161 /// corresponding to non-definition portions of the declaration, such as
3162 /// default arguments and the exception specification.
3163 FunctionDecl *
3164 getTemplateInstantiationPattern(bool ForDefinition = true) const;
3165
3166 /// Retrieve the primary template that this function template
3167 /// specialization either specializes or was instantiated from.
3168 ///
3169 /// If this function declaration is not a function template specialization,
3170 /// returns NULL.
3172
3173 /// Retrieve the template arguments used to produce this function
3174 /// template specialization from the primary template.
3175 ///
3176 /// If this function declaration is not a function template specialization,
3177 /// returns NULL.
3179
3180 /// Retrieve the template argument list as written in the sources,
3181 /// if any.
3182 ///
3183 /// If this function declaration is not a function template specialization
3184 /// or if it had no explicit template argument list, returns NULL.
3185 /// Note that it an explicit template argument list may be written empty,
3186 /// e.g., template<> void foo<>(char* s);
3189
3190 /// Specify that this function declaration is actually a function
3191 /// template specialization.
3192 ///
3193 /// \param Template the function template that this function template
3194 /// specialization specializes.
3195 ///
3196 /// \param TemplateArgs the template arguments that produced this
3197 /// function template specialization from the template.
3198 ///
3199 /// \param InsertToken If set, the insert token in the function template
3200 /// specialization set where the function template specialization data will
3201 /// be inserted.
3202 ///
3203 /// \param TSK the kind of template specialization this is.
3204 ///
3205 /// \param TemplateArgsAsWritten location info of template arguments.
3206 ///
3207 /// \param PointOfInstantiation point at which the function template
3208 /// specialization was first instantiated.
3211 llvm::FoldingSetInsertToken InsertToken,
3213 TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
3214 SourceLocation PointOfInstantiation = SourceLocation()) {
3215 setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
3216 InsertToken, TSK, TemplateArgsAsWritten,
3217 PointOfInstantiation);
3218 }
3219
3220 /// Specifies that this function declaration is actually a
3221 /// dependent function template specialization.
3223 ASTContext &Context, const UnresolvedSetImpl &Templates,
3224 const TemplateArgumentListInfo *TemplateArgs);
3225
3228
3229 /// Determine what kind of template instantiation this function
3230 /// represents.
3232
3233 /// Determine the kind of template specialization this function represents
3234 /// for the purpose of template instantiation.
3237
3238 /// Determine what kind of template instantiation this function
3239 /// represents.
3241 SourceLocation PointOfInstantiation = SourceLocation());
3242
3243 /// True if both __host__ and __device__ are implicit attributes and this is
3244 /// (or is a member of) an explicit template instantiation.
3246
3247 /// Retrieve the (first) point of instantiation of a function template
3248 /// specialization or a member of a class template specialization.
3249 ///
3250 /// \returns the first point of instantiation, if this function was
3251 /// instantiated from a template; otherwise, returns an invalid source
3252 /// location.
3254
3255 /// Determine whether this is or was instantiated from an out-of-line
3256 /// definition of a member function.
3257 bool isOutOfLine() const override;
3258
3259 /// Identify a memory copying or setting function.
3260 /// If the given function is a memory copy or setting function, returns
3261 /// the corresponding Builtin ID. If the function is not a memory function,
3262 /// returns 0.
3263 unsigned getMemoryFunctionKind() const;
3264
3265 /// Returns ODRHash of the function. This value is calculated and
3266 /// stored on first call, then the stored value returned on the other calls.
3267 unsigned getODRHash();
3268
3269 /// Returns cached ODRHash of the function. This must have been previously
3270 /// computed and stored.
3271 unsigned getODRHash() const;
3272
3274 // Effects may differ between declarations, but they should be propagated
3275 // from old to new on any redeclaration, so it suffices to look at
3276 // getMostRecentDecl().
3277 if (const auto *FPT =
3278 getMostRecentDecl()->getType()->getAs<FunctionProtoType>())
3279 return FPT->getFunctionEffects();
3280 return {};
3281 }
3282
3283 // Implement isa/cast/dyncast/etc.
3284 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3285 static bool classofKind(Kind K) {
3286 return K >= firstFunction && K <= lastFunction;
3287 }
3289 return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
3290 }
3292 return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
3293 }
3294
3295 bool isReferenceableKernel() const;
3296};
3297
3298/// Represents a member of a struct/union/class.
3299class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
3300 /// The kinds of value we can store in StorageKind.
3301 ///
3302 /// Note that this is compatible with InClassInitStyle except for
3303 /// ISK_CapturedVLAType.
3304 enum InitStorageKind {
3305 /// If the pointer is null, there's nothing special. Otherwise,
3306 /// this is a bitfield and the pointer is the Expr* storing the
3307 /// bit-width.
3308 ISK_NoInit = (unsigned) ICIS_NoInit,
3309
3310 /// The pointer is an (optional due to delayed parsing) Expr*
3311 /// holding the copy-initializer.
3312 ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
3313
3314 /// The pointer is an (optional due to delayed parsing) Expr*
3315 /// holding the list-initializer.
3316 ISK_InClassListInit = (unsigned) ICIS_ListInit,
3317
3318 /// The pointer is a VariableArrayType* that's been captured;
3319 /// the enclosing context is a lambda or captured statement.
3320 ISK_CapturedVLAType,
3321 };
3322
3323 LLVM_PREFERRED_TYPE(bool)
3324 unsigned BitField : 1;
3325 LLVM_PREFERRED_TYPE(bool)
3326 unsigned Mutable : 1;
3327 LLVM_PREFERRED_TYPE(InitStorageKind)
3328 unsigned StorageKind : 2;
3329 mutable unsigned CachedFieldIndex : 28;
3330
3331 /// If this is a bitfield with a default member initializer, this
3332 /// structure is used to represent the two expressions.
3333 struct InitAndBitWidthStorage {
3335 Expr *BitWidth;
3336 };
3337
3338 /// Storage for either the bit-width, the in-class initializer, or
3339 /// both (via InitAndBitWidth), or the captured variable length array bound.
3340 ///
3341 /// If the storage kind is ISK_InClassCopyInit or
3342 /// ISK_InClassListInit, but the initializer is null, then this
3343 /// field has an in-class initializer that has not yet been parsed
3344 /// and attached.
3345 // FIXME: Tail-allocate this to reduce the size of FieldDecl in the
3346 // overwhelmingly common case that we have none of these things.
3347 union {
3348 // Active member if ISK is not ISK_CapturedVLAType and BitField is false.
3350 // Active member if ISK is ISK_NoInit and BitField is true.
3352 // Active member if ISK is ISK_InClass*Init and BitField is true.
3353 InitAndBitWidthStorage *InitAndBitWidth;
3354 // Active member if ISK is ISK_CapturedVLAType.
3356 };
3357
3358protected:
3360 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
3361 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3362 InClassInitStyle InitStyle)
3363 : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), BitField(false),
3364 Mutable(Mutable), StorageKind((InitStorageKind)InitStyle),
3365 CachedFieldIndex(0), Init() {
3366 if (BW)
3367 setBitWidth(BW);
3368 }
3369
3370public:
3371 friend class ASTDeclReader;
3372 friend class ASTDeclWriter;
3373
3374 static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
3375 SourceLocation StartLoc, SourceLocation IdLoc,
3376 const IdentifierInfo *Id, QualType T,
3377 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3378 InClassInitStyle InitStyle);
3379
3381
3382 /// Returns the index of this field within its record,
3383 /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
3384 unsigned getFieldIndex() const {
3385 const FieldDecl *Canonical = getCanonicalDecl();
3386 if (Canonical->CachedFieldIndex == 0) {
3387 Canonical->setCachedFieldIndex();
3388 assert(Canonical->CachedFieldIndex != 0);
3389 }
3390 return Canonical->CachedFieldIndex - 1;
3391 }
3392
3393private:
3394 /// Set CachedFieldIndex to the index of this field plus one.
3395 void setCachedFieldIndex() const;
3396
3397public:
3398 /// Determines whether this field is mutable (C++ only).
3399 bool isMutable() const { return Mutable; }
3400
3401 /// Determines whether this field is a bitfield.
3402 bool isBitField() const { return BitField; }
3403
3404 /// Determines whether this is an unnamed bitfield.
3405 bool isUnnamedBitField() const { return isBitField() && !getDeclName(); }
3406
3407 /// Determines whether this field is a
3408 /// representative for an anonymous struct or union. Such fields are
3409 /// unnamed and are implicitly generated by the implementation to
3410 /// store the data for the anonymous union or struct.
3411 bool isAnonymousStructOrUnion() const;
3412
3413 /// Returns the expression that represents the bit width, if this field
3414 /// is a bit field. For non-bitfields, this returns \c nullptr.
3416 if (!BitField)
3417 return nullptr;
3418 return hasInClassInitializer() ? InitAndBitWidth->BitWidth : BitWidth;
3419 }
3420
3421 /// Determines whether the bit width of this field is a constant integer.
3422 /// This may not always be the case, such as inside template-dependent
3423 /// expressions.
3424 bool hasConstantIntegerBitWidth() const;
3425
3426 /// Computes the bit width of this field, if this is a bit field.
3427 /// May not be called on non-bitfields.
3428 /// Note that in order to successfully use this function, the bitwidth
3429 /// expression must be a ConstantExpr with a valid integer result set.
3430 unsigned getBitWidthValue() const;
3431
3432 /// Set the bit-field width for this member.
3433 // Note: used by some clients (i.e., do not remove it).
3434 void setBitWidth(Expr *Width) {
3435 assert(!hasCapturedVLAType() && !BitField &&
3436 "bit width or captured type already set");
3437 assert(Width && "no bit width specified");
3440 new (getASTContext()) InitAndBitWidthStorage{Init, Width};
3441 else
3442 BitWidth = Width;
3443 BitField = true;
3444 }
3445
3446 /// Remove the bit-field width from this member.
3447 // Note: used by some clients (i.e., do not remove it).
3449 assert(isBitField() && "no bitfield width to remove");
3450 if (hasInClassInitializer()) {
3451 // Read the old initializer before we change the active union member.
3452 auto ExistingInit = InitAndBitWidth->Init;
3453 Init = ExistingInit;
3454 }
3455 BitField = false;
3456 }
3457
3458 /// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
3459 /// at all and instead act as a separator between contiguous runs of other
3460 /// bit-fields.
3461 bool isZeroLengthBitField() const;
3462
3463 /// Determine if this field is a subobject of zero size, that is, either a
3464 /// zero-length bit-field or a field of empty class type with the
3465 /// [[no_unique_address]] attribute.
3466 bool isZeroSize(const ASTContext &Ctx) const;
3467
3468 /// Determine if this field is of potentially-overlapping class type, that
3469 /// is, subobject with the [[no_unique_address]] attribute
3470 bool isPotentiallyOverlapping() const;
3471
3472 /// Get the kind of (C++11) default member initializer that this field has.
3474 return (StorageKind == ISK_CapturedVLAType ? ICIS_NoInit
3475 : (InClassInitStyle)StorageKind);
3476 }
3477
3478 /// Determine whether this member has a C++11 default member initializer.
3480 return getInClassInitStyle() != ICIS_NoInit;
3481 }
3482
3483 /// Determine whether getInClassInitializer() would return a non-null pointer
3484 /// without deserializing the initializer.
3486 return hasInClassInitializer() && (BitField ? InitAndBitWidth->Init : Init);
3487 }
3488
3489 /// Get the C++11 default member initializer for this member, or null if one
3490 /// has not been set. If a valid declaration has a default member initializer,
3491 /// but this returns null, then we have not parsed and attached it yet.
3492 Expr *getInClassInitializer() const;
3493
3494 /// Set the C++11 in-class initializer for this member.
3495 void setInClassInitializer(Expr *NewInit);
3496
3497 /// Find the FieldDecl specified in a FAM's "counted_by" attribute. Returns
3498 /// \p nullptr if either the attribute or the field doesn't exist.
3499 const FieldDecl *findCountedByField() const;
3500
3501private:
3502 void setLazyInClassInitializer(LazyDeclStmtPtr NewInit);
3503
3504public:
3505 /// Remove the C++11 in-class initializer from this member.
3507 assert(hasInClassInitializer() && "no initializer to remove");
3508 StorageKind = ISK_NoInit;
3509 if (BitField) {
3510 // Read the bit width before we change the active union member.
3511 Expr *ExistingBitWidth = InitAndBitWidth->BitWidth;
3512 BitWidth = ExistingBitWidth;
3513 }
3514 }
3515
3516 /// Determine whether this member captures the variable length array
3517 /// type.
3518 bool hasCapturedVLAType() const {
3519 return StorageKind == ISK_CapturedVLAType;
3520 }
3521
3522 /// Get the captured variable length array type.
3524 return hasCapturedVLAType() ? CapturedVLAType : nullptr;
3525 }
3526
3527 /// Set the captured variable length array type for this field.
3528 void setCapturedVLAType(const VariableArrayType *VLAType);
3529
3530 /// Returns the parent of this field declaration, which
3531 /// is the struct in which this field is defined.
3532 ///
3533 /// Returns null if this is not a normal class/struct field declaration, e.g.
3534 /// ObjCAtDefsFieldDecl, ObjCIvarDecl.
3535 const RecordDecl *getParent() const {
3536 return dyn_cast<RecordDecl>(getDeclContext());
3537 }
3538
3540 return dyn_cast<RecordDecl>(getDeclContext());
3541 }
3542
3543 SourceRange getSourceRange() const override LLVM_READONLY;
3544
3545 /// Retrieves the canonical declaration of this field.
3546 FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3547 const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3548
3549 // Implement isa/cast/dyncast/etc.
3550 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3551 static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
3552
3553 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
3554};
3555
3556/// An instance of this object exists for each enum constant
3557/// that is defined. For example, in "enum X {a,b}", each of a/b are
3558/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
3559/// TagType for the X EnumDecl.
3561 public Mergeable<EnumConstantDecl>,
3562 public APIntStorage {
3563 Stmt *Init; // an integer constant expression
3564 bool IsUnsigned;
3565
3566protected:
3568 IdentifierInfo *Id, QualType T, Expr *E,
3569 const llvm::APSInt &V);
3570
3571public:
3572 friend class StmtIteratorBase;
3573
3576 QualType T, Expr *E,
3577 const llvm::APSInt &V);
3579
3580 const Expr *getInitExpr() const { return (const Expr*) Init; }
3581 Expr *getInitExpr() { return (Expr*) Init; }
3582 llvm::APSInt getInitVal() const {
3583 return llvm::APSInt(getValue(), IsUnsigned);
3584 }
3585
3586 void setInitExpr(Expr *E) { Init = (Stmt*) E; }
3587 void setInitVal(const ASTContext &C, const llvm::APSInt &V) {
3588 setValue(C, V);
3589 IsUnsigned = V.isUnsigned();
3590 }
3591
3592 SourceRange getSourceRange() const override LLVM_READONLY;
3593
3594 /// Retrieves the canonical declaration of this enumerator.
3597
3598 // Implement isa/cast/dyncast/etc.
3599 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3600 static bool classofKind(Kind K) { return K == EnumConstant; }
3601};
3602
3603/// Represents a field injected from an anonymous union/struct into the parent
3604/// scope. These are always implicit.
3605class IndirectFieldDecl : public ValueDecl,
3606 public Mergeable<IndirectFieldDecl> {
3607 NamedDecl **Chaining;
3608 unsigned ChainingSize;
3609
3610 IndirectFieldDecl(ASTContext &C, DeclContext *DC, SourceLocation L,
3613
3614 void anchor() override;
3615
3616public:
3617 friend class ASTDeclReader;
3618
3619 static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC,
3620 SourceLocation L, const IdentifierInfo *Id,
3622
3623 static IndirectFieldDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3624
3626
3627 ArrayRef<NamedDecl *> chain() const { return {Chaining, ChainingSize}; }
3628 chain_iterator chain_begin() const { return chain().begin(); }
3629 chain_iterator chain_end() const { return chain().end(); }
3630
3631 unsigned getChainingSize() const { return ChainingSize; }
3632
3634 assert(chain().size() >= 2);
3635 return cast<FieldDecl>(chain().back());
3636 }
3637
3639 assert(chain().size() >= 2);
3640 return dyn_cast<VarDecl>(chain().front());
3641 }
3642
3643 IndirectFieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3644 const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3645
3646 // Implement isa/cast/dyncast/etc.
3647 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3648 static bool classofKind(Kind K) { return K == IndirectField; }
3649};
3650
3651/// Represents a declaration of a type.
3652class TypeDecl : public NamedDecl {
3653 friend class ASTContext;
3654 friend class ASTReader;
3655
3656 /// This indicates the Type object that represents
3657 /// this TypeDecl. It is a cache maintained by
3658 /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
3659 /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
3660 mutable const Type *TypeForDecl = nullptr;
3661
3662 /// The start of the source range for this declaration.
3663 SourceLocation LocStart;
3664
3665 void anchor() override;
3666
3667protected:
3669 SourceLocation StartL = SourceLocation())
3670 : NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
3671
3672public:
3673 // Low-level accessor. If you just want the type defined by this node,
3674 // check out ASTContext::getTypeDeclType or one of
3675 // ASTContext::getTypedefType, ASTContext::getTagType, etc. if you
3676 // already know the specific kind of node this is.
3677 const Type *getTypeForDecl() const {
3678 assert(!isa<TagDecl>(this));
3679 return TypeForDecl;
3680 }
3681 void setTypeForDecl(const Type *TD) {
3682 assert(!isa<TagDecl>(this));
3683 TypeForDecl = TD;
3684 }
3685
3686 SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
3687 void setLocStart(SourceLocation L) { LocStart = L; }
3688 SourceRange getSourceRange() const override LLVM_READONLY {
3689 if (LocStart.isValid())
3690 return SourceRange(LocStart, getLocation());
3691 else
3692 return SourceRange(getLocation());
3693 }
3694
3695 // Implement isa/cast/dyncast/etc.
3696 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3697 static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
3698};
3699
3700/// Base class for declarations which introduce a typedef-name.
3701class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
3702 struct alignas(8) ModedTInfo {
3703 TypeSourceInfo *first;
3704 QualType second;
3705 };
3706
3707 /// If int part is 0, we have not computed IsTransparentTag.
3708 /// Otherwise, IsTransparentTag is (getInt() >> 1).
3709 mutable llvm::PointerIntPair<
3710 llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
3711 MaybeModedTInfo;
3712
3713 void anchor() override;
3714
3715protected:
3717 SourceLocation StartLoc, SourceLocation IdLoc,
3718 const IdentifierInfo *Id, TypeSourceInfo *TInfo)
3719 : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
3720 MaybeModedTInfo(TInfo, 0) {}
3721
3723
3727
3729 return getPreviousDecl();
3730 }
3731
3733 return getMostRecentDecl();
3734 }
3735
3736public:
3738 using redecl_iterator = redeclarable_base::redecl_iterator;
3739
3746
3747 bool isModed() const {
3748 return isa<ModedTInfo *>(MaybeModedTInfo.getPointer());
3749 }
3750
3752 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->first
3753 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer());
3754 }
3755
3757 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->second
3758 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer())
3759 ->getType();
3760 }
3761
3763 MaybeModedTInfo.setPointer(newType);
3764 }
3765
3767 MaybeModedTInfo.setPointer(new (getASTContext(), 8)
3768 ModedTInfo({unmodedTSI, modedTy}));
3769 }
3770
3771 /// Retrieves the canonical declaration of this typedef-name.
3773 const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
3774
3775 /// Retrieves the tag declaration for which this is the typedef name for
3776 /// linkage purposes, if any.
3777 ///
3778 /// \param AnyRedecl Look for the tag declaration in any redeclaration of
3779 /// this typedef declaration.
3780 TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
3781
3782 /// Determines if this typedef shares a name and spelling location with its
3783 /// underlying tag type, as is the case with the NS_ENUM macro.
3784 bool isTransparentTag() const {
3785 if (MaybeModedTInfo.getInt())
3786 return MaybeModedTInfo.getInt() & 0x2;
3787 return isTransparentTagSlow();
3788 }
3789
3790 // These types are created lazily, use the ASTContext methods to obtain them.
3791 const Type *getTypeForDecl() const = delete;
3792 void setTypeForDecl(const Type *TD) = delete;
3793
3794 // Implement isa/cast/dyncast/etc.
3795 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3796 static bool classofKind(Kind K) {
3797 return K >= firstTypedefName && K <= lastTypedefName;
3798 }
3799
3800private:
3801 bool isTransparentTagSlow() const;
3802};
3803
3804/// Represents the declaration of a typedef-name via the 'typedef'
3805/// type specifier.
3806class TypedefDecl : public TypedefNameDecl {
3807 TypedefDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3808 SourceLocation IdLoc, const IdentifierInfo *Id,
3809 TypeSourceInfo *TInfo)
3810 : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
3811
3812public:
3813 static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
3814 SourceLocation StartLoc, SourceLocation IdLoc,
3815 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3816 static TypedefDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3817
3818 SourceRange getSourceRange() const override LLVM_READONLY;
3819
3820 // Implement isa/cast/dyncast/etc.
3821 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3822 static bool classofKind(Kind K) { return K == Typedef; }
3823};
3824
3825/// Represents the declaration of a typedef-name via a C++11
3826/// alias-declaration.
3827class TypeAliasDecl : public TypedefNameDecl {
3828 /// The template for which this is the pattern, if any.
3829 TypeAliasTemplateDecl *Template;
3830
3831 TypeAliasDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3832 SourceLocation IdLoc, const IdentifierInfo *Id,
3833 TypeSourceInfo *TInfo)
3834 : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
3835 Template(nullptr) {}
3836
3837public:
3838 static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
3839 SourceLocation StartLoc, SourceLocation IdLoc,
3840 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3841 static TypeAliasDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3842
3843 SourceRange getSourceRange() const override LLVM_READONLY;
3844
3847
3848 // Implement isa/cast/dyncast/etc.
3849 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3850 static bool classofKind(Kind K) { return K == TypeAlias; }
3851};
3852
3853/// Represents the declaration of a struct/union/class/enum.
3854class TagDecl : public TypeDecl,
3855 public DeclContext,
3856 public Redeclarable<TagDecl> {
3857 // This class stores some data in DeclContext::TagDeclBits
3858 // to save some space. Use the provided accessors to access it.
3859public:
3860 // This is really ugly.
3862
3863private:
3864 SourceRange BraceRange;
3865
3866 // A struct representing syntactic qualifier info,
3867 // to be used for the (uncommon) case of out-of-line declarations.
3868 using ExtInfo = QualifierInfo;
3869
3870 /// If the (out-of-line) tag declaration name
3871 /// is qualified, it points to the qualifier info (nns and range);
3872 /// otherwise, if the tag declaration is anonymous and it is part of
3873 /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
3874 /// otherwise, if the tag declaration is anonymous and it is used as a
3875 /// declaration specifier for variables, it points to the first VarDecl (used
3876 /// for mangling);
3877 /// otherwise, it is a null (TypedefNameDecl) pointer.
3878 llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3879
3880 bool hasExtInfo() const { return isa<ExtInfo *>(TypedefNameDeclOrQualifier); }
3881 ExtInfo *getExtInfo() { return cast<ExtInfo *>(TypedefNameDeclOrQualifier); }
3882 const ExtInfo *getExtInfo() const {
3883 return cast<ExtInfo *>(TypedefNameDeclOrQualifier);
3884 }
3885
3886protected:
3887 TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3888 SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3889 SourceLocation StartL);
3890
3892
3894 return getNextRedeclaration();
3895 }
3896
3898 return getPreviousDecl();
3899 }
3900
3902 return getMostRecentDecl();
3903 }
3904
3905 /// Completes the definition of this tag declaration.
3906 ///
3907 /// This is a helper function for derived classes.
3908 void completeDefinition();
3909
3910 /// True if this decl is currently being defined.
3911 void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; }
3912
3913 void printAnonymousTagDecl(llvm::raw_ostream &OS,
3914 const PrintingPolicy &Policy) const;
3915
3916 void printAnonymousTagDeclLocation(llvm::raw_ostream &OS,
3917 const PrintingPolicy &Policy) const;
3918
3919public:
3920 friend class ASTDeclReader;
3921 friend class ASTDeclWriter;
3922
3924 using redecl_iterator = redeclarable_base::redecl_iterator;
3925
3932
3933 SourceRange getBraceRange() const { return BraceRange; }
3934 void setBraceRange(SourceRange R) { BraceRange = R; }
3935
3936 /// Return SourceLocation representing start of source
3937 /// range ignoring outer template declarations.
3939
3940 /// Return SourceLocation representing start of source
3941 /// range taking into account any outer template declarations.
3943 SourceRange getSourceRange() const override LLVM_READONLY;
3944
3945 TagDecl *getCanonicalDecl() override;
3946 const TagDecl *getCanonicalDecl() const {
3947 return const_cast<TagDecl*>(this)->getCanonicalDecl();
3948 }
3949
3950 /// Return true if this declaration is a completion definition of the type.
3951 /// Provided for consistency.
3953 return isCompleteDefinition();
3954 }
3955
3956 /// Return true if this decl has its body fully specified.
3957 bool isCompleteDefinition() const { return TagDeclBits.IsCompleteDefinition; }
3958
3959 /// True if this decl has its body fully specified.
3960 void setCompleteDefinition(bool V = true) {
3961 TagDeclBits.IsCompleteDefinition = V;
3962 }
3963
3964 /// Return true if this complete decl is
3965 /// required to be complete for some existing use.
3967 return TagDeclBits.IsCompleteDefinitionRequired;
3968 }
3969
3970 /// True if this complete decl is
3971 /// required to be complete for some existing use.
3973 TagDeclBits.IsCompleteDefinitionRequired = V;
3974 }
3975
3976 /// Return true if this decl is currently being defined.
3977 bool isBeingDefined() const { return TagDeclBits.IsBeingDefined; }
3978
3979 /// True if this tag declaration is "embedded" (i.e., defined or declared
3980 /// for the very first time) in the syntax of a declarator.
3982 return TagDeclBits.IsEmbeddedInDeclarator;
3983 }
3984
3985 /// True if this tag declaration is "embedded" (i.e., defined or declared
3986 /// for the very first time) in the syntax of a declarator.
3987 void setEmbeddedInDeclarator(bool isInDeclarator) {
3988 TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator;
3989 }
3990
3991 /// True if this tag is free standing, e.g. "struct foo;".
3992 bool isFreeStanding() const { return TagDeclBits.IsFreeStanding; }
3993
3994 /// True if this tag is free standing, e.g. "struct foo;".
3996 TagDeclBits.IsFreeStanding = isFreeStanding;
3997 }
3998
3999 /// Whether this declaration declares a type that is
4000 /// dependent, i.e., a type that somehow depends on template
4001 /// parameters.
4002 bool isDependentType() const { return isDependentContext(); }
4003
4004 /// Whether this declaration was a definition in some module but was forced
4005 /// to be a declaration.
4006 ///
4007 /// Useful for clients checking if a module has a definition of a specific
4008 /// symbol and not interested in the final AST with deduplicated definitions.
4010 return TagDeclBits.IsThisDeclarationADemotedDefinition;
4011 }
4012
4013 /// Mark a definition as a declaration and maintain information it _was_
4014 /// a definition.
4016 assert(isCompleteDefinition() &&
4017 "Should demote definitions only, not forward declarations");
4018 setCompleteDefinition(false);
4019 TagDeclBits.IsThisDeclarationADemotedDefinition = true;
4020 }
4021
4022 /// Starts the definition of this tag declaration.
4023 ///
4024 /// This method should be invoked at the beginning of the definition
4025 /// of this tag declaration. It will set the tag type into a state
4026 /// where it is in the process of being defined.
4027 void startDefinition();
4028
4029 /// Returns the TagDecl that actually defines this
4030 /// struct/union/class/enum. When determining whether or not a
4031 /// struct/union/class/enum has a definition, one should use this
4032 /// method as opposed to 'isDefinition'. 'isDefinition' indicates
4033 /// whether or not a specific TagDecl is defining declaration, not
4034 /// whether or not the struct/union/class/enum type is defined.
4035 /// This method returns NULL if there is no TagDecl that defines
4036 /// the struct/union/class/enum.
4037 TagDecl *getDefinition() const;
4038
4040 if (TagDecl *Def = getDefinition())
4041 return Def;
4042 return const_cast<TagDecl *>(this);
4043 }
4044
4045 /// Determines whether this entity is in the process of being defined.
4047 if (const TagDecl *Def = getDefinition())
4048 return Def->isBeingDefined();
4049 return false;
4050 }
4051
4052 StringRef getKindName() const {
4054 }
4055
4057 return static_cast<TagKind>(TagDeclBits.TagDeclKind);
4058 }
4059
4061 TagDeclBits.TagDeclKind = llvm::to_underlying(TK);
4062 }
4063
4064 bool isStruct() const { return getTagKind() == TagTypeKind::Struct; }
4065 bool isInterface() const { return getTagKind() == TagTypeKind::Interface; }
4066 bool isClass() const { return getTagKind() == TagTypeKind::Class; }
4067 bool isUnion() const { return getTagKind() == TagTypeKind::Union; }
4068 bool isEnum() const { return getTagKind() == TagTypeKind::Enum; }
4069
4070 bool isStructureOrClass() const {
4071 return isStruct() || isClass() || isInterface();
4072 }
4073
4074 /// Is this tag type named, either directly or via being defined in
4075 /// a typedef of this type?
4076 ///
4077 /// C++11 [basic.link]p8:
4078 /// A type is said to have linkage if and only if:
4079 /// - it is a class or enumeration type that is named (or has a
4080 /// name for linkage purposes) and the name has linkage; ...
4081 /// C++11 [dcl.typedef]p9:
4082 /// If the typedef declaration defines an unnamed class (or enum),
4083 /// the first typedef-name declared by the declaration to be that
4084 /// class type (or enum type) is used to denote the class type (or
4085 /// enum type) for linkage purposes only.
4086 ///
4087 /// C does not have an analogous rule, but the same concept is
4088 /// nonetheless useful in some places.
4089 bool hasNameForLinkage() const {
4090 return (getDeclName() || getTypedefNameForAnonDecl());
4091 }
4092
4094 return hasExtInfo() ? nullptr
4095 : cast<TypedefNameDecl *>(TypedefNameDeclOrQualifier);
4096 }
4097
4099
4100 /// Retrieve the nested-name-specifier that qualifies the name of this
4101 /// declaration, if it was present in the source.
4103 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
4104 : std::nullopt;
4105 }
4106
4107 /// Retrieve the nested-name-specifier (with source-location
4108 /// information) that qualifies the name of this declaration, if it was
4109 /// present in the source.
4111 return hasExtInfo() ? getExtInfo()->QualifierLoc
4113 }
4114
4115 void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
4116
4118 if (!hasExtInfo())
4119 return {};
4120 return {/*data=*/getExtInfo()->TemplParamLists,
4121 /*length=*/getExtInfo()->NumTemplParamLists};
4122 }
4123
4124 // These types are created lazily, use the ASTContext methods to obtain them.
4125 const Type *getTypeForDecl() const = delete;
4126 void setTypeForDecl(const Type *TD) = delete;
4127
4128 using TypeDecl::printName;
4129 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
4130
4133
4134 // Implement isa/cast/dyncast/etc.
4135 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4136 static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
4137
4139 return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
4140 }
4141
4143 return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
4144 }
4145};
4146
4147/// Represents an enum. In C++11, enums can be forward-declared
4148/// with a fixed underlying type, and in C we allow them to be forward-declared
4149/// with no underlying type as an extension.
4150class EnumDecl : public TagDecl {
4151 // This class stores some data in DeclContext::EnumDeclBits
4152 // to save some space. Use the provided accessors to access it.
4153
4154 /// This represent the integer type that the enum corresponds
4155 /// to for code generation purposes. Note that the enumerator constants may
4156 /// have a different type than this does.
4157 ///
4158 /// If the underlying integer type was explicitly stated in the source
4159 /// code, this is a TypeSourceInfo* for that type. Otherwise this type
4160 /// was automatically deduced somehow, and this is a Type*.
4161 ///
4162 /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
4163 /// some cases it won't.
4164 ///
4165 /// The underlying type of an enumeration never has any qualifiers, so
4166 /// we can get away with just storing a raw Type*, and thus save an
4167 /// extra pointer when TypeSourceInfo is needed.
4168 llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
4169
4170 /// The integer type that values of this type should
4171 /// promote to. In C, enumerators are generally of an integer type
4172 /// directly, but gcc-style large enumerators (and all enumerators
4173 /// in C++) are of the enum type instead.
4174 QualType PromotionType;
4175
4176 /// If this enumeration is an instantiation of a member enumeration
4177 /// of a class template specialization, this is the member specialization
4178 /// information.
4179 MemberSpecializationInfo *SpecializationInfo = nullptr;
4180
4181 /// Store the ODRHash after first calculation.
4182 /// The corresponding flag HasODRHash is in EnumDeclBits
4183 /// and can be accessed with the provided accessors.
4184 unsigned ODRHash;
4185
4186 /// Source range covering the enum key:
4187 /// - 'enum' (unscoped)
4188 /// - 'enum class|struct' (scoped)
4189 SourceRange EnumKeyRange;
4190
4191 EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
4192 SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
4193 bool Scoped, bool ScopedUsingClassTag, bool Fixed);
4194
4195 void anchor() override;
4196
4197 void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
4199
4200 /// Sets the width in bits required to store all the
4201 /// non-negative enumerators of this enum.
4202 void setNumPositiveBits(unsigned Num) {
4203 EnumDeclBits.NumPositiveBits = Num;
4204 assert(EnumDeclBits.NumPositiveBits == Num && "can't store this bitcount");
4205 }
4206
4207 /// Returns the width in bits required to store all the
4208 /// negative enumerators of this enum. (see getNumNegativeBits)
4209 void setNumNegativeBits(unsigned Num) { EnumDeclBits.NumNegativeBits = Num; }
4210
4211public:
4212 /// True if this tag declaration is a scoped enumeration. Only
4213 /// possible in C++11 mode.
4214 void setScoped(bool Scoped = true) { EnumDeclBits.IsScoped = Scoped; }
4215
4216 /// If this tag declaration is a scoped enum,
4217 /// then this is true if the scoped enum was declared using the class
4218 /// tag, false if it was declared with the struct tag. No meaning is
4219 /// associated if this tag declaration is not a scoped enum.
4220 void setScopedUsingClassTag(bool ScopedUCT = true) {
4221 EnumDeclBits.IsScopedUsingClassTag = ScopedUCT;
4222 }
4223
4224 /// True if this is an Objective-C, C++11, or
4225 /// Microsoft-style enumeration with a fixed underlying type.
4226 void setFixed(bool Fixed = true) { EnumDeclBits.IsFixed = Fixed; }
4227
4228 SourceRange getEnumKeyRange() const { return EnumKeyRange; }
4229
4230 void setEnumKeyRange(SourceRange Range) { EnumKeyRange = Range; }
4231
4232private:
4233 /// True if a valid hash is stored in ODRHash.
4234 bool hasODRHash() const { return EnumDeclBits.HasODRHash; }
4235 void setHasODRHash(bool Hash = true) { EnumDeclBits.HasODRHash = Hash; }
4236
4237public:
4238 friend class ASTDeclReader;
4239
4240 EnumDecl *getCanonicalDecl() override {
4242 }
4243 const EnumDecl *getCanonicalDecl() const {
4244 return const_cast<EnumDecl*>(this)->getCanonicalDecl();
4245 }
4246
4247 EnumDecl *getPreviousDecl() {
4248 return cast_or_null<EnumDecl>(
4249 static_cast<TagDecl *>(this)->getPreviousDecl());
4250 }
4251 const EnumDecl *getPreviousDecl() const {
4252 return const_cast<EnumDecl*>(this)->getPreviousDecl();
4253 }
4254
4255 EnumDecl *getMostRecentDecl() {
4256 return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
4257 }
4258 const EnumDecl *getMostRecentDecl() const {
4259 return const_cast<EnumDecl*>(this)->getMostRecentDecl();
4260 }
4261
4262 EnumDecl *getDefinition() const {
4263 return cast_or_null<EnumDecl>(TagDecl::getDefinition());
4264 }
4265
4266 EnumDecl *getDefinitionOrSelf() const {
4267 return cast_or_null<EnumDecl>(TagDecl::getDefinitionOrSelf());
4268 }
4269
4270 static EnumDecl *Create(ASTContext &C, DeclContext *DC,
4271 SourceLocation StartLoc, SourceLocation IdLoc,
4272 IdentifierInfo *Id, EnumDecl *PrevDecl,
4273 bool IsScoped, bool IsScopedUsingClassTag,
4274 bool IsFixed);
4276
4277 /// Overrides to provide correct range when there's an enum-base specifier
4278 /// with forward declarations.
4279 SourceRange getSourceRange() const override LLVM_READONLY;
4280
4281 /// When created, the EnumDecl corresponds to a
4282 /// forward-declared enum. This method is used to mark the
4283 /// declaration as being defined; its enumerators have already been
4284 /// added (via DeclContext::addDecl). NewType is the new underlying
4285 /// type of the enumeration type.
4286 void completeDefinition(QualType NewType,
4287 QualType PromotionType,
4288 unsigned NumPositiveBits,
4289 unsigned NumNegativeBits);
4290
4291 // Iterates through the enumerators of this enumeration.
4295
4299
4301 const EnumDecl *E = getDefinition();
4302 if (!E)
4303 E = this;
4304 return enumerator_iterator(E->decls_begin());
4305 }
4306
4308 const EnumDecl *E = getDefinition();
4309 if (!E)
4310 E = this;
4311 return enumerator_iterator(E->decls_end());
4312 }
4313
4314 /// Return the integer type that enumerators should promote to.
4315 QualType getPromotionType() const { return PromotionType; }
4316
4317 /// Set the promotion type.
4318 void setPromotionType(QualType T) { PromotionType = T; }
4319
4320 /// Return the integer type this enum decl corresponds to.
4321 /// This returns a null QualType for an enum forward definition with no fixed
4322 /// underlying type.
4324 if (!IntegerType)
4325 return QualType();
4326 if (const Type *T = dyn_cast<const Type *>(IntegerType))
4327 return QualType(T, 0);
4328 return cast<TypeSourceInfo *>(IntegerType)->getType().getUnqualifiedType();
4329 }
4330
4331 /// Set the underlying integer type.
4332 void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
4333
4334 /// Set the underlying integer type source info.
4335 void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
4336
4337 /// Return the type source info for the underlying integer type,
4338 /// if no type source info exists, return 0.
4340 return dyn_cast_if_present<TypeSourceInfo *>(IntegerType);
4341 }
4342
4343 /// Retrieve the source range that covers the underlying type if
4344 /// specified.
4345 SourceRange getIntegerTypeRange() const LLVM_READONLY;
4346
4347 /// Returns the width in bits required to store all the
4348 /// non-negative enumerators of this enum.
4349 unsigned getNumPositiveBits() const { return EnumDeclBits.NumPositiveBits; }
4350
4351 /// Returns the width in bits required to store all the
4352 /// negative enumerators of this enum. These widths include
4353 /// the rightmost leading 1; that is:
4354 ///
4355 /// MOST NEGATIVE ENUMERATOR PATTERN NUM NEGATIVE BITS
4356 /// ------------------------ ------- -----------------
4357 /// -1 1111111 1
4358 /// -10 1110110 5
4359 /// -101 1001011 8
4360 unsigned getNumNegativeBits() const { return EnumDeclBits.NumNegativeBits; }
4361
4362 /// Calculates the [Min,Max) values the enum can store based on the
4363 /// NumPositiveBits and NumNegativeBits. This matters for enums that do not
4364 /// have a fixed underlying type.
4365 void getValueRange(llvm::APInt &Max, llvm::APInt &Min) const;
4366
4367 /// Returns true if this is a C++11 scoped enumeration.
4368 bool isScoped() const { return EnumDeclBits.IsScoped; }
4369
4370 /// Returns true if this is a C++11 scoped enumeration.
4372 return EnumDeclBits.IsScopedUsingClassTag;
4373 }
4374
4375 /// Returns true if this is an Objective-C, C++11, or
4376 /// Microsoft-style enumeration with a fixed underlying type.
4377 bool isFixed() const { return EnumDeclBits.IsFixed; }
4378
4379 unsigned getODRHash();
4380
4381 /// Returns true if this can be considered a complete type.
4382 bool isComplete() const {
4383 // IntegerType is set for fixed type enums and non-fixed but implicitly
4384 // int-sized Microsoft enums.
4385 return isCompleteDefinition() || IntegerType;
4386 }
4387
4388 /// Returns true if this enum is either annotated with
4389 /// enum_extensibility(closed) or isn't annotated with enum_extensibility.
4390 bool isClosed() const;
4391
4392 /// Returns true if this enum is annotated with flag_enum and isn't annotated
4393 /// with enum_extensibility(open).
4394 bool isClosedFlag() const;
4395
4396 /// Returns true if this enum is annotated with neither flag_enum nor
4397 /// enum_extensibility(open).
4398 bool isClosedNonFlag() const;
4399
4400 /// Retrieve the enum definition from which this enumeration could
4401 /// be instantiated, if it is an instantiation (rather than a non-template).
4403
4404 /// Returns the enumeration (declared within the template)
4405 /// from which this enumeration type was instantiated, or NULL if
4406 /// this enumeration was not instantiated from any template.
4408
4409 /// If this enumeration is a member of a specialization of a
4410 /// templated class, determine what kind of template specialization
4411 /// or instantiation this is.
4413
4414 /// For an enumeration member that was instantiated from a member
4415 /// enumeration of a templated class, set the template specialiation kind.
4417 SourceLocation PointOfInstantiation = SourceLocation());
4418
4419 /// If this enumeration is an instantiation of a member enumeration of
4420 /// a class template specialization, retrieves the member specialization
4421 /// information.
4423 return SpecializationInfo;
4424 }
4425
4426 /// Specify that this enumeration is an instantiation of the
4427 /// member enumeration ED.
4430 setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
4431 }
4432
4433 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4434 static bool classofKind(Kind K) { return K == Enum; }
4435};
4436
4437/// Enum that represents the different ways arguments are passed to and
4438/// returned from function calls. This takes into account the target-specific
4439/// and version-specific rules along with the rules determined by the
4440/// language.
4442 /// The argument of this type can be passed directly in registers.
4444
4445 /// The argument of this type cannot be passed directly in registers.
4446 /// Records containing this type as a subobject are not forced to be passed
4447 /// indirectly. This value is used only in C++. This value is required by
4448 /// C++ because, in uncommon situations, it is possible for a class to have
4449 /// only trivial copy/move constructors even when one of its subobjects has
4450 /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
4451 /// constructor in the derived class is deleted).
4453
4454 /// The argument of this type cannot be passed directly in registers.
4455 /// Records containing this type as a subobject are forced to be passed
4456 /// indirectly.
4458};
4459
4460/// Represents a struct/union/class. For example:
4461/// struct X; // Forward declaration, no "body".
4462/// union Y { int A, B; }; // Has body with members A and B (FieldDecls).
4463/// This decl will be marked invalid if *any* members are invalid.
4464class RecordDecl : public TagDecl {
4465 // This class stores some data in DeclContext::RecordDeclBits
4466 // to save some space. Use the provided accessors to access it.
4467public:
4468 friend class DeclContext;
4469 friend class ASTDeclReader;
4470
4471protected:
4472 RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
4473 SourceLocation StartLoc, SourceLocation IdLoc,
4474 IdentifierInfo *Id, RecordDecl *PrevDecl);
4475
4476public:
4477 static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
4478 SourceLocation StartLoc, SourceLocation IdLoc,
4479 IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
4481
4483 return cast_or_null<RecordDecl>(
4484 static_cast<TagDecl *>(this)->getPreviousDecl());
4485 }
4487 return const_cast<RecordDecl*>(this)->getPreviousDecl();
4488 }
4489
4491 return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
4492 }
4494 return const_cast<RecordDecl*>(this)->getMostRecentDecl();
4495 }
4496
4498 return RecordDeclBits.HasFlexibleArrayMember;
4499 }
4500
4502 RecordDeclBits.HasFlexibleArrayMember = V;
4503 }
4504
4505 /// Whether this is an anonymous struct or union. To be an anonymous
4506 /// struct or union, it must have been declared without a name and
4507 /// there must be no objects of this type declared, e.g.,
4508 /// @code
4509 /// union { int i; float f; };
4510 /// @endcode
4511 /// is an anonymous union but neither of the following are:
4512 /// @code
4513 /// union X { int i; float f; };
4514 /// union { int i; float f; } obj;
4515 /// @endcode
4517 return RecordDeclBits.AnonymousStructOrUnion;
4518 }
4519
4521 RecordDeclBits.AnonymousStructOrUnion = Anon;
4522 }
4523
4524 bool hasObjectMember() const { return RecordDeclBits.HasObjectMember; }
4525 void setHasObjectMember(bool val) { RecordDeclBits.HasObjectMember = val; }
4526
4527 bool hasVolatileMember() const { return RecordDeclBits.HasVolatileMember; }
4528
4529 void setHasVolatileMember(bool val) {
4530 RecordDeclBits.HasVolatileMember = val;
4531 }
4532
4534 return RecordDeclBits.LoadedFieldsFromExternalStorage;
4535 }
4536
4538 RecordDeclBits.LoadedFieldsFromExternalStorage = val;
4539 }
4540
4541 /// Functions to query basic properties of non-trivial C structs.
4543 return RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize;
4544 }
4545
4547 RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize = V;
4548 }
4549
4551 return RecordDeclBits.NonTrivialToPrimitiveCopy;
4552 }
4553
4555 RecordDeclBits.NonTrivialToPrimitiveCopy = V;
4556 }
4557
4559 return RecordDeclBits.NonTrivialToPrimitiveDestroy;
4560 }
4561
4563 RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
4564 }
4565
4567 return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion;
4568 }
4569
4571 RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V;
4572 }
4573
4575 return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion;
4576 }
4577
4579 RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V;
4580 }
4581
4583 return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion;
4584 }
4585
4587 RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V;
4588 }
4589
4591 return RecordDeclBits.HasUninitializedExplicitInitFields;
4592 }
4593
4595 RecordDeclBits.HasUninitializedExplicitInitFields = V;
4596 }
4597
4598 /// Determine whether this class can be passed in registers. In C++ mode,
4599 /// it must have at least one trivial, non-deleted copy or move constructor.
4600 /// FIXME: This should be set as part of completeDefinition.
4604
4606 return static_cast<RecordArgPassingKind>(
4607 RecordDeclBits.ArgPassingRestrictions);
4608 }
4609
4611 RecordDeclBits.ArgPassingRestrictions = llvm::to_underlying(Kind);
4612 }
4613
4615 return RecordDeclBits.ParamDestroyedInCallee;
4616 }
4617
4619 RecordDeclBits.ParamDestroyedInCallee = V;
4620 }
4621
4622 bool isRandomized() const { return RecordDeclBits.IsRandomized; }
4623
4624 void setIsRandomized(bool V) { RecordDeclBits.IsRandomized = V; }
4625
4626 void reorderDecls(const SmallVectorImpl<Decl *> &Decls);
4627
4628 /// Determine whether this record is a class describing a lambda
4629 /// function object.
4630 bool isLambda() const;
4631
4632 /// Determine whether this record is a record for captured variables in
4633 /// CapturedStmt construct.
4634 bool isCapturedRecord() const;
4635
4636 /// Mark the record as a record for captured variables in CapturedStmt
4637 /// construct.
4638 void setCapturedRecord();
4639
4640 /// Returns the RecordDecl that actually defines
4641 /// this struct/union/class. When determining whether or not a
4642 /// struct/union/class is completely defined, one should use this
4643 /// method as opposed to 'isCompleteDefinition'.
4644 /// 'isCompleteDefinition' indicates whether or not a specific
4645 /// RecordDecl is a completed definition, not whether or not the
4646 /// record type is defined. This method returns NULL if there is
4647 /// no RecordDecl that defines the struct/union/tag.
4649 return cast_or_null<RecordDecl>(TagDecl::getDefinition());
4650 }
4651
4653 return cast_or_null<RecordDecl>(TagDecl::getDefinitionOrSelf());
4654 }
4655
4656 /// Returns whether this record is a union, or contains (at any nesting level)
4657 /// a union member. This is used by CMSE to warn about possible information
4658 /// leaks.
4659 bool isOrContainsUnion() const;
4660
4661 // Iterator access to field members. The field iterator only visits
4662 // the non-static data members of this class, ignoring any static
4663 // data members, functions, constructors, destructors, etc.
4665 using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
4666
4669
4671 return field_iterator(decl_iterator());
4672 }
4673
4674 // Whether there are any fields (non-static data members) in this record.
4675 bool field_empty() const {
4676 return field_begin() == field_end();
4677 }
4678
4679 /// Returns the number of fields (non-static data members) in this record.
4680 unsigned getNumFields() const {
4681 return std::distance(field_begin(), field_end());
4682 }
4683
4684 /// noload_fields - Iterate over the fields stored in this record
4685 /// that are currently loaded; don't attempt to retrieve anything
4686 /// from an external source.
4690
4695
4696 // Whether there are any fields (non-static data members) in this record.
4697 bool noload_field_empty() const {
4699 }
4700
4701 /// Note that the definition of this type is now complete.
4702 virtual void completeDefinition();
4703
4704 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4705 static bool classofKind(Kind K) {
4706 return K >= firstRecord && K <= lastRecord;
4707 }
4708
4709 /// Get whether or not this is an ms_struct which can
4710 /// be turned on with an attribute, pragma, or -mms-bitfields
4711 /// commandline option.
4712 bool isMsStruct(const ASTContext &C) const;
4713
4714 /// Whether we are allowed to insert extra padding between fields.
4715 /// These padding are added to help AddressSanitizer detect
4716 /// intra-object-overflow bugs.
4717 bool mayInsertExtraPadding(bool EmitRemark = false) const;
4718
4719 /// Finds the first data member which has a name.
4720 /// nullptr is returned if no named data member exists.
4721 const FieldDecl *findFirstNamedDataMember() const;
4722
4723 /// Get precomputed ODRHash or add a new one.
4724 unsigned getODRHash();
4725
4726private:
4727 /// Deserialize just the fields.
4728 void LoadFieldsFromExternalStorage() const;
4729
4730 /// True if a valid hash is stored in ODRHash.
4731 bool hasODRHash() const { return RecordDeclBits.ODRHash; }
4732 void setODRHash(unsigned Hash) { RecordDeclBits.ODRHash = Hash; }
4733};
4734
4735class FileScopeAsmDecl : public Decl {
4736 Expr *AsmString;
4737 SourceLocation RParenLoc;
4738
4739 FileScopeAsmDecl(DeclContext *DC, Expr *asmstring, SourceLocation StartL,
4740 SourceLocation EndL)
4741 : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
4742
4743 virtual void anchor();
4744
4745public:
4746 static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC, Expr *Str,
4747 SourceLocation AsmLoc,
4748 SourceLocation RParenLoc);
4749
4750 static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4751
4753 SourceLocation getRParenLoc() const { return RParenLoc; }
4754 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4755 SourceRange getSourceRange() const override LLVM_READONLY {
4756 return SourceRange(getAsmLoc(), getRParenLoc());
4757 }
4758
4759 const Expr *getAsmStringExpr() const { return AsmString; }
4760 Expr *getAsmStringExpr() { return AsmString; }
4761 void setAsmString(Expr *Asm) { AsmString = Asm; }
4762
4763 std::string getAsmString() const;
4764
4765 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4766 static bool classofKind(Kind K) { return K == FileScopeAsm; }
4767};
4768
4769/// A declaration that models statements at global scope. This declaration
4770/// supports incremental and interactive C/C++.
4771///
4772/// \note This is used in libInterpreter, clang -cc1 -fincremental-extensions
4773/// and in tools such as clang-repl.
4774class TopLevelStmtDecl : public Decl, public DeclContext {
4775 friend class ASTDeclReader;
4776 friend class ASTDeclWriter;
4777
4778 Stmt *Statement = nullptr;
4779 bool IsSemiMissing = false;
4780 /// Position among all top-level statements of the session, in parse order.
4781 unsigned Ordinal = 0;
4782
4783 TopLevelStmtDecl(DeclContext *DC, SourceLocation L, Stmt *S)
4784 : Decl(TopLevelStmt, DC, L), DeclContext(TopLevelStmt), Statement(S) {}
4785
4786 virtual void anchor();
4787
4788public:
4789 static TopLevelStmtDecl *Create(ASTContext &C, Stmt *Statement);
4791
4792 SourceRange getSourceRange() const override LLVM_READONLY;
4793 Stmt *getStmt() { return Statement; }
4794 const Stmt *getStmt() const { return Statement; }
4795 void setStmt(Stmt *S);
4796 bool isSemiMissing() const { return IsSemiMissing; }
4797 void setSemiMissing(bool Missing = true) { IsSemiMissing = Missing; }
4798 unsigned getOrdinal() const { return Ordinal; }
4799
4800 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4801 static bool classofKind(Kind K) { return K == TopLevelStmt; }
4802
4803 static DeclContext *castToDeclContext(const TopLevelStmtDecl *D) {
4804 return static_cast<DeclContext *>(const_cast<TopLevelStmtDecl *>(D));
4805 }
4806 static TopLevelStmtDecl *castFromDeclContext(const DeclContext *DC) {
4807 return static_cast<TopLevelStmtDecl *>(const_cast<DeclContext *>(DC));
4808 }
4809};
4810
4811/// Represents a block literal declaration, which is like an
4812/// unnamed FunctionDecl. For example:
4813/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
4814class BlockDecl : public Decl, public DeclContext {
4815 // This class stores some data in DeclContext::BlockDeclBits
4816 // to save some space. Use the provided accessors to access it.
4817public:
4818 /// A class which contains all the information about a particular
4819 /// captured value.
4820 class Capture {
4821 enum {
4822 flag_isByRef = 0x1,
4823 flag_isNested = 0x2
4824 };
4825
4826 /// The variable being captured.
4827 llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
4828
4829 /// The copy expression, expressed in terms of a DeclRef (or
4830 /// BlockDeclRef) to the captured variable. Only required if the
4831 /// variable has a C++ class type.
4832 Expr *CopyExpr;
4833
4834 public:
4835 Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
4836 : VariableAndFlags(variable,
4837 (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
4838 CopyExpr(copy) {}
4839
4840 /// The variable being captured.
4841 VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
4842
4843 /// Whether this is a "by ref" capture, i.e. a capture of a __block
4844 /// variable.
4845 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
4846
4847 bool isEscapingByref() const {
4848 return getVariable()->isEscapingByref();
4849 }
4850
4851 bool isNonEscapingByref() const {
4852 return getVariable()->isNonEscapingByref();
4853 }
4854
4855 /// Whether this is a nested capture, i.e. the variable captured
4856 /// is not from outside the immediately enclosing function/block.
4857 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
4858
4859 bool hasCopyExpr() const { return CopyExpr != nullptr; }
4860 Expr *getCopyExpr() const { return CopyExpr; }
4861 void setCopyExpr(Expr *e) { CopyExpr = e; }
4862 };
4863
4864private:
4865 /// A new[]'d array of pointers to ParmVarDecls for the formal
4866 /// parameters of this function. This is null if a prototype or if there are
4867 /// no formals.
4868 ParmVarDecl **ParamInfo = nullptr;
4869 unsigned NumParams = 0;
4870
4871 Stmt *Body = nullptr;
4872 TypeSourceInfo *SignatureAsWritten = nullptr;
4873
4874 const Capture *Captures = nullptr;
4875 unsigned NumCaptures = 0;
4876
4877 unsigned ManglingNumber = 0;
4878 Decl *ManglingContextDecl = nullptr;
4879
4880protected:
4881 BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
4882
4883public:
4886
4888
4889 bool isVariadic() const { return BlockDeclBits.IsVariadic; }
4890 void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; }
4891
4892 CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
4893 Stmt *getBody() const override { return (Stmt*) Body; }
4894 void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
4895
4896 void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
4897 TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
4898
4899 // ArrayRef access to formal parameters.
4901 return {ParamInfo, getNumParams()};
4902 }
4904 return {ParamInfo, getNumParams()};
4905 }
4906
4907 // Iterator access to formal parameters.
4910
4911 bool param_empty() const { return parameters().empty(); }
4912 param_iterator param_begin() { return parameters().begin(); }
4914 param_const_iterator param_begin() const { return parameters().begin(); }
4915 param_const_iterator param_end() const { return parameters().end(); }
4916 size_t param_size() const { return parameters().size(); }
4917
4918 unsigned getNumParams() const { return NumParams; }
4919
4920 const ParmVarDecl *getParamDecl(unsigned i) const {
4921 assert(i < getNumParams() && "Illegal param #");
4922 return ParamInfo[i];
4923 }
4925 assert(i < getNumParams() && "Illegal param #");
4926 return ParamInfo[i];
4927 }
4928
4929 void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
4930
4931 /// True if this block (or its nested blocks) captures
4932 /// anything of local storage from its enclosing scopes.
4933 bool hasCaptures() const { return NumCaptures || capturesCXXThis(); }
4934
4935 /// Returns the number of captured variables.
4936 /// Does not include an entry for 'this'.
4937 unsigned getNumCaptures() const { return NumCaptures; }
4938
4940
4941 ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; }
4942
4943 capture_const_iterator capture_begin() const { return captures().begin(); }
4944 capture_const_iterator capture_end() const { return captures().end(); }
4945
4946 bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
4947 void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
4948
4950 return BlockDeclBits.BlockMissingReturnType;
4951 }
4952
4953 void setBlockMissingReturnType(bool val = true) {
4954 BlockDeclBits.BlockMissingReturnType = val;
4955 }
4956
4958 return BlockDeclBits.IsConversionFromLambda;
4959 }
4960
4961 void setIsConversionFromLambda(bool val = true) {
4962 BlockDeclBits.IsConversionFromLambda = val;
4963 }
4964
4965 bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
4966 void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
4967
4968 bool canAvoidCopyToHeap() const {
4969 return BlockDeclBits.CanAvoidCopyToHeap;
4970 }
4971 void setCanAvoidCopyToHeap(bool B = true) {
4972 BlockDeclBits.CanAvoidCopyToHeap = B;
4973 }
4974
4975 bool capturesVariable(const VarDecl *var) const;
4976
4977 void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
4978 bool CapturesCXXThis);
4979
4980 unsigned getBlockManglingNumber() const { return ManglingNumber; }
4981
4982 Decl *getBlockManglingContextDecl() const { return ManglingContextDecl; }
4983
4984 void setBlockMangling(unsigned Number, Decl *Ctx) {
4985 ManglingNumber = Number;
4986 ManglingContextDecl = Ctx;
4987 }
4988
4989 SourceRange getSourceRange() const override LLVM_READONLY;
4990
4992 if (const TypeSourceInfo *TSI = getSignatureAsWritten())
4993 if (const auto *FPT = TSI->getType()->getAs<FunctionProtoType>())
4994 return FPT->getFunctionEffects();
4995 return {};
4996 }
4997
4998 // Implement isa/cast/dyncast/etc.
4999 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5000 static bool classofKind(Kind K) { return K == Block; }
5002 return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
5003 }
5005 return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
5006 }
5007};
5008
5009/// Represents a partial function definition.
5010///
5011/// An outlined function declaration contains the parameters and body of
5012/// a function independent of other function definition concerns such
5013/// as function name, type, and calling convention. Such declarations may
5014/// be used to hold a parameterized and transformed sequence of statements
5015/// used to generate a target dependent function definition without losing
5016/// association with the original statements. See SYCLKernelCallStmt as an
5017/// example.
5018class OutlinedFunctionDecl final
5019 : public Decl,
5020 public DeclContext,
5021 private llvm::TrailingObjects<OutlinedFunctionDecl, ImplicitParamDecl *> {
5022private:
5023 /// The number of parameters to the outlined function.
5024 unsigned NumParams;
5025
5026 /// The body of the outlined function.
5027 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
5028
5029 explicit OutlinedFunctionDecl(DeclContext *DC, unsigned NumParams);
5030
5031 ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }
5032
5033 ImplicitParamDecl **getParams() { return getTrailingObjects(); }
5034
5035public:
5036 friend class ASTDeclReader;
5037 friend class ASTDeclWriter;
5039
5040 static OutlinedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
5041 unsigned NumParams);
5042 static OutlinedFunctionDecl *
5043 CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams);
5044
5045 Stmt *getBody() const override;
5046 void setBody(Stmt *B);
5047
5048 bool isNothrow() const;
5049 void setNothrow(bool Nothrow = true);
5050
5051 unsigned getNumParams() const { return NumParams; }
5052
5053 ImplicitParamDecl *getParam(unsigned i) const {
5054 assert(i < NumParams);
5055 return getParams()[i];
5056 }
5057 void setParam(unsigned i, ImplicitParamDecl *P) {
5058 assert(i < NumParams);
5059 getParams()[i] = P;
5060 }
5061
5062 // Range interface to parameters.
5064 using parameter_const_range = llvm::iterator_range<parameter_const_iterator>;
5066 return {param_begin(), param_end()};
5067 }
5068 parameter_const_iterator param_begin() const { return getParams(); }
5069 parameter_const_iterator param_end() const { return getParams() + NumParams; }
5070
5071 // Implement isa/cast/dyncast/etc.
5072 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5073 static bool classofKind(Kind K) { return K == OutlinedFunction; }
5074 static DeclContext *castToDeclContext(const OutlinedFunctionDecl *D) {
5075 return static_cast<DeclContext *>(const_cast<OutlinedFunctionDecl *>(D));
5076 }
5077 static OutlinedFunctionDecl *castFromDeclContext(const DeclContext *DC) {
5078 return static_cast<OutlinedFunctionDecl *>(const_cast<DeclContext *>(DC));
5079 }
5080};
5081
5082/// Represents the body of a CapturedStmt, and serves as its DeclContext.
5083class CapturedDecl final
5084 : public Decl,
5085 public DeclContext,
5086 private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
5087protected:
5088 size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
5089 return NumParams;
5090 }
5091
5092private:
5093 /// The number of parameters to the outlined function.
5094 unsigned NumParams;
5095
5096 /// The position of context parameter in list of parameters.
5097 unsigned ContextParam;
5098
5099 /// The body of the outlined function.
5100 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
5101
5102 explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
5103
5104 ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }
5105
5106 ImplicitParamDecl **getParams() { return getTrailingObjects(); }
5107
5108public:
5109 friend class ASTDeclReader;
5110 friend class ASTDeclWriter;
5112
5113 static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
5114 unsigned NumParams);
5115 static CapturedDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
5116 unsigned NumParams);
5117
5118 Stmt *getBody() const override;
5119 void setBody(Stmt *B);
5120
5121 bool isNothrow() const;
5122 void setNothrow(bool Nothrow = true);
5123
5124 unsigned getNumParams() const { return NumParams; }
5125
5126 ImplicitParamDecl *getParam(unsigned i) const {
5127 assert(i < NumParams);
5128 return getParams()[i];
5129 }
5130 void setParam(unsigned i, ImplicitParamDecl *P) {
5131 assert(i < NumParams);
5132 getParams()[i] = P;
5133 }
5134
5135 // ArrayRef interface to parameters.
5137 return {getParams(), getNumParams()};
5138 }
5140 return {getParams(), getNumParams()};
5141 }
5142
5143 /// Retrieve the parameter containing captured variables.
5145 assert(ContextParam < NumParams);
5146 return getParam(ContextParam);
5147 }
5148 void setContextParam(unsigned i, ImplicitParamDecl *P) {
5149 assert(i < NumParams);
5150 ContextParam = i;
5151 setParam(i, P);
5152 }
5153 unsigned getContextParamPosition() const { return ContextParam; }
5154
5156 using param_range = llvm::iterator_range<param_iterator>;
5157
5158 /// Retrieve an iterator pointing to the first parameter decl.
5159 param_iterator param_begin() const { return getParams(); }
5160 /// Retrieve an iterator one past the last parameter decl.
5161 param_iterator param_end() const { return getParams() + NumParams; }
5162
5163 // Implement isa/cast/dyncast/etc.
5164 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5165 static bool classofKind(Kind K) { return K == Captured; }
5166 static DeclContext *castToDeclContext(const CapturedDecl *D) {
5167 return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
5168 }
5169 static CapturedDecl *castFromDeclContext(const DeclContext *DC) {
5170 return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
5171 }
5172};
5173
5174/// Describes a module import declaration, which makes the contents
5175/// of the named module visible in the current translation unit.
5176///
5177/// An import declaration imports the named module (or submodule). For example:
5178/// \code
5179/// @import std.vector;
5180/// \endcode
5181///
5182/// A C++20 module import declaration imports the named module or partition.
5183/// Periods are permitted in C++20 module names, but have no semantic meaning.
5184/// For example:
5185/// \code
5186/// import NamedModule;
5187/// import :SomePartition; // Must be a partition of the current module.
5188/// import Names.Like.this; // Allowed.
5189/// import :and.Also.Partition.names;
5190/// \endcode
5191///
5192/// Import declarations can also be implicitly generated from
5193/// \#include/\#import directives.
5194class ImportDecl final : public Decl,
5195 llvm::TrailingObjects<ImportDecl, SourceLocation> {
5196 friend class ASTContext;
5197 friend class ASTDeclReader;
5198 friend class ASTReader;
5199 friend TrailingObjects;
5200
5201 /// The imported module.
5202 Module *ImportedModule = nullptr;
5203
5204 /// The next import in the list of imports local to the translation
5205 /// unit being parsed (not loaded from an AST file).
5206 ///
5207 /// Includes a bit that indicates whether we have source-location information
5208 /// for each identifier in the module name.
5209 ///
5210 /// When the bit is false, we only have a single source location for the
5211 /// end of the import declaration.
5212 llvm::PointerIntPair<ImportDecl *, 1, bool> NextLocalImportAndComplete;
5213
5214 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
5215 ArrayRef<SourceLocation> IdentifierLocs);
5216
5217 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
5218 SourceLocation EndLoc);
5219
5220 ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
5221
5222 bool isImportComplete() const { return NextLocalImportAndComplete.getInt(); }
5223
5224 void setImportComplete(bool C) { NextLocalImportAndComplete.setInt(C); }
5225
5226 /// The next import in the list of imports local to the translation
5227 /// unit being parsed (not loaded from an AST file).
5228 ImportDecl *getNextLocalImport() const {
5229 return NextLocalImportAndComplete.getPointer();
5230 }
5231
5232 void setNextLocalImport(ImportDecl *Import) {
5233 NextLocalImportAndComplete.setPointer(Import);
5234 }
5235
5236public:
5237 /// Create a new module import declaration.
5238 static ImportDecl *Create(ASTContext &C, DeclContext *DC,
5239 SourceLocation StartLoc, Module *Imported,
5240 ArrayRef<SourceLocation> IdentifierLocs);
5241
5242 /// Create a new module import declaration for an implicitly-generated
5243 /// import.
5244 static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
5245 SourceLocation StartLoc, Module *Imported,
5246 SourceLocation EndLoc);
5247
5248 /// Create a new, deserialized module import declaration.
5249 static ImportDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
5250 unsigned NumLocations);
5251
5252 /// Retrieve the module that was imported by the import declaration.
5253 Module *getImportedModule() const { return ImportedModule; }
5254
5255 /// Retrieves the locations of each of the identifiers that make up
5256 /// the complete module name in the import declaration.
5257 ///
5258 /// This will return an empty array if the locations of the individual
5259 /// identifiers aren't available.
5261
5262 SourceRange getSourceRange() const override LLVM_READONLY;
5263
5264 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5265 static bool classofKind(Kind K) { return K == Import; }
5266};
5267
5268/// Represents a standard C++ module export declaration.
5269///
5270/// For example:
5271/// \code
5272/// export void foo();
5273/// \endcode
5274class ExportDecl final : public Decl, public DeclContext {
5275 LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
5276
5277private:
5278 friend class ASTDeclReader;
5279
5280 /// The source location for the right brace (if valid).
5281 SourceLocation RBraceLoc;
5282
5283 ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
5284 : Decl(Export, DC, ExportLoc), DeclContext(Export),
5285 RBraceLoc(SourceLocation()) {}
5286
5287public:
5289 SourceLocation ExportLoc);
5291
5293 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5294 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
5295
5296 bool hasBraces() const { return RBraceLoc.isValid(); }
5297
5298 SourceLocation getEndLoc() const LLVM_READONLY {
5299 if (hasBraces())
5300 return RBraceLoc;
5301 // No braces: get the end location of the (only) declaration in context
5302 // (if present).
5303 return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
5304 }
5305
5306 SourceRange getSourceRange() const override LLVM_READONLY {
5307 return SourceRange(getLocation(), getEndLoc());
5308 }
5309
5310 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5311 static bool classofKind(Kind K) { return K == Export; }
5312 static DeclContext *castToDeclContext(const ExportDecl *D) {
5313 return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
5314 }
5315 static ExportDecl *castFromDeclContext(const DeclContext *DC) {
5316 return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
5317 }
5318};
5319
5320/// Represents an empty-declaration.
5321class EmptyDecl : public Decl {
5322 EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {}
5323
5324 virtual void anchor();
5325
5326public:
5327 static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
5328 SourceLocation L);
5329 static EmptyDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
5330
5331 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5332 static bool classofKind(Kind K) { return K == Empty; }
5333};
5334
5335/// HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
5336class HLSLBufferDecl final : public NamedDecl, public DeclContext {
5337 /// LBraceLoc - The ending location of the source range.
5338 SourceLocation LBraceLoc;
5339 /// RBraceLoc - The ending location of the source range.
5340 SourceLocation RBraceLoc;
5341 /// KwLoc - The location of the cbuffer or tbuffer keyword.
5342 SourceLocation KwLoc;
5343 /// IsCBuffer - Whether the buffer is a cbuffer (and not a tbuffer).
5344 bool IsCBuffer;
5345 /// HasValidPackoffset - Whether the buffer has valid packoffset annotations
5346 // on all declarations
5347 bool HasValidPackoffset;
5348 // LayoutStruct - Layout struct for the buffer
5349 CXXRecordDecl *LayoutStruct;
5350
5351 // For default (implicit) constant buffer, an array of references of global
5352 // decls that belong to the buffer. The decls are already parented by the
5353 // translation unit context. The array is allocated by the ASTContext
5354 // allocator in HLSLBufferDecl::CreateDefaultCBuffer.
5355 ArrayRef<Decl *> DefaultBufferDecls;
5356
5357 HLSLBufferDecl(DeclContext *DC, bool CBuffer, SourceLocation KwLoc,
5358 IdentifierInfo *ID, SourceLocation IDLoc,
5359 SourceLocation LBrace);
5360
5361 void setDefaultBufferDecls(ArrayRef<Decl *> Decls);
5362
5363public:
5364 static HLSLBufferDecl *Create(ASTContext &C, DeclContext *LexicalParent,
5365 bool CBuffer, SourceLocation KwLoc,
5366 IdentifierInfo *ID, SourceLocation IDLoc,
5367 SourceLocation LBrace);
5368 static HLSLBufferDecl *
5370 ArrayRef<Decl *> DefaultCBufferDecls);
5371 static HLSLBufferDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
5372
5373 SourceRange getSourceRange() const override LLVM_READONLY {
5374 return SourceRange(getLocStart(), RBraceLoc);
5375 }
5376 SourceLocation getLocStart() const LLVM_READONLY { return KwLoc; }
5377 SourceLocation getLBraceLoc() const { return LBraceLoc; }
5378 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5379 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
5380 bool isCBuffer() const { return IsCBuffer; }
5381 void setHasValidPackoffset(bool PO) { HasValidPackoffset = PO; }
5382 bool hasValidPackoffset() const { return HasValidPackoffset; }
5383 const CXXRecordDecl *getLayoutStruct() const { return LayoutStruct; }
5385
5386 // Implement isa/cast/dyncast/etc.
5387 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5388 static bool classofKind(Kind K) { return K == HLSLBuffer; }
5389 static DeclContext *castToDeclContext(const HLSLBufferDecl *D) {
5390 return static_cast<DeclContext *>(const_cast<HLSLBufferDecl *>(D));
5391 }
5392 static HLSLBufferDecl *castFromDeclContext(const DeclContext *DC) {
5393 return static_cast<HLSLBufferDecl *>(const_cast<DeclContext *>(DC));
5394 }
5395
5396 // Iterator for the buffer decls. For constant buffers explicitly declared
5397 // with `cbuffer` keyword this will the list of decls parented by this
5398 // HLSLBufferDecl (equal to `decls()`).
5399 // For implicit $Globals buffer this will be the list of default buffer
5400 // declarations stored in DefaultBufferDecls plus the implicit layout
5401 // struct (the only child of HLSLBufferDecl in this case).
5402 //
5403 // The iterator uses llvm::concat_iterator to concatenate the lists
5404 // `decls()` and `DefaultBufferDecls`. For non-default buffers
5405 // `DefaultBufferDecls` is always empty.
5407 llvm::concat_iterator<Decl *const, SmallVector<Decl *>::const_iterator,
5409 using buffer_decl_range = llvm::iterator_range<buffer_decl_iterator>;
5410
5416 bool buffer_decls_empty();
5417
5418 friend class ASTDeclReader;
5419 friend class ASTDeclWriter;
5420};
5421
5422class HLSLRootSignatureDecl final
5423 : public NamedDecl,
5424 private llvm::TrailingObjects<HLSLRootSignatureDecl,
5425 llvm::hlsl::rootsig::RootElement> {
5426 friend TrailingObjects;
5427
5428 llvm::dxbc::RootSignatureVersion Version;
5429
5430 unsigned NumElems;
5431
5432 llvm::hlsl::rootsig::RootElement *getElems() { return getTrailingObjects(); }
5433
5434 const llvm::hlsl::rootsig::RootElement *getElems() const {
5435 return getTrailingObjects();
5436 }
5437
5438 HLSLRootSignatureDecl(DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
5439 llvm::dxbc::RootSignatureVersion Version,
5440 unsigned NumElems);
5441
5442public:
5443 static HLSLRootSignatureDecl *
5445 llvm::dxbc::RootSignatureVersion Version,
5447
5448 static HLSLRootSignatureDecl *CreateDeserialized(ASTContext &C,
5449 GlobalDeclID ID);
5450
5451 llvm::dxbc::RootSignatureVersion getVersion() const { return Version; }
5452
5454 return {getElems(), NumElems};
5455 }
5456
5457 // Implement isa/cast/dyncast/etc.
5458 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5459 static bool classofKind(Kind K) { return K == HLSLRootSignature; }
5460};
5461
5462/// Insertion operator for diagnostics. This allows sending NamedDecl's
5463/// into a diagnostic with <<.
5465 const NamedDecl *ND) {
5466 PD.AddTaggedVal(reinterpret_cast<uint64_t>(ND),
5468 return PD;
5469}
5470
5471template<typename decl_type>
5473 // Note: This routine is implemented here because we need both NamedDecl
5474 // and Redeclarable to be defined.
5475 assert(RedeclLink.isFirst() &&
5476 "setPreviousDecl on a decl already in a redeclaration chain");
5477
5478 if (PrevDecl) {
5479 // Linking this declaration to a previous one may change its linkage.
5480 static_cast<decl_type *>(this)->invalidateCachedLinkage();
5481
5482 // Point to previous. Make sure that this is actually the most recent
5483 // redeclaration, or we can build invalid chains. If the most recent
5484 // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
5485 First = PrevDecl->getFirstDecl();
5486 assert(First->RedeclLink.isFirst() && "Expected first");
5487 decl_type *MostRecent = First->getNextRedeclaration();
5489
5490 // If the declaration was previously visible, a redeclaration of it remains
5491 // visible even if it wouldn't be visible by itself.
5492 static_cast<decl_type*>(this)->IdentifierNamespace |=
5493 MostRecent->getIdentifierNamespace() &
5495 } else {
5496 // Make this first.
5497 First = static_cast<decl_type*>(this);
5498 }
5499
5500 // First one will point to this one as latest.
5501 First->RedeclLink.setLatest(static_cast<decl_type*>(this));
5502
5503 assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
5504 cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
5505}
5506
5507// Inline function definitions.
5508
5509/// Check if the given decl is complete.
5510///
5511/// We use this function to break a cycle between the inline definitions in
5512/// Type.h and Decl.h.
5514 if (const auto *Def = ED->getDefinition())
5515 return Def->isComplete();
5516 return ED->isComplete();
5517}
5518
5519/// Check if the given decl is scoped.
5520///
5521/// We use this function to break a cycle between the inline definitions in
5522/// Type.h and Decl.h.
5523inline bool IsEnumDeclScoped(EnumDecl *ED) {
5524 return ED->isScoped();
5525}
5526
5527/// OpenMP variants are mangled early based on their OpenMP context selector.
5528/// The new name looks likes this:
5529/// <name> + OpenMPVariantManglingSeparatorStr + <mangled OpenMP context>
5530static constexpr StringRef getOpenMPVariantManglingSeparatorStr() {
5531 return "$ompvariant";
5532}
5533
5534/// Returns whether the given FunctionDecl has an __arm[_locally]_streaming
5535/// attribute.
5536bool IsArmStreamingFunction(const FunctionDecl *FD,
5537 bool IncludeLocallyStreaming);
5538
5539/// Returns whether the given FunctionDecl has Arm ZA state.
5540bool hasArmZAState(const FunctionDecl *FD);
5541
5542/// Returns whether the given FunctionDecl has Arm ZT0 state.
5543bool hasArmZT0State(const FunctionDecl *FD);
5544
5545} // namespace clang
5546
5547#endif // LLVM_CLANG_AST_DECL_H
#define V(N, I)
Provides definitions for the various language-specific address spaces.
Defines the Diagnostic-related interfaces.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
static const Decl * getCanonicalDecl(const Decl *D)
#define X(type, name)
Definition Value.h:97
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
Defines an enumeration for C++ overloaded operators.
Defines clang::OptionalUnsigned.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
C Language Family Type Representation.
Defines the clang::Visibility enumeration and various utility functions.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
void setValue(const ASTContext &C, const llvm::APInt &Val)
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:158
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
bool isNested() const
Whether this is a nested capture, i.e.
Definition Decl.h:4857
void setCopyExpr(Expr *e)
Definition Decl.h:4861
Expr * getCopyExpr() const
Definition Decl.h:4860
bool isByRef() const
Whether this is a "by ref" capture, i.e.
Definition Decl.h:4845
Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
Definition Decl.h:4835
bool isNonEscapingByref() const
Definition Decl.h:4851
VarDecl * getVariable() const
The variable being captured.
Definition Decl.h:4841
bool isEscapingByref() const
Definition Decl.h:4847
bool hasCopyExpr() const
Definition Decl.h:4859
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4814
ParmVarDecl * getParamDecl(unsigned i)
Definition Decl.h:4924
BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
Definition Decl.cpp:5515
static bool classofKind(Kind K)
Definition Decl.h:5000
CompoundStmt * getCompoundBody() const
Definition Decl.h:4892
static bool classof(const Decl *D)
Definition Decl.h:4999
unsigned getNumParams() const
Definition Decl.h:4918
unsigned getNumCaptures() const
Returns the number of captured variables.
Definition Decl.h:4937
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition Decl.cpp:5525
capture_const_iterator capture_begin() const
Definition Decl.h:4943
bool canAvoidCopyToHeap() const
Definition Decl.h:4968
void setDoesNotEscape(bool B=true)
Definition Decl.h:4966
param_iterator param_end()
Definition Decl.h:4913
capture_const_iterator capture_end() const
Definition Decl.h:4944
ArrayRef< Capture >::const_iterator capture_const_iterator
Definition Decl.h:4939
unsigned getBlockManglingNumber() const
Definition Decl.h:4980
param_const_iterator param_end() const
Definition Decl.h:4915
MutableArrayRef< ParmVarDecl * >::iterator param_iterator
Definition Decl.h:4908
size_t param_size() const
Definition Decl.h:4916
void setCapturesCXXThis(bool B=true)
Definition Decl.h:4947
void setSignatureAsWritten(TypeSourceInfo *Sig)
Definition Decl.h:4896
void setBlockMangling(unsigned Number, Decl *Ctx)
Definition Decl.h:4984
MutableArrayRef< ParmVarDecl * > parameters()
Definition Decl.h:4903
void setCanAvoidCopyToHeap(bool B=true)
Definition Decl.h:4971
param_iterator param_begin()
Definition Decl.h:4912
void setIsConversionFromLambda(bool val=true)
Definition Decl.h:4961
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition Decl.h:4893
static DeclContext * castToDeclContext(const BlockDecl *D)
Definition Decl.h:5001
void setBlockMissingReturnType(bool val=true)
Definition Decl.h:4953
FunctionEffectsRef getFunctionEffects() const
Definition Decl.h:4991
ArrayRef< Capture > captures() const
Definition Decl.h:4941
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5558
static BlockDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5733
void setIsVariadic(bool value)
Definition Decl.h:4890
bool param_empty() const
Definition Decl.h:4911
bool blockMissingReturnType() const
Definition Decl.h:4949
SourceLocation getCaretLocation() const
Definition Decl.h:4887
bool capturesCXXThis() const
Definition Decl.h:4946
bool capturesVariable(const VarDecl *var) const
Definition Decl.cpp:5549
bool doesNotEscape() const
Definition Decl.h:4965
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
Definition Decl.h:4933
Decl * getBlockManglingContextDecl() const
Definition Decl.h:4982
ArrayRef< ParmVarDecl * >::const_iterator param_const_iterator
Definition Decl.h:4909
static BlockDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5004
const ParmVarDecl * getParamDecl(unsigned i) const
Definition Decl.h:4920
void setBody(CompoundStmt *B)
Definition Decl.h:4894
param_const_iterator param_begin() const
Definition Decl.h:4914
bool isConversionFromLambda() const
Definition Decl.h:4957
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:4900
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
Definition Decl.cpp:5536
bool isVariadic() const
Definition Decl.h:4889
TypeSourceInfo * getSignatureAsWritten() const
Definition Decl.h:4897
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:5086
unsigned getNumParams() const
Definition Decl.h:5124
void setBody(Stmt *B)
Definition Decl.cpp:5783
static bool classof(const Decl *D)
Definition Decl.h:5164
ImplicitParamDecl *const * param_iterator
Definition Decl.h:5155
ImplicitParamDecl * getContextParam() const
Retrieve the parameter containing captured variables.
Definition Decl.h:5144
ArrayRef< ImplicitParamDecl * > parameters() const
Definition Decl.h:5136
static DeclContext * castToDeclContext(const CapturedDecl *D)
Definition Decl.h:5166
size_t numTrailingObjects(OverloadToken< ImplicitParamDecl >)
Definition Decl.h:5088
static CapturedDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams)
Definition Decl.cpp:5776
unsigned getContextParamPosition() const
Definition Decl.h:5153
bool isNothrow() const
Definition Decl.cpp:5785
static CapturedDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5169
static bool classofKind(Kind K)
Definition Decl.h:5165
friend class ASTDeclReader
Definition Decl.h:5109
void setContextParam(unsigned i, ImplicitParamDecl *P)
Definition Decl.h:5148
void setNothrow(bool Nothrow=true)
Definition Decl.cpp:5786
void setParam(unsigned i, ImplicitParamDecl *P)
Definition Decl.h:5130
friend TrailingObjects
Definition Decl.h:5111
friend class ASTDeclWriter
Definition Decl.h:5110
param_iterator param_end() const
Retrieve an iterator one past the last parameter decl.
Definition Decl.h:5161
MutableArrayRef< ImplicitParamDecl * > parameters()
Definition Decl.h:5139
param_iterator param_begin() const
Retrieve an iterator pointing to the first parameter decl.
Definition Decl.h:5159
llvm::iterator_range< param_iterator > param_range
Definition Decl.h:5156
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition Decl.cpp:5782
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:5126
This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1752
decl_iterator - Iterates through the declarations stored within this context.
Definition DeclBase.h:2376
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition DeclBase.h:2439
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1468
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2122
FunctionDeclBitfields FunctionDeclBits
Definition DeclBase.h:2057
TagDeclBitfields TagDeclBits
Definition DeclBase.h:2053
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
EnumDeclBitfields EnumDeclBits
Definition DeclBase.h:2054
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
BlockDeclBitfields BlockDeclBits
Definition DeclBase.h:2062
bool isRecord() const
Definition DeclBase.h:2222
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
RecordDeclBitfields RecordDeclBits
Definition DeclBase.h:2055
DeclContext(Decl::Kind K)
decl_iterator decls_end() const
Definition DeclBase.h:2421
NamespaceDeclBitfields NamespaceDeclBits
Definition DeclBase.h:2052
bool decls_empty() const
bool isFunctionOrMethod() const
Returns true if this DeclContext is a function, Objective-C method, or block, or a DeclContext that c...
Definition DeclBase.h:2177
Decl::Kind getDeclKind() const
Definition DeclBase.h:2115
DeclContext * getNonTransparentContext()
decl_iterator decls_begin() const
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Decl()=delete
SourceLocation getEndLoc() const LLVM_READONLY
Definition DeclBase.h:445
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
Definition DeclBase.h:658
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:550
friend class Redeclarable
Definition DeclBase.h:335
virtual Decl * getPreviousDeclImpl()
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition DeclBase.h:1014
bool hasCachedLinkage() const
Definition DeclBase.h:431
Kind
Lists the kind of concrete classes of Decl.
Definition DeclBase.h:89
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
Definition DeclBase.h:198
virtual Decl * getNextRedeclarationImpl()
Returns the next redeclaration or itself if this is the only decl.
Definition DeclBase.h:1010
bool hasDefiningAttr() const
Return true if this declaration has an attribute which acts as definition of the entity,...
Definition DeclBase.cpp:637
SourceLocation getLocation() const
Definition DeclBase.h:449
@ IDNS_Ordinary
Ordinary names.
Definition DeclBase.h:144
@ IDNS_Type
Types, declared with 'struct foo', typedefs, etc.
Definition DeclBase.h:130
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition DeclBase.h:125
void setImplicit(bool I=true)
Definition DeclBase.h:604
DeclContext * getDeclContext()
Definition DeclBase.h:458
bool isInAnonymousNamespace() const
Definition DeclBase.cpp:443
virtual Decl * getMostRecentDeclImpl()
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition DeclBase.h:1018
void setModulePrivate()
Specify that this declaration was marked as being private to the module in which it was defined.
Definition DeclBase.h:720
friend class RecordDecl
Definition DeclBase.h:334
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition DeclBase.cpp:385
Module * getOwningModuleForLinkage() const
Get the module that owns this declaration for linkage purposes.
Definition Decl.cpp:1638
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition DeclBase.h:937
friend class DeclContext
Definition DeclBase.h:260
Kind getKind() const
Definition DeclBase.h:452
DeclarationNameLoc - Additional source/type location info for a declaration name.
The name of a declaration.
SourceLocation getTypeSpecEndLoc() const
Definition Decl.cpp:2010
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition Decl.h:823
static bool classofKind(Kind K)
Definition Decl.h:878
void setInnerLocStart(SourceLocation L)
Definition Decl.h:824
SourceLocation getOuterLocStart() const
Return start of source range taking into account any outer template declarations.
Definition Decl.cpp:2066
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:2070
friend class ASTDeclReader
Definition Decl.h:807
SourceLocation getTypeSpecStartLoc() const
Definition Decl.cpp:2004
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:832
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition Decl.h:856
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition Decl.h:815
DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T, TypeSourceInfo *TInfo, SourceLocation StartL)
Definition Decl.h:801
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:2016
void setTrailingRequiresClause(const AssociatedConstraint &AC)
Definition Decl.cpp:2035
friend class ASTDeclWriter
Definition Decl.h:808
ArrayRef< TemplateParameterList * > getTemplateParameterLists() const
Definition Decl.h:863
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:846
static bool classof(const Decl *D)
Definition Decl.h:877
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition Decl.h:838
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:810
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition Decl.cpp:2050
Provides information about a dependent function-template specialization declaration.
@ ak_nameddecl
NamedDecl *.
Definition Diagnostic.h:287
static EmptyDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5980
static bool classof(const Decl *D)
Definition Decl.h:5331
static bool classofKind(Kind K)
Definition Decl.h:5332
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3562
friend class StmtIteratorBase
Definition Decl.h:3572
EnumConstantDecl(const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
Definition Decl.cpp:5788
static EnumConstantDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5802
static bool classofKind(Kind K)
Definition Decl.h:3600
const EnumConstantDecl * getCanonicalDecl() const
Definition Decl.h:3596
void setInitExpr(Expr *E)
Definition Decl.h:3586
void setInitVal(const ASTContext &C, const llvm::APSInt &V)
Definition Decl.h:3587
llvm::APSInt getInitVal() const
Definition Decl.h:3582
EnumConstantDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this enumerator.
Definition Decl.h:3595
static bool classof(const Decl *D)
Definition Decl.h:3599
const Expr * getInitExpr() const
Definition Decl.h:3580
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5836
Represents an enum.
Definition Decl.h:4150
const EnumDecl * getMostRecentDecl() const
Definition Decl.h:4258
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4422
enumerator_range enumerators() const
Definition Decl.h:4296
void setFixed(bool Fixed=true)
True if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying type.
Definition Decl.h:4226
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4368
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4360
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4371
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4332
llvm::iterator_range< specific_decl_iterator< EnumConstantDecl > > enumerator_range
Definition Decl.h:4293
void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo)
Set the underlying integer type source info.
Definition Decl.h:4335
enumerator_iterator enumerator_begin() const
Definition Decl.h:4300
bool isComplete() const
Returns true if this can be considered a complete type.
Definition Decl.h:4382
void setInstantiationOfMemberEnum(EnumDecl *ED, TemplateSpecializationKind TSK)
Specify that this enumeration is an instantiation of the member enumeration ED.
Definition Decl.h:4428
const EnumDecl * getCanonicalDecl() const
Definition Decl.h:4243
unsigned getODRHash()
Definition Decl.cpp:5246
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For an enumeration member that was instantiated from a member enumeration of a templated class,...
Definition Decl.cpp:5207
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists,...
Definition Decl.h:4339
friend class ASTDeclReader
Definition Decl.h:4238
static EnumDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5162
bool isClosedFlag() const
Returns true if this enum is annotated with flag_enum and isn't annotated with enum_extensibility(ope...
Definition Decl.cpp:5192
EnumDecl * getMostRecentDecl()
Definition Decl.h:4255
EnumDecl * getDefinitionOrSelf() const
Definition Decl.h:4266
void setScoped(bool Scoped=true)
True if this tag declaration is a scoped enumeration.
Definition Decl.h:4214
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4377
SourceRange getIntegerTypeRange() const LLVM_READONLY
Retrieve the source range that covers the underlying type if specified.
Definition Decl.cpp:5167
void setPromotionType(QualType T)
Set the promotion type.
Definition Decl.h:4318
void setEnumKeyRange(SourceRange Range)
Definition Decl.h:4230
EnumDecl * getPreviousDecl()
Definition Decl.h:4247
SourceRange getSourceRange() const override LLVM_READONLY
Overrides to provide correct range when there's an enum-base specifier with forward declarations.
Definition Decl.cpp:5257
static bool classofKind(Kind K)
Definition Decl.h:4434
SourceRange getEnumKeyRange() const
Definition Decl.h:4228
static bool classof(const Decl *D)
Definition Decl.h:4433
EnumDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.h:4240
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4323
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5233
EnumDecl * getDefinition() const
Definition Decl.h:4262
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4349
const EnumDecl * getPreviousDecl() const
Definition Decl.h:4251
specific_decl_iterator< EnumConstantDecl > enumerator_iterator
Definition Decl.h:4292
TemplateSpecializationKind getTemplateSpecializationKind() const
If this enumeration is a member of a specialization of a templated class, determine what kind of temp...
Definition Decl.cpp:5200
void setScopedUsingClassTag(bool ScopedUCT=true)
If this tag declaration is a scoped enum, then this is true if the scoped enum was declared using the...
Definition Decl.h:4220
bool isClosed() const
Returns true if this enum is either annotated with enum_extensibility(closed) or isn't annotated with...
Definition Decl.cpp:5186
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4315
EnumDecl * getTemplateInstantiationPattern() const
Retrieve the enum definition from which this enumeration could be instantiated, if it is an instantia...
Definition Decl.cpp:5218
bool isClosedNonFlag() const
Returns true if this enum is annotated with neither flag_enum nor enum_extensibility(open).
Definition Decl.cpp:5196
enumerator_iterator enumerator_end() const
Definition Decl.h:4307
void getValueRange(llvm::APInt &Max, llvm::APInt &Min) const
Calculates the [Min,Max) values the enum can store based on the NumPositiveBits and NumNegativeBits.
Definition Decl.cpp:5268
Represents a standard C++ module export declaration.
Definition Decl.h:5274
static bool classof(const Decl *D)
Definition Decl.h:5310
SourceLocation getRBraceLoc() const
Definition Decl.h:5293
SourceLocation getEndLoc() const LLVM_READONLY
Definition Decl.h:5298
SourceLocation getExportLoc() const
Definition Decl.h:5292
static bool classofKind(Kind K)
Definition Decl.h:5311
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:5306
void setRBraceLoc(SourceLocation L)
Definition Decl.h:5294
friend class ASTDeclReader
Definition Decl.h:5278
static DeclContext * castToDeclContext(const ExportDecl *D)
Definition Decl.h:5312
static ExportDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5315
static ExportDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:6181
bool hasBraces() const
Definition Decl.h:5296
This represents one expression.
Definition Expr.h:113
static DeclContext * castToDeclContext(const ExternCContextDecl *D)
Definition Decl.h:262
static bool classof(const Decl *D)
Definition Decl.h:260
static bool classofKind(Kind K)
Definition Decl.h:261
static ExternCContextDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:265
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
Definition Decl.h:3299
Expr * BitWidth
Definition Decl.h:3351
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3399
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4798
bool isBitField() const
Determines whether this field is a bitfield.
Definition Decl.h:3402
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3479
FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
Definition Decl.h:3359
LazyDeclStmtPtr Init
Definition Decl.h:3349
unsigned getBitWidthValue() const
Computes the bit width of this field, if this is a bit field.
Definition Decl.cpp:4825
bool isAnonymousStructOrUnion() const
Determines whether this field is a representative for an anonymous struct or union.
Definition Decl.cpp:4788
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4899
void setBitWidth(Expr *Width)
Set the bit-field width for this member.
Definition Decl.h:3434
void removeBitWidth()
Remove the bit-field width from this member.
Definition Decl.h:3448
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3473
bool hasConstantIntegerBitWidth() const
Determines whether the bit width of this field is a constant integer.
Definition Decl.cpp:4820
friend class ASTDeclReader
Definition Decl.h:3371
static FieldDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:4782
void removeInClassInitializer()
Remove the C++11 in-class initializer from this member.
Definition Decl.h:3506
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4808
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition Decl.h:3384
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition Decl.h:3535
bool isZeroSize(const ASTContext &Ctx) const
Determine if this field is a subobject of zero size, that is, either a zero-length bit-field or a fie...
Definition Decl.cpp:4839
InitAndBitWidthStorage * InitAndBitWidth
Definition Decl.h:3353
FieldDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this field.
Definition Decl.h:3546
static bool classofKind(Kind K)
Definition Decl.h:3551
bool hasCapturedVLAType() const
Determine whether this member captures the variable length array type.
Definition Decl.h:3518
friend class ASTDeclWriter
Definition Decl.h:3372
bool isUnnamedBitField() const
Determines whether this is an unnamed bitfield.
Definition Decl.h:3405
bool isZeroLengthBitField() const
Is this a zero-length bit-field?
Definition Decl.cpp:4834
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3415
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:4918
const FieldDecl * getCanonicalDecl() const
Definition Decl.h:3547
const FieldDecl * findCountedByField() const
Find the FieldDecl specified in a FAM's "counted_by" attribute.
Definition Decl.cpp:4928
RecordDecl * getParent()
Definition Decl.h:3539
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3523
bool isPotentiallyOverlapping() const
Determine if this field is of potentially-overlapping class type, that is, subobject with the [[no_un...
Definition Decl.cpp:4877
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4908
bool hasNonNullInClassInitializer() const
Determine whether getInClassInitializer() would return a non-null pointer without deserializing the i...
Definition Decl.h:3485
const VariableArrayType * CapturedVLAType
Definition Decl.h:3355
static bool classof(const Decl *D)
Definition Decl.h:3550
void setRParenLoc(SourceLocation L)
Definition Decl.h:4754
SourceLocation getAsmLoc() const
Definition Decl.h:4752
std::string getAsmString() const
Definition Decl.cpp:5940
Expr * getAsmStringExpr()
Definition Decl.h:4760
static bool classofKind(Kind K)
Definition Decl.h:4766
const Expr * getAsmStringExpr() const
Definition Decl.h:4759
SourceLocation getRParenLoc() const
Definition Decl.h:4753
static bool classof(const Decl *D)
Definition Decl.h:4765
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:4755
void setAsmString(Expr *Asm)
Definition Decl.h:4761
static FileScopeAsmDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5934
CXXSpecialMemberKind asSpecialMember() const
Definition Decl.h:2152
DefaultedFunctionKind(DefaultedComparisonKind Comp)
Definition Decl.h:2135
DefaultedComparisonKind asComparison() const
Definition Decl.h:2155
DefaultedFunctionKind(CXXSpecialMemberKind CSM)
Definition Decl.h:2132
unsigned getDiagnosticIndex() const
Get the index of this function kind for use in diagnostics.
Definition Decl.h:2160
Stashed information about a defaulted/deleted function body, including the active FP pragma overrides...
Definition Decl.h:2090
void setDeletedMessage(StringLiteral *Message)
Definition Decl.cpp:3172
ArrayRef< DeclAccessPair > getUnqualifiedLookups() const
Get the unqualified lookup results that should be used in this defaulted function definition.
Definition Decl.h:2110
Represents a function declaration or definition.
Definition Decl.h:2059
unsigned getMemoryFunctionKind() const
Identify a memory copying or setting function.
Definition Decl.cpp:4620
static constexpr unsigned RequiredTypeAwareDeleteParameterCount
Count of mandatory parameters for type aware operator delete.
Definition Decl.h:2773
void setInstantiationIsPending(bool IC)
State that the instantiation of this function is pending.
Definition Decl.h:2640
bool isTargetClonesMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target-clones functional...
Definition Decl.cpp:3769
bool isMultiVersion() const
True if this function is considered a multiversioned function.
Definition Decl.h:2820
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin=false, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=ConstexprSpecKind::Unspecified, const AssociatedConstraint &TrailingRequiresClause={})
Definition Decl.h:2303
const ParmVarDecl * getParamDecl(unsigned i) const
Definition Decl.h:2932
ExceptionSpecificationType getExceptionSpecType() const
Gets the ExceptionSpecificationType as declared.
Definition Decl.h:3004
bool isTrivialForCall() const
Definition Decl.h:2507
bool hasTrivialBody() const
Returns whether the function has a trivial body that does not require any specific codegen.
Definition Decl.cpp:3200
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2603
DefaultedOrDeletedFunctionInfo * getDefaultedOrDeletedInfo() const
Definition Decl.cpp:3184
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
Definition Decl.cpp:3897
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition Decl.cpp:4252
void setPreviousDeclaration(FunctionDecl *PrevDecl)
Definition Decl.cpp:3778
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4245
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4240
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3343
const FunctionDecl * getDefinition() const
Definition Decl.h:2402
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
Definition Decl.h:2428
unsigned getNumParamsIncludingThis() const
Return the number of parameters, including the implicit 'this' parameter if this function has one.
Definition Decl.cpp:3876
bool isImmediateFunction() const
Definition Decl.cpp:3385
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3150
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition Decl.h:2832
SourceLocation getEllipsisLoc() const
Returns the location of the ellipsis of a variadic function.
Definition Decl.h:2337
static bool classofKind(Kind K)
Definition Decl.h:3285
void setHasSkippedBody(bool Skipped=true)
Definition Decl.h:2811
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type.
Definition Decl.cpp:4074
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3596
static FunctionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5717
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
Definition Decl.cpp:3807
void setUsesSEHTry(bool UST)
Definition Decl.h:2646
param_iterator param_end()
Definition Decl.h:2918
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
Definition Decl.h:2889
SourceLocation getPointOfInstantiation() const
Retrieve the (first) point of instantiation of a function template specialization or a member of a cl...
Definition Decl.cpp:4581
bool isMemberLikeConstrainedFriend() const
Determine whether a function is a friend function that cannot be redeclared outside of its class,...
Definition Decl.cpp:3711
bool hasCXXExplicitFunctionObjectParameter() const
Definition Decl.cpp:3915
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
Definition Decl.h:3056
void setIsMultiVersion(bool V=true)
Sets the multiversion state for this declaration and all of its redeclarations.
Definition Decl.h:2826
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition Decl.h:3044
SourceLocation getDefaultLoc() const
Definition Decl.h:2525
void setInstantiationOfMemberFunction(FunctionDecl *FD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member function FD.
Definition Decl.h:3109
bool usesSEHTry() const
Indicates the function uses __try.
Definition Decl.h:2645
void setHasWrittenPrototype(bool P=true)
State that this function has a written prototype.
Definition Decl.h:2580
bool isNoReturn() const
Determines whether this function is known to be 'noreturn', through an attribute on its declaration o...
Definition Decl.cpp:3696
QualType getReturnType() const
Definition Decl.h:2980
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2905
bool isCPUSpecificMultiVersion() const
True if this function is a multiversioned processor specific function as a part of the cpu_specific/c...
Definition Decl.cpp:3751
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
Definition Decl.cpp:4311
bool isMSExternInline() const
The combination of the extern and inline keywords under MSVC forces the function to be required.
Definition Decl.cpp:3941
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2516
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2504
bool instantiationIsPending() const
Whether the instantiation of this function is pending.
Definition Decl.h:2634
unsigned getMinRequiredExplicitArguments() const
Returns the minimum number of non-object arguments needed to call this function.
Definition Decl.cpp:3924
const FunctionDecl * getCanonicalDecl() const
Definition Decl.h:2898
bool BodyContainsImmediateEscalatingExpressions() const
Definition Decl.h:2617
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
Definition Decl.cpp:3659
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
Definition Decl.cpp:4360
MutableArrayRef< ParmVarDecl * >::iterator param_iterator
Definition Decl.h:2913
FunctionDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition Decl.h:2276
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2575
void setWillHaveBody(bool V=true)
Definition Decl.h:2817
void setDeclarationNameLoc(DeclarationNameLoc L)
Definition Decl.h:2334
bool isReplaceableGlobalAllocationFunction(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions:
Definition Decl.h:2723
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4219
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
Definition Decl.h:2570
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4370
void setUsesFPIntrin(bool I)
Set whether the function was declared in source context that requires constrained FP intrinsics.
Definition Decl.h:3048
void setDefaultLoc(SourceLocation NewLoc)
Definition Decl.h:2529
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:3792
void getAssociatedConstraints(SmallVectorImpl< AssociatedConstraint > &ACs) const
Get the associated-constraints of this function declaration.
Definition Decl.h:2883
FunctionTypeLoc getFunctionTypeLoc() const
Find the source location information for how the type of this function was written.
Definition Decl.cpp:4051
void setInstantiatedFromMemberTemplate(bool Val=true)
Definition Decl.h:2496
MutableArrayRef< ParmVarDecl * > parameters()
Definition Decl.h:2908
param_iterator param_begin()
Definition Decl.h:2917
FunctionDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition Decl.h:2280
const ParmVarDecl * getNonObjectParameter(unsigned I) const
Definition Decl.h:2958
bool isVariadic() const
Whether this function is variadic.
Definition Decl.cpp:3122
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2440
bool isConstexprSpecified() const
Definition Decl.h:2606
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition Decl.cpp:4436
bool isDeleted() const
Whether this function has been deleted.
Definition Decl.h:2667
void setBodyContainsImmediateEscalatingExpressions(bool Set)
Definition Decl.h:2613
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition Decl.cpp:4376
FunctionEffectsRef getFunctionEffects() const
Definition Decl.h:3273
static DeclContext * castToDeclContext(const FunctionDecl *D)
Definition Decl.h:3288
SourceRange getExceptionSpecSourceRange() const
Attempt to compute an informative source range covering the function exception specification,...
Definition Decl.cpp:4103
bool hasBody() const override
Returns true if this Decl represents a declaration for a body of code, such as a function or method d...
Definition Decl.h:2367
bool isMSVCRTEntryPoint() const
Determines whether this function is a MSVCRT user defined entry point.
Definition Decl.cpp:3420
unsigned getODRHash()
Returns ODRHash of the function.
Definition Decl.cpp:4752
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Determine the kind of template specialization this function represents for the purpose of template in...
Definition Decl.cpp:4488
ArrayRef< ParmVarDecl * >::const_iterator param_const_iterator
Definition Decl.h:2914
FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass S, bool UsesFPIntrin, bool isInlineSpecified, ConstexprSpecKind ConstexprKind, const AssociatedConstraint &TrailingRequiresClause)
Definition Decl.cpp:3068
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
Definition Decl.cpp:4304
void setInlineSpecified(bool I)
Set whether the "inline" keyword was specified for this function.
Definition Decl.h:3037
unsigned getNumNonObjectParams() const
Definition Decl.cpp:3919
TemplatedKind
The kind of templated function a FunctionDecl can be.
Definition Decl.h:2064
@ TK_FunctionTemplateSpecialization
Definition Decl.h:2075
@ TK_DependentFunctionTemplateSpecialization
Definition Decl.h:2078
redeclarable_base::redecl_range redecl_range
Definition Decl.h:2292
friend class ASTDeclReader
Definition Decl.h:2289
UsualDeleteParams getUsualDeleteParams() const
Definition Decl.cpp:3612
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:3023
FunctionDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition Decl.h:2284
bool isStatic() const
Definition Decl.h:3064
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:2293
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a member function.
Definition Decl.cpp:4593
void setTrivial(bool IT)
Definition Decl.h:2505
bool isInlineBuiltinDeclaration() const
Determine if this function provides an inline implementation of a builtin.
Definition Decl.cpp:3571
bool FriendConstraintRefersToEnclosingTemplate() const
Definition Decl.h:2838
ParmVarDecl * getParamDecl(unsigned i)
Definition Decl.h:2936
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition Decl.cpp:4191
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4258
DefaultedComparisonKind getDefaultedComparisonKind() const
Definition Decl.h:2463
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition Decl.h:2597
bool isDeletedAsWritten() const
Definition Decl.h:2671
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
Definition Decl.cpp:3448
ParmVarDecl * getNonObjectParameter(unsigned I)
Definition Decl.h:2962
void setHasInheritedPrototype(bool P=true)
State that this function inherited its prototype from a previous declaration.
Definition Decl.h:2592
void setDependentTemplateSpecialization(ASTContext &Context, const UnresolvedSetImpl &Templates, const TemplateArgumentListInfo *TemplateArgs)
Specifies that this function declaration is actually a dependent function template specialization.
Definition Decl.cpp:4425
bool isInExternCContext() const
Determines whether this function's context is, or is nested within, a C++ extern "C" linkage spec.
Definition Decl.cpp:3667
static constexpr unsigned RequiredTypeAwareNewParameterCount
Count of mandatory parameters for type aware operator new.
Definition Decl.h:2769
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2480
bool isImplicitlyInstantiable() const
Determines whether this function is a function template specialization or a member of a class templat...
Definition Decl.cpp:4269
bool isExternC() const
Determines whether this function is a function with external, C linkage.
Definition Decl.cpp:3663
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition Decl.h:2414
bool isLateTemplateParsed() const
Whether this templated function will be late parsed.
Definition Decl.h:2484
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
bool isDefined() const
Definition Decl.h:2390
LazyDeclStmtPtr Body
The body of the function.
Definition Decl.h:2180
bool hasImplicitReturnZero() const
Whether falling off this function implicitly returns null/zero.
Definition Decl.h:2555
bool isImmediateEscalating() const
Definition Decl.cpp:3356
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition Decl.h:2476
bool hasSkippedBody() const
True if the function was a definition but its body was skipped.
Definition Decl.h:2810
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition Decl.cpp:3600
static bool classof(const Decl *D)
Definition Decl.h:3284
void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template, TemplateArgumentList *TemplateArgs, llvm::FoldingSetInsertToken InsertToken, TemplateSpecializationKind TSK=TSK_ImplicitInstantiation, TemplateArgumentListInfo *TemplateArgsAsWritten=nullptr, SourceLocation PointOfInstantiation=SourceLocation())
Specify that this function declaration is actually a function template specialization.
Definition Decl.h:3209
void setLateTemplateParsed(bool ILT=true)
State that this templated function will be late parsed.
Definition Decl.h:2489
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
Definition Decl.cpp:3471
DefaultedOrDeletedFunctionInfo * DefaultedOrDeletedInfo
Information about a future defaulted function definition.
Definition Decl.h:2182
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition Decl.h:2396
bool isTypeAwareOperatorNewOrDelete() const
Determine whether this is a type aware operator new or delete.
Definition Decl.cpp:3604
bool isInExternCXXContext() const
Determines whether this function's context is, or is nested within, a C++ extern "C++" linkage spec.
Definition Decl.cpp:3673
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program.
Definition Decl.cpp:3413
void setImplicitlyInline(bool I=true)
Flag that this function is implicitly inline.
Definition Decl.h:3051
bool isTargetVersionMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target-version functiona...
Definition Decl.cpp:3773
void setTrivialForCall(bool IT)
Definition Decl.h:2508
bool param_empty() const
Definition Decl.h:2916
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3608
void setLazyBody(uint64_t Offset)
Definition Decl.h:2446
friend class ASTDeclWriter
Definition Decl.h:2290
bool isThisDeclarationInstantiatedFromAFriendDefinition() const
Determine whether this specific declaration of the function is a friend declaration that was instanti...
Definition Decl.cpp:3213
void setRangeEnd(SourceLocation E)
Definition Decl.h:2332
bool isCPUDispatchMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the cpu_specific/cpu_dispatc...
Definition Decl.cpp:3747
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2512
bool isIneligibleOrNotSelected() const
Definition Decl.h:2545
bool isReferenceableKernel() const
Definition Decl.cpp:5724
void setIneligibleOrNotSelected(bool II)
Definition Decl.h:2548
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4616
bool isOverloadedOperator() const
Whether this function declaration represents an C++ overloaded operator, e.g., "operator+".
Definition Decl.h:3068
FunctionDecl * getInstantiatedFromDecl() const
Definition Decl.cpp:4264
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4533
const IdentifierInfo * getLiteralIdentifier() const
getLiteralIdentifier - The literal suffix identifier this function represents, if any.
Definition Decl.cpp:4185
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition Decl.cpp:4177
void setConstexprKind(ConstexprSpecKind CSK)
Definition Decl.h:2600
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4464
param_const_iterator param_begin() const
Definition Decl.h:2919
bool doesDeclarationForceExternallyVisibleDefinition() const
For a function declaration in C or C++, determine whether this declaration causes the definition to b...
Definition Decl.cpp:3991
void setDefaulted(bool D=true)
Definition Decl.h:2513
bool isConsteval() const
Definition Decl.h:2609
bool isTargetMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target functionality.
Definition Decl.cpp:3755
bool isUserProvided() const
True if this method is user-declared and was not deleted or defaulted on its first declaration.
Definition Decl.h:2537
bool isAnalyzerNoReturn() const
Determines whether this function is known to be 'noreturn' for analyzer, through an analyzer_noreturn...
Definition Decl.cpp:3707
DefaultedFunctionKind getDefaultedFunctionKind() const
Determine the kind of defaulting that would be done for a given function.
Definition Decl.cpp:3289
QualType getDeclaredReturnType() const
Get the declared return type, which may differ from the actual return type if the return type is dedu...
Definition Decl.h:2997
void setStorageClass(StorageClass SClass)
Sets the storage class as written in the source.
Definition Decl.h:3028
void setBody(Stmt *B)
Definition Decl.cpp:3281
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2471
bool isGlobal() const
Determines whether this is a global function.
Definition Decl.cpp:3677
bool hasOneParamOrDefaultArgs() const
Determine whether this function has a single parameter, or multiple parameters where all but the firs...
Definition Decl.cpp:3929
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3159
bool isImplicitHDExplicitInstantiation() const
True if both host and device are implicit attributes and this is (or is a member of) an explicit temp...
Definition Decl.cpp:4561
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition Decl.h:2521
param_const_iterator param_end() const
Definition Decl.h:2920
bool hasInheritedPrototype() const
Whether this function inherited its prototype from a previous declaration.
Definition Decl.h:2586
bool isTargetMultiVersionDefault() const
True if this function is the default version of a multiversioned dispatch function as a part of the t...
Definition Decl.cpp:3760
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4212
bool isInlineDefinitionExternallyVisible() const
For an inline function definition in C, or for a gnu_inline function in C++, determine whether the de...
Definition Decl.cpp:4125
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition Decl.cpp:3871
size_t param_size() const
Definition Decl.h:2921
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2325
Redeclarable< FunctionDecl > redeclarable_base
Definition Decl.h:2274
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition Decl.cpp:3189
SourceRange getParametersSourceRange() const
Attempt to compute an informative source range covering the function parameters, including the ellips...
Definition Decl.cpp:4087
static FunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:3291
void setHasImplicitReturnZero(bool IRZ)
State that falling off this function implicitly returns null/zero.
Definition Decl.h:2562
FunctionDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition Decl.h:3034
MultiVersionKind getMultiVersionKind() const
Gets the kind of multiversioning attribute this declaration has.
Definition Decl.cpp:3733
void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const override
Appends a human-readable name for this declaration into the given stream.
Definition Decl.cpp:3114
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition Decl.h:2940
bool willHaveBody() const
True if this function will eventually have a body, once it's fully parsed.
Definition Decl.h:2816
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Definition Decl.cpp:4386
QualType getCallResultType() const
Determine the type of an expression that calls this function.
Definition Decl.h:3016
bool isInstantiatedFromMemberTemplate() const
Definition Decl.h:2493
An immutable set of FunctionEffects and possibly conditions attached to them.
Definition TypeBase.h:5216
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5416
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition TypeBase.h:5723
SourceLocation getEllipsisLoc() const
Definition TypeBase.h:5822
Declaration of a template function.
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Wrapper for source info for functions.
Definition TypeLoc.h:1675
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition TypeBase.h:4612
static HLSLBufferDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5392
buffer_decl_iterator buffer_decls_begin() const
Definition Decl.cpp:6051
static DeclContext * castToDeclContext(const HLSLBufferDecl *D)
Definition Decl.h:5389
bool isCBuffer() const
Definition Decl.h:5380
const CXXRecordDecl * getLayoutStruct() const
Definition Decl.h:5383
SourceLocation getLBraceLoc() const
Definition Decl.h:5377
SourceLocation getLocStart() const LLVM_READONLY
Definition Decl.h:5376
friend class ASTDeclReader
Definition Decl.h:5418
void addLayoutStruct(CXXRecordDecl *LS)
Definition Decl.cpp:6031
bool buffer_decls_empty()
Definition Decl.cpp:6063
SourceLocation getRBraceLoc() const
Definition Decl.h:5378
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:5373
void setRBraceLoc(SourceLocation L)
Definition Decl.h:5379
friend class ASTDeclWriter
Definition Decl.h:5419
bool hasValidPackoffset() const
Definition Decl.h:5382
llvm::concat_iterator< Decl *const, SmallVector< Decl * >::const_iterator, decl_iterator > buffer_decl_iterator
Definition Decl.h:5406
static bool classofKind(Kind K)
Definition Decl.h:5388
llvm::iterator_range< buffer_decl_iterator > buffer_decl_range
Definition Decl.h:5409
void setHasValidPackoffset(bool PO)
Definition Decl.h:5381
static HLSLBufferDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:6025
buffer_decl_iterator buffer_decls_end() const
Definition Decl.cpp:6057
static HLSLBufferDecl * CreateDefaultCBuffer(ASTContext &C, DeclContext *LexicalParent, ArrayRef< Decl * > DefaultCBufferDecls)
Definition Decl.cpp:6014
buffer_decl_range buffer_decls() const
Definition Decl.h:5411
static bool classof(const Decl *D)
Definition Decl.h:5387
static HLSLRootSignatureDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:6092
ArrayRef< llvm::hlsl::rootsig::RootElement > getRootElements() const
Definition Decl.h:5453
llvm::dxbc::RootSignatureVersion getVersion() const
Definition Decl.h:5451
static bool classofKind(Kind K)
Definition Decl.h:5459
static bool classof(const Decl *D)
Definition Decl.h:5458
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
static bool classofKind(Kind K)
Definition Decl.h:1816
ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, const IdentifierInfo *Id, QualType Type, ImplicitParamKind ParamKind)
Definition Decl.h:1782
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition Decl.h:1810
static bool classof(const Decl *D)
Definition Decl.h:1815
ImplicitParamDecl(ASTContext &C, QualType Type, ImplicitParamKind ParamKind)
Definition Decl.h:1791
static ImplicitParamDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5698
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:6163
static ImportDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumLocations)
Create a new, deserialized module import declaration.
Definition Decl.cpp:6150
friend class ASTReader
Definition Decl.h:5198
friend class ASTDeclReader
Definition Decl.h:5197
friend class ASTContext
Definition Decl.h:5196
static bool classof(const Decl *D)
Definition Decl.h:5264
ArrayRef< SourceLocation > getIdentifierLocs() const
Retrieves the locations of each of the identifiers that make up the complete module name in the impor...
Definition Decl.cpp:6156
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition Decl.h:5253
static bool classofKind(Kind K)
Definition Decl.h:5265
static ImportDecl * CreateImplicit(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, Module *Imported, SourceLocation EndLoc)
Create a new module import declaration for an implicitly-generated import.
Definition Decl.cpp:6140
const IndirectFieldDecl * getCanonicalDecl() const
Definition Decl.h:3644
static bool classofKind(Kind K)
Definition Decl.h:3648
static bool classof(const Decl *D)
Definition Decl.h:3647
FieldDecl * getAnonField() const
Definition Decl.h:3633
static IndirectFieldDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5830
friend class ASTDeclReader
Definition Decl.h:3617
unsigned getChainingSize() const
Definition Decl.h:3631
IndirectFieldDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.h:3643
chain_iterator chain_end() const
Definition Decl.h:3629
chain_iterator chain_begin() const
Definition Decl.h:3628
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3627
VarDecl * getVarDecl() const
Definition Decl.h:3638
ArrayRef< NamedDecl * >::const_iterator chain_iterator
Definition Decl.h:3625
static bool classofKind(Kind K)
Definition Decl.h:567
void setMSAsmLabel(StringRef Name)
Definition Decl.cpp:5651
bool isResolvedMSAsmLabel() const
Definition Decl.h:560
bool isGnuLocal() const
Definition Decl.h:552
static bool classof(const Decl *D)
Definition Decl.h:566
void setLocStart(SourceLocation L)
Definition Decl.h:553
LabelStmt * getStmt() const
Definition Decl.h:549
StringRef getMSAsmLabel() const
Definition Decl.h:562
void setStmt(LabelStmt *T)
Definition Decl.h:550
void setMSAsmLabelResolved()
Definition Decl.h:563
static LabelDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5646
bool isMSAsmLabel() const
Definition Decl.h:559
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:555
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2158
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Visibility getVisibility() const
Definition Visibility.h:89
Provides information a specialization of a member of a class template, which may be a member function...
Describes a module or submodule.
Definition Module.h:340
This represents a decl that may have a name.
Definition Decl.h:275
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition Decl.h:488
ExplicitVisibilityKind
Kinds of explicit visibility.
Definition Decl.h:453
@ VisibilityForValue
Do an LV computation for, ultimately, a non-type declaration.
Definition Decl.h:462
@ VisibilityForType
Do an LV computation for, ultimately, a type.
Definition Decl.h:457
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition Decl.cpp:1183
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:296
NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
Definition Decl.h:287
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
Definition Decl.cpp:1228
bool isLinkageValid() const
True if the computed linkage is valid.
Definition Decl.cpp:1086
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:302
bool isPlaceholderVar(const LangOptions &LangOpts) const
Definition Decl.cpp:1096
Visibility getVisibility() const
Determines the visibility of this entity.
Definition Decl.h:445
bool hasLinkageBeenComputed() const
True if something has required us to compute the linkage of this declaration.
Definition Decl.h:480
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
Definition Decl.h:430
static bool classof(const Decl *D)
Definition Decl.h:511
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:341
std::string getQualifiedNameAsString() const
Definition Decl.cpp:1682
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Definition Decl.h:318
std::optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition Decl.cpp:1315
NamedDecl * getMostRecentDecl()
Definition Decl.h:502
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
Appends a human-readable name for this declaration into the given stream.
Definition Decl.cpp:1848
bool declarationReplaces(const NamedDecl *OldD, bool IsKnownNewer=true) const
Determine whether this declaration, if known to be well-formed within its context,...
Definition Decl.cpp:1872
ObjCStringFormatFamily getObjCFStringFormattingFamily() const
Definition Decl.cpp:1170
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
Definition Decl.cpp:1208
void printQualifiedName(raw_ostream &OS) const
Returns a human-readable qualified name for this declaration, like A::B::i, for i being member of nam...
Definition Decl.cpp:1689
static bool classofKind(Kind K)
Definition Decl.h:512
virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:1674
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
Definition Decl.cpp:1976
bool hasLinkage() const
Determine whether this declaration has linkage.
Definition Decl.cpp:1944
const NamedDecl * getMostRecentDecl() const
Definition Decl.h:505
bool isExternallyVisible() const
Definition Decl.h:434
void setDeclName(DeclarationName N)
Set the name of this declaration.
Definition Decl.h:344
ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const
Determine if the declaration obeys the reserved identifier rules of the given language.
Definition Decl.cpp:1133
bool isCXXClassMember() const
Determine whether this declaration is a C++ class member.
Definition Decl.h:398
const NamedDecl * getUnderlyingDecl() const
Definition Decl.h:498
void printNestedNameSpecifier(raw_ostream &OS) const
Print only the nested name specifier part of a fully-qualified name, including the '::' at the end.
Definition Decl.cpp:1716
bool isExternallyDeclarable() const
Determine whether this declaration can be redeclared in a different translation unit.
Definition Decl.h:440
Represents C++ namespaces and their aliases.
Definition Decl.h:574
const NamespaceDecl * getNamespace() const
Definition Decl.h:580
NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
Definition Decl.h:287
static bool classof(const Decl *D)
Definition Decl.h:584
NamespaceDecl * getNamespace()
Definition DeclCXX.cpp:3351
static bool classofKind(Kind K)
Definition Decl.h:585
Represent a C++ namespace.
Definition Decl.h:593
NamespaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this namespace.
Definition Decl.h:685
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:626
SourceLocation getRBraceLoc() const
Definition Decl.h:693
const NamespaceDecl * getCanonicalDecl() const
Definition Decl.h:686
void setAnonymousNamespace(NamespaceDecl *D)
Definition Decl.h:680
static bool classofKind(Kind K)
Definition Decl.h:699
void setNested(bool Nested)
Set whether this is a nested namespace declaration.
Definition Decl.h:661
static DeclContext * castToDeclContext(const NamespaceDecl *D)
Definition Decl.h:700
friend class ASTDeclReader
Definition Decl.h:615
void setLocStart(SourceLocation L)
Definition Decl.h:694
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:692
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Definition Decl.h:644
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition Decl.h:649
static bool classof(const Decl *D)
Definition Decl.h:698
static NamespaceDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:703
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:688
friend class ASTDeclWriter
Definition Decl.h:616
void setInline(bool Inline)
Set whether this is an inline namespace declaration.
Definition Decl.h:652
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition Decl.h:676
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition Decl.h:658
static NamespaceDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3382
void setRBraceLoc(SourceLocation L)
Definition Decl.h:695
redeclarable_base::redecl_range redecl_range
Definition Decl.h:625
bool isRedundantInlineQualifierFor(DeclarationName Name) const
Returns true if the inline qualifier for Name is redundant.
Definition Decl.h:664
A C++ nested-name-specifier augmented with source location information.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:5053
const ImplicitParamDecl *const * parameter_const_iterator
Definition Decl.h:5063
parameter_const_range parameters() const
Definition Decl.h:5065
static bool classof(const Decl *D)
Definition Decl.h:5072
static OutlinedFunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5077
static DeclContext * castToDeclContext(const OutlinedFunctionDecl *D)
Definition Decl.h:5074
friend class ASTDeclReader
Definition Decl.h:5036
void setNothrow(bool Nothrow=true)
Definition Decl.cpp:5762
parameter_const_iterator param_end() const
Definition Decl.h:5069
static bool classofKind(Kind K)
Definition Decl.h:5073
llvm::iterator_range< parameter_const_iterator > parameter_const_range
Definition Decl.h:5064
static OutlinedFunctionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams)
Definition Decl.cpp:5750
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition Decl.cpp:5756
void setParam(unsigned i, ImplicitParamDecl *P)
Definition Decl.h:5057
friend class ASTDeclWriter
Definition Decl.h:5037
parameter_const_iterator param_begin() const
Definition Decl.h:5068
unsigned getNumParams() const
Definition Decl.h:5051
Represents a parameter to a function.
Definition Decl.h:1820
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition Decl.h:1901
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1880
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition Decl.h:1888
static bool classofKind(Kind K)
Definition Decl.h:1983
void setDefaultArg(Expr *defarg)
Definition Decl.cpp:3011
static ParmVarDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:2963
SourceLocation getExplicitObjectParamThisLoc() const
Definition Decl.h:1916
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition Decl.h:1961
ParmVarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition Decl.h:1826
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition Decl.h:1949
SourceRange getDefaultArgRange() const
Retrieve the source range that covers the entire default argument.
Definition Decl.cpp:3016
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3036
bool isObjCMethodParameter() const
Definition Decl.h:1863
ObjCDeclQualifier getObjCDeclQualifier() const
Definition Decl.h:1884
static constexpr unsigned getMaxFunctionScopeDepth()
Definition Decl.h:1875
const Expr * getDefaultArg() const
Definition Decl.h:1921
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1853
bool hasUninstantiatedDefaultArg() const
Definition Decl.h:1953
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition Decl.h:1848
bool isDestroyedInCallee() const
Determines whether this parameter is destroyed in the callee function.
Definition Decl.cpp:2984
bool hasInheritedDefaultArg() const
Definition Decl.h:1965
bool isExplicitObjectParameter() const
Definition Decl.h:1908
void setKNRPromoted(bool promoted)
Definition Decl.h:1904
friend class ASTDeclReader
Definition Decl.h:1986
QualType getOriginalType() const
Definition Decl.cpp:2955
const Expr * getUninstantiatedDefaultArg() const
Definition Decl.h:1932
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1912
Expr * getDefaultArg()
Definition Decl.cpp:2999
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3041
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3047
unsigned getFunctionScopeDepth() const
Definition Decl.h:1870
void setHasInheritedDefaultArg(bool I=true)
Definition Decl.h:1969
void setOwningFunction(DeclContext *FD)
Sets the function declaration that owns this ParmVarDecl.
Definition Decl.h:1979
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:2969
static bool classof(const Decl *D)
Definition Decl.h:1982
Represents a #pragma comment line.
Definition Decl.h:168
StringRef getArg() const
Definition Decl.h:191
static PragmaCommentDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned ArgSize)
Definition Decl.cpp:5594
friend class ASTDeclReader
Definition Decl.h:169
friend class ASTDeclWriter
Definition Decl.h:170
static bool classof(const Decl *D)
Definition Decl.h:194
PragmaMSCommentKind getCommentKind() const
Definition Decl.h:189
static bool classofKind(Kind K)
Definition Decl.h:195
Represents a #pragma detect_mismatch line.
Definition Decl.h:202
StringRef getName() const
Definition Decl.h:223
static PragmaDetectMismatchDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NameValueSize)
Definition Decl.cpp:5619
StringRef getValue() const
Definition Decl.h:224
static bool classofKind(Kind K)
Definition Decl.h:228
static bool classof(const Decl *D)
Definition Decl.h:227
A (possibly-)qualified type.
Definition TypeBase.h:938
Represents a struct/union/class.
Definition Decl.h:4464
bool hasLoadedFieldsFromExternalStorage() const
Definition Decl.h:4533
unsigned getODRHash()
Get precomputed ODRHash or add a new one.
Definition Decl.cpp:5497
bool hasNonTrivialToPrimitiveDestructCUnion() const
Definition Decl.h:4574
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5325
bool hasNonTrivialToPrimitiveCopyCUnion() const
Definition Decl.h:4582
bool isMsStruct(const ASTContext &C) const
Get whether or not this is an ms_struct which can be turned on with an attribute, pragma,...
Definition Decl.cpp:5391
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4520
bool canPassInRegisters() const
Determine whether this class can be passed in registers.
Definition Decl.h:4601
field_range noload_fields() const
noload_fields - Iterate over the fields stored in this record that are currently loaded; don't attemp...
Definition Decl.h:4687
unsigned getNumFields() const
Returns the number of fields (non-static data members) in this record.
Definition Decl.h:4680
RecordArgPassingKind getArgPassingRestrictions() const
Definition Decl.h:4605
RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl)
Definition Decl.cpp:5287
bool hasVolatileMember() const
Definition Decl.h:4527
bool hasFlexibleArrayMember() const
Definition Decl.h:4497
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Definition Decl.h:4566
const FieldDecl * findFirstNamedDataMember() const
Finds the first data member which has a name.
Definition Decl.cpp:5483
field_iterator noload_field_begin() const
Definition Decl.cpp:5364
const RecordDecl * getMostRecentDecl() const
Definition Decl.h:4493
void setArgPassingRestrictions(RecordArgPassingKind Kind)
Definition Decl.h:4610
void setNonTrivialToPrimitiveCopy(bool V)
Definition Decl.h:4554
bool hasObjectMember() const
Definition Decl.h:4524
bool isNonTrivialToPrimitiveDestroy() const
Definition Decl.h:4558
bool isNonTrivialToPrimitiveCopy() const
Definition Decl.h:4550
bool isCapturedRecord() const
Determine whether this record is a record for captured variables in CapturedStmt construct.
Definition Decl.cpp:5331
void setHasNonTrivialToPrimitiveCopyCUnion(bool V)
Definition Decl.h:4586
field_iterator field_end() const
Definition Decl.h:4670
field_range fields() const
Definition Decl.h:4667
llvm::iterator_range< specific_decl_iterator< FieldDecl > > field_range
Definition Decl.h:4665
bool isRandomized() const
Definition Decl.h:4622
void setHasNonTrivialToPrimitiveDestructCUnion(bool V)
Definition Decl.h:4578
friend class ASTDeclReader
Definition Decl.h:4469
static bool classofKind(Kind K)
Definition Decl.h:4705
void setHasFlexibleArrayMember(bool V)
Definition Decl.h:4501
void setParamDestroyedInCallee(bool V)
Definition Decl.h:4618
void setNonTrivialToPrimitiveDestroy(bool V)
Definition Decl.h:4562
void setHasObjectMember(bool val)
Definition Decl.h:4525
void setHasVolatileMember(bool val)
Definition Decl.h:4529
void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V)
Definition Decl.h:4570
void reorderDecls(const SmallVectorImpl< Decl * > &Decls)
Definition Decl.cpp:5402
void setIsRandomized(bool V)
Definition Decl.h:4624
bool isParamDestroyedInCallee() const
Definition Decl.h:4614
static RecordDecl * CreateDeserialized(const ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5318
bool noload_field_empty() const
Definition Decl.h:4697
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
Definition Decl.cpp:5439
static bool classof(const Decl *D)
Definition Decl.h:4704
RecordDecl * getMostRecentDecl()
Definition Decl.h:4490
const RecordDecl * getPreviousDecl() const
Definition Decl.h:4486
bool isOrContainsUnion() const
Returns whether this record is a union, or contains (at any nesting level) a union member.
Definition Decl.cpp:5339
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5370
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4648
bool hasUninitializedExplicitInitFields() const
Definition Decl.h:4590
field_iterator noload_field_end() const
Definition Decl.h:4692
void setCapturedRecord()
Mark the record as a record for captured variables in CapturedStmt construct.
Definition Decl.cpp:5335
specific_decl_iterator< FieldDecl > field_iterator
Definition Decl.h:4664
void setHasUninitializedExplicitInitFields(bool V)
Definition Decl.h:4594
RecordDecl * getPreviousDecl()
Definition Decl.h:4482
void setNonTrivialToPrimitiveDefaultInitialize(bool V)
Definition Decl.h:4546
RecordDecl * getDefinitionOrSelf() const
Definition Decl.h:4652
bool isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C structs.
Definition Decl.h:4542
friend class DeclContext
Definition Decl.h:4468
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4516
void setHasLoadedFieldsFromExternalStorage(bool val) const
Definition Decl.h:4537
bool field_empty() const
Definition Decl.h:4675
field_iterator field_begin() const
Definition Decl.cpp:5354
TranslationUnitDecl * getNextRedeclaration() const
Redeclarable(const ASTContext &Ctx)
DeclLink RedeclLink
Points to the next redeclaration in the chain.
llvm::iterator_range< redecl_iterator > redecl_range
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition Decl.h:5472
static DeclLink PreviousDeclLink(decl_type *D)
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition Stmt.h:85
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
void AddTaggedVal(uint64_t V, DiagnosticsEngine::ArgumentKind Kind) const
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1823
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3856
TagDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
void setTagKind(TagKind TK)
Definition Decl.h:4060
void setCompleteDefinitionRequired(bool V=true)
True if this complete decl is required to be complete for some existing use.
Definition Decl.h:3972
static TagDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4142
SourceRange getBraceRange() const
Definition Decl.h:3933
TagTypeKind TagKind
Definition Decl.h:3861
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3977
void demoteThisDefinitionToDeclaration()
Mark a definition as a declaration and maintain information it was a definition.
Definition Decl.h:4015
TagDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition Decl.h:3901
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:5008
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3952
bool isEnum() const
Definition Decl.h:4068
void setEmbeddedInDeclarator(bool isInDeclarator)
True if this tag declaration is "embedded" (i.e., defined or declared for the very first time) in the...
Definition Decl.h:3987
SourceLocation getInnerLocStart() const
Return SourceLocation representing start of source range ignoring outer template declarations.
Definition Decl.h:3938
bool isEmbeddedInDeclarator() const
True if this tag declaration is "embedded" (i.e., defined or declared for the very first time) in the...
Definition Decl.h:3981
bool isStructureOrClass() const
Definition Decl.h:4070
StringRef getKindName() const
Definition Decl.h:4052
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3957
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:4110
bool isStruct() const
Definition Decl.h:4064
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:3924
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:4093
static bool classofKind(Kind K)
Definition Decl.h:4136
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4985
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:4978
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4980
friend class ASTDeclReader
Definition Decl.h:3920
SourceLocation getOuterLocStart() const
Return SourceLocation representing start of source range taking into account any outer template decla...
Definition Decl.cpp:4968
bool isCompleteDefinitionRequired() const
Return true if this complete decl is required to be complete for some existing use.
Definition Decl.h:3966
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4972
void printAnonymousTagDeclLocation(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
Definition Decl.cpp:5042
bool isEntityBeingDefined() const
Determines whether this entity is in the process of being defined.
Definition Decl.h:4046
bool isFreeStanding() const
True if this tag is free standing, e.g. "struct foo;".
Definition Decl.h:3992
ArrayRef< TemplateParameterList * > getTemplateParameterLists() const
Definition Decl.h:4117
bool isUnion() const
Definition Decl.h:4067
void setBeingDefined(bool V=true)
True if this decl is currently being defined.
Definition Decl.h:3911
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:5022
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition Decl.cpp:5121
void completeDefinition()
Completes the definition of this tag declaration.
Definition Decl.cpp:4996
bool isInterface() const
Definition Decl.h:4065
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:5107
friend class ASTDeclWriter
Definition Decl.h:3921
void setTypeForDecl(const Type *TD)=delete
static bool classof(const Decl *D)
Definition Decl.h:4135
Redeclarable< TagDecl > redeclarable_base
Definition Decl.h:3891
bool isClass() const
Definition Decl.h:4066
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition Decl.h:4102
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type?
Definition Decl.h:4089
void setFreeStanding(bool isFreeStanding=true)
True if this tag is free standing, e.g. "struct foo;".
Definition Decl.h:3995
TagKind getTagKind() const
Definition Decl.h:4056
TagDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition Decl.h:3893
TagDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition Decl.h:3897
bool isThisDeclarationADemotedDefinition() const
Whether this declaration was a definition in some module but was forced to be a declaration.
Definition Decl.h:4009
redeclarable_base::redecl_range redecl_range
Definition Decl.h:3923
static DeclContext * castToDeclContext(const TagDecl *D)
Definition Decl.h:4138
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition Decl.h:4002
void printAnonymousTagDecl(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
Definition Decl.cpp:5066
const Type * getTypeForDecl() const =delete
TagDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setBraceRange(SourceRange R)
Definition Decl.h:3934
TagDecl * getDefinitionOrSelf() const
Definition Decl.h:4039
TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl, SourceLocation StartL)
Definition Decl.cpp:4951
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3960
A convenient class for passing around template argument information.
A template argument list.
Stores a list of template parameters for a TemplateDecl and its derived classes.
A declaration that models statements at global scope.
Definition Decl.h:4774
static bool classofKind(Kind K)
Definition Decl.h:4801
const Stmt * getStmt() const
Definition Decl.h:4794
void setSemiMissing(bool Missing=true)
Definition Decl.h:4797
unsigned getOrdinal() const
Definition Decl.h:4798
static bool classof(const Decl *D)
Definition Decl.h:4800
static TopLevelStmtDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5958
friend class ASTDeclReader
Definition Decl.h:4775
bool isSemiMissing() const
Definition Decl.h:4796
friend class ASTDeclWriter
Definition Decl.h:4776
static DeclContext * castToDeclContext(const TopLevelStmtDecl *D)
Definition Decl.h:4803
static TopLevelStmtDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4806
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5964
void setStmt(Stmt *S)
Definition Decl.cpp:5968
The top declaration context.
Definition Decl.h:106
static TranslationUnitDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:155
static DeclContext * castToDeclContext(const TranslationUnitDecl *D)
Definition Decl.h:152
redeclarable_base::redecl_range redecl_range
Definition Decl.h:132
const TranslationUnitDecl * getCanonicalDecl() const
Definition Decl.h:161
static bool classofKind(Kind K)
Definition Decl.h:151
NamespaceDecl * getAnonymousNamespace() const
Definition Decl.h:144
TranslationUnitDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
ASTContext & getASTContext() const
Definition Decl.h:142
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:133
static bool classof(const Decl *D)
Definition Decl.h:150
TranslationUnitDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this translation unit.
Definition Decl.h:160
TranslationUnitDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setAnonymousNamespace(NamespaceDecl *D)
Definition Decl.cpp:5572
static TypeAliasDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5904
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3845
void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT)
Definition Decl.h:3846
static bool classof(const Decl *D)
Definition Decl.h:3849
static bool classofKind(Kind K)
Definition Decl.h:3850
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5919
Declaration of an alias template.
void setLocStart(SourceLocation L)
Definition Decl.h:3687
static bool classofKind(Kind K)
Definition Decl.h:3697
void setTypeForDecl(const Type *TD)
Definition Decl.h:3681
friend class ASTReader
Definition Decl.h:3654
const Type * getTypeForDecl() const
Definition Decl.h:3677
friend class ASTContext
Definition Decl.h:3653
static bool classof(const Decl *D)
Definition Decl.h:3696
TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, const IdentifierInfo *Id, SourceLocation StartL=SourceLocation())
Definition Decl.h:3668
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:3688
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:3686
A container of type source information.
Definition TypeBase.h:8417
The base class of the type hierarchy.
Definition TypeBase.h:1879
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9366
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9299
static bool classofKind(Kind K)
Definition Decl.h:3822
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5910
static TypedefDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5891
static bool classof(const Decl *D)
Definition Decl.h:3821
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3701
TypedefNameDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition Decl.h:3724
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3751
Redeclarable< TypedefNameDecl > redeclarable_base
Definition Decl.h:3722
TypedefNameDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition Decl.h:3728
void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy)
Definition Decl.h:3766
redeclarable_base::redecl_range redecl_range
Definition Decl.h:3737
const Type * getTypeForDecl() const =delete
TypedefNameDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
TypedefNameDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setTypeForDecl(const Type *TD)=delete
bool isModed() const
Definition Decl.h:3747
static bool classof(const Decl *D)
Definition Decl.h:3795
const TypedefNameDecl * getCanonicalDecl() const
Definition Decl.h:3773
TypedefNameDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition Decl.h:3732
TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition Decl.h:3716
QualType getUnderlyingType() const
Definition Decl.h:3756
bool isTransparentTag() const
Determines if this typedef shares a name and spelling location with its underlying tag type,...
Definition Decl.h:3784
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:3738
TypedefNameDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this typedef-name.
Definition Decl.h:3772
void setTypeSourceInfo(TypeSourceInfo *newType)
Definition Decl.h:3762
static bool classofKind(Kind K)
Definition Decl.h:3796
TagDecl * getAnonDeclWithTypedefName(bool AnyRedecl=false) const
Retrieves the tag declaration for which this is the typedef name for linkage purposes,...
Definition Decl.cpp:5854
A set of unresolved declarations.
static bool classof(const Decl *D)
Definition Decl.h:748
ValueDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T)
Definition Decl.h:719
void setType(QualType newType)
Definition Decl.h:725
QualType getType() const
Definition Decl.h:724
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Definition Decl.cpp:5672
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Definition Decl.cpp:5660
static bool classofKind(Kind K)
Definition Decl.h:749
VarDecl * getPotentiallyDecomposedVarDecl()
Definition DeclCXX.cpp:3695
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition Decl.cpp:5666
const VarDecl * getPotentiallyDecomposedVarDecl() const
Definition Decl.h:739
Represents a variable declaration or definition.
Definition Decl.h:933
const VarDecl * getDefinition() const
Definition Decl.h:1357
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition Decl.cpp:2785
void setObjCForDecl(bool FRD)
Definition Decl.h:1561
Stmt ** getInitAddress()
Retrieve the address of the initializer expression.
Definition Decl.cpp:2407
const VarDecl * getInitializingDeclaration() const
Definition Decl.h:1406
void setCXXForRangeDecl(bool FRD)
Definition Decl.h:1550
DefinitionKind isThisDeclarationADefinition() const
Definition Decl.h:1332
bool isFunctionOrMethodVarDecl() const
Similar to isLocalVarDecl, but excludes variables declared in blocks.
Definition Decl.h:1291
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1594
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition Decl.cpp:2908
TLSKind getTLSKind() const
Definition Decl.cpp:2148
@ DAK_Uninstantiated
Definition Decl.h:1010
bool hasInit() const
Definition Decl.cpp:2383
bool hasICEInitializer(const ASTContext &Context) const
Determine whether the initializer of this variable is an integer constant expression.
Definition Decl.cpp:2632
redeclarable_base::redecl_range redecl_range
Definition Decl.h:1154
ParmVarDeclBitfields ParmVarDeclBits
Definition Decl.h:1131
void setARCPseudoStrong(bool PS)
Definition Decl.h:1573
VarDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition Decl.h:1141
@ NumParameterIndexBits
Definition Decl.h:1005
void setInitStyle(InitializationStyle Style)
Definition Decl.h:1477
void setEscapingByref()
Definition Decl.h:1632
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:1155
VarDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setCXXForRangeImplicitVar(bool FRV)
Definition Decl.h:1652
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
Definition Decl.h:1491
void setInitCapture(bool IC)
Definition Decl.h:1606
DefinitionKind hasDefinition() const
Definition Decl.h:1338
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition Decl.cpp:2101
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:2170
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a static data member.
Definition Decl.cpp:2446
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:2237
bool hasFlexibleArrayInit(const ASTContext &Ctx) const
Whether this variable has a flexible array member initialized with one or more elements.
Definition Decl.cpp:2837
bool isNoDestroy(const ASTContext &) const
Is destruction of this variable entirely suppressed?
Definition Decl.cpp:2811
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition Decl.h:1603
bool isCXXCondDecl() const
Definition Decl.h:1636
friend class StmtIteratorBase
Definition Decl.h:984
const APValue * getEvaluatedValue() const
Return the already-evaluated value of this variable's initializer, or nullptr if the value is not yet...
Definition Decl.cpp:2624
InitializationStyle
Initialization styles.
Definition Decl.h:936
@ ListInit
Direct list-initialization (C++11)
Definition Decl.h:944
@ CInit
C-style initialization with assignment.
Definition Decl.h:938
@ ParenListInit
Parenthesized list-initialization (C++20)
Definition Decl.h:947
@ CallInit
Call-style initialization (C++98)
Definition Decl.h:941
void setCXXCondDecl()
Definition Decl.h:1640
bool isObjCForDecl() const
Determine whether this variable is a for-loop declaration for a for-in statement in Objective-C.
Definition Decl.h:1557
void setStorageClass(StorageClass SC)
Definition Decl.cpp:2143
void setPreviousDeclInSameBlockScope(bool Same)
Definition Decl.h:1618
bool isInternalLinkageFileVar() const
Returns true if this is a file-scope variable with internal linkage.
Definition Decl.h:1223
bool hasInitWithSideEffects() const
Checks whether this declaration has an initializer with side effects.
Definition Decl.cpp:2429
bool isInlineSpecified() const
Definition Decl.h:1579
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition Decl.h:1307
static VarDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:2137
VarDecl * getTemplateInstantiationPattern() const
Retrieve the variable declaration from which this variable could be instantiated, if it is an instant...
Definition Decl.cpp:2702
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
Definition Decl.h:1248
VarDeclBitfields VarDeclBits
Definition Decl.h:1130
CharUnits getFlexibleArrayInitChars(const ASTContext &Ctx) const
If hasFlexibleArrayInit is true, compute the number of additional bytes necessary to store those elem...
Definition Decl.cpp:2852
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
Definition Decl.cpp:2644
void assignAddressSpace(const ASTContext &Ctxt, LangAS AS)
Apply a deduced address space, if one isn't already set.
Definition Decl.cpp:2915
bool isCXXForRangeDecl() const
Determine whether this variable is the for-range-declaration in a C++0x for-range statement.
Definition Decl.h:1547
friend class ASTDeclReader
Definition Decl.h:982
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
Definition Decl.cpp:2221
static bool classofKind(Kind K)
Definition Decl.h:1749
unsigned AllBits
Definition Decl.h:1129
const VarDecl * getDefinition(ASTContext &C) const
Definition Decl.h:1351
friend class ASTNodeImporter
Definition Decl.h:983
EvaluatedStmt * getEvaluatedStmt() const
Definition Decl.cpp:2556
bool mightBeUsableInConstantExpressions(const ASTContext &C) const
Determine whether this variable's value might be usable in a constant expression, according to the re...
Definition Decl.cpp:2471
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition Decl.cpp:2542
bool evaluateDestruction(SmallVectorImpl< PartialDiagnosticAt > &Notes) const
Evaluate the destruction of this variable to determine if it constitutes constant destruction.
static bool classof(const Decl *D)
Definition Decl.h:1748
bool isNRVOVariable() const
Determine whether this local variable can be used with the named return value optimization (NRVO).
Definition Decl.h:1537
void setInlineSpecified()
Definition Decl.h:1583
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
Definition Decl.h:1215
const VarDecl * getCanonicalDecl() const
Definition Decl.h:1313
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition Decl.cpp:2747
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition Decl.h:1366
bool isCXXForRangeImplicitVar() const
Whether this variable is the implicit '__range' variable in C++ range-based for loops.
Definition Decl.h:1647
bool isExceptionVariable() const
Determine whether this variable is the exception variable in a C++ catch statememt or an Objective-C ...
Definition Decl.h:1519
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For a static data member that was instantiated from a static data member of a class template,...
Definition Decl.cpp:2880
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition Decl.h:1180
void setNRVOVariable(bool NRVO)
Definition Decl.h:1540
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
Definition Decl.cpp:2826
bool checkForConstantInitialization(SmallVectorImpl< PartialDiagnosticAt > &Notes) const
Evaluate the initializer of this variable to determine whether it's a constant initializer.
Definition Decl.cpp:2660
bool isInline() const
Whether this variable is (C++1z) inline.
Definition Decl.h:1576
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1184
const Expr * getInit() const
Definition Decl.h:1392
bool isNonEscapingByref() const
Indicates the capture is a __block variable that is never captured by an escaping block.
Definition Decl.cpp:2690
bool isInExternCContext() const
Determines whether this variable's context is, or is nested within, a C++ extern "C" linkage spec.
Definition Decl.cpp:2229
NonParmVarDeclBitfields NonParmVarDeclBits
Definition Decl.h:1132
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
Definition Decl.h:1239
InitType Init
The initializer for this variable or, for a ParmVarDecl, the C++ default argument.
Definition Decl.h:979
const APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
Definition Decl.cpp:2560
Redeclarable< VarDecl > redeclarable_base
Definition Decl.h:1139
bool isARCPseudoStrong() const
Determine whether this variable is an ARC pseudo-__strong variable.
Definition Decl.h:1572
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
Definition Decl.h:1191
VarDecl * getInitializingDeclaration()
Get the initializing declaration of this variable, if any.
Definition Decl.cpp:2414
void setConstexpr(bool IC)
Definition Decl.h:1597
TLSKind
Kinds of thread-local storage.
Definition Decl.h:951
@ TLS_Static
TLS with a known-constant initializer.
Definition Decl.h:956
@ TLS_Dynamic
TLS with a dynamic initializer.
Definition Decl.h:959
@ TLS_None
Not a TLS variable.
Definition Decl.h:953
void setInit(Expr *I)
Definition Decl.cpp:2462
VarDecl * getActingDefinition()
Get the tentative definition that acts as the real definition in a TU.
Definition Decl.cpp:2330
@ TentativeDefinition
This declaration is a tentative definition.
Definition Decl.h:1322
@ DeclarationOnly
This declaration is only a declaration.
Definition Decl.h:1319
@ Definition
This declaration is definitely a definition.
Definition Decl.h:1325
@ NumScopeDepthOrObjCQualsBits
Definition Decl.h:1014
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition Decl.cpp:2790
bool isExternC() const
Determines whether this variable is a variable with external, C linkage.
Definition Decl.cpp:2225
VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass SC)
Definition Decl.cpp:2114
void deduceParmAddressSpace(const ASTContext &Ctxt)
Definition Decl.cpp:2936
llvm::PointerUnion< Stmt *, EvaluatedStmt * > InitType
Definition Decl.h:975
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
Definition Decl.h:1275
bool isDirectInit() const
Whether the initializer is a direct-initializer (list or call).
Definition Decl.h:1496
VarDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition Decl.h:1149
StorageDuration getStorageDuration() const
Get the storage duration of this variable, per C++ [basic.stc].
Definition Decl.h:1251
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1175
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
Definition Decl.cpp:2686
void setImplicitlyInline()
Definition Decl.h:1588
bool isThisDeclarationADemotedDefinition() const
If this definition should pretend to be a declaration.
Definition Decl.h:1501
bool isPreviousDeclInSameBlockScope() const
Whether this local extern variable declaration's previous declaration was declared in the same block ...
Definition Decl.h:1613
VarDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
bool isUsableInConstantExpressions(const ASTContext &C) const
Determine whether this variable's value can be used in a constant expression, according to the releva...
Definition Decl.cpp:2513
bool isInExternCXXContext() const
Determines whether this variable's context is, or is nested within, a C++ extern "C++" linkage spec.
Definition Decl.cpp:2233
SourceLocation getPointOfInstantiation() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition Decl.cpp:2775
bool hasDependentAlignment() const
Determines if this variable's alignment is dependent.
Definition Decl.cpp:2694
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Get the template specialization kind of this variable for the purposes of template instantiation.
Definition Decl.cpp:2765
VarDecl * getDefinition()
Definition Decl.h:1354
bool isLocalVarDeclOrParm() const
Similar to isLocalVarDecl but also includes parameters.
Definition Decl.h:1286
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition Decl.cpp:2754
const VarDecl * getActingDefinition() const
Definition Decl.h:1345
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition Decl.h:1382
void setExceptionVariable(bool EV)
Definition Decl.h:1522
bool isKnownToBeDefined() const
Definition Decl.cpp:2794
VarDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition Decl.h:1145
void demoteThisDefinitionToDeclaration()
This is a definition which should be demoted to a declaration.
Definition Decl.h:1511
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition Decl.cpp:2873
Declaration of a variable template.
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:4064
Defines the Linkage enumeration and various utility functions.
Top level wrappers for InstallAPI frontend operations.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
bool isa(CodeGen::Address addr)
Definition Address.h:330
LazyOffsetPtr< Stmt, uint64_t, &ExternalASTSource::GetExternalDeclStmt > LazyDeclStmtPtr
A lazy pointer to a statement.
PragmaMSCommentKind
Definition PragmaKinds.h:14
ConstexprSpecKind
Define the kind of constexpr specifier.
Definition Specifiers.h:36
InClassInitStyle
In-class initialization styles for non-static data members.
Definition Specifiers.h:275
@ ICIS_CopyInit
Copy initialization.
Definition Specifiers.h:277
@ ICIS_ListInit
Direct list-initialization.
Definition Specifiers.h:278
@ ICIS_NoInit
No in-class initializer.
Definition Specifiers.h:276
bool IsEnumDeclComplete(EnumDecl *ED)
Check if the given decl is complete.
Definition Decl.h:5513
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have.
Definition Linkage.h:63
StorageClass
Storage classes.
Definition Specifiers.h:252
@ SC_Auto
Definition Specifiers.h:260
@ SC_PrivateExtern
Definition Specifiers.h:257
@ SC_Extern
Definition Specifiers.h:255
@ SC_Register
Definition Specifiers.h:261
@ SC_Static
Definition Specifiers.h:256
@ SC_None
Definition Specifiers.h:254
ThreadStorageClassSpecifier
Thread storage-class-specifier.
Definition Specifiers.h:239
@ TSCS_thread_local
C++11 thread_local.
Definition Specifiers.h:245
@ TSCS_unspecified
Definition Specifiers.h:240
static constexpr StringRef getOpenMPVariantManglingSeparatorStr()
OpenMP variants are mangled early based on their OpenMP context selector.
Definition Decl.h:5530
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition Linkage.h:24
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Definition Linkage.h:54
@ Asm
Assembly: we accept this only so that we can preprocess it.
StorageDuration
The storage duration for an object (per C++ [basic.stc]).
Definition Specifiers.h:341
@ SD_Thread
Thread storage duration.
Definition Specifiers.h:344
@ SD_Static
Static storage duration.
Definition Specifiers.h:345
@ SD_Automatic
Automatic storage duration (most local variables).
Definition Specifiers.h:343
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
Definition Parser.h:81
bool hasArmZT0State(const FunctionDecl *FD)
Returns whether the given FunctionDecl has Arm ZT0 state.
Definition Decl.cpp:6206
TagTypeKind
The kind of a tag type.
Definition TypeBase.h:6039
@ Interface
The "__interface" keyword.
Definition TypeBase.h:6044
@ Struct
The "struct" keyword.
Definition TypeBase.h:6041
@ Class
The "class" keyword.
Definition TypeBase.h:6050
@ Union
The "union" keyword.
Definition TypeBase.h:6047
@ Enum
The "enum" keyword.
Definition TypeBase.h:6053
bool IsEnumDeclScoped(EnumDecl *ED)
Check if the given decl is scoped.
Definition Decl.h:5523
DefaultedComparisonKind
Kinds of defaulted comparison operator functions.
Definition Decl.h:2030
@ Relational
This is an <, <=, >, or >= that should be implemented as a rewrite in terms of a <=> comparison.
Definition Decl.h:2044
@ NotEqual
This is an operator!= that should be implemented as a rewrite in terms of a == comparison.
Definition Decl.h:2041
@ ThreeWay
This is an operator<=> that should be implemented as a series of subobject comparisons.
Definition Decl.h:2038
@ None
This is not a defaultable comparison operator.
Definition Decl.h:2032
LangAS
Defines the address space values used by the address space qualifier of QualType.
RecordArgPassingKind
Enum that represents the different ways arguments are passed to and returned from function calls.
Definition Decl.h:4441
@ CanPassInRegs
The argument of this type can be passed directly in registers.
Definition Decl.h:4443
@ CanNeverPassInRegs
The argument of this type cannot be passed directly in registers.
Definition Decl.h:4457
@ CannotPassInRegs
The argument of this type cannot be passed directly in registers.
Definition Decl.h:4452
CXXSpecialMemberKind
Kinds of C++ special members.
Definition Decl.h:2019
MultiVersionKind
Definition Decl.h:2009
bool isExternalFormalLinkage(Linkage L)
Definition Linkage.h:117
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition Specifiers.h:192
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition Specifiers.h:198
U cast(CodeGen::Address addr)
Definition Address.h:327
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6028
bool IsArmStreamingFunction(const FunctionDecl *FD, bool IncludeLocallyStreaming)
Returns whether the given FunctionDecl has an __arm[_locally]_streaming attribute.
Definition Decl.cpp:6185
ReservedIdentifierStatus
bool isExternallyVisible(Linkage L)
Definition Linkage.h:90
ImplicitParamKind
Defines the kind of the implicit parameter: is this an implicit parameter with pointer to 'this',...
Definition Decl.h:1755
@ CXXThis
Parameter for C++ 'this' argument.
Definition Decl.h:1763
@ ThreadPrivateVar
Parameter for Thread private variable.
Definition Decl.h:1772
@ Other
Other implicit parameter.
Definition Decl.h:1775
@ CXXVTT
Parameter for C++ virtual table pointers.
Definition Decl.h:1766
@ ObjCSelf
Parameter for Objective-C 'self' argument.
Definition Decl.h:1757
@ ObjCCmd
Parameter for Objective-C '_cmd' argument.
Definition Decl.h:1760
@ CapturedContext
Parameter for captured context.
Definition Decl.h:1769
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_None
no exception specification
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition Visibility.h:34
bool hasArmZAState(const FunctionDecl *FD)
Returns whether the given FunctionDecl has Arm ZA state.
Definition Decl.cpp:6199
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
#define false
Definition stdbool.h:26
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
bool isNull() const
Definition Decl.h:100
AssociatedConstraint(const Expr *ConstraintExpr, UnsignedOrNone ArgPackSubstIndex=std::nullopt)
Definition Decl.h:94
const Expr * ConstraintExpr
Definition Decl.h:89
UnsignedOrNone ArgPackSubstIndex
Definition Decl.h:90
constexpr AssociatedConstraint()=default
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition DeclBase.h:102
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
Structure used to store a statement, the constant value to which it was evaluated (if any),...
Definition Decl.h:886
unsigned CheckedForICEInit
Definition Decl.h:915
unsigned WasEvaluated
Whether this statement was already evaluated.
Definition Decl.h:889
unsigned HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition Decl.h:900
LazyDeclStmtPtr Value
Definition Decl.h:922
unsigned HasICEInit
In C++98, whether the initializer is an ICE.
Definition Decl.h:913
unsigned HasSideEffects
Definition Decl.h:918
APValue Evaluated
Definition Decl.h:923
unsigned CheckedForSideEffects
Definition Decl.h:920
unsigned IsEvaluating
Whether this statement is being evaluated.
Definition Decl.h:893
unsigned HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition Decl.h:908
static StringRef getTagTypeKindName(TagTypeKind Kind)
Definition TypeBase.h:6078
Describes how types, statements, expressions, and declarations should be printed.
A struct with extended info about a syntactic name qualifier, to be used for the case of out-of-line ...
Definition Decl.h:754
QualifierInfo & operator=(const QualifierInfo &)=delete
TemplateParameterList ** TemplParamLists
A new-allocated array of size NumTemplParamLists, containing pointers to the "outer" template paramet...
Definition Decl.h:768
NestedNameSpecifierLoc QualifierLoc
Definition Decl.h:755
QualifierInfo(const QualifierInfo &)=delete
unsigned NumTemplParamLists
The number of "outer" template parameter lists.
Definition Decl.h:761
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Sets info about "outer" template parameter lists.
Definition Decl.cpp:2081
The parameters to pass to a usual operator delete.
Definition ExprCXX.h:2349