clang 19.0.0git
Decl.cpp
Go to the documentation of this file.
1//===- Decl.cpp - Declaration AST Node Implementation ---------------------===//
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 implements the Decl subclasses.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/Decl.h"
14#include "Linkage.h"
17#include "clang/AST/ASTLambda.h"
19#include "clang/AST/Attr.h"
21#include "clang/AST/DeclBase.h"
22#include "clang/AST/DeclCXX.h"
23#include "clang/AST/DeclObjC.h"
27#include "clang/AST/Expr.h"
28#include "clang/AST/ExprCXX.h"
30#include "clang/AST/ODRHash.h"
36#include "clang/AST/Stmt.h"
38#include "clang/AST/Type.h"
39#include "clang/AST/TypeLoc.h"
42#include "clang/Basic/LLVM.h"
44#include "clang/Basic/Linkage.h"
45#include "clang/Basic/Module.h"
55#include "llvm/ADT/APSInt.h"
56#include "llvm/ADT/ArrayRef.h"
57#include "llvm/ADT/STLExtras.h"
58#include "llvm/ADT/SmallVector.h"
59#include "llvm/ADT/StringRef.h"
60#include "llvm/ADT/StringSwitch.h"
61#include "llvm/Support/Casting.h"
62#include "llvm/Support/ErrorHandling.h"
63#include "llvm/Support/raw_ostream.h"
64#include "llvm/TargetParser/Triple.h"
65#include <algorithm>
66#include <cassert>
67#include <cstddef>
68#include <cstring>
69#include <memory>
70#include <optional>
71#include <string>
72#include <tuple>
73#include <type_traits>
74
75using namespace clang;
76
79}
80
81void PrettyDeclStackTraceEntry::print(raw_ostream &OS) const {
82 SourceLocation Loc = this->Loc;
83 if (!Loc.isValid() && TheDecl) Loc = TheDecl->getLocation();
84 if (Loc.isValid()) {
85 Loc.print(OS, Context.getSourceManager());
86 OS << ": ";
87 }
88 OS << Message;
89
90 if (auto *ND = dyn_cast_if_present<NamedDecl>(TheDecl)) {
91 OS << " '";
92 ND->getNameForDiagnostic(OS, Context.getPrintingPolicy(), true);
93 OS << "'";
94 }
95
96 OS << '\n';
97}
98
99// Defined here so that it can be inlined into its direct callers.
100bool Decl::isOutOfLine() const {
102}
103
104TranslationUnitDecl::TranslationUnitDecl(ASTContext &ctx)
105 : Decl(TranslationUnit, nullptr, SourceLocation()),
106 DeclContext(TranslationUnit), redeclarable_base(ctx), Ctx(ctx) {}
107
108//===----------------------------------------------------------------------===//
109// NamedDecl Implementation
110//===----------------------------------------------------------------------===//
111
112// Visibility rules aren't rigorously externally specified, but here
113// are the basic principles behind what we implement:
114//
115// 1. An explicit visibility attribute is generally a direct expression
116// of the user's intent and should be honored. Only the innermost
117// visibility attribute applies. If no visibility attribute applies,
118// global visibility settings are considered.
119//
120// 2. There is one caveat to the above: on or in a template pattern,
121// an explicit visibility attribute is just a default rule, and
122// visibility can be decreased by the visibility of template
123// arguments. But this, too, has an exception: an attribute on an
124// explicit specialization or instantiation causes all the visibility
125// restrictions of the template arguments to be ignored.
126//
127// 3. A variable that does not otherwise have explicit visibility can
128// be restricted by the visibility of its type.
129//
130// 4. A visibility restriction is explicit if it comes from an
131// attribute (or something like it), not a global visibility setting.
132// When emitting a reference to an external symbol, visibility
133// restrictions are ignored unless they are explicit.
134//
135// 5. When computing the visibility of a non-type, including a
136// non-type member of a class, only non-type visibility restrictions
137// are considered: the 'visibility' attribute, global value-visibility
138// settings, and a few special cases like __private_extern.
139//
140// 6. When computing the visibility of a type, including a type member
141// of a class, only type visibility restrictions are considered:
142// the 'type_visibility' attribute and global type-visibility settings.
143// However, a 'visibility' attribute counts as a 'type_visibility'
144// attribute on any declaration that only has the former.
145//
146// The visibility of a "secondary" entity, like a template argument,
147// is computed using the kind of that entity, not the kind of the
148// primary entity for which we are computing visibility. For example,
149// the visibility of a specialization of either of these templates:
150// template <class T, bool (&compare)(T, X)> bool has_match(list<T>, X);
151// template <class T, bool (&compare)(T, X)> class matcher;
152// is restricted according to the type visibility of the argument 'T',
153// the type visibility of 'bool(&)(T,X)', and the value visibility of
154// the argument function 'compare'. That 'has_match' is a value
155// and 'matcher' is a type only matters when looking for attributes
156// and settings from the immediate context.
157
158/// Does this computation kind permit us to consider additional
159/// visibility settings from attributes and the like?
161 return computation.IgnoreExplicitVisibility;
162}
163
164/// Given an LVComputationKind, return one of the same type/value sort
165/// that records that it already has explicit visibility.
168 Kind.IgnoreExplicitVisibility = true;
169 return Kind;
170}
171
172static std::optional<Visibility> getExplicitVisibility(const NamedDecl *D,
173 LVComputationKind kind) {
174 assert(!kind.IgnoreExplicitVisibility &&
175 "asking for explicit visibility when we shouldn't be");
176 return D->getExplicitVisibility(kind.getExplicitVisibilityKind());
177}
178
179/// Is the given declaration a "type" or a "value" for the purposes of
180/// visibility computation?
181static bool usesTypeVisibility(const NamedDecl *D) {
182 return isa<TypeDecl>(D) ||
183 isa<ClassTemplateDecl>(D) ||
184 isa<ObjCInterfaceDecl>(D);
185}
186
187/// Does the given declaration have member specialization information,
188/// and if so, is it an explicit specialization?
189template <class T>
190static std::enable_if_t<!std::is_base_of_v<RedeclarableTemplateDecl, T>, bool>
192 if (const MemberSpecializationInfo *member =
193 D->getMemberSpecializationInfo()) {
194 return member->isExplicitSpecialization();
195 }
196 return false;
197}
198
199/// For templates, this question is easier: a member template can't be
200/// explicitly instantiated, so there's a single bit indicating whether
201/// or not this is an explicit member specialization.
203 return D->isMemberSpecialization();
204}
205
206/// Given a visibility attribute, return the explicit visibility
207/// associated with it.
208template <class T>
209static Visibility getVisibilityFromAttr(const T *attr) {
210 switch (attr->getVisibility()) {
211 case T::Default:
212 return DefaultVisibility;
213 case T::Hidden:
214 return HiddenVisibility;
215 case T::Protected:
216 return ProtectedVisibility;
217 }
218 llvm_unreachable("bad visibility kind");
219}
220
221/// Return the explicit visibility of the given declaration.
222static std::optional<Visibility>
224 // If we're ultimately computing the visibility of a type, look for
225 // a 'type_visibility' attribute before looking for 'visibility'.
226 if (kind == NamedDecl::VisibilityForType) {
227 if (const auto *A = D->getAttr<TypeVisibilityAttr>()) {
228 return getVisibilityFromAttr(A);
229 }
230 }
231
232 // If this declaration has an explicit visibility attribute, use it.
233 if (const auto *A = D->getAttr<VisibilityAttr>()) {
234 return getVisibilityFromAttr(A);
235 }
236
237 return std::nullopt;
238}
239
240LinkageInfo LinkageComputer::getLVForType(const Type &T,
241 LVComputationKind computation) {
242 if (computation.IgnoreAllVisibility)
243 return LinkageInfo(T.getLinkage(), DefaultVisibility, true);
245}
246
247/// Get the most restrictive linkage for the types in the given
248/// template parameter list. For visibility purposes, template
249/// parameters are part of the signature of a template.
250LinkageInfo LinkageComputer::getLVForTemplateParameterList(
251 const TemplateParameterList *Params, LVComputationKind computation) {
252 LinkageInfo LV;
253 for (const NamedDecl *P : *Params) {
254 // Template type parameters are the most common and never
255 // contribute to visibility, pack or not.
256 if (isa<TemplateTypeParmDecl>(P))
257 continue;
258
259 // Non-type template parameters can be restricted by the value type, e.g.
260 // template <enum X> class A { ... };
261 // We have to be careful here, though, because we can be dealing with
262 // dependent types.
263 if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
264 // Handle the non-pack case first.
265 if (!NTTP->isExpandedParameterPack()) {
266 if (!NTTP->getType()->isDependentType()) {
267 LV.merge(getLVForType(*NTTP->getType(), computation));
268 }
269 continue;
270 }
271
272 // Look at all the types in an expanded pack.
273 for (unsigned i = 0, n = NTTP->getNumExpansionTypes(); i != n; ++i) {
274 QualType type = NTTP->getExpansionType(i);
275 if (!type->isDependentType())
277 }
278 continue;
279 }
280
281 // Template template parameters can be restricted by their
282 // template parameters, recursively.
283 const auto *TTP = cast<TemplateTemplateParmDecl>(P);
284
285 // Handle the non-pack case first.
286 if (!TTP->isExpandedParameterPack()) {
287 LV.merge(getLVForTemplateParameterList(TTP->getTemplateParameters(),
288 computation));
289 continue;
290 }
291
292 // Look at all expansions in an expanded pack.
293 for (unsigned i = 0, n = TTP->getNumExpansionTemplateParameters();
294 i != n; ++i) {
295 LV.merge(getLVForTemplateParameterList(
296 TTP->getExpansionTemplateParameters(i), computation));
297 }
298 }
299
300 return LV;
301}
302
303static const Decl *getOutermostFuncOrBlockContext(const Decl *D) {
304 const Decl *Ret = nullptr;
305 const DeclContext *DC = D->getDeclContext();
306 while (DC->getDeclKind() != Decl::TranslationUnit) {
307 if (isa<FunctionDecl>(DC) || isa<BlockDecl>(DC))
308 Ret = cast<Decl>(DC);
309 DC = DC->getParent();
310 }
311 return Ret;
312}
313
314/// Get the most restrictive linkage for the types and
315/// declarations in the given template argument list.
316///
317/// Note that we don't take an LVComputationKind because we always
318/// want to honor the visibility of template arguments in the same way.
320LinkageComputer::getLVForTemplateArgumentList(ArrayRef<TemplateArgument> Args,
321 LVComputationKind computation) {
322 LinkageInfo LV;
323
324 for (const TemplateArgument &Arg : Args) {
325 switch (Arg.getKind()) {
329 continue;
330
332 LV.merge(getLVForType(*Arg.getAsType(), computation));
333 continue;
334
336 const NamedDecl *ND = Arg.getAsDecl();
337 assert(!usesTypeVisibility(ND));
338 LV.merge(getLVForDecl(ND, computation));
339 continue;
340 }
341
343 LV.merge(getTypeLinkageAndVisibility(Arg.getNullPtrType()));
344 continue;
345
347 LV.merge(getLVForValue(Arg.getAsStructuralValue(), computation));
348 continue;
349
352 if (TemplateDecl *Template =
353 Arg.getAsTemplateOrTemplatePattern().getAsTemplateDecl())
354 LV.merge(getLVForDecl(Template, computation));
355 continue;
356
358 LV.merge(getLVForTemplateArgumentList(Arg.getPackAsArray(), computation));
359 continue;
360 }
361 llvm_unreachable("bad template argument kind");
362 }
363
364 return LV;
365}
366
368LinkageComputer::getLVForTemplateArgumentList(const TemplateArgumentList &TArgs,
369 LVComputationKind computation) {
370 return getLVForTemplateArgumentList(TArgs.asArray(), computation);
371}
372
374 const FunctionTemplateSpecializationInfo *specInfo) {
375 // Include visibility from the template parameters and arguments
376 // only if this is not an explicit instantiation or specialization
377 // with direct explicit visibility. (Implicit instantiations won't
378 // have a direct attribute.)
380 return true;
381
382 return !fn->hasAttr<VisibilityAttr>();
383}
384
385/// Merge in template-related linkage and visibility for the given
386/// function template specialization.
387///
388/// We don't need a computation kind here because we can assume
389/// LVForValue.
390///
391/// \param[out] LV the computation to use for the parent
392void LinkageComputer::mergeTemplateLV(
393 LinkageInfo &LV, const FunctionDecl *fn,
395 LVComputationKind computation) {
396 bool considerVisibility =
398
399 FunctionTemplateDecl *temp = specInfo->getTemplate();
400 // Merge information from the template declaration.
401 LinkageInfo tempLV = getLVForDecl(temp, computation);
402 // The linkage of the specialization should be consistent with the
403 // template declaration.
404 LV.setLinkage(tempLV.getLinkage());
405
406 // Merge information from the template parameters.
407 LinkageInfo paramsLV =
408 getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
409 LV.mergeMaybeWithVisibility(paramsLV, considerVisibility);
410
411 // Merge information from the template arguments.
412 const TemplateArgumentList &templateArgs = *specInfo->TemplateArguments;
413 LinkageInfo argsLV = getLVForTemplateArgumentList(templateArgs, computation);
414 LV.mergeMaybeWithVisibility(argsLV, considerVisibility);
415}
416
417/// Does the given declaration have a direct visibility attribute
418/// that would match the given rules?
420 LVComputationKind computation) {
421 if (computation.IgnoreAllVisibility)
422 return false;
423
424 return (computation.isTypeVisibility() && D->hasAttr<TypeVisibilityAttr>()) ||
425 D->hasAttr<VisibilityAttr>();
426}
427
428/// Should we consider visibility associated with the template
429/// arguments and parameters of the given class template specialization?
432 LVComputationKind computation) {
433 // Include visibility from the template parameters and arguments
434 // only if this is not an explicit instantiation or specialization
435 // with direct explicit visibility (and note that implicit
436 // instantiations won't have a direct attribute).
437 //
438 // Furthermore, we want to ignore template parameters and arguments
439 // for an explicit specialization when computing the visibility of a
440 // member thereof with explicit visibility.
441 //
442 // This is a bit complex; let's unpack it.
443 //
444 // An explicit class specialization is an independent, top-level
445 // declaration. As such, if it or any of its members has an
446 // explicit visibility attribute, that must directly express the
447 // user's intent, and we should honor it. The same logic applies to
448 // an explicit instantiation of a member of such a thing.
449
450 // Fast path: if this is not an explicit instantiation or
451 // specialization, we always want to consider template-related
452 // visibility restrictions.
454 return true;
455
456 // This is the 'member thereof' check.
457 if (spec->isExplicitSpecialization() &&
458 hasExplicitVisibilityAlready(computation))
459 return false;
460
461 return !hasDirectVisibilityAttribute(spec, computation);
462}
463
464/// Merge in template-related linkage and visibility for the given
465/// class template specialization.
466void LinkageComputer::mergeTemplateLV(
468 LVComputationKind computation) {
469 bool considerVisibility = shouldConsiderTemplateVisibility(spec, computation);
470
471 // Merge information from the template parameters, but ignore
472 // visibility if we're only considering template arguments.
474 // Merge information from the template declaration.
475 LinkageInfo tempLV = getLVForDecl(temp, computation);
476 // The linkage of the specialization should be consistent with the
477 // template declaration.
478 LV.setLinkage(tempLV.getLinkage());
479
480 LinkageInfo paramsLV =
481 getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
482 LV.mergeMaybeWithVisibility(paramsLV,
483 considerVisibility && !hasExplicitVisibilityAlready(computation));
484
485 // Merge information from the template arguments. We ignore
486 // template-argument visibility if we've got an explicit
487 // instantiation with a visibility attribute.
488 const TemplateArgumentList &templateArgs = spec->getTemplateArgs();
489 LinkageInfo argsLV = getLVForTemplateArgumentList(templateArgs, computation);
490 if (considerVisibility)
491 LV.mergeVisibility(argsLV);
492 LV.mergeExternalVisibility(argsLV);
493}
494
495/// Should we consider visibility associated with the template
496/// arguments and parameters of the given variable template
497/// specialization? As usual, follow class template specialization
498/// logic up to initialization.
501 LVComputationKind computation) {
502 // Include visibility from the template parameters and arguments
503 // only if this is not an explicit instantiation or specialization
504 // with direct explicit visibility (and note that implicit
505 // instantiations won't have a direct attribute).
507 return true;
508
509 // An explicit variable specialization is an independent, top-level
510 // declaration. As such, if it has an explicit visibility attribute,
511 // that must directly express the user's intent, and we should honor
512 // it.
513 if (spec->isExplicitSpecialization() &&
514 hasExplicitVisibilityAlready(computation))
515 return false;
516
517 return !hasDirectVisibilityAttribute(spec, computation);
518}
519
520/// Merge in template-related linkage and visibility for the given
521/// variable template specialization. As usual, follow class template
522/// specialization logic up to initialization.
523void LinkageComputer::mergeTemplateLV(LinkageInfo &LV,
525 LVComputationKind computation) {
526 bool considerVisibility = shouldConsiderTemplateVisibility(spec, computation);
527
528 // Merge information from the template parameters, but ignore
529 // visibility if we're only considering template arguments.
531 LinkageInfo tempLV =
532 getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
533 LV.mergeMaybeWithVisibility(tempLV,
534 considerVisibility && !hasExplicitVisibilityAlready(computation));
535
536 // Merge information from the template arguments. We ignore
537 // template-argument visibility if we've got an explicit
538 // instantiation with a visibility attribute.
539 const TemplateArgumentList &templateArgs = spec->getTemplateArgs();
540 LinkageInfo argsLV = getLVForTemplateArgumentList(templateArgs, computation);
541 if (considerVisibility)
542 LV.mergeVisibility(argsLV);
543 LV.mergeExternalVisibility(argsLV);
544}
545
547 // FIXME: we should warn if -fvisibility-inlines-hidden is used with c.
548 const LangOptions &Opts = D->getASTContext().getLangOpts();
549 if (!Opts.CPlusPlus || !Opts.InlineVisibilityHidden)
550 return false;
551
552 const auto *FD = dyn_cast<FunctionDecl>(D);
553 if (!FD)
554 return false;
555
558 = FD->getTemplateSpecializationInfo()) {
559 TSK = spec->getTemplateSpecializationKind();
560 } else if (MemberSpecializationInfo *MSI =
561 FD->getMemberSpecializationInfo()) {
562 TSK = MSI->getTemplateSpecializationKind();
563 }
564
565 const FunctionDecl *Def = nullptr;
566 // InlineVisibilityHidden only applies to definitions, and
567 // isInlined() only gives meaningful answers on definitions
568 // anyway.
571 FD->hasBody(Def) && Def->isInlined() && !Def->hasAttr<GNUInlineAttr>();
572}
573
574template <typename T> static bool isFirstInExternCContext(T *D) {
575 const T *First = D->getFirstDecl();
576 return First->isInExternCContext();
577}
578
579static bool isSingleLineLanguageLinkage(const Decl &D) {
580 if (const auto *SD = dyn_cast<LinkageSpecDecl>(D.getDeclContext()))
581 if (!SD->hasBraces())
582 return true;
583 return false;
584}
585
587 if (auto *M = D->getOwningModule())
588 return M->isInterfaceOrPartition();
589 return false;
590}
591
593 return LinkageInfo::external();
594}
595
597 if (auto *TD = dyn_cast<TemplateDecl>(D))
598 D = TD->getTemplatedDecl();
599 if (D) {
600 if (auto *VD = dyn_cast<VarDecl>(D))
601 return VD->getStorageClass();
602 if (auto *FD = dyn_cast<FunctionDecl>(D))
603 return FD->getStorageClass();
604 }
605 return SC_None;
606}
607
609LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
610 LVComputationKind computation,
611 bool IgnoreVarTypeLinkage) {
613 "Not a name having namespace scope");
614 ASTContext &Context = D->getASTContext();
615
616 // C++ [basic.link]p3:
617 // A name having namespace scope (3.3.6) has internal linkage if it
618 // is the name of
619
621 // - a variable, variable template, function, or function template
622 // that is explicitly declared static; or
623 // (This bullet corresponds to C99 6.2.2p3.)
624 return LinkageInfo::internal();
625 }
626
627 if (const auto *Var = dyn_cast<VarDecl>(D)) {
628 // - a non-template variable of non-volatile const-qualified type, unless
629 // - it is explicitly declared extern, or
630 // - it is declared in the purview of a module interface unit
631 // (outside the private-module-fragment, if any) or module partition, or
632 // - it is inline, or
633 // - it was previously declared and the prior declaration did not have
634 // internal linkage
635 // (There is no equivalent in C99.)
636 if (Context.getLangOpts().CPlusPlus && Var->getType().isConstQualified() &&
637 !Var->getType().isVolatileQualified() && !Var->isInline() &&
639 !isa<VarTemplateSpecializationDecl>(Var) &&
640 !Var->getDescribedVarTemplate()) {
641 const VarDecl *PrevVar = Var->getPreviousDecl();
642 if (PrevVar)
643 return getLVForDecl(PrevVar, computation);
644
645 if (Var->getStorageClass() != SC_Extern &&
646 Var->getStorageClass() != SC_PrivateExtern &&
648 return LinkageInfo::internal();
649 }
650
651 for (const VarDecl *PrevVar = Var->getPreviousDecl(); PrevVar;
652 PrevVar = PrevVar->getPreviousDecl()) {
653 if (PrevVar->getStorageClass() == SC_PrivateExtern &&
654 Var->getStorageClass() == SC_None)
655 return getDeclLinkageAndVisibility(PrevVar);
656 // Explicitly declared static.
657 if (PrevVar->getStorageClass() == SC_Static)
658 return LinkageInfo::internal();
659 }
660 } else if (const auto *IFD = dyn_cast<IndirectFieldDecl>(D)) {
661 // - a data member of an anonymous union.
662 const VarDecl *VD = IFD->getVarDecl();
663 assert(VD && "Expected a VarDecl in this IndirectFieldDecl!");
664 return getLVForNamespaceScopeDecl(VD, computation, IgnoreVarTypeLinkage);
665 }
666 assert(!isa<FieldDecl>(D) && "Didn't expect a FieldDecl!");
667
668 // FIXME: This gives internal linkage to names that should have no linkage
669 // (those not covered by [basic.link]p6).
670 if (D->isInAnonymousNamespace()) {
671 const auto *Var = dyn_cast<VarDecl>(D);
672 const auto *Func = dyn_cast<FunctionDecl>(D);
673 // FIXME: The check for extern "C" here is not justified by the standard
674 // wording, but we retain it from the pre-DR1113 model to avoid breaking
675 // code.
676 //
677 // C++11 [basic.link]p4:
678 // An unnamed namespace or a namespace declared directly or indirectly
679 // within an unnamed namespace has internal linkage.
680 if ((!Var || !isFirstInExternCContext(Var)) &&
682 return LinkageInfo::internal();
683 }
684
685 // Set up the defaults.
686
687 // C99 6.2.2p5:
688 // If the declaration of an identifier for an object has file
689 // scope and no storage-class specifier, its linkage is
690 // external.
692
693 if (!hasExplicitVisibilityAlready(computation)) {
694 if (std::optional<Visibility> Vis = getExplicitVisibility(D, computation)) {
695 LV.mergeVisibility(*Vis, true);
696 } else {
697 // If we're declared in a namespace with a visibility attribute,
698 // use that namespace's visibility, and it still counts as explicit.
699 for (const DeclContext *DC = D->getDeclContext();
700 !isa<TranslationUnitDecl>(DC);
701 DC = DC->getParent()) {
702 const auto *ND = dyn_cast<NamespaceDecl>(DC);
703 if (!ND) continue;
704 if (std::optional<Visibility> Vis =
705 getExplicitVisibility(ND, computation)) {
706 LV.mergeVisibility(*Vis, true);
707 break;
708 }
709 }
710 }
711
712 // Add in global settings if the above didn't give us direct visibility.
713 if (!LV.isVisibilityExplicit()) {
714 // Use global type/value visibility as appropriate.
715 Visibility globalVisibility =
716 computation.isValueVisibility()
717 ? Context.getLangOpts().getValueVisibilityMode()
718 : Context.getLangOpts().getTypeVisibilityMode();
719 LV.mergeVisibility(globalVisibility, /*explicit*/ false);
720
721 // If we're paying attention to global visibility, apply
722 // -finline-visibility-hidden if this is an inline method.
724 LV.mergeVisibility(HiddenVisibility, /*visibilityExplicit=*/false);
725 }
726 }
727
728 // C++ [basic.link]p4:
729
730 // A name having namespace scope that has not been given internal linkage
731 // above and that is the name of
732 // [...bullets...]
733 // has its linkage determined as follows:
734 // - if the enclosing namespace has internal linkage, the name has
735 // internal linkage; [handled above]
736 // - otherwise, if the declaration of the name is attached to a named
737 // module and is not exported, the name has module linkage;
738 // - otherwise, the name has external linkage.
739 // LV is currently set up to handle the last two bullets.
740 //
741 // The bullets are:
742
743 // - a variable; or
744 if (const auto *Var = dyn_cast<VarDecl>(D)) {
745 // GCC applies the following optimization to variables and static
746 // data members, but not to functions:
747 //
748 // Modify the variable's LV by the LV of its type unless this is
749 // C or extern "C". This follows from [basic.link]p9:
750 // A type without linkage shall not be used as the type of a
751 // variable or function with external linkage unless
752 // - the entity has C language linkage, or
753 // - the entity is declared within an unnamed namespace, or
754 // - the entity is not used or is defined in the same
755 // translation unit.
756 // and [basic.link]p10:
757 // ...the types specified by all declarations referring to a
758 // given variable or function shall be identical...
759 // C does not have an equivalent rule.
760 //
761 // Ignore this if we've got an explicit attribute; the user
762 // probably knows what they're doing.
763 //
764 // Note that we don't want to make the variable non-external
765 // because of this, but unique-external linkage suits us.
766
767 if (Context.getLangOpts().CPlusPlus && !isFirstInExternCContext(Var) &&
768 !IgnoreVarTypeLinkage) {
769 LinkageInfo TypeLV = getLVForType(*Var->getType(), computation);
770 if (!isExternallyVisible(TypeLV.getLinkage()))
772 if (!LV.isVisibilityExplicit())
773 LV.mergeVisibility(TypeLV);
774 }
775
776 if (Var->getStorageClass() == SC_PrivateExtern)
778
779 // Note that Sema::MergeVarDecl already takes care of implementing
780 // C99 6.2.2p4 and propagating the visibility attribute, so we don't have
781 // to do it here.
782
783 // As per function and class template specializations (below),
784 // consider LV for the template and template arguments. We're at file
785 // scope, so we do not need to worry about nested specializations.
786 if (const auto *spec = dyn_cast<VarTemplateSpecializationDecl>(Var)) {
787 mergeTemplateLV(LV, spec, computation);
788 }
789
790 // - a function; or
791 } else if (const auto *Function = dyn_cast<FunctionDecl>(D)) {
792 // In theory, we can modify the function's LV by the LV of its
793 // type unless it has C linkage (see comment above about variables
794 // for justification). In practice, GCC doesn't do this, so it's
795 // just too painful to make work.
796
797 if (Function->getStorageClass() == SC_PrivateExtern)
799
800 // OpenMP target declare device functions are not callable from the host so
801 // they should not be exported from the device image. This applies to all
802 // functions as the host-callable kernel functions are emitted at codegen.
803 if (Context.getLangOpts().OpenMP &&
804 Context.getLangOpts().OpenMPIsTargetDevice &&
805 ((Context.getTargetInfo().getTriple().isAMDGPU() ||
806 Context.getTargetInfo().getTriple().isNVPTX()) ||
807 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Function)))
808 LV.mergeVisibility(HiddenVisibility, /*newExplicit=*/false);
809
810 // Note that Sema::MergeCompatibleFunctionDecls already takes care of
811 // merging storage classes and visibility attributes, so we don't have to
812 // look at previous decls in here.
813
814 // In C++, then if the type of the function uses a type with
815 // unique-external linkage, it's not legally usable from outside
816 // this translation unit. However, we should use the C linkage
817 // rules instead for extern "C" declarations.
818 if (Context.getLangOpts().CPlusPlus && !isFirstInExternCContext(Function)) {
819 // Only look at the type-as-written. Otherwise, deducing the return type
820 // of a function could change its linkage.
821 QualType TypeAsWritten = Function->getType();
822 if (TypeSourceInfo *TSI = Function->getTypeSourceInfo())
823 TypeAsWritten = TSI->getType();
824 if (!isExternallyVisible(TypeAsWritten->getLinkage()))
826 }
827
828 // Consider LV from the template and the template arguments.
829 // We're at file scope, so we do not need to worry about nested
830 // specializations.
832 = Function->getTemplateSpecializationInfo()) {
833 mergeTemplateLV(LV, Function, specInfo, computation);
834 }
835
836 // - a named class (Clause 9), or an unnamed class defined in a
837 // typedef declaration in which the class has the typedef name
838 // for linkage purposes (7.1.3); or
839 // - a named enumeration (7.2), or an unnamed enumeration
840 // defined in a typedef declaration in which the enumeration
841 // has the typedef name for linkage purposes (7.1.3); or
842 } else if (const auto *Tag = dyn_cast<TagDecl>(D)) {
843 // Unnamed tags have no linkage.
844 if (!Tag->hasNameForLinkage())
845 return LinkageInfo::none();
846
847 // If this is a class template specialization, consider the
848 // linkage of the template and template arguments. We're at file
849 // scope, so we do not need to worry about nested specializations.
850 if (const auto *spec = dyn_cast<ClassTemplateSpecializationDecl>(Tag)) {
851 mergeTemplateLV(LV, spec, computation);
852 }
853
854 // FIXME: This is not part of the C++ standard any more.
855 // - an enumerator belonging to an enumeration with external linkage; or
856 } else if (isa<EnumConstantDecl>(D)) {
857 LinkageInfo EnumLV = getLVForDecl(cast<NamedDecl>(D->getDeclContext()),
858 computation);
859 if (!isExternalFormalLinkage(EnumLV.getLinkage()))
860 return LinkageInfo::none();
861 LV.merge(EnumLV);
862
863 // - a template
864 } else if (const auto *temp = dyn_cast<TemplateDecl>(D)) {
865 bool considerVisibility = !hasExplicitVisibilityAlready(computation);
866 LinkageInfo tempLV =
867 getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
868 LV.mergeMaybeWithVisibility(tempLV, considerVisibility);
869
870 // An unnamed namespace or a namespace declared directly or indirectly
871 // within an unnamed namespace has internal linkage. All other namespaces
872 // have external linkage.
873 //
874 // We handled names in anonymous namespaces above.
875 } else if (isa<NamespaceDecl>(D)) {
876 return LV;
877
878 // By extension, we assign external linkage to Objective-C
879 // interfaces.
880 } else if (isa<ObjCInterfaceDecl>(D)) {
881 // fallout
882
883 } else if (auto *TD = dyn_cast<TypedefNameDecl>(D)) {
884 // A typedef declaration has linkage if it gives a type a name for
885 // linkage purposes.
886 if (!TD->getAnonDeclWithTypedefName(/*AnyRedecl*/true))
887 return LinkageInfo::none();
888
889 } else if (isa<MSGuidDecl>(D)) {
890 // A GUID behaves like an inline variable with external linkage. Fall
891 // through.
892
893 // Everything not covered here has no linkage.
894 } else {
895 return LinkageInfo::none();
896 }
897
898 // If we ended up with non-externally-visible linkage, visibility should
899 // always be default.
901 return LinkageInfo(LV.getLinkage(), DefaultVisibility, false);
902
903 return LV;
904}
905
907LinkageComputer::getLVForClassMember(const NamedDecl *D,
908 LVComputationKind computation,
909 bool IgnoreVarTypeLinkage) {
910 // Only certain class members have linkage. Note that fields don't
911 // really have linkage, but it's convenient to say they do for the
912 // purposes of calculating linkage of pointer-to-data-member
913 // template arguments.
914 //
915 // Templates also don't officially have linkage, but since we ignore
916 // the C++ standard and look at template arguments when determining
917 // linkage and visibility of a template specialization, we might hit
918 // a template template argument that way. If we do, we need to
919 // consider its linkage.
920 if (!(isa<CXXMethodDecl>(D) ||
921 isa<VarDecl>(D) ||
922 isa<FieldDecl>(D) ||
923 isa<IndirectFieldDecl>(D) ||
924 isa<TagDecl>(D) ||
925 isa<TemplateDecl>(D)))
926 return LinkageInfo::none();
927
928 LinkageInfo LV;
929
930 // If we have an explicit visibility attribute, merge that in.
931 if (!hasExplicitVisibilityAlready(computation)) {
932 if (std::optional<Visibility> Vis = getExplicitVisibility(D, computation))
933 LV.mergeVisibility(*Vis, true);
934 // If we're paying attention to global visibility, apply
935 // -finline-visibility-hidden if this is an inline method.
936 //
937 // Note that we do this before merging information about
938 // the class visibility.
940 LV.mergeVisibility(HiddenVisibility, /*visibilityExplicit=*/false);
941 }
942
943 // If this class member has an explicit visibility attribute, the only
944 // thing that can change its visibility is the template arguments, so
945 // only look for them when processing the class.
946 LVComputationKind classComputation = computation;
947 if (LV.isVisibilityExplicit())
948 classComputation = withExplicitVisibilityAlready(computation);
949
950 LinkageInfo classLV =
951 getLVForDecl(cast<RecordDecl>(D->getDeclContext()), classComputation);
952 // The member has the same linkage as the class. If that's not externally
953 // visible, we don't need to compute anything about the linkage.
954 // FIXME: If we're only computing linkage, can we bail out here?
955 if (!isExternallyVisible(classLV.getLinkage()))
956 return classLV;
957
958
959 // Otherwise, don't merge in classLV yet, because in certain cases
960 // we need to completely ignore the visibility from it.
961
962 // Specifically, if this decl exists and has an explicit attribute.
963 const NamedDecl *explicitSpecSuppressor = nullptr;
964
965 if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
966 // Only look at the type-as-written. Otherwise, deducing the return type
967 // of a function could change its linkage.
968 QualType TypeAsWritten = MD->getType();
969 if (TypeSourceInfo *TSI = MD->getTypeSourceInfo())
970 TypeAsWritten = TSI->getType();
971 if (!isExternallyVisible(TypeAsWritten->getLinkage()))
973
974 // If this is a method template specialization, use the linkage for
975 // the template parameters and arguments.
977 = MD->getTemplateSpecializationInfo()) {
978 mergeTemplateLV(LV, MD, spec, computation);
979 if (spec->isExplicitSpecialization()) {
980 explicitSpecSuppressor = MD;
981 } else if (isExplicitMemberSpecialization(spec->getTemplate())) {
982 explicitSpecSuppressor = spec->getTemplate()->getTemplatedDecl();
983 }
984 } else if (isExplicitMemberSpecialization(MD)) {
985 explicitSpecSuppressor = MD;
986 }
987
988 // OpenMP target declare device functions are not callable from the host so
989 // they should not be exported from the device image. This applies to all
990 // functions as the host-callable kernel functions are emitted at codegen.
991 ASTContext &Context = D->getASTContext();
992 if (Context.getLangOpts().OpenMP &&
993 Context.getLangOpts().OpenMPIsTargetDevice &&
994 ((Context.getTargetInfo().getTriple().isAMDGPU() ||
995 Context.getTargetInfo().getTriple().isNVPTX()) ||
996 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(MD)))
997 LV.mergeVisibility(HiddenVisibility, /*newExplicit=*/false);
998
999 } else if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
1000 if (const auto *spec = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
1001 mergeTemplateLV(LV, spec, computation);
1002 if (spec->isExplicitSpecialization()) {
1003 explicitSpecSuppressor = spec;
1004 } else {
1005 const ClassTemplateDecl *temp = spec->getSpecializedTemplate();
1007 explicitSpecSuppressor = temp->getTemplatedDecl();
1008 }
1009 }
1010 } else if (isExplicitMemberSpecialization(RD)) {
1011 explicitSpecSuppressor = RD;
1012 }
1013
1014 // Static data members.
1015 } else if (const auto *VD = dyn_cast<VarDecl>(D)) {
1016 if (const auto *spec = dyn_cast<VarTemplateSpecializationDecl>(VD))
1017 mergeTemplateLV(LV, spec, computation);
1018
1019 // Modify the variable's linkage by its type, but ignore the
1020 // type's visibility unless it's a definition.
1021 if (!IgnoreVarTypeLinkage) {
1022 LinkageInfo typeLV = getLVForType(*VD->getType(), computation);
1023 // FIXME: If the type's linkage is not externally visible, we can
1024 // give this static data member UniqueExternalLinkage.
1025 if (!LV.isVisibilityExplicit() && !classLV.isVisibilityExplicit())
1026 LV.mergeVisibility(typeLV);
1027 LV.mergeExternalVisibility(typeLV);
1028 }
1029
1031 explicitSpecSuppressor = VD;
1032 }
1033
1034 // Template members.
1035 } else if (const auto *temp = dyn_cast<TemplateDecl>(D)) {
1036 bool considerVisibility =
1037 (!LV.isVisibilityExplicit() &&
1038 !classLV.isVisibilityExplicit() &&
1039 !hasExplicitVisibilityAlready(computation));
1040 LinkageInfo tempLV =
1041 getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
1042 LV.mergeMaybeWithVisibility(tempLV, considerVisibility);
1043
1044 if (const auto *redeclTemp = dyn_cast<RedeclarableTemplateDecl>(temp)) {
1045 if (isExplicitMemberSpecialization(redeclTemp)) {
1046 explicitSpecSuppressor = temp->getTemplatedDecl();
1047 }
1048 }
1049 }
1050
1051 // We should never be looking for an attribute directly on a template.
1052 assert(!explicitSpecSuppressor || !isa<TemplateDecl>(explicitSpecSuppressor));
1053
1054 // If this member is an explicit member specialization, and it has
1055 // an explicit attribute, ignore visibility from the parent.
1056 bool considerClassVisibility = true;
1057 if (explicitSpecSuppressor &&
1058 // optimization: hasDVA() is true only with explicit visibility.
1059 LV.isVisibilityExplicit() &&
1060 classLV.getVisibility() != DefaultVisibility &&
1061 hasDirectVisibilityAttribute(explicitSpecSuppressor, computation)) {
1062 considerClassVisibility = false;
1063 }
1064
1065 // Finally, merge in information from the class.
1066 LV.mergeMaybeWithVisibility(classLV, considerClassVisibility);
1067 return LV;
1068}
1069
1070void NamedDecl::anchor() {}
1071
1073 if (!hasCachedLinkage())
1074 return true;
1075
1078 .getLinkage();
1079 return L == getCachedLinkage();
1080}
1081
1082bool NamedDecl::isPlaceholderVar(const LangOptions &LangOpts) const {
1083 // [C++2c] [basic.scope.scope]/p5
1084 // A declaration is name-independent if its name is _ and it declares
1085 // - a variable with automatic storage duration,
1086 // - a structured binding not inhabiting a namespace scope,
1087 // - the variable introduced by an init-capture
1088 // - or a non-static data member.
1089
1090 if (!LangOpts.CPlusPlus || !getIdentifier() ||
1091 !getIdentifier()->isPlaceholder())
1092 return false;
1093 if (isa<FieldDecl>(this))
1094 return true;
1095 if (const auto *IFD = dyn_cast<IndirectFieldDecl>(this)) {
1097 !getDeclContext()->isRecord())
1098 return false;
1099 const VarDecl *VD = IFD->getVarDecl();
1100 return !VD || VD->getStorageDuration() == SD_Automatic;
1101 }
1102 // and it declares a variable with automatic storage duration
1103 if (const auto *VD = dyn_cast<VarDecl>(this)) {
1104 if (isa<ParmVarDecl>(VD))
1105 return false;
1106 if (VD->isInitCapture())
1107 return true;
1109 }
1110 if (const auto *BD = dyn_cast<BindingDecl>(this);
1112 const VarDecl *VD = BD->getHoldingVar();
1114 }
1115 return false;
1116}
1117
1119NamedDecl::isReserved(const LangOptions &LangOpts) const {
1120 const IdentifierInfo *II = getIdentifier();
1121
1122 // This triggers at least for CXXLiteralIdentifiers, which we already checked
1123 // at lexing time.
1124 if (!II)
1126
1127 ReservedIdentifierStatus Status = II->isReserved(LangOpts);
1128 if (isReservedAtGlobalScope(Status) && !isReservedInAllContexts(Status)) {
1129 // This name is only reserved at global scope. Check if this declaration
1130 // conflicts with a global scope declaration.
1131 if (isa<ParmVarDecl>(this) || isTemplateParameter())
1133
1134 // C++ [dcl.link]/7:
1135 // Two declarations [conflict] if [...] one declares a function or
1136 // variable with C language linkage, and the other declares [...] a
1137 // variable that belongs to the global scope.
1138 //
1139 // Therefore names that are reserved at global scope are also reserved as
1140 // names of variables and functions with C language linkage.
1142 if (DC->isTranslationUnit())
1143 return Status;
1144 if (auto *VD = dyn_cast<VarDecl>(this))
1145 if (VD->isExternC())
1147 if (auto *FD = dyn_cast<FunctionDecl>(this))
1148 if (FD->isExternC())
1151 }
1152
1153 return Status;
1154}
1155
1157 StringRef name = getName();
1158 if (name.empty()) return SFF_None;
1159
1160 if (name.front() == 'C')
1161 if (name == "CFStringCreateWithFormat" ||
1162 name == "CFStringCreateWithFormatAndArguments" ||
1163 name == "CFStringAppendFormat" ||
1164 name == "CFStringAppendFormatAndArguments")
1165 return SFF_CFString;
1166 return SFF_None;
1167}
1168
1170 // We don't care about visibility here, so ask for the cheapest
1171 // possible visibility analysis.
1172 return LinkageComputer{}
1174 .getLinkage();
1175}
1176
1177/// Determine whether D is attached to a named module.
1178static bool isInNamedModule(const NamedDecl *D) {
1179 if (auto *M = D->getOwningModule())
1180 return M->isNamedModule();
1181 return false;
1182}
1183
1185 // FIXME: Handle isModulePrivate.
1186 switch (D->getModuleOwnershipKind()) {
1190 return false;
1193 return isInNamedModule(D);
1194 }
1195 llvm_unreachable("unexpected module ownership kind");
1196}
1197
1198/// Get the linkage from a semantic point of view. Entities in
1199/// anonymous namespaces are external (in c++98).
1201 Linkage InternalLinkage = getLinkageInternal();
1202
1203 // C++ [basic.link]p4.8:
1204 // - if the declaration of the name is attached to a named module and is not
1205 // exported
1206 // the name has module linkage;
1207 //
1208 // [basic.namespace.general]/p2
1209 // A namespace is never attached to a named module and never has a name with
1210 // module linkage.
1211 if (isInNamedModule(this) && InternalLinkage == Linkage::External &&
1213 cast<NamedDecl>(this->getCanonicalDecl())) &&
1214 !isa<NamespaceDecl>(this))
1215 InternalLinkage = Linkage::Module;
1216
1217 return clang::getFormalLinkage(InternalLinkage);
1218}
1219
1222}
1223
1224static std::optional<Visibility>
1227 bool IsMostRecent) {
1228 assert(!IsMostRecent || ND == ND->getMostRecentDecl());
1229
1230 // Check the declaration itself first.
1231 if (std::optional<Visibility> V = getVisibilityOf(ND, kind))
1232 return V;
1233
1234 // If this is a member class of a specialization of a class template
1235 // and the corresponding decl has explicit visibility, use that.
1236 if (const auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
1237 CXXRecordDecl *InstantiatedFrom = RD->getInstantiatedFromMemberClass();
1238 if (InstantiatedFrom)
1239 return getVisibilityOf(InstantiatedFrom, kind);
1240 }
1241
1242 // If there wasn't explicit visibility there, and this is a
1243 // specialization of a class template, check for visibility
1244 // on the pattern.
1245 if (const auto *spec = dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
1246 // Walk all the template decl till this point to see if there are
1247 // explicit visibility attributes.
1248 const auto *TD = spec->getSpecializedTemplate()->getTemplatedDecl();
1249 while (TD != nullptr) {
1250 auto Vis = getVisibilityOf(TD, kind);
1251 if (Vis != std::nullopt)
1252 return Vis;
1253 TD = TD->getPreviousDecl();
1254 }
1255 return std::nullopt;
1256 }
1257
1258 // Use the most recent declaration.
1259 if (!IsMostRecent && !isa<NamespaceDecl>(ND)) {
1260 const NamedDecl *MostRecent = ND->getMostRecentDecl();
1261 if (MostRecent != ND)
1262 return getExplicitVisibilityAux(MostRecent, kind, true);
1263 }
1264
1265 if (const auto *Var = dyn_cast<VarDecl>(ND)) {
1266 if (Var->isStaticDataMember()) {
1267 VarDecl *InstantiatedFrom = Var->getInstantiatedFromStaticDataMember();
1268 if (InstantiatedFrom)
1269 return getVisibilityOf(InstantiatedFrom, kind);
1270 }
1271
1272 if (const auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(Var))
1273 return getVisibilityOf(VTSD->getSpecializedTemplate()->getTemplatedDecl(),
1274 kind);
1275
1276 return std::nullopt;
1277 }
1278 // Also handle function template specializations.
1279 if (const auto *fn = dyn_cast<FunctionDecl>(ND)) {
1280 // If the function is a specialization of a template with an
1281 // explicit visibility attribute, use that.
1282 if (FunctionTemplateSpecializationInfo *templateInfo
1284 return getVisibilityOf(templateInfo->getTemplate()->getTemplatedDecl(),
1285 kind);
1286
1287 // If the function is a member of a specialization of a class template
1288 // and the corresponding decl has explicit visibility, use that.
1289 FunctionDecl *InstantiatedFrom = fn->getInstantiatedFromMemberFunction();
1290 if (InstantiatedFrom)
1291 return getVisibilityOf(InstantiatedFrom, kind);
1292
1293 return std::nullopt;
1294 }
1295
1296 // The visibility of a template is stored in the templated decl.
1297 if (const auto *TD = dyn_cast<TemplateDecl>(ND))
1298 return getVisibilityOf(TD->getTemplatedDecl(), kind);
1299
1300 return std::nullopt;
1301}
1302
1303std::optional<Visibility>
1305 return getExplicitVisibilityAux(this, kind, false);
1306}
1307
1308LinkageInfo LinkageComputer::getLVForClosure(const DeclContext *DC,
1309 Decl *ContextDecl,
1310 LVComputationKind computation) {
1311 // This lambda has its linkage/visibility determined by its owner.
1312 const NamedDecl *Owner;
1313 if (!ContextDecl)
1314 Owner = dyn_cast<NamedDecl>(DC);
1315 else if (isa<ParmVarDecl>(ContextDecl))
1316 Owner =
1317 dyn_cast<NamedDecl>(ContextDecl->getDeclContext()->getRedeclContext());
1318 else if (isa<ImplicitConceptSpecializationDecl>(ContextDecl)) {
1319 // Replace with the concept's owning decl, which is either a namespace or a
1320 // TU, so this needs a dyn_cast.
1321 Owner = dyn_cast<NamedDecl>(ContextDecl->getDeclContext());
1322 } else {
1323 Owner = cast<NamedDecl>(ContextDecl);
1324 }
1325
1326 if (!Owner)
1327 return LinkageInfo::none();
1328
1329 // If the owner has a deduced type, we need to skip querying the linkage and
1330 // visibility of that type, because it might involve this closure type. The
1331 // only effect of this is that we might give a lambda VisibleNoLinkage rather
1332 // than NoLinkage when we don't strictly need to, which is benign.
1333 auto *VD = dyn_cast<VarDecl>(Owner);
1334 LinkageInfo OwnerLV =
1335 VD && VD->getType()->getContainedDeducedType()
1336 ? computeLVForDecl(Owner, computation, /*IgnoreVarTypeLinkage*/true)
1337 : getLVForDecl(Owner, computation);
1338
1339 // A lambda never formally has linkage. But if the owner is externally
1340 // visible, then the lambda is too. We apply the same rules to blocks.
1341 if (!isExternallyVisible(OwnerLV.getLinkage()))
1342 return LinkageInfo::none();
1344 OwnerLV.isVisibilityExplicit());
1345}
1346
1347LinkageInfo LinkageComputer::getLVForLocalDecl(const NamedDecl *D,
1348 LVComputationKind computation) {
1349 if (const auto *Function = dyn_cast<FunctionDecl>(D)) {
1350 if (Function->isInAnonymousNamespace() &&
1352 return LinkageInfo::internal();
1353
1354 // This is a "void f();" which got merged with a file static.
1355 if (Function->getCanonicalDecl()->getStorageClass() == SC_Static)
1356 return LinkageInfo::internal();
1357
1358 LinkageInfo LV;
1359 if (!hasExplicitVisibilityAlready(computation)) {
1360 if (std::optional<Visibility> Vis =
1361 getExplicitVisibility(Function, computation))
1362 LV.mergeVisibility(*Vis, true);
1363 }
1364
1365 // Note that Sema::MergeCompatibleFunctionDecls already takes care of
1366 // merging storage classes and visibility attributes, so we don't have to
1367 // look at previous decls in here.
1368
1369 return LV;
1370 }
1371
1372 if (const auto *Var = dyn_cast<VarDecl>(D)) {
1373 if (Var->hasExternalStorage()) {
1374 if (Var->isInAnonymousNamespace() && !isFirstInExternCContext(Var))
1375 return LinkageInfo::internal();
1376
1377 LinkageInfo LV;
1378 if (Var->getStorageClass() == SC_PrivateExtern)
1380 else if (!hasExplicitVisibilityAlready(computation)) {
1381 if (std::optional<Visibility> Vis =
1382 getExplicitVisibility(Var, computation))
1383 LV.mergeVisibility(*Vis, true);
1384 }
1385
1386 if (const VarDecl *Prev = Var->getPreviousDecl()) {
1387 LinkageInfo PrevLV = getLVForDecl(Prev, computation);
1388 if (PrevLV.getLinkage() != Linkage::Invalid)
1389 LV.setLinkage(PrevLV.getLinkage());
1390 LV.mergeVisibility(PrevLV);
1391 }
1392
1393 return LV;
1394 }
1395
1396 if (!Var->isStaticLocal())
1397 return LinkageInfo::none();
1398 }
1399
1400 ASTContext &Context = D->getASTContext();
1401 if (!Context.getLangOpts().CPlusPlus)
1402 return LinkageInfo::none();
1403
1404 const Decl *OuterD = getOutermostFuncOrBlockContext(D);
1405 if (!OuterD || OuterD->isInvalidDecl())
1406 return LinkageInfo::none();
1407
1408 LinkageInfo LV;
1409 if (const auto *BD = dyn_cast<BlockDecl>(OuterD)) {
1410 if (!BD->getBlockManglingNumber())
1411 return LinkageInfo::none();
1412
1413 LV = getLVForClosure(BD->getDeclContext()->getRedeclContext(),
1414 BD->getBlockManglingContextDecl(), computation);
1415 } else {
1416 const auto *FD = cast<FunctionDecl>(OuterD);
1417 if (!FD->isInlined() &&
1418 !isTemplateInstantiation(FD->getTemplateSpecializationKind()))
1419 return LinkageInfo::none();
1420
1421 // If a function is hidden by -fvisibility-inlines-hidden option and
1422 // is not explicitly attributed as a hidden function,
1423 // we should not make static local variables in the function hidden.
1424 LV = getLVForDecl(FD, computation);
1425 if (isa<VarDecl>(D) && useInlineVisibilityHidden(FD) &&
1426 !LV.isVisibilityExplicit() &&
1427 !Context.getLangOpts().VisibilityInlinesHiddenStaticLocalVar) {
1428 assert(cast<VarDecl>(D)->isStaticLocal());
1429 // If this was an implicitly hidden inline method, check again for
1430 // explicit visibility on the parent class, and use that for static locals
1431 // if present.
1432 if (const auto *MD = dyn_cast<CXXMethodDecl>(FD))
1433 LV = getLVForDecl(MD->getParent(), computation);
1434 if (!LV.isVisibilityExplicit()) {
1435 Visibility globalVisibility =
1436 computation.isValueVisibility()
1437 ? Context.getLangOpts().getValueVisibilityMode()
1438 : Context.getLangOpts().getTypeVisibilityMode();
1439 return LinkageInfo(Linkage::VisibleNone, globalVisibility,
1440 /*visibilityExplicit=*/false);
1441 }
1442 }
1443 }
1445 return LinkageInfo::none();
1448}
1449
1451 LVComputationKind computation,
1452 bool IgnoreVarTypeLinkage) {
1453 // Internal_linkage attribute overrides other considerations.
1454 if (D->hasAttr<InternalLinkageAttr>())
1455 return LinkageInfo::internal();
1456
1457 // Objective-C: treat all Objective-C declarations as having external
1458 // linkage.
1459 switch (D->getKind()) {
1460 default:
1461 break;
1462
1463 // Per C++ [basic.link]p2, only the names of objects, references,
1464 // functions, types, templates, namespaces, and values ever have linkage.
1465 //
1466 // Note that the name of a typedef, namespace alias, using declaration,
1467 // and so on are not the name of the corresponding type, namespace, or
1468 // declaration, so they do *not* have linkage.
1469 case Decl::ImplicitParam:
1470 case Decl::Label:
1471 case Decl::NamespaceAlias:
1472 case Decl::ParmVar:
1473 case Decl::Using:
1474 case Decl::UsingEnum:
1475 case Decl::UsingShadow:
1476 case Decl::UsingDirective:
1477 return LinkageInfo::none();
1478
1479 case Decl::EnumConstant:
1480 // C++ [basic.link]p4: an enumerator has the linkage of its enumeration.
1481 if (D->getASTContext().getLangOpts().CPlusPlus)
1482 return getLVForDecl(cast<EnumDecl>(D->getDeclContext()), computation);
1484
1485 case Decl::Typedef:
1486 case Decl::TypeAlias:
1487 // A typedef declaration has linkage if it gives a type a name for
1488 // linkage purposes.
1489 if (!cast<TypedefNameDecl>(D)
1490 ->getAnonDeclWithTypedefName(/*AnyRedecl*/true))
1491 return LinkageInfo::none();
1492 break;
1493
1494 case Decl::TemplateTemplateParm: // count these as external
1495 case Decl::NonTypeTemplateParm:
1496 case Decl::ObjCAtDefsField:
1497 case Decl::ObjCCategory:
1498 case Decl::ObjCCategoryImpl:
1499 case Decl::ObjCCompatibleAlias:
1500 case Decl::ObjCImplementation:
1501 case Decl::ObjCMethod:
1502 case Decl::ObjCProperty:
1503 case Decl::ObjCPropertyImpl:
1504 case Decl::ObjCProtocol:
1505 return getExternalLinkageFor(D);
1506
1507 case Decl::CXXRecord: {
1508 const auto *Record = cast<CXXRecordDecl>(D);
1509 if (Record->isLambda()) {
1510 if (Record->hasKnownLambdaInternalLinkage() ||
1511 !Record->getLambdaManglingNumber()) {
1512 // This lambda has no mangling number, so it's internal.
1513 return LinkageInfo::internal();
1514 }
1515
1516 return getLVForClosure(
1517 Record->getDeclContext()->getRedeclContext(),
1518 Record->getLambdaContextDecl(), computation);
1519 }
1520
1521 break;
1522 }
1523
1524 case Decl::TemplateParamObject: {
1525 // The template parameter object can be referenced from anywhere its type
1526 // and value can be referenced.
1527 auto *TPO = cast<TemplateParamObjectDecl>(D);
1528 LinkageInfo LV = getLVForType(*TPO->getType(), computation);
1529 LV.merge(getLVForValue(TPO->getValue(), computation));
1530 return LV;
1531 }
1532 }
1533
1534 // Handle linkage for namespace-scope names.
1536 return getLVForNamespaceScopeDecl(D, computation, IgnoreVarTypeLinkage);
1537
1538 // C++ [basic.link]p5:
1539 // In addition, a member function, static data member, a named
1540 // class or enumeration of class scope, or an unnamed class or
1541 // enumeration defined in a class-scope typedef declaration such
1542 // that the class or enumeration has the typedef name for linkage
1543 // purposes (7.1.3), has external linkage if the name of the class
1544 // has external linkage.
1545 if (D->getDeclContext()->isRecord())
1546 return getLVForClassMember(D, computation, IgnoreVarTypeLinkage);
1547
1548 // C++ [basic.link]p6:
1549 // The name of a function declared in block scope and the name of
1550 // an object declared by a block scope extern declaration have
1551 // linkage. If there is a visible declaration of an entity with
1552 // linkage having the same name and type, ignoring entities
1553 // declared outside the innermost enclosing namespace scope, the
1554 // block scope declaration declares that same entity and receives
1555 // the linkage of the previous declaration. If there is more than
1556 // one such matching entity, the program is ill-formed. Otherwise,
1557 // if no matching entity is found, the block scope entity receives
1558 // external linkage.
1560 return getLVForLocalDecl(D, computation);
1561
1562 // C++ [basic.link]p6:
1563 // Names not covered by these rules have no linkage.
1564 return LinkageInfo::none();
1565}
1566
1567/// getLVForDecl - Get the linkage and visibility for the given declaration.
1569 LVComputationKind computation) {
1570 // Internal_linkage attribute overrides other considerations.
1571 if (D->hasAttr<InternalLinkageAttr>())
1572 return LinkageInfo::internal();
1573
1574 if (computation.IgnoreAllVisibility && D->hasCachedLinkage())
1575 return LinkageInfo(D->getCachedLinkage(), DefaultVisibility, false);
1576
1577 if (std::optional<LinkageInfo> LI = lookup(D, computation))
1578 return *LI;
1579
1580 LinkageInfo LV = computeLVForDecl(D, computation);
1581 if (D->hasCachedLinkage())
1582 assert(D->getCachedLinkage() == LV.getLinkage());
1583
1585 cache(D, computation, LV);
1586
1587#ifndef NDEBUG
1588 // In C (because of gnu inline) and in c++ with microsoft extensions an
1589 // static can follow an extern, so we can have two decls with different
1590 // linkages.
1591 const LangOptions &Opts = D->getASTContext().getLangOpts();
1592 if (!Opts.CPlusPlus || Opts.MicrosoftExt)
1593 return LV;
1594
1595 // We have just computed the linkage for this decl. By induction we know
1596 // that all other computed linkages match, check that the one we just
1597 // computed also does.
1598 NamedDecl *Old = nullptr;
1599 for (auto *I : D->redecls()) {
1600 auto *T = cast<NamedDecl>(I);
1601 if (T == D)
1602 continue;
1603 if (!T->isInvalidDecl() && T->hasCachedLinkage()) {
1604 Old = T;
1605 break;
1606 }
1607 }
1608 assert(!Old || Old->getCachedLinkage() == D->getCachedLinkage());
1609#endif
1610
1611 return LV;
1612}
1613
1618 LVComputationKind CK(EK);
1619 return getLVForDecl(D, D->getASTContext().getLangOpts().IgnoreXCOFFVisibility
1620 ? CK.forLinkageOnly()
1621 : CK);
1622}
1623
1624Module *Decl::getOwningModuleForLinkage(bool IgnoreLinkage) const {
1625 if (isa<NamespaceDecl>(this))
1626 // Namespaces never have module linkage. It is the entities within them
1627 // that [may] do.
1628 return nullptr;
1629
1630 Module *M = getOwningModule();
1631 if (!M)
1632 return nullptr;
1633
1634 switch (M->Kind) {
1636 // Module map modules have no special linkage semantics.
1637 return nullptr;
1638
1643 return M;
1644
1648 // External linkage declarations in the global module have no owning module
1649 // for linkage purposes. But internal linkage declarations in the global
1650 // module fragment of a particular module are owned by that module for
1651 // linkage purposes.
1652 // FIXME: p1815 removes the need for this distinction -- there are no
1653 // internal linkage declarations that need to be referred to from outside
1654 // this TU.
1655 if (IgnoreLinkage)
1656 return nullptr;
1657 bool InternalLinkage;
1658 if (auto *ND = dyn_cast<NamedDecl>(this))
1659 InternalLinkage = !ND->hasExternalFormalLinkage();
1660 else
1661 InternalLinkage = isInAnonymousNamespace();
1662 return InternalLinkage ? M->Kind == Module::ModuleHeaderUnit ? M : M->Parent
1663 : nullptr;
1664 }
1665
1667 // The private module fragment is part of its containing module for linkage
1668 // purposes.
1669 return M->Parent;
1670 }
1671
1672 llvm_unreachable("unknown module kind");
1673}
1674
1675void NamedDecl::printName(raw_ostream &OS, const PrintingPolicy &Policy) const {
1676 Name.print(OS, Policy);
1677}
1678
1679void NamedDecl::printName(raw_ostream &OS) const {
1680 printName(OS, getASTContext().getPrintingPolicy());
1681}
1682
1684 std::string QualName;
1685 llvm::raw_string_ostream OS(QualName);
1686 printQualifiedName(OS, getASTContext().getPrintingPolicy());
1687 return QualName;
1688}
1689
1690void NamedDecl::printQualifiedName(raw_ostream &OS) const {
1691 printQualifiedName(OS, getASTContext().getPrintingPolicy());
1692}
1693
1695 const PrintingPolicy &P) const {
1697 // We do not print '(anonymous)' for function parameters without name.
1698 printName(OS, P);
1699 return;
1700 }
1702 if (getDeclName())
1703 OS << *this;
1704 else {
1705 // Give the printName override a chance to pick a different name before we
1706 // fall back to "(anonymous)".
1707 SmallString<64> NameBuffer;
1708 llvm::raw_svector_ostream NameOS(NameBuffer);
1709 printName(NameOS, P);
1710 if (NameBuffer.empty())
1711 OS << "(anonymous)";
1712 else
1713 OS << NameBuffer;
1714 }
1715}
1716
1717void NamedDecl::printNestedNameSpecifier(raw_ostream &OS) const {
1718 printNestedNameSpecifier(OS, getASTContext().getPrintingPolicy());
1719}
1720
1722 const PrintingPolicy &P) const {
1723 const DeclContext *Ctx = getDeclContext();
1724
1725 // For ObjC methods and properties, look through categories and use the
1726 // interface as context.
1727 if (auto *MD = dyn_cast<ObjCMethodDecl>(this)) {
1728 if (auto *ID = MD->getClassInterface())
1729 Ctx = ID;
1730 } else if (auto *PD = dyn_cast<ObjCPropertyDecl>(this)) {
1731 if (auto *MD = PD->getGetterMethodDecl())
1732 if (auto *ID = MD->getClassInterface())
1733 Ctx = ID;
1734 } else if (auto *ID = dyn_cast<ObjCIvarDecl>(this)) {
1735 if (auto *CI = ID->getContainingInterface())
1736 Ctx = CI;
1737 }
1738
1739 if (Ctx->isFunctionOrMethod())
1740 return;
1741
1742 using ContextsTy = SmallVector<const DeclContext *, 8>;
1743 ContextsTy Contexts;
1744
1745 // Collect named contexts.
1746 DeclarationName NameInScope = getDeclName();
1747 for (; Ctx; Ctx = Ctx->getParent()) {
1748 // Suppress anonymous namespace if requested.
1749 if (P.SuppressUnwrittenScope && isa<NamespaceDecl>(Ctx) &&
1750 cast<NamespaceDecl>(Ctx)->isAnonymousNamespace())
1751 continue;
1752
1753 // Suppress inline namespace if it doesn't make the result ambiguous.
1754 if (P.SuppressInlineNamespace && Ctx->isInlineNamespace() && NameInScope &&
1755 cast<NamespaceDecl>(Ctx)->isRedundantInlineQualifierFor(NameInScope))
1756 continue;
1757
1758 // Skip non-named contexts such as linkage specifications and ExportDecls.
1759 const NamedDecl *ND = dyn_cast<NamedDecl>(Ctx);
1760 if (!ND)
1761 continue;
1762
1763 Contexts.push_back(Ctx);
1764 NameInScope = ND->getDeclName();
1765 }
1766
1767 for (const DeclContext *DC : llvm::reverse(Contexts)) {
1768 if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
1769 OS << Spec->getName();
1770 const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
1772 OS, TemplateArgs.asArray(), P,
1773 Spec->getSpecializedTemplate()->getTemplateParameters());
1774 } else if (const auto *ND = dyn_cast<NamespaceDecl>(DC)) {
1775 if (ND->isAnonymousNamespace()) {
1776 OS << (P.MSVCFormatting ? "`anonymous namespace\'"
1777 : "(anonymous namespace)");
1778 }
1779 else
1780 OS << *ND;
1781 } else if (const auto *RD = dyn_cast<RecordDecl>(DC)) {
1782 if (!RD->getIdentifier())
1783 OS << "(anonymous " << RD->getKindName() << ')';
1784 else
1785 OS << *RD;
1786 } else if (const auto *FD = dyn_cast<FunctionDecl>(DC)) {
1787 const FunctionProtoType *FT = nullptr;
1788 if (FD->hasWrittenPrototype())
1789 FT = dyn_cast<FunctionProtoType>(FD->getType()->castAs<FunctionType>());
1790
1791 OS << *FD << '(';
1792 if (FT) {
1793 unsigned NumParams = FD->getNumParams();
1794 for (unsigned i = 0; i < NumParams; ++i) {
1795 if (i)
1796 OS << ", ";
1797 OS << FD->getParamDecl(i)->getType().stream(P);
1798 }
1799
1800 if (FT->isVariadic()) {
1801 if (NumParams > 0)
1802 OS << ", ";
1803 OS << "...";
1804 }
1805 }
1806 OS << ')';
1807 } else if (const auto *ED = dyn_cast<EnumDecl>(DC)) {
1808 // C++ [dcl.enum]p10: Each enum-name and each unscoped
1809 // enumerator is declared in the scope that immediately contains
1810 // the enum-specifier. Each scoped enumerator is declared in the
1811 // scope of the enumeration.
1812 // For the case of unscoped enumerator, do not include in the qualified
1813 // name any information about its enum enclosing scope, as its visibility
1814 // is global.
1815 if (ED->isScoped())
1816 OS << *ED;
1817 else
1818 continue;
1819 } else {
1820 OS << *cast<NamedDecl>(DC);
1821 }
1822 OS << "::";
1823 }
1824}
1825
1827 const PrintingPolicy &Policy,
1828 bool Qualified) const {
1829 if (Qualified)
1830 printQualifiedName(OS, Policy);
1831 else
1832 printName(OS, Policy);
1833}
1834
1835template<typename T> static bool isRedeclarableImpl(Redeclarable<T> *) {
1836 return true;
1837}
1838static bool isRedeclarableImpl(...) { return false; }
1840 switch (K) {
1841#define DECL(Type, Base) \
1842 case Decl::Type: \
1843 return isRedeclarableImpl((Type##Decl *)nullptr);
1844#define ABSTRACT_DECL(DECL)
1845#include "clang/AST/DeclNodes.inc"
1846 }
1847 llvm_unreachable("unknown decl kind");
1848}
1849
1851 bool IsKnownNewer) const {
1852 assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch");
1853
1854 // Never replace one imported declaration with another; we need both results
1855 // when re-exporting.
1856 if (OldD->isFromASTFile() && isFromASTFile())
1857 return false;
1858
1859 // A kind mismatch implies that the declaration is not replaced.
1860 if (OldD->getKind() != getKind())
1861 return false;
1862
1863 // For method declarations, we never replace. (Why?)
1864 if (isa<ObjCMethodDecl>(this))
1865 return false;
1866
1867 // For parameters, pick the newer one. This is either an error or (in
1868 // Objective-C) permitted as an extension.
1869 if (isa<ParmVarDecl>(this))
1870 return true;
1871
1872 // Inline namespaces can give us two declarations with the same
1873 // name and kind in the same scope but different contexts; we should
1874 // keep both declarations in this case.
1875 if (!this->getDeclContext()->getRedeclContext()->Equals(
1876 OldD->getDeclContext()->getRedeclContext()))
1877 return false;
1878
1879 // Using declarations can be replaced if they import the same name from the
1880 // same context.
1881 if (const auto *UD = dyn_cast<UsingDecl>(this)) {
1882 ASTContext &Context = getASTContext();
1883 return Context.getCanonicalNestedNameSpecifier(UD->getQualifier()) ==
1885 cast<UsingDecl>(OldD)->getQualifier());
1886 }
1887 if (const auto *UUVD = dyn_cast<UnresolvedUsingValueDecl>(this)) {
1888 ASTContext &Context = getASTContext();
1889 return Context.getCanonicalNestedNameSpecifier(UUVD->getQualifier()) ==
1891 cast<UnresolvedUsingValueDecl>(OldD)->getQualifier());
1892 }
1893
1894 if (isRedeclarable(getKind())) {
1895 if (getCanonicalDecl() != OldD->getCanonicalDecl())
1896 return false;
1897
1898 if (IsKnownNewer)
1899 return true;
1900
1901 // Check whether this is actually newer than OldD. We want to keep the
1902 // newer declaration. This loop will usually only iterate once, because
1903 // OldD is usually the previous declaration.
1904 for (const auto *D : redecls()) {
1905 if (D == OldD)
1906 break;
1907
1908 // If we reach the canonical declaration, then OldD is not actually older
1909 // than this one.
1910 //
1911 // FIXME: In this case, we should not add this decl to the lookup table.
1912 if (D->isCanonicalDecl())
1913 return false;
1914 }
1915
1916 // It's a newer declaration of the same kind of declaration in the same
1917 // scope: we want this decl instead of the existing one.
1918 return true;
1919 }
1920
1921 // In all other cases, we need to keep both declarations in case they have
1922 // different visibility. Any attempt to use the name will result in an
1923 // ambiguity if more than one is visible.
1924 return false;
1925}
1926
1928 switch (getFormalLinkage()) {
1929 case Linkage::Invalid:
1930 llvm_unreachable("Linkage hasn't been computed!");
1931 case Linkage::None:
1932 return false;
1933 case Linkage::Internal:
1934 return true;
1937 llvm_unreachable("Non-formal linkage is not allowed here!");
1938 case Linkage::Module:
1939 case Linkage::External:
1940 return true;
1941 }
1942 llvm_unreachable("Unhandled Linkage enum");
1943}
1944
1945NamedDecl *NamedDecl::getUnderlyingDeclImpl() {
1946 NamedDecl *ND = this;
1947 if (auto *UD = dyn_cast<UsingShadowDecl>(ND))
1948 ND = UD->getTargetDecl();
1949
1950 if (auto *AD = dyn_cast<ObjCCompatibleAliasDecl>(ND))
1951 return AD->getClassInterface();
1952
1953 if (auto *AD = dyn_cast<NamespaceAliasDecl>(ND))
1954 return AD->getNamespace();
1955
1956 return ND;
1957}
1958
1960 if (!isCXXClassMember())
1961 return false;
1962
1963 const NamedDecl *D = this;
1964 if (isa<UsingShadowDecl>(D))
1965 D = cast<UsingShadowDecl>(D)->getTargetDecl();
1966
1967 if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<MSPropertyDecl>(D))
1968 return true;
1969 if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(D->getAsFunction()))
1970 return MD->isInstance();
1971 return false;
1972}
1973
1974//===----------------------------------------------------------------------===//
1975// DeclaratorDecl Implementation
1976//===----------------------------------------------------------------------===//
1977
1978template <typename DeclT>
1980 if (decl->getNumTemplateParameterLists() > 0)
1981 return decl->getTemplateParameterList(0)->getTemplateLoc();
1982 return decl->getInnerLocStart();
1983}
1984
1987 if (TSI) return TSI->getTypeLoc().getBeginLoc();
1988 return SourceLocation();
1989}
1990
1993 if (TSI) return TSI->getTypeLoc().getEndLoc();
1994 return SourceLocation();
1995}
1996
1998 if (QualifierLoc) {
1999 // Make sure the extended decl info is allocated.
2000 if (!hasExtInfo()) {
2001 // Save (non-extended) type source info pointer.
2002 auto *savedTInfo = DeclInfo.get<TypeSourceInfo*>();
2003 // Allocate external info struct.
2004 DeclInfo = new (getASTContext()) ExtInfo;
2005 // Restore savedTInfo into (extended) decl info.
2006 getExtInfo()->TInfo = savedTInfo;
2007 }
2008 // Set qualifier info.
2009 getExtInfo()->QualifierLoc = QualifierLoc;
2010 } else if (hasExtInfo()) {
2011 // Here Qualifier == 0, i.e., we are removing the qualifier (if any).
2012 getExtInfo()->QualifierLoc = QualifierLoc;
2013 }
2014}
2015
2017 assert(TrailingRequiresClause);
2018 // Make sure the extended decl info is allocated.
2019 if (!hasExtInfo()) {
2020 // Save (non-extended) type source info pointer.
2021 auto *savedTInfo = DeclInfo.get<TypeSourceInfo*>();
2022 // Allocate external info struct.
2023 DeclInfo = new (getASTContext()) ExtInfo;
2024 // Restore savedTInfo into (extended) decl info.
2025 getExtInfo()->TInfo = savedTInfo;
2026 }
2027 // Set requires clause info.
2028 getExtInfo()->TrailingRequiresClause = TrailingRequiresClause;
2029}
2030
2033 assert(!TPLists.empty());
2034 // Make sure the extended decl info is allocated.
2035 if (!hasExtInfo()) {
2036 // Save (non-extended) type source info pointer.
2037 auto *savedTInfo = DeclInfo.get<TypeSourceInfo*>();
2038 // Allocate external info struct.
2039 DeclInfo = new (getASTContext()) ExtInfo;
2040 // Restore savedTInfo into (extended) decl info.
2041 getExtInfo()->TInfo = savedTInfo;
2042 }
2043 // Set the template parameter lists info.
2044 getExtInfo()->setTemplateParameterListsInfo(Context, TPLists);
2045}
2046
2048 return getTemplateOrInnerLocStart(this);
2049}
2050
2051// Helper function: returns true if QT is or contains a type
2052// having a postfix component.
2053static bool typeIsPostfix(QualType QT) {
2054 while (true) {
2055 const Type* T = QT.getTypePtr();
2056 switch (T->getTypeClass()) {
2057 default:
2058 return false;
2059 case Type::Pointer:
2060 QT = cast<PointerType>(T)->getPointeeType();
2061 break;
2062 case Type::BlockPointer:
2063 QT = cast<BlockPointerType>(T)->getPointeeType();
2064 break;
2065 case Type::MemberPointer:
2066 QT = cast<MemberPointerType>(T)->getPointeeType();
2067 break;
2068 case Type::LValueReference:
2069 case Type::RValueReference:
2070 QT = cast<ReferenceType>(T)->getPointeeType();
2071 break;
2072 case Type::PackExpansion:
2073 QT = cast<PackExpansionType>(T)->getPattern();
2074 break;
2075 case Type::Paren:
2076 case Type::ConstantArray:
2077 case Type::DependentSizedArray:
2078 case Type::IncompleteArray:
2079 case Type::VariableArray:
2080 case Type::FunctionProto:
2081 case Type::FunctionNoProto:
2082 return true;
2083 }
2084 }
2085}
2086
2088 SourceLocation RangeEnd = getLocation();
2089 if (TypeSourceInfo *TInfo = getTypeSourceInfo()) {
2090 // If the declaration has no name or the type extends past the name take the
2091 // end location of the type.
2092 if (!getDeclName() || typeIsPostfix(TInfo->getType()))
2093 RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd();
2094 }
2095 return SourceRange(getOuterLocStart(), RangeEnd);
2096}
2097
2100 // Free previous template parameters (if any).
2101 if (NumTemplParamLists > 0) {
2102 Context.Deallocate(TemplParamLists);
2103 TemplParamLists = nullptr;
2105 }
2106 // Set info on matched template parameter lists (if any).
2107 if (!TPLists.empty()) {
2108 TemplParamLists = new (Context) TemplateParameterList *[TPLists.size()];
2109 NumTemplParamLists = TPLists.size();
2110 std::copy(TPLists.begin(), TPLists.end(), TemplParamLists);
2111 }
2112}
2113
2114//===----------------------------------------------------------------------===//
2115// VarDecl Implementation
2116//===----------------------------------------------------------------------===//
2117
2119 switch (SC) {
2120 case SC_None: break;
2121 case SC_Auto: return "auto";
2122 case SC_Extern: return "extern";
2123 case SC_PrivateExtern: return "__private_extern__";
2124 case SC_Register: return "register";
2125 case SC_Static: return "static";
2126 }
2127
2128 llvm_unreachable("Invalid storage class");
2129}
2130
2132 SourceLocation StartLoc, SourceLocation IdLoc,
2133 const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
2134 StorageClass SC)
2135 : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc),
2137 static_assert(sizeof(VarDeclBitfields) <= sizeof(unsigned),
2138 "VarDeclBitfields too large!");
2139 static_assert(sizeof(ParmVarDeclBitfields) <= sizeof(unsigned),
2140 "ParmVarDeclBitfields too large!");
2141 static_assert(sizeof(NonParmVarDeclBitfields) <= sizeof(unsigned),
2142 "NonParmVarDeclBitfields too large!");
2143 AllBits = 0;
2144 VarDeclBits.SClass = SC;
2145 // Everything else is implicitly initialized to false.
2146}
2147
2149 SourceLocation IdL, const IdentifierInfo *Id,
2150 QualType T, TypeSourceInfo *TInfo, StorageClass S) {
2151 return new (C, DC) VarDecl(Var, C, DC, StartL, IdL, Id, T, TInfo, S);
2152}
2153
2155 return new (C, ID)
2156 VarDecl(Var, C, nullptr, SourceLocation(), SourceLocation(), nullptr,
2157 QualType(), nullptr, SC_None);
2158}
2159
2161 assert(isLegalForVariable(SC));
2162 VarDeclBits.SClass = SC;
2163}
2164
2166 switch (VarDeclBits.TSCSpec) {
2167 case TSCS_unspecified:
2168 if (!hasAttr<ThreadAttr>() &&
2169 !(getASTContext().getLangOpts().OpenMPUseTLS &&
2170 getASTContext().getTargetInfo().isTLSSupported() &&
2171 hasAttr<OMPThreadPrivateDeclAttr>()))
2172 return TLS_None;
2173 return ((getASTContext().getLangOpts().isCompatibleWithMSVC(
2175 hasAttr<OMPThreadPrivateDeclAttr>())
2176 ? TLS_Dynamic
2177 : TLS_Static;
2178 case TSCS___thread: // Fall through.
2179 case TSCS__Thread_local:
2180 return TLS_Static;
2181 case TSCS_thread_local:
2182 return TLS_Dynamic;
2183 }
2184 llvm_unreachable("Unknown thread storage class specifier!");
2185}
2186
2188 if (const Expr *Init = getInit()) {
2189 SourceLocation InitEnd = Init->getEndLoc();
2190 // If Init is implicit, ignore its source range and fallback on
2191 // DeclaratorDecl::getSourceRange() to handle postfix elements.
2192 if (InitEnd.isValid() && InitEnd != getLocation())
2193 return SourceRange(getOuterLocStart(), InitEnd);
2194 }
2196}
2197
2198template<typename T>
2200 // C++ [dcl.link]p1: All function types, function names with external linkage,
2201 // and variable names with external linkage have a language linkage.
2202 if (!D.hasExternalFormalLinkage())
2203 return NoLanguageLinkage;
2204
2205 // Language linkage is a C++ concept, but saying that everything else in C has
2206 // C language linkage fits the implementation nicely.
2207 if (!D.getASTContext().getLangOpts().CPlusPlus)
2208 return CLanguageLinkage;
2209
2210 // C++ [dcl.link]p4: A C language linkage is ignored in determining the
2211 // language linkage of the names of class members and the function type of
2212 // class member functions.
2213 const DeclContext *DC = D.getDeclContext();
2214 if (DC->isRecord())
2215 return CXXLanguageLinkage;
2216
2217 // If the first decl is in an extern "C" context, any other redeclaration
2218 // will have C language linkage. If the first one is not in an extern "C"
2219 // context, we would have reported an error for any other decl being in one.
2221 return CLanguageLinkage;
2222 return CXXLanguageLinkage;
2223}
2224
2225template<typename T>
2226static bool isDeclExternC(const T &D) {
2227 // Since the context is ignored for class members, they can only have C++
2228 // language linkage or no language linkage.
2229 const DeclContext *DC = D.getDeclContext();
2230 if (DC->isRecord()) {
2231 assert(D.getASTContext().getLangOpts().CPlusPlus);
2232 return false;
2233 }
2234
2235 return D.getLanguageLinkage() == CLanguageLinkage;
2236}
2237
2239 return getDeclLanguageLinkage(*this);
2240}
2241
2243 return isDeclExternC(*this);
2244}
2245
2248}
2249
2252}
2253
2255
2259 return DeclarationOnly;
2260
2261 // C++ [basic.def]p2:
2262 // A declaration is a definition unless [...] it contains the 'extern'
2263 // specifier or a linkage-specification and neither an initializer [...],
2264 // it declares a non-inline static data member in a class declaration [...],
2265 // it declares a static data member outside a class definition and the variable
2266 // was defined within the class with the constexpr specifier [...],
2267 // C++1y [temp.expl.spec]p15:
2268 // An explicit specialization of a static data member or an explicit
2269 // specialization of a static data member template is a definition if the
2270 // declaration includes an initializer; otherwise, it is a declaration.
2271 //
2272 // FIXME: How do you declare (but not define) a partial specialization of
2273 // a static data member template outside the containing class?
2274 if (isStaticDataMember()) {
2275 if (isOutOfLine() &&
2276 !(getCanonicalDecl()->isInline() &&
2278 (hasInit() ||
2279 // If the first declaration is out-of-line, this may be an
2280 // instantiation of an out-of-line partial specialization of a variable
2281 // template for which we have not yet instantiated the initializer.
2286 isa<VarTemplatePartialSpecializationDecl>(this)))
2287 return Definition;
2288 if (!isOutOfLine() && isInline())
2289 return Definition;
2290 return DeclarationOnly;
2291 }
2292 // C99 6.7p5:
2293 // A definition of an identifier is a declaration for that identifier that
2294 // [...] causes storage to be reserved for that object.
2295 // Note: that applies for all non-file-scope objects.
2296 // C99 6.9.2p1:
2297 // If the declaration of an identifier for an object has file scope and an
2298 // initializer, the declaration is an external definition for the identifier
2299 if (hasInit())
2300 return Definition;
2301
2302 if (hasDefiningAttr())
2303 return Definition;
2304
2305 if (const auto *SAA = getAttr<SelectAnyAttr>())
2306 if (!SAA->isInherited())
2307 return Definition;
2308
2309 // A variable template specialization (other than a static data member
2310 // template or an explicit specialization) is a declaration until we
2311 // instantiate its initializer.
2312 if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(this)) {
2313 if (VTSD->getTemplateSpecializationKind() != TSK_ExplicitSpecialization &&
2314 !isa<VarTemplatePartialSpecializationDecl>(VTSD) &&
2315 !VTSD->IsCompleteDefinition)
2316 return DeclarationOnly;
2317 }
2318
2319 if (hasExternalStorage())
2320 return DeclarationOnly;
2321
2322 // [dcl.link] p7:
2323 // A declaration directly contained in a linkage-specification is treated
2324 // as if it contains the extern specifier for the purpose of determining
2325 // the linkage of the declared name and whether it is a definition.
2326 if (isSingleLineLanguageLinkage(*this))
2327 return DeclarationOnly;
2328
2329 // C99 6.9.2p2:
2330 // A declaration of an object that has file scope without an initializer,
2331 // and without a storage class specifier or the scs 'static', constitutes
2332 // a tentative definition.
2333 // No such thing in C++.
2334 if (!C.getLangOpts().CPlusPlus && isFileVarDecl())
2335 return TentativeDefinition;
2336
2337 // What's left is (in C, block-scope) declarations without initializers or
2338 // external storage. These are definitions.
2339 return Definition;
2340}
2341
2345 return nullptr;
2346
2347 VarDecl *LastTentative = nullptr;
2348
2349 // Loop through the declaration chain, starting with the most recent.
2351 Decl = Decl->getPreviousDecl()) {
2352 Kind = Decl->isThisDeclarationADefinition();
2353 if (Kind == Definition)
2354 return nullptr;
2355 // Record the first (most recent) TentativeDefinition that is encountered.
2356 if (Kind == TentativeDefinition && !LastTentative)
2357 LastTentative = Decl;
2358 }
2359
2360 return LastTentative;
2361}
2362
2365 for (auto *I : First->redecls()) {
2366 if (I->isThisDeclarationADefinition(C) == Definition)
2367 return I;
2368 }
2369 return nullptr;
2370}
2371
2374
2375 const VarDecl *First = getFirstDecl();
2376 for (auto *I : First->redecls()) {
2377 Kind = std::max(Kind, I->isThisDeclarationADefinition(C));
2378 if (Kind == Definition)
2379 break;
2380 }
2381
2382 return Kind;
2383}
2384
2385const Expr *VarDecl::getAnyInitializer(const VarDecl *&D) const {
2386 for (auto *I : redecls()) {
2387 if (auto Expr = I->getInit()) {
2388 D = I;
2389 return Expr;
2390 }
2391 }
2392 return nullptr;
2393}
2394
2395bool VarDecl::hasInit() const {
2396 if (auto *P = dyn_cast<ParmVarDecl>(this))
2397 if (P->hasUnparsedDefaultArg() || P->hasUninstantiatedDefaultArg())
2398 return false;
2399
2400 return !Init.isNull();
2401}
2402
2404 if (!hasInit())
2405 return nullptr;
2406
2407 if (auto *S = Init.dyn_cast<Stmt *>())
2408 return cast<Expr>(S);
2409
2410 auto *Eval = getEvaluatedStmt();
2411 return cast<Expr>(Eval->Value.isOffset()
2412 ? Eval->Value.get(getASTContext().getExternalSource())
2413 : Eval->Value.get(nullptr));
2414}
2415
2417 if (auto *ES = Init.dyn_cast<EvaluatedStmt *>())
2418 return ES->Value.getAddressOfPointer(getASTContext().getExternalSource());
2419
2420 return Init.getAddrOfPtr1();
2421}
2422
2424 VarDecl *Def = nullptr;
2425 for (auto *I : redecls()) {
2426 if (I->hasInit())
2427 return I;
2428
2429 if (I->isThisDeclarationADefinition()) {
2430 if (isStaticDataMember())
2431 return I;
2432 Def = I;
2433 }
2434 }
2435 return Def;
2436}
2437
2439 if (Decl::isOutOfLine())
2440 return true;
2441
2442 if (!isStaticDataMember())
2443 return false;
2444
2445 // If this static data member was instantiated from a static data member of
2446 // a class template, check whether that static data member was defined
2447 // out-of-line.
2449 return VD->isOutOfLine();
2450
2451 return false;
2452}
2453
2455 if (auto *Eval = Init.dyn_cast<EvaluatedStmt *>()) {
2456 Eval->~EvaluatedStmt();
2457 getASTContext().Deallocate(Eval);
2458 }
2459
2460 Init = I;
2461}
2462
2464 const LangOptions &Lang = C.getLangOpts();
2465
2466 // OpenCL permits const integral variables to be used in constant
2467 // expressions, like in C++98.
2468 if (!Lang.CPlusPlus && !Lang.OpenCL && !Lang.C23)
2469 return false;
2470
2471 // Function parameters are never usable in constant expressions.
2472 if (isa<ParmVarDecl>(this))
2473 return false;
2474
2475 // The values of weak variables are never usable in constant expressions.
2476 if (isWeak())
2477 return false;
2478
2479 // In C++11, any variable of reference type can be used in a constant
2480 // expression if it is initialized by a constant expression.
2481 if (Lang.CPlusPlus11 && getType()->isReferenceType())
2482 return true;
2483
2484 // Only const objects can be used in constant expressions in C++. C++98 does
2485 // not require the variable to be non-volatile, but we consider this to be a
2486 // defect.
2487 if (!getType().isConstant(C) || getType().isVolatileQualified())
2488 return false;
2489
2490 // In C++, but not in C, const, non-volatile variables of integral or
2491 // enumeration types can be used in constant expressions.
2492 if (getType()->isIntegralOrEnumerationType() && !Lang.C23)
2493 return true;
2494
2495 // C23 6.6p7: An identifier that is:
2496 // ...
2497 // - declared with storage-class specifier constexpr and has an object type,
2498 // is a named constant, ... such a named constant is a constant expression
2499 // with the type and value of the declared object.
2500 // Additionally, in C++11, non-volatile constexpr variables can be used in
2501 // constant expressions.
2502 return (Lang.CPlusPlus11 || Lang.C23) && isConstexpr();
2503}
2504
2506 // C++2a [expr.const]p3:
2507 // A variable is usable in constant expressions after its initializing
2508 // declaration is encountered...
2509 const VarDecl *DefVD = nullptr;
2510 const Expr *Init = getAnyInitializer(DefVD);
2511 if (!Init || Init->isValueDependent() || getType()->isDependentType())
2512 return false;
2513 // ... if it is a constexpr variable, or it is of reference type or of
2514 // const-qualified integral or enumeration type, ...
2515 if (!DefVD->mightBeUsableInConstantExpressions(Context))
2516 return false;
2517 // ... and its initializer is a constant initializer.
2518 if (Context.getLangOpts().CPlusPlus && !DefVD->hasConstantInitialization())
2519 return false;
2520 // C++98 [expr.const]p1:
2521 // An integral constant-expression can involve only [...] const variables
2522 // or static data members of integral or enumeration types initialized with
2523 // [integer] constant expressions (dcl.init)
2524 if ((Context.getLangOpts().CPlusPlus || Context.getLangOpts().OpenCL) &&
2525 !Context.getLangOpts().CPlusPlus11 && !DefVD->hasICEInitializer(Context))
2526 return false;
2527 return true;
2528}
2529
2530/// Convert the initializer for this declaration to the elaborated EvaluatedStmt
2531/// form, which contains extra information on the evaluated value of the
2532/// initializer.
2534 auto *Eval = Init.dyn_cast<EvaluatedStmt *>();
2535 if (!Eval) {
2536 // Note: EvaluatedStmt contains an APValue, which usually holds
2537 // resources not allocated from the ASTContext. We need to do some
2538 // work to avoid leaking those, but we do so in VarDecl::evaluateValue
2539 // where we can detect whether there's anything to clean up or not.
2540 Eval = new (getASTContext()) EvaluatedStmt;
2541 Eval->Value = Init.get<Stmt *>();
2542 Init = Eval;
2543 }
2544 return Eval;
2545}
2546
2548 return Init.dyn_cast<EvaluatedStmt *>();
2549}
2550
2553 return evaluateValueImpl(Notes, hasConstantInitialization());
2554}
2555
2556APValue *VarDecl::evaluateValueImpl(SmallVectorImpl<PartialDiagnosticAt> &Notes,
2557 bool IsConstantInitialization) const {
2559
2560 const auto *Init = getInit();
2561 assert(!Init->isValueDependent());
2562
2563 // We only produce notes indicating why an initializer is non-constant the
2564 // first time it is evaluated. FIXME: The notes won't always be emitted the
2565 // first time we try evaluation, so might not be produced at all.
2566 if (Eval->WasEvaluated)
2567 return Eval->Evaluated.isAbsent() ? nullptr : &Eval->Evaluated;
2568
2569 if (Eval->IsEvaluating) {
2570 // FIXME: Produce a diagnostic for self-initialization.
2571 return nullptr;
2572 }
2573
2574 Eval->IsEvaluating = true;
2575
2576 ASTContext &Ctx = getASTContext();
2577 bool Result = Init->EvaluateAsInitializer(Eval->Evaluated, Ctx, this, Notes,
2578 IsConstantInitialization);
2579
2580 // In C++, or in C23 if we're initialising a 'constexpr' variable, this isn't
2581 // a constant initializer if we produced notes. In that case, we can't keep
2582 // the result, because it may only be correct under the assumption that the
2583 // initializer is a constant context.
2584 if (IsConstantInitialization &&
2585 (Ctx.getLangOpts().CPlusPlus ||
2586 (isConstexpr() && Ctx.getLangOpts().C23)) &&
2587 !Notes.empty())
2588 Result = false;
2589
2590 // Ensure the computed APValue is cleaned up later if evaluation succeeded,
2591 // or that it's empty (so that there's nothing to clean up) if evaluation
2592 // failed.
2593 if (!Result)
2594 Eval->Evaluated = APValue();
2595 else if (Eval->Evaluated.needsCleanup())
2596 Ctx.addDestruction(&Eval->Evaluated);
2597
2598 Eval->IsEvaluating = false;
2599 Eval->WasEvaluated = true;
2600
2601 return Result ? &Eval->Evaluated : nullptr;
2602}
2603
2605 if (EvaluatedStmt *Eval = getEvaluatedStmt())
2606 if (Eval->WasEvaluated)
2607 return &Eval->Evaluated;
2608
2609 return nullptr;
2610}
2611
2612bool VarDecl::hasICEInitializer(const ASTContext &Context) const {
2613 const Expr *Init = getInit();
2614 assert(Init && "no initializer");
2615
2617 if (!Eval->CheckedForICEInit) {
2618 Eval->CheckedForICEInit = true;
2619 Eval->HasICEInit = Init->isIntegerConstantExpr(Context);
2620 }
2621 return Eval->HasICEInit;
2622}
2623
2625 // In C, all globals (and only globals) have constant initialization.
2627 return true;
2628
2629 // In C++, it depends on whether the evaluation at the point of definition
2630 // was evaluatable as a constant initializer.
2631 if (EvaluatedStmt *Eval = getEvaluatedStmt())
2632 return Eval->HasConstantInitialization;
2633
2634 return false;
2635}
2636
2640 // If we ask for the value before we know whether we have a constant
2641 // initializer, we can compute the wrong value (for example, due to
2642 // std::is_constant_evaluated()).
2643 assert(!Eval->WasEvaluated &&
2644 "already evaluated var value before checking for constant init");
2645 assert((getASTContext().getLangOpts().CPlusPlus ||
2647 "only meaningful in C++/C23");
2648
2649 assert(!getInit()->isValueDependent());
2650
2651 // Evaluate the initializer to check whether it's a constant expression.
2653 evaluateValueImpl(Notes, true) && Notes.empty();
2654
2655 // If evaluation as a constant initializer failed, allow re-evaluation as a
2656 // non-constant initializer if we later find we want the value.
2657 if (!Eval->HasConstantInitialization)
2658 Eval->WasEvaluated = false;
2659
2660 return Eval->HasConstantInitialization;
2661}
2662
2664 return isa<PackExpansionType>(getType());
2665}
2666
2667template<typename DeclT>
2668static DeclT *getDefinitionOrSelf(DeclT *D) {
2669 assert(D);
2670 if (auto *Def = D->getDefinition())
2671 return Def;
2672 return D;
2673}
2674
2676 return hasAttr<BlocksAttr>() && NonParmVarDeclBits.EscapingByref;
2677}
2678
2680 return hasAttr<BlocksAttr>() && !NonParmVarDeclBits.EscapingByref;
2681}
2682
2684 QualType T = getType();
2685 return T->isDependentType() || T->isUndeducedType() ||
2686 llvm::any_of(specific_attrs<AlignedAttr>(), [](const AlignedAttr *AA) {
2687 return AA->isAlignmentDependent();
2688 });
2689}
2690
2692 const VarDecl *VD = this;
2693
2694 // If this is an instantiated member, walk back to the template from which
2695 // it was instantiated.
2697 if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) {
2699 while (auto *NewVD = VD->getInstantiatedFromStaticDataMember())
2700 VD = NewVD;
2701 }
2702 }
2703
2704 // If it's an instantiated variable template specialization, find the
2705 // template or partial specialization from which it was instantiated.
2706 if (auto *VDTemplSpec = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
2707 if (isTemplateInstantiation(VDTemplSpec->getTemplateSpecializationKind())) {
2708 auto From = VDTemplSpec->getInstantiatedFrom();
2709 if (auto *VTD = From.dyn_cast<VarTemplateDecl *>()) {
2710 while (!VTD->isMemberSpecialization()) {
2711 auto *NewVTD = VTD->getInstantiatedFromMemberTemplate();
2712 if (!NewVTD)
2713 break;
2714 VTD = NewVTD;
2715 }
2716 return getDefinitionOrSelf(VTD->getTemplatedDecl());
2717 }
2718 if (auto *VTPSD =
2719 From.dyn_cast<VarTemplatePartialSpecializationDecl *>()) {
2720 while (!VTPSD->isMemberSpecialization()) {
2721 auto *NewVTPSD = VTPSD->getInstantiatedFromMember();
2722 if (!NewVTPSD)
2723 break;
2724 VTPSD = NewVTPSD;
2725 }
2726 return getDefinitionOrSelf<VarDecl>(VTPSD);
2727 }
2728 }
2729 }
2730
2731 // If this is the pattern of a variable template, find where it was
2732 // instantiated from. FIXME: Is this necessary?
2733 if (VarTemplateDecl *VarTemplate = VD->getDescribedVarTemplate()) {
2734 while (!VarTemplate->isMemberSpecialization()) {
2735 auto *NewVT = VarTemplate->getInstantiatedFromMemberTemplate();
2736 if (!NewVT)
2737 break;
2738 VarTemplate = NewVT;
2739 }
2740
2741 return getDefinitionOrSelf(VarTemplate->getTemplatedDecl());
2742 }
2743
2744 if (VD == this)
2745 return nullptr;
2746 return getDefinitionOrSelf(const_cast<VarDecl*>(VD));
2747}
2748
2751 return cast<VarDecl>(MSI->getInstantiatedFrom());
2752
2753 return nullptr;
2754}
2755
2757 if (const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(this))
2758 return Spec->getSpecializationKind();
2759
2761 return MSI->getTemplateSpecializationKind();
2762
2763 return TSK_Undeclared;
2764}
2765
2769 return MSI->getTemplateSpecializationKind();
2770
2771 if (const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(this))
2772 return Spec->getSpecializationKind();
2773
2774 return TSK_Undeclared;
2775}
2776
2778 if (const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(this))
2779 return Spec->getPointOfInstantiation();
2780
2782 return MSI->getPointOfInstantiation();
2783
2784 return SourceLocation();
2785}
2786
2789 .dyn_cast<VarTemplateDecl *>();
2790}
2791
2794}
2795
2797 const auto &LangOpts = getASTContext().getLangOpts();
2798 // In CUDA mode without relocatable device code, variables of form 'extern
2799 // __shared__ Foo foo[]' are pointers to the base of the GPU core's shared
2800 // memory pool. These are never undefined variables, even if they appear
2801 // inside of an anon namespace or static function.
2802 //
2803 // With CUDA relocatable device code enabled, these variables don't get
2804 // special handling; they're treated like regular extern variables.
2805 if (LangOpts.CUDA && !LangOpts.GPURelocatableDeviceCode &&
2806 hasExternalStorage() && hasAttr<CUDASharedAttr>() &&
2807 isa<IncompleteArrayType>(getType()))
2808 return true;
2809
2810 return hasDefinition();
2811}
2812
2813bool VarDecl::isNoDestroy(const ASTContext &Ctx) const {
2814 return hasGlobalStorage() && (hasAttr<NoDestroyAttr>() ||
2815 (!Ctx.getLangOpts().RegisterStaticDestructors &&
2816 !hasAttr<AlwaysDestroyAttr>()));
2817}
2818
2821 if (EvaluatedStmt *Eval = getEvaluatedStmt())
2822 if (Eval->HasConstantDestruction)
2823 return QualType::DK_none;
2824
2825 if (isNoDestroy(Ctx))
2826 return QualType::DK_none;
2827
2828 return getType().isDestructedType();
2829}
2830
2832 assert(hasInit() && "Expect initializer to check for flexible array init");
2833 auto *Ty = getType()->getAs<RecordType>();
2834 if (!Ty || !Ty->getDecl()->hasFlexibleArrayMember())
2835 return false;
2836 auto *List = dyn_cast<InitListExpr>(getInit()->IgnoreParens());
2837 if (!List)
2838 return false;
2839 const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1);
2840 auto InitTy = Ctx.getAsConstantArrayType(FlexibleInit->getType());
2841 if (!InitTy)
2842 return false;
2843 return InitTy->getSize() != 0;
2844}
2845
2847 assert(hasInit() && "Expect initializer to check for flexible array init");
2848 auto *Ty = getType()->getAs<RecordType>();
2849 if (!Ty || !Ty->getDecl()->hasFlexibleArrayMember())
2850 return CharUnits::Zero();
2851 auto *List = dyn_cast<InitListExpr>(getInit()->IgnoreParens());
2852 if (!List || List->getNumInits() == 0)
2853 return CharUnits::Zero();
2854 const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1);
2855 auto InitTy = Ctx.getAsConstantArrayType(FlexibleInit->getType());
2856 if (!InitTy)
2857 return CharUnits::Zero();
2858 CharUnits FlexibleArraySize = Ctx.getTypeSizeInChars(InitTy);
2859 const ASTRecordLayout &RL = Ctx.getASTRecordLayout(Ty->getDecl());
2860 CharUnits FlexibleArrayOffset =
2862 if (FlexibleArrayOffset + FlexibleArraySize < RL.getSize())
2863 return CharUnits::Zero();
2864 return FlexibleArrayOffset + FlexibleArraySize - RL.getSize();
2865}
2866
2868 if (isStaticDataMember())
2869 // FIXME: Remove ?
2870 // return getASTContext().getInstantiatedFromStaticDataMember(this);
2872 .dyn_cast<MemberSpecializationInfo *>();
2873 return nullptr;
2874}
2875
2877 SourceLocation PointOfInstantiation) {
2878 assert((isa<VarTemplateSpecializationDecl>(this) ||
2880 "not a variable or static data member template specialization");
2881
2883 dyn_cast<VarTemplateSpecializationDecl>(this)) {
2884 Spec->setSpecializationKind(TSK);
2885 if (TSK != TSK_ExplicitSpecialization &&
2886 PointOfInstantiation.isValid() &&
2887 Spec->getPointOfInstantiation().isInvalid()) {
2888 Spec->setPointOfInstantiation(PointOfInstantiation);
2890 L->InstantiationRequested(this);
2891 }
2893 MSI->setTemplateSpecializationKind(TSK);
2894 if (TSK != TSK_ExplicitSpecialization && PointOfInstantiation.isValid() &&
2895 MSI->getPointOfInstantiation().isInvalid()) {
2896 MSI->setPointOfInstantiation(PointOfInstantiation);
2898 L->InstantiationRequested(this);
2899 }
2900 }
2901}
2902
2903void
2906 assert(getASTContext().getTemplateOrSpecializationInfo(this).isNull() &&
2907 "Previous template or instantiation?");
2909}
2910
2911//===----------------------------------------------------------------------===//
2912// ParmVarDecl Implementation
2913//===----------------------------------------------------------------------===//
2914
2916 SourceLocation StartLoc,
2918 QualType T, TypeSourceInfo *TInfo,
2919 StorageClass S, Expr *DefArg) {
2920 return new (C, DC) ParmVarDecl(ParmVar, C, DC, StartLoc, IdLoc, Id, T, TInfo,
2921 S, DefArg);
2922}
2923
2926 QualType T = TSI ? TSI->getType() : getType();
2927 if (const auto *DT = dyn_cast<DecayedType>(T))
2928 return DT->getOriginalType();
2929 return T;
2930}
2931
2933 return new (C, ID)
2934 ParmVarDecl(ParmVar, C, nullptr, SourceLocation(), SourceLocation(),
2935 nullptr, QualType(), nullptr, SC_None, nullptr);
2936}
2937
2939 if (!hasInheritedDefaultArg()) {
2940 SourceRange ArgRange = getDefaultArgRange();
2941 if (ArgRange.isValid())
2942 return SourceRange(getOuterLocStart(), ArgRange.getEnd());
2943 }
2944
2945 // DeclaratorDecl considers the range of postfix types as overlapping with the
2946 // declaration name, but this is not the case with parameters in ObjC methods.
2947 if (isa<ObjCMethodDecl>(getDeclContext()))
2949
2951}
2952
2954 // ns_consumed only affects code generation in ARC
2955 if (hasAttr<NSConsumedAttr>())
2956 return getASTContext().getLangOpts().ObjCAutoRefCount;
2957
2958 // FIXME: isParamDestroyedInCallee() should probably imply
2959 // isDestructedType()
2960 const auto *RT = getType()->getAs<RecordType>();
2961 if (RT && RT->getDecl()->isParamDestroyedInCallee() &&
2963 return true;
2964
2965 return false;
2966}
2967
2969 assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!");
2970 assert(!hasUninstantiatedDefaultArg() &&
2971 "Default argument is not yet instantiated!");
2972
2973 Expr *Arg = getInit();
2974 if (auto *E = dyn_cast_if_present<FullExpr>(Arg))
2975 return E->getSubExpr();
2976
2977 return Arg;
2978}
2979
2981 ParmVarDeclBits.DefaultArgKind = DAK_Normal;
2982 Init = defarg;
2983}
2984
2986 switch (ParmVarDeclBits.DefaultArgKind) {
2987 case DAK_None:
2988 case DAK_Unparsed:
2989 // Nothing we can do here.
2990 return SourceRange();
2991
2992 case DAK_Uninstantiated:
2994
2995 case DAK_Normal:
2996 if (const Expr *E = getInit())
2997 return E->getSourceRange();
2998
2999 // Missing an actual expression, may be invalid.
3000 return SourceRange();
3001 }
3002 llvm_unreachable("Invalid default argument kind.");
3003}
3004
3006 ParmVarDeclBits.DefaultArgKind = DAK_Uninstantiated;
3007 Init = arg;
3008}
3009
3011 assert(hasUninstantiatedDefaultArg() &&
3012 "Wrong kind of initialization expression!");
3013 return cast_if_present<Expr>(Init.get<Stmt *>());
3014}
3015
3017 // FIXME: We should just return false for DAK_None here once callers are
3018 // prepared for the case that we encountered an invalid default argument and
3019 // were unable to even build an invalid expression.
3021 !Init.isNull();
3022}
3023
3024void ParmVarDecl::setParameterIndexLarge(unsigned parameterIndex) {
3025 getASTContext().setParameterIndex(this, parameterIndex);
3026 ParmVarDeclBits.ParameterIndex = ParameterIndexSentinel;
3027}
3028
3029unsigned ParmVarDecl::getParameterIndexLarge() const {
3030 return getASTContext().getParameterIndex(this);
3031}
3032
3033//===----------------------------------------------------------------------===//
3034// FunctionDecl Implementation
3035//===----------------------------------------------------------------------===//
3036
3038 SourceLocation StartLoc,
3039 const DeclarationNameInfo &NameInfo, QualType T,
3040 TypeSourceInfo *TInfo, StorageClass S,
3041 bool UsesFPIntrin, bool isInlineSpecified,
3042 ConstexprSpecKind ConstexprKind,
3043 Expr *TrailingRequiresClause)
3044 : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo,
3045 StartLoc),
3046 DeclContext(DK), redeclarable_base(C), Body(), ODRHash(0),
3047 EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) {
3048 assert(T.isNull() || T->isFunctionType());
3049 FunctionDeclBits.SClass = S;
3051 FunctionDeclBits.IsInlineSpecified = isInlineSpecified;
3052 FunctionDeclBits.IsVirtualAsWritten = false;
3053 FunctionDeclBits.IsPureVirtual = false;
3054 FunctionDeclBits.HasInheritedPrototype = false;
3055 FunctionDeclBits.HasWrittenPrototype = true;
3056 FunctionDeclBits.IsDeleted = false;
3057 FunctionDeclBits.IsTrivial = false;
3058 FunctionDeclBits.IsTrivialForCall = false;
3059 FunctionDeclBits.IsDefaulted = false;
3060 FunctionDeclBits.IsExplicitlyDefaulted = false;
3061 FunctionDeclBits.HasDefaultedFunctionInfo = false;
3062 FunctionDeclBits.IsIneligibleOrNotSelected = false;
3063 FunctionDeclBits.HasImplicitReturnZero = false;
3064 FunctionDeclBits.IsLateTemplateParsed = false;
3065 FunctionDeclBits.ConstexprKind = static_cast<uint64_t>(ConstexprKind);
3066 FunctionDeclBits.BodyContainsImmediateEscalatingExpression = false;
3067 FunctionDeclBits.InstantiationIsPending = false;
3068 FunctionDeclBits.UsesSEHTry = false;
3069 FunctionDeclBits.UsesFPIntrin = UsesFPIntrin;
3070 FunctionDeclBits.HasSkippedBody = false;
3071 FunctionDeclBits.WillHaveBody = false;
3072 FunctionDeclBits.IsMultiVersion = false;
3073 FunctionDeclBits.DeductionCandidateKind =
3074 static_cast<unsigned char>(DeductionCandidate::Normal);
3075 FunctionDeclBits.HasODRHash = false;
3076 FunctionDeclBits.FriendConstraintRefersToEnclosingTemplate = false;
3077 if (TrailingRequiresClause)
3078 setTrailingRequiresClause(TrailingRequiresClause);
3079}
3080
3082 raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
3085 if (TemplateArgs)
3086 printTemplateArgumentList(OS, TemplateArgs->asArray(), Policy);
3087}
3088
3090 if (const auto *FT = getType()->getAs<FunctionProtoType>())
3091 return FT->isVariadic();
3092 return false;
3093}
3094
3097 ArrayRef<DeclAccessPair> Lookups) {
3098 DefaultedFunctionInfo *Info = new (Context.Allocate(
3099 totalSizeToAlloc<DeclAccessPair>(Lookups.size()),
3100 std::max(alignof(DefaultedFunctionInfo), alignof(DeclAccessPair))))
3102 Info->NumLookups = Lookups.size();
3103 std::uninitialized_copy(Lookups.begin(), Lookups.end(),
3104 Info->getTrailingObjects<DeclAccessPair>());
3105 return Info;
3106}
3107
3109 assert(!FunctionDeclBits.HasDefaultedFunctionInfo && "already have this");
3110 assert(!Body && "can't replace function body with defaulted function info");
3111
3112 FunctionDeclBits.HasDefaultedFunctionInfo = true;
3113 DefaultedInfo = Info;
3114}
3115
3118 return FunctionDeclBits.HasDefaultedFunctionInfo ? DefaultedInfo : nullptr;
3119}
3120
3122 for (const auto *I : redecls()) {
3123 if (I->doesThisDeclarationHaveABody()) {
3124 Definition = I;
3125 return true;
3126 }
3127 }
3128
3129 return false;
3130}
3131
3133 const Stmt *S = getBody();
3134 if (!S) {
3135 // Since we don't have a body for this function, we don't know if it's
3136 // trivial or not.
3137 return false;
3138 }
3139
3140 if (isa<CompoundStmt>(S) && cast<CompoundStmt>(S)->body_empty())
3141 return true;
3142 return false;
3143}
3144
3146 if (!getFriendObjectKind())
3147 return false;
3148
3149 // Check for a friend function instantiated from a friend function
3150 // definition in a templated class.
3151 if (const FunctionDecl *InstantiatedFrom =
3153 return InstantiatedFrom->getFriendObjectKind() &&
3154 InstantiatedFrom->isThisDeclarationADefinition();
3155
3156 // Check for a friend function template instantiated from a friend
3157 // function template definition in a templated class.
3158 if (const FunctionTemplateDecl *Template = getDescribedFunctionTemplate()) {
3159 if (const FunctionTemplateDecl *InstantiatedFrom =
3161 return InstantiatedFrom->getFriendObjectKind() &&
3162 InstantiatedFrom->isThisDeclarationADefinition();
3163 }
3164
3165 return false;
3166}
3167
3169 bool CheckForPendingFriendDefinition) const {
3170 for (const FunctionDecl *FD : redecls()) {
3171 if (FD->isThisDeclarationADefinition()) {
3172 Definition = FD;
3173 return true;
3174 }
3175
3176 // If this is a friend function defined in a class template, it does not
3177 // have a body until it is used, nevertheless it is a definition, see
3178 // [temp.inst]p2:
3179 //
3180 // ... for the purpose of determining whether an instantiated redeclaration
3181 // is valid according to [basic.def.odr] and [class.mem], a declaration that
3182 // corresponds to a definition in the template is considered to be a
3183 // definition.
3184 //
3185 // The following code must produce redefinition error:
3186 //
3187 // template<typename T> struct C20 { friend void func_20() {} };
3188 // C20<int> c20i;
3189 // void func_20() {}
3190 //
3191 if (CheckForPendingFriendDefinition &&
3192 FD->isThisDeclarationInstantiatedFromAFriendDefinition()) {
3193 Definition = FD;
3194 return true;
3195 }
3196 }
3197
3198 return false;
3199}
3200
3202 if (!hasBody(Definition))
3203 return nullptr;
3204
3205 assert(!Definition->FunctionDeclBits.HasDefaultedFunctionInfo &&
3206 "definition should not have a body");
3207 if (Definition->Body)
3208 return Definition->Body.get(getASTContext().getExternalSource());
3209
3210 return nullptr;
3211}
3212
3214 FunctionDeclBits.HasDefaultedFunctionInfo = false;
3215 Body = LazyDeclStmtPtr(B);
3216 if (B)
3217 EndRangeLoc = B->getEndLoc();
3218}
3219
3221 FunctionDeclBits.IsPureVirtual = P;
3222 if (P)
3223 if (auto *Parent = dyn_cast<CXXRecordDecl>(getDeclContext()))
3224 Parent->markedVirtualFunctionPure();
3225}
3226
3227template<std::size_t Len>
3228static bool isNamed(const NamedDecl *ND, const char (&Str)[Len]) {
3229 const IdentifierInfo *II = ND->getIdentifier();
3230 return II && II->isStr(Str);
3231}
3232
3234 // C++23 [expr.const]/p17
3235 // An immediate-escalating function is
3236 // - the call operator of a lambda that is not declared with the consteval
3237 // specifier,
3238 if (isLambdaCallOperator(this) && !isConsteval())
3239 return true;
3240 // - a defaulted special member function that is not declared with the
3241 // consteval specifier,
3242 if (isDefaulted() && !isConsteval())
3243 return true;
3244 // - a function that results from the instantiation of a templated entity
3245 // defined with the constexpr specifier.
3247 if (TK != TK_NonTemplate && TK != TK_DependentNonTemplate &&
3249 return true;
3250 return false;
3251}
3252
3254 // C++23 [expr.const]/p18
3255 // An immediate function is a function or constructor that is
3256 // - declared with the consteval specifier
3257 if (isConsteval())
3258 return true;
3259 // - an immediate-escalating function F whose function body contains an
3260 // immediate-escalating expression
3262 return true;
3263
3264 if (const auto *MD = dyn_cast<CXXMethodDecl>(this);
3265 MD && MD->isLambdaStaticInvoker())
3266 return MD->getParent()->getLambdaCallOperator()->isImmediateFunction();
3267
3268 return false;
3269}
3270
3272 const TranslationUnitDecl *tunit =
3273 dyn_cast<TranslationUnitDecl>(getDeclContext()->getRedeclContext());
3274 return tunit &&
3275 !tunit->getASTContext().getLangOpts().Freestanding &&
3276 isNamed(this, "main");
3277}
3278
3280 const TranslationUnitDecl *TUnit =
3281 dyn_cast<TranslationUnitDecl>(getDeclContext()->getRedeclContext());
3282 if (!TUnit)
3283 return false;
3284
3285 // Even though we aren't really targeting MSVCRT if we are freestanding,
3286 // semantic analysis for these functions remains the same.
3287
3288 // MSVCRT entry points only exist on MSVCRT targets.
3289 if (!TUnit->getASTContext().getTargetInfo().getTriple().isOSMSVCRT())
3290 return false;
3291
3292 // Nameless functions like constructors cannot be entry points.
3293 if (!getIdentifier())
3294 return false;
3295
3296 return llvm::StringSwitch<bool>(getName())
3297 .Cases("main", // an ANSI console app
3298 "wmain", // a Unicode console App
3299 "WinMain", // an ANSI GUI app
3300 "wWinMain", // a Unicode GUI app
3301 "DllMain", // a DLL
3302 true)
3303 .Default(false);
3304}
3305
3307 if (getDeclName().getNameKind() != DeclarationName::CXXOperatorName)
3308 return false;
3309 if (getDeclName().getCXXOverloadedOperator() != OO_New &&
3310 getDeclName().getCXXOverloadedOperator() != OO_Delete &&
3311 getDeclName().getCXXOverloadedOperator() != OO_Array_New &&
3312 getDeclName().getCXXOverloadedOperator() != OO_Array_Delete)
3313 return false;
3314
3316 return false;
3317
3318 const auto *proto = getType()->castAs<FunctionProtoType>();
3319 if (proto->getNumParams() != 2 || proto->isVariadic())
3320 return false;
3321
3322 const ASTContext &Context =
3323 cast<TranslationUnitDecl>(getDeclContext()->getRedeclContext())
3324 ->getASTContext();
3325
3326 // The result type and first argument type are constant across all
3327 // these operators. The second argument must be exactly void*.
3328 return (proto->getParamType(1).getCanonicalType() == Context.VoidPtrTy);
3329}
3330
3332 std::optional<unsigned> *AlignmentParam, bool *IsNothrow) const {
3333 if (getDeclName().getNameKind() != DeclarationName::CXXOperatorName)
3334 return false;
3335 if (getDeclName().getCXXOverloadedOperator() != OO_New &&
3336 getDeclName().getCXXOverloadedOperator() != OO_Delete &&
3337 getDeclName().getCXXOverloadedOperator() != OO_Array_New &&
3338 getDeclName().getCXXOverloadedOperator() != OO_Array_Delete)
3339 return false;
3340
3341 if (isa<CXXRecordDecl>(getDeclContext()))
3342 return false;
3343
3344 // This can only fail for an invalid 'operator new' declaration.
3346 return false;
3347
3348 const auto *FPT = getType()->castAs<FunctionProtoType>();
3349 if (FPT->getNumParams() == 0 || FPT->getNumParams() > 4 || FPT->isVariadic())
3350 return false;
3351
3352 // If this is a single-parameter function, it must be a replaceable global
3353 // allocation or deallocation function.
3354 if (FPT->getNumParams() == 1)
3355 return true;
3356
3357 unsigned Params = 1;
3358 QualType Ty = FPT->getParamType(Params);
3359 const ASTContext &Ctx = getASTContext();
3360
3361 auto Consume = [&] {
3362 ++Params;
3363 Ty = Params < FPT->getNumParams() ? FPT->getParamType(Params) : QualType();
3364 };
3365
3366 // In C++14, the next parameter can be a 'std::size_t' for sized delete.
3367 bool IsSizedDelete = false;
3368 if (Ctx.getLangOpts().SizedDeallocation &&
3369 (getDeclName().getCXXOverloadedOperator() == OO_Delete ||
3370 getDeclName().getCXXOverloadedOperator() == OO_Array_Delete) &&
3371 Ctx.hasSameType(Ty, Ctx.getSizeType())) {
3372 IsSizedDelete = true;
3373 Consume();
3374 }
3375
3376 // In C++17, the next parameter can be a 'std::align_val_t' for aligned
3377 // new/delete.
3378 if (Ctx.getLangOpts().AlignedAllocation && !Ty.isNull() && Ty->isAlignValT()) {
3379 Consume();
3380 if (AlignmentParam)
3381 *AlignmentParam = Params;
3382 }
3383
3384 // If this is not a sized delete, the next parameter can be a
3385 // 'const std::nothrow_t&'.
3386 if (!IsSizedDelete && !Ty.isNull() && Ty->isReferenceType()) {
3387 Ty = Ty->getPointeeType();
3389 return false;
3390 if (Ty->isNothrowT()) {
3391 if (IsNothrow)
3392 *IsNothrow = true;
3393 Consume();
3394 }
3395 }
3396
3397 // Finally, recognize the not yet standard versions of new that take a
3398 // hot/cold allocation hint (__hot_cold_t). These are currently supported by
3399 // tcmalloc (see
3400 // https://github.com/google/tcmalloc/blob/220043886d4e2efff7a5702d5172cb8065253664/tcmalloc/malloc_extension.h#L53).
3401 if (!IsSizedDelete && !Ty.isNull() && Ty->isEnumeralType()) {
3402 QualType T = Ty;
3403 while (const auto *TD = T->getAs<TypedefType>())
3404 T = TD->getDecl()->getUnderlyingType();
3405 const IdentifierInfo *II =
3406 T->castAs<EnumType>()->getDecl()->getIdentifier();
3407 if (II && II->isStr("__hot_cold_t"))
3408 Consume();
3409 }
3410
3411 return Params == FPT->getNumParams();
3412}
3413
3415 if (!getBuiltinID())
3416 return false;
3417
3418 const FunctionDecl *Definition;
3419 if (!hasBody(Definition))
3420 return false;
3421
3422 if (!Definition->isInlineSpecified() ||
3423 !Definition->hasAttr<AlwaysInlineAttr>())
3424 return false;
3425
3426 ASTContext &Context = getASTContext();
3427 switch (Context.GetGVALinkageForFunction(Definition)) {
3428 case GVA_Internal:
3429 case GVA_DiscardableODR:
3430 case GVA_StrongODR:
3431 return false;
3433 case GVA_StrongExternal:
3434 return true;
3435 }
3436 llvm_unreachable("Unknown GVALinkage");
3437}
3438
3440 // C++ P0722:
3441 // Within a class C, a single object deallocation function with signature
3442 // (T, std::destroying_delete_t, <more params>)
3443 // is a destroying operator delete.
3444 if (!isa<CXXMethodDecl>(this) || getOverloadedOperator() != OO_Delete ||
3445 getNumParams() < 2)
3446 return false;
3447
3448 auto *RD = getParamDecl(1)->getType()->getAsCXXRecordDecl();
3449 return RD && RD->isInStdNamespace() && RD->getIdentifier() &&
3450 RD->getIdentifier()->isStr("destroying_delete_t");
3451}
3452
3454 return getDeclLanguageLinkage(*this);
3455}
3456
3458 return isDeclExternC(*this);
3459}
3460
3462 if (hasAttr<OpenCLKernelAttr>())
3463 return true;
3465}
3466
3469}
3470
3472 if (const auto *Method = dyn_cast<CXXMethodDecl>(this))
3473 return Method->isStatic();
3474
3476 return false;
3477
3478 for (const DeclContext *DC = getDeclContext();
3479 DC->isNamespace();
3480 DC = DC->getParent()) {
3481 if (const auto *Namespace = cast<NamespaceDecl>(DC)) {
3482 if (!Namespace->getDeclName())
3483 return false;
3484 }
3485 }
3486
3487 return true;
3488}
3489
3491 if (hasAttr<NoReturnAttr>() || hasAttr<CXX11NoReturnAttr>() ||
3492 hasAttr<C11NoReturnAttr>())
3493 return true;
3494
3495 if (auto *FnTy = getType()->getAs<FunctionType>())
3496 return FnTy->getNoReturnAttr();
3497
3498 return false;
3499}
3500
3502 // C++20 [temp.friend]p9:
3503 // A non-template friend declaration with a requires-clause [or]
3504 // a friend function template with a constraint that depends on a template
3505 // parameter from an enclosing template [...] does not declare the same
3506 // function or function template as a declaration in any other scope.
3507
3508 // If this isn't a friend then it's not a member-like constrained friend.
3509 if (!getFriendObjectKind()) {
3510 return false;
3511 }
3512
3514 // If these friends don't have constraints, they aren't constrained, and
3515 // thus don't fall under temp.friend p9. Else the simple presence of a
3516 // constraint makes them unique.
3518 }
3519
3521}
3522
3524 if (hasAttr<TargetAttr>())
3526 if (hasAttr<TargetVersionAttr>())
3528 if (hasAttr<CPUDispatchAttr>())
3530 if (hasAttr<CPUSpecificAttr>())
3532 if (hasAttr<TargetClonesAttr>())
3535}
3536
3538 return isMultiVersion() && hasAttr<CPUDispatchAttr>();
3539}
3540
3542 return isMultiVersion() && hasAttr<CPUSpecificAttr>();
3543}
3544
3546 return isMultiVersion() &&
3547 (hasAttr<TargetAttr>() || hasAttr<TargetVersionAttr>());
3548}
3549
3551 if (!isMultiVersion())
3552 return false;
3553 if (hasAttr<TargetAttr>())
3554 return getAttr<TargetAttr>()->isDefaultVersion();
3555 return hasAttr<TargetVersionAttr>() &&
3556 getAttr<TargetVersionAttr>()->isDefaultVersion();
3557}
3558
3560 return isMultiVersion() && hasAttr<TargetClonesAttr>();
3561}
3562
3564 return isMultiVersion() && hasAttr<TargetVersionAttr>();
3565}
3566
3567void
3570
3572 FunctionTemplateDecl *PrevFunTmpl
3573 = PrevDecl? PrevDecl->getDescribedFunctionTemplate() : nullptr;
3574 assert((!PrevDecl || PrevFunTmpl) && "Function/function template mismatch");
3575 FunTmpl->setPreviousDecl(PrevFunTmpl);
3576 }
3577
3578 if (PrevDecl && PrevDecl->isInlined())
3579 setImplicitlyInline(true);
3580}
3581
3583
3584/// Returns a value indicating whether this function corresponds to a builtin
3585/// function.
3586///
3587/// The function corresponds to a built-in function if it is declared at
3588/// translation scope or within an extern "C" block and its name matches with
3589/// the name of a builtin. The returned value will be 0 for functions that do
3590/// not correspond to a builtin, a value of type \c Builtin::ID if in the
3591/// target-independent range \c [1,Builtin::First), or a target-specific builtin
3592/// value.
3593///
3594/// \param ConsiderWrapperFunctions If true, we should consider wrapper
3595/// functions as their wrapped builtins. This shouldn't be done in general, but
3596/// it's useful in Sema to diagnose calls to wrappers based on their semantics.
3597unsigned FunctionDecl::getBuiltinID(bool ConsiderWrapperFunctions) const {
3598 unsigned BuiltinID = 0;
3599
3600 if (const auto *ABAA = getAttr<ArmBuiltinAliasAttr>()) {
3601 BuiltinID = ABAA->getBuiltinName()->getBuiltinID();
3602 } else if (const auto *BAA = getAttr<BuiltinAliasAttr>()) {
3603 BuiltinID = BAA->getBuiltinName()->getBuiltinID();
3604 } else if (const auto *A = getAttr<BuiltinAttr>()) {
3605 BuiltinID = A->getID();
3606 }
3607
3608 if (!BuiltinID)
3609 return 0;
3610
3611 // If the function is marked "overloadable", it has a different mangled name
3612 // and is not the C library function.
3613 if (!ConsiderWrapperFunctions && hasAttr<OverloadableAttr>() &&
3614 (!hasAttr<ArmBuiltinAliasAttr>() && !hasAttr<BuiltinAliasAttr>()))
3615 return 0;
3616
3617 const ASTContext &Context = getASTContext();
3618 if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
3619 return BuiltinID;
3620
3621 // This function has the name of a known C library
3622 // function. Determine whether it actually refers to the C library
3623 // function or whether it just has the same name.
3624
3625 // If this is a static function, it's not a builtin.
3626 if (!ConsiderWrapperFunctions && getStorageClass() == SC_Static)
3627 return 0;
3628
3629 // OpenCL v1.2 s6.9.f - The library functions defined in
3630 // the C99 standard headers are not available.
3631 if (Context.getLangOpts().OpenCL &&
3632 Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
3633 return 0;
3634
3635 // CUDA does not have device-side standard library. printf and malloc are the
3636 // only special cases that are supported by device-side runtime.
3637 if (Context.getLangOpts().CUDA && hasAttr<CUDADeviceAttr>() &&
3638 !hasAttr<CUDAHostAttr>() &&
3639 !(BuiltinID == Builtin::BIprintf || BuiltinID == Builtin::BImalloc))
3640 return 0;
3641
3642 // As AMDGCN implementation of OpenMP does not have a device-side standard
3643 // library, none of the predefined library functions except printf and malloc
3644 // should be treated as a builtin i.e. 0 should be returned for them.
3645 if (Context.getTargetInfo().getTriple().isAMDGCN() &&
3646 Context.getLangOpts().OpenMPIsTargetDevice &&
3647 Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID) &&
3648 !(BuiltinID == Builtin::BIprintf || BuiltinID == Builtin::BImalloc))
3649 return 0;
3650
3651 return BuiltinID;
3652}
3653
3654/// getNumParams - Return the number of parameters this function must have
3655/// based on its FunctionType. This is the length of the ParamInfo array
3656/// after it has been created.
3658 const auto *FPT = getType()->getAs<FunctionProtoType>();
3659 return FPT ? FPT->getNumParams() : 0;
3660}
3661
3662void FunctionDecl::setParams(ASTContext &C,
3663 ArrayRef<ParmVarDecl *> NewParamInfo) {
3664 assert(!ParamInfo && "Already has param info!");
3665 assert(NewParamInfo.size() == getNumParams() && "Parameter count mismatch!");
3666
3667 // Zero params -> null pointer.
3668 if (!NewParamInfo.empty()) {
3669 ParamInfo = new (C) ParmVarDecl*[NewParamInfo.size()];
3670 std::copy(NewParamInfo.begin(), NewParamInfo.end(), ParamInfo);
3671 }
3672}
3673
3674/// getMinRequiredArguments - Returns the minimum number of arguments
3675/// needed to call this function. This may be fewer than the number of
3676/// function parameters, if some of the parameters have default
3677/// arguments (in C++) or are parameter packs (C++11).
3680 return getNumParams();
3681
3682 // Note that it is possible for a parameter with no default argument to
3683 // follow a parameter with a default argument.
3684 unsigned NumRequiredArgs = 0;
3685 unsigned MinParamsSoFar = 0;
3686 for (auto *Param : parameters()) {
3687 if (!Param->isParameterPack()) {
3688 ++MinParamsSoFar;
3689 if (!Param->hasDefaultArg())
3690 NumRequiredArgs = MinParamsSoFar;
3691 }
3692 }
3693 return NumRequiredArgs;
3694}
3695
3698}
3699
3701 return getNumParams() -
3702 static_cast<unsigned>(hasCXXExplicitFunctionObjectParameter());
3703}
3704
3706 return getMinRequiredArguments() -
3707 static_cast<unsigned>(hasCXXExplicitFunctionObjectParameter());
3708}
3709
3711 return getNumParams() == 1 ||
3712 (getNumParams() > 1 &&
3713 llvm::all_of(llvm::drop_begin(parameters()),
3714 [](ParmVarDecl *P) { return P->hasDefaultArg(); }));
3715}
3716
3717/// The combination of the extern and inline keywords under MSVC forces
3718/// the function to be required.
3719///
3720/// Note: This function assumes that we will only get called when isInlined()
3721/// would return true for this FunctionDecl.
3723 assert(isInlined() && "expected to get called on an inlined function!");
3724
3725 const ASTContext &Context = getASTContext();
3726 if (!Context.getTargetInfo().getCXXABI().isMicrosoft() &&
3727 !hasAttr<DLLExportAttr>())
3728 return false;
3729
3730 for (const FunctionDecl *FD = getMostRecentDecl(); FD;
3731 FD = FD->getPreviousDecl())
3732 if (!FD->isImplicit() && FD->getStorageClass() == SC_Extern)
3733 return true;
3734
3735 return false;
3736}
3737
3738static bool redeclForcesDefMSVC(const FunctionDecl *Redecl) {
3739 if (Redecl->getStorageClass() != SC_Extern)
3740 return false;
3741
3742 for (const FunctionDecl *FD = Redecl->getPreviousDecl(); FD;
3743 FD = FD->getPreviousDecl())
3744 if (!FD->isImplicit() && FD->getStorageClass() == SC_Extern)
3745 return false;
3746
3747 return true;
3748}
3749
3750static bool RedeclForcesDefC99(const FunctionDecl *Redecl) {
3751 // Only consider file-scope declarations in this test.
3752 if (!Redecl->getLexicalDeclContext()->isTranslationUnit())
3753 return false;
3754
3755 // Only consider explicit declarations; the presence of a builtin for a
3756 // libcall shouldn't affect whether a definition is externally visible.
3757 if (Redecl->isImplicit())
3758 return false;
3759
3760 if (!Redecl->isInlineSpecified() || Redecl->getStorageClass() == SC_Extern)
3761 return true; // Not an inline definition
3762
3763 return false;
3764}
3765
3766/// For a function declaration in C or C++, determine whether this
3767/// declaration causes the definition to be externally visible.
3768///
3769/// For instance, this determines if adding the current declaration to the set
3770/// of redeclarations of the given functions causes
3771/// isInlineDefinitionExternallyVisible to change from false to true.
3773 assert(!doesThisDeclarationHaveABody() &&
3774 "Must have a declaration without a body.");
3775
3776 const ASTContext &Context = getASTContext();
3777
3778 if (Context.getLangOpts().MSVCCompat) {
3779 const FunctionDecl *Definition;
3780 if (hasBody(Definition) && Definition->isInlined() &&
3781 redeclForcesDefMSVC(this))
3782 return true;
3783 }
3784
3785 if (Context.getLangOpts().CPlusPlus)
3786 return false;
3787
3788 if (Context.getLangOpts().GNUInline || hasAttr<GNUInlineAttr>()) {
3789 // With GNU inlining, a declaration with 'inline' but not 'extern', forces
3790 // an externally visible definition.
3791 //
3792 // FIXME: What happens if gnu_inline gets added on after the first
3793 // declaration?
3795 return false;
3796
3797 const FunctionDecl *Prev = this;
3798 bool FoundBody = false;
3799 while ((Prev = Prev->getPreviousDecl())) {
3800 FoundBody |= Prev->doesThisDeclarationHaveABody();
3801
3802 if (Prev->doesThisDeclarationHaveABody()) {
3803 // If it's not the case that both 'inline' and 'extern' are
3804 // specified on the definition, then it is always externally visible.
3805 if (!Prev->isInlineSpecified() ||
3806 Prev->getStorageClass() != SC_Extern)
3807 return false;
3808 } else if (Prev->isInlineSpecified() &&
3809 Prev->getStorageClass() != SC_Extern) {
3810 return false;
3811 }
3812 }
3813 return FoundBody;
3814 }
3815
3816 // C99 6.7.4p6:
3817 // [...] If all of the file scope declarations for a function in a
3818 // translation unit include the inline function specifier without extern,
3819 // then the definition in that translation unit is an inline definition.
3821 return false;
3822 const FunctionDecl *Prev = this;
3823 bool FoundBody = false;
3824 while ((Prev = Prev->getPreviousDecl())) {
3825 FoundBody |= Prev->doesThisDeclarationHaveABody();
3826 if (RedeclForcesDefC99(Prev))
3827 return false;
3828 }
3829 return FoundBody;
3830}
3831
3833 const TypeSourceInfo *TSI = getTypeSourceInfo();
3834 return TSI ? TSI->getTypeLoc().IgnoreParens().getAs<FunctionTypeLoc>()
3835 : FunctionTypeLoc();
3836}
3837
3840 if (!FTL)
3841 return SourceRange();
3842
3843 // Skip self-referential return types.
3845 SourceRange RTRange = FTL.getReturnLoc().getSourceRange();
3846 SourceLocation Boundary = getNameInfo().getBeginLoc();
3847 if (RTRange.isInvalid() || Boundary.isInvalid() ||
3848 !SM.isBeforeInTranslationUnit(RTRange.getEnd(), Boundary))
3849 return SourceRange();
3850
3851 return RTRange;
3852}
3853
3855 unsigned NP = getNumParams();
3856 SourceLocation EllipsisLoc = getEllipsisLoc();
3857
3858 if (NP == 0 && EllipsisLoc.isInvalid())
3859 return SourceRange();
3860
3862 NP > 0 ? ParamInfo[0]->getSourceRange().getBegin() : EllipsisLoc;
3863 SourceLocation End = EllipsisLoc.isValid()
3864 ? EllipsisLoc
3865 : ParamInfo[NP - 1]->getSourceRange().getEnd();
3866
3867 return SourceRange(Begin, End);
3868}
3869
3872 return FTL ? FTL.getExceptionSpecRange() : SourceRange();
3873}
3874
3875/// For an inline function definition in C, or for a gnu_inline function
3876/// in C++, determine whether the definition will be externally visible.
3877///
3878/// Inline function definitions are always available for inlining optimizations.
3879/// However, depending on the language dialect, declaration specifiers, and
3880/// attributes, the definition of an inline function may or may not be
3881/// "externally" visible to other translation units in the program.
3882///
3883/// In C99, inline definitions are not externally visible by default. However,
3884/// if even one of the global-scope declarations is marked "extern inline", the
3885/// inline definition becomes externally visible (C99 6.7.4p6).
3886///
3887/// In GNU89 mode, or if the gnu_inline attribute is attached to the function
3888/// definition, we use the GNU semantics for inline, which are nearly the
3889/// opposite of C99 semantics. In particular, "inline" by itself will create
3890/// an externally visible symbol, but "extern inline" will not create an
3891/// externally visible symbol.
3894 hasAttr<AliasAttr>()) &&
3895 "Must be a function definition");
3896 assert(isInlined() && "Function must be inline");
3897 ASTContext &Context = getASTContext();
3898
3899 if (Context.getLangOpts().GNUInline || hasAttr<GNUInlineAttr>()) {
3900 // Note: If you change the logic here, please change
3901 // doesDeclarationForceExternallyVisibleDefinition as well.
3902 //
3903 // If it's not the case that both 'inline' and 'extern' are
3904 // specified on the definition, then this inline definition is
3905 // externally visible.
3906 if (Context.getLangOpts().CPlusPlus)
3907 return false;
3909 return true;
3910
3911 // If any declaration is 'inline' but not 'extern', then this definition
3912 // is externally visible.
3913 for (auto *Redecl : redecls()) {
3914 if (Redecl->isInlineSpecified() &&
3915 Redecl->getStorageClass() != SC_Extern)
3916 return true;
3917 }
3918
3919 return false;
3920 }
3921
3922 // The rest of this function is C-only.
3923 assert(!Context.getLangOpts().CPlusPlus &&
3924 "should not use C inline rules in C++");
3925
3926 // C99 6.7.4p6:
3927 // [...] If all of the file scope declarations for a function in a
3928 // translation unit include the inline function specifier without extern,
3929 // then the definition in that translation unit is an inline definition.
3930 for (auto *Redecl : redecls()) {
3931 if (RedeclForcesDefC99(Redecl))
3932 return true;
3933 }
3934
3935 // C99 6.7.4p6:
3936 // An inline definition does not provide an external definition for the
3937 // function, and does not forbid an external definition in another
3938 // translation unit.
3939 return false;
3940}
3941
3942/// getOverloadedOperator - Which C++ overloaded operator this
3943/// function represents, if any.
3945 if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName)
3947 return OO_None;
3948}
3949
3950/// getLiteralIdentifier - The literal suffix identifier this function
3951/// represents, if any.
3955 return nullptr;
3956}
3957
3959 if (TemplateOrSpecialization.isNull())
3960 return TK_NonTemplate;
3961 if (const auto *ND = TemplateOrSpecialization.dyn_cast<NamedDecl *>()) {
3962 if (isa<FunctionDecl>(ND))
3964 assert(isa<FunctionTemplateDecl>(ND) &&
3965 "No other valid types in NamedDecl");
3966 return TK_FunctionTemplate;
3967 }
3968 if (TemplateOrSpecialization.is<MemberSpecializationInfo *>())
3970 if (TemplateOrSpecialization.is<FunctionTemplateSpecializationInfo *>())
3972 if (TemplateOrSpecialization.is
3975
3976 llvm_unreachable("Did we miss a TemplateOrSpecialization type?");
3977}
3978
3981 return cast<FunctionDecl>(Info->getInstantiatedFrom());
3982
3983 return nullptr;
3984}
3985
3987 if (auto *MSI =
3988 TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo *>())
3989 return MSI;
3990 if (auto *FTSI = TemplateOrSpecialization
3991 .dyn_cast<FunctionTemplateSpecializationInfo *>())
3992 return FTSI->getMemberSpecializationInfo();
3993 return nullptr;
3994}
3995
3996void
3997FunctionDecl::setInstantiationOfMemberFunction(ASTContext &C,
3998 FunctionDecl *FD,
4000 assert(TemplateOrSpecialization.isNull() &&
4001 "Member function is already a specialization");
4003 = new (C) MemberSpecializationInfo(FD, TSK);
4004 TemplateOrSpecialization = Info;
4005}
4006
4008 return dyn_cast_if_present<FunctionTemplateDecl>(
4009 TemplateOrSpecialization.dyn_cast<NamedDecl *>());
4010}
4011
4013 FunctionTemplateDecl *Template) {
4014 assert(TemplateOrSpecialization.isNull() &&
4015 "Member function is already a specialization");
4016 TemplateOrSpecialization = Template;
4017}
4018
4020 return TemplateOrSpecialization.is<FunctionTemplateSpecializationInfo *>() ||
4021 TemplateOrSpecialization
4022 .is<DependentFunctionTemplateSpecializationInfo *>();
4023}
4024
4026 assert(TemplateOrSpecialization.isNull() &&
4027 "Function is already a specialization");
4028 TemplateOrSpecialization = FD;
4029}
4030
4032 return dyn_cast_if_present<FunctionDecl>(
4033 TemplateOrSpecialization.dyn_cast<NamedDecl *>());
4034}
4035
4037 // If the function is invalid, it can't be implicitly instantiated.
4038 if (isInvalidDecl())
4039 return false;
4040
4042 case TSK_Undeclared:
4045 return false;
4046
4048 return true;
4049
4051 // Handled below.
4052 break;
4053 }
4054
4055 // Find the actual template from which we will instantiate.
4056 const FunctionDecl *PatternDecl = getTemplateInstantiationPattern();
4057 bool HasPattern = false;
4058 if (PatternDecl)
4059 HasPattern = PatternDecl->hasBody(PatternDecl);
4060
4061 // C++0x [temp.explicit]p9:
4062 // Except for inline functions, other explicit instantiation declarations
4063 // have the effect of suppressing the implicit instantiation of the entity
4064 // to which they refer.
4065 if (!HasPattern || !PatternDecl)
4066 return true;
4067
4068 return PatternDecl->isInlined();
4069}
4070
4072 // FIXME: Remove this, it's not clear what it means. (Which template
4073 // specialization kind?)
4075}
4076
4079 // If this is a generic lambda call operator specialization, its
4080 // instantiation pattern is always its primary template's pattern
4081 // even if its primary template was instantiated from another
4082 // member template (which happens with nested generic lambdas).
4083 // Since a lambda's call operator's body is transformed eagerly,
4084 // we don't have to go hunting for a prototype definition template
4085 // (i.e. instantiated-from-member-template) to use as an instantiation
4086 // pattern.
4087
4089 dyn_cast<CXXMethodDecl>(this))) {
4090 assert(getPrimaryTemplate() && "not a generic lambda call operator?");
4091 return getDefinitionOrSelf(getPrimaryTemplate()->getTemplatedDecl());
4092 }
4093
4094 // Check for a declaration of this function that was instantiated from a
4095 // friend definition.
4096 const FunctionDecl *FD = nullptr;
4097 if (!isDefined(FD, /*CheckForPendingFriendDefinition=*/true))
4098 FD = this;
4099
4101 if (ForDefinition &&
4103 return nullptr;
4104 return getDefinitionOrSelf(cast<FunctionDecl>(Info->getInstantiatedFrom()));
4105 }
4106
4107 if (ForDefinition &&
4109 return nullptr;
4110
4111 if (FunctionTemplateDecl *Primary = getPrimaryTemplate()) {
4112 // If we hit a point where the user provided a specialization of this
4113 // template, we're done looking.
4114 while (!ForDefinition || !Primary->isMemberSpecialization()) {
4115 auto *NewPrimary = Primary->getInstantiatedFromMemberTemplate();
4116 if (!NewPrimary)
4117 break;
4118 Primary = NewPrimary;
4119 }
4120
4121 return getDefinitionOrSelf(Primary->getTemplatedDecl());
4122 }
4123
4124 return nullptr;
4125}
4126
4129 = TemplateOrSpecialization
4130 .dyn_cast<FunctionTemplateSpecializationInfo*>()) {
4131 return Info->getTemplate();
4132 }
4133 return nullptr;
4134}
4135
4138 return TemplateOrSpecialization
4140}
4141
4145 = TemplateOrSpecialization
4146 .dyn_cast<FunctionTemplateSpecializationInfo*>()) {
4147 return Info->TemplateArguments;
4148 }
4149 return nullptr;
4150}
4151
4155 = TemplateOrSpecialization
4156 .dyn_cast<FunctionTemplateSpecializationInfo*>()) {
4157 return Info->TemplateArgumentsAsWritten;
4158 }
4160 TemplateOrSpecialization
4161 .dyn_cast<DependentFunctionTemplateSpecializationInfo *>()) {
4162 return Info->TemplateArgumentsAsWritten;
4163 }
4164 return nullptr;
4165}
4166
4167void
4168FunctionDecl::setFunctionTemplateSpecialization(ASTContext &C,
4169 FunctionTemplateDecl *Template,
4170 const TemplateArgumentList *TemplateArgs,
4171 void *InsertPos,
4173 const TemplateArgumentListInfo *TemplateArgsAsWritten,
4174 SourceLocation PointOfInstantiation) {
4175 assert((TemplateOrSpecialization.isNull() ||
4176 TemplateOrSpecialization.is<MemberSpecializationInfo *>()) &&
4177 "Member function is already a specialization");
4178 assert(TSK != TSK_Undeclared &&
4179 "Must specify the type of function template specialization");
4180 assert((TemplateOrSpecialization.isNull() ||
4183 "Member specialization must be an explicit specialization");
4186 C, this, Template, TSK, TemplateArgs, TemplateArgsAsWritten,
4187 PointOfInstantiation,
4188 TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo *>());
4189 TemplateOrSpecialization = Info;
4190 Template->addSpecialization(Info, InsertPos);
4191}
4192
4194 ASTContext &Context, const UnresolvedSetImpl &Templates,
4195 const TemplateArgumentListInfo *TemplateArgs) {
4196 assert(TemplateOrSpecialization.isNull());
4199 TemplateArgs);
4200 TemplateOrSpecialization = Info;
4201}
4202
4205 return TemplateOrSpecialization
4207}
4208
4211 ASTContext &Context, const UnresolvedSetImpl &Candidates,
4212 const TemplateArgumentListInfo *TArgs) {
4213 const auto *TArgsWritten =
4214 TArgs ? ASTTemplateArgumentListInfo::Create(Context, *TArgs) : nullptr;
4215 return new (Context.Allocate(
4216 totalSizeToAlloc<FunctionTemplateDecl *>(Candidates.size())))
4217 DependentFunctionTemplateSpecializationInfo(Candidates, TArgsWritten);
4218}
4219
4220DependentFunctionTemplateSpecializationInfo::
4221 DependentFunctionTemplateSpecializationInfo(
4222 const UnresolvedSetImpl &Candidates,
4223 const ASTTemplateArgumentListInfo *TemplateArgsWritten)
4224 : NumCandidates(Candidates.size()),
4225 TemplateArgumentsAsWritten(TemplateArgsWritten) {
4226 std::transform(Candidates.begin(), Candidates.end(),
4227 getTrailingObjects<FunctionTemplateDecl *>(),
4228 [](NamedDecl *ND) {
4229 return cast<FunctionTemplateDecl>(ND->getUnderlyingDecl());
4230 });
4231}
4232
4234 // For a function template specialization, query the specialization
4235 // information object.
4237 TemplateOrSpecialization
4238 .dyn_cast<FunctionTemplateSpecializationInfo *>())
4239 return FTSInfo->getTemplateSpecializationKind();
4240
4241 if (MemberSpecializationInfo *MSInfo =
4242 TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo *>())
4243 return MSInfo->getTemplateSpecializationKind();
4244
4245 // A dependent function template specialization is an explicit specialization,
4246 // except when it's a friend declaration.
4247 if (TemplateOrSpecialization
4248 .is<DependentFunctionTemplateSpecializationInfo *>() &&
4251
4252 return TSK_Undeclared;
4253}
4254
4257 // This is the same as getTemplateSpecializationKind(), except that for a
4258 // function that is both a function template specialization and a member
4259 // specialization, we prefer the member specialization information. Eg:
4260 //
4261 // template<typename T> struct A {
4262 // template<typename U> void f() {}
4263 // template<> void f<int>() {}
4264 // };
4265 //
4266 // Within the templated CXXRecordDecl, A<T>::f<int> is a dependent function
4267 // template specialization; both getTemplateSpecializationKind() and
4268 // getTemplateSpecializationKindForInstantiation() will return
4269 // TSK_ExplicitSpecialization.
4270 //
4271 // For A<int>::f<int>():
4272 // * getTemplateSpecializationKind() will return TSK_ExplicitSpecialization
4273 // * getTemplateSpecializationKindForInstantiation() will return
4274 // TSK_ImplicitInstantiation
4275 //
4276 // This reflects the facts that A<int>::f<int> is an explicit specialization
4277 // of A<int>::f, and that A<int>::f<int> should be implicitly instantiated
4278 // from A::f<int> if a definition is needed.
4280 TemplateOrSpecialization
4281 .dyn_cast<FunctionTemplateSpecializationInfo *>()) {
4282 if (auto *MSInfo = FTSInfo->getMemberSpecializationInfo())
4283 return MSInfo->getTemplateSpecializationKind();
4284 return FTSInfo->getTemplateSpecializationKind();
4285 }
4286
4287 if (MemberSpecializationInfo *MSInfo =
4288 TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo *>())
4289 return MSInfo->getTemplateSpecializationKind();
4290
4291 if (TemplateOrSpecialization
4292 .is<DependentFunctionTemplateSpecializationInfo *>() &&
4295
4296 return TSK_Undeclared;
4297}
4298
4299void
4301 SourceLocation PointOfInstantiation) {
4303 = TemplateOrSpecialization.dyn_cast<
4305 FTSInfo->setTemplateSpecializationKind(TSK);
4306 if (TSK != TSK_ExplicitSpecialization &&
4307 PointOfInstantiation.isValid() &&
4308 FTSInfo->getPointOfInstantiation().isInvalid()) {
4309 FTSInfo->setPointOfInstantiation(PointOfInstantiation);
4311 L->InstantiationRequested(this);
4312 }
4313 } else if (MemberSpecializationInfo *MSInfo
4314 = TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>()) {
4315 MSInfo->setTemplateSpecializationKind(TSK);
4316 if (TSK != TSK_ExplicitSpecialization &&
4317 PointOfInstantiation.isValid() &&
4318 MSInfo->getPointOfInstantiation().isInvalid()) {
4319 MSInfo->setPointOfInstantiation(PointOfInstantiation);
4321 L->InstantiationRequested(this);
4322 }
4323 } else
4324 llvm_unreachable("Function cannot have a template specialization kind");
4325}
4326
4329 = TemplateOrSpecialization.dyn_cast<
4331 return FTSInfo->getPointOfInstantiation();
4332 if (MemberSpecializationInfo *MSInfo =
4333 TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo *>())
4334 return MSInfo->getPointOfInstantiation();
4335
4336 return SourceLocation();
4337}
4338
4340 if (Decl::isOutOfLine())
4341 return true;
4342
4343 // If this function was instantiated from a member function of a
4344 // class template, check whether that member function was defined out-of-line.
4346 const FunctionDecl *Definition;
4347 if (FD->hasBody(Definition))
4348 return Definition->isOutOfLine();
4349 }
4350
4351 // If this function was instantiated from a function template,
4352 // check whether that function template was defined out-of-line.
4353 if (FunctionTemplateDecl *FunTmpl = getPrimaryTemplate()) {
4354 const FunctionDecl *Definition;
4355 if (FunTmpl->getTemplatedDecl()->hasBody(Definition))
4356 return Definition->isOutOfLine();
4357 }
4358
4359 return false;
4360}
4361
4363 return SourceRange(getOuterLocStart(), EndRangeLoc);
4364}
4365
4367 IdentifierInfo *FnInfo = getIdentifier();
4368
4369 if (!FnInfo)
4370 return 0;
4371
4372 // Builtin handling.
4373 switch (getBuiltinID()) {
4374 case Builtin::BI__builtin_memset:
4375 case Builtin::BI__builtin___memset_chk:
4376 case Builtin::BImemset:
4377 return Builtin::BImemset;
4378
4379 case Builtin::BI__builtin_memcpy:
4380 case Builtin::BI__builtin___memcpy_chk:
4381 case Builtin::BImemcpy:
4382 return Builtin::BImemcpy;
4383
4384 case Builtin::BI__builtin_mempcpy:
4385 case Builtin::BI__builtin___mempcpy_chk:
4386 case Builtin::BImempcpy:
4387 return Builtin::BImempcpy;
4388
4389 case Builtin::BI__builtin_memmove:
4390 case Builtin::BI__builtin___memmove_chk:
4391 case Builtin::BImemmove:
4392 return Builtin::BImemmove;
4393
4394 case Builtin::BIstrlcpy:
4395 case Builtin::BI__builtin___strlcpy_chk:
4396 return Builtin::BIstrlcpy;
4397
4398 case Builtin::BIstrlcat:
4399 case Builtin::BI__builtin___strlcat_chk:
4400 return Builtin::BIstrlcat;
4401
4402 case Builtin::BI__builtin_memcmp:
4403 case Builtin::BImemcmp:
4404 return Builtin::BImemcmp;
4405
4406 case Builtin::BI__builtin_bcmp:
4407 case Builtin::BIbcmp:
4408 return Builtin::BIbcmp;
4409
4410 case Builtin::BI__builtin_strncpy:
4411 case Builtin::BI__builtin___strncpy_chk:
4412 case Builtin::BIstrncpy:
4413 return Builtin::BIstrncpy;
4414
4415 case Builtin::BI__builtin_strncmp:
4416 case Builtin::BIstrncmp:
4417 return Builtin::BIstrncmp;
4418
4419 case Builtin::BI__builtin_strncasecmp:
4420 case Builtin::BIstrncasecmp:
4421 return Builtin::BIstrncasecmp;
4422
4423 case Builtin::BI__builtin_strncat:
4424 case Builtin::BI__builtin___strncat_chk:
4425 case Builtin::BIstrncat:
4426 return Builtin::BIstrncat;
4427
4428 case Builtin::BI__builtin_strndup:
4429 case Builtin::BIstrndup:
4430 return Builtin::BIstrndup;
4431
4432 case Builtin::BI__builtin_strlen:
4433 case Builtin::BIstrlen:
4434 return Builtin::BIstrlen;
4435
4436 case Builtin::BI__builtin_bzero:
4437 case Builtin::BIbzero:
4438 return Builtin::BIbzero;
4439
4440 case Builtin::BI__builtin_bcopy:
4441 case Builtin::BIbcopy:
4442 return Builtin::BIbcopy;
4443
4444 case Builtin::BIfree:
4445 return Builtin::BIfree;
4446
4447 default:
4448 if (isExternC()) {
4449 if (FnInfo->isStr("memset"))
4450 return Builtin::BImemset;
4451 if (FnInfo->isStr("memcpy"))
4452 return Builtin::BImemcpy;
4453 if (FnInfo->isStr("mempcpy"))
4454 return Builtin::BImempcpy;
4455 if (FnInfo->isStr("memmove"))
4456 return Builtin::BImemmove;
4457 if (FnInfo->isStr("memcmp"))
4458 return Builtin::BImemcmp;
4459 if (FnInfo->isStr("bcmp"))
4460 return Builtin::BIbcmp;
4461 if (FnInfo->isStr("strncpy"))
4462 return Builtin::BIstrncpy;
4463 if (FnInfo->isStr("strncmp"))
4464 return Builtin::BIstrncmp;
4465 if (FnInfo->isStr("strncasecmp"))
4466 return Builtin::BIstrncasecmp;
4467 if (FnInfo->isStr("strncat"))
4468 return Builtin::BIstrncat;
4469 if (FnInfo->isStr("strndup"))
4470 return Builtin::BIstrndup;
4471 if (FnInfo->isStr("strlen"))
4472 return Builtin::BIstrlen;
4473 if (FnInfo->isStr("bzero"))
4474 return Builtin::BIbzero;
4475 if (FnInfo->isStr("bcopy"))
4476 return Builtin::BIbcopy;
4477 } else if (isInStdNamespace()) {
4478 if (FnInfo->isStr("free"))
4479 return Builtin::BIfree;
4480 }
4481 break;
4482 }
4483 return 0;
4484}
4485
4487 assert(hasODRHash());
4488 return ODRHash;
4489}
4490
4492 if (hasODRHash())
4493 return ODRHash;
4494
4495 if (auto *FT = getInstantiatedFromMemberFunction()) {
4496 setHasODRHash(true);
4497 ODRHash = FT->getODRHash();
4498 return ODRHash;
4499 }
4500
4501 class ODRHash Hash;
4502 Hash.AddFunctionDecl(this, /*SkipBody=*/shouldSkipCheckingODR());
4503 setHasODRHash(true);
4504 ODRHash = Hash.CalculateHash();
4505 return ODRHash;
4506}
4507
4508//===----------------------------------------------------------------------===//
4509// FieldDecl Implementation
4510//===----------------------------------------------------------------------===//
4511
4513 SourceLocation StartLoc, SourceLocation IdLoc,
4515 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
4516 InClassInitStyle InitStyle) {
4517 return new (C, DC) FieldDecl(Decl::Field, DC, StartLoc, IdLoc, Id, T, TInfo,
4518 BW, Mutable, InitStyle);
4519}
4520
4522 return new (C, ID) FieldDecl(Field, nullptr, SourceLocation(),
4523 SourceLocation(), nullptr, QualType(), nullptr,
4524 nullptr, false, ICIS_NoInit);
4525}
4526
4528 if (!isImplicit() || getDeclName())
4529 return false;
4530
4531 if (const auto *Record = getType()->getAs<RecordType>())
4532 return Record->getDecl()->isAnonymousStructOrUnion();
4533
4534 return false;
4535}
4536
4538 if (!hasInClassInitializer())
4539 return nullptr;
4540
4541 LazyDeclStmtPtr InitPtr = BitField ? InitAndBitWidth->Init : Init;
4542 return cast_if_present<Expr>(
4543 InitPtr.isOffset() ? InitPtr.get(getASTContext().getExternalSource())
4544 : InitPtr.get(nullptr));
4545}
4546
4548 setLazyInClassInitializer(LazyDeclStmtPtr(NewInit));
4549}
4550
4551void FieldDecl::setLazyInClassInitializer(LazyDeclStmtPtr NewInit) {
4553 if (BitField)
4554 InitAndBitWidth->Init = NewInit;
4555 else
4556 Init = NewInit;
4557}
4558
4559unsigned FieldDecl::getBitWidthValue(const ASTContext &Ctx) const {
4560 assert(isBitField() && "not a bitfield");
4561 return getBitWidth()->EvaluateKnownConstInt(Ctx).getZExtValue();
4562}
4563
4566 getBitWidthValue(Ctx) == 0;
4567}
4568
4569bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
4570 if (isZeroLengthBitField(Ctx))
4571 return true;
4572
4573 // C++2a [intro.object]p7:
4574 // An object has nonzero size if it
4575 // -- is not a potentially-overlapping subobject, or
4576 if (!hasAttr<NoUniqueAddressAttr>())
4577 return false;
4578
4579 // -- is not of class type, or
4580 const auto *RT = getType()->getAs<RecordType>();
4581 if (!RT)
4582 return false;
4583 const RecordDecl *RD = RT->getDecl()->getDefinition();
4584 if (!RD) {
4585 assert(isInvalidDecl() && "valid field has incomplete type");
4586 return false;
4587 }
4588
4589 // -- [has] virtual member functions or virtual base classes, or
4590 // -- has subobjects of nonzero size or bit-fields of nonzero length
4591 const auto *CXXRD = cast<CXXRecordDecl>(RD);
4592 if (!CXXRD->isEmpty())
4593 return false;
4594
4595 // Otherwise, [...] the circumstances under which the object has zero size
4596 // are implementation-defined.
4597 if (!Ctx.getTargetInfo().getCXXABI().isMicrosoft())
4598 return true;
4599
4600 // MS ABI: has nonzero size if it is a class type with class type fields,
4601 // whether or not they have nonzero size
4602 return !llvm::any_of(CXXRD->fields(), [](const FieldDecl *Field) {
4603 return Field->getType()->getAs<RecordType>();
4604 });
4605}
4606
4608 return hasAttr<NoUniqueAddressAttr>() && getType()->getAsCXXRecordDecl();
4609}
4610
4612 const FieldDecl *Canonical = getCanonicalDecl();
4613 if (Canonical != this)
4614 return Canonical->getFieldIndex();
4615
4616 if (CachedFieldIndex) return CachedFieldIndex - 1;
4617
4618 unsigned Index = 0;
4619 const RecordDecl *RD = getParent()->getDefinition();
4620 assert(RD && "requested index for field of struct with no definition");
4621
4622 for (auto *Field : RD->fields()) {
4623 Field->getCanonicalDecl()->CachedFieldIndex = Index + 1;
4624 assert(Field->getCanonicalDecl()->CachedFieldIndex == Index + 1 &&
4625 "overflow in field numbering");
4626 ++Index;
4627 }
4628
4629 assert(CachedFieldIndex && "failed to find field in parent");
4630 return CachedFieldIndex - 1;
4631}
4632
4634 const Expr *FinalExpr = getInClassInitializer();
4635 if (!FinalExpr)
4636 FinalExpr = getBitWidth();
4637 if (FinalExpr)
4638 return SourceRange(getInnerLocStart(), FinalExpr->getEndLoc());
4640}
4641
4643 assert((getParent()->isLambda() || getParent()->isCapturedRecord()) &&
4644 "capturing type in non-lambda or captured record.");
4645 assert(StorageKind == ISK_NoInit && !BitField &&
4646 "bit-field or field with default member initializer cannot capture "
4647 "VLA type");
4648 StorageKind = ISK_CapturedVLAType;
4649 CapturedVLAType = VLAType;
4650}
4651
4652void FieldDecl::printName(raw_ostream &OS, const PrintingPolicy &Policy) const {
4653 // Print unnamed members using name of their type.
4655 this->getType().print(OS, Policy);
4656 return;
4657 }
4658 // Otherwise, do the normal printing.
4659 DeclaratorDecl::printName(OS, Policy);
4660}
4661
4662//===----------------------------------------------------------------------===//
4663// TagDecl Implementation
4664//===----------------------------------------------------------------------===//
4665
4667 SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
4668 SourceLocation StartL)
4669 : TypeDecl(DK, DC, L, Id, StartL), DeclContext(DK), redeclarable_base(C),
4670 TypedefNameDeclOrQualifier((TypedefNameDecl *)nullptr) {
4671 assert((DK != Enum || TK == TagTypeKind::Enum) &&
4672 "EnumDecl not matched with TagTypeKind::Enum");
4673 setPreviousDecl(PrevDecl);
4674 setTagKind(TK);
4675 setCompleteDefinition(false);
4676 setBeingDefined(false);
4678 setFreeStanding(false);
4680 TagDeclBits.IsThisDeclarationADemotedDefinition = false;
4681}
4682
4684 return getTemplateOrInnerLocStart(this);
4685}
4686
4688 SourceLocation RBraceLoc = BraceRange.getEnd();
4689 SourceLocation E = RBraceLoc.isValid() ? RBraceLoc : getLocation();
4690 return SourceRange(getOuterLocStart(), E);
4691}
4692
4694
4696 TypedefNameDeclOrQualifier = TDD;
4697 if (const Type *T = getTypeForDecl()) {
4698 (void)T;
4699 assert(T->isLinkageValid());
4700 }
4701 assert(isLinkageValid());
4702}
4703
4705 setBeingDefined(true);
4706
4707 if (auto *D = dyn_cast<CXXRecordDecl>(this)) {
4708 struct CXXRecordDecl::DefinitionData *Data =
4709 new (getASTContext()) struct CXXRecordDecl::DefinitionData(D);
4710 for (auto *I : redecls())
4711 cast<CXXRecordDecl>(I)->DefinitionData = Data;
4712 }
4713}
4714
4716 assert((!isa<CXXRecordDecl>(this) ||
4717 cast<CXXRecordDecl>(this)->hasDefinition()) &&
4718 "definition completed but not started");
4719
4721 setBeingDefined(false);
4722
4724 L->CompletedTagDefinition(this);
4725}
4726
4729 return const_cast<TagDecl *>(this);
4730
4731 // If it's possible for us to have an out-of-date definition, check now.
4732 if (mayHaveOutOfDateDef()) {
4733 if (IdentifierInfo *II = getIdentifier()) {
4734 if (II->isOutOfDate()) {
4735 updateOutOfDate(*II);
4736 }
4737 }
4738 }
4739
4740 if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(this))
4741 return CXXRD->getDefinition();
4742
4743 for (auto *R : redecls())
4744 if (R->isCompleteDefinition())
4745 return R;
4746
4747 return nullptr;
4748}
4749
4751 if (QualifierLoc) {
4752 // Make sure the extended qualifier info is allocated.
4753 if (!hasExtInfo())
4754 TypedefNameDeclOrQualifier = new (getASTContext()) ExtInfo;
4755 // Set qualifier info.
4756 getExtInfo()->QualifierLoc = QualifierLoc;
4757 } else {
4758 // Here Qualifier == 0, i.e., we are removing the qualifier (if any).
4759 if (hasExtInfo()) {
4760 if (getExtInfo()->NumTemplParamLists == 0) {
4761 getASTContext().Deallocate(getExtInfo());
4762 TypedefNameDeclOrQualifier = (TypedefNameDecl *)nullptr;
4763 }
4764 else
4765 getExtInfo()->QualifierLoc = QualifierLoc;
4766 }
4767 }
4768}
4769
4770void TagDecl::printName(raw_ostream &OS, const PrintingPolicy &Policy) const {
4772 // If the name is supposed to have an identifier but does not have one, then
4773 // the tag is anonymous and we should print it differently.
4774 if (Name.isIdentifier() && !Name.getAsIdentifierInfo()) {
4775 // If the caller wanted to print a qualified name, they've already printed
4776 // the scope. And if the caller doesn't want that, the scope information
4777 // is already printed as part of the type.
4778 PrintingPolicy Copy(Policy);
4779 Copy.SuppressScope = true;
4781 return;
4782 }
4783 // Otherwise, do the normal printing.
4784 Name.print(OS, Policy);
4785}
4786
4789 assert(!TPLists.empty());
4790 // Make sure the extended decl info is allocated.
4791 if (!hasExtInfo())
4792 // Allocate external info struct.
4793 TypedefNameDeclOrQualifier = new (getASTContext()) ExtInfo;
4794 // Set the template parameter lists info.
4795 getExtInfo()->setTemplateParameterListsInfo(Context, TPLists);
4796}
4797
4798//===----------------------------------------------------------------------===//
4799// EnumDecl Implementation
4800//===----------------------------------------------------------------------===//
4801
4802EnumDecl::EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
4803 SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
4804 bool Scoped, bool ScopedUsingClassTag, bool Fixed)
4805 : TagDecl(Enum, TagTypeKind::Enum, C, DC, IdLoc, Id, PrevDecl, StartLoc) {
4806 assert(Scoped || !ScopedUsingClassTag);
4807 IntegerType = nullptr;
4808 setNumPositiveBits(0);
4809 setNumNegativeBits(0);
4810 setScoped(Scoped);
4811 setScopedUsingClassTag(ScopedUsingClassTag);
4812 setFixed(Fixed);
4813 setHasODRHash(false);
4814 ODRHash = 0;
4815}
4816
4817void EnumDecl::anchor() {}
4818
4820 SourceLocation StartLoc, SourceLocation IdLoc,
4822 EnumDecl *PrevDecl, bool IsScoped,
4823 bool IsScopedUsingClassTag, bool IsFixed) {
4824 auto *Enum = new (C, DC) EnumDecl(C, DC, StartLoc, IdLoc, Id, PrevDecl,
4825 IsScoped, IsScopedUsingClassTag, IsFixed);
4826 Enum->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
4827 C.getTypeDeclType(Enum, PrevDecl);
4828 return Enum;
4829}
4830
4832 EnumDecl *Enum =
4833 new (C, ID) EnumDecl(C, nullptr, SourceLocation(), SourceLocation(),
4834 nullptr, nullptr, false, false, false);
4835 Enum->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
4836 return Enum;
4837}
4838
4840 if (const TypeSourceInfo *TI = getIntegerTypeSourceInfo())
4841 return TI->getTypeLoc().getSourceRange();
4842 return SourceRange();
4843}
4844
4846 QualType NewPromotionType,
4847 unsigned NumPositiveBits,
4848 unsigned NumNegativeBits) {
4849 assert(!isCompleteDefinition() && "Cannot redefine enums!");
4850 if (!IntegerType)
4851 IntegerType = NewType.getTypePtr();
4852 PromotionType = NewPromotionType;
4853 setNumPositiveBits(NumPositiveBits);
4854 setNumNegativeBits(NumNegativeBits);
4856}
4857
4859 if (const auto *A = getAttr<EnumExtensibilityAttr>())
4860 return A->getExtensibility() == EnumExtensibilityAttr::Closed;
4861 return true;
4862}
4863
4865 return isClosed() && hasAttr<FlagEnumAttr>();
4866}
4867
4869 return isClosed() && !hasAttr<FlagEnumAttr>();
4870}
4871
4874 return MSI->getTemplateSpecializationKind();
4875
4876 return TSK_Undeclared;
4877}
4878
4880 SourceLocation PointOfInstantiation) {
4882 assert(MSI && "Not an instantiated member enumeration?");
4884 if (TSK != TSK_ExplicitSpecialization &&
4885 PointOfInstantiation.isValid() &&
4887 MSI->setPointOfInstantiation(PointOfInstantiation);
4888}
4889
4892 if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) {
4894 while (auto *NewED = ED->getInstantiatedFromMemberEnum())
4895 ED = NewED;
4896 return getDefinitionOrSelf(ED);
4897 }
4898 }
4899
4901 "couldn't find pattern for enum instantiation");
4902 return nullptr;
4903}
4904
4906 if (SpecializationInfo)
4907 return cast<EnumDecl>(SpecializationInfo->getInstantiatedFrom());
4908
4909 return nullptr;
4910}
4911
4912void EnumDecl::setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
4914 assert(!SpecializationInfo && "Member enum is already a specialization");
4915 SpecializationInfo = new (C) MemberSpecializationInfo(ED, TSK);
4916}
4917
4919 if (hasODRHash())
4920 return ODRHash;
4921
4922 class ODRHash Hash;
4923 Hash.AddEnumDecl(this);
4924 setHasODRHash(true);
4925 ODRHash = Hash.CalculateHash();
4926 return ODRHash;
4927}
4928
4930 auto Res = TagDecl::getSourceRange();
4931 // Set end-point to enum-base, e.g. enum foo : ^bar
4932 if (auto *TSI = getIntegerTypeSourceInfo()) {
4933 // TagDecl doesn't know about the enum base.
4934 if (!getBraceRange().getEnd().isValid())
4935 Res.setEnd(TSI->getTypeLoc().getEndLoc());
4936 }
4937 return Res;
4938}
4939
4940void EnumDecl::getValueRange(llvm::APInt &Max, llvm::APInt &Min) const {
4941 unsigned Bitwidth = getASTContext().getIntWidth(getIntegerType());
4942 unsigned NumNegativeBits = getNumNegativeBits();
4943 unsigned NumPositiveBits = getNumPositiveBits();
4944
4945 if (NumNegativeBits) {
4946 unsigned NumBits = std::max(NumNegativeBits, NumPositiveBits + 1);
4947 Max = llvm::APInt(Bitwidth, 1) << (NumBits - 1);
4948 Min = -Max;
4949 } else {
4950 Max = llvm::APInt(Bitwidth, 1) << NumPositiveBits;
4951 Min = llvm::APInt::getZero(Bitwidth);
4952 }
4953}
4954
4955//===----------------------------------------------------------------------===//
4956// RecordDecl Implementation
4957//===----------------------------------------------------------------------===//
4958
4960 DeclContext *DC, SourceLocation StartLoc,
4962 RecordDecl *PrevDecl)
4963 : TagDecl(DK, TK, C, DC, IdLoc, Id, PrevDecl, StartLoc) {
4964 assert(classof(static_cast<Decl *>(this)) && "Invalid Kind!");
4967 setHasObjectMember(false);
4968 setHasVolatileMember(false);
4978 setIsRandomized(false);
4979 setODRHash(0);
4980}
4981
4983 SourceLocation StartLoc, SourceLocation IdLoc,
4984 IdentifierInfo *Id, RecordDecl* PrevDecl) {
4985 RecordDecl *R = new (C, DC) RecordDecl(Record, TK, C, DC,
4986 StartLoc, IdLoc, Id, PrevDecl);
4987 R->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
4988
4989 C.getTypeDeclType(R, PrevDecl);
4990 return R;
4991}
4992
4994 RecordDecl *R = new (C, ID)
4996 SourceLocation(), nullptr, nullptr);
4997 R->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
4998 return R;
4999}
5000
5002 return isImplicit() && getDeclName() && getDeclContext()->isRecord() &&
5003 cast<RecordDecl>(getDeclContext())->getDeclName() == getDeclName();
5004}
5005
5007 if (auto RD = dyn_cast<CXXRecordDecl>(this))
5008 return RD->isLambda();
5009 return false;
5010}
5011
5013 return hasAttr<CapturedRecordAttr>();
5014}
5015
5017 addAttr(CapturedRecordAttr::CreateImplicit(getASTContext()));
5018}
5019
5021 if (isUnion())
5022 return true;
5023
5024 if (const RecordDecl *Def = getDefinition()) {
5025 for (const FieldDecl *FD : Def->fields()) {
5026 const RecordType *RT = FD->getType()->getAs<RecordType>();
5027 if (RT && RT->getDecl()->isOrContainsUnion())
5028 return true;
5029 }
5030 }
5031
5032 return false;
5033}
5034
5037 LoadFieldsFromExternalStorage();
5038 // This is necessary for correctness for C++ with modules.
5039 // FIXME: Come up with a test case that breaks without definition.
5040 if (RecordDecl *D = getDefinition(); D && D != this)
5041 return D->field_begin();
5043}
5044
5045/// completeDefinition - Notes that the definition of this type is now
5046/// complete.
5048 assert(!isCompleteDefinition() && "Cannot redefine record!");
5050
5051 ASTContext &Ctx = getASTContext();
5052
5053 // Layouts are dumped when computed, so if we are dumping for all complete
5054 // types, we need to force usage to get types that wouldn't be used elsewhere.
5055 //
5056 // If the type is dependent, then we can't compute its layout because there
5057 // is no way for us to know the size or alignment of a dependent type. Also
5058 // ignore declarations marked as invalid since 'getASTRecordLayout()' asserts
5059 // on that.
5060 if (Ctx.getLangOpts().DumpRecordLayoutsComplete && !isDependentType() &&
5061 !isInvalidDecl())
5062 (void)Ctx.getASTRecordLayout(this);
5063}
5064
5065/// isMsStruct - Get whether or not this record uses ms_struct layout.
5066/// This which can be turned on with an attribute, pragma, or the
5067/// -mms-bitfields command-line option.
5069 return hasAttr<MSStructAttr>() || C.getLangOpts().MSBitfields == 1;
5070}
5071
5073 std::tie(FirstDecl, LastDecl) = DeclContext::BuildDeclChain(Decls, false);
5074 LastDecl->NextInContextAndBits.setPointer(nullptr);
5075 setIsRandomized(true);
5076}
5077
5078void RecordDecl::LoadFieldsFromExternalStorage() const {
5080 assert(hasExternalLexicalStorage() && Source && "No external storage?");
5081
5082 // Notify that we have a RecordDecl doing some initialization.
5083 ExternalASTSource::Deserializing TheFields(Source);
5084
5087 Source->FindExternalLexicalDecls(this, [](Decl::Kind K) {
5089 }, Decls);
5090
5091#ifndef NDEBUG
5092 // Check that all decls we got were FieldDecls.
5093 for (unsigned i=0, e=Decls.size(); i != e; ++i)
5094 assert(isa<FieldDecl>(Decls[i]) || isa<IndirectFieldDecl>(Decls[i]));
5095#endif
5096
5097 if (Decls.empty())
5098 return;
5099
5100 auto [ExternalFirst, ExternalLast] =
5101 BuildDeclChain(Decls,
5102 /*FieldsAlreadyLoaded=*/false);
5103 ExternalLast->NextInContextAndBits.setPointer(FirstDecl);
5104 FirstDecl = ExternalFirst;
5105 if (!LastDecl)
5106 LastDecl = ExternalLast;
5107}
5108
5109bool RecordDecl::mayInsertExtraPadding(bool EmitRemark) const {
5110 ASTContext &Context = getASTContext();
5111 const SanitizerMask EnabledAsanMask = Context.getLangOpts().Sanitize.Mask &
5112 (SanitizerKind::Address | SanitizerKind::KernelAddress);
5113 if (!EnabledAsanMask || !Context.getLangOpts().SanitizeAddressFieldPadding)
5114 return false;
5115 const auto &NoSanitizeList = Context.getNoSanitizeList();
5116 const auto *CXXRD = dyn_cast<CXXRecordDecl>(this);
5117 // We may be able to relax some of these requirements.
5118 int ReasonToReject = -1;
5119 if (!CXXRD || CXXRD->isExternCContext())
5120 ReasonToReject = 0; // is not C++.
5121 else if (CXXRD->hasAttr<PackedAttr>())
5122 ReasonToReject = 1; // is packed.
5123 else if (CXXRD->isUnion())
5124 ReasonToReject = 2; // is a union.
5125 else if (CXXRD->isTriviallyCopyable())
5126 ReasonToReject = 3; // is trivially copyable.
5127 else if (CXXRD->hasTrivialDestructor())
5128 ReasonToReject = 4; // has trivial destructor.
5129 else if (CXXRD->isStandardLayout())
5130 ReasonToReject = 5; // is standard layout.
5131 else if (NoSanitizeList.containsLocation(EnabledAsanMask, getLocation(),
5132 "field-padding"))
5133 ReasonToReject = 6; // is in an excluded file.
5135 EnabledAsanMask, getQualifiedNameAsString(), "field-padding"))
5136 ReasonToReject = 7; // The type is excluded.
5137
5138 if (EmitRemark) {
5139 if (ReasonToReject >= 0)
5140 Context.getDiagnostics().Report(
5141 getLocation(),
5142 diag::remark_sanitize_address_insert_extra_padding_rejected)
5143 << getQualifiedNameAsString() << ReasonToReject;
5144 else
5145 Context.getDiagnostics().Report(
5146 getLocation(),
5147 diag::remark_sanitize_address_insert_extra_padding_accepted)
5149 }
5150 return ReasonToReject < 0;
5151}
5152
5154 for (const auto *I : fields()) {
5155 if (I->getIdentifier())
5156 return I;
5157
5158 if (const auto *RT = I->getType()->getAs<RecordType>())
5159 if (const FieldDecl *NamedDataMember =
5160 RT->getDecl()->findFirstNamedDataMember())
5161 return NamedDataMember;
5162 }
5163
5164 // We didn't find a named data member.
5165 return nullptr;
5166}
5167
5169 if (hasODRHash())
5170 return RecordDeclBits.ODRHash;
5171
5172 // Only calculate hash on first call of getODRHash per record.
5173 ODRHash Hash;
5174 Hash.AddRecordDecl(this);
5175 // For RecordDecl the ODRHash is stored in the remaining 26
5176 // bit of RecordDeclBits, adjust the hash to accomodate.
5177 setODRHash(Hash.CalculateHash() >> 6);
5178 return RecordDeclBits.ODRHash;
5179}
5180
5181//===----------------------------------------------------------------------===//
5182// BlockDecl Implementation
5183//===----------------------------------------------------------------------===//
5184
5186 : Decl(Block, DC, CaretLoc), DeclContext(Block) {
5187 setIsVariadic(false);
5188 setCapturesCXXThis(false);
5191 setDoesNotEscape(false);
5192 setCanAvoidCopyToHeap(false);
5193}
5194
5196 assert(!ParamInfo && "Already has param info!");
5197
5198 // Zero params -> null pointer.
5199 if (!NewParamInfo.empty()) {
5200 NumParams = NewParamInfo.size();
5201 ParamInfo = new (getASTContext()) ParmVarDecl*[NewParamInfo.size()];
5202 std::copy(NewParamInfo.begin(), NewParamInfo.end(), ParamInfo);
5203 }
5204}
5205
5207 bool CapturesCXXThis) {
5208 this->setCapturesCXXThis(CapturesCXXThis);
5209 this->NumCaptures = Captures.size();
5210
5211 if (Captures.empty()) {
5212 this->Captures = nullptr;
5213 return;
5214 }
5215
5216 this->Captures = Captures.copy(Context).data();
5217}
5218
5219bool BlockDecl::capturesVariable(const VarDecl *variable) const {
5220 for (const auto &I : captures())
5221 // Only auto vars can be captured, so no redeclaration worries.
5222 if (I.getVariable() == variable)
5223 return true;
5224
5225 return false;
5226}
5227
5229 return SourceRange(getLocation(), Body ? Body->getEndLoc() : getLocation());
5230}
5231
5232//===----------------------------------------------------------------------===//
5233// Other Decl Allocation/Deallocation Method Implementations
5234//===----------------------------------------------------------------------===//
5235
5236void TranslationUnitDecl::anchor() {}
5237
5239 return new (C, (DeclContext *)nullptr) TranslationUnitDecl(C);
5240}
5241
5242void PragmaCommentDecl::anchor() {}
5243
5246 SourceLocation CommentLoc,
5247 PragmaMSCommentKind CommentKind,
5248 StringRef Arg) {
5249 PragmaCommentDecl *PCD =
5250 new (C, DC, additionalSizeToAlloc<char>(Arg.size() + 1))
5251 PragmaCommentDecl(DC, CommentLoc, CommentKind);
5252 memcpy(PCD->getTrailingObjects<char>(), Arg.data(), Arg.size());
5253 PCD->getTrailingObjects<char>()[Arg.size()] = '\0';
5254 return PCD;
5255}
5256
5258 unsigned ID,
5259 unsigned ArgSize) {
5260 return new (C, ID, additionalSizeToAlloc<char>(ArgSize + 1))
5262}
5263
5264void PragmaDetectMismatchDecl::anchor() {}
5265
5268 SourceLocation Loc, StringRef Name,
5269 StringRef Value) {
5270 size_t ValueStart = Name.size() + 1;
5272 new (C, DC, additionalSizeToAlloc<char>(ValueStart + Value.size() + 1))
5273 PragmaDetectMismatchDecl(DC, Loc, ValueStart);
5274 memcpy(PDMD->getTrailingObjects<char>(), Name.data(), Name.size());
5275 PDMD->getTrailingObjects<char>()[Name.size()] = '\0';
5276 memcpy(PDMD->getTrailingObjects<char>() + ValueStart, Value.data(),
5277 Value.size());
5278 PDMD->getTrailingObjects<char>()[ValueStart + Value.size()] = '\0';
5279 return PDMD;
5280}
5281
5284 unsigned NameValueSize) {
5285 return new (C, ID, additionalSizeToAlloc<char>(NameValueSize + 1))
5287}
5288
5289void ExternCContextDecl::anchor() {}
5290
5292 TranslationUnitDecl *DC) {
5293 return new (C, DC) ExternCContextDecl(DC);
5294}
5295
5296void LabelDecl::anchor() {}
5297
5299 SourceLocation IdentL, IdentifierInfo *II) {
5300 return new (C, DC) LabelDecl(DC, IdentL, II, nullptr, IdentL);
5301}
5302
5304 SourceLocation IdentL, IdentifierInfo *II,
5305 SourceLocation GnuLabelL) {
5306 assert(GnuLabelL != IdentL && "Use this only for GNU local labels");
5307 return new (C, DC) LabelDecl(DC, IdentL, II, nullptr, GnuLabelL);
5308}
5309
5311 return new (C, ID) LabelDecl(nullptr, SourceLocation(), nullptr, nullptr,
5312 SourceLocation());
5313}
5314
5315void LabelDecl::setMSAsmLabel(StringRef Name) {
5316char *Buffer = new (getASTContext(), 1) char[Name.size() + 1];
5317 memcpy(Buffer, Name.data(), Name.size());
5318 Buffer[Name.size()] = '\0';
5319 MSAsmName = Buffer;
5320}
5321
5322void ValueDecl::anchor() {}
5323
5324bool ValueDecl::isWeak() const {
5325 auto *MostRecent = getMostRecentDecl();
5326 return MostRecent->hasAttr<WeakAttr>() ||
5327 MostRecent->hasAttr<WeakRefAttr>() || isWeakImported();
5328}
5329
5331 if (auto *Var = llvm::dyn_cast<VarDecl>(this))
5332 return Var->isInitCapture();
5333 return false;
5334}
5335
5336void ImplicitParamDecl::anchor() {}
5337
5339 SourceLocation IdLoc,
5341 ImplicitParamKind ParamKind) {
5342 return new (C, DC) ImplicitParamDecl(C, DC, IdLoc, Id, Type, ParamKind);
5343}
5344
5346 ImplicitParamKind ParamKind) {
5347 return new (C, nullptr) ImplicitParamDecl(C, Type, ParamKind);
5348}
5349
5351 unsigned ID) {
5353}
5354
5357 const DeclarationNameInfo &NameInfo, QualType T,
5358 TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin,
5359 bool isInlineSpecified, bool hasWrittenPrototype,
5360 ConstexprSpecKind ConstexprKind,
5361 Expr *TrailingRequiresClause) {
5362 FunctionDecl *New = new (C, DC) FunctionDecl(
5363 Function, C, DC, StartLoc, NameInfo, T, TInfo, SC, UsesFPIntrin,
5364 isInlineSpecified, ConstexprKind, TrailingRequiresClause);
5366 return New;
5367}
5368
5370 return new (C, ID) FunctionDecl(
5372 nullptr, SC_None, false, false, ConstexprSpecKind::Unspecified, nullptr);
5373}
5374
5376 return new (C, DC) BlockDecl(DC, L);
5377}
5378
5380 return new (C, ID) BlockDecl(nullptr, SourceLocation());
5381}
5382
5383CapturedDecl::CapturedDecl(DeclContext *DC, unsigned NumParams)
5384 : Decl(Captured, DC, SourceLocation()), DeclContext(Captured),
5385 NumParams(NumParams), ContextParam(0), BodyAndNothrow(nullptr, false) {}
5386
5388 unsigned NumParams) {
5389 return new (C, DC, additionalSizeToAlloc<ImplicitParamDecl *>(NumParams))
5390 CapturedDecl(DC, NumParams);
5391}
5392
5394 unsigned NumParams) {
5395 return new (C, ID, additionalSizeToAlloc<ImplicitParamDecl *>(NumParams))
5396 CapturedDecl(nullptr, NumParams);
5397}
5398
5399Stmt *CapturedDecl::getBody() const { return BodyAndNothrow.getPointer(); }
5400void CapturedDecl::setBody(Stmt *B) { BodyAndNothrow.setPointer(B); }
5401
5402bool CapturedDecl::isNothrow() const { return BodyAndNothrow.getInt(); }
5403void CapturedDecl::setNothrow(bool Nothrow) { BodyAndNothrow.setInt(Nothrow); }
5404
5407 QualType T, Expr *E, const llvm::APSInt &V)
5408 : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt *)E) {
5409 setInitVal(C, V);
5410}
5411
5415 Expr *E, const llvm::APSInt &V) {
5416 return new (C, CD) EnumConstantDecl(C, CD, L, Id, T, E, V);
5417}
5418
5421 return new (C, ID) EnumConstantDecl(C, nullptr, SourceLocation(), nullptr,
5422 QualType(), nullptr, llvm::APSInt());
5423}
5424
5425void IndirectFieldDecl::anchor() {}
5426
5427IndirectFieldDecl::IndirectFieldDecl(ASTContext &C, DeclContext *DC,
5429 QualType T,
5431 : ValueDecl(IndirectField, DC, L, N, T), Chaining(CH.data()),
5432 ChainingSize(CH.size()) {
5433 // In C++, indirect field declarations conflict with tag declarations in the
5434 // same scope, so add them to IDNS_Tag so that tag redeclaration finds them.
5435 if (C.getLangOpts().CPlusPlus)
5437}
5438
5443 return new (C, DC) IndirectFieldDecl(C, DC, L, Id, T, CH);
5444}
5445
5447 unsigned ID) {
5448 return new (C, ID)
5450 QualType(), std::nullopt);
5451}
5452
5455 if (Init)
5456 End = Init->getEndLoc();
5457 return SourceRange(getLocation(), End);
5458}
5459
5460void TypeDecl::anchor() {}
5461
5463 SourceLocation StartLoc, SourceLocation IdLoc,
5464 IdentifierInfo *Id, TypeSourceInfo *TInfo) {
5465 return new (C, DC) TypedefDecl(C, DC, StartLoc, IdLoc, Id, TInfo);
5466}
5467
5468void TypedefNameDecl::anchor() {}
5469
5471 if (auto *TT = getTypeSourceInfo()->getType()->getAs<TagType>()) {
5472 auto *OwningTypedef = TT->getDecl()->getTypedefNameForAnonDecl();
5473 auto *ThisTypedef = this;
5474 if (AnyRedecl && OwningTypedef) {
5475 OwningTypedef = OwningTypedef->getCanonicalDecl();
5476 ThisTypedef = ThisTypedef->getCanonicalDecl();
5477 }
5478 if (OwningTypedef == ThisTypedef)
5479 return TT->getDecl();
5480 }
5481
5482 return nullptr;
5483}
5484
5485bool TypedefNameDecl::isTransparentTagSlow() const {
5486 auto determineIsTransparent = [&]() {
5487 if (auto *TT = getUnderlyingType()->getAs<TagType>()) {
5488 if (auto *TD = TT->getDecl()) {
5489 if (TD->getName() != getName())
5490 return false;
5491 SourceLocation TTLoc = getLocation();
5492 SourceLocation TDLoc = TD->getLocation();
5493 if (!TTLoc.isMacroID() || !TDLoc.isMacroID())
5494 return false;
5496 return SM.getSpellingLoc(TTLoc) == SM.getSpellingLoc(TDLoc);
5497 }
5498 }
5499 return false;
5500 };
5501
5502 bool isTransparent = determineIsTransparent();
5503 MaybeModedTInfo.setInt((isTransparent << 1) | 1);
5504 return isTransparent;
5505}
5506
5508 return new (C, ID) TypedefDecl(C, nullptr, SourceLocation(), SourceLocation(),
5509 nullptr, nullptr);
5510}
5511
5513 SourceLocation StartLoc,
5515 TypeSourceInfo *TInfo) {
5516 return new (C, DC) TypeAliasDecl(C, DC, StartLoc, IdLoc, Id, TInfo);
5517}
5518
5520 return new (C, ID) TypeAliasDecl(C, nullptr, SourceLocation(),
5521 SourceLocation(), nullptr, nullptr);
5522}
5523
5525 SourceLocation RangeEnd = getLocation();
5526 if (TypeSourceInfo *TInfo = getTypeSourceInfo()) {
5527 if (typeIsPostfix(TInfo->getType()))
5528 RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd();
5529 }
5530 return SourceRange(getBeginLoc(), RangeEnd);
5531}
5532
5534 SourceLocation RangeEnd = getBeginLoc();
5535 if (TypeSourceInfo *TInfo = getTypeSourceInfo())
5536 RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd();
5537 return SourceRange(getBeginLoc(), RangeEnd);
5538}
5539
5540void FileScopeAsmDecl::anchor() {}
5541
5543 StringLiteral *Str,
5544 SourceLocation AsmLoc,
5545 SourceLocation RParenLoc) {
5546 return new (C, DC) FileScopeAsmDecl(DC, Str, AsmLoc, RParenLoc);
5547}
5548
5550 unsigned ID) {
5551 return new (C, ID) FileScopeAsmDecl(nullptr, nullptr, SourceLocation(),
5552 SourceLocation());
5553}
5554
5555void TopLevelStmtDecl::anchor() {}
5556
5558 assert(C.getLangOpts().IncrementalExtensions &&
5559 "Must be used only in incremental mode");
5560
5561 SourceLocation Loc = Statement ? Statement->getBeginLoc() : SourceLocation();
5562 DeclContext *DC = C.getTranslationUnitDecl();
5563
5564 return new (C, DC) TopLevelStmtDecl(DC, Loc, Statement);
5565}
5566
5568 unsigned ID) {
5569 return new (C, ID)
5570 TopLevelStmtDecl(/*DC=*/nullptr, SourceLocation(), /*S=*/nullptr);
5571}
5572
5574 return SourceRange(getLocation(), Statement->getEndLoc());
5575}
5576
5578 assert(S);
5579 Statement = S;
5580 setLocation(Statement->getBeginLoc());
5581}
5582
5583void EmptyDecl::anchor() {}
5584
5586 return new (C, DC) EmptyDecl(DC, L);
5587}
5588
5590 return new (C, ID) EmptyDecl(nullptr, SourceLocation());
5591}
5592
5593HLSLBufferDecl::HLSLBufferDecl(DeclContext *DC, bool CBuffer,
5595 SourceLocation IDLoc, SourceLocation LBrace)
5596 : NamedDecl(Decl::Kind::HLSLBuffer, DC, IDLoc, DeclarationName(ID)),
5597 DeclContext(Decl::Kind::HLSLBuffer), LBraceLoc(LBrace), KwLoc(KwLoc),
5598 IsCBuffer(CBuffer) {}
5599
5601 DeclContext *LexicalParent, bool CBuffer,
5603 SourceLocation IDLoc,
5604 SourceLocation LBrace) {
5605 // For hlsl like this
5606 // cbuffer A {
5607 // cbuffer B {
5608 // }
5609 // }
5610 // compiler should treat it as
5611 // cbuffer A {
5612 // }
5613 // cbuffer B {
5614 // }
5615 // FIXME: support nested buffers if required for back-compat.
5616 DeclContext *DC = LexicalParent;
5618 new (C, DC) HLSLBufferDecl(DC, CBuffer, KwLoc, ID, IDLoc, LBrace);
5619 return Result;
5620}
5621
5623 return new (C, ID) HLSLBufferDecl(nullptr, false, SourceLocation(), nullptr,
5625}
5626
5627//===----------------------------------------------------------------------===//
5628// ImportDecl Implementation
5629//===----------------------------------------------------------------------===//
5630
5631/// Retrieve the number of module identifiers needed to name the given
5632/// module.
5633static unsigned getNumModuleIdentifiers(Module *Mod) {
5634 unsigned Result = 1;
5635 while (Mod->Parent) {
5636 Mod = Mod->Parent;
5637 ++Result;
5638 }
5639 return Result;
5640}
5641
5642ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
5643 Module *Imported,
5644 ArrayRef<SourceLocation> IdentifierLocs)
5645 : Decl(Import, DC, StartLoc), ImportedModule(Imported),
5646 NextLocalImportAndComplete(nullptr, true) {
5647 assert(getNumModuleIdentifiers(Imported) == IdentifierLocs.size());
5648 auto *StoredLocs = getTrailingObjects<SourceLocation>();
5649 std::uninitialized_copy(IdentifierLocs.begin(), IdentifierLocs.end(),
5650 StoredLocs);
5651}
5652
5653ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
5654 Module *Imported, SourceLocation EndLoc)
5655 : Decl(Import, DC, StartLoc), ImportedModule(Imported),
5656 NextLocalImportAndComplete(nullptr, false) {
5657 *getTrailingObjects<SourceLocation>() = EndLoc;
5658}
5659
5661 SourceLocation StartLoc, Module *Imported,
5662 ArrayRef<SourceLocation> IdentifierLocs) {
5663 return new (C, DC,
5664 additionalSizeToAlloc<SourceLocation>(IdentifierLocs.size()))
5665 ImportDecl(DC, StartLoc, Imported, IdentifierLocs);
5666}
5667
5669 SourceLocation StartLoc,
5670 Module *Imported,
5671 SourceLocation EndLoc) {
5672 ImportDecl *Import = new (C, DC, additionalSizeToAlloc<SourceLocation>(1))
5673 ImportDecl(DC, StartLoc, Imported, EndLoc);
5674 Import->setImplicit();
5675 return Import;
5676}
5677
5679 unsigned NumLocations) {
5680 return new (C, ID, additionalSizeToAlloc<SourceLocation>(NumLocations))
5682}
5683
5685 if (!isImportComplete())
5686 return std::nullopt;
5687
5688 const auto *StoredLocs = getTrailingObjects<SourceLocation>();
5689 return llvm::ArrayRef(StoredLocs,
5691}
5692
5694 if (!isImportComplete())
5695 return SourceRange(getLocation(), *getTrailingObjects<SourceLocation>());
5696
5697 return SourceRange(getLocation(), getIdentifierLocs().back());
5698}
5699
5700//===----------------------------------------------------------------------===//
5701// ExportDecl Implementation
5702//===----------------------------------------------------------------------===//
5703
5704void ExportDecl::anchor() {}
5705
5707 SourceLocation ExportLoc) {
5708 return new (C, DC) ExportDecl(DC, ExportLoc);
5709}
5710
5712 return new (C, ID) ExportDecl(nullptr, SourceLocation());
5713}
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3259
NodeId Parent
Definition: ASTDiff.cpp:191
int Id
Definition: ASTDiff.cpp:190
This file provides some common utility functions for processing Lambda related AST Constructs.
StringRef P
static char ID
Definition: Arena.cpp:183
#define SM(sm)
Definition: Cuda.cpp:82
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines OpenMP nodes for declarative directives.
Defines the C++ template declaration subclasses.
static bool isFirstInExternCContext(T *D)
Definition: Decl.cpp:574
static bool isRedeclarableImpl(Redeclarable< T > *)
Definition: Decl.cpp:1835
static bool isDeclExternC(const T &D)
Definition: Decl.cpp:2226
static bool hasExplicitVisibilityAlready(LVComputationKind computation)
Does this computation kind permit us to consider additional visibility settings from attributes and t...
Definition: Decl.cpp:160
static bool RedeclForcesDefC99(const FunctionDecl *Redecl)
Definition: Decl.cpp:3750
static bool isExportedFromModuleInterfaceUnit(const NamedDecl *D)
Definition: Decl.cpp:1184
static bool isRedeclarable(Decl::Kind K)
Definition: Decl.cpp:1839
static bool redeclForcesDefMSVC(const FunctionDecl *Redecl)
Definition: Decl.cpp:3738
static bool usesTypeVisibility(const NamedDecl *D)
Is the given declaration a "type" or a "value" for the purposes of visibility computation?
Definition: Decl.cpp:181
static std::optional< Visibility > getVisibilityOf(const NamedDecl *D, NamedDecl::ExplicitVisibilityKind kind)
Return the explicit visibility of the given declaration.
Definition: Decl.cpp:223
static bool isDeclaredInModuleInterfaceOrPartition(const NamedDecl *D)
Definition: Decl.cpp:586
static bool isInNamedModule(const NamedDecl *D)
Determine whether D is attached to a named module.
Definition: Decl.cpp:1178
static LanguageLinkage getDeclLanguageLinkage(const T &D)
Definition: Decl.cpp:2199
static LVComputationKind withExplicitVisibilityAlready(LVComputationKind Kind)
Given an LVComputationKind, return one of the same type/value sort that records that it already has e...
Definition: Decl.cpp:167
static std::enable_if_t<!std::is_base_of_v< RedeclarableTemplateDecl, T >, bool > isExplicitMemberSpecialization(const T *D)
Does the given declaration have member specialization information, and if so, is it an explicit speci...
Definition: Decl.cpp:191
static unsigned getNumModuleIdentifiers(Module *Mod)
Retrieve the number of module identifiers needed to name the given module.
Definition: Decl.cpp:5633
static bool isSingleLineLanguageLinkage(const Decl &D)
Definition: Decl.cpp:579
static bool useInlineVisibilityHidden(const NamedDecl *D)
Definition: Decl.cpp:546
static bool shouldConsiderTemplateVisibility(const FunctionDecl *fn, const FunctionTemplateSpecializationInfo *specInfo)
Definition: Decl.cpp:373
static bool hasDirectVisibilityAttribute(const NamedDecl *D, LVComputationKind computation)
Does the given declaration have a direct visibility attribute that would match the given rules?
Definition: Decl.cpp:419
static DeclT * getDefinitionOrSelf(DeclT *D)
Definition: Decl.cpp:2668
static Visibility getVisibilityFromAttr(const T *attr)
Given a visibility attribute, return the explicit visibility associated with it.
Definition: Decl.cpp:209
static const Decl * getOutermostFuncOrBlockContext(const Decl *D)
Definition: Decl.cpp:303
static bool typeIsPostfix(QualType QT)
Definition: Decl.cpp:2053
static LinkageInfo getExternalLinkageFor(const NamedDecl *D)
Definition: Decl.cpp:592
static StorageClass getStorageClass(const Decl *D)
Definition: Decl.cpp:596
static std::optional< Visibility > getExplicitVisibilityAux(const NamedDecl *ND, NamedDecl::ExplicitVisibilityKind kind, bool IsMostRecent)
Definition: Decl.cpp:1225
static SourceLocation getTemplateOrInnerLocStart(const DeclT *decl)
Definition: Decl.cpp:1979
static bool isNamed(const NamedDecl *ND, const char(&Str)[Len])
Definition: Decl.cpp:3228
static std::optional< Visibility > getExplicitVisibility(const NamedDecl *D, LVComputationKind kind)
Definition: Decl.cpp:172
static bool hasDefinition(const ObjCObjectPointerType *ObjPtr)
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Definition: MachO.h:28
Defines the clang::Module class, which describes a module in the source code.
This file contains the declaration of the ODRHash class, which calculates a hash based on AST nodes,...
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
static std::string getName(const CallEvent &Call)
Defines the clang::SanitizerKind enum.
static bool isFunctionOrMethod(const Decl *D)
isFunctionOrMethod - Return true if the given decl has function type (function or function-typed vari...
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the TargetCXXABI class, which abstracts details of the C++ ABI that we're targeting.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
static const TypeInfo & getInfo(unsigned id)
Definition: Types.cpp:47
SourceLocation Begin
Defines the clang::Visibility enumeration and various utility functions.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
bool isAbsent() const
Definition: APValue.h:397
bool needsCleanup() const
Returns whether the object performed allocations.
Definition: APValue.cpp:431
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
SourceManager & getSourceManager()
Definition: ASTContext.h:700
const ConstantArrayType * getAsConstantArrayType(QualType T) const
Definition: ASTContext.h:2742
unsigned getIntWidth(QualType T) const
TemplateOrSpecializationInfo getTemplateOrSpecializationInfo(const VarDecl *Var)
void setTemplateOrSpecializationInfo(VarDecl *Inst, TemplateOrSpecializationInfo TSI)
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2565
CanQualType VoidPtrTy
Definition: ASTContext.h:1113
void Deallocate(void *Ptr) const
Definition: ASTContext.h:719
Builtin::Context & BuiltinInfo
Definition: ASTContext.h:641
const LangOptions & getLangOpts() const
Definition: ASTContext.h:770
void setParameterIndex(const ParmVarDecl *D, unsigned index)
Used by ParmVarDecl to store on the side the index of the parameter when it exceeds the size of the n...
Decl * getPrimaryMergedDecl(Decl *D)
Definition: ASTContext.h:1030
const NoSanitizeList & getNoSanitizeList() const
Definition: ASTContext.h:780
GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:692
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:713
void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
Note that the static data member Inst is an instantiation of the static data member template Tmpl of ...
DiagnosticsEngine & getDiagnostics() const
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:752
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
void addDestruction(T *Ptr) const
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
Definition: ASTContext.h:3086
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1182
NestedNameSpecifier * getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const
Retrieves the "canonical" nested name specifier for a given nested name specifier.
unsigned getParameterIndex(const ParmVarDecl *D) const
Used by ParmVarDecl to retrieve on the side the index of the parameter when it exceeds the size of th...
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
Definition: RecordLayout.h:38
CharUnits getSize() const
getSize - Get the record size in characters.
Definition: RecordLayout.h:193
unsigned getFieldCount() const
getFieldCount - Get the number of fields in the layout.
Definition: RecordLayout.h:196
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
Definition: RecordLayout.h:200
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4459
BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
Definition: Decl.cpp:5185
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition: Decl.cpp:5195
void setDoesNotEscape(bool B=true)
Definition: Decl.h:4611
void setCapturesCXXThis(bool B=true)
Definition: Decl.h:4592
void setCanAvoidCopyToHeap(bool B=true)
Definition: Decl.h:4616
static BlockDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5379
void setIsConversionFromLambda(bool val=true)
Definition: Decl.h:4606
void setBlockMissingReturnType(bool val=true)
Definition: Decl.h:4598
ArrayRef< Capture > captures() const
Definition: Decl.h:4586
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5228
void setIsVariadic(bool value)
Definition: Decl.h:4535
bool capturesVariable(const VarDecl *var) const
Definition: Decl.cpp:5219
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
Definition: Decl.cpp:5206
static BlockDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L)
Definition: Decl.cpp:5375
bool isPredefinedLibFunction(unsigned ID) const
Determines whether this builtin is a predefined libc/libm function, such as "malloc",...
Definition: Builtins.h:160
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
Definition: DeclCXX.cpp:1875
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4651
void setBody(Stmt *B)
Definition: Decl.cpp:5400
static CapturedDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NumParams)
Definition: Decl.cpp:5393
bool isNothrow() const
Definition: Decl.cpp:5402
void setNothrow(bool Nothrow=true)
Definition: Decl.cpp:5403
static CapturedDecl * Create(ASTContext &C, DeclContext *DC, unsigned NumParams)
Definition: Decl.cpp:5387
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:5399
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition: CharUnits.h:53
Declaration of a class template.
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
Represents a class template specialization, which refers to a class template with a given set of temp...
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
const llvm::APInt & getSize() const
Definition: Type.h:3207
A POD class for pairing a NamedDecl* with an access specifier.
decl_iterator - Iterates through the declarations stored within this context.
Definition: DeclBase.h:2289
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2352
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1446
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2076
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
Definition: DeclBase.h:2201
FunctionDeclBitfields FunctionDeclBits
Definition: DeclBase.h:2013
bool isFileContext() const
Definition: DeclBase.h:2147
static std::pair< Decl *, Decl * > BuildDeclChain(ArrayRef< Decl * > Decls, bool FieldsAlreadyLoaded)
Build up a chain of declarations.
Definition: DeclBase.cpp:1456
TagDeclBitfields TagDeclBits
Definition: DeclBase.h:2009
bool isExternCXXContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Definition: DeclBase.cpp:1331
bool isNamespace() const
Definition: DeclBase.h:2161
bool isTranslationUnit() const
Definition: DeclBase.h:2152
bool isRecord() const
Definition: DeclBase.h:2156
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1921
RecordDeclBitfields RecordDeclBits
Definition: DeclBase.h:2011
Decl * FirstDecl
FirstDecl - The first declaration stored within this declaration context.
Definition: DeclBase.h:2046
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2647
Decl * LastDecl
LastDecl - The last declaration stored within this declaration context.
Definition: DeclBase.h:2052
bool isInlineNamespace() const
Definition: DeclBase.cpp:1244
bool isFunctionOrMethod() const
Definition: DeclBase.h:2128
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Definition: DeclBase.cpp:1316
Decl::Kind getDeclKind() const
Definition: DeclBase.h:2069
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition: DeclBase.h:1061
bool isInStdNamespace() const
Definition: DeclBase.cpp:403
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1226
T * getAttr() const
Definition: DeclBase.h:578
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
void addAttr(Attr *A)
Definition: DeclBase.cpp:975
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:598
virtual bool isOutOfLine() const
Determine whether this declaration is declared out of line (outside its semantic context).
Definition: Decl.cpp:100
Module * getOwningModuleForLinkage(bool IgnoreLinkage=false) const
Get the module that owns this declaration for linkage purposes.
Definition: Decl.cpp:1624
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
Definition: DeclBase.cpp:804
ModuleOwnershipKind getModuleOwnershipKind() const
Get the kind of module ownership for this declaration.
Definition: DeclBase.h:876
ASTMutationListener * getASTMutationListener() const
Definition: DeclBase.cpp:511
bool hasCachedLinkage() const
Definition: DeclBase.h:426
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:88
@ FOK_None
Not a friend object.
Definition: DeclBase.h:1217
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:984
llvm::PointerIntPair< Decl *, 3, ModuleOwnershipKind > NextInContextAndBits
The next declaration within the same lexical DeclContext.
Definition: DeclBase.h:248
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
Definition: DeclBase.h:843
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:227
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:786
Linkage getCachedLinkage() const
Definition: DeclBase.h:418
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
Definition: DeclBase.h:2749
bool isInvalidDecl() const
Definition: DeclBase.h:593
bool hasDefiningAttr() const
Return true if this declaration has an attribute which acts as definition of the entity,...
Definition: DeclBase.cpp:588
SourceLocation getLocation() const
Definition: DeclBase.h:444
bool shouldSkipCheckingODR() const
Check if we should skip checking ODRHash for declaration.
Definition: DeclBase.cpp:1105
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition: DeclBase.h:114
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition: DeclBase.h:124
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:1049
void setLocation(SourceLocation L)
Definition: DeclBase.h:445
DeclContext * getDeclContext()
Definition: DeclBase.h:453
bool isInAnonymousNamespace() const
Definition: DeclBase.cpp:393
void setCachedLinkage(Linkage L) const
Definition: DeclBase.h:422
friend class RecordDecl
Definition: DeclBase.h:332
void updateOutOfDate(IdentifierInfo &II) const
Update a potentially out-of-date declaration.
Definition: DeclBase.cpp:63
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:918
bool hasAttr() const
Definition: DeclBase.h:582
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:978
@ VisibleWhenImported
This declaration has an owning module, and is visible when that module is imported.
@ Unowned
This declaration is not owned by a module.
@ ReachableWhenImported
This declaration has an owning module, and is visible to lookups that occurs within that module.
@ ModulePrivate
This declaration has an owning module, but is only visible to lookups that occur within that module.
@ Visible
This declaration has an owning module, but is globally visible (typically because its owning module i...
Kind getKind() const
Definition: DeclBase.h:447
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
Definition: DeclBase.cpp:507
The name of a declaration.
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:770
SourceLocation getTypeSpecEndLoc() const
Definition: Decl.cpp:1991
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:813
SourceLocation getOuterLocStart() const
Return start of source range taking into account any outer template declarations.
Definition: Decl.cpp:2047
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:2087
SourceLocation getTypeSpecStartLoc() const
Definition: Decl.cpp:1985
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:822
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1997
void setTrailingRequiresClause(Expr *TrailingRequiresClause)
Definition: Decl.cpp:2016
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition: Decl.h:846
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:799
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition: Decl.cpp:2031
Provides information about a dependent function-template specialization declaration.
Definition: DeclTemplate.h:690
static DependentFunctionTemplateSpecializationInfo * Create(ASTContext &Context, const UnresolvedSetImpl &Candidates, const TemplateArgumentListInfo *TemplateArgs)
Definition: Decl.cpp:4210
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1547
Represents an empty-declaration.
Definition: Decl.h:4890
static EmptyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L)
Definition: Decl.cpp:5585
static EmptyDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5589
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3265
EnumConstantDecl(const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
Definition: Decl.cpp:5405
void setInitVal(const ASTContext &C, const llvm::APSInt &V)
Definition: Decl.h:3290
static EnumConstantDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5420
static EnumConstantDecl * Create(ASTContext &C, EnumDecl *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
Definition: Decl.cpp:5412
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5453
Represents an enum.
Definition: Decl.h:3832
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4091
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:4029
unsigned getODRHash()
Definition: Decl.cpp:4918
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:4879
static EnumDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl, bool IsScoped, bool IsScopedUsingClassTag, bool IsFixed)
Definition: Decl.cpp:4819
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists,...
Definition: Decl.h:4008
static EnumDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4831
bool isClosedFlag() const
Returns true if this enum is annotated with flag_enum and isn't annotated with enum_extensibility(ope...
Definition: Decl.cpp:4864
SourceRange getIntegerTypeRange() const LLVM_READONLY
Retrieve the source range that covers the underlying type if specified.
Definition: Decl.cpp:4839
SourceRange getSourceRange() const override LLVM_READONLY
Overrides to provide correct range when there's an enum-base specifier with forward declarations.
Definition: Decl.cpp:4929
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:3992
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4905
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition: Decl.h:4018
TemplateSpecializationKind getTemplateSpecializationKind() const
If this enumeration is a member of a specialization of a templated class, determine what kind of temp...
Definition: Decl.cpp:4872
bool isClosed() const
Returns true if this enum is either annotated with enum_extensibility(closed) or isn't annotated with...
Definition: Decl.cpp:4858
EnumDecl * getTemplateInstantiationPattern() const
Retrieve the enum definition from which this enumeration could be instantiated, if it is an instantia...
Definition: Decl.cpp:4890
bool isClosedNonFlag() const
Returns true if this enum is annotated with neither flag_enum nor enum_extensibility(open).
Definition: Decl.cpp:4868
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:4940
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5118
Represents a standard C++ module export declaration.
Definition: Decl.h:4843
static ExportDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation ExportLoc)
Definition: Decl.cpp:5706
static ExportDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5711
This represents one expression.
Definition: Expr.h:110
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:175
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
QualType getType() const
Definition: Expr.h:142
Declaration context for names declared as extern "C" in C++.
Definition: Decl.h:222
static ExternCContextDecl * Create(const ASTContext &C, TranslationUnitDecl *TU)
Definition: Decl.cpp:5291
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
Abstract interface for external sources of AST nodes.
virtual void FindExternalLexicalDecls(const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl * > &Result)
Finds all declarations lexically contained within the given DeclContext, after applying an optional f...
Represents a member of a struct/union/class.
Definition: Decl.h:3025
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4537
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:3116
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:3186
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition: Decl.cpp:4611
LazyDeclStmtPtr Init
Definition: Decl.h:3075
bool isAnonymousStructOrUnion() const
Determines whether this field is a representative for an anonymous struct or union.
Definition: Decl.cpp:4527
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4633
bool isZeroLengthBitField(const ASTContext &Ctx) const
Is this a zero-length bit-field? Such bit-fields aren't really bit-fields at all and instead act as a...
Definition: Decl.cpp:4564
bool isUnnamedBitfield() const
Determines whether this is an unnamed bitfield.
Definition: Decl.h:3119
unsigned getBitWidthValue(const ASTContext &Ctx) const
Computes the bit width of this field, if this is a bit field.
Definition: Decl.cpp:4559
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition: Decl.cpp:4547
static FieldDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4521
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition: Decl.h:3238
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:4569
InitAndBitWidthStorage * InitAndBitWidth
Definition: Decl.h:3079
FieldDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this field.
Definition: Decl.h:3249
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
Definition: Decl.cpp:4512
static bool classofKind(Kind K)
Definition: Decl.h:3254
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition: Decl.h:3129
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition: Decl.cpp:4652
bool isPotentiallyOverlapping() const
Determine if this field is of potentially-overlapping class type, that is, subobject with the [[no_un...
Definition: Decl.cpp:4607
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition: Decl.cpp:4642
const VariableArrayType * CapturedVLAType
Definition: Decl.h:3081
static FileScopeAsmDecl * Create(ASTContext &C, DeclContext *DC, StringLiteral *Str, SourceLocation AsmLoc, SourceLocation RParenLoc)
Definition: Decl.cpp:5542
static FileScopeAsmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5549
Stashed information about a defaulted function definition whose body has not yet been lazily generate...
Definition: Decl.h:1987
static DefaultedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups)
Definition: Decl.cpp:3096
Represents a function declaration or definition.
Definition: Decl.h:1959
unsigned getMemoryFunctionKind() const
Identify a memory copying or setting function.
Definition: Decl.cpp:4366
bool isTargetClonesMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target-clones functional...
Definition: Decl.cpp:3559
bool isMultiVersion() const
True if this function is considered a multiversioned function.
Definition: Decl.h:2574
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2674
bool hasTrivialBody() const
Returns whether the function has a trivial body that does not require any specific codegen.
Definition: Decl.cpp:3132
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
Definition: Decl.cpp:3678
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition: Decl.cpp:4019
void setPreviousDeclaration(FunctionDecl *PrevDecl)
Definition: Decl.cpp:3568
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:4012
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:4007
void setIsPureVirtual(bool P=true)
Definition: Decl.cpp:3220
bool isImmediateFunction() const
Definition: Decl.cpp:3253
SourceLocation getEllipsisLoc() const
Returns the location of the ellipsis of a variadic function.
Definition: Decl.h:2167
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type.
Definition: Decl.cpp:3838
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition: Decl.cpp:3439
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
Definition: Decl.cpp:3597
SourceLocation getPointOfInstantiation() const
Retrieve the (first) point of instantiation of a function template specialization or a member of a cl...
Definition: Decl.cpp:4327
bool isMemberLikeConstrainedFriend() const
Determine whether a function is a friend function that cannot be redeclared outside of its class,...
Definition: Decl.cpp:3501
bool hasCXXExplicitFunctionObjectParameter() const
Definition: Decl.cpp:3696
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
Definition: Decl.h:2798
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition: Decl.h:2786
void setHasWrittenPrototype(bool P=true)
State that this function has a written prototype.
Definition: Decl.h:2390
bool isNoReturn() const
Determines whether this function is known to be 'noreturn', through an attribute on its declaration o...
Definition: Decl.cpp:3490
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2651
bool isCPUSpecificMultiVersion() const
True if this function is a multiversioned processor specific function as a part of the cpu_specific/c...
Definition: Decl.cpp:3541
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:4078
bool isMSExternInline() const
The combination of the extern and inline keywords under MSVC forces the function to be required.
Definition: Decl.cpp:3722
unsigned getMinRequiredExplicitArguments() const
Returns the minimum number of non-object arguments needed to call this function.
Definition: Decl.cpp:3705
bool BodyContainsImmediateEscalatingExpressions() const
Definition: Decl.h:2427
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
Definition: Decl.cpp:3453
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
Definition: Decl.cpp:4127
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition: Decl.h:2385
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:3986
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition: Decl.cpp:4137
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:3582
FunctionTypeLoc getFunctionTypeLoc() const
Find the source location information for how the type of this function was written.
Definition: Decl.cpp:3832
bool isVariadic() const
Whether this function is variadic.
Definition: Decl.cpp:3089
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition: Decl.h:2270
bool isConstexprSpecified() const
Definition: Decl.h:2416
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition: Decl.cpp:4204
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition: Decl.cpp:4143
SourceRange getExceptionSpecSourceRange() const
Attempt to compute an informative source range covering the function exception specification,...
Definition: Decl.cpp:3870
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:2197
bool isMSVCRTEntryPoint() const
Determines whether this function is a MSVCRT user defined entry point.
Definition: Decl.cpp:3279
unsigned getODRHash()
Returns ODRHash of the function.
Definition: Decl.cpp:4491
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Determine the kind of template specialization this function represents for the purpose of template in...
Definition: Decl.cpp:4256
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
Definition: Decl.cpp:4071
unsigned getNumNonObjectParams() const
Definition: Decl.cpp:3700
TemplatedKind
The kind of templated function a FunctionDecl can be.
Definition: Decl.h:1964
@ TK_MemberSpecialization
Definition: Decl.h:1971
@ TK_DependentNonTemplate
Definition: Decl.h:1980
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1975
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1978
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2765
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a member function.
Definition: Decl.cpp:4339
bool isInlineBuiltinDeclaration() const
Determine if this function provides an inline implementation of a builtin.
Definition: Decl.cpp:3414
bool FriendConstraintRefersToEnclosingTemplate() const
Definition: Decl.h:2592
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition: Decl.cpp:3958
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition: Decl.cpp:4025
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
Definition: Decl.cpp:3306
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:4193
bool isInExternCContext() const
Determines whether this function's context is, or is nested within, a C++ extern "C" linkage spec.
Definition: Decl.cpp:3461
FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass S, bool UsesFPIntrin, bool isInlineSpecified, ConstexprSpecKind ConstexprKind, Expr *TrailingRequiresClause=nullptr)
Definition: Decl.cpp:3037
bool isImplicitlyInstantiable() const
Determines whether this function is a function template specialization or a member of a class templat...
Definition: Decl.cpp:4036
bool isExternC() const
Determines whether this function is a function with external, C linkage.
Definition: Decl.cpp:3457
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:2244
bool isDefined() const
Definition: Decl.h:2220
LazyDeclStmtPtr Body
The body of the function.
Definition: Decl.h:2011
bool isImmediateEscalating() const
Definition: Decl.cpp:3233
bool isInExternCXXContext() const
Determines whether this function's context is, or is nested within, a C++ extern "C++" linkage spec.
Definition: Decl.cpp:3467
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program.
Definition: Decl.cpp:3271
void setImplicitlyInline(bool I=true)
Flag that this function is implicitly inline.
Definition: Decl.h:2793
bool isTargetVersionMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target-version functiona...
Definition: Decl.cpp:3563
bool isReplaceableGlobalAllocationFunction(std::optional< unsigned > *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions: void *operato...
Definition: Decl.cpp:3331
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, Expr *TrailingRequiresClause=nullptr)
Definition: Decl.h:2135
bool isThisDeclarationInstantiatedFromAFriendDefinition() const
Determine whether this specific declaration of the function is a friend declaration that was instanti...
Definition: Decl.cpp:3145
bool isCPUDispatchMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the cpu_specific/cpu_dispatc...
Definition: Decl.cpp:3537
bool isDefaulted() const
Whether this function is defaulted.
Definition: Decl.h:2322
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4362
FunctionDecl * getInstantiatedFromDecl() const
Definition: Decl.cpp:4031
static FunctionDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5369
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:4300
const IdentifierInfo * getLiteralIdentifier() const
getLiteralIdentifier - The literal suffix identifier this function represents, if any.
Definition: Decl.cpp:3952
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition: Decl.cpp:3944
DefaultedFunctionInfo * DefaultedInfo
Information about a future defaulted function definition.
Definition: Decl.h:2013
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:4233
bool doesDeclarationForceExternallyVisibleDefinition() const
For a function declaration in C or C++, determine whether this declaration causes the definition to b...
Definition: Decl.cpp:3772
bool isConsteval() const
Definition: Decl.h:2419
bool isTargetMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target functionality.
Definition: Decl.cpp:3545
DefaultedFunctionInfo * getDefaultedFunctionInfo() const
Definition: Decl.cpp:3117
void setBody(Stmt *B)
Definition: Decl.cpp:3213
bool isGlobal() const
Determines whether this is a global function.
Definition: Decl.cpp:3471
bool hasOneParamOrDefaultArgs() const
Determine whether this function has a single parameter, or multiple parameters where all but the firs...
Definition: Decl.cpp:3710
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:3550
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:3979
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:3892
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3657
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:2157
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:3121
SourceRange getParametersSourceRange() const
Attempt to compute an informative source range covering the function parameters, including the ellips...
Definition: Decl.cpp:3854
void setDefaultedFunctionInfo(DefaultedFunctionInfo *Info)
Definition: Decl.cpp:3108
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2776
MultiVersionKind getMultiVersionKind() const
Gets the kind of multiversioning attribute this declaration has.
Definition: Decl.cpp:3523
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:3081
bool willHaveBody() const
True if this function will eventually have a body, once it's fully parsed.
Definition: Decl.h:2570
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Definition: Decl.cpp:4153
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4199
unsigned getNumParams() const
Definition: Type.h:4432
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:4555
Declaration of a template function.
Definition: DeclTemplate.h:958
void addSpecialization(FunctionTemplateSpecializationInfo *Info, void *InsertPos)
Add a specialization of this function template.
FunctionTemplateDecl * getInstantiatedFromMemberTemplate() const
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Definition: DeclTemplate.h:467
const TemplateArgumentList * TemplateArguments
The template arguments used to produce the function template specialization from the function templat...
Definition: DeclTemplate.h:481
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
Definition: DeclTemplate.h:523
static FunctionTemplateSpecializationInfo * Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs, const TemplateArgumentListInfo *TemplateArgsAsWritten, SourceLocation POI, MemberSpecializationInfo *MSInfo)
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
Definition: DeclTemplate.h:537
Wrapper for source info for functions.
Definition: TypeLoc.h:1402
SourceRange getExceptionSpecRange() const
Definition: TypeLoc.h:1454
TypeLoc getReturnLoc() const
Definition: TypeLoc.h:1483
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3799
HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
Definition: Decl.h:4905
static HLSLBufferDecl * Create(ASTContext &C, DeclContext *LexicalParent, bool CBuffer, SourceLocation KwLoc, IdentifierInfo *ID, SourceLocation IDLoc, SourceLocation LBrace)
Definition: Decl.cpp:5600
static HLSLBufferDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5622
One of these records is kept for each identifier that is lexed.
ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const
Determine whether this is a name reserved for the implementation (C99 7.1.3, C++ [lib....
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
static ImplicitParamDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5350
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
Definition: Decl.cpp:5338
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4764
static ImportDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, Module *Imported, ArrayRef< SourceLocation > IdentifierLocs)
Create a new module import declaration.
Definition: Decl.cpp:5660
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5693
static ImportDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NumLocations)
Create a new, deserialized module import declaration.
Definition: Decl.cpp:5678
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:5684
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition: Decl.h:4822
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:5668
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3309
static bool classofKind(Kind K)
Definition: Decl.h:3353
static IndirectFieldDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, llvm::MutableArrayRef< NamedDecl * > CH)
Definition: Decl.cpp:5440
static IndirectFieldDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5446
Represents the declaration of a label.
Definition: Decl.h:499
void setMSAsmLabel(StringRef Name)
Definition: Decl.cpp:5315
static LabelDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II)
Definition: Decl.cpp:5298
static LabelDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5310
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:418
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:424
LinkageInfo getTypeLinkageAndVisibility(const Type *T)
Definition: Type.cpp:4503
LinkageInfo computeLVForDecl(const NamedDecl *D, LVComputationKind computation, bool IgnoreVarTypeLinkage=false)
Definition: Decl.cpp:1450
LinkageInfo getLVForDecl(const NamedDecl *D, LVComputationKind computation)
getLVForDecl - Get the linkage and visibility for the given declaration.
Definition: Decl.cpp:1568
LinkageInfo getDeclLinkageAndVisibility(const NamedDecl *D)
Definition: Decl.cpp:1614
Visibility getVisibility() const
Definition: Visibility.h:89
static LinkageInfo external()
Definition: Visibility.h:72
static LinkageInfo none()
Definition: Visibility.h:81
void setLinkage(Linkage L)
Definition: Visibility.h:92
void mergeExternalVisibility(Linkage L)
Definition: Visibility.h:101
void mergeMaybeWithVisibility(LinkageInfo other, bool withVis)
Merge linkage and conditionally merge visibility.
Definition: Visibility.h:143
Linkage getLinkage() const
Definition: Visibility.h:88
static LinkageInfo internal()
Definition: Visibility.h:75
static LinkageInfo visible_none()
Definition: Visibility.h:84
static LinkageInfo uniqueExternal()
Definition: Visibility.h:78
void mergeVisibility(Visibility newVis, bool newExplicit)
Merge in the visibility 'newVis'.
Definition: Visibility.h:116
bool isVisibilityExplicit() const
Definition: Visibility.h:90
void merge(LinkageInfo other)
Merge both linkage and visibility.
Definition: Visibility.h:137
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:616
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
Definition: DeclTemplate.h:647
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:638
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:656
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:661
NamedDecl * getInstantiatedFrom() const
Retrieve the member declaration from which this member was instantiated.
Definition: DeclTemplate.h:635
Describes a module or submodule.
Definition: Module.h:105
Module * Parent
The parent of this module.
Definition: Module.h:154
ModuleKind Kind
The kind of this module.
Definition: Module.h:150
@ ModuleImplementationUnit
This is a C++20 module implementation unit.
Definition: Module.h:128
@ ModuleMapModule
This is a module that was defined by a module map and built out of header files.
Definition: Module.h:119
@ ImplicitGlobalModuleFragment
This is an implicit fragment of the global module which contains only language linkage declarations (...
Definition: Module.h:146
@ ModulePartitionInterface
This is a C++20 module partition interface.
Definition: Module.h:131
@ ModuleInterfaceUnit
This is a C++20 module interface unit.
Definition: Module.h:125
@ ModuleHeaderUnit
This is a C++20 header unit.
Definition: Module.h:122
@ ModulePartitionImplementation
This is a C++20 module partition implementation.
Definition: Module.h:134
@ PrivateModuleFragment
This is the private module fragment within some C++ module.
Definition: Module.h:141
@ ExplicitGlobalModuleFragment
This is the explicit Global Module Fragment of a modular TU.
Definition: Module.h:138
This represents a decl that may have a name.
Definition: Decl.h:249
ExplicitVisibilityKind
Kinds of explicit visibility.
Definition: Decl.h:427
@ VisibilityForValue
Do an LV computation for, ultimately, a non-type declaration.
Definition: Decl.h:436
@ VisibilityForType
Do an LV computation for, ultimately, a type.
Definition: Decl.h:431
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1169
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
Definition: Decl.cpp:1220
bool isLinkageValid() const
True if the computed linkage is valid.
Definition: Decl.cpp:1072
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
bool isPlaceholderVar(const LangOptions &LangOpts) const
Definition: Decl.cpp:1082
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
Definition: Decl.h:404
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:315
std::string getQualifiedNameAsString() const
Definition: Decl.cpp:1683
std::optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition: Decl.cpp:1304
NamedDecl * getMostRecentDecl()
Definition: Decl.h:476
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:1826
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:1850
ObjCStringFormatFamily getObjCFStringFormattingFamily() const
Definition: Decl.cpp:1156
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
Definition: Decl.cpp:1200
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
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:1959
bool hasLinkage() const
Determine whether this declaration has linkage.
Definition: Decl.cpp:1927
ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const
Determine if the declaration obeys the reserved identifier rules of the given language.
Definition: Decl.cpp:1119
bool isCXXClassMember() const
Determine whether this declaration is a C++ class member.
Definition: Decl.h:372
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
A C++ nested-name-specifier augmented with source location information.
bool containsType(SanitizerMask Mask, StringRef MangledTypeName, StringRef Category=StringRef()) const
bool containsLocation(SanitizerMask Mask, SourceLocation Loc, StringRef Category=StringRef()) const
void AddEnumDecl(const EnumDecl *Enum)
Definition: ODRHash.cpp:740
void AddFunctionDecl(const FunctionDecl *Function, bool SkipBody=false)
Definition: ODRHash.cpp:653
void AddRecordDecl(const RecordDecl *Record)
Definition: ODRHash.cpp:608
unsigned CalculateHash()
Definition: ODRHash.cpp:218
Represents a parameter to a function.
Definition: Decl.h:1749
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:2980
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1878
SourceRange getDefaultArgRange() const
Retrieve the source range that covers the entire default argument.
Definition: Decl.cpp:2985
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:3005
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1882
bool isDestroyedInCallee() const
Determines whether this parameter is destroyed in the callee function.
Definition: Decl.cpp:2953
bool hasInheritedDefaultArg() const
Definition: Decl.h:1894
bool isExplicitObjectParameter() const
Definition: Decl.h:1837
QualType getOriginalType() const
Definition: Decl.cpp:2924
Expr * getDefaultArg()
Definition: Decl.cpp:2968
static ParmVarDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:2932
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2915
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:3010
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition: Decl.cpp:3016
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:2938
Represents a #pragma comment line.
Definition: Decl.h:142
static PragmaCommentDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation CommentLoc, PragmaMSCommentKind CommentKind, StringRef Arg)
Definition: Decl.cpp:5244
static PragmaCommentDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned ArgSize)
Definition: Decl.cpp:5257
Represents a #pragma detect_mismatch line.
Definition: Decl.h:176
static PragmaDetectMismatchDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation Loc, StringRef Name, StringRef Value)
Definition: Decl.cpp:5267
static PragmaDetectMismatchDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NameValueSize)
Definition: Decl.cpp:5283
void print(raw_ostream &OS) const override
Definition: Decl.cpp:81
A (possibly-)qualified type.
Definition: Type.h:737
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:804
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6902
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition: Type.h:1323
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
Definition: Type.h:6948
Represents a struct/union/class.
Definition: Decl.h:4133
bool hasLoadedFieldsFromExternalStorage() const
Definition: Decl.h:4202
unsigned getODRHash()
Get precomputed ODRHash or add a new one.
Definition: Decl.cpp:5168
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition: Decl.cpp:5006
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:5068
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:4189
static RecordDecl * CreateDeserialized(const ASTContext &C, unsigned ID)
Definition: Decl.cpp:4993
const FieldDecl * findFirstNamedDataMember() const
Finds the first data member which has a name.
Definition: Decl.cpp:5153
void setArgPassingRestrictions(RecordArgPassingKind Kind)
Definition: Decl.h:4271
void setNonTrivialToPrimitiveCopy(bool V)
Definition: Decl.h:4223
bool isCapturedRecord() const
Determine whether this record is a record for captured variables in CapturedStmt construct.
Definition: Decl.cpp:5012
void setHasNonTrivialToPrimitiveCopyCUnion(bool V)
Definition: Decl.h:4255
field_range fields() const
Definition: Decl.h:4339
void setHasNonTrivialToPrimitiveDestructCUnion(bool V)
Definition: Decl.h:4247
void setHasFlexibleArrayMember(bool V)
Definition: Decl.h:4170
void setParamDestroyedInCallee(bool V)
Definition: Decl.h:4279
void setNonTrivialToPrimitiveDestroy(bool V)
Definition: Decl.h:4231
void setHasObjectMember(bool val)
Definition: Decl.h:4194
static RecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl=nullptr)
Definition: Decl.cpp:4982
bool isInjectedClassName() const
Determines whether this declaration represents the injected class name.
Definition: Decl.cpp:5001
void setHasVolatileMember(bool val)
Definition: Decl.h:4198
void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V)
Definition: Decl.h:4239
void reorderDecls(const SmallVectorImpl< Decl * > &Decls)
Definition: Decl.cpp:5072
void setIsRandomized(bool V)
Definition: Decl.h:4285
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
Definition: Decl.cpp:5109
static bool classof(const Decl *D)
Definition: Decl.h:4354
bool isOrContainsUnion() const
Returns whether this record is a union, or contains (at any nesting level) a union member.
Definition: Decl.cpp:5020
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:5047
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4324
void setCapturedRecord()
Mark the record as a record for captured variables in CapturedStmt construct.
Definition: Decl.cpp:5016
specific_decl_iterator< FieldDecl > field_iterator
Definition: Decl.h:4336
void setNonTrivialToPrimitiveDefaultInitialize(bool V)
Definition: Decl.h:4215
void setHasLoadedFieldsFromExternalStorage(bool val) const
Definition: Decl.h:4206
field_iterator field_begin() const
Definition: Decl.cpp:5035
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5092
RecordDecl * getDecl() const
Definition: Type.h:5102
Declaration of a redeclarable template.
Definition: DeclTemplate.h:717
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Definition: DeclTemplate.h:861
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:84
VarDecl * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:216
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:204
VarDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:226
void setPreviousDecl(FunctionDecl *PrevDecl)
Set the previous declaration.
Definition: Decl.h:4959
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: Redeclarable.h:296
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
void print(raw_ostream &OS, const SourceManager &SM) const
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
bool isInvalid() const
SourceLocation getEnd() const
SourceLocation getBegin() const
bool isValid() const
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:350
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:326
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1773
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3549
void setTagKind(TagKind TK)
Definition: Decl.h:3748
void setCompleteDefinitionRequired(bool V=true)
True if this complete decl is required to be complete for some existing use.
Definition: Decl.h:3667
SourceRange getBraceRange() const
Definition: Decl.h:3628
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition: Decl.cpp:4727
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:3682
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3652
void setMayHaveOutOfDateDef(bool V=true)
Indicates whether it is possible for declarations of this kind to have an out-of-date definition.
Definition: Decl.h:3610
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3777
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4704
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:4693
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:4695
bool mayHaveOutOfDateDef() const
Indicates whether it is possible for declarations of this kind to have an out-of-date definition.
Definition: Decl.h:3698
SourceLocation getOuterLocStart() const
Return SourceLocation representing start of source range taking into account any outer template decla...
Definition: Decl.cpp:4683
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4687
bool isUnion() const
Definition: Decl.h:3755
void setBeingDefined(bool V=true)
True if this decl is currently being defined.
Definition: Decl.h:3604
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:4750
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition: Decl.cpp:4787
void completeDefinition()
Completes the definition of this tag declaration.
Definition: Decl.cpp:4715
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition: Decl.cpp:4770
void setFreeStanding(bool isFreeStanding=true)
True if this tag is free standing, e.g. "struct foo;".
Definition: Decl.h:3690
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition: Decl.h:3703
TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl, SourceLocation StartL)
Definition: Decl.cpp:4666
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition: Decl.h:3655
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:136
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1220
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1291
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
A template argument list.
Definition: DeclTemplate.h:244
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:274
Represents a template argument.
Definition: TemplateBase.h:61
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:394
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:413
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
A declaration that models statements at global scope.
Definition: Decl.h:4422
static TopLevelStmtDecl * Create(ASTContext &C, Stmt *Statement)
Definition: Decl.cpp:5557
static TopLevelStmtDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5567
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5573
void setStmt(Stmt *S)
Definition: Decl.cpp:5577
The top declaration context.
Definition: Decl.h:84
static TranslationUnitDecl * Create(ASTContext &C)
Definition: Decl.cpp:5238
ASTContext & getASTContext() const
Definition: Decl.h:120
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3521
static TypeAliasDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5519
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5533
static TypeAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.cpp:5512
Represents a declaration of a type.
Definition: Decl.h:3357
const Type * getTypeForDecl() const
Definition: Decl.h:3381
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:3384
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:89
TypeLoc IgnoreParens() const
Definition: TypeLoc.h:1199
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:153
SourceLocation getEndLoc() const
Get the end source location.
Definition: TypeLoc.cpp:235
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:192
A container of type source information.
Definition: Type.h:6873
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6884
The base class of the type hierarchy.
Definition: Type.h:1606
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1819
bool isLinkageValid() const
True if the computed linkage is valid.
Definition: Type.cpp:4493
bool isNothrowT() const
Definition: Type.cpp:2998
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7724
bool isReferenceType() const
Definition: Type.h:7166
bool isEnumeralType() const
Definition: Type.h:7248
bool isAlignValT() const
Definition: Type.cpp:3007
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:651
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2420
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.cpp:1948
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Definition: Type.h:7573
bool isFunctionType() const
Definition: Type.h:7150
Linkage getLinkage() const
Determine the linkage of this type.
Definition: Type.cpp:4406
TypeClass getTypeClass() const
Definition: Type.h:2074
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7657
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3501
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5524
static TypedefDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.cpp:5462
static TypedefDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:5507
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3399
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:3449
QualType getUnderlyingType() const
Definition: Decl.h:3454
TypedefNameDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this typedef-name.
Definition: Decl.h:3471
TagDecl * getAnonDeclWithTypedefName(bool AnyRedecl=false) const
Retrieves the tag declaration for which this is the typedef name for linkage purposes,...
Definition: Decl.cpp:5470
A set of unresolved declarations.
Definition: UnresolvedSet.h:61
unsigned size() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:706
QualType getType() const
Definition: Decl.h:717
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Definition: Decl.cpp:5324
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition: Decl.cpp:5330
Represents a variable declaration or definition.
Definition: Decl.h:918
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition: Decl.cpp:2787
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
Definition: Decl.cpp:2148
Stmt ** getInitAddress()
Retrieve the address of the initializer expression.
Definition: Decl.cpp:2416
DefinitionKind isThisDeclarationADefinition() const
Definition: Decl.h:1292
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1546
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition: Decl.cpp:2904
TLSKind getTLSKind() const
Definition: Decl.cpp:2165
@ DAK_Unparsed
Definition: Decl.h:994
@ DAK_Normal
Definition: Decl.h:996
@ DAK_Uninstantiated
Definition: Decl.h:995
bool hasInit() const
Definition: Decl.cpp:2395
bool hasICEInitializer(const ASTContext &Context) const
Determine whether the initializer of this variable is an integer constant expression.
Definition: Decl.cpp:2612
ParmVarDeclBitfields ParmVarDeclBits
Definition: Decl.h:1108
DefinitionKind hasDefinition() const
Definition: Decl.h:1298
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition: Decl.cpp:2118
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:2187
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:2438
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:2254
bool hasFlexibleArrayInit(const ASTContext &Ctx) const
Whether this variable has a flexible array member initialized with one or more elements.
Definition: Decl.cpp:2831
bool isNoDestroy(const ASTContext &) const
Is destruction of this variable entirely suppressed? If so, the variable need not have a usable destr...
Definition: Decl.cpp:2813
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition: Decl.h:1555
static VarDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:2154
void setStorageClass(StorageClass SC)
Definition: Decl.cpp:2160
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
Definition: Decl.cpp:2551
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition: Decl.h:1267
VarDecl * getTemplateInstantiationPattern() const
Retrieve the variable declaration from which this variable could be instantiated, if it is an instant...
Definition: Decl.cpp:2691
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
Definition: Decl.h:1210
VarDeclBitfields VarDeclBits
Definition: Decl.h:1107
CharUnits getFlexibleArrayInitChars(const ASTContext &Ctx) const
If hasFlexibleArrayInit is true, compute the number of additional bytes necessary to store those elem...
Definition: Decl.cpp:2846
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
Definition: Decl.cpp:2624
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
Definition: Decl.cpp:2238
unsigned AllBits
Definition: Decl.h:1106
EvaluatedStmt * getEvaluatedStmt() const
Definition: Decl.cpp:2547
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:2463
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition: Decl.cpp:2533
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition: Decl.cpp:2749
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition: Decl.h:1326
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:2876
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
Definition: Decl.cpp:2820
bool checkForConstantInitialization(SmallVectorImpl< PartialDiagnosticAt > &Notes) const
Evaluate the initializer of this variable to determine whether it's a constant initializer.
Definition: Decl.cpp:2637
bool isInline() const
Whether this variable is (C++1z) inline.
Definition: Decl.h:1528
const Expr * getInit() const
Definition: Decl.h:1352
bool isNonEscapingByref() const
Indicates the capture is a __block variable that is never captured by an escaping block.
Definition: Decl.cpp:2679
bool isInExternCContext() const
Determines whether this variable's context is, or is nested within, a C++ extern "C" linkage spec.
Definition: Decl.cpp:2246
NonParmVarDeclBitfields NonParmVarDeclBits
Definition: Decl.h:1109
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
Definition: Decl.h:1201
InitType Init
The initializer for this variable or, for a ParmVarDecl, the C++ default argument.
Definition: Decl.h:964
APValue * getEvaluatedValue() const
Return the already-evaluated value of this variable's initializer, or NULL if the value is not yet kn...
Definition: Decl.cpp:2604
VarDecl * getInitializingDeclaration()
Get the initializing declaration of this variable, if any.
Definition: Decl.cpp:2423
TLSKind
Kinds of thread-local storage.
Definition: Decl.h:936
@ TLS_Static
TLS with a known-constant initializer.
Definition: Decl.h:941
@ TLS_Dynamic
TLS with a dynamic initializer.
Definition: Decl.h:944
@ TLS_None
Not a TLS variable.
Definition: Decl.h:938
void setInit(Expr *I)
Definition: Decl.cpp:2454
VarDecl * getActingDefinition()
Get the tentative definition that acts as the real definition in a TU.
Definition: Decl.cpp:2342
@ TentativeDefinition
This declaration is a tentative definition.
Definition: Decl.h:1282
@ DeclarationOnly
This declaration is only a declaration.
Definition: Decl.h:1279
@ Definition
This declaration is definitely a definition.
Definition: Decl.h:1285
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2792
bool isExternC() const
Determines whether this variable is a variable with external, C linkage.
Definition: Decl.cpp:2242
VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass SC)
Definition: Decl.cpp:2131
StorageDuration getStorageDuration() const
Get the storage duration of this variable, per C++ [basic.stc].
Definition: Decl.h:1213
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1152
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
Definition: Decl.cpp:2675
bool isThisDeclarationADemotedDefinition() const
If this definition should pretend to be a declaration.
Definition: Decl.h:1453
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:2505
bool isInExternCXXContext() const
Determines whether this variable's context is, or is nested within, a C++ extern "C++" linkage spec.
Definition: Decl.cpp:2250
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:2777
bool hasDependentAlignment() const
Determines if this variable's alignment is dependent.
Definition: Decl.cpp:2683
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Get the template specialization kind of this variable for the purposes of template instantiation.
Definition: Decl.cpp:2767
VarDecl * getDefinition()
Definition: Decl.h:1314
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:2756
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition: Decl.h:1342
bool isKnownToBeDefined() const
Definition: Decl.cpp:2796
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
Definition: Decl.cpp:2663
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition: Decl.cpp:2867
Declaration of a variable template.
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
Represents a variable template specialization, which refers to a variable template with a given set o...
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3290
Defines the Linkage enumeration and various utility functions.
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
@ OO_None
Not an overloaded operator.
Definition: OperatorKinds.h:22
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:209
ObjCStringFormatFamily
@ CPlusPlus
Definition: LangStandard.h:54
@ GVA_StrongODR
Definition: Linkage.h:77
@ GVA_StrongExternal
Definition: Linkage.h:76
@ GVA_AvailableExternally
Definition: Linkage.h:74
@ GVA_DiscardableODR
Definition: Linkage.h:75
@ GVA_Internal
Definition: Linkage.h:73
bool isReservedInAllContexts(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved in all contexts.
PragmaMSCommentKind
Definition: PragmaKinds.h:14
@ PCK_Unknown
Definition: PragmaKinds.h:15
ConstexprSpecKind
Define the kind of constexpr specifier.
Definition: Specifiers.h:35
Decl * getPrimaryMergedDecl(Decl *D)
Get the primary declaration for a declaration from an AST file.
Definition: Decl.cpp:77
InClassInitStyle
In-class initialization styles for non-static data members.
Definition: Specifiers.h:268
@ ICIS_NoInit
No in-class initializer.
Definition: Specifiers.h:269
LazyOffsetPtr< Stmt, uint64_t, &ExternalASTSource::GetExternalDeclStmt > LazyDeclStmtPtr
A lazy pointer to a statement.
Linkage getFormalLinkage(Linkage L)
Definition: Linkage.h:106
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have.
Definition: Linkage.h:63
@ CLanguageLinkage
Definition: Linkage.h:64
@ CXXLanguageLinkage
Definition: Linkage.h:65
@ NoLanguageLinkage
Definition: Linkage.h:66
StorageClass
Storage classes.
Definition: Specifiers.h:245
@ SC_Auto
Definition: Specifiers.h:253
@ SC_PrivateExtern
Definition: Specifiers.h:250
@ SC_Extern
Definition: Specifiers.h:248
@ SC_Register
Definition: Specifiers.h:254
@ SC_Static
Definition: Specifiers.h:249
@ SC_None
Definition: Specifiers.h:247
@ TSCS_thread_local
C++11 thread_local.
Definition: Specifiers.h:238
@ TSCS_unspecified
Definition: Specifiers.h:233
@ TSCS__Thread_local
C11 _Thread_local.
Definition: Specifiers.h:241
@ TSCS___thread
GNU __thread.
Definition: Specifiers.h:235
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:24
@ VisibleNone
No linkage according to the standard, but is visible from other translation units because of types de...
@ None
No linkage, which means that the entity is unique and can only be referred to from within its scope.
@ UniqueExternal
External linkage within a unique namespace.
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
@ External
External linkage, which indicates that the entity can be referred to from other translation units.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
@ SD_Automatic
Automatic storage duration (most local variables).
Definition: Specifiers.h:325
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition: ASTLambda.h:27
@ Result
The result type of a method or function.
TagTypeKind
The kind of a tag type.
Definition: Type.h:5842
@ Struct
The "struct" keyword.
@ Enum
The "enum" keyword.
@ CanPassInRegs
The argument of this type can be passed directly in registers.
bool isLegalForVariable(StorageClass SC)
Checks whether the given storage class is legal for variables.
Definition: Specifiers.h:263
MultiVersionKind
Definition: Decl.h:1938
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy, const TemplateParameterList *TPL=nullptr)
Print a template argument list, including the '<' and '>' enclosing the template arguments.
bool isReservedAtGlobalScope(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved for use as a name at global scope.
bool isExternalFormalLinkage(Linkage L)
Definition: Linkage.h:117
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:185
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:203
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:199
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
Definition: Specifiers.h:195
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:191
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
Definition: Specifiers.h:188
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
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:1685
@ Other
Other implicit parameter.
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:34
@ HiddenVisibility
Objects with "hidden" visibility are not seen by the dynamic linker.
Definition: Visibility.h:37
@ ProtectedVisibility
Objects with "protected" visibility are seen by the dynamic linker but always dynamically resolve to ...
Definition: Visibility.h:42
@ DefaultVisibility
Objects with "default" visibility are seen by the dynamic linker and act like normal objects.
Definition: Visibility.h:46
bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD)
Definition: ASTLambda.h:53
#define true
Definition: stdbool.h:21
#define false
Definition: stdbool.h:22
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:676
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:101
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getBeginLoc() const
getBeginLoc - Retrieve the location of the first token.
Structure used to store a statement, the constant value to which it was evaluated (if any),...
Definition: Decl.h:883
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition: Decl.h:901
bool WasEvaluated
Whether this statement was already evaluated.
Definition: Decl.h:885
bool CheckedForICEInit
Definition: Decl.h:906
LazyDeclStmtPtr Value
Definition: Decl.h:908
APValue Evaluated
Definition: Decl.h:909
bool IsEvaluating
Whether this statement is being evaluated.
Definition: Decl.h:888
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition: Decl.h:894
bool HasICEInit
In C++98, whether the initializer is an ICE.
Definition: Decl.h:905
Kinds of LV computation.
Definition: Linkage.h:29
bool isTypeVisibility() const
Definition: Linkage.h:53
unsigned IgnoreExplicitVisibility
Whether explicit visibility attributes should be ignored.
Definition: Linkage.h:37
unsigned IgnoreAllVisibility
Whether all visibility should be ignored.
Definition: Linkage.h:41
static LVComputationKind forLinkageOnly()
Do an LV computation when we only care about the linkage.
Definition: Linkage.h:61
bool isValueVisibility() const
Definition: Linkage.h:56
bool isOffset() const
Whether this pointer is currently stored as an offset.
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer points to.
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
A struct with extended info about a syntactic name qualifier, to be used for the case of out-of-line ...
Definition: Decl.h:743
TemplateParameterList ** TemplParamLists
A new-allocated array of size NumTemplParamLists, containing pointers to the "outer" template paramet...
Definition: Decl.h:757
NestedNameSpecifierLoc QualifierLoc
Definition: Decl.h:744
unsigned NumTemplParamLists
The number of "outer" template parameter lists.
Definition: Decl.h:750
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Sets info about "outer" template parameter lists.
Definition: Decl.cpp:2098
SanitizerMask Mask
Bitmask of enabled sanitizers.
Definition: Sanitizers.h:182