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