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 const ParmVarDecl *getParamDecl(unsigned i) const {
2929 assert(i < getNumParams() && "Illegal param #");
2930 return ParamInfo[i];
2931 }
2933 assert(i < getNumParams() && "Illegal param #");
2934 return ParamInfo[i];
2935 }
2937 setParams(getASTContext(), NewParamInfo);
2938 }
2939
2940 /// Returns the minimum number of arguments needed to call this function. This
2941 /// may be fewer than the number of function parameters, if some of the
2942 /// parameters have default arguments (in C++).
2943 unsigned getMinRequiredArguments() const;
2944
2945 /// Returns the minimum number of non-object arguments needed to call this
2946 /// function. This produces the same value as getMinRequiredArguments except
2947 /// it does not count the explicit object argument, if any.
2948 unsigned getMinRequiredExplicitArguments() const;
2949
2951
2952 unsigned getNumNonObjectParams() const;
2953
2954 const ParmVarDecl *getNonObjectParameter(unsigned I) const {
2956 }
2957
2961
2962 /// Determine whether this function has a single parameter, or multiple
2963 /// parameters where all but the first have default arguments.
2964 ///
2965 /// This notion is used in the definition of copy/move constructors and
2966 /// initializer list constructors. Note that, unlike getMinRequiredArguments,
2967 /// parameter packs are not treated specially here.
2968 bool hasOneParamOrDefaultArgs() const;
2969
2970 /// Find the source location information for how the type of this function
2971 /// was written. May be absent (for example if the function was declared via
2972 /// a typedef) and may contain a different type from that of the function
2973 /// (for example if the function type was adjusted by an attribute).
2975
2977 return getType()->castAs<FunctionType>()->getReturnType();
2978 }
2979
2980 /// Attempt to compute an informative source range covering the
2981 /// function return type. This may omit qualifiers and other information with
2982 /// limited representation in the AST.
2984
2985 /// Attempt to compute an informative source range covering the
2986 /// function parameters, including the ellipsis of a variadic function.
2987 /// The source range excludes the parentheses, and is invalid if there are
2988 /// no parameters and no ellipsis.
2990
2991 /// Get the declared return type, which may differ from the actual return
2992 /// type if the return type is deduced.
2994 auto *TSI = getTypeSourceInfo();
2995 QualType T = TSI ? TSI->getType() : getType();
2996 return T->castAs<FunctionType>()->getReturnType();
2997 }
2998
2999 /// Gets the ExceptionSpecificationType as declared.
3001 auto *TSI = getTypeSourceInfo();
3002 QualType T = TSI ? TSI->getType() : getType();
3003 const auto *FPT = T->getAs<FunctionProtoType>();
3004 return FPT ? FPT->getExceptionSpecType() : EST_None;
3005 }
3006
3007 /// Attempt to compute an informative source range covering the
3008 /// function exception specification, if any.
3010
3011 /// Determine the type of an expression that calls this function.
3016
3017 /// Returns the storage class as written in the source. For the
3018 /// computed linkage of symbol, see getLinkage.
3020 return static_cast<StorageClass>(FunctionDeclBits.SClass);
3021 }
3022
3023 /// Sets the storage class as written in the source.
3025 FunctionDeclBits.SClass = SClass;
3026 }
3027
3028 /// Determine whether the "inline" keyword was specified for this
3029 /// function.
3030 bool isInlineSpecified() const { return FunctionDeclBits.IsInlineSpecified; }
3031
3032 /// Set whether the "inline" keyword was specified for this function.
3033 void setInlineSpecified(bool I) {
3034 FunctionDeclBits.IsInlineSpecified = I;
3035 FunctionDeclBits.IsInline = I;
3036 }
3037
3038 /// Determine whether the function was declared in source context
3039 /// that requires constrained FP intrinsics
3040 bool UsesFPIntrin() const { return FunctionDeclBits.UsesFPIntrin; }
3041
3042 /// Set whether the function was declared in source context
3043 /// that requires constrained FP intrinsics
3044 void setUsesFPIntrin(bool I) { FunctionDeclBits.UsesFPIntrin = I; }
3045
3046 /// Flag that this function is implicitly inline.
3047 void setImplicitlyInline(bool I = true) { FunctionDeclBits.IsInline = I; }
3048
3049 /// Determine whether this function should be inlined, because it is
3050 /// either marked "inline" or "constexpr" or is a member function of a class
3051 /// that was defined in the class body.
3052 bool isInlined() const { return FunctionDeclBits.IsInline; }
3053
3055
3056 bool isMSExternInline() const;
3057
3059
3060 bool isStatic() const { return getStorageClass() == SC_Static; }
3061
3062 /// Whether this function declaration represents an C++ overloaded
3063 /// operator, e.g., "operator+".
3065 return getOverloadedOperator() != OO_None;
3066 }
3067
3069
3070 const IdentifierInfo *getLiteralIdentifier() const;
3071
3072 /// If this function is an instantiation of a member function
3073 /// of a class template specialization, retrieves the function from
3074 /// which it was instantiated.
3075 ///
3076 /// This routine will return non-NULL for (non-templated) member
3077 /// functions of class templates and for instantiations of function
3078 /// templates. For example, given:
3079 ///
3080 /// \code
3081 /// template<typename T>
3082 /// struct X {
3083 /// void f(T);
3084 /// };
3085 /// \endcode
3086 ///
3087 /// The declaration for X<int>::f is a (non-templated) FunctionDecl
3088 /// whose parent is the class template specialization X<int>. For
3089 /// this declaration, getInstantiatedFromFunction() will return
3090 /// the FunctionDecl X<T>::A. When a complete definition of
3091 /// X<int>::A is required, it will be instantiated from the
3092 /// declaration returned by getInstantiatedFromMemberFunction().
3094
3095 /// What kind of templated function this is.
3097
3098 /// If this function is an instantiation of a member function of a
3099 /// class template specialization, retrieves the member specialization
3100 /// information.
3102
3103 /// Specify that this record is an instantiation of the
3104 /// member function FD.
3107 setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
3108 }
3109
3110 /// Specify that this function declaration was instantiated from a
3111 /// FunctionDecl FD. This is only used if this is a function declaration
3112 /// declared locally inside of a function template.
3114
3116
3117 /// Retrieves the function template that is described by this
3118 /// function declaration.
3119 ///
3120 /// Every function template is represented as a FunctionTemplateDecl
3121 /// and a FunctionDecl (or something derived from FunctionDecl). The
3122 /// former contains template properties (such as the template
3123 /// parameter lists) while the latter contains the actual
3124 /// description of the template's
3125 /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
3126 /// FunctionDecl that describes the function template,
3127 /// getDescribedFunctionTemplate() retrieves the
3128 /// FunctionTemplateDecl from a FunctionDecl.
3130
3132
3133 /// Determine whether this function is a function template
3134 /// specialization.
3136
3137 /// If this function is actually a function template specialization,
3138 /// retrieve information about this function template specialization.
3139 /// Otherwise, returns NULL.
3141
3142 /// Determines whether this function is a function template
3143 /// specialization or a member of a class template specialization that can
3144 /// be implicitly instantiated.
3145 bool isImplicitlyInstantiable() const;
3146
3147 /// Determines if the given function was instantiated from a
3148 /// function template.
3149 bool isTemplateInstantiation() const;
3150
3151 /// Retrieve the function declaration from which this function could
3152 /// be instantiated, if it is an instantiation (rather than a non-template
3153 /// or a specialization, for example).
3154 ///
3155 /// If \p ForDefinition is \c false, explicit specializations will be treated
3156 /// as if they were implicit instantiations. This will then find the pattern
3157 /// corresponding to non-definition portions of the declaration, such as
3158 /// default arguments and the exception specification.
3159 FunctionDecl *
3160 getTemplateInstantiationPattern(bool ForDefinition = true) const;
3161
3162 /// Retrieve the primary template that this function template
3163 /// specialization either specializes or was instantiated from.
3164 ///
3165 /// If this function declaration is not a function template specialization,
3166 /// returns NULL.
3168
3169 /// Retrieve the template arguments used to produce this function
3170 /// template specialization from the primary template.
3171 ///
3172 /// If this function declaration is not a function template specialization,
3173 /// returns NULL.
3175
3176 /// Retrieve the template argument list as written in the sources,
3177 /// if any.
3178 ///
3179 /// If this function declaration is not a function template specialization
3180 /// or if it had no explicit template argument list, returns NULL.
3181 /// Note that it an explicit template argument list may be written empty,
3182 /// e.g., template<> void foo<>(char* s);
3185
3186 /// Specify that this function declaration is actually a function
3187 /// template specialization.
3188 ///
3189 /// \param Template the function template that this function template
3190 /// specialization specializes.
3191 ///
3192 /// \param TemplateArgs the template arguments that produced this
3193 /// function template specialization from the template.
3194 ///
3195 /// \param InsertToken If set, the insert token in the function template
3196 /// specialization set where the function template specialization data will
3197 /// be inserted.
3198 ///
3199 /// \param TSK the kind of template specialization this is.
3200 ///
3201 /// \param TemplateArgsAsWritten location info of template arguments.
3202 ///
3203 /// \param PointOfInstantiation point at which the function template
3204 /// specialization was first instantiated.
3207 llvm::FoldingSetInsertToken InsertToken,
3209 TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
3210 SourceLocation PointOfInstantiation = SourceLocation()) {
3211 setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
3212 InsertToken, TSK, TemplateArgsAsWritten,
3213 PointOfInstantiation);
3214 }
3215
3216 /// Specifies that this function declaration is actually a
3217 /// dependent function template specialization.
3219 ASTContext &Context, const UnresolvedSetImpl &Templates,
3220 const TemplateArgumentListInfo *TemplateArgs);
3221
3224
3225 /// Determine what kind of template instantiation this function
3226 /// represents.
3228
3229 /// Determine the kind of template specialization this function represents
3230 /// for the purpose of template instantiation.
3233
3234 /// Determine what kind of template instantiation this function
3235 /// represents.
3237 SourceLocation PointOfInstantiation = SourceLocation());
3238
3239 /// True if both __host__ and __device__ are implicit attributes and this is
3240 /// (or is a member of) an explicit template instantiation.
3242
3243 /// Retrieve the (first) point of instantiation of a function template
3244 /// specialization or a member of a class template specialization.
3245 ///
3246 /// \returns the first point of instantiation, if this function was
3247 /// instantiated from a template; otherwise, returns an invalid source
3248 /// location.
3250
3251 /// Determine whether this is or was instantiated from an out-of-line
3252 /// definition of a member function.
3253 bool isOutOfLine() const override;
3254
3255 /// Identify a memory copying or setting function.
3256 /// If the given function is a memory copy or setting function, returns
3257 /// the corresponding Builtin ID. If the function is not a memory function,
3258 /// returns 0.
3259 unsigned getMemoryFunctionKind() const;
3260
3261 /// Returns ODRHash of the function. This value is calculated and
3262 /// stored on first call, then the stored value returned on the other calls.
3263 unsigned getODRHash();
3264
3265 /// Returns cached ODRHash of the function. This must have been previously
3266 /// computed and stored.
3267 unsigned getODRHash() const;
3268
3270 // Effects may differ between declarations, but they should be propagated
3271 // from old to new on any redeclaration, so it suffices to look at
3272 // getMostRecentDecl().
3273 if (const auto *FPT =
3274 getMostRecentDecl()->getType()->getAs<FunctionProtoType>())
3275 return FPT->getFunctionEffects();
3276 return {};
3277 }
3278
3279 // Implement isa/cast/dyncast/etc.
3280 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3281 static bool classofKind(Kind K) {
3282 return K >= firstFunction && K <= lastFunction;
3283 }
3285 return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
3286 }
3288 return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
3289 }
3290
3291 bool isReferenceableKernel() const;
3292};
3293
3294/// Represents a member of a struct/union/class.
3295class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
3296 /// The kinds of value we can store in StorageKind.
3297 ///
3298 /// Note that this is compatible with InClassInitStyle except for
3299 /// ISK_CapturedVLAType.
3300 enum InitStorageKind {
3301 /// If the pointer is null, there's nothing special. Otherwise,
3302 /// this is a bitfield and the pointer is the Expr* storing the
3303 /// bit-width.
3304 ISK_NoInit = (unsigned) ICIS_NoInit,
3305
3306 /// The pointer is an (optional due to delayed parsing) Expr*
3307 /// holding the copy-initializer.
3308 ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
3309
3310 /// The pointer is an (optional due to delayed parsing) Expr*
3311 /// holding the list-initializer.
3312 ISK_InClassListInit = (unsigned) ICIS_ListInit,
3313
3314 /// The pointer is a VariableArrayType* that's been captured;
3315 /// the enclosing context is a lambda or captured statement.
3316 ISK_CapturedVLAType,
3317 };
3318
3319 LLVM_PREFERRED_TYPE(bool)
3320 unsigned BitField : 1;
3321 LLVM_PREFERRED_TYPE(bool)
3322 unsigned Mutable : 1;
3323 LLVM_PREFERRED_TYPE(InitStorageKind)
3324 unsigned StorageKind : 2;
3325 mutable unsigned CachedFieldIndex : 28;
3326
3327 /// If this is a bitfield with a default member initializer, this
3328 /// structure is used to represent the two expressions.
3329 struct InitAndBitWidthStorage {
3331 Expr *BitWidth;
3332 };
3333
3334 /// Storage for either the bit-width, the in-class initializer, or
3335 /// both (via InitAndBitWidth), or the captured variable length array bound.
3336 ///
3337 /// If the storage kind is ISK_InClassCopyInit or
3338 /// ISK_InClassListInit, but the initializer is null, then this
3339 /// field has an in-class initializer that has not yet been parsed
3340 /// and attached.
3341 // FIXME: Tail-allocate this to reduce the size of FieldDecl in the
3342 // overwhelmingly common case that we have none of these things.
3343 union {
3344 // Active member if ISK is not ISK_CapturedVLAType and BitField is false.
3346 // Active member if ISK is ISK_NoInit and BitField is true.
3348 // Active member if ISK is ISK_InClass*Init and BitField is true.
3349 InitAndBitWidthStorage *InitAndBitWidth;
3350 // Active member if ISK is ISK_CapturedVLAType.
3352 };
3353
3354protected:
3356 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
3357 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3358 InClassInitStyle InitStyle)
3359 : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), BitField(false),
3360 Mutable(Mutable), StorageKind((InitStorageKind)InitStyle),
3361 CachedFieldIndex(0), Init() {
3362 if (BW)
3363 setBitWidth(BW);
3364 }
3365
3366public:
3367 friend class ASTDeclReader;
3368 friend class ASTDeclWriter;
3369
3370 static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
3371 SourceLocation StartLoc, SourceLocation IdLoc,
3372 const IdentifierInfo *Id, QualType T,
3373 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3374 InClassInitStyle InitStyle);
3375
3377
3378 /// Returns the index of this field within its record,
3379 /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
3380 unsigned getFieldIndex() const {
3381 const FieldDecl *Canonical = getCanonicalDecl();
3382 if (Canonical->CachedFieldIndex == 0) {
3383 Canonical->setCachedFieldIndex();
3384 assert(Canonical->CachedFieldIndex != 0);
3385 }
3386 return Canonical->CachedFieldIndex - 1;
3387 }
3388
3389private:
3390 /// Set CachedFieldIndex to the index of this field plus one.
3391 void setCachedFieldIndex() const;
3392
3393public:
3394 /// Determines whether this field is mutable (C++ only).
3395 bool isMutable() const { return Mutable; }
3396
3397 /// Determines whether this field is a bitfield.
3398 bool isBitField() const { return BitField; }
3399
3400 /// Determines whether this is an unnamed bitfield.
3401 bool isUnnamedBitField() const { return isBitField() && !getDeclName(); }
3402
3403 /// Determines whether this field is a
3404 /// representative for an anonymous struct or union. Such fields are
3405 /// unnamed and are implicitly generated by the implementation to
3406 /// store the data for the anonymous union or struct.
3407 bool isAnonymousStructOrUnion() const;
3408
3409 /// Returns the expression that represents the bit width, if this field
3410 /// is a bit field. For non-bitfields, this returns \c nullptr.
3412 if (!BitField)
3413 return nullptr;
3414 return hasInClassInitializer() ? InitAndBitWidth->BitWidth : BitWidth;
3415 }
3416
3417 /// Determines whether the bit width of this field is a constant integer.
3418 /// This may not always be the case, such as inside template-dependent
3419 /// expressions.
3420 bool hasConstantIntegerBitWidth() const;
3421
3422 /// Computes the bit width of this field, if this is a bit field.
3423 /// May not be called on non-bitfields.
3424 /// Note that in order to successfully use this function, the bitwidth
3425 /// expression must be a ConstantExpr with a valid integer result set.
3426 unsigned getBitWidthValue() const;
3427
3428 /// Set the bit-field width for this member.
3429 // Note: used by some clients (i.e., do not remove it).
3430 void setBitWidth(Expr *Width) {
3431 assert(!hasCapturedVLAType() && !BitField &&
3432 "bit width or captured type already set");
3433 assert(Width && "no bit width specified");
3436 new (getASTContext()) InitAndBitWidthStorage{Init, Width};
3437 else
3438 BitWidth = Width;
3439 BitField = true;
3440 }
3441
3442 /// Remove the bit-field width from this member.
3443 // Note: used by some clients (i.e., do not remove it).
3445 assert(isBitField() && "no bitfield width to remove");
3446 if (hasInClassInitializer()) {
3447 // Read the old initializer before we change the active union member.
3448 auto ExistingInit = InitAndBitWidth->Init;
3449 Init = ExistingInit;
3450 }
3451 BitField = false;
3452 }
3453
3454 /// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
3455 /// at all and instead act as a separator between contiguous runs of other
3456 /// bit-fields.
3457 bool isZeroLengthBitField() const;
3458
3459 /// Determine if this field is a subobject of zero size, that is, either a
3460 /// zero-length bit-field or a field of empty class type with the
3461 /// [[no_unique_address]] attribute.
3462 bool isZeroSize(const ASTContext &Ctx) const;
3463
3464 /// Determine if this field is of potentially-overlapping class type, that
3465 /// is, subobject with the [[no_unique_address]] attribute
3466 bool isPotentiallyOverlapping() const;
3467
3468 /// Get the kind of (C++11) default member initializer that this field has.
3470 return (StorageKind == ISK_CapturedVLAType ? ICIS_NoInit
3471 : (InClassInitStyle)StorageKind);
3472 }
3473
3474 /// Determine whether this member has a C++11 default member initializer.
3476 return getInClassInitStyle() != ICIS_NoInit;
3477 }
3478
3479 /// Determine whether getInClassInitializer() would return a non-null pointer
3480 /// without deserializing the initializer.
3482 return hasInClassInitializer() && (BitField ? InitAndBitWidth->Init : Init);
3483 }
3484
3485 /// Get the C++11 default member initializer for this member, or null if one
3486 /// has not been set. If a valid declaration has a default member initializer,
3487 /// but this returns null, then we have not parsed and attached it yet.
3488 Expr *getInClassInitializer() const;
3489
3490 /// Set the C++11 in-class initializer for this member.
3491 void setInClassInitializer(Expr *NewInit);
3492
3493 /// Find the FieldDecl specified in a FAM's "counted_by" attribute. Returns
3494 /// \p nullptr if either the attribute or the field doesn't exist.
3495 const FieldDecl *findCountedByField() const;
3496
3497private:
3498 void setLazyInClassInitializer(LazyDeclStmtPtr NewInit);
3499
3500public:
3501 /// Remove the C++11 in-class initializer from this member.
3503 assert(hasInClassInitializer() && "no initializer to remove");
3504 StorageKind = ISK_NoInit;
3505 if (BitField) {
3506 // Read the bit width before we change the active union member.
3507 Expr *ExistingBitWidth = InitAndBitWidth->BitWidth;
3508 BitWidth = ExistingBitWidth;
3509 }
3510 }
3511
3512 /// Determine whether this member captures the variable length array
3513 /// type.
3514 bool hasCapturedVLAType() const {
3515 return StorageKind == ISK_CapturedVLAType;
3516 }
3517
3518 /// Get the captured variable length array type.
3520 return hasCapturedVLAType() ? CapturedVLAType : nullptr;
3521 }
3522
3523 /// Set the captured variable length array type for this field.
3524 void setCapturedVLAType(const VariableArrayType *VLAType);
3525
3526 /// Returns the parent of this field declaration, which
3527 /// is the struct in which this field is defined.
3528 ///
3529 /// Returns null if this is not a normal class/struct field declaration, e.g.
3530 /// ObjCAtDefsFieldDecl, ObjCIvarDecl.
3531 const RecordDecl *getParent() const {
3532 return dyn_cast<RecordDecl>(getDeclContext());
3533 }
3534
3536 return dyn_cast<RecordDecl>(getDeclContext());
3537 }
3538
3539 SourceRange getSourceRange() const override LLVM_READONLY;
3540
3541 /// Retrieves the canonical declaration of this field.
3542 FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3543 const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3544
3545 // Implement isa/cast/dyncast/etc.
3546 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3547 static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
3548
3549 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
3550};
3551
3552/// An instance of this object exists for each enum constant
3553/// that is defined. For example, in "enum X {a,b}", each of a/b are
3554/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
3555/// TagType for the X EnumDecl.
3557 public Mergeable<EnumConstantDecl>,
3558 public APIntStorage {
3559 Stmt *Init; // an integer constant expression
3560 bool IsUnsigned;
3561
3562protected:
3564 IdentifierInfo *Id, QualType T, Expr *E,
3565 const llvm::APSInt &V);
3566
3567public:
3568 friend class StmtIteratorBase;
3569
3572 QualType T, Expr *E,
3573 const llvm::APSInt &V);
3575
3576 const Expr *getInitExpr() const { return (const Expr*) Init; }
3577 Expr *getInitExpr() { return (Expr*) Init; }
3578 llvm::APSInt getInitVal() const {
3579 return llvm::APSInt(getValue(), IsUnsigned);
3580 }
3581
3582 void setInitExpr(Expr *E) { Init = (Stmt*) E; }
3583 void setInitVal(const ASTContext &C, const llvm::APSInt &V) {
3584 setValue(C, V);
3585 IsUnsigned = V.isUnsigned();
3586 }
3587
3588 SourceRange getSourceRange() const override LLVM_READONLY;
3589
3590 /// Retrieves the canonical declaration of this enumerator.
3593
3594 // Implement isa/cast/dyncast/etc.
3595 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3596 static bool classofKind(Kind K) { return K == EnumConstant; }
3597};
3598
3599/// Represents a field injected from an anonymous union/struct into the parent
3600/// scope. These are always implicit.
3601class IndirectFieldDecl : public ValueDecl,
3602 public Mergeable<IndirectFieldDecl> {
3603 NamedDecl **Chaining;
3604 unsigned ChainingSize;
3605
3606 IndirectFieldDecl(ASTContext &C, DeclContext *DC, SourceLocation L,
3609
3610 void anchor() override;
3611
3612public:
3613 friend class ASTDeclReader;
3614
3615 static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC,
3616 SourceLocation L, const IdentifierInfo *Id,
3618
3619 static IndirectFieldDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3620
3622
3623 ArrayRef<NamedDecl *> chain() const { return {Chaining, ChainingSize}; }
3624 chain_iterator chain_begin() const { return chain().begin(); }
3625 chain_iterator chain_end() const { return chain().end(); }
3626
3627 unsigned getChainingSize() const { return ChainingSize; }
3628
3630 assert(chain().size() >= 2);
3631 return cast<FieldDecl>(chain().back());
3632 }
3633
3635 assert(chain().size() >= 2);
3636 return dyn_cast<VarDecl>(chain().front());
3637 }
3638
3639 IndirectFieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3640 const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3641
3642 // Implement isa/cast/dyncast/etc.
3643 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3644 static bool classofKind(Kind K) { return K == IndirectField; }
3645};
3646
3647/// Represents a declaration of a type.
3648class TypeDecl : public NamedDecl {
3649 friend class ASTContext;
3650 friend class ASTReader;
3651
3652 /// This indicates the Type object that represents
3653 /// this TypeDecl. It is a cache maintained by
3654 /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
3655 /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
3656 mutable const Type *TypeForDecl = nullptr;
3657
3658 /// The start of the source range for this declaration.
3659 SourceLocation LocStart;
3660
3661 void anchor() override;
3662
3663protected:
3665 SourceLocation StartL = SourceLocation())
3666 : NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
3667
3668public:
3669 // Low-level accessor. If you just want the type defined by this node,
3670 // check out ASTContext::getTypeDeclType or one of
3671 // ASTContext::getTypedefType, ASTContext::getTagType, etc. if you
3672 // already know the specific kind of node this is.
3673 const Type *getTypeForDecl() const {
3674 assert(!isa<TagDecl>(this));
3675 return TypeForDecl;
3676 }
3677 void setTypeForDecl(const Type *TD) {
3678 assert(!isa<TagDecl>(this));
3679 TypeForDecl = TD;
3680 }
3681
3682 SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
3683 void setLocStart(SourceLocation L) { LocStart = L; }
3684 SourceRange getSourceRange() const override LLVM_READONLY {
3685 if (LocStart.isValid())
3686 return SourceRange(LocStart, getLocation());
3687 else
3688 return SourceRange(getLocation());
3689 }
3690
3691 // Implement isa/cast/dyncast/etc.
3692 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3693 static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
3694};
3695
3696/// Base class for declarations which introduce a typedef-name.
3697class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
3698 struct alignas(8) ModedTInfo {
3699 TypeSourceInfo *first;
3700 QualType second;
3701 };
3702
3703 /// If int part is 0, we have not computed IsTransparentTag.
3704 /// Otherwise, IsTransparentTag is (getInt() >> 1).
3705 mutable llvm::PointerIntPair<
3706 llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
3707 MaybeModedTInfo;
3708
3709 void anchor() override;
3710
3711protected:
3713 SourceLocation StartLoc, SourceLocation IdLoc,
3714 const IdentifierInfo *Id, TypeSourceInfo *TInfo)
3715 : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
3716 MaybeModedTInfo(TInfo, 0) {}
3717
3719
3723
3725 return getPreviousDecl();
3726 }
3727
3729 return getMostRecentDecl();
3730 }
3731
3732public:
3734 using redecl_iterator = redeclarable_base::redecl_iterator;
3735
3742
3743 bool isModed() const {
3744 return isa<ModedTInfo *>(MaybeModedTInfo.getPointer());
3745 }
3746
3748 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->first
3749 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer());
3750 }
3751
3753 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->second
3754 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer())
3755 ->getType();
3756 }
3757
3759 MaybeModedTInfo.setPointer(newType);
3760 }
3761
3763 MaybeModedTInfo.setPointer(new (getASTContext(), 8)
3764 ModedTInfo({unmodedTSI, modedTy}));
3765 }
3766
3767 /// Retrieves the canonical declaration of this typedef-name.
3769 const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
3770
3771 /// Retrieves the tag declaration for which this is the typedef name for
3772 /// linkage purposes, if any.
3773 ///
3774 /// \param AnyRedecl Look for the tag declaration in any redeclaration of
3775 /// this typedef declaration.
3776 TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
3777
3778 /// Determines if this typedef shares a name and spelling location with its
3779 /// underlying tag type, as is the case with the NS_ENUM macro.
3780 bool isTransparentTag() const {
3781 if (MaybeModedTInfo.getInt())
3782 return MaybeModedTInfo.getInt() & 0x2;
3783 return isTransparentTagSlow();
3784 }
3785
3786 // These types are created lazily, use the ASTContext methods to obtain them.
3787 const Type *getTypeForDecl() const = delete;
3788 void setTypeForDecl(const Type *TD) = delete;
3789
3790 // Implement isa/cast/dyncast/etc.
3791 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3792 static bool classofKind(Kind K) {
3793 return K >= firstTypedefName && K <= lastTypedefName;
3794 }
3795
3796private:
3797 bool isTransparentTagSlow() const;
3798};
3799
3800/// Represents the declaration of a typedef-name via the 'typedef'
3801/// type specifier.
3802class TypedefDecl : public TypedefNameDecl {
3803 TypedefDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3804 SourceLocation IdLoc, const IdentifierInfo *Id,
3805 TypeSourceInfo *TInfo)
3806 : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
3807
3808public:
3809 static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
3810 SourceLocation StartLoc, SourceLocation IdLoc,
3811 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3812 static TypedefDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3813
3814 SourceRange getSourceRange() const override LLVM_READONLY;
3815
3816 // Implement isa/cast/dyncast/etc.
3817 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3818 static bool classofKind(Kind K) { return K == Typedef; }
3819};
3820
3821/// Represents the declaration of a typedef-name via a C++11
3822/// alias-declaration.
3823class TypeAliasDecl : public TypedefNameDecl {
3824 /// The template for which this is the pattern, if any.
3825 TypeAliasTemplateDecl *Template;
3826
3827 TypeAliasDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3828 SourceLocation IdLoc, const IdentifierInfo *Id,
3829 TypeSourceInfo *TInfo)
3830 : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
3831 Template(nullptr) {}
3832
3833public:
3834 static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
3835 SourceLocation StartLoc, SourceLocation IdLoc,
3836 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3837 static TypeAliasDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3838
3839 SourceRange getSourceRange() const override LLVM_READONLY;
3840
3843
3844 // Implement isa/cast/dyncast/etc.
3845 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3846 static bool classofKind(Kind K) { return K == TypeAlias; }
3847};
3848
3849/// Represents the declaration of a struct/union/class/enum.
3850class TagDecl : public TypeDecl,
3851 public DeclContext,
3852 public Redeclarable<TagDecl> {
3853 // This class stores some data in DeclContext::TagDeclBits
3854 // to save some space. Use the provided accessors to access it.
3855public:
3856 // This is really ugly.
3858
3859private:
3860 SourceRange BraceRange;
3861
3862 // A struct representing syntactic qualifier info,
3863 // to be used for the (uncommon) case of out-of-line declarations.
3864 using ExtInfo = QualifierInfo;
3865
3866 /// If the (out-of-line) tag declaration name
3867 /// is qualified, it points to the qualifier info (nns and range);
3868 /// otherwise, if the tag declaration is anonymous and it is part of
3869 /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
3870 /// otherwise, if the tag declaration is anonymous and it is used as a
3871 /// declaration specifier for variables, it points to the first VarDecl (used
3872 /// for mangling);
3873 /// otherwise, it is a null (TypedefNameDecl) pointer.
3874 llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3875
3876 bool hasExtInfo() const { return isa<ExtInfo *>(TypedefNameDeclOrQualifier); }
3877 ExtInfo *getExtInfo() { return cast<ExtInfo *>(TypedefNameDeclOrQualifier); }
3878 const ExtInfo *getExtInfo() const {
3879 return cast<ExtInfo *>(TypedefNameDeclOrQualifier);
3880 }
3881
3882protected:
3883 TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3884 SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3885 SourceLocation StartL);
3886
3888
3890 return getNextRedeclaration();
3891 }
3892
3894 return getPreviousDecl();
3895 }
3896
3898 return getMostRecentDecl();
3899 }
3900
3901 /// Completes the definition of this tag declaration.
3902 ///
3903 /// This is a helper function for derived classes.
3904 void completeDefinition();
3905
3906 /// True if this decl is currently being defined.
3907 void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; }
3908
3909 void printAnonymousTagDecl(llvm::raw_ostream &OS,
3910 const PrintingPolicy &Policy) const;
3911
3912 void printAnonymousTagDeclLocation(llvm::raw_ostream &OS,
3913 const PrintingPolicy &Policy) const;
3914
3915public:
3916 friend class ASTDeclReader;
3917 friend class ASTDeclWriter;
3918
3920 using redecl_iterator = redeclarable_base::redecl_iterator;
3921
3928
3929 SourceRange getBraceRange() const { return BraceRange; }
3930 void setBraceRange(SourceRange R) { BraceRange = R; }
3931
3932 /// Return SourceLocation representing start of source
3933 /// range ignoring outer template declarations.
3935
3936 /// Return SourceLocation representing start of source
3937 /// range taking into account any outer template declarations.
3939 SourceRange getSourceRange() const override LLVM_READONLY;
3940
3941 TagDecl *getCanonicalDecl() override;
3942 const TagDecl *getCanonicalDecl() const {
3943 return const_cast<TagDecl*>(this)->getCanonicalDecl();
3944 }
3945
3946 /// Return true if this declaration is a completion definition of the type.
3947 /// Provided for consistency.
3949 return isCompleteDefinition();
3950 }
3951
3952 /// Return true if this decl has its body fully specified.
3953 bool isCompleteDefinition() const { return TagDeclBits.IsCompleteDefinition; }
3954
3955 /// True if this decl has its body fully specified.
3956 void setCompleteDefinition(bool V = true) {
3957 TagDeclBits.IsCompleteDefinition = V;
3958 }
3959
3960 /// Return true if this complete decl is
3961 /// required to be complete for some existing use.
3963 return TagDeclBits.IsCompleteDefinitionRequired;
3964 }
3965
3966 /// True if this complete decl is
3967 /// required to be complete for some existing use.
3969 TagDeclBits.IsCompleteDefinitionRequired = V;
3970 }
3971
3972 /// Return true if this decl is currently being defined.
3973 bool isBeingDefined() const { return TagDeclBits.IsBeingDefined; }
3974
3975 /// True if this tag declaration is "embedded" (i.e., defined or declared
3976 /// for the very first time) in the syntax of a declarator.
3978 return TagDeclBits.IsEmbeddedInDeclarator;
3979 }
3980
3981 /// True if this tag declaration is "embedded" (i.e., defined or declared
3982 /// for the very first time) in the syntax of a declarator.
3983 void setEmbeddedInDeclarator(bool isInDeclarator) {
3984 TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator;
3985 }
3986
3987 /// True if this tag is free standing, e.g. "struct foo;".
3988 bool isFreeStanding() const { return TagDeclBits.IsFreeStanding; }
3989
3990 /// True if this tag is free standing, e.g. "struct foo;".
3992 TagDeclBits.IsFreeStanding = isFreeStanding;
3993 }
3994
3995 /// Whether this declaration declares a type that is
3996 /// dependent, i.e., a type that somehow depends on template
3997 /// parameters.
3998 bool isDependentType() const { return isDependentContext(); }
3999
4000 /// Whether this declaration was a definition in some module but was forced
4001 /// to be a declaration.
4002 ///
4003 /// Useful for clients checking if a module has a definition of a specific
4004 /// symbol and not interested in the final AST with deduplicated definitions.
4006 return TagDeclBits.IsThisDeclarationADemotedDefinition;
4007 }
4008
4009 /// Mark a definition as a declaration and maintain information it _was_
4010 /// a definition.
4012 assert(isCompleteDefinition() &&
4013 "Should demote definitions only, not forward declarations");
4014 setCompleteDefinition(false);
4015 TagDeclBits.IsThisDeclarationADemotedDefinition = true;
4016 }
4017
4018 /// Starts the definition of this tag declaration.
4019 ///
4020 /// This method should be invoked at the beginning of the definition
4021 /// of this tag declaration. It will set the tag type into a state
4022 /// where it is in the process of being defined.
4023 void startDefinition();
4024
4025 /// Returns the TagDecl that actually defines this
4026 /// struct/union/class/enum. When determining whether or not a
4027 /// struct/union/class/enum has a definition, one should use this
4028 /// method as opposed to 'isDefinition'. 'isDefinition' indicates
4029 /// whether or not a specific TagDecl is defining declaration, not
4030 /// whether or not the struct/union/class/enum type is defined.
4031 /// This method returns NULL if there is no TagDecl that defines
4032 /// the struct/union/class/enum.
4033 TagDecl *getDefinition() const;
4034
4036 if (TagDecl *Def = getDefinition())
4037 return Def;
4038 return const_cast<TagDecl *>(this);
4039 }
4040
4041 /// Determines whether this entity is in the process of being defined.
4043 if (const TagDecl *Def = getDefinition())
4044 return Def->isBeingDefined();
4045 return false;
4046 }
4047
4048 StringRef getKindName() const {
4050 }
4051
4053 return static_cast<TagKind>(TagDeclBits.TagDeclKind);
4054 }
4055
4057 TagDeclBits.TagDeclKind = llvm::to_underlying(TK);
4058 }
4059
4060 bool isStruct() const { return getTagKind() == TagTypeKind::Struct; }
4061 bool isInterface() const { return getTagKind() == TagTypeKind::Interface; }
4062 bool isClass() const { return getTagKind() == TagTypeKind::Class; }
4063 bool isUnion() const { return getTagKind() == TagTypeKind::Union; }
4064 bool isEnum() const { return getTagKind() == TagTypeKind::Enum; }
4065
4066 bool isStructureOrClass() const {
4067 return isStruct() || isClass() || isInterface();
4068 }
4069
4070 /// Is this tag type named, either directly or via being defined in
4071 /// a typedef of this type?
4072 ///
4073 /// C++11 [basic.link]p8:
4074 /// A type is said to have linkage if and only if:
4075 /// - it is a class or enumeration type that is named (or has a
4076 /// name for linkage purposes) and the name has linkage; ...
4077 /// C++11 [dcl.typedef]p9:
4078 /// If the typedef declaration defines an unnamed class (or enum),
4079 /// the first typedef-name declared by the declaration to be that
4080 /// class type (or enum type) is used to denote the class type (or
4081 /// enum type) for linkage purposes only.
4082 ///
4083 /// C does not have an analogous rule, but the same concept is
4084 /// nonetheless useful in some places.
4085 bool hasNameForLinkage() const {
4086 return (getDeclName() || getTypedefNameForAnonDecl());
4087 }
4088
4090 return hasExtInfo() ? nullptr
4091 : cast<TypedefNameDecl *>(TypedefNameDeclOrQualifier);
4092 }
4093
4095
4096 /// Retrieve the nested-name-specifier that qualifies the name of this
4097 /// declaration, if it was present in the source.
4099 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
4100 : std::nullopt;
4101 }
4102
4103 /// Retrieve the nested-name-specifier (with source-location
4104 /// information) that qualifies the name of this declaration, if it was
4105 /// present in the source.
4107 return hasExtInfo() ? getExtInfo()->QualifierLoc
4109 }
4110
4111 void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
4112
4114 if (!hasExtInfo())
4115 return {};
4116 return {/*data=*/getExtInfo()->TemplParamLists,
4117 /*length=*/getExtInfo()->NumTemplParamLists};
4118 }
4119
4120 // These types are created lazily, use the ASTContext methods to obtain them.
4121 const Type *getTypeForDecl() const = delete;
4122 void setTypeForDecl(const Type *TD) = delete;
4123
4124 using TypeDecl::printName;
4125 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
4126
4129
4130 // Implement isa/cast/dyncast/etc.
4131 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4132 static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
4133
4135 return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
4136 }
4137
4139 return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
4140 }
4141};
4142
4143/// Represents an enum. In C++11, enums can be forward-declared
4144/// with a fixed underlying type, and in C we allow them to be forward-declared
4145/// with no underlying type as an extension.
4146class EnumDecl : public TagDecl {
4147 // This class stores some data in DeclContext::EnumDeclBits
4148 // to save some space. Use the provided accessors to access it.
4149
4150 /// This represent the integer type that the enum corresponds
4151 /// to for code generation purposes. Note that the enumerator constants may
4152 /// have a different type than this does.
4153 ///
4154 /// If the underlying integer type was explicitly stated in the source
4155 /// code, this is a TypeSourceInfo* for that type. Otherwise this type
4156 /// was automatically deduced somehow, and this is a Type*.
4157 ///
4158 /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
4159 /// some cases it won't.
4160 ///
4161 /// The underlying type of an enumeration never has any qualifiers, so
4162 /// we can get away with just storing a raw Type*, and thus save an
4163 /// extra pointer when TypeSourceInfo is needed.
4164 llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
4165
4166 /// The integer type that values of this type should
4167 /// promote to. In C, enumerators are generally of an integer type
4168 /// directly, but gcc-style large enumerators (and all enumerators
4169 /// in C++) are of the enum type instead.
4170 QualType PromotionType;
4171
4172 /// If this enumeration is an instantiation of a member enumeration
4173 /// of a class template specialization, this is the member specialization
4174 /// information.
4175 MemberSpecializationInfo *SpecializationInfo = nullptr;
4176
4177 /// Store the ODRHash after first calculation.
4178 /// The corresponding flag HasODRHash is in EnumDeclBits
4179 /// and can be accessed with the provided accessors.
4180 unsigned ODRHash;
4181
4182 /// Source range covering the enum key:
4183 /// - 'enum' (unscoped)
4184 /// - 'enum class|struct' (scoped)
4185 SourceRange EnumKeyRange;
4186
4187 EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
4188 SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
4189 bool Scoped, bool ScopedUsingClassTag, bool Fixed);
4190
4191 void anchor() override;
4192
4193 void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
4195
4196 /// Sets the width in bits required to store all the
4197 /// non-negative enumerators of this enum.
4198 void setNumPositiveBits(unsigned Num) {
4199 EnumDeclBits.NumPositiveBits = Num;
4200 assert(EnumDeclBits.NumPositiveBits == Num && "can't store this bitcount");
4201 }
4202
4203 /// Returns the width in bits required to store all the
4204 /// negative enumerators of this enum. (see getNumNegativeBits)
4205 void setNumNegativeBits(unsigned Num) { EnumDeclBits.NumNegativeBits = Num; }
4206
4207public:
4208 /// True if this tag declaration is a scoped enumeration. Only
4209 /// possible in C++11 mode.
4210 void setScoped(bool Scoped = true) { EnumDeclBits.IsScoped = Scoped; }
4211
4212 /// If this tag declaration is a scoped enum,
4213 /// then this is true if the scoped enum was declared using the class
4214 /// tag, false if it was declared with the struct tag. No meaning is
4215 /// associated if this tag declaration is not a scoped enum.
4216 void setScopedUsingClassTag(bool ScopedUCT = true) {
4217 EnumDeclBits.IsScopedUsingClassTag = ScopedUCT;
4218 }
4219
4220 /// True if this is an Objective-C, C++11, or
4221 /// Microsoft-style enumeration with a fixed underlying type.
4222 void setFixed(bool Fixed = true) { EnumDeclBits.IsFixed = Fixed; }
4223
4224 SourceRange getEnumKeyRange() const { return EnumKeyRange; }
4225
4226 void setEnumKeyRange(SourceRange Range) { EnumKeyRange = Range; }
4227
4228private:
4229 /// True if a valid hash is stored in ODRHash.
4230 bool hasODRHash() const { return EnumDeclBits.HasODRHash; }
4231 void setHasODRHash(bool Hash = true) { EnumDeclBits.HasODRHash = Hash; }
4232
4233public:
4234 friend class ASTDeclReader;
4235
4236 EnumDecl *getCanonicalDecl() override {
4238 }
4239 const EnumDecl *getCanonicalDecl() const {
4240 return const_cast<EnumDecl*>(this)->getCanonicalDecl();
4241 }
4242
4243 EnumDecl *getPreviousDecl() {
4244 return cast_or_null<EnumDecl>(
4245 static_cast<TagDecl *>(this)->getPreviousDecl());
4246 }
4247 const EnumDecl *getPreviousDecl() const {
4248 return const_cast<EnumDecl*>(this)->getPreviousDecl();
4249 }
4250
4251 EnumDecl *getMostRecentDecl() {
4252 return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
4253 }
4254 const EnumDecl *getMostRecentDecl() const {
4255 return const_cast<EnumDecl*>(this)->getMostRecentDecl();
4256 }
4257
4258 EnumDecl *getDefinition() const {
4259 return cast_or_null<EnumDecl>(TagDecl::getDefinition());
4260 }
4261
4262 EnumDecl *getDefinitionOrSelf() const {
4263 return cast_or_null<EnumDecl>(TagDecl::getDefinitionOrSelf());
4264 }
4265
4266 static EnumDecl *Create(ASTContext &C, DeclContext *DC,
4267 SourceLocation StartLoc, SourceLocation IdLoc,
4268 IdentifierInfo *Id, EnumDecl *PrevDecl,
4269 bool IsScoped, bool IsScopedUsingClassTag,
4270 bool IsFixed);
4272
4273 /// Overrides to provide correct range when there's an enum-base specifier
4274 /// with forward declarations.
4275 SourceRange getSourceRange() const override LLVM_READONLY;
4276
4277 /// When created, the EnumDecl corresponds to a
4278 /// forward-declared enum. This method is used to mark the
4279 /// declaration as being defined; its enumerators have already been
4280 /// added (via DeclContext::addDecl). NewType is the new underlying
4281 /// type of the enumeration type.
4282 void completeDefinition(QualType NewType,
4283 QualType PromotionType,
4284 unsigned NumPositiveBits,
4285 unsigned NumNegativeBits);
4286
4287 // Iterates through the enumerators of this enumeration.
4291
4295
4297 const EnumDecl *E = getDefinition();
4298 if (!E)
4299 E = this;
4300 return enumerator_iterator(E->decls_begin());
4301 }
4302
4304 const EnumDecl *E = getDefinition();
4305 if (!E)
4306 E = this;
4307 return enumerator_iterator(E->decls_end());
4308 }
4309
4310 /// Return the integer type that enumerators should promote to.
4311 QualType getPromotionType() const { return PromotionType; }
4312
4313 /// Set the promotion type.
4314 void setPromotionType(QualType T) { PromotionType = T; }
4315
4316 /// Return the integer type this enum decl corresponds to.
4317 /// This returns a null QualType for an enum forward definition with no fixed
4318 /// underlying type.
4320 if (!IntegerType)
4321 return QualType();
4322 if (const Type *T = dyn_cast<const Type *>(IntegerType))
4323 return QualType(T, 0);
4324 return cast<TypeSourceInfo *>(IntegerType)->getType().getUnqualifiedType();
4325 }
4326
4327 /// Set the underlying integer type.
4328 void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
4329
4330 /// Set the underlying integer type source info.
4331 void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
4332
4333 /// Return the type source info for the underlying integer type,
4334 /// if no type source info exists, return 0.
4336 return dyn_cast_if_present<TypeSourceInfo *>(IntegerType);
4337 }
4338
4339 /// Retrieve the source range that covers the underlying type if
4340 /// specified.
4341 SourceRange getIntegerTypeRange() const LLVM_READONLY;
4342
4343 /// Returns the width in bits required to store all the
4344 /// non-negative enumerators of this enum.
4345 unsigned getNumPositiveBits() const { return EnumDeclBits.NumPositiveBits; }
4346
4347 /// Returns the width in bits required to store all the
4348 /// negative enumerators of this enum. These widths include
4349 /// the rightmost leading 1; that is:
4350 ///
4351 /// MOST NEGATIVE ENUMERATOR PATTERN NUM NEGATIVE BITS
4352 /// ------------------------ ------- -----------------
4353 /// -1 1111111 1
4354 /// -10 1110110 5
4355 /// -101 1001011 8
4356 unsigned getNumNegativeBits() const { return EnumDeclBits.NumNegativeBits; }
4357
4358 /// Calculates the [Min,Max) values the enum can store based on the
4359 /// NumPositiveBits and NumNegativeBits. This matters for enums that do not
4360 /// have a fixed underlying type.
4361 void getValueRange(llvm::APInt &Max, llvm::APInt &Min) const;
4362
4363 /// Returns true if this is a C++11 scoped enumeration.
4364 bool isScoped() const { return EnumDeclBits.IsScoped; }
4365
4366 /// Returns true if this is a C++11 scoped enumeration.
4368 return EnumDeclBits.IsScopedUsingClassTag;
4369 }
4370
4371 /// Returns true if this is an Objective-C, C++11, or
4372 /// Microsoft-style enumeration with a fixed underlying type.
4373 bool isFixed() const { return EnumDeclBits.IsFixed; }
4374
4375 unsigned getODRHash();
4376
4377 /// Returns true if this can be considered a complete type.
4378 bool isComplete() const {
4379 // IntegerType is set for fixed type enums and non-fixed but implicitly
4380 // int-sized Microsoft enums.
4381 return isCompleteDefinition() || IntegerType;
4382 }
4383
4384 /// Returns true if this enum is either annotated with
4385 /// enum_extensibility(closed) or isn't annotated with enum_extensibility.
4386 bool isClosed() const;
4387
4388 /// Returns true if this enum is annotated with flag_enum and isn't annotated
4389 /// with enum_extensibility(open).
4390 bool isClosedFlag() const;
4391
4392 /// Returns true if this enum is annotated with neither flag_enum nor
4393 /// enum_extensibility(open).
4394 bool isClosedNonFlag() const;
4395
4396 /// Retrieve the enum definition from which this enumeration could
4397 /// be instantiated, if it is an instantiation (rather than a non-template).
4399
4400 /// Returns the enumeration (declared within the template)
4401 /// from which this enumeration type was instantiated, or NULL if
4402 /// this enumeration was not instantiated from any template.
4404
4405 /// If this enumeration is a member of a specialization of a
4406 /// templated class, determine what kind of template specialization
4407 /// or instantiation this is.
4409
4410 /// For an enumeration member that was instantiated from a member
4411 /// enumeration of a templated class, set the template specialiation kind.
4413 SourceLocation PointOfInstantiation = SourceLocation());
4414
4415 /// If this enumeration is an instantiation of a member enumeration of
4416 /// a class template specialization, retrieves the member specialization
4417 /// information.
4419 return SpecializationInfo;
4420 }
4421
4422 /// Specify that this enumeration is an instantiation of the
4423 /// member enumeration ED.
4426 setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
4427 }
4428
4429 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4430 static bool classofKind(Kind K) { return K == Enum; }
4431};
4432
4433/// Enum that represents the different ways arguments are passed to and
4434/// returned from function calls. This takes into account the target-specific
4435/// and version-specific rules along with the rules determined by the
4436/// language.
4438 /// The argument of this type can be passed directly in registers.
4440
4441 /// The argument of this type cannot be passed directly in registers.
4442 /// Records containing this type as a subobject are not forced to be passed
4443 /// indirectly. This value is used only in C++. This value is required by
4444 /// C++ because, in uncommon situations, it is possible for a class to have
4445 /// only trivial copy/move constructors even when one of its subobjects has
4446 /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
4447 /// constructor in the derived class is deleted).
4449
4450 /// The argument of this type cannot be passed directly in registers.
4451 /// Records containing this type as a subobject are forced to be passed
4452 /// indirectly.
4454};
4455
4456/// Represents a struct/union/class. For example:
4457/// struct X; // Forward declaration, no "body".
4458/// union Y { int A, B; }; // Has body with members A and B (FieldDecls).
4459/// This decl will be marked invalid if *any* members are invalid.
4460class RecordDecl : public TagDecl {
4461 // This class stores some data in DeclContext::RecordDeclBits
4462 // to save some space. Use the provided accessors to access it.
4463public:
4464 friend class DeclContext;
4465 friend class ASTDeclReader;
4466
4467protected:
4468 RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
4469 SourceLocation StartLoc, SourceLocation IdLoc,
4470 IdentifierInfo *Id, RecordDecl *PrevDecl);
4471
4472public:
4473 static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
4474 SourceLocation StartLoc, SourceLocation IdLoc,
4475 IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
4477
4479 return cast_or_null<RecordDecl>(
4480 static_cast<TagDecl *>(this)->getPreviousDecl());
4481 }
4483 return const_cast<RecordDecl*>(this)->getPreviousDecl();
4484 }
4485
4487 return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
4488 }
4490 return const_cast<RecordDecl*>(this)->getMostRecentDecl();
4491 }
4492
4494 return RecordDeclBits.HasFlexibleArrayMember;
4495 }
4496
4498 RecordDeclBits.HasFlexibleArrayMember = V;
4499 }
4500
4501 /// Whether this is an anonymous struct or union. To be an anonymous
4502 /// struct or union, it must have been declared without a name and
4503 /// there must be no objects of this type declared, e.g.,
4504 /// @code
4505 /// union { int i; float f; };
4506 /// @endcode
4507 /// is an anonymous union but neither of the following are:
4508 /// @code
4509 /// union X { int i; float f; };
4510 /// union { int i; float f; } obj;
4511 /// @endcode
4513 return RecordDeclBits.AnonymousStructOrUnion;
4514 }
4515
4517 RecordDeclBits.AnonymousStructOrUnion = Anon;
4518 }
4519
4520 bool hasObjectMember() const { return RecordDeclBits.HasObjectMember; }
4521 void setHasObjectMember(bool val) { RecordDeclBits.HasObjectMember = val; }
4522
4523 bool hasVolatileMember() const { return RecordDeclBits.HasVolatileMember; }
4524
4525 void setHasVolatileMember(bool val) {
4526 RecordDeclBits.HasVolatileMember = val;
4527 }
4528
4530 return RecordDeclBits.LoadedFieldsFromExternalStorage;
4531 }
4532
4534 RecordDeclBits.LoadedFieldsFromExternalStorage = val;
4535 }
4536
4537 /// Functions to query basic properties of non-trivial C structs.
4539 return RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize;
4540 }
4541
4543 RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize = V;
4544 }
4545
4547 return RecordDeclBits.NonTrivialToPrimitiveCopy;
4548 }
4549
4551 RecordDeclBits.NonTrivialToPrimitiveCopy = V;
4552 }
4553
4555 return RecordDeclBits.NonTrivialToPrimitiveDestroy;
4556 }
4557
4559 RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
4560 }
4561
4563 return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion;
4564 }
4565
4567 RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V;
4568 }
4569
4571 return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion;
4572 }
4573
4575 RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V;
4576 }
4577
4579 return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion;
4580 }
4581
4583 RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V;
4584 }
4585
4587 return RecordDeclBits.HasUninitializedExplicitInitFields;
4588 }
4589
4591 RecordDeclBits.HasUninitializedExplicitInitFields = V;
4592 }
4593
4594 /// Determine whether this class can be passed in registers. In C++ mode,
4595 /// it must have at least one trivial, non-deleted copy or move constructor.
4596 /// FIXME: This should be set as part of completeDefinition.
4600
4602 return static_cast<RecordArgPassingKind>(
4603 RecordDeclBits.ArgPassingRestrictions);
4604 }
4605
4607 RecordDeclBits.ArgPassingRestrictions = llvm::to_underlying(Kind);
4608 }
4609
4611 return RecordDeclBits.ParamDestroyedInCallee;
4612 }
4613
4615 RecordDeclBits.ParamDestroyedInCallee = V;
4616 }
4617
4618 bool isRandomized() const { return RecordDeclBits.IsRandomized; }
4619
4620 void setIsRandomized(bool V) { RecordDeclBits.IsRandomized = V; }
4621
4622 void reorderDecls(const SmallVectorImpl<Decl *> &Decls);
4623
4624 /// Determine whether this record is a class describing a lambda
4625 /// function object.
4626 bool isLambda() const;
4627
4628 /// Determine whether this record is a record for captured variables in
4629 /// CapturedStmt construct.
4630 bool isCapturedRecord() const;
4631
4632 /// Mark the record as a record for captured variables in CapturedStmt
4633 /// construct.
4634 void setCapturedRecord();
4635
4636 /// Returns the RecordDecl that actually defines
4637 /// this struct/union/class. When determining whether or not a
4638 /// struct/union/class is completely defined, one should use this
4639 /// method as opposed to 'isCompleteDefinition'.
4640 /// 'isCompleteDefinition' indicates whether or not a specific
4641 /// RecordDecl is a completed definition, not whether or not the
4642 /// record type is defined. This method returns NULL if there is
4643 /// no RecordDecl that defines the struct/union/tag.
4645 return cast_or_null<RecordDecl>(TagDecl::getDefinition());
4646 }
4647
4649 return cast_or_null<RecordDecl>(TagDecl::getDefinitionOrSelf());
4650 }
4651
4652 /// Returns whether this record is a union, or contains (at any nesting level)
4653 /// a union member. This is used by CMSE to warn about possible information
4654 /// leaks.
4655 bool isOrContainsUnion() const;
4656
4657 // Iterator access to field members. The field iterator only visits
4658 // the non-static data members of this class, ignoring any static
4659 // data members, functions, constructors, destructors, etc.
4661 using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
4662
4665
4667 return field_iterator(decl_iterator());
4668 }
4669
4670 // Whether there are any fields (non-static data members) in this record.
4671 bool field_empty() const {
4672 return field_begin() == field_end();
4673 }
4674
4675 /// Returns the number of fields (non-static data members) in this record.
4676 unsigned getNumFields() const {
4677 return std::distance(field_begin(), field_end());
4678 }
4679
4680 /// noload_fields - Iterate over the fields stored in this record
4681 /// that are currently loaded; don't attempt to retrieve anything
4682 /// from an external source.
4686
4691
4692 // Whether there are any fields (non-static data members) in this record.
4693 bool noload_field_empty() const {
4695 }
4696
4697 /// Note that the definition of this type is now complete.
4698 virtual void completeDefinition();
4699
4700 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4701 static bool classofKind(Kind K) {
4702 return K >= firstRecord && K <= lastRecord;
4703 }
4704
4705 /// Get whether or not this is an ms_struct which can
4706 /// be turned on with an attribute, pragma, or -mms-bitfields
4707 /// commandline option.
4708 bool isMsStruct(const ASTContext &C) const;
4709
4710 /// Whether we are allowed to insert extra padding between fields.
4711 /// These padding are added to help AddressSanitizer detect
4712 /// intra-object-overflow bugs.
4713 bool mayInsertExtraPadding(bool EmitRemark = false) const;
4714
4715 /// Finds the first data member which has a name.
4716 /// nullptr is returned if no named data member exists.
4717 const FieldDecl *findFirstNamedDataMember() const;
4718
4719 /// Get precomputed ODRHash or add a new one.
4720 unsigned getODRHash();
4721
4722private:
4723 /// Deserialize just the fields.
4724 void LoadFieldsFromExternalStorage() const;
4725
4726 /// True if a valid hash is stored in ODRHash.
4727 bool hasODRHash() const { return RecordDeclBits.ODRHash; }
4728 void setODRHash(unsigned Hash) { RecordDeclBits.ODRHash = Hash; }
4729};
4730
4731class FileScopeAsmDecl : public Decl {
4732 Expr *AsmString;
4733 SourceLocation RParenLoc;
4734
4735 FileScopeAsmDecl(DeclContext *DC, Expr *asmstring, SourceLocation StartL,
4736 SourceLocation EndL)
4737 : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
4738
4739 virtual void anchor();
4740
4741public:
4742 static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC, Expr *Str,
4743 SourceLocation AsmLoc,
4744 SourceLocation RParenLoc);
4745
4746 static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4747
4749 SourceLocation getRParenLoc() const { return RParenLoc; }
4750 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4751 SourceRange getSourceRange() const override LLVM_READONLY {
4752 return SourceRange(getAsmLoc(), getRParenLoc());
4753 }
4754
4755 const Expr *getAsmStringExpr() const { return AsmString; }
4756 Expr *getAsmStringExpr() { return AsmString; }
4757 void setAsmString(Expr *Asm) { AsmString = Asm; }
4758
4759 std::string getAsmString() const;
4760
4761 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4762 static bool classofKind(Kind K) { return K == FileScopeAsm; }
4763};
4764
4765/// A declaration that models statements at global scope. This declaration
4766/// supports incremental and interactive C/C++.
4767///
4768/// \note This is used in libInterpreter, clang -cc1 -fincremental-extensions
4769/// and in tools such as clang-repl.
4770class TopLevelStmtDecl : public Decl, public DeclContext {
4771 friend class ASTDeclReader;
4772 friend class ASTDeclWriter;
4773
4774 Stmt *Statement = nullptr;
4775 bool IsSemiMissing = false;
4776
4777 TopLevelStmtDecl(DeclContext *DC, SourceLocation L, Stmt *S)
4778 : Decl(TopLevelStmt, DC, L), DeclContext(TopLevelStmt), Statement(S) {}
4779
4780 virtual void anchor();
4781
4782public:
4783 static TopLevelStmtDecl *Create(ASTContext &C, Stmt *Statement);
4785
4786 SourceRange getSourceRange() const override LLVM_READONLY;
4787 Stmt *getStmt() { return Statement; }
4788 const Stmt *getStmt() const { return Statement; }
4789 void setStmt(Stmt *S);
4790 bool isSemiMissing() const { return IsSemiMissing; }
4791 void setSemiMissing(bool Missing = true) { IsSemiMissing = Missing; }
4792
4793 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4794 static bool classofKind(Kind K) { return K == TopLevelStmt; }
4795
4796 static DeclContext *castToDeclContext(const TopLevelStmtDecl *D) {
4797 return static_cast<DeclContext *>(const_cast<TopLevelStmtDecl *>(D));
4798 }
4799 static TopLevelStmtDecl *castFromDeclContext(const DeclContext *DC) {
4800 return static_cast<TopLevelStmtDecl *>(const_cast<DeclContext *>(DC));
4801 }
4802};
4803
4804/// Represents a block literal declaration, which is like an
4805/// unnamed FunctionDecl. For example:
4806/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
4807class BlockDecl : public Decl, public DeclContext {
4808 // This class stores some data in DeclContext::BlockDeclBits
4809 // to save some space. Use the provided accessors to access it.
4810public:
4811 /// A class which contains all the information about a particular
4812 /// captured value.
4813 class Capture {
4814 enum {
4815 flag_isByRef = 0x1,
4816 flag_isNested = 0x2
4817 };
4818
4819 /// The variable being captured.
4820 llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
4821
4822 /// The copy expression, expressed in terms of a DeclRef (or
4823 /// BlockDeclRef) to the captured variable. Only required if the
4824 /// variable has a C++ class type.
4825 Expr *CopyExpr;
4826
4827 public:
4828 Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
4829 : VariableAndFlags(variable,
4830 (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
4831 CopyExpr(copy) {}
4832
4833 /// The variable being captured.
4834 VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
4835
4836 /// Whether this is a "by ref" capture, i.e. a capture of a __block
4837 /// variable.
4838 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
4839
4840 bool isEscapingByref() const {
4841 return getVariable()->isEscapingByref();
4842 }
4843
4844 bool isNonEscapingByref() const {
4845 return getVariable()->isNonEscapingByref();
4846 }
4847
4848 /// Whether this is a nested capture, i.e. the variable captured
4849 /// is not from outside the immediately enclosing function/block.
4850 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
4851
4852 bool hasCopyExpr() const { return CopyExpr != nullptr; }
4853 Expr *getCopyExpr() const { return CopyExpr; }
4854 void setCopyExpr(Expr *e) { CopyExpr = e; }
4855 };
4856
4857private:
4858 /// A new[]'d array of pointers to ParmVarDecls for the formal
4859 /// parameters of this function. This is null if a prototype or if there are
4860 /// no formals.
4861 ParmVarDecl **ParamInfo = nullptr;
4862 unsigned NumParams = 0;
4863
4864 Stmt *Body = nullptr;
4865 TypeSourceInfo *SignatureAsWritten = nullptr;
4866
4867 const Capture *Captures = nullptr;
4868 unsigned NumCaptures = 0;
4869
4870 unsigned ManglingNumber = 0;
4871 Decl *ManglingContextDecl = nullptr;
4872
4873protected:
4874 BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
4875
4876public:
4879
4881
4882 bool isVariadic() const { return BlockDeclBits.IsVariadic; }
4883 void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; }
4884
4885 CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
4886 Stmt *getBody() const override { return (Stmt*) Body; }
4887 void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
4888
4889 void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
4890 TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
4891
4892 // ArrayRef access to formal parameters.
4894 return {ParamInfo, getNumParams()};
4895 }
4897 return {ParamInfo, getNumParams()};
4898 }
4899
4900 // Iterator access to formal parameters.
4903
4904 bool param_empty() const { return parameters().empty(); }
4905 param_iterator param_begin() { return parameters().begin(); }
4907 param_const_iterator param_begin() const { return parameters().begin(); }
4908 param_const_iterator param_end() const { return parameters().end(); }
4909 size_t param_size() const { return parameters().size(); }
4910
4911 unsigned getNumParams() const { return NumParams; }
4912
4913 const ParmVarDecl *getParamDecl(unsigned i) const {
4914 assert(i < getNumParams() && "Illegal param #");
4915 return ParamInfo[i];
4916 }
4918 assert(i < getNumParams() && "Illegal param #");
4919 return ParamInfo[i];
4920 }
4921
4922 void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
4923
4924 /// True if this block (or its nested blocks) captures
4925 /// anything of local storage from its enclosing scopes.
4926 bool hasCaptures() const { return NumCaptures || capturesCXXThis(); }
4927
4928 /// Returns the number of captured variables.
4929 /// Does not include an entry for 'this'.
4930 unsigned getNumCaptures() const { return NumCaptures; }
4931
4933
4934 ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; }
4935
4936 capture_const_iterator capture_begin() const { return captures().begin(); }
4937 capture_const_iterator capture_end() const { return captures().end(); }
4938
4939 bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
4940 void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
4941
4943 return BlockDeclBits.BlockMissingReturnType;
4944 }
4945
4946 void setBlockMissingReturnType(bool val = true) {
4947 BlockDeclBits.BlockMissingReturnType = val;
4948 }
4949
4951 return BlockDeclBits.IsConversionFromLambda;
4952 }
4953
4954 void setIsConversionFromLambda(bool val = true) {
4955 BlockDeclBits.IsConversionFromLambda = val;
4956 }
4957
4958 bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
4959 void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
4960
4961 bool canAvoidCopyToHeap() const {
4962 return BlockDeclBits.CanAvoidCopyToHeap;
4963 }
4964 void setCanAvoidCopyToHeap(bool B = true) {
4965 BlockDeclBits.CanAvoidCopyToHeap = B;
4966 }
4967
4968 bool capturesVariable(const VarDecl *var) const;
4969
4970 void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
4971 bool CapturesCXXThis);
4972
4973 unsigned getBlockManglingNumber() const { return ManglingNumber; }
4974
4975 Decl *getBlockManglingContextDecl() const { return ManglingContextDecl; }
4976
4977 void setBlockMangling(unsigned Number, Decl *Ctx) {
4978 ManglingNumber = Number;
4979 ManglingContextDecl = Ctx;
4980 }
4981
4982 SourceRange getSourceRange() const override LLVM_READONLY;
4983
4985 if (const TypeSourceInfo *TSI = getSignatureAsWritten())
4986 if (const auto *FPT = TSI->getType()->getAs<FunctionProtoType>())
4987 return FPT->getFunctionEffects();
4988 return {};
4989 }
4990
4991 // Implement isa/cast/dyncast/etc.
4992 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4993 static bool classofKind(Kind K) { return K == Block; }
4995 return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
4996 }
4998 return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
4999 }
5000};
5001
5002/// Represents a partial function definition.
5003///
5004/// An outlined function declaration contains the parameters and body of
5005/// a function independent of other function definition concerns such
5006/// as function name, type, and calling convention. Such declarations may
5007/// be used to hold a parameterized and transformed sequence of statements
5008/// used to generate a target dependent function definition without losing
5009/// association with the original statements. See SYCLKernelCallStmt as an
5010/// example.
5011class OutlinedFunctionDecl final
5012 : public Decl,
5013 public DeclContext,
5014 private llvm::TrailingObjects<OutlinedFunctionDecl, ImplicitParamDecl *> {
5015private:
5016 /// The number of parameters to the outlined function.
5017 unsigned NumParams;
5018
5019 /// The body of the outlined function.
5020 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
5021
5022 explicit OutlinedFunctionDecl(DeclContext *DC, unsigned NumParams);
5023
5024 ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }
5025
5026 ImplicitParamDecl **getParams() { return getTrailingObjects(); }
5027
5028public:
5029 friend class ASTDeclReader;
5030 friend class ASTDeclWriter;
5032
5033 static OutlinedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
5034 unsigned NumParams);
5035 static OutlinedFunctionDecl *
5036 CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams);
5037
5038 Stmt *getBody() const override;
5039 void setBody(Stmt *B);
5040
5041 bool isNothrow() const;
5042 void setNothrow(bool Nothrow = true);
5043
5044 unsigned getNumParams() const { return NumParams; }
5045
5046 ImplicitParamDecl *getParam(unsigned i) const {
5047 assert(i < NumParams);
5048 return getParams()[i];
5049 }
5050 void setParam(unsigned i, ImplicitParamDecl *P) {
5051 assert(i < NumParams);
5052 getParams()[i] = P;
5053 }
5054
5055 // Range interface to parameters.
5057 using parameter_const_range = llvm::iterator_range<parameter_const_iterator>;
5059 return {param_begin(), param_end()};
5060 }
5061 parameter_const_iterator param_begin() const { return getParams(); }
5062 parameter_const_iterator param_end() const { return getParams() + NumParams; }
5063
5064 // Implement isa/cast/dyncast/etc.
5065 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5066 static bool classofKind(Kind K) { return K == OutlinedFunction; }
5067 static DeclContext *castToDeclContext(const OutlinedFunctionDecl *D) {
5068 return static_cast<DeclContext *>(const_cast<OutlinedFunctionDecl *>(D));
5069 }
5070 static OutlinedFunctionDecl *castFromDeclContext(const DeclContext *DC) {
5071 return static_cast<OutlinedFunctionDecl *>(const_cast<DeclContext *>(DC));
5072 }
5073};
5074
5075/// Represents the body of a CapturedStmt, and serves as its DeclContext.
5076class CapturedDecl final
5077 : public Decl,
5078 public DeclContext,
5079 private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
5080protected:
5081 size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
5082 return NumParams;
5083 }
5084
5085private:
5086 /// The number of parameters to the outlined function.
5087 unsigned NumParams;
5088
5089 /// The position of context parameter in list of parameters.
5090 unsigned ContextParam;
5091
5092 /// The body of the outlined function.
5093 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
5094
5095 explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
5096
5097 ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }
5098
5099 ImplicitParamDecl **getParams() { return getTrailingObjects(); }
5100
5101public:
5102 friend class ASTDeclReader;
5103 friend class ASTDeclWriter;
5105
5106 static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
5107 unsigned NumParams);
5108 static CapturedDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
5109 unsigned NumParams);
5110
5111 Stmt *getBody() const override;
5112 void setBody(Stmt *B);
5113
5114 bool isNothrow() const;
5115 void setNothrow(bool Nothrow = true);
5116
5117 unsigned getNumParams() const { return NumParams; }
5118
5119 ImplicitParamDecl *getParam(unsigned i) const {
5120 assert(i < NumParams);
5121 return getParams()[i];
5122 }
5123 void setParam(unsigned i, ImplicitParamDecl *P) {
5124 assert(i < NumParams);
5125 getParams()[i] = P;
5126 }
5127
5128 // ArrayRef interface to parameters.
5130 return {getParams(), getNumParams()};
5131 }
5133 return {getParams(), getNumParams()};
5134 }
5135
5136 /// Retrieve the parameter containing captured variables.
5138 assert(ContextParam < NumParams);
5139 return getParam(ContextParam);
5140 }
5141 void setContextParam(unsigned i, ImplicitParamDecl *P) {
5142 assert(i < NumParams);
5143 ContextParam = i;
5144 setParam(i, P);
5145 }
5146 unsigned getContextParamPosition() const { return ContextParam; }
5147
5149 using param_range = llvm::iterator_range<param_iterator>;
5150
5151 /// Retrieve an iterator pointing to the first parameter decl.
5152 param_iterator param_begin() const { return getParams(); }
5153 /// Retrieve an iterator one past the last parameter decl.
5154 param_iterator param_end() const { return getParams() + NumParams; }
5155
5156 // Implement isa/cast/dyncast/etc.
5157 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5158 static bool classofKind(Kind K) { return K == Captured; }
5159 static DeclContext *castToDeclContext(const CapturedDecl *D) {
5160 return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
5161 }
5162 static CapturedDecl *castFromDeclContext(const DeclContext *DC) {
5163 return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
5164 }
5165};
5166
5167/// Describes a module import declaration, which makes the contents
5168/// of the named module visible in the current translation unit.
5169///
5170/// An import declaration imports the named module (or submodule). For example:
5171/// \code
5172/// @import std.vector;
5173/// \endcode
5174///
5175/// A C++20 module import declaration imports the named module or partition.
5176/// Periods are permitted in C++20 module names, but have no semantic meaning.
5177/// For example:
5178/// \code
5179/// import NamedModule;
5180/// import :SomePartition; // Must be a partition of the current module.
5181/// import Names.Like.this; // Allowed.
5182/// import :and.Also.Partition.names;
5183/// \endcode
5184///
5185/// Import declarations can also be implicitly generated from
5186/// \#include/\#import directives.
5187class ImportDecl final : public Decl,
5188 llvm::TrailingObjects<ImportDecl, SourceLocation> {
5189 friend class ASTContext;
5190 friend class ASTDeclReader;
5191 friend class ASTReader;
5192 friend TrailingObjects;
5193
5194 /// The imported module.
5195 Module *ImportedModule = nullptr;
5196
5197 /// The next import in the list of imports local to the translation
5198 /// unit being parsed (not loaded from an AST file).
5199 ///
5200 /// Includes a bit that indicates whether we have source-location information
5201 /// for each identifier in the module name.
5202 ///
5203 /// When the bit is false, we only have a single source location for the
5204 /// end of the import declaration.
5205 llvm::PointerIntPair<ImportDecl *, 1, bool> NextLocalImportAndComplete;
5206
5207 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
5208 ArrayRef<SourceLocation> IdentifierLocs);
5209
5210 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
5211 SourceLocation EndLoc);
5212
5213 ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
5214
5215 bool isImportComplete() const { return NextLocalImportAndComplete.getInt(); }
5216
5217 void setImportComplete(bool C) { NextLocalImportAndComplete.setInt(C); }
5218
5219 /// The next import in the list of imports local to the translation
5220 /// unit being parsed (not loaded from an AST file).
5221 ImportDecl *getNextLocalImport() const {
5222 return NextLocalImportAndComplete.getPointer();
5223 }
5224
5225 void setNextLocalImport(ImportDecl *Import) {
5226 NextLocalImportAndComplete.setPointer(Import);
5227 }
5228
5229public:
5230 /// Create a new module import declaration.
5231 static ImportDecl *Create(ASTContext &C, DeclContext *DC,
5232 SourceLocation StartLoc, Module *Imported,
5233 ArrayRef<SourceLocation> IdentifierLocs);
5234
5235 /// Create a new module import declaration for an implicitly-generated
5236 /// import.
5237 static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
5238 SourceLocation StartLoc, Module *Imported,
5239 SourceLocation EndLoc);
5240
5241 /// Create a new, deserialized module import declaration.
5242 static ImportDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
5243 unsigned NumLocations);
5244
5245 /// Retrieve the module that was imported by the import declaration.
5246 Module *getImportedModule() const { return ImportedModule; }
5247
5248 /// Retrieves the locations of each of the identifiers that make up
5249 /// the complete module name in the import declaration.
5250 ///
5251 /// This will return an empty array if the locations of the individual
5252 /// identifiers aren't available.
5254
5255 SourceRange getSourceRange() const override LLVM_READONLY;
5256
5257 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5258 static bool classofKind(Kind K) { return K == Import; }
5259};
5260
5261/// Represents a standard C++ module export declaration.
5262///
5263/// For example:
5264/// \code
5265/// export void foo();
5266/// \endcode
5267class ExportDecl final : public Decl, public DeclContext {
5268 LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
5269
5270private:
5271 friend class ASTDeclReader;
5272
5273 /// The source location for the right brace (if valid).
5274 SourceLocation RBraceLoc;
5275
5276 ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
5277 : Decl(Export, DC, ExportLoc), DeclContext(Export),
5278 RBraceLoc(SourceLocation()) {}
5279
5280public:
5282 SourceLocation ExportLoc);
5284
5286 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5287 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
5288
5289 bool hasBraces() const { return RBraceLoc.isValid(); }
5290
5291 SourceLocation getEndLoc() const LLVM_READONLY {
5292 if (hasBraces())
5293 return RBraceLoc;
5294 // No braces: get the end location of the (only) declaration in context
5295 // (if present).
5296 return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
5297 }
5298
5299 SourceRange getSourceRange() const override LLVM_READONLY {
5300 return SourceRange(getLocation(), getEndLoc());
5301 }
5302
5303 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5304 static bool classofKind(Kind K) { return K == Export; }
5305 static DeclContext *castToDeclContext(const ExportDecl *D) {
5306 return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
5307 }
5308 static ExportDecl *castFromDeclContext(const DeclContext *DC) {
5309 return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
5310 }
5311};
5312
5313/// Represents an empty-declaration.
5314class EmptyDecl : public Decl {
5315 EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {}
5316
5317 virtual void anchor();
5318
5319public:
5320 static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
5321 SourceLocation L);
5322 static EmptyDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
5323
5324 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5325 static bool classofKind(Kind K) { return K == Empty; }
5326};
5327
5328/// HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
5329class HLSLBufferDecl final : public NamedDecl, public DeclContext {
5330 /// LBraceLoc - The ending location of the source range.
5331 SourceLocation LBraceLoc;
5332 /// RBraceLoc - The ending location of the source range.
5333 SourceLocation RBraceLoc;
5334 /// KwLoc - The location of the cbuffer or tbuffer keyword.
5335 SourceLocation KwLoc;
5336 /// IsCBuffer - Whether the buffer is a cbuffer (and not a tbuffer).
5337 bool IsCBuffer;
5338 /// HasValidPackoffset - Whether the buffer has valid packoffset annotations
5339 // on all declarations
5340 bool HasValidPackoffset;
5341 // LayoutStruct - Layout struct for the buffer
5342 CXXRecordDecl *LayoutStruct;
5343
5344 // For default (implicit) constant buffer, an array of references of global
5345 // decls that belong to the buffer. The decls are already parented by the
5346 // translation unit context. The array is allocated by the ASTContext
5347 // allocator in HLSLBufferDecl::CreateDefaultCBuffer.
5348 ArrayRef<Decl *> DefaultBufferDecls;
5349
5350 HLSLBufferDecl(DeclContext *DC, bool CBuffer, SourceLocation KwLoc,
5351 IdentifierInfo *ID, SourceLocation IDLoc,
5352 SourceLocation LBrace);
5353
5354 void setDefaultBufferDecls(ArrayRef<Decl *> Decls);
5355
5356public:
5357 static HLSLBufferDecl *Create(ASTContext &C, DeclContext *LexicalParent,
5358 bool CBuffer, SourceLocation KwLoc,
5359 IdentifierInfo *ID, SourceLocation IDLoc,
5360 SourceLocation LBrace);
5361 static HLSLBufferDecl *
5363 ArrayRef<Decl *> DefaultCBufferDecls);
5364 static HLSLBufferDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
5365
5366 SourceRange getSourceRange() const override LLVM_READONLY {
5367 return SourceRange(getLocStart(), RBraceLoc);
5368 }
5369 SourceLocation getLocStart() const LLVM_READONLY { return KwLoc; }
5370 SourceLocation getLBraceLoc() const { return LBraceLoc; }
5371 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5372 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
5373 bool isCBuffer() const { return IsCBuffer; }
5374 void setHasValidPackoffset(bool PO) { HasValidPackoffset = PO; }
5375 bool hasValidPackoffset() const { return HasValidPackoffset; }
5376 const CXXRecordDecl *getLayoutStruct() const { return LayoutStruct; }
5378
5379 // Implement isa/cast/dyncast/etc.
5380 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5381 static bool classofKind(Kind K) { return K == HLSLBuffer; }
5382 static DeclContext *castToDeclContext(const HLSLBufferDecl *D) {
5383 return static_cast<DeclContext *>(const_cast<HLSLBufferDecl *>(D));
5384 }
5385 static HLSLBufferDecl *castFromDeclContext(const DeclContext *DC) {
5386 return static_cast<HLSLBufferDecl *>(const_cast<DeclContext *>(DC));
5387 }
5388
5389 // Iterator for the buffer decls. For constant buffers explicitly declared
5390 // with `cbuffer` keyword this will the list of decls parented by this
5391 // HLSLBufferDecl (equal to `decls()`).
5392 // For implicit $Globals buffer this will be the list of default buffer
5393 // declarations stored in DefaultBufferDecls plus the implicit layout
5394 // struct (the only child of HLSLBufferDecl in this case).
5395 //
5396 // The iterator uses llvm::concat_iterator to concatenate the lists
5397 // `decls()` and `DefaultBufferDecls`. For non-default buffers
5398 // `DefaultBufferDecls` is always empty.
5400 llvm::concat_iterator<Decl *const, SmallVector<Decl *>::const_iterator,
5402 using buffer_decl_range = llvm::iterator_range<buffer_decl_iterator>;
5403
5409 bool buffer_decls_empty();
5410
5411 friend class ASTDeclReader;
5412 friend class ASTDeclWriter;
5413};
5414
5415class HLSLRootSignatureDecl final
5416 : public NamedDecl,
5417 private llvm::TrailingObjects<HLSLRootSignatureDecl,
5418 llvm::hlsl::rootsig::RootElement> {
5419 friend TrailingObjects;
5420
5421 llvm::dxbc::RootSignatureVersion Version;
5422
5423 unsigned NumElems;
5424
5425 llvm::hlsl::rootsig::RootElement *getElems() { return getTrailingObjects(); }
5426
5427 const llvm::hlsl::rootsig::RootElement *getElems() const {
5428 return getTrailingObjects();
5429 }
5430
5431 HLSLRootSignatureDecl(DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
5432 llvm::dxbc::RootSignatureVersion Version,
5433 unsigned NumElems);
5434
5435public:
5436 static HLSLRootSignatureDecl *
5438 llvm::dxbc::RootSignatureVersion Version,
5440
5441 static HLSLRootSignatureDecl *CreateDeserialized(ASTContext &C,
5442 GlobalDeclID ID);
5443
5444 llvm::dxbc::RootSignatureVersion getVersion() const { return Version; }
5445
5447 return {getElems(), NumElems};
5448 }
5449
5450 // Implement isa/cast/dyncast/etc.
5451 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5452 static bool classofKind(Kind K) { return K == HLSLRootSignature; }
5453};
5454
5455/// Insertion operator for diagnostics. This allows sending NamedDecl's
5456/// into a diagnostic with <<.
5458 const NamedDecl *ND) {
5459 PD.AddTaggedVal(reinterpret_cast<uint64_t>(ND),
5461 return PD;
5462}
5463
5464template<typename decl_type>
5466 // Note: This routine is implemented here because we need both NamedDecl
5467 // and Redeclarable to be defined.
5468 assert(RedeclLink.isFirst() &&
5469 "setPreviousDecl on a decl already in a redeclaration chain");
5470
5471 if (PrevDecl) {
5472 // Point to previous. Make sure that this is actually the most recent
5473 // redeclaration, or we can build invalid chains. If the most recent
5474 // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
5475 First = PrevDecl->getFirstDecl();
5476 assert(First->RedeclLink.isFirst() && "Expected first");
5477 decl_type *MostRecent = First->getNextRedeclaration();
5479
5480 // If the declaration was previously visible, a redeclaration of it remains
5481 // visible even if it wouldn't be visible by itself.
5482 static_cast<decl_type*>(this)->IdentifierNamespace |=
5483 MostRecent->getIdentifierNamespace() &
5485 } else {
5486 // Make this first.
5487 First = static_cast<decl_type*>(this);
5488 }
5489
5490 // First one will point to this one as latest.
5491 First->RedeclLink.setLatest(static_cast<decl_type*>(this));
5492
5493 assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
5494 cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
5495}
5496
5497// Inline function definitions.
5498
5499/// Check if the given decl is complete.
5500///
5501/// We use this function to break a cycle between the inline definitions in
5502/// Type.h and Decl.h.
5504 if (const auto *Def = ED->getDefinition())
5505 return Def->isComplete();
5506 return ED->isComplete();
5507}
5508
5509/// Check if the given decl is scoped.
5510///
5511/// We use this function to break a cycle between the inline definitions in
5512/// Type.h and Decl.h.
5513inline bool IsEnumDeclScoped(EnumDecl *ED) {
5514 return ED->isScoped();
5515}
5516
5517/// OpenMP variants are mangled early based on their OpenMP context selector.
5518/// The new name looks likes this:
5519/// <name> + OpenMPVariantManglingSeparatorStr + <mangled OpenMP context>
5520static constexpr StringRef getOpenMPVariantManglingSeparatorStr() {
5521 return "$ompvariant";
5522}
5523
5524/// Returns whether the given FunctionDecl has an __arm[_locally]_streaming
5525/// attribute.
5526bool IsArmStreamingFunction(const FunctionDecl *FD,
5527 bool IncludeLocallyStreaming);
5528
5529/// Returns whether the given FunctionDecl has Arm ZA state.
5530bool hasArmZAState(const FunctionDecl *FD);
5531
5532/// Returns whether the given FunctionDecl has Arm ZT0 state.
5533bool hasArmZT0State(const FunctionDecl *FD);
5534
5535} // namespace clang
5536
5537#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:239
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:122
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:239
bool isNested() const
Whether this is a nested capture, i.e.
Definition Decl.h:4850
void setCopyExpr(Expr *e)
Definition Decl.h:4854
Expr * getCopyExpr() const
Definition Decl.h:4853
bool isByRef() const
Whether this is a "by ref" capture, i.e.
Definition Decl.h:4838
Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
Definition Decl.h:4828
bool isNonEscapingByref() const
Definition Decl.h:4844
VarDecl * getVariable() const
The variable being captured.
Definition Decl.h:4834
bool isEscapingByref() const
Definition Decl.h:4840
bool hasCopyExpr() const
Definition Decl.h:4852
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4807
ParmVarDecl * getParamDecl(unsigned i)
Definition Decl.h:4917
BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
Definition Decl.cpp:5500
static bool classofKind(Kind K)
Definition Decl.h:4993
CompoundStmt * getCompoundBody() const
Definition Decl.h:4885
static bool classof(const Decl *D)
Definition Decl.h:4992
unsigned getNumParams() const
Definition Decl.h:4911
unsigned getNumCaptures() const
Returns the number of captured variables.
Definition Decl.h:4930
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition Decl.cpp:5510
capture_const_iterator capture_begin() const
Definition Decl.h:4936
bool canAvoidCopyToHeap() const
Definition Decl.h:4961
void setDoesNotEscape(bool B=true)
Definition Decl.h:4959
param_iterator param_end()
Definition Decl.h:4906
capture_const_iterator capture_end() const
Definition Decl.h:4937
ArrayRef< Capture >::const_iterator capture_const_iterator
Definition Decl.h:4932
unsigned getBlockManglingNumber() const
Definition Decl.h:4973
param_const_iterator param_end() const
Definition Decl.h:4908
MutableArrayRef< ParmVarDecl * >::iterator param_iterator
Definition Decl.h:4901
size_t param_size() const
Definition Decl.h:4909
void setCapturesCXXThis(bool B=true)
Definition Decl.h:4940
void setSignatureAsWritten(TypeSourceInfo *Sig)
Definition Decl.h:4889
void setBlockMangling(unsigned Number, Decl *Ctx)
Definition Decl.h:4977
MutableArrayRef< ParmVarDecl * > parameters()
Definition Decl.h:4896
void setCanAvoidCopyToHeap(bool B=true)
Definition Decl.h:4964
param_iterator param_begin()
Definition Decl.h:4905
void setIsConversionFromLambda(bool val=true)
Definition Decl.h:4954
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:4886
static DeclContext * castToDeclContext(const BlockDecl *D)
Definition Decl.h:4994
void setBlockMissingReturnType(bool val=true)
Definition Decl.h:4946
FunctionEffectsRef getFunctionEffects() const
Definition Decl.h:4984
ArrayRef< Capture > captures() const
Definition Decl.h:4934
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5543
static BlockDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5718
void setIsVariadic(bool value)
Definition Decl.h:4883
bool param_empty() const
Definition Decl.h:4904
bool blockMissingReturnType() const
Definition Decl.h:4942
SourceLocation getCaretLocation() const
Definition Decl.h:4880
bool capturesCXXThis() const
Definition Decl.h:4939
bool capturesVariable(const VarDecl *var) const
Definition Decl.cpp:5534
bool doesNotEscape() const
Definition Decl.h:4958
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
Definition Decl.h:4926
Decl * getBlockManglingContextDecl() const
Definition Decl.h:4975
ArrayRef< ParmVarDecl * >::const_iterator param_const_iterator
Definition Decl.h:4902
static BlockDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4997
const ParmVarDecl * getParamDecl(unsigned i) const
Definition Decl.h:4913
void setBody(CompoundStmt *B)
Definition Decl.h:4887
param_const_iterator param_begin() const
Definition Decl.h:4907
bool isConversionFromLambda() const
Definition Decl.h:4950
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:4893
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
Definition Decl.cpp:5521
bool isVariadic() const
Definition Decl.h:4882
TypeSourceInfo * getSignatureAsWritten() const
Definition Decl.h:4890
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:5079
unsigned getNumParams() const
Definition Decl.h:5117
void setBody(Stmt *B)
Definition Decl.cpp:5768
static bool classof(const Decl *D)
Definition Decl.h:5157
ImplicitParamDecl *const * param_iterator
Definition Decl.h:5148
ImplicitParamDecl * getContextParam() const
Retrieve the parameter containing captured variables.
Definition Decl.h:5137
ArrayRef< ImplicitParamDecl * > parameters() const
Definition Decl.h:5129
static DeclContext * castToDeclContext(const CapturedDecl *D)
Definition Decl.h:5159
size_t numTrailingObjects(OverloadToken< ImplicitParamDecl >)
Definition Decl.h:5081
static CapturedDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams)
Definition Decl.cpp:5761
unsigned getContextParamPosition() const
Definition Decl.h:5146
bool isNothrow() const
Definition Decl.cpp:5770
static CapturedDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5162
static bool classofKind(Kind K)
Definition Decl.h:5158
friend class ASTDeclReader
Definition Decl.h:5102
void setContextParam(unsigned i, ImplicitParamDecl *P)
Definition Decl.h:5141
void setNothrow(bool Nothrow=true)
Definition Decl.cpp:5771
void setParam(unsigned i, ImplicitParamDecl *P)
Definition Decl.h:5123
friend TrailingObjects
Definition Decl.h:5104
friend class ASTDeclWriter
Definition Decl.h:5103
param_iterator param_end() const
Retrieve an iterator one past the last parameter decl.
Definition Decl.h:5154
MutableArrayRef< ImplicitParamDecl * > parameters()
Definition Decl.h:5132
param_iterator param_begin() const
Retrieve an iterator pointing to the first parameter decl.
Definition Decl.h:5152
llvm::iterator_range< param_iterator > param_range
Definition Decl.h:5149
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:5767
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:5119
CharUnits - 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:2360
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition DeclBase.h:2423
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2126
FunctionDeclBitfields FunctionDeclBits
Definition DeclBase.h:2061
TagDeclBitfields TagDeclBits
Definition DeclBase.h:2057
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
EnumDeclBitfields EnumDeclBits
Definition DeclBase.h:2058
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
BlockDeclBitfields BlockDeclBits
Definition DeclBase.h:2066
bool isRecord() const
Definition DeclBase.h:2206
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
RecordDeclBitfields RecordDeclBits
Definition DeclBase.h:2059
DeclContext(Decl::Kind K)
decl_iterator decls_end() const
Definition DeclBase.h:2405
NamespaceDeclBitfields NamespaceDeclBits
Definition DeclBase.h:2056
bool decls_empty() const
bool isFunctionOrMethod() const
Definition DeclBase.h:2178
Decl::Kind getDeclKind() const
Definition DeclBase.h:2119
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:443
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
Definition DeclBase.h:656
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:550
friend class Redeclarable
Definition DeclBase.h:339
virtual Decl * getPreviousDeclImpl()
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition DeclBase.h:1012
bool hasCachedLinkage() const
Definition DeclBase.h:429
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:1008
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:447
@ 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:602
DeclContext * getDeclContext()
Definition DeclBase.h:456
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:1016
void setModulePrivate()
Specify that this declaration was marked as being private to the module in which it was defined.
Definition DeclBase.h:718
friend class RecordDecl
Definition DeclBase.h:338
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:1640
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition DeclBase.h:935
friend class DeclContext
Definition DeclBase.h:260
Kind getKind() const
Definition DeclBase.h:450
DeclarationNameLoc - Additional source/type location info for a declaration name.
The name of a declaration.
SourceLocation getTypeSpecEndLoc() const
Definition Decl.cpp:2012
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:2068
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:2072
friend class ASTDeclReader
Definition Decl.h:807
SourceLocation getTypeSpecStartLoc() const
Definition Decl.cpp:2006
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:2018
void setTrailingRequiresClause(const AssociatedConstraint &AC)
Definition Decl.cpp:2037
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:2052
Provides information about a dependent function-template specialization declaration.
@ ak_nameddecl
NamedDecl *.
Definition Diagnostic.h:280
static EmptyDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5963
static bool classof(const Decl *D)
Definition Decl.h:5324
static bool classofKind(Kind K)
Definition Decl.h:5325
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3558
friend class StmtIteratorBase
Definition Decl.h:3568
EnumConstantDecl(const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
Definition Decl.cpp:5773
static EnumConstantDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5787
static bool classofKind(Kind K)
Definition Decl.h:3596
const EnumConstantDecl * getCanonicalDecl() const
Definition Decl.h:3592
void setInitExpr(Expr *E)
Definition Decl.h:3582
void setInitVal(const ASTContext &C, const llvm::APSInt &V)
Definition Decl.h:3583
llvm::APSInt getInitVal() const
Definition Decl.h:3578
EnumConstantDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this enumerator.
Definition Decl.h:3591
static bool classof(const Decl *D)
Definition Decl.h:3595
const Expr * getInitExpr() const
Definition Decl.h:3576
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5821
Represents an enum.
Definition Decl.h:4146
const EnumDecl * getMostRecentDecl() const
Definition Decl.h:4254
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4418
enumerator_range enumerators() const
Definition Decl.h:4292
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:4222
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4364
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4356
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4367
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4328
llvm::iterator_range< specific_decl_iterator< EnumConstantDecl > > enumerator_range
Definition Decl.h:4289
void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo)
Set the underlying integer type source info.
Definition Decl.h:4331
enumerator_iterator enumerator_begin() const
Definition Decl.h:4296
bool isComplete() const
Returns true if this can be considered a complete type.
Definition Decl.h:4378
void setInstantiationOfMemberEnum(EnumDecl *ED, TemplateSpecializationKind TSK)
Specify that this enumeration is an instantiation of the member enumeration ED.
Definition Decl.h:4424
const EnumDecl * getCanonicalDecl() const
Definition Decl.h:4239
unsigned getODRHash()
Definition Decl.cpp:5231
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:5192
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists,...
Definition Decl.h:4335
friend class ASTDeclReader
Definition Decl.h:4234
static EnumDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5147
bool isClosedFlag() const
Returns true if this enum is annotated with flag_enum and isn't annotated with enum_extensibility(ope...
Definition Decl.cpp:5177
EnumDecl * getMostRecentDecl()
Definition Decl.h:4251
EnumDecl * getDefinitionOrSelf() const
Definition Decl.h:4262
void setScoped(bool Scoped=true)
True if this tag declaration is a scoped enumeration.
Definition Decl.h:4210
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4373
SourceRange getIntegerTypeRange() const LLVM_READONLY
Retrieve the source range that covers the underlying type if specified.
Definition Decl.cpp:5152
void setPromotionType(QualType T)
Set the promotion type.
Definition Decl.h:4314
void setEnumKeyRange(SourceRange Range)
Definition Decl.h:4226
EnumDecl * getPreviousDecl()
Definition Decl.h:4243
SourceRange getSourceRange() const override LLVM_READONLY
Overrides to provide correct range when there's an enum-base specifier with forward declarations.
Definition Decl.cpp:5242
static bool classofKind(Kind K)
Definition Decl.h:4430
SourceRange getEnumKeyRange() const
Definition Decl.h:4224
static bool classof(const Decl *D)
Definition Decl.h:4429
EnumDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.h:4236
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4319
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5218
EnumDecl * getDefinition() const
Definition Decl.h:4258
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4345
const EnumDecl * getPreviousDecl() const
Definition Decl.h:4247
specific_decl_iterator< EnumConstantDecl > enumerator_iterator
Definition Decl.h:4288
TemplateSpecializationKind getTemplateSpecializationKind() const
If this enumeration is a member of a specialization of a templated class, determine what kind of temp...
Definition Decl.cpp:5185
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:4216
bool isClosed() const
Returns true if this enum is either annotated with enum_extensibility(closed) or isn't annotated with...
Definition Decl.cpp:5171
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4311
EnumDecl * getTemplateInstantiationPattern() const
Retrieve the enum definition from which this enumeration could be instantiated, if it is an instantia...
Definition Decl.cpp:5203
bool isClosedNonFlag() const
Returns true if this enum is annotated with neither flag_enum nor enum_extensibility(open).
Definition Decl.cpp:5181
enumerator_iterator enumerator_end() const
Definition Decl.h:4303
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:5253
Represents a standard C++ module export declaration.
Definition Decl.h:5267
static bool classof(const Decl *D)
Definition Decl.h:5303
SourceLocation getRBraceLoc() const
Definition Decl.h:5286
SourceLocation getEndLoc() const LLVM_READONLY
Definition Decl.h:5291
SourceLocation getExportLoc() const
Definition Decl.h:5285
static bool classofKind(Kind K)
Definition Decl.h:5304
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:5299
void setRBraceLoc(SourceLocation L)
Definition Decl.h:5287
friend class ASTDeclReader
Definition Decl.h:5271
static DeclContext * castToDeclContext(const ExportDecl *D)
Definition Decl.h:5305
static ExportDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5308
static ExportDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:6164
bool hasBraces() const
Definition Decl.h:5289
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:3295
Expr * BitWidth
Definition Decl.h:3347
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3395
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4789
bool isBitField() const
Determines whether this field is a bitfield.
Definition Decl.h:3398
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3475
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:3355
LazyDeclStmtPtr Init
Definition Decl.h:3345
unsigned getBitWidthValue() const
Computes the bit width of this field, if this is a bit field.
Definition Decl.cpp:4816
bool isAnonymousStructOrUnion() const
Determines whether this field is a representative for an anonymous struct or union.
Definition Decl.cpp:4779
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4890
void setBitWidth(Expr *Width)
Set the bit-field width for this member.
Definition Decl.h:3430
void removeBitWidth()
Remove the bit-field width from this member.
Definition Decl.h:3444
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3469
bool hasConstantIntegerBitWidth() const
Determines whether the bit width of this field is a constant integer.
Definition Decl.cpp:4811
friend class ASTDeclReader
Definition Decl.h:3367
static FieldDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:4773
void removeInClassInitializer()
Remove the C++11 in-class initializer from this member.
Definition Decl.h:3502
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4799
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition Decl.h:3380
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition Decl.h:3531
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:4830
InitAndBitWidthStorage * InitAndBitWidth
Definition Decl.h:3349
FieldDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this field.
Definition Decl.h:3542
static bool classofKind(Kind K)
Definition Decl.h:3547
bool hasCapturedVLAType() const
Determine whether this member captures the variable length array type.
Definition Decl.h:3514
friend class ASTDeclWriter
Definition Decl.h:3368
bool isUnnamedBitField() const
Determines whether this is an unnamed bitfield.
Definition Decl.h:3401
bool isZeroLengthBitField() const
Is this a zero-length bit-field?
Definition Decl.cpp:4825
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3411
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:4909
const FieldDecl * getCanonicalDecl() const
Definition Decl.h:3543
const FieldDecl * findCountedByField() const
Find the FieldDecl specified in a FAM's "counted_by" attribute.
Definition Decl.cpp:4919
RecordDecl * getParent()
Definition Decl.h:3535
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3519
bool isPotentiallyOverlapping() const
Determine if this field is of potentially-overlapping class type, that is, subobject with the [[no_un...
Definition Decl.cpp:4868
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4899
bool hasNonNullInClassInitializer() const
Determine whether getInClassInitializer() would return a non-null pointer without deserializing the i...
Definition Decl.h:3481
const VariableArrayType * CapturedVLAType
Definition Decl.h:3351
static bool classof(const Decl *D)
Definition Decl.h:3546
void setRParenLoc(SourceLocation L)
Definition Decl.h:4750
SourceLocation getAsmLoc() const
Definition Decl.h:4748
std::string getAsmString() const
Definition Decl.cpp:5925
Expr * getAsmStringExpr()
Definition Decl.h:4756
static bool classofKind(Kind K)
Definition Decl.h:4762
const Expr * getAsmStringExpr() const
Definition Decl.h:4755
SourceLocation getRParenLoc() const
Definition Decl.h:4749
static bool classof(const Decl *D)
Definition Decl.h:4761
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:4751
void setAsmString(Expr *Asm)
Definition Decl.h:4757
static FileScopeAsmDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5919
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:3171
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:4614
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:3768
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:2928
ExceptionSpecificationType getExceptionSpecType() const
Gets the ExceptionSpecificationType as declared.
Definition Decl.h:3000
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:3199
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2603
DefaultedOrDeletedFunctionInfo * getDefaultedOrDeletedInfo() const
Definition Decl.cpp:3183
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
Definition Decl.cpp:3891
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition Decl.cpp:4246
void setPreviousDeclaration(FunctionDecl *PrevDecl)
Definition Decl.cpp:3777
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4239
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4234
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3342
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
bool isImmediateFunction() const
Definition Decl.cpp:3384
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3149
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:3281
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:4068
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3595
static FunctionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5702
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
Definition Decl.cpp:3806
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:4575
bool isMemberLikeConstrainedFriend() const
Determine whether a function is a friend function that cannot be redeclared outside of its class,...
Definition Decl.cpp:3710
bool hasCXXExplicitFunctionObjectParameter() const
Definition Decl.cpp:3909
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
Definition Decl.h:3052
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:3040
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:3105
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:3695
QualType getReturnType() const
Definition Decl.h:2976
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:3750
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:4305
bool isMSExternInline() const
The combination of the extern and inline keywords under MSVC forces the function to be required.
Definition Decl.cpp:3935
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:3918
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:3658
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
Definition Decl.cpp:4354
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:4213
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:4364
void setUsesFPIntrin(bool I)
Set whether the function was declared in source context that requires constrained FP intrinsics.
Definition Decl.h:3044
void setDefaultLoc(SourceLocation NewLoc)
Definition Decl.h:2529
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:3791
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:4045
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:2954
bool isVariadic() const
Whether this function is variadic.
Definition Decl.cpp:3121
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:4430
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:4370
FunctionEffectsRef getFunctionEffects() const
Definition Decl.h:3269
static DeclContext * castToDeclContext(const FunctionDecl *D)
Definition Decl.h:3284
SourceRange getExceptionSpecSourceRange() const
Attempt to compute an informative source range covering the function exception specification,...
Definition Decl.cpp:4097
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:3419
unsigned getODRHash()
Returns ODRHash of the function.
Definition Decl.cpp:4743
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Determine the kind of template specialization this function represents for the purpose of template in...
Definition Decl.cpp:4482
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:3067
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
Definition Decl.cpp:4298
void setInlineSpecified(bool I)
Set whether the "inline" keyword was specified for this function.
Definition Decl.h:3033
unsigned getNumNonObjectParams() const
Definition Decl.cpp:3913
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:3611
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:3019
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:3060
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:4587
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:3570
bool FriendConstraintRefersToEnclosingTemplate() const
Definition Decl.h:2838
ParmVarDecl * getParamDecl(unsigned i)
Definition Decl.h:2932
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition Decl.cpp:4185
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4252
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:3447
ParmVarDecl * getNonObjectParameter(unsigned I)
Definition Decl.h:2958
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:4419
bool isInExternCContext() const
Determines whether this function's context is, or is nested within, a C++ extern "C" linkage spec.
Definition Decl.cpp:3666
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:4263
bool isExternC() const
Determines whether this function is a function with external, C linkage.
Definition Decl.cpp:3662
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:3355
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:3599
static bool classof(const Decl *D)
Definition Decl.h:3280
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:3205
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:3470
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:3603
bool isInExternCXXContext() const
Determines whether this function's context is, or is nested within, a C++ extern "C++" linkage spec.
Definition Decl.cpp:3672
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program.
Definition Decl.cpp:3412
void setImplicitlyInline(bool I=true)
Flag that this function is implicitly inline.
Definition Decl.h:3047
bool isTargetVersionMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target-version functiona...
Definition Decl.cpp:3772
void setTrivialForCall(bool IT)
Definition Decl.h:2508
bool param_empty() const
Definition Decl.h:2916
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3607
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:3212
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:3746
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:5709
void setIneligibleOrNotSelected(bool II)
Definition Decl.h:2548
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4610
bool isOverloadedOperator() const
Whether this function declaration represents an C++ overloaded operator, e.g., "operator+".
Definition Decl.h:3064
FunctionDecl * getInstantiatedFromDecl() const
Definition Decl.cpp:4258
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4527
const IdentifierInfo * getLiteralIdentifier() const
getLiteralIdentifier - The literal suffix identifier this function represents, if any.
Definition Decl.cpp:4179
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition Decl.cpp:4171
void setConstexprKind(ConstexprSpecKind CSK)
Definition Decl.h:2600
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4458
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:3985
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:3754
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:3706
DefaultedFunctionKind getDefaultedFunctionKind() const
Determine the kind of defaulting that would be done for a given function.
Definition Decl.cpp:3288
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:2993
void setStorageClass(StorageClass SClass)
Sets the storage class as written in the source.
Definition Decl.h:3024
void setBody(Stmt *B)
Definition Decl.cpp:3280
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:3676
bool hasOneParamOrDefaultArgs() const
Determine whether this function has a single parameter, or multiple parameters where all but the firs...
Definition Decl.cpp:3923
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3158
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:4555
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:3759
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4206
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:4119
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition Decl.cpp:3870
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:3188
SourceRange getParametersSourceRange() const
Attempt to compute an informative source range covering the function parameters, including the ellips...
Definition Decl.cpp:4081
static FunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:3287
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:3030
MultiVersionKind getMultiVersionKind() const
Gets the kind of multiversioning attribute this declaration has.
Definition Decl.cpp:3732
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:3113
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition Decl.h:2936
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:4380
QualType getCallResultType() const
Determine the type of an expression that calls this function.
Definition Decl.h:3012
bool isInstantiatedFromMemberTemplate() const
Definition Decl.h:2493
An immutable set of FunctionEffects and possibly conditions attached to them.
Definition TypeBase.h:5185
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5385
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition TypeBase.h:5692
SourceLocation getEllipsisLoc() const
Definition TypeBase.h:5791
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:4581
static HLSLBufferDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5385
buffer_decl_iterator buffer_decls_begin() const
Definition Decl.cpp:6034
static DeclContext * castToDeclContext(const HLSLBufferDecl *D)
Definition Decl.h:5382
bool isCBuffer() const
Definition Decl.h:5373
const CXXRecordDecl * getLayoutStruct() const
Definition Decl.h:5376
SourceLocation getLBraceLoc() const
Definition Decl.h:5370
SourceLocation getLocStart() const LLVM_READONLY
Definition Decl.h:5369
friend class ASTDeclReader
Definition Decl.h:5411
void addLayoutStruct(CXXRecordDecl *LS)
Definition Decl.cpp:6014
bool buffer_decls_empty()
Definition Decl.cpp:6046
SourceLocation getRBraceLoc() const
Definition Decl.h:5371
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:5366
void setRBraceLoc(SourceLocation L)
Definition Decl.h:5372
friend class ASTDeclWriter
Definition Decl.h:5412
bool hasValidPackoffset() const
Definition Decl.h:5375
llvm::concat_iterator< Decl *const, SmallVector< Decl * >::const_iterator, decl_iterator > buffer_decl_iterator
Definition Decl.h:5399
static bool classofKind(Kind K)
Definition Decl.h:5381
llvm::iterator_range< buffer_decl_iterator > buffer_decl_range
Definition Decl.h:5402
void setHasValidPackoffset(bool PO)
Definition Decl.h:5374
static HLSLBufferDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:6008
buffer_decl_iterator buffer_decls_end() const
Definition Decl.cpp:6040
static HLSLBufferDecl * CreateDefaultCBuffer(ASTContext &C, DeclContext *LexicalParent, ArrayRef< Decl * > DefaultCBufferDecls)
Definition Decl.cpp:5997
buffer_decl_range buffer_decls() const
Definition Decl.h:5404
static bool classof(const Decl *D)
Definition Decl.h:5380
static HLSLRootSignatureDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:6075
ArrayRef< llvm::hlsl::rootsig::RootElement > getRootElements() const
Definition Decl.h:5446
llvm::dxbc::RootSignatureVersion getVersion() const
Definition Decl.h:5444
static bool classofKind(Kind K)
Definition Decl.h:5452
static bool classof(const Decl *D)
Definition Decl.h:5451
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:5683
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:6146
static ImportDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumLocations)
Create a new, deserialized module import declaration.
Definition Decl.cpp:6133
friend class ASTReader
Definition Decl.h:5191
friend class ASTDeclReader
Definition Decl.h:5190
friend class ASTContext
Definition Decl.h:5189
static bool classof(const Decl *D)
Definition Decl.h:5257
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:6139
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition Decl.h:5246
static bool classofKind(Kind K)
Definition Decl.h:5258
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:6123
const IndirectFieldDecl * getCanonicalDecl() const
Definition Decl.h:3640
static bool classofKind(Kind K)
Definition Decl.h:3644
static bool classof(const Decl *D)
Definition Decl.h:3643
FieldDecl * getAnonField() const
Definition Decl.h:3629
static IndirectFieldDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5815
friend class ASTDeclReader
Definition Decl.h:3613
unsigned getChainingSize() const
Definition Decl.h:3627
IndirectFieldDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.h:3639
chain_iterator chain_end() const
Definition Decl.h:3625
chain_iterator chain_begin() const
Definition Decl.h:3624
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3623
VarDecl * getVarDecl() const
Definition Decl.h:3634
ArrayRef< NamedDecl * >::const_iterator chain_iterator
Definition Decl.h:3621
static bool classofKind(Kind K)
Definition Decl.h:567
void setMSAsmLabel(StringRef Name)
Definition Decl.cpp:5636
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:5631
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:1684
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:1850
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:1874
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:1691
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:1676
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
Definition Decl.cpp:1978
bool hasLinkage() const
Determine whether this declaration has linkage.
Definition Decl.cpp:1946
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:1718
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:5046
const ImplicitParamDecl *const * parameter_const_iterator
Definition Decl.h:5056
parameter_const_range parameters() const
Definition Decl.h:5058
static bool classof(const Decl *D)
Definition Decl.h:5065
static OutlinedFunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5070
static DeclContext * castToDeclContext(const OutlinedFunctionDecl *D)
Definition Decl.h:5067
friend class ASTDeclReader
Definition Decl.h:5029
void setNothrow(bool Nothrow=true)
Definition Decl.cpp:5747
parameter_const_iterator param_end() const
Definition Decl.h:5062
static bool classofKind(Kind K)
Definition Decl.h:5066
llvm::iterator_range< parameter_const_iterator > parameter_const_range
Definition Decl.h:5057
static OutlinedFunctionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams)
Definition Decl.cpp:5735
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:5741
void setParam(unsigned i, ImplicitParamDecl *P)
Definition Decl.h:5050
friend class ASTDeclWriter
Definition Decl.h:5030
parameter_const_iterator param_begin() const
Definition Decl.h:5061
unsigned getNumParams() const
Definition Decl.h:5044
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:3010
static ParmVarDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:2962
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:3015
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3035
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:2983
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:2954
const Expr * getUninstantiatedDefaultArg() const
Definition Decl.h:1932
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1912
Expr * getDefaultArg()
Definition Decl.cpp:2998
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3040
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3046
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:2968
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:5579
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:5604
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:4460
bool hasLoadedFieldsFromExternalStorage() const
Definition Decl.h:4529
unsigned getODRHash()
Get precomputed ODRHash or add a new one.
Definition Decl.cpp:5482
bool hasNonTrivialToPrimitiveDestructCUnion() const
Definition Decl.h:4570
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5310
bool hasNonTrivialToPrimitiveCopyCUnion() const
Definition Decl.h:4578
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:5376
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4516
bool canPassInRegisters() const
Determine whether this class can be passed in registers.
Definition Decl.h:4597
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:4683
unsigned getNumFields() const
Returns the number of fields (non-static data members) in this record.
Definition Decl.h:4676
RecordArgPassingKind getArgPassingRestrictions() const
Definition Decl.h:4601
RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl)
Definition Decl.cpp:5272
bool hasVolatileMember() const
Definition Decl.h:4523
bool hasFlexibleArrayMember() const
Definition Decl.h:4493
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Definition Decl.h:4562
const FieldDecl * findFirstNamedDataMember() const
Finds the first data member which has a name.
Definition Decl.cpp:5468
field_iterator noload_field_begin() const
Definition Decl.cpp:5349
const RecordDecl * getMostRecentDecl() const
Definition Decl.h:4489
void setArgPassingRestrictions(RecordArgPassingKind Kind)
Definition Decl.h:4606
void setNonTrivialToPrimitiveCopy(bool V)
Definition Decl.h:4550
bool hasObjectMember() const
Definition Decl.h:4520
bool isNonTrivialToPrimitiveDestroy() const
Definition Decl.h:4554
bool isNonTrivialToPrimitiveCopy() const
Definition Decl.h:4546
bool isCapturedRecord() const
Determine whether this record is a record for captured variables in CapturedStmt construct.
Definition Decl.cpp:5316
void setHasNonTrivialToPrimitiveCopyCUnion(bool V)
Definition Decl.h:4582
field_iterator field_end() const
Definition Decl.h:4666
field_range fields() const
Definition Decl.h:4663
llvm::iterator_range< specific_decl_iterator< FieldDecl > > field_range
Definition Decl.h:4661
bool isRandomized() const
Definition Decl.h:4618
void setHasNonTrivialToPrimitiveDestructCUnion(bool V)
Definition Decl.h:4574
friend class ASTDeclReader
Definition Decl.h:4465
static bool classofKind(Kind K)
Definition Decl.h:4701
void setHasFlexibleArrayMember(bool V)
Definition Decl.h:4497
void setParamDestroyedInCallee(bool V)
Definition Decl.h:4614
void setNonTrivialToPrimitiveDestroy(bool V)
Definition Decl.h:4558
void setHasObjectMember(bool val)
Definition Decl.h:4521
void setHasVolatileMember(bool val)
Definition Decl.h:4525
void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V)
Definition Decl.h:4566
void reorderDecls(const SmallVectorImpl< Decl * > &Decls)
Definition Decl.cpp:5387
void setIsRandomized(bool V)
Definition Decl.h:4620
bool isParamDestroyedInCallee() const
Definition Decl.h:4610
static RecordDecl * CreateDeserialized(const ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5303
bool noload_field_empty() const
Definition Decl.h:4693
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
Definition Decl.cpp:5424
static bool classof(const Decl *D)
Definition Decl.h:4700
RecordDecl * getMostRecentDecl()
Definition Decl.h:4486
const RecordDecl * getPreviousDecl() const
Definition Decl.h:4482
bool isOrContainsUnion() const
Returns whether this record is a union, or contains (at any nesting level) a union member.
Definition Decl.cpp:5324
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5355
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4644
bool hasUninitializedExplicitInitFields() const
Definition Decl.h:4586
field_iterator noload_field_end() const
Definition Decl.h:4688
void setCapturedRecord()
Mark the record as a record for captured variables in CapturedStmt construct.
Definition Decl.cpp:5320
specific_decl_iterator< FieldDecl > field_iterator
Definition Decl.h:4660
void setHasUninitializedExplicitInitFields(bool V)
Definition Decl.h:4590
RecordDecl * getPreviousDecl()
Definition Decl.h:4478
void setNonTrivialToPrimitiveDefaultInitialize(bool V)
Definition Decl.h:4542
RecordDecl * getDefinitionOrSelf() const
Definition Decl.h:4648
bool isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C structs.
Definition Decl.h:4538
friend class DeclContext
Definition Decl.h:4464
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4512
void setHasLoadedFieldsFromExternalStorage(bool val) const
Definition Decl.h:4533
bool field_empty() const
Definition Decl.h:4671
field_iterator field_begin() const
Definition Decl.cpp:5339
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:5465
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:1819
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3852
TagDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
void setTagKind(TagKind TK)
Definition Decl.h:4056
void setCompleteDefinitionRequired(bool V=true)
True if this complete decl is required to be complete for some existing use.
Definition Decl.h:3968
static TagDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4138
SourceRange getBraceRange() const
Definition Decl.h:3929
TagTypeKind TagKind
Definition Decl.h:3857
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3973
void demoteThisDefinitionToDeclaration()
Mark a definition as a declaration and maintain information it was a definition.
Definition Decl.h:4011
TagDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition Decl.h:3897
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4993
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3948
bool isEnum() const
Definition Decl.h:4064
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:3983
SourceLocation getInnerLocStart() const
Return SourceLocation representing start of source range ignoring outer template declarations.
Definition Decl.h:3934
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:3977
bool isStructureOrClass() const
Definition Decl.h:4066
StringRef getKindName() const
Definition Decl.h:4048
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3953
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:4106
bool isStruct() const
Definition Decl.h:4060
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:3920
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:4089
static bool classofKind(Kind K)
Definition Decl.h:4132
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4970
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:4963
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4965
friend class ASTDeclReader
Definition Decl.h:3916
SourceLocation getOuterLocStart() const
Return SourceLocation representing start of source range taking into account any outer template decla...
Definition Decl.cpp:4953
bool isCompleteDefinitionRequired() const
Return true if this complete decl is required to be complete for some existing use.
Definition Decl.h:3962
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4957
void printAnonymousTagDeclLocation(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
Definition Decl.cpp:5027
bool isEntityBeingDefined() const
Determines whether this entity is in the process of being defined.
Definition Decl.h:4042
bool isFreeStanding() const
True if this tag is free standing, e.g. "struct foo;".
Definition Decl.h:3988
ArrayRef< TemplateParameterList * > getTemplateParameterLists() const
Definition Decl.h:4113
bool isUnion() const
Definition Decl.h:4063
void setBeingDefined(bool V=true)
True if this decl is currently being defined.
Definition Decl.h:3907
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:5007
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition Decl.cpp:5106
void completeDefinition()
Completes the definition of this tag declaration.
Definition Decl.cpp:4981
bool isInterface() const
Definition Decl.h:4061
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:5092
friend class ASTDeclWriter
Definition Decl.h:3917
void setTypeForDecl(const Type *TD)=delete
static bool classof(const Decl *D)
Definition Decl.h:4131
Redeclarable< TagDecl > redeclarable_base
Definition Decl.h:3887
bool isClass() const
Definition Decl.h:4062
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition Decl.h:4098
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type?
Definition Decl.h:4085
void setFreeStanding(bool isFreeStanding=true)
True if this tag is free standing, e.g. "struct foo;".
Definition Decl.h:3991
TagKind getTagKind() const
Definition Decl.h:4052
TagDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition Decl.h:3889
TagDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition Decl.h:3893
bool isThisDeclarationADemotedDefinition() const
Whether this declaration was a definition in some module but was forced to be a declaration.
Definition Decl.h:4005
redeclarable_base::redecl_range redecl_range
Definition Decl.h:3919
static DeclContext * castToDeclContext(const TagDecl *D)
Definition Decl.h:4134
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition Decl.h:3998
void printAnonymousTagDecl(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
Definition Decl.cpp:5051
const Type * getTypeForDecl() const =delete
TagDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setBraceRange(SourceRange R)
Definition Decl.h:3930
TagDecl * getDefinitionOrSelf() const
Definition Decl.h:4035
TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl, SourceLocation StartL)
Definition Decl.cpp:4936
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3956
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:4770
static bool classofKind(Kind K)
Definition Decl.h:4794
const Stmt * getStmt() const
Definition Decl.h:4788
void setSemiMissing(bool Missing=true)
Definition Decl.h:4791
static bool classof(const Decl *D)
Definition Decl.h:4793
static TopLevelStmtDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5941
friend class ASTDeclReader
Definition Decl.h:4771
bool isSemiMissing() const
Definition Decl.h:4790
friend class ASTDeclWriter
Definition Decl.h:4772
static DeclContext * castToDeclContext(const TopLevelStmtDecl *D)
Definition Decl.h:4796
static TopLevelStmtDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4799
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5947
void setStmt(Stmt *S)
Definition Decl.cpp:5951
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:5557
static TypeAliasDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5889
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3841
void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT)
Definition Decl.h:3842
static bool classof(const Decl *D)
Definition Decl.h:3845
static bool classofKind(Kind K)
Definition Decl.h:3846
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5904
Declaration of an alias template.
void setLocStart(SourceLocation L)
Definition Decl.h:3683
static bool classofKind(Kind K)
Definition Decl.h:3693
void setTypeForDecl(const Type *TD)
Definition Decl.h:3677
friend class ASTReader
Definition Decl.h:3650
const Type * getTypeForDecl() const
Definition Decl.h:3673
friend class ASTContext
Definition Decl.h:3649
static bool classof(const Decl *D)
Definition Decl.h:3692
TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, const IdentifierInfo *Id, SourceLocation StartL=SourceLocation())
Definition Decl.h:3664
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:3684
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:3682
A container of type source information.
Definition TypeBase.h:8389
The base class of the type hierarchy.
Definition TypeBase.h:1879
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9321
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9254
static bool classofKind(Kind K)
Definition Decl.h:3818
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5895
static TypedefDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5876
static bool classof(const Decl *D)
Definition Decl.h:3817
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3697
TypedefNameDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition Decl.h:3720
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3747
Redeclarable< TypedefNameDecl > redeclarable_base
Definition Decl.h:3718
TypedefNameDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition Decl.h:3724
void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy)
Definition Decl.h:3762
redeclarable_base::redecl_range redecl_range
Definition Decl.h:3733
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:3743
static bool classof(const Decl *D)
Definition Decl.h:3791
const TypedefNameDecl * getCanonicalDecl() const
Definition Decl.h:3769
TypedefNameDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition Decl.h:3728
TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition Decl.h:3712
QualType getUnderlyingType() const
Definition Decl.h:3752
bool isTransparentTag() const
Determines if this typedef shares a name and spelling location with its underlying tag type,...
Definition Decl.h:3780
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:3734
TypedefNameDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this typedef-name.
Definition Decl.h:3768
void setTypeSourceInfo(TypeSourceInfo *newType)
Definition Decl.h:3758
static bool classofKind(Kind K)
Definition Decl.h:3792
TagDecl * getAnonDeclWithTypedefName(bool AnyRedecl=false) const
Retrieves the tag declaration for which this is the typedef name for linkage purposes,...
Definition Decl.cpp:5839
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:5657
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Definition Decl.cpp:5645
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:5651
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:2782
void setObjCForDecl(bool FRD)
Definition Decl.h:1561
Stmt ** getInitAddress()
Retrieve the address of the initializer expression.
Definition Decl.cpp:2404
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:2907
TLSKind getTLSKind() const
Definition Decl.cpp:2150
@ DAK_Uninstantiated
Definition Decl.h:1010
bool hasInit() const
Definition Decl.cpp:2380
bool hasICEInitializer(const ASTContext &Context) const
Determine whether the initializer of this variable is an integer constant expression.
Definition Decl.cpp:2629
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:2103
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:2172
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:2443
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:2239
bool hasFlexibleArrayInit(const ASTContext &Ctx) const
Whether this variable has a flexible array member initialized with one or more elements.
Definition Decl.cpp:2834
bool isNoDestroy(const ASTContext &) const
Is destruction of this variable entirely suppressed?
Definition Decl.cpp:2808
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:2621
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:2145
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:2426
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:2139
VarDecl * getTemplateInstantiationPattern() const
Retrieve the variable declaration from which this variable could be instantiated, if it is an instant...
Definition Decl.cpp:2699
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:2849
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
Definition Decl.cpp:2641
void assignAddressSpace(const ASTContext &Ctxt, LangAS AS)
Apply a deduced address space, if one isn't already set.
Definition Decl.cpp:2914
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:2223
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:2553
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:2468
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition Decl.cpp:2539
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:2744
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:2879
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:2823
bool checkForConstantInitialization(SmallVectorImpl< PartialDiagnosticAt > &Notes) const
Evaluate the initializer of this variable to determine whether it's a constant initializer.
Definition Decl.cpp:2657
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:2687
bool isInExternCContext() const
Determines whether this variable's context is, or is nested within, a C++ extern "C" linkage spec.
Definition Decl.cpp:2231
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:2557
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:2411
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:2459
VarDecl * getActingDefinition()
Get the tentative definition that acts as the real definition in a TU.
Definition Decl.cpp:2327
@ 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:2787
bool isExternC() const
Determines whether this variable is a variable with external, C linkage.
Definition Decl.cpp:2227
VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass SC)
Definition Decl.cpp:2116
void deduceParmAddressSpace(const ASTContext &Ctxt)
Definition Decl.cpp:2935
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:2683
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:2510
bool isInExternCXXContext() const
Determines whether this variable's context is, or is nested within, a C++ extern "C++" linkage spec.
Definition Decl.cpp:2235
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:2772
bool hasDependentAlignment() const
Determines if this variable's alignment is dependent.
Definition Decl.cpp:2691
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Get the template specialization kind of this variable for the purposes of template instantiation.
Definition Decl.cpp:2762
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:2751
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:2791
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:2870
Declaration of a variable template.
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:4044
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:272
@ ICIS_CopyInit
Copy initialization.
Definition Specifiers.h:274
@ ICIS_ListInit
Direct list-initialization.
Definition Specifiers.h:275
@ ICIS_NoInit
No in-class initializer.
Definition Specifiers.h:273
bool IsEnumDeclComplete(EnumDecl *ED)
Check if the given decl is complete.
Definition Decl.h:5503
@ 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:249
@ SC_Auto
Definition Specifiers.h:257
@ SC_PrivateExtern
Definition Specifiers.h:254
@ SC_Extern
Definition Specifiers.h:252
@ SC_Register
Definition Specifiers.h:258
@ SC_Static
Definition Specifiers.h:253
@ SC_None
Definition Specifiers.h:251
ThreadStorageClassSpecifier
Thread storage-class-specifier.
Definition Specifiers.h:236
@ TSCS_thread_local
C++11 thread_local.
Definition Specifiers.h:242
@ TSCS_unspecified
Definition Specifiers.h:237
static constexpr StringRef getOpenMPVariantManglingSeparatorStr()
OpenMP variants are mangled early based on their OpenMP context selector.
Definition Decl.h:5520
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:338
@ SD_Thread
Thread storage duration.
Definition Specifiers.h:341
@ SD_Static
Static storage duration.
Definition Specifiers.h:342
@ SD_Automatic
Automatic storage duration (most local variables).
Definition Specifiers.h:340
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:6189
TagTypeKind
The kind of a tag type.
Definition TypeBase.h:6008
@ Interface
The "__interface" keyword.
Definition TypeBase.h:6013
@ Struct
The "struct" keyword.
Definition TypeBase.h:6010
@ Class
The "class" keyword.
Definition TypeBase.h:6019
@ Union
The "union" keyword.
Definition TypeBase.h:6016
@ Enum
The "enum" keyword.
Definition TypeBase.h:6022
bool IsEnumDeclScoped(EnumDecl *ED)
Check if the given decl is scoped.
Definition Decl.h:5513
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:4437
@ CanPassInRegs
The argument of this type can be passed directly in registers.
Definition Decl.h:4439
@ CanNeverPassInRegs
The argument of this type cannot be passed directly in registers.
Definition Decl.h:4453
@ CannotPassInRegs
The argument of this type cannot be passed directly in registers.
Definition Decl.h:4448
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:189
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition Specifiers.h:195
U cast(CodeGen::Address addr)
Definition Address.h:327
@ None
The alignment was not explicit in code.
Definition ASTContext.h:176
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5997
bool IsArmStreamingFunction(const FunctionDecl *FD, bool IncludeLocallyStreaming)
Returns whether the given FunctionDecl has an __arm[_locally]_streaming attribute.
Definition Decl.cpp:6168
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:6182
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:6047
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:2083
The parameters to pass to a usual operator delete.
Definition ExprCXX.h:2348