clang  8.0.0
Decl.cpp
Go to the documentation of this file.
1 //===- Decl.cpp - Declaration AST Node Implementation ---------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Decl subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/Decl.h"
15 #include "Linkage.h"
16 #include "clang/AST/ASTContext.h"
18 #include "clang/AST/ASTLambda.h"
21 #include "clang/AST/DeclBase.h"
22 #include "clang/AST/DeclCXX.h"
23 #include "clang/AST/DeclObjC.h"
24 #include "clang/AST/DeclOpenMP.h"
25 #include "clang/AST/DeclTemplate.h"
27 #include "clang/AST/Expr.h"
28 #include "clang/AST/ExprCXX.h"
30 #include "clang/AST/ODRHash.h"
33 #include "clang/AST/Redeclarable.h"
34 #include "clang/AST/Stmt.h"
35 #include "clang/AST/TemplateBase.h"
36 #include "clang/AST/Type.h"
37 #include "clang/AST/TypeLoc.h"
38 #include "clang/Basic/Builtins.h"
40 #include "clang/Basic/LLVM.h"
42 #include "clang/Basic/Linkage.h"
43 #include "clang/Basic/Module.h"
46 #include "clang/Basic/Sanitizers.h"
49 #include "clang/Basic/Specifiers.h"
51 #include "clang/Basic/TargetInfo.h"
52 #include "clang/Basic/Visibility.h"
53 #include "llvm/ADT/APSInt.h"
54 #include "llvm/ADT/ArrayRef.h"
55 #include "llvm/ADT/None.h"
56 #include "llvm/ADT/Optional.h"
57 #include "llvm/ADT/STLExtras.h"
58 #include "llvm/ADT/SmallVector.h"
59 #include "llvm/ADT/StringSwitch.h"
60 #include "llvm/ADT/StringRef.h"
61 #include "llvm/ADT/Triple.h"
62 #include "llvm/Support/Casting.h"
63 #include "llvm/Support/ErrorHandling.h"
64 #include "llvm/Support/raw_ostream.h"
65 #include <algorithm>
66 #include <cassert>
67 #include <cstddef>
68 #include <cstring>
69 #include <memory>
70 #include <string>
71 #include <tuple>
72 #include <type_traits>
73 
74 using namespace clang;
75 
77  return D->getASTContext().getPrimaryMergedDecl(D);
78 }
79 
80 void PrettyDeclStackTraceEntry::print(raw_ostream &OS) const {
81  SourceLocation Loc = this->Loc;
82  if (!Loc.isValid() && TheDecl) Loc = TheDecl->getLocation();
83  if (Loc.isValid()) {
84  Loc.print(OS, Context.getSourceManager());
85  OS << ": ";
86  }
87  OS << Message;
88 
89  if (auto *ND = dyn_cast_or_null<NamedDecl>(TheDecl)) {
90  OS << " '";
91  ND->getNameForDiagnostic(OS, Context.getPrintingPolicy(), true);
92  OS << "'";
93  }
94 
95  OS << '\n';
96 }
97 
98 // Defined here so that it can be inlined into its direct callers.
99 bool Decl::isOutOfLine() const {
100  return !getLexicalDeclContext()->Equals(getDeclContext());
101 }
102 
103 TranslationUnitDecl::TranslationUnitDecl(ASTContext &ctx)
104  : Decl(TranslationUnit, nullptr, SourceLocation()),
105  DeclContext(TranslationUnit), Ctx(ctx) {}
106 
107 //===----------------------------------------------------------------------===//
108 // NamedDecl Implementation
109 //===----------------------------------------------------------------------===//
110 
111 // Visibility rules aren't rigorously externally specified, but here
112 // are the basic principles behind what we implement:
113 //
114 // 1. An explicit visibility attribute is generally a direct expression
115 // of the user's intent and should be honored. Only the innermost
116 // visibility attribute applies. If no visibility attribute applies,
117 // global visibility settings are considered.
118 //
119 // 2. There is one caveat to the above: on or in a template pattern,
120 // an explicit visibility attribute is just a default rule, and
121 // visibility can be decreased by the visibility of template
122 // arguments. But this, too, has an exception: an attribute on an
123 // explicit specialization or instantiation causes all the visibility
124 // restrictions of the template arguments to be ignored.
125 //
126 // 3. A variable that does not otherwise have explicit visibility can
127 // be restricted by the visibility of its type.
128 //
129 // 4. A visibility restriction is explicit if it comes from an
130 // attribute (or something like it), not a global visibility setting.
131 // When emitting a reference to an external symbol, visibility
132 // restrictions are ignored unless they are explicit.
133 //
134 // 5. When computing the visibility of a non-type, including a
135 // non-type member of a class, only non-type visibility restrictions
136 // are considered: the 'visibility' attribute, global value-visibility
137 // settings, and a few special cases like __private_extern.
138 //
139 // 6. When computing the visibility of a type, including a type member
140 // of a class, only type visibility restrictions are considered:
141 // the 'type_visibility' attribute and global type-visibility settings.
142 // However, a 'visibility' attribute counts as a 'type_visibility'
143 // attribute on any declaration that only has the former.
144 //
145 // The visibility of a "secondary" entity, like a template argument,
146 // is computed using the kind of that entity, not the kind of the
147 // primary entity for which we are computing visibility. For example,
148 // the visibility of a specialization of either of these templates:
149 // template <class T, bool (&compare)(T, X)> bool has_match(list<T>, X);
150 // template <class T, bool (&compare)(T, X)> class matcher;
151 // is restricted according to the type visibility of the argument 'T',
152 // the type visibility of 'bool(&)(T,X)', and the value visibility of
153 // the argument function 'compare'. That 'has_match' is a value
154 // and 'matcher' is a type only matters when looking for attributes
155 // and settings from the immediate context.
156 
157 /// Does this computation kind permit us to consider additional
158 /// visibility settings from attributes and the like?
160  return computation.IgnoreExplicitVisibility;
161 }
162 
163 /// Given an LVComputationKind, return one of the same type/value sort
164 /// that records that it already has explicit visibility.
165 static LVComputationKind
167  Kind.IgnoreExplicitVisibility = true;
168  return Kind;
169 }
170 
173  assert(!kind.IgnoreExplicitVisibility &&
174  "asking for explicit visibility when we shouldn't be");
176 }
177 
178 /// Is the given declaration a "type" or a "value" for the purposes of
179 /// visibility computation?
180 static bool usesTypeVisibility(const NamedDecl *D) {
181  return isa<TypeDecl>(D) ||
182  isa<ClassTemplateDecl>(D) ||
183  isa<ObjCInterfaceDecl>(D);
184 }
185 
186 /// Does the given declaration have member specialization information,
187 /// and if so, is it an explicit specialization?
188 template <class T> static typename
189 std::enable_if<!std::is_base_of<RedeclarableTemplateDecl, T>::value, bool>::type
191  if (const MemberSpecializationInfo *member =
192  D->getMemberSpecializationInfo()) {
193  return member->isExplicitSpecialization();
194  }
195  return false;
196 }
197 
198 /// For templates, this question is easier: a member template can't be
199 /// explicitly instantiated, so there's a single bit indicating whether
200 /// or not this is an explicit member specialization.
202  return D->isMemberSpecialization();
203 }
204 
205 /// Given a visibility attribute, return the explicit visibility
206 /// associated with it.
207 template <class T>
208 static Visibility getVisibilityFromAttr(const T *attr) {
209  switch (attr->getVisibility()) {
210  case T::Default:
211  return DefaultVisibility;
212  case T::Hidden:
213  return HiddenVisibility;
214  case T::Protected:
215  return ProtectedVisibility;
216  }
217  llvm_unreachable("bad visibility kind");
218 }
219 
220 /// Return the explicit visibility of the given declaration.
223  // If we're ultimately computing the visibility of a type, look for
224  // a 'type_visibility' attribute before looking for 'visibility'.
225  if (kind == NamedDecl::VisibilityForType) {
226  if (const auto *A = D->getAttr<TypeVisibilityAttr>()) {
227  return getVisibilityFromAttr(A);
228  }
229  }
230 
231  // If this declaration has an explicit visibility attribute, use it.
232  if (const auto *A = D->getAttr<VisibilityAttr>()) {
233  return getVisibilityFromAttr(A);
234  }
235 
236  return None;
237 }
238 
239 LinkageInfo LinkageComputer::getLVForType(const Type &T,
240  LVComputationKind computation) {
241  if (computation.IgnoreAllVisibility)
242  return LinkageInfo(T.getLinkage(), DefaultVisibility, true);
243  return getTypeLinkageAndVisibility(&T);
244 }
245 
246 /// Get the most restrictive linkage for the types in the given
247 /// template parameter list. For visibility purposes, template
248 /// parameters are part of the signature of a template.
249 LinkageInfo LinkageComputer::getLVForTemplateParameterList(
250  const TemplateParameterList *Params, LVComputationKind computation) {
251  LinkageInfo LV;
252  for (const NamedDecl *P : *Params) {
253  // Template type parameters are the most common and never
254  // contribute to visibility, pack or not.
255  if (isa<TemplateTypeParmDecl>(P))
256  continue;
257 
258  // Non-type template parameters can be restricted by the value type, e.g.
259  // template <enum X> class A { ... };
260  // We have to be careful here, though, because we can be dealing with
261  // dependent types.
262  if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
263  // Handle the non-pack case first.
264  if (!NTTP->isExpandedParameterPack()) {
265  if (!NTTP->getType()->isDependentType()) {
266  LV.merge(getLVForType(*NTTP->getType(), computation));
267  }
268  continue;
269  }
270 
271  // Look at all the types in an expanded pack.
272  for (unsigned i = 0, n = NTTP->getNumExpansionTypes(); i != n; ++i) {
273  QualType type = NTTP->getExpansionType(i);
274  if (!type->isDependentType())
275  LV.merge(getTypeLinkageAndVisibility(type));
276  }
277  continue;
278  }
279 
280  // Template template parameters can be restricted by their
281  // template parameters, recursively.
282  const auto *TTP = cast<TemplateTemplateParmDecl>(P);
283 
284  // Handle the non-pack case first.
285  if (!TTP->isExpandedParameterPack()) {
286  LV.merge(getLVForTemplateParameterList(TTP->getTemplateParameters(),
287  computation));
288  continue;
289  }
290 
291  // Look at all expansions in an expanded pack.
292  for (unsigned i = 0, n = TTP->getNumExpansionTemplateParameters();
293  i != n; ++i) {
294  LV.merge(getLVForTemplateParameterList(
295  TTP->getExpansionTemplateParameters(i), computation));
296  }
297  }
298 
299  return LV;
300 }
301 
302 static const Decl *getOutermostFuncOrBlockContext(const Decl *D) {
303  const Decl *Ret = nullptr;
304  const DeclContext *DC = D->getDeclContext();
305  while (DC->getDeclKind() != Decl::TranslationUnit) {
306  if (isa<FunctionDecl>(DC) || isa<BlockDecl>(DC))
307  Ret = cast<Decl>(DC);
308  DC = DC->getParent();
309  }
310  return Ret;
311 }
312 
313 /// Get the most restrictive linkage for the types and
314 /// declarations in the given template argument list.
315 ///
316 /// Note that we don't take an LVComputationKind because we always
317 /// want to honor the visibility of template arguments in the same way.
319 LinkageComputer::getLVForTemplateArgumentList(ArrayRef<TemplateArgument> Args,
320  LVComputationKind computation) {
321  LinkageInfo LV;
322 
323  for (const TemplateArgument &Arg : Args) {
324  switch (Arg.getKind()) {
328  continue;
329 
331  LV.merge(getLVForType(*Arg.getAsType(), computation));
332  continue;
333 
335  const NamedDecl *ND = Arg.getAsDecl();
336  assert(!usesTypeVisibility(ND));
337  LV.merge(getLVForDecl(ND, computation));
338  continue;
339  }
340 
342  LV.merge(getTypeLinkageAndVisibility(Arg.getNullPtrType()));
343  continue;
344 
347  if (TemplateDecl *Template =
348  Arg.getAsTemplateOrTemplatePattern().getAsTemplateDecl())
349  LV.merge(getLVForDecl(Template, computation));
350  continue;
351 
353  LV.merge(getLVForTemplateArgumentList(Arg.getPackAsArray(), computation));
354  continue;
355  }
356  llvm_unreachable("bad template argument kind");
357  }
358 
359  return LV;
360 }
361 
363 LinkageComputer::getLVForTemplateArgumentList(const TemplateArgumentList &TArgs,
364  LVComputationKind computation) {
365  return getLVForTemplateArgumentList(TArgs.asArray(), computation);
366 }
367 
369  const FunctionTemplateSpecializationInfo *specInfo) {
370  // Include visibility from the template parameters and arguments
371  // only if this is not an explicit instantiation or specialization
372  // with direct explicit visibility. (Implicit instantiations won't
373  // have a direct attribute.)
375  return true;
376 
377  return !fn->hasAttr<VisibilityAttr>();
378 }
379 
380 /// Merge in template-related linkage and visibility for the given
381 /// function template specialization.
382 ///
383 /// We don't need a computation kind here because we can assume
384 /// LVForValue.
385 ///
386 /// \param[out] LV the computation to use for the parent
387 void LinkageComputer::mergeTemplateLV(
388  LinkageInfo &LV, const FunctionDecl *fn,
389  const FunctionTemplateSpecializationInfo *specInfo,
390  LVComputationKind computation) {
391  bool considerVisibility =
392  shouldConsiderTemplateVisibility(fn, specInfo);
393 
394  // Merge information from the template parameters.
395  FunctionTemplateDecl *temp = specInfo->getTemplate();
396  LinkageInfo tempLV =
397  getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
398  LV.mergeMaybeWithVisibility(tempLV, considerVisibility);
399 
400  // Merge information from the template arguments.
401  const TemplateArgumentList &templateArgs = *specInfo->TemplateArguments;
402  LinkageInfo argsLV = getLVForTemplateArgumentList(templateArgs, computation);
403  LV.mergeMaybeWithVisibility(argsLV, considerVisibility);
404 }
405 
406 /// Does the given declaration have a direct visibility attribute
407 /// that would match the given rules?
409  LVComputationKind computation) {
410  if (computation.IgnoreAllVisibility)
411  return false;
412 
413  return (computation.isTypeVisibility() && D->hasAttr<TypeVisibilityAttr>()) ||
414  D->hasAttr<VisibilityAttr>();
415 }
416 
417 /// Should we consider visibility associated with the template
418 /// arguments and parameters of the given class template specialization?
421  LVComputationKind computation) {
422  // Include visibility from the template parameters and arguments
423  // only if this is not an explicit instantiation or specialization
424  // with direct explicit visibility (and note that implicit
425  // instantiations won't have a direct attribute).
426  //
427  // Furthermore, we want to ignore template parameters and arguments
428  // for an explicit specialization when computing the visibility of a
429  // member thereof with explicit visibility.
430  //
431  // This is a bit complex; let's unpack it.
432  //
433  // An explicit class specialization is an independent, top-level
434  // declaration. As such, if it or any of its members has an
435  // explicit visibility attribute, that must directly express the
436  // user's intent, and we should honor it. The same logic applies to
437  // an explicit instantiation of a member of such a thing.
438 
439  // Fast path: if this is not an explicit instantiation or
440  // specialization, we always want to consider template-related
441  // visibility restrictions.
443  return true;
444 
445  // This is the 'member thereof' check.
446  if (spec->isExplicitSpecialization() &&
447  hasExplicitVisibilityAlready(computation))
448  return false;
449 
450  return !hasDirectVisibilityAttribute(spec, computation);
451 }
452 
453 /// Merge in template-related linkage and visibility for the given
454 /// class template specialization.
455 void LinkageComputer::mergeTemplateLV(
457  LVComputationKind computation) {
458  bool considerVisibility = shouldConsiderTemplateVisibility(spec, computation);
459 
460  // Merge information from the template parameters, but ignore
461  // visibility if we're only considering template arguments.
462 
464  LinkageInfo tempLV =
465  getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
466  LV.mergeMaybeWithVisibility(tempLV,
467  considerVisibility && !hasExplicitVisibilityAlready(computation));
468 
469  // Merge information from the template arguments. We ignore
470  // template-argument visibility if we've got an explicit
471  // instantiation with a visibility attribute.
472  const TemplateArgumentList &templateArgs = spec->getTemplateArgs();
473  LinkageInfo argsLV = getLVForTemplateArgumentList(templateArgs, computation);
474  if (considerVisibility)
475  LV.mergeVisibility(argsLV);
476  LV.mergeExternalVisibility(argsLV);
477 }
478 
479 /// Should we consider visibility associated with the template
480 /// arguments and parameters of the given variable template
481 /// specialization? As usual, follow class template specialization
482 /// logic up to initialization.
484  const VarTemplateSpecializationDecl *spec,
485  LVComputationKind computation) {
486  // Include visibility from the template parameters and arguments
487  // only if this is not an explicit instantiation or specialization
488  // with direct explicit visibility (and note that implicit
489  // instantiations won't have a direct attribute).
491  return true;
492 
493  // An explicit variable specialization is an independent, top-level
494  // declaration. As such, if it has an explicit visibility attribute,
495  // that must directly express the user's intent, and we should honor
496  // it.
497  if (spec->isExplicitSpecialization() &&
498  hasExplicitVisibilityAlready(computation))
499  return false;
500 
501  return !hasDirectVisibilityAttribute(spec, computation);
502 }
503 
504 /// Merge in template-related linkage and visibility for the given
505 /// variable template specialization. As usual, follow class template
506 /// specialization logic up to initialization.
507 void LinkageComputer::mergeTemplateLV(LinkageInfo &LV,
508  const VarTemplateSpecializationDecl *spec,
509  LVComputationKind computation) {
510  bool considerVisibility = shouldConsiderTemplateVisibility(spec, computation);
511 
512  // Merge information from the template parameters, but ignore
513  // visibility if we're only considering template arguments.
514 
515  VarTemplateDecl *temp = spec->getSpecializedTemplate();
516  LinkageInfo tempLV =
517  getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
518  LV.mergeMaybeWithVisibility(tempLV,
519  considerVisibility && !hasExplicitVisibilityAlready(computation));
520 
521  // Merge information from the template arguments. We ignore
522  // template-argument visibility if we've got an explicit
523  // instantiation with a visibility attribute.
524  const TemplateArgumentList &templateArgs = spec->getTemplateArgs();
525  LinkageInfo argsLV = getLVForTemplateArgumentList(templateArgs, computation);
526  if (considerVisibility)
527  LV.mergeVisibility(argsLV);
528  LV.mergeExternalVisibility(argsLV);
529 }
530 
531 static bool useInlineVisibilityHidden(const NamedDecl *D) {
532  // FIXME: we should warn if -fvisibility-inlines-hidden is used with c.
533  const LangOptions &Opts = D->getASTContext().getLangOpts();
534  if (!Opts.CPlusPlus || !Opts.InlineVisibilityHidden)
535  return false;
536 
537  const auto *FD = dyn_cast<FunctionDecl>(D);
538  if (!FD)
539  return false;
540 
543  = FD->getTemplateSpecializationInfo()) {
544  TSK = spec->getTemplateSpecializationKind();
545  } else if (MemberSpecializationInfo *MSI =
546  FD->getMemberSpecializationInfo()) {
547  TSK = MSI->getTemplateSpecializationKind();
548  }
549 
550  const FunctionDecl *Def = nullptr;
551  // InlineVisibilityHidden only applies to definitions, and
552  // isInlined() only gives meaningful answers on definitions
553  // anyway.
554  return TSK != TSK_ExplicitInstantiationDeclaration &&
556  FD->hasBody(Def) && Def->isInlined() && !Def->hasAttr<GNUInlineAttr>();
557 }
558 
559 template <typename T> static bool isFirstInExternCContext(T *D) {
560  const T *First = D->getFirstDecl();
561  return First->isInExternCContext();
562 }
563 
564 static bool isSingleLineLanguageLinkage(const Decl &D) {
565  if (const auto *SD = dyn_cast<LinkageSpecDecl>(D.getDeclContext()))
566  if (!SD->hasBraces())
567  return true;
568  return false;
569 }
570 
572  // FIXME: Handle isModulePrivate.
573  switch (D->getModuleOwnershipKind()) {
576  return false;
579  if (auto *M = D->getOwningModule())
580  return M->Kind == Module::ModuleInterfaceUnit;
581  }
582  llvm_unreachable("unexpected module ownership kind");
583 }
584 
586  // Internal linkage declarations within a module interface unit are modeled
587  // as "module-internal linkage", which means that they have internal linkage
588  // formally but can be indirectly accessed from outside the module via inline
589  // functions and templates defined within the module.
590  if (auto *M = D->getOwningModule())
591  if (M->Kind == Module::ModuleInterfaceUnit)
593 
594  return LinkageInfo::internal();
595 }
596 
598  // C++ Modules TS [basic.link]/6.8:
599  // - A name declared at namespace scope that does not have internal linkage
600  // by the previous rules and that is introduced by a non-exported
601  // declaration has module linkage.
602  if (auto *M = D->getOwningModule())
603  if (M->Kind == Module::ModuleInterfaceUnit)
605  cast<NamedDecl>(D->getCanonicalDecl())))
607 
608  return LinkageInfo::external();
609 }
610 
612 LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
613  LVComputationKind computation,
614  bool IgnoreVarTypeLinkage) {
615  assert(D->getDeclContext()->getRedeclContext()->isFileContext() &&
616  "Not a name having namespace scope");
617  ASTContext &Context = D->getASTContext();
618 
619  // C++ [basic.link]p3:
620  // A name having namespace scope (3.3.6) has internal linkage if it
621  // is the name of
622  // - an object, reference, function or function template that is
623  // explicitly declared static; or,
624  // (This bullet corresponds to C99 6.2.2p3.)
625  if (const auto *Var = dyn_cast<VarDecl>(D)) {
626  // Explicitly declared static.
627  if (Var->getStorageClass() == SC_Static)
628  return getInternalLinkageFor(Var);
629 
630  // - a non-inline, non-volatile object or reference that is explicitly
631  // declared const or constexpr and neither explicitly declared extern
632  // nor previously declared to have external linkage; or (there is no
633  // equivalent in C99)
634  // The C++ modules TS adds "non-exported" to this list.
635  if (Context.getLangOpts().CPlusPlus &&
636  Var->getType().isConstQualified() &&
637  !Var->getType().isVolatileQualified() &&
638  !Var->isInline() &&
640  const VarDecl *PrevVar = Var->getPreviousDecl();
641  if (PrevVar)
642  return getLVForDecl(PrevVar, computation);
643 
644  if (Var->getStorageClass() != SC_Extern &&
645  Var->getStorageClass() != SC_PrivateExtern &&
647  return getInternalLinkageFor(Var);
648  }
649 
650  for (const VarDecl *PrevVar = Var->getPreviousDecl(); PrevVar;
651  PrevVar = PrevVar->getPreviousDecl()) {
652  if (PrevVar->getStorageClass() == SC_PrivateExtern &&
653  Var->getStorageClass() == SC_None)
654  return getDeclLinkageAndVisibility(PrevVar);
655  // Explicitly declared static.
656  if (PrevVar->getStorageClass() == SC_Static)
657  return getInternalLinkageFor(Var);
658  }
659  } else if (const FunctionDecl *Function = D->getAsFunction()) {
660  // C++ [temp]p4:
661  // A non-member function template can have internal linkage; any
662  // other template name shall have external linkage.
663 
664  // Explicitly declared static.
665  if (Function->getCanonicalDecl()->getStorageClass() == SC_Static)
666  return getInternalLinkageFor(Function);
667  } else if (const auto *IFD = dyn_cast<IndirectFieldDecl>(D)) {
668  // - a data member of an anonymous union.
669  const VarDecl *VD = IFD->getVarDecl();
670  assert(VD && "Expected a VarDecl in this IndirectFieldDecl!");
671  return getLVForNamespaceScopeDecl(VD, computation, IgnoreVarTypeLinkage);
672  }
673  assert(!isa<FieldDecl>(D) && "Didn't expect a FieldDecl!");
674 
675  if (D->isInAnonymousNamespace()) {
676  const auto *Var = dyn_cast<VarDecl>(D);
677  const auto *Func = dyn_cast<FunctionDecl>(D);
678  // FIXME: The check for extern "C" here is not justified by the standard
679  // wording, but we retain it from the pre-DR1113 model to avoid breaking
680  // code.
681  //
682  // C++11 [basic.link]p4:
683  // An unnamed namespace or a namespace declared directly or indirectly
684  // within an unnamed namespace has internal linkage.
685  if ((!Var || !isFirstInExternCContext(Var)) &&
686  (!Func || !isFirstInExternCContext(Func)))
687  return getInternalLinkageFor(D);
688  }
689 
690  // Set up the defaults.
691 
692  // C99 6.2.2p5:
693  // If the declaration of an identifier for an object has file
694  // scope and no storage-class specifier, its linkage is
695  // external.
697 
698  if (!hasExplicitVisibilityAlready(computation)) {
699  if (Optional<Visibility> Vis = getExplicitVisibility(D, computation)) {
700  LV.mergeVisibility(*Vis, true);
701  } else {
702  // If we're declared in a namespace with a visibility attribute,
703  // use that namespace's visibility, and it still counts as explicit.
704  for (const DeclContext *DC = D->getDeclContext();
705  !isa<TranslationUnitDecl>(DC);
706  DC = DC->getParent()) {
707  const auto *ND = dyn_cast<NamespaceDecl>(DC);
708  if (!ND) continue;
709  if (Optional<Visibility> Vis = getExplicitVisibility(ND, computation)) {
710  LV.mergeVisibility(*Vis, true);
711  break;
712  }
713  }
714  }
715 
716  // Add in global settings if the above didn't give us direct visibility.
717  if (!LV.isVisibilityExplicit()) {
718  // Use global type/value visibility as appropriate.
719  Visibility globalVisibility =
720  computation.isValueVisibility()
721  ? Context.getLangOpts().getValueVisibilityMode()
722  : Context.getLangOpts().getTypeVisibilityMode();
723  LV.mergeVisibility(globalVisibility, /*explicit*/ false);
724 
725  // If we're paying attention to global visibility, apply
726  // -finline-visibility-hidden if this is an inline method.
728  LV.mergeVisibility(HiddenVisibility, /*visibilityExplicit=*/false);
729  }
730  }
731 
732  // C++ [basic.link]p4:
733 
734  // A name having namespace scope has external linkage if it is the
735  // name of
736  //
737  // - an object or reference, unless it has internal linkage; or
738  if (const auto *Var = dyn_cast<VarDecl>(D)) {
739  // GCC applies the following optimization to variables and static
740  // data members, but not to functions:
741  //
742  // Modify the variable's LV by the LV of its type unless this is
743  // C or extern "C". This follows from [basic.link]p9:
744  // A type without linkage shall not be used as the type of a
745  // variable or function with external linkage unless
746  // - the entity has C language linkage, or
747  // - the entity is declared within an unnamed namespace, or
748  // - the entity is not used or is defined in the same
749  // translation unit.
750  // and [basic.link]p10:
751  // ...the types specified by all declarations referring to a
752  // given variable or function shall be identical...
753  // C does not have an equivalent rule.
754  //
755  // Ignore this if we've got an explicit attribute; the user
756  // probably knows what they're doing.
757  //
758  // Note that we don't want to make the variable non-external
759  // because of this, but unique-external linkage suits us.
760  if (Context.getLangOpts().CPlusPlus && !isFirstInExternCContext(Var) &&
761  !IgnoreVarTypeLinkage) {
762  LinkageInfo TypeLV = getLVForType(*Var->getType(), computation);
763  if (!isExternallyVisible(TypeLV.getLinkage()))
765  if (!LV.isVisibilityExplicit())
766  LV.mergeVisibility(TypeLV);
767  }
768 
769  if (Var->getStorageClass() == SC_PrivateExtern)
771 
772  // Note that Sema::MergeVarDecl already takes care of implementing
773  // C99 6.2.2p4 and propagating the visibility attribute, so we don't have
774  // to do it here.
775 
776  // As per function and class template specializations (below),
777  // consider LV for the template and template arguments. We're at file
778  // scope, so we do not need to worry about nested specializations.
779  if (const auto *spec = dyn_cast<VarTemplateSpecializationDecl>(Var)) {
780  mergeTemplateLV(LV, spec, computation);
781  }
782 
783  // - a function, unless it has internal linkage; or
784  } else if (const auto *Function = dyn_cast<FunctionDecl>(D)) {
785  // In theory, we can modify the function's LV by the LV of its
786  // type unless it has C linkage (see comment above about variables
787  // for justification). In practice, GCC doesn't do this, so it's
788  // just too painful to make work.
789 
790  if (Function->getStorageClass() == SC_PrivateExtern)
792 
793  // Note that Sema::MergeCompatibleFunctionDecls already takes care of
794  // merging storage classes and visibility attributes, so we don't have to
795  // look at previous decls in here.
796 
797  // In C++, then if the type of the function uses a type with
798  // unique-external linkage, it's not legally usable from outside
799  // this translation unit. However, we should use the C linkage
800  // rules instead for extern "C" declarations.
801  if (Context.getLangOpts().CPlusPlus && !isFirstInExternCContext(Function)) {
802  // Only look at the type-as-written. Otherwise, deducing the return type
803  // of a function could change its linkage.
804  QualType TypeAsWritten = Function->getType();
805  if (TypeSourceInfo *TSI = Function->getTypeSourceInfo())
806  TypeAsWritten = TSI->getType();
807  if (!isExternallyVisible(TypeAsWritten->getLinkage()))
809  }
810 
811  // Consider LV from the template and the template arguments.
812  // We're at file scope, so we do not need to worry about nested
813  // specializations.
815  = Function->getTemplateSpecializationInfo()) {
816  mergeTemplateLV(LV, Function, specInfo, computation);
817  }
818 
819  // - a named class (Clause 9), or an unnamed class defined in a
820  // typedef declaration in which the class has the typedef name
821  // for linkage purposes (7.1.3); or
822  // - a named enumeration (7.2), or an unnamed enumeration
823  // defined in a typedef declaration in which the enumeration
824  // has the typedef name for linkage purposes (7.1.3); or
825  } else if (const auto *Tag = dyn_cast<TagDecl>(D)) {
826  // Unnamed tags have no linkage.
827  if (!Tag->hasNameForLinkage())
828  return LinkageInfo::none();
829 
830  // If this is a class template specialization, consider the
831  // linkage of the template and template arguments. We're at file
832  // scope, so we do not need to worry about nested specializations.
833  if (const auto *spec = dyn_cast<ClassTemplateSpecializationDecl>(Tag)) {
834  mergeTemplateLV(LV, spec, computation);
835  }
836 
837  // - an enumerator belonging to an enumeration with external linkage;
838  } else if (isa<EnumConstantDecl>(D)) {
839  LinkageInfo EnumLV = getLVForDecl(cast<NamedDecl>(D->getDeclContext()),
840  computation);
841  if (!isExternalFormalLinkage(EnumLV.getLinkage()))
842  return LinkageInfo::none();
843  LV.merge(EnumLV);
844 
845  // - a template, unless it is a function template that has
846  // internal linkage (Clause 14);
847  } else if (const auto *temp = dyn_cast<TemplateDecl>(D)) {
848  bool considerVisibility = !hasExplicitVisibilityAlready(computation);
849  LinkageInfo tempLV =
850  getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
851  LV.mergeMaybeWithVisibility(tempLV, considerVisibility);
852 
853  // - a namespace (7.3), unless it is declared within an unnamed
854  // namespace.
855  //
856  // We handled names in anonymous namespaces above.
857  } else if (isa<NamespaceDecl>(D)) {
858  return LV;
859 
860  // By extension, we assign external linkage to Objective-C
861  // interfaces.
862  } else if (isa<ObjCInterfaceDecl>(D)) {
863  // fallout
864 
865  } else if (auto *TD = dyn_cast<TypedefNameDecl>(D)) {
866  // A typedef declaration has linkage if it gives a type a name for
867  // linkage purposes.
868  if (!TD->getAnonDeclWithTypedefName(/*AnyRedecl*/true))
869  return LinkageInfo::none();
870 
871  // Everything not covered here has no linkage.
872  } else {
873  return LinkageInfo::none();
874  }
875 
876  // If we ended up with non-externally-visible linkage, visibility should
877  // always be default.
878  if (!isExternallyVisible(LV.getLinkage()))
879  return LinkageInfo(LV.getLinkage(), DefaultVisibility, false);
880 
881  return LV;
882 }
883 
885 LinkageComputer::getLVForClassMember(const NamedDecl *D,
886  LVComputationKind computation,
887  bool IgnoreVarTypeLinkage) {
888  // Only certain class members have linkage. Note that fields don't
889  // really have linkage, but it's convenient to say they do for the
890  // purposes of calculating linkage of pointer-to-data-member
891  // template arguments.
892  //
893  // Templates also don't officially have linkage, but since we ignore
894  // the C++ standard and look at template arguments when determining
895  // linkage and visibility of a template specialization, we might hit
896  // a template template argument that way. If we do, we need to
897  // consider its linkage.
898  if (!(isa<CXXMethodDecl>(D) ||
899  isa<VarDecl>(D) ||
900  isa<FieldDecl>(D) ||
901  isa<IndirectFieldDecl>(D) ||
902  isa<TagDecl>(D) ||
903  isa<TemplateDecl>(D)))
904  return LinkageInfo::none();
905 
906  LinkageInfo LV;
907 
908  // If we have an explicit visibility attribute, merge that in.
909  if (!hasExplicitVisibilityAlready(computation)) {
910  if (Optional<Visibility> Vis = getExplicitVisibility(D, computation))
911  LV.mergeVisibility(*Vis, true);
912  // If we're paying attention to global visibility, apply
913  // -finline-visibility-hidden if this is an inline method.
914  //
915  // Note that we do this before merging information about
916  // the class visibility.
918  LV.mergeVisibility(HiddenVisibility, /*visibilityExplicit=*/false);
919  }
920 
921  // If this class member has an explicit visibility attribute, the only
922  // thing that can change its visibility is the template arguments, so
923  // only look for them when processing the class.
924  LVComputationKind classComputation = computation;
925  if (LV.isVisibilityExplicit())
926  classComputation = withExplicitVisibilityAlready(computation);
927 
928  LinkageInfo classLV =
929  getLVForDecl(cast<RecordDecl>(D->getDeclContext()), classComputation);
930  // The member has the same linkage as the class. If that's not externally
931  // visible, we don't need to compute anything about the linkage.
932  // FIXME: If we're only computing linkage, can we bail out here?
933  if (!isExternallyVisible(classLV.getLinkage()))
934  return classLV;
935 
936 
937  // Otherwise, don't merge in classLV yet, because in certain cases
938  // we need to completely ignore the visibility from it.
939 
940  // Specifically, if this decl exists and has an explicit attribute.
941  const NamedDecl *explicitSpecSuppressor = nullptr;
942 
943  if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
944  // Only look at the type-as-written. Otherwise, deducing the return type
945  // of a function could change its linkage.
946  QualType TypeAsWritten = MD->getType();
947  if (TypeSourceInfo *TSI = MD->getTypeSourceInfo())
948  TypeAsWritten = TSI->getType();
949  if (!isExternallyVisible(TypeAsWritten->getLinkage()))
951 
952  // If this is a method template specialization, use the linkage for
953  // the template parameters and arguments.
955  = MD->getTemplateSpecializationInfo()) {
956  mergeTemplateLV(LV, MD, spec, computation);
957  if (spec->isExplicitSpecialization()) {
958  explicitSpecSuppressor = MD;
959  } else if (isExplicitMemberSpecialization(spec->getTemplate())) {
960  explicitSpecSuppressor = spec->getTemplate()->getTemplatedDecl();
961  }
962  } else if (isExplicitMemberSpecialization(MD)) {
963  explicitSpecSuppressor = MD;
964  }
965 
966  } else if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
967  if (const auto *spec = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
968  mergeTemplateLV(LV, spec, computation);
969  if (spec->isExplicitSpecialization()) {
970  explicitSpecSuppressor = spec;
971  } else {
972  const ClassTemplateDecl *temp = spec->getSpecializedTemplate();
973  if (isExplicitMemberSpecialization(temp)) {
974  explicitSpecSuppressor = temp->getTemplatedDecl();
975  }
976  }
977  } else if (isExplicitMemberSpecialization(RD)) {
978  explicitSpecSuppressor = RD;
979  }
980 
981  // Static data members.
982  } else if (const auto *VD = dyn_cast<VarDecl>(D)) {
983  if (const auto *spec = dyn_cast<VarTemplateSpecializationDecl>(VD))
984  mergeTemplateLV(LV, spec, computation);
985 
986  // Modify the variable's linkage by its type, but ignore the
987  // type's visibility unless it's a definition.
988  if (!IgnoreVarTypeLinkage) {
989  LinkageInfo typeLV = getLVForType(*VD->getType(), computation);
990  // FIXME: If the type's linkage is not externally visible, we can
991  // give this static data member UniqueExternalLinkage.
992  if (!LV.isVisibilityExplicit() && !classLV.isVisibilityExplicit())
993  LV.mergeVisibility(typeLV);
994  LV.mergeExternalVisibility(typeLV);
995  }
996 
998  explicitSpecSuppressor = VD;
999  }
1000 
1001  // Template members.
1002  } else if (const auto *temp = dyn_cast<TemplateDecl>(D)) {
1003  bool considerVisibility =
1004  (!LV.isVisibilityExplicit() &&
1005  !classLV.isVisibilityExplicit() &&
1006  !hasExplicitVisibilityAlready(computation));
1007  LinkageInfo tempLV =
1008  getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
1009  LV.mergeMaybeWithVisibility(tempLV, considerVisibility);
1010 
1011  if (const auto *redeclTemp = dyn_cast<RedeclarableTemplateDecl>(temp)) {
1012  if (isExplicitMemberSpecialization(redeclTemp)) {
1013  explicitSpecSuppressor = temp->getTemplatedDecl();
1014  }
1015  }
1016  }
1017 
1018  // We should never be looking for an attribute directly on a template.
1019  assert(!explicitSpecSuppressor || !isa<TemplateDecl>(explicitSpecSuppressor));
1020 
1021  // If this member is an explicit member specialization, and it has
1022  // an explicit attribute, ignore visibility from the parent.
1023  bool considerClassVisibility = true;
1024  if (explicitSpecSuppressor &&
1025  // optimization: hasDVA() is true only with explicit visibility.
1026  LV.isVisibilityExplicit() &&
1027  classLV.getVisibility() != DefaultVisibility &&
1028  hasDirectVisibilityAttribute(explicitSpecSuppressor, computation)) {
1029  considerClassVisibility = false;
1030  }
1031 
1032  // Finally, merge in information from the class.
1033  LV.mergeMaybeWithVisibility(classLV, considerClassVisibility);
1034  return LV;
1035 }
1036 
1037 void NamedDecl::anchor() {}
1038 
1040  if (!hasCachedLinkage())
1041  return true;
1042 
1043  Linkage L = LinkageComputer{}
1045  .getLinkage();
1046  return L == getCachedLinkage();
1047 }
1048 
1050  StringRef name = getName();
1051  if (name.empty()) return SFF_None;
1052 
1053  if (name.front() == 'C')
1054  if (name == "CFStringCreateWithFormat" ||
1055  name == "CFStringCreateWithFormatAndArguments" ||
1056  name == "CFStringAppendFormat" ||
1057  name == "CFStringAppendFormatAndArguments")
1058  return SFF_CFString;
1059  return SFF_None;
1060 }
1061 
1063  // We don't care about visibility here, so ask for the cheapest
1064  // possible visibility analysis.
1065  return LinkageComputer{}
1067  .getLinkage();
1068 }
1069 
1072 }
1073 
1074 static Optional<Visibility>
1077  bool IsMostRecent) {
1078  assert(!IsMostRecent || ND == ND->getMostRecentDecl());
1079 
1080  // Check the declaration itself first.
1081  if (Optional<Visibility> V = getVisibilityOf(ND, kind))
1082  return V;
1083 
1084  // If this is a member class of a specialization of a class template
1085  // and the corresponding decl has explicit visibility, use that.
1086  if (const auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
1087  CXXRecordDecl *InstantiatedFrom = RD->getInstantiatedFromMemberClass();
1088  if (InstantiatedFrom)
1089  return getVisibilityOf(InstantiatedFrom, kind);
1090  }
1091 
1092  // If there wasn't explicit visibility there, and this is a
1093  // specialization of a class template, check for visibility
1094  // on the pattern.
1095  if (const auto *spec = dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
1096  // Walk all the template decl till this point to see if there are
1097  // explicit visibility attributes.
1098  const auto *TD = spec->getSpecializedTemplate()->getTemplatedDecl();
1099  while (TD != nullptr) {
1100  auto Vis = getVisibilityOf(TD, kind);
1101  if (Vis != None)
1102  return Vis;
1103  TD = TD->getPreviousDecl();
1104  }
1105  return None;
1106  }
1107 
1108  // Use the most recent declaration.
1109  if (!IsMostRecent && !isa<NamespaceDecl>(ND)) {
1110  const NamedDecl *MostRecent = ND->getMostRecentDecl();
1111  if (MostRecent != ND)
1112  return getExplicitVisibilityAux(MostRecent, kind, true);
1113  }
1114 
1115  if (const auto *Var = dyn_cast<VarDecl>(ND)) {
1116  if (Var->isStaticDataMember()) {
1117  VarDecl *InstantiatedFrom = Var->getInstantiatedFromStaticDataMember();
1118  if (InstantiatedFrom)
1119  return getVisibilityOf(InstantiatedFrom, kind);
1120  }
1121 
1122  if (const auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(Var))
1123  return getVisibilityOf(VTSD->getSpecializedTemplate()->getTemplatedDecl(),
1124  kind);
1125 
1126  return None;
1127  }
1128  // Also handle function template specializations.
1129  if (const auto *fn = dyn_cast<FunctionDecl>(ND)) {
1130  // If the function is a specialization of a template with an
1131  // explicit visibility attribute, use that.
1132  if (FunctionTemplateSpecializationInfo *templateInfo
1134  return getVisibilityOf(templateInfo->getTemplate()->getTemplatedDecl(),
1135  kind);
1136 
1137  // If the function is a member of a specialization of a class template
1138  // and the corresponding decl has explicit visibility, use that.
1139  FunctionDecl *InstantiatedFrom = fn->getInstantiatedFromMemberFunction();
1140  if (InstantiatedFrom)
1141  return getVisibilityOf(InstantiatedFrom, kind);
1142 
1143  return None;
1144  }
1145 
1146  // The visibility of a template is stored in the templated decl.
1147  if (const auto *TD = dyn_cast<TemplateDecl>(ND))
1148  return getVisibilityOf(TD->getTemplatedDecl(), kind);
1149 
1150  return None;
1151 }
1152 
1155  return getExplicitVisibilityAux(this, kind, false);
1156 }
1157 
1158 LinkageInfo LinkageComputer::getLVForClosure(const DeclContext *DC,
1159  Decl *ContextDecl,
1160  LVComputationKind computation) {
1161  // This lambda has its linkage/visibility determined by its owner.
1162  const NamedDecl *Owner;
1163  if (!ContextDecl)
1164  Owner = dyn_cast<NamedDecl>(DC);
1165  else if (isa<ParmVarDecl>(ContextDecl))
1166  Owner =
1167  dyn_cast<NamedDecl>(ContextDecl->getDeclContext()->getRedeclContext());
1168  else
1169  Owner = cast<NamedDecl>(ContextDecl);
1170 
1171  if (!Owner)
1172  return LinkageInfo::none();
1173 
1174  // If the owner has a deduced type, we need to skip querying the linkage and
1175  // visibility of that type, because it might involve this closure type. The
1176  // only effect of this is that we might give a lambda VisibleNoLinkage rather
1177  // than NoLinkage when we don't strictly need to, which is benign.
1178  auto *VD = dyn_cast<VarDecl>(Owner);
1179  LinkageInfo OwnerLV =
1180  VD && VD->getType()->getContainedDeducedType()
1181  ? computeLVForDecl(Owner, computation, /*IgnoreVarTypeLinkage*/true)
1182  : getLVForDecl(Owner, computation);
1183 
1184  // A lambda never formally has linkage. But if the owner is externally
1185  // visible, then the lambda is too. We apply the same rules to blocks.
1186  if (!isExternallyVisible(OwnerLV.getLinkage()))
1187  return LinkageInfo::none();
1188  return LinkageInfo(VisibleNoLinkage, OwnerLV.getVisibility(),
1189  OwnerLV.isVisibilityExplicit());
1190 }
1191 
1192 LinkageInfo LinkageComputer::getLVForLocalDecl(const NamedDecl *D,
1193  LVComputationKind computation) {
1194  if (const auto *Function = dyn_cast<FunctionDecl>(D)) {
1195  if (Function->isInAnonymousNamespace() &&
1196  !isFirstInExternCContext(Function))
1197  return getInternalLinkageFor(Function);
1198 
1199  // This is a "void f();" which got merged with a file static.
1200  if (Function->getCanonicalDecl()->getStorageClass() == SC_Static)
1201  return getInternalLinkageFor(Function);
1202 
1203  LinkageInfo LV;
1204  if (!hasExplicitVisibilityAlready(computation)) {
1205  if (Optional<Visibility> Vis =
1206  getExplicitVisibility(Function, computation))
1207  LV.mergeVisibility(*Vis, true);
1208  }
1209 
1210  // Note that Sema::MergeCompatibleFunctionDecls already takes care of
1211  // merging storage classes and visibility attributes, so we don't have to
1212  // look at previous decls in here.
1213 
1214  return LV;
1215  }
1216 
1217  if (const auto *Var = dyn_cast<VarDecl>(D)) {
1218  if (Var->hasExternalStorage()) {
1219  if (Var->isInAnonymousNamespace() && !isFirstInExternCContext(Var))
1220  return getInternalLinkageFor(Var);
1221 
1222  LinkageInfo LV;
1223  if (Var->getStorageClass() == SC_PrivateExtern)
1225  else if (!hasExplicitVisibilityAlready(computation)) {
1226  if (Optional<Visibility> Vis = getExplicitVisibility(Var, computation))
1227  LV.mergeVisibility(*Vis, true);
1228  }
1229 
1230  if (const VarDecl *Prev = Var->getPreviousDecl()) {
1231  LinkageInfo PrevLV = getLVForDecl(Prev, computation);
1232  if (PrevLV.getLinkage())
1233  LV.setLinkage(PrevLV.getLinkage());
1234  LV.mergeVisibility(PrevLV);
1235  }
1236 
1237  return LV;
1238  }
1239 
1240  if (!Var->isStaticLocal())
1241  return LinkageInfo::none();
1242  }
1243 
1244  ASTContext &Context = D->getASTContext();
1245  if (!Context.getLangOpts().CPlusPlus)
1246  return LinkageInfo::none();
1247 
1248  const Decl *OuterD = getOutermostFuncOrBlockContext(D);
1249  if (!OuterD || OuterD->isInvalidDecl())
1250  return LinkageInfo::none();
1251 
1252  LinkageInfo LV;
1253  if (const auto *BD = dyn_cast<BlockDecl>(OuterD)) {
1254  if (!BD->getBlockManglingNumber())
1255  return LinkageInfo::none();
1256 
1257  LV = getLVForClosure(BD->getDeclContext()->getRedeclContext(),
1258  BD->getBlockManglingContextDecl(), computation);
1259  } else {
1260  const auto *FD = cast<FunctionDecl>(OuterD);
1261  if (!FD->isInlined() &&
1262  !isTemplateInstantiation(FD->getTemplateSpecializationKind()))
1263  return LinkageInfo::none();
1264 
1265  // If a function is hidden by -fvisibility-inlines-hidden option and
1266  // is not explicitly attributed as a hidden function,
1267  // we should not make static local variables in the function hidden.
1268  LV = getLVForDecl(FD, computation);
1269  if (isa<VarDecl>(D) && useInlineVisibilityHidden(FD) &&
1270  !LV.isVisibilityExplicit()) {
1271  assert(cast<VarDecl>(D)->isStaticLocal());
1272  // If this was an implicitly hidden inline method, check again for
1273  // explicit visibility on the parent class, and use that for static locals
1274  // if present.
1275  if (const auto *MD = dyn_cast<CXXMethodDecl>(FD))
1276  LV = getLVForDecl(MD->getParent(), computation);
1277  if (!LV.isVisibilityExplicit()) {
1278  Visibility globalVisibility =
1279  computation.isValueVisibility()
1280  ? Context.getLangOpts().getValueVisibilityMode()
1281  : Context.getLangOpts().getTypeVisibilityMode();
1282  return LinkageInfo(VisibleNoLinkage, globalVisibility,
1283  /*visibilityExplicit=*/false);
1284  }
1285  }
1286  }
1287  if (!isExternallyVisible(LV.getLinkage()))
1288  return LinkageInfo::none();
1290  LV.isVisibilityExplicit());
1291 }
1292 
1293 static inline const CXXRecordDecl*
1295  const CXXRecordDecl *Ret = Record;
1296  while (Record && Record->isLambda()) {
1297  Ret = Record;
1298  if (!Record->getParent()) break;
1299  // Get the Containing Class of this Lambda Class
1300  Record = dyn_cast_or_null<CXXRecordDecl>(
1301  Record->getParent()->getParent());
1302  }
1303  return Ret;
1304 }
1305 
1307  LVComputationKind computation,
1308  bool IgnoreVarTypeLinkage) {
1309  // Internal_linkage attribute overrides other considerations.
1310  if (D->hasAttr<InternalLinkageAttr>())
1311  return getInternalLinkageFor(D);
1312 
1313  // Objective-C: treat all Objective-C declarations as having external
1314  // linkage.
1315  switch (D->getKind()) {
1316  default:
1317  break;
1318 
1319  // Per C++ [basic.link]p2, only the names of objects, references,
1320  // functions, types, templates, namespaces, and values ever have linkage.
1321  //
1322  // Note that the name of a typedef, namespace alias, using declaration,
1323  // and so on are not the name of the corresponding type, namespace, or
1324  // declaration, so they do *not* have linkage.
1325  case Decl::ImplicitParam:
1326  case Decl::Label:
1327  case Decl::NamespaceAlias:
1328  case Decl::ParmVar:
1329  case Decl::Using:
1330  case Decl::UsingShadow:
1331  case Decl::UsingDirective:
1332  return LinkageInfo::none();
1333 
1334  case Decl::EnumConstant:
1335  // C++ [basic.link]p4: an enumerator has the linkage of its enumeration.
1336  if (D->getASTContext().getLangOpts().CPlusPlus)
1337  return getLVForDecl(cast<EnumDecl>(D->getDeclContext()), computation);
1338  return LinkageInfo::visible_none();
1339 
1340  case Decl::Typedef:
1341  case Decl::TypeAlias:
1342  // A typedef declaration has linkage if it gives a type a name for
1343  // linkage purposes.
1344  if (!cast<TypedefNameDecl>(D)
1345  ->getAnonDeclWithTypedefName(/*AnyRedecl*/true))
1346  return LinkageInfo::none();
1347  break;
1348 
1349  case Decl::TemplateTemplateParm: // count these as external
1350  case Decl::NonTypeTemplateParm:
1351  case Decl::ObjCAtDefsField:
1352  case Decl::ObjCCategory:
1353  case Decl::ObjCCategoryImpl:
1354  case Decl::ObjCCompatibleAlias:
1355  case Decl::ObjCImplementation:
1356  case Decl::ObjCMethod:
1357  case Decl::ObjCProperty:
1358  case Decl::ObjCPropertyImpl:
1359  case Decl::ObjCProtocol:
1360  return getExternalLinkageFor(D);
1361 
1362  case Decl::CXXRecord: {
1363  const auto *Record = cast<CXXRecordDecl>(D);
1364  if (Record->isLambda()) {
1365  if (!Record->getLambdaManglingNumber()) {
1366  // This lambda has no mangling number, so it's internal.
1367  return getInternalLinkageFor(D);
1368  }
1369 
1370  // This lambda has its linkage/visibility determined:
1371  // - either by the outermost lambda if that lambda has no mangling
1372  // number.
1373  // - or by the parent of the outer most lambda
1374  // This prevents infinite recursion in settings such as nested lambdas
1375  // used in NSDMI's, for e.g.
1376  // struct L {
1377  // int t{};
1378  // int t2 = ([](int a) { return [](int b) { return b; };})(t)(t);
1379  // };
1380  const CXXRecordDecl *OuterMostLambda =
1382  if (!OuterMostLambda->getLambdaManglingNumber())
1383  return getInternalLinkageFor(D);
1384 
1385  return getLVForClosure(
1386  OuterMostLambda->getDeclContext()->getRedeclContext(),
1387  OuterMostLambda->getLambdaContextDecl(), computation);
1388  }
1389 
1390  break;
1391  }
1392  }
1393 
1394  // Handle linkage for namespace-scope names.
1396  return getLVForNamespaceScopeDecl(D, computation, IgnoreVarTypeLinkage);
1397 
1398  // C++ [basic.link]p5:
1399  // In addition, a member function, static data member, a named
1400  // class or enumeration of class scope, or an unnamed class or
1401  // enumeration defined in a class-scope typedef declaration such
1402  // that the class or enumeration has the typedef name for linkage
1403  // purposes (7.1.3), has external linkage if the name of the class
1404  // has external linkage.
1405  if (D->getDeclContext()->isRecord())
1406  return getLVForClassMember(D, computation, IgnoreVarTypeLinkage);
1407 
1408  // C++ [basic.link]p6:
1409  // The name of a function declared in block scope and the name of
1410  // an object declared by a block scope extern declaration have
1411  // linkage. If there is a visible declaration of an entity with
1412  // linkage having the same name and type, ignoring entities
1413  // declared outside the innermost enclosing namespace scope, the
1414  // block scope declaration declares that same entity and receives
1415  // the linkage of the previous declaration. If there is more than
1416  // one such matching entity, the program is ill-formed. Otherwise,
1417  // if no matching entity is found, the block scope entity receives
1418  // external linkage.
1419  if (D->getDeclContext()->isFunctionOrMethod())
1420  return getLVForLocalDecl(D, computation);
1421 
1422  // C++ [basic.link]p6:
1423  // Names not covered by these rules have no linkage.
1424  return LinkageInfo::none();
1425 }
1426 
1427 /// getLVForDecl - Get the linkage and visibility for the given declaration.
1429  LVComputationKind computation) {
1430  // Internal_linkage attribute overrides other considerations.
1431  if (D->hasAttr<InternalLinkageAttr>())
1432  return getInternalLinkageFor(D);
1433 
1434  if (computation.IgnoreAllVisibility && D->hasCachedLinkage())
1435  return LinkageInfo(D->getCachedLinkage(), DefaultVisibility, false);
1436 
1437  if (llvm::Optional<LinkageInfo> LI = lookup(D, computation))
1438  return *LI;
1439 
1440  LinkageInfo LV = computeLVForDecl(D, computation);
1441  if (D->hasCachedLinkage())
1442  assert(D->getCachedLinkage() == LV.getLinkage());
1443 
1444  D->setCachedLinkage(LV.getLinkage());
1445  cache(D, computation, LV);
1446 
1447 #ifndef NDEBUG
1448  // In C (because of gnu inline) and in c++ with microsoft extensions an
1449  // static can follow an extern, so we can have two decls with different
1450  // linkages.
1451  const LangOptions &Opts = D->getASTContext().getLangOpts();
1452  if (!Opts.CPlusPlus || Opts.MicrosoftExt)
1453  return LV;
1454 
1455  // We have just computed the linkage for this decl. By induction we know
1456  // that all other computed linkages match, check that the one we just
1457  // computed also does.
1458  NamedDecl *Old = nullptr;
1459  for (auto I : D->redecls()) {
1460  auto *T = cast<NamedDecl>(I);
1461  if (T == D)
1462  continue;
1463  if (!T->isInvalidDecl() && T->hasCachedLinkage()) {
1464  Old = T;
1465  break;
1466  }
1467  }
1468  assert(!Old || Old->getCachedLinkage() == D->getCachedLinkage());
1469 #endif
1470 
1471  return LV;
1472 }
1473 
1475  return getLVForDecl(D,
1479 }
1480 
1481 Module *Decl::getOwningModuleForLinkage(bool IgnoreLinkage) const {
1482  Module *M = getOwningModule();
1483  if (!M)
1484  return nullptr;
1485 
1486  switch (M->Kind) {
1488  // Module map modules have no special linkage semantics.
1489  return nullptr;
1490 
1492  return M;
1493 
1495  // External linkage declarations in the global module have no owning module
1496  // for linkage purposes. But internal linkage declarations in the global
1497  // module fragment of a particular module are owned by that module for
1498  // linkage purposes.
1499  if (IgnoreLinkage)
1500  return nullptr;
1501  bool InternalLinkage;
1502  if (auto *ND = dyn_cast<NamedDecl>(this))
1503  InternalLinkage = !ND->hasExternalFormalLinkage();
1504  else {
1505  auto *NSD = dyn_cast<NamespaceDecl>(this);
1506  InternalLinkage = (NSD && NSD->isAnonymousNamespace()) ||
1507  isInAnonymousNamespace();
1508  }
1509  return InternalLinkage ? M->Parent : nullptr;
1510  }
1511  }
1512 
1513  llvm_unreachable("unknown module kind");
1514 }
1515 
1516 void NamedDecl::printName(raw_ostream &os) const {
1517  os << Name;
1518 }
1519 
1521  std::string QualName;
1522  llvm::raw_string_ostream OS(QualName);
1523  printQualifiedName(OS, getASTContext().getPrintingPolicy());
1524  return OS.str();
1525 }
1526 
1527 void NamedDecl::printQualifiedName(raw_ostream &OS) const {
1528  printQualifiedName(OS, getASTContext().getPrintingPolicy());
1529 }
1530 
1531 void NamedDecl::printQualifiedName(raw_ostream &OS,
1532  const PrintingPolicy &P) const {
1533  const DeclContext *Ctx = getDeclContext();
1534 
1535  // For ObjC methods, look through categories and use the interface as context.
1536  if (auto *MD = dyn_cast<ObjCMethodDecl>(this))
1537  if (auto *ID = MD->getClassInterface())
1538  Ctx = ID;
1539 
1540  if (Ctx->isFunctionOrMethod()) {
1541  printName(OS);
1542  return;
1543  }
1544 
1545  using ContextsTy = SmallVector<const DeclContext *, 8>;
1546  ContextsTy Contexts;
1547 
1548  // Collect named contexts.
1549  while (Ctx) {
1550  if (isa<NamedDecl>(Ctx))
1551  Contexts.push_back(Ctx);
1552  Ctx = Ctx->getParent();
1553  }
1554 
1555  for (const DeclContext *DC : llvm::reverse(Contexts)) {
1556  if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
1557  OS << Spec->getName();
1558  const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
1559  printTemplateArgumentList(OS, TemplateArgs.asArray(), P);
1560  } else if (const auto *ND = dyn_cast<NamespaceDecl>(DC)) {
1561  if (P.SuppressUnwrittenScope &&
1562  (ND->isAnonymousNamespace() || ND->isInline()))
1563  continue;
1564  if (ND->isAnonymousNamespace()) {
1565  OS << (P.MSVCFormatting ? "`anonymous namespace\'"
1566  : "(anonymous namespace)");
1567  }
1568  else
1569  OS << *ND;
1570  } else if (const auto *RD = dyn_cast<RecordDecl>(DC)) {
1571  if (!RD->getIdentifier())
1572  OS << "(anonymous " << RD->getKindName() << ')';
1573  else
1574  OS << *RD;
1575  } else if (const auto *FD = dyn_cast<FunctionDecl>(DC)) {
1576  const FunctionProtoType *FT = nullptr;
1577  if (FD->hasWrittenPrototype())
1578  FT = dyn_cast<FunctionProtoType>(FD->getType()->castAs<FunctionType>());
1579 
1580  OS << *FD << '(';
1581  if (FT) {
1582  unsigned NumParams = FD->getNumParams();
1583  for (unsigned i = 0; i < NumParams; ++i) {
1584  if (i)
1585  OS << ", ";
1586  OS << FD->getParamDecl(i)->getType().stream(P);
1587  }
1588 
1589  if (FT->isVariadic()) {
1590  if (NumParams > 0)
1591  OS << ", ";
1592  OS << "...";
1593  }
1594  }
1595  OS << ')';
1596  } else if (const auto *ED = dyn_cast<EnumDecl>(DC)) {
1597  // C++ [dcl.enum]p10: Each enum-name and each unscoped
1598  // enumerator is declared in the scope that immediately contains
1599  // the enum-specifier. Each scoped enumerator is declared in the
1600  // scope of the enumeration.
1601  // For the case of unscoped enumerator, do not include in the qualified
1602  // name any information about its enum enclosing scope, as its visibility
1603  // is global.
1604  if (ED->isScoped())
1605  OS << *ED;
1606  else
1607  continue;
1608  } else {
1609  OS << *cast<NamedDecl>(DC);
1610  }
1611  OS << "::";
1612  }
1613 
1614  if (getDeclName() || isa<DecompositionDecl>(this))
1615  OS << *this;
1616  else
1617  OS << "(anonymous)";
1618 }
1619 
1620 void NamedDecl::getNameForDiagnostic(raw_ostream &OS,
1621  const PrintingPolicy &Policy,
1622  bool Qualified) const {
1623  if (Qualified)
1624  printQualifiedName(OS, Policy);
1625  else
1626  printName(OS);
1627 }
1628 
1629 template<typename T> static bool isRedeclarableImpl(Redeclarable<T> *) {
1630  return true;
1631 }
1632 static bool isRedeclarableImpl(...) { return false; }
1633 static bool isRedeclarable(Decl::Kind K) {
1634  switch (K) {
1635 #define DECL(Type, Base) \
1636  case Decl::Type: \
1637  return isRedeclarableImpl((Type##Decl *)nullptr);
1638 #define ABSTRACT_DECL(DECL)
1639 #include "clang/AST/DeclNodes.inc"
1640  }
1641  llvm_unreachable("unknown decl kind");
1642 }
1643 
1644 bool NamedDecl::declarationReplaces(NamedDecl *OldD, bool IsKnownNewer) const {
1645  assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch");
1646 
1647  // Never replace one imported declaration with another; we need both results
1648  // when re-exporting.
1649  if (OldD->isFromASTFile() && isFromASTFile())
1650  return false;
1651 
1652  // A kind mismatch implies that the declaration is not replaced.
1653  if (OldD->getKind() != getKind())
1654  return false;
1655 
1656  // For method declarations, we never replace. (Why?)
1657  if (isa<ObjCMethodDecl>(this))
1658  return false;
1659 
1660  // For parameters, pick the newer one. This is either an error or (in
1661  // Objective-C) permitted as an extension.
1662  if (isa<ParmVarDecl>(this))
1663  return true;
1664 
1665  // Inline namespaces can give us two declarations with the same
1666  // name and kind in the same scope but different contexts; we should
1667  // keep both declarations in this case.
1668  if (!this->getDeclContext()->getRedeclContext()->Equals(
1669  OldD->getDeclContext()->getRedeclContext()))
1670  return false;
1671 
1672  // Using declarations can be replaced if they import the same name from the
1673  // same context.
1674  if (auto *UD = dyn_cast<UsingDecl>(this)) {
1675  ASTContext &Context = getASTContext();
1676  return Context.getCanonicalNestedNameSpecifier(UD->getQualifier()) ==
1678  cast<UsingDecl>(OldD)->getQualifier());
1679  }
1680  if (auto *UUVD = dyn_cast<UnresolvedUsingValueDecl>(this)) {
1681  ASTContext &Context = getASTContext();
1682  return Context.getCanonicalNestedNameSpecifier(UUVD->getQualifier()) ==
1684  cast<UnresolvedUsingValueDecl>(OldD)->getQualifier());
1685  }
1686 
1687  if (isRedeclarable(getKind())) {
1688  if (getCanonicalDecl() != OldD->getCanonicalDecl())
1689  return false;
1690 
1691  if (IsKnownNewer)
1692  return true;
1693 
1694  // Check whether this is actually newer than OldD. We want to keep the
1695  // newer declaration. This loop will usually only iterate once, because
1696  // OldD is usually the previous declaration.
1697  for (auto D : redecls()) {
1698  if (D == OldD)
1699  break;
1700 
1701  // If we reach the canonical declaration, then OldD is not actually older
1702  // than this one.
1703  //
1704  // FIXME: In this case, we should not add this decl to the lookup table.
1705  if (D->isCanonicalDecl())
1706  return false;
1707  }
1708 
1709  // It's a newer declaration of the same kind of declaration in the same
1710  // scope: we want this decl instead of the existing one.
1711  return true;
1712  }
1713 
1714  // In all other cases, we need to keep both declarations in case they have
1715  // different visibility. Any attempt to use the name will result in an
1716  // ambiguity if more than one is visible.
1717  return false;
1718 }
1719 
1721  return getFormalLinkage() != NoLinkage;
1722 }
1723 
1724 NamedDecl *NamedDecl::getUnderlyingDeclImpl() {
1725  NamedDecl *ND = this;
1726  while (auto *UD = dyn_cast<UsingShadowDecl>(ND))
1727  ND = UD->getTargetDecl();
1728 
1729  if (auto *AD = dyn_cast<ObjCCompatibleAliasDecl>(ND))
1730  return AD->getClassInterface();
1731 
1732  if (auto *AD = dyn_cast<NamespaceAliasDecl>(ND))
1733  return AD->getNamespace();
1734 
1735  return ND;
1736 }
1737 
1739  if (!isCXXClassMember())
1740  return false;
1741 
1742  const NamedDecl *D = this;
1743  if (isa<UsingShadowDecl>(D))
1744  D = cast<UsingShadowDecl>(D)->getTargetDecl();
1745 
1746  if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<MSPropertyDecl>(D))
1747  return true;
1748  if (const auto *MD = dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()))
1749  return MD->isInstance();
1750  return false;
1751 }
1752 
1753 //===----------------------------------------------------------------------===//
1754 // DeclaratorDecl Implementation
1755 //===----------------------------------------------------------------------===//
1756 
1757 template <typename DeclT>
1759  if (decl->getNumTemplateParameterLists() > 0)
1760  return decl->getTemplateParameterList(0)->getTemplateLoc();
1761  else
1762  return decl->getInnerLocStart();
1763 }
1764 
1766  TypeSourceInfo *TSI = getTypeSourceInfo();
1767  if (TSI) return TSI->getTypeLoc().getBeginLoc();
1768  return SourceLocation();
1769 }
1770 
1772  if (QualifierLoc) {
1773  // Make sure the extended decl info is allocated.
1774  if (!hasExtInfo()) {
1775  // Save (non-extended) type source info pointer.
1776  auto *savedTInfo = DeclInfo.get<TypeSourceInfo*>();
1777  // Allocate external info struct.
1778  DeclInfo = new (getASTContext()) ExtInfo;
1779  // Restore savedTInfo into (extended) decl info.
1780  getExtInfo()->TInfo = savedTInfo;
1781  }
1782  // Set qualifier info.
1783  getExtInfo()->QualifierLoc = QualifierLoc;
1784  } else {
1785  // Here Qualifier == 0, i.e., we are removing the qualifier (if any).
1786  if (hasExtInfo()) {
1787  if (getExtInfo()->NumTemplParamLists == 0) {
1788  // Save type source info pointer.
1789  TypeSourceInfo *savedTInfo = getExtInfo()->TInfo;
1790  // Deallocate the extended decl info.
1791  getASTContext().Deallocate(getExtInfo());
1792  // Restore savedTInfo into (non-extended) decl info.
1793  DeclInfo = savedTInfo;
1794  }
1795  else
1796  getExtInfo()->QualifierLoc = QualifierLoc;
1797  }
1798  }
1799 }
1800 
1802  ASTContext &Context, ArrayRef<TemplateParameterList *> TPLists) {
1803  assert(!TPLists.empty());
1804  // Make sure the extended decl info is allocated.
1805  if (!hasExtInfo()) {
1806  // Save (non-extended) type source info pointer.
1807  auto *savedTInfo = DeclInfo.get<TypeSourceInfo*>();
1808  // Allocate external info struct.
1809  DeclInfo = new (getASTContext()) ExtInfo;
1810  // Restore savedTInfo into (extended) decl info.
1811  getExtInfo()->TInfo = savedTInfo;
1812  }
1813  // Set the template parameter lists info.
1814  getExtInfo()->setTemplateParameterListsInfo(Context, TPLists);
1815 }
1816 
1818  return getTemplateOrInnerLocStart(this);
1819 }
1820 
1821 // Helper function: returns true if QT is or contains a type
1822 // having a postfix component.
1823 static bool typeIsPostfix(QualType QT) {
1824  while (true) {
1825  const Type* T = QT.getTypePtr();
1826  switch (T->getTypeClass()) {
1827  default:
1828  return false;
1829  case Type::Pointer:
1830  QT = cast<PointerType>(T)->getPointeeType();
1831  break;
1832  case Type::BlockPointer:
1833  QT = cast<BlockPointerType>(T)->getPointeeType();
1834  break;
1835  case Type::MemberPointer:
1836  QT = cast<MemberPointerType>(T)->getPointeeType();
1837  break;
1838  case Type::LValueReference:
1839  case Type::RValueReference:
1840  QT = cast<ReferenceType>(T)->getPointeeType();
1841  break;
1842  case Type::PackExpansion:
1843  QT = cast<PackExpansionType>(T)->getPattern();
1844  break;
1845  case Type::Paren:
1846  case Type::ConstantArray:
1847  case Type::DependentSizedArray:
1848  case Type::IncompleteArray:
1849  case Type::VariableArray:
1850  case Type::FunctionProto:
1851  case Type::FunctionNoProto:
1852  return true;
1853  }
1854  }
1855 }
1856 
1858  SourceLocation RangeEnd = getLocation();
1859  if (TypeSourceInfo *TInfo = getTypeSourceInfo()) {
1860  // If the declaration has no name or the type extends past the name take the
1861  // end location of the type.
1862  if (!getDeclName() || typeIsPostfix(TInfo->getType()))
1863  RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd();
1864  }
1865  return SourceRange(getOuterLocStart(), RangeEnd);
1866 }
1867 
1869  ASTContext &Context, ArrayRef<TemplateParameterList *> TPLists) {
1870  // Free previous template parameters (if any).
1871  if (NumTemplParamLists > 0) {
1872  Context.Deallocate(TemplParamLists);
1873  TemplParamLists = nullptr;
1874  NumTemplParamLists = 0;
1875  }
1876  // Set info on matched template parameter lists (if any).
1877  if (!TPLists.empty()) {
1878  TemplParamLists = new (Context) TemplateParameterList *[TPLists.size()];
1879  NumTemplParamLists = TPLists.size();
1880  std::copy(TPLists.begin(), TPLists.end(), TemplParamLists);
1881  }
1882 }
1883 
1884 //===----------------------------------------------------------------------===//
1885 // VarDecl Implementation
1886 //===----------------------------------------------------------------------===//
1887 
1889  switch (SC) {
1890  case SC_None: break;
1891  case SC_Auto: return "auto";
1892  case SC_Extern: return "extern";
1893  case SC_PrivateExtern: return "__private_extern__";
1894  case SC_Register: return "register";
1895  case SC_Static: return "static";
1896  }
1897 
1898  llvm_unreachable("Invalid storage class");
1899 }
1900 
1902  SourceLocation StartLoc, SourceLocation IdLoc,
1904  StorageClass SC)
1905  : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc),
1906  redeclarable_base(C) {
1907  static_assert(sizeof(VarDeclBitfields) <= sizeof(unsigned),
1908  "VarDeclBitfields too large!");
1909  static_assert(sizeof(ParmVarDeclBitfields) <= sizeof(unsigned),
1910  "ParmVarDeclBitfields too large!");
1911  static_assert(sizeof(NonParmVarDeclBitfields) <= sizeof(unsigned),
1912  "NonParmVarDeclBitfields too large!");
1913  AllBits = 0;
1914  VarDeclBits.SClass = SC;
1915  // Everything else is implicitly initialized to false.
1916 }
1917 
1919  SourceLocation StartL, SourceLocation IdL,
1921  StorageClass S) {
1922  return new (C, DC) VarDecl(Var, C, DC, StartL, IdL, Id, T, TInfo, S);
1923 }
1924 
1926  return new (C, ID)
1927  VarDecl(Var, C, nullptr, SourceLocation(), SourceLocation(), nullptr,
1928  QualType(), nullptr, SC_None);
1929 }
1930 
1932  assert(isLegalForVariable(SC));
1933  VarDeclBits.SClass = SC;
1934 }
1935 
1937  switch (VarDeclBits.TSCSpec) {
1938  case TSCS_unspecified:
1939  if (!hasAttr<ThreadAttr>() &&
1940  !(getASTContext().getLangOpts().OpenMPUseTLS &&
1941  getASTContext().getTargetInfo().isTLSSupported() &&
1942  hasAttr<OMPThreadPrivateDeclAttr>()))
1943  return TLS_None;
1944  return ((getASTContext().getLangOpts().isCompatibleWithMSVC(
1946  hasAttr<OMPThreadPrivateDeclAttr>())
1947  ? TLS_Dynamic
1948  : TLS_Static;
1949  case TSCS___thread: // Fall through.
1950  case TSCS__Thread_local:
1951  return TLS_Static;
1952  case TSCS_thread_local:
1953  return TLS_Dynamic;
1954  }
1955  llvm_unreachable("Unknown thread storage class specifier!");
1956 }
1957 
1959  if (const Expr *Init = getInit()) {
1960  SourceLocation InitEnd = Init->getEndLoc();
1961  // If Init is implicit, ignore its source range and fallback on
1962  // DeclaratorDecl::getSourceRange() to handle postfix elements.
1963  if (InitEnd.isValid() && InitEnd != getLocation())
1964  return SourceRange(getOuterLocStart(), InitEnd);
1965  }
1967 }
1968 
1969 template<typename T>
1971  // C++ [dcl.link]p1: All function types, function names with external linkage,
1972  // and variable names with external linkage have a language linkage.
1973  if (!D.hasExternalFormalLinkage())
1974  return NoLanguageLinkage;
1975 
1976  // Language linkage is a C++ concept, but saying that everything else in C has
1977  // C language linkage fits the implementation nicely.
1978  ASTContext &Context = D.getASTContext();
1979  if (!Context.getLangOpts().CPlusPlus)
1980  return CLanguageLinkage;
1981 
1982  // C++ [dcl.link]p4: A C language linkage is ignored in determining the
1983  // language linkage of the names of class members and the function type of
1984  // class member functions.
1985  const DeclContext *DC = D.getDeclContext();
1986  if (DC->isRecord())
1987  return CXXLanguageLinkage;
1988 
1989  // If the first decl is in an extern "C" context, any other redeclaration
1990  // will have C language linkage. If the first one is not in an extern "C"
1991  // context, we would have reported an error for any other decl being in one.
1992  if (isFirstInExternCContext(&D))
1993  return CLanguageLinkage;
1994  return CXXLanguageLinkage;
1995 }
1996 
1997 template<typename T>
1998 static bool isDeclExternC(const T &D) {
1999  // Since the context is ignored for class members, they can only have C++
2000  // language linkage or no language linkage.
2001  const DeclContext *DC = D.getDeclContext();
2002  if (DC->isRecord()) {
2003  assert(D.getASTContext().getLangOpts().CPlusPlus);
2004  return false;
2005  }
2006 
2007  return D.getLanguageLinkage() == CLanguageLinkage;
2008 }
2009 
2011  return getDeclLanguageLinkage(*this);
2012 }
2013 
2014 bool VarDecl::isExternC() const {
2015  return isDeclExternC(*this);
2016 }
2017 
2020 }
2021 
2024 }
2025 
2027 
2031  return DeclarationOnly;
2032 
2033  // C++ [basic.def]p2:
2034  // A declaration is a definition unless [...] it contains the 'extern'
2035  // specifier or a linkage-specification and neither an initializer [...],
2036  // it declares a non-inline static data member in a class declaration [...],
2037  // it declares a static data member outside a class definition and the variable
2038  // was defined within the class with the constexpr specifier [...],
2039  // C++1y [temp.expl.spec]p15:
2040  // An explicit specialization of a static data member or an explicit
2041  // specialization of a static data member template is a definition if the
2042  // declaration includes an initializer; otherwise, it is a declaration.
2043  //
2044  // FIXME: How do you declare (but not define) a partial specialization of
2045  // a static data member template outside the containing class?
2046  if (isStaticDataMember()) {
2047  if (isOutOfLine() &&
2048  !(getCanonicalDecl()->isInline() &&
2049  getCanonicalDecl()->isConstexpr()) &&
2050  (hasInit() ||
2051  // If the first declaration is out-of-line, this may be an
2052  // instantiation of an out-of-line partial specialization of a variable
2053  // template for which we have not yet instantiated the initializer.
2058  isa<VarTemplatePartialSpecializationDecl>(this)))
2059  return Definition;
2060  else if (!isOutOfLine() && isInline())
2061  return Definition;
2062  else
2063  return DeclarationOnly;
2064  }
2065  // C99 6.7p5:
2066  // A definition of an identifier is a declaration for that identifier that
2067  // [...] causes storage to be reserved for that object.
2068  // Note: that applies for all non-file-scope objects.
2069  // C99 6.9.2p1:
2070  // If the declaration of an identifier for an object has file scope and an
2071  // initializer, the declaration is an external definition for the identifier
2072  if (hasInit())
2073  return Definition;
2074 
2075  if (hasDefiningAttr())
2076  return Definition;
2077 
2078  if (const auto *SAA = getAttr<SelectAnyAttr>())
2079  if (!SAA->isInherited())
2080  return Definition;
2081 
2082  // A variable template specialization (other than a static data member
2083  // template or an explicit specialization) is a declaration until we
2084  // instantiate its initializer.
2085  if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(this)) {
2086  if (VTSD->getTemplateSpecializationKind() != TSK_ExplicitSpecialization &&
2087  !isa<VarTemplatePartialSpecializationDecl>(VTSD) &&
2088  !VTSD->IsCompleteDefinition)
2089  return DeclarationOnly;
2090  }
2091 
2092  if (hasExternalStorage())
2093  return DeclarationOnly;
2094 
2095  // [dcl.link] p7:
2096  // A declaration directly contained in a linkage-specification is treated
2097  // as if it contains the extern specifier for the purpose of determining
2098  // the linkage of the declared name and whether it is a definition.
2099  if (isSingleLineLanguageLinkage(*this))
2100  return DeclarationOnly;
2101 
2102  // C99 6.9.2p2:
2103  // A declaration of an object that has file scope without an initializer,
2104  // and without a storage class specifier or the scs 'static', constitutes
2105  // a tentative definition.
2106  // No such thing in C++.
2107  if (!C.getLangOpts().CPlusPlus && isFileVarDecl())
2108  return TentativeDefinition;
2109 
2110  // What's left is (in C, block-scope) declarations without initializers or
2111  // external storage. These are definitions.
2112  return Definition;
2113 }
2114 
2117  if (Kind != TentativeDefinition)
2118  return nullptr;
2119 
2120  VarDecl *LastTentative = nullptr;
2121  VarDecl *First = getFirstDecl();
2122  for (auto I : First->redecls()) {
2123  Kind = I->isThisDeclarationADefinition();
2124  if (Kind == Definition)
2125  return nullptr;
2126  else if (Kind == TentativeDefinition)
2127  LastTentative = I;
2128  }
2129  return LastTentative;
2130 }
2131 
2133  VarDecl *First = getFirstDecl();
2134  for (auto I : First->redecls()) {
2135  if (I->isThisDeclarationADefinition(C) == Definition)
2136  return I;
2137  }
2138  return nullptr;
2139 }
2140 
2143 
2144  const VarDecl *First = getFirstDecl();
2145  for (auto I : First->redecls()) {
2146  Kind = std::max(Kind, I->isThisDeclarationADefinition(C));
2147  if (Kind == Definition)
2148  break;
2149  }
2150 
2151  return Kind;
2152 }
2153 
2154 const Expr *VarDecl::getAnyInitializer(const VarDecl *&D) const {
2155  for (auto I : redecls()) {
2156  if (auto Expr = I->getInit()) {
2157  D = I;
2158  return Expr;
2159  }
2160  }
2161  return nullptr;
2162 }
2163 
2164 bool VarDecl::hasInit() const {
2165  if (auto *P = dyn_cast<ParmVarDecl>(this))
2166  if (P->hasUnparsedDefaultArg() || P->hasUninstantiatedDefaultArg())
2167  return false;
2168 
2169  return !Init.isNull();
2170 }
2171 
2173  if (!hasInit())
2174  return nullptr;
2175 
2176  if (auto *S = Init.dyn_cast<Stmt *>())
2177  return cast<Expr>(S);
2178 
2179  return cast_or_null<Expr>(Init.get<EvaluatedStmt *>()->Value);
2180 }
2181 
2183  if (auto *ES = Init.dyn_cast<EvaluatedStmt *>())
2184  return &ES->Value;
2185 
2186  return Init.getAddrOfPtr1();
2187 }
2188 
2189 bool VarDecl::isOutOfLine() const {
2190  if (Decl::isOutOfLine())
2191  return true;
2192 
2193  if (!isStaticDataMember())
2194  return false;
2195 
2196  // If this static data member was instantiated from a static data member of
2197  // a class template, check whether that static data member was defined
2198  // out-of-line.
2200  return VD->isOutOfLine();
2201 
2202  return false;
2203 }
2204 
2206  if (auto *Eval = Init.dyn_cast<EvaluatedStmt *>()) {
2207  Eval->~EvaluatedStmt();
2208  getASTContext().Deallocate(Eval);
2209  }
2210 
2211  Init = I;
2212 }
2213 
2215  const LangOptions &Lang = C.getLangOpts();
2216 
2217  if (!Lang.CPlusPlus)
2218  return false;
2219 
2220  // In C++11, any variable of reference type can be used in a constant
2221  // expression if it is initialized by a constant expression.
2222  if (Lang.CPlusPlus11 && getType()->isReferenceType())
2223  return true;
2224 
2225  // Only const objects can be used in constant expressions in C++. C++98 does
2226  // not require the variable to be non-volatile, but we consider this to be a
2227  // defect.
2228  if (!getType().isConstQualified() || getType().isVolatileQualified())
2229  return false;
2230 
2231  // In C++, const, non-volatile variables of integral or enumeration types
2232  // can be used in constant expressions.
2233  if (getType()->isIntegralOrEnumerationType())
2234  return true;
2235 
2236  // Additionally, in C++11, non-volatile constexpr variables can be used in
2237  // constant expressions.
2238  return Lang.CPlusPlus11 && isConstexpr();
2239 }
2240 
2241 /// Convert the initializer for this declaration to the elaborated EvaluatedStmt
2242 /// form, which contains extra information on the evaluated value of the
2243 /// initializer.
2245  auto *Eval = Init.dyn_cast<EvaluatedStmt *>();
2246  if (!Eval) {
2247  // Note: EvaluatedStmt contains an APValue, which usually holds
2248  // resources not allocated from the ASTContext. We need to do some
2249  // work to avoid leaking those, but we do so in VarDecl::evaluateValue
2250  // where we can detect whether there's anything to clean up or not.
2251  Eval = new (getASTContext()) EvaluatedStmt;
2252  Eval->Value = Init.get<Stmt *>();
2253  Init = Eval;
2254  }
2255  return Eval;
2256 }
2257 
2260  return evaluateValue(Notes);
2261 }
2262 
2264  SmallVectorImpl<PartialDiagnosticAt> &Notes) const {
2266 
2267  // We only produce notes indicating why an initializer is non-constant the
2268  // first time it is evaluated. FIXME: The notes won't always be emitted the
2269  // first time we try evaluation, so might not be produced at all.
2270  if (Eval->WasEvaluated)
2271  return Eval->Evaluated.isUninit() ? nullptr : &Eval->Evaluated;
2272 
2273  const auto *Init = cast<Expr>(Eval->Value);
2274  assert(!Init->isValueDependent());
2275 
2276  if (Eval->IsEvaluating) {
2277  // FIXME: Produce a diagnostic for self-initialization.
2278  Eval->CheckedICE = true;
2279  Eval->IsICE = false;
2280  return nullptr;
2281  }
2282 
2283  Eval->IsEvaluating = true;
2284 
2285  bool Result = Init->EvaluateAsInitializer(Eval->Evaluated, getASTContext(),
2286  this, Notes);
2287 
2288  // Ensure the computed APValue is cleaned up later if evaluation succeeded,
2289  // or that it's empty (so that there's nothing to clean up) if evaluation
2290  // failed.
2291  if (!Result)
2292  Eval->Evaluated = APValue();
2293  else if (Eval->Evaluated.needsCleanup())
2295 
2296  Eval->IsEvaluating = false;
2297  Eval->WasEvaluated = true;
2298 
2299  // In C++11, we have determined whether the initializer was a constant
2300  // expression as a side-effect.
2301  if (getASTContext().getLangOpts().CPlusPlus11 && !Eval->CheckedICE) {
2302  Eval->CheckedICE = true;
2303  Eval->IsICE = Result && Notes.empty();
2304  }
2305 
2306  return Result ? &Eval->Evaluated : nullptr;
2307 }
2308 
2310  if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
2311  if (Eval->WasEvaluated)
2312  return &Eval->Evaluated;
2313 
2314  return nullptr;
2315 }
2316 
2318  if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>())
2319  return Eval->CheckedICE;
2320 
2321  return false;
2322 }
2323 
2324 bool VarDecl::isInitICE() const {
2325  assert(isInitKnownICE() &&
2326  "Check whether we already know that the initializer is an ICE");
2327  return Init.get<EvaluatedStmt *>()->IsICE;
2328 }
2329 
2331  // Initializers of weak variables are never ICEs.
2332  if (isWeak())
2333  return false;
2334 
2336  if (Eval->CheckedICE)
2337  // We have already checked whether this subexpression is an
2338  // integral constant expression.
2339  return Eval->IsICE;
2340 
2341  const auto *Init = cast<Expr>(Eval->Value);
2342  assert(!Init->isValueDependent());
2343 
2344  // In C++11, evaluate the initializer to check whether it's a constant
2345  // expression.
2346  if (getASTContext().getLangOpts().CPlusPlus11) {
2348  evaluateValue(Notes);
2349  return Eval->IsICE;
2350  }
2351 
2352  // It's an ICE whether or not the definition we found is
2353  // out-of-line. See DR 721 and the discussion in Clang PR
2354  // 6206 for details.
2355 
2356  if (Eval->CheckingICE)
2357  return false;
2358  Eval->CheckingICE = true;
2359 
2360  Eval->IsICE = Init->isIntegerConstantExpr(getASTContext());
2361  Eval->CheckingICE = false;
2362  Eval->CheckedICE = true;
2363  return Eval->IsICE;
2364 }
2365 
2366 template<typename DeclT>
2367 static DeclT *getDefinitionOrSelf(DeclT *D) {
2368  assert(D);
2369  if (auto *Def = D->getDefinition())
2370  return Def;
2371  return D;
2372 }
2373 
2375  return hasAttr<BlocksAttr>() && NonParmVarDeclBits.EscapingByref;
2376 }
2377 
2379  return hasAttr<BlocksAttr>() && !NonParmVarDeclBits.EscapingByref;
2380 }
2381 
2383  // If it's a variable template specialization, find the template or partial
2384  // specialization from which it was instantiated.
2385  if (auto *VDTemplSpec = dyn_cast<VarTemplateSpecializationDecl>(this)) {
2386  auto From = VDTemplSpec->getInstantiatedFrom();
2387  if (auto *VTD = From.dyn_cast<VarTemplateDecl *>()) {
2388  while (auto *NewVTD = VTD->getInstantiatedFromMemberTemplate()) {
2389  if (NewVTD->isMemberSpecialization())
2390  break;
2391  VTD = NewVTD;
2392  }
2393  return getDefinitionOrSelf(VTD->getTemplatedDecl());
2394  }
2395  if (auto *VTPSD =
2396  From.dyn_cast<VarTemplatePartialSpecializationDecl *>()) {
2397  while (auto *NewVTPSD = VTPSD->getInstantiatedFromMember()) {
2398  if (NewVTPSD->isMemberSpecialization())
2399  break;
2400  VTPSD = NewVTPSD;
2401  }
2402  return getDefinitionOrSelf<VarDecl>(VTPSD);
2403  }
2404  }
2405 
2407  if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) {
2409  while (auto *NewVD = VD->getInstantiatedFromStaticDataMember())
2410  VD = NewVD;
2411  return getDefinitionOrSelf(VD);
2412  }
2413  }
2414 
2415  if (VarTemplateDecl *VarTemplate = getDescribedVarTemplate()) {
2416  while (VarTemplate->getInstantiatedFromMemberTemplate()) {
2417  if (VarTemplate->isMemberSpecialization())
2418  break;
2419  VarTemplate = VarTemplate->getInstantiatedFromMemberTemplate();
2420  }
2421 
2422  return getDefinitionOrSelf(VarTemplate->getTemplatedDecl());
2423  }
2424  return nullptr;
2425 }
2426 
2429  return cast<VarDecl>(MSI->getInstantiatedFrom());
2430 
2431  return nullptr;
2432 }
2433 
2435  if (const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(this))
2436  return Spec->getSpecializationKind();
2437 
2439  return MSI->getTemplateSpecializationKind();
2440 
2441  return TSK_Undeclared;
2442 }
2443 
2445  if (const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(this))
2446  return Spec->getPointOfInstantiation();
2447 
2449  return MSI->getPointOfInstantiation();
2450 
2451  return SourceLocation();
2452 }
2453 
2456  .dyn_cast<VarTemplateDecl *>();
2457 }
2458 
2461 }
2462 
2464  const auto &LangOpts = getASTContext().getLangOpts();
2465  // In CUDA mode without relocatable device code, variables of form 'extern
2466  // __shared__ Foo foo[]' are pointers to the base of the GPU core's shared
2467  // memory pool. These are never undefined variables, even if they appear
2468  // inside of an anon namespace or static function.
2469  //
2470  // With CUDA relocatable device code enabled, these variables don't get
2471  // special handling; they're treated like regular extern variables.
2472  if (LangOpts.CUDA && !LangOpts.GPURelocatableDeviceCode &&
2473  hasExternalStorage() && hasAttr<CUDASharedAttr>() &&
2474  isa<IncompleteArrayType>(getType()))
2475  return true;
2476 
2477  return hasDefinition();
2478 }
2479 
2480 bool VarDecl::isNoDestroy(const ASTContext &Ctx) const {
2481  return hasGlobalStorage() && (hasAttr<NoDestroyAttr>() ||
2482  (!Ctx.getLangOpts().RegisterStaticDestructors &&
2483  !hasAttr<AlwaysDestroyAttr>()));
2484 }
2485 
2487  if (isStaticDataMember())
2488  // FIXME: Remove ?
2489  // return getASTContext().getInstantiatedFromStaticDataMember(this);
2491  .dyn_cast<MemberSpecializationInfo *>();
2492  return nullptr;
2493 }
2494 
2496  SourceLocation PointOfInstantiation) {
2497  assert((isa<VarTemplateSpecializationDecl>(this) ||
2499  "not a variable or static data member template specialization");
2500 
2501  if (VarTemplateSpecializationDecl *Spec =
2502  dyn_cast<VarTemplateSpecializationDecl>(this)) {
2503  Spec->setSpecializationKind(TSK);
2504  if (TSK != TSK_ExplicitSpecialization && PointOfInstantiation.isValid() &&
2505  Spec->getPointOfInstantiation().isInvalid()) {
2506  Spec->setPointOfInstantiation(PointOfInstantiation);
2508  L->InstantiationRequested(this);
2509  }
2510  }
2511 
2513  MSI->setTemplateSpecializationKind(TSK);
2514  if (TSK != TSK_ExplicitSpecialization && PointOfInstantiation.isValid() &&
2515  MSI->getPointOfInstantiation().isInvalid()) {
2516  MSI->setPointOfInstantiation(PointOfInstantiation);
2518  L->InstantiationRequested(this);
2519  }
2520  }
2521 }
2522 
2523 void
2526  assert(getASTContext().getTemplateOrSpecializationInfo(this).isNull() &&
2527  "Previous template or instantiation?");
2529 }
2530 
2531 //===----------------------------------------------------------------------===//
2532 // ParmVarDecl Implementation
2533 //===----------------------------------------------------------------------===//
2534 
2536  SourceLocation StartLoc,
2538  QualType T, TypeSourceInfo *TInfo,
2539  StorageClass S, Expr *DefArg) {
2540  return new (C, DC) ParmVarDecl(ParmVar, C, DC, StartLoc, IdLoc, Id, T, TInfo,
2541  S, DefArg);
2542 }
2543 
2546  QualType T = TSI ? TSI->getType() : getType();
2547  if (const auto *DT = dyn_cast<DecayedType>(T))
2548  return DT->getOriginalType();
2549  return T;
2550 }
2551 
2553  return new (C, ID)
2554  ParmVarDecl(ParmVar, C, nullptr, SourceLocation(), SourceLocation(),
2555  nullptr, QualType(), nullptr, SC_None, nullptr);
2556 }
2557 
2559  if (!hasInheritedDefaultArg()) {
2560  SourceRange ArgRange = getDefaultArgRange();
2561  if (ArgRange.isValid())
2562  return SourceRange(getOuterLocStart(), ArgRange.getEnd());
2563  }
2564 
2565  // DeclaratorDecl considers the range of postfix types as overlapping with the
2566  // declaration name, but this is not the case with parameters in ObjC methods.
2567  if (isa<ObjCMethodDecl>(getDeclContext()))
2569 
2571 }
2572 
2574  assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!");
2575  assert(!hasUninstantiatedDefaultArg() &&
2576  "Default argument is not yet instantiated!");
2577 
2578  Expr *Arg = getInit();
2579  if (auto *E = dyn_cast_or_null<FullExpr>(Arg))
2580  return E->getSubExpr();
2581 
2582  return Arg;
2583 }
2584 
2586  ParmVarDeclBits.DefaultArgKind = DAK_Normal;
2587  Init = defarg;
2588 }
2589 
2591  switch (ParmVarDeclBits.DefaultArgKind) {
2592  case DAK_None:
2593  case DAK_Unparsed:
2594  // Nothing we can do here.
2595  return SourceRange();
2596 
2597  case DAK_Uninstantiated:
2598  return getUninstantiatedDefaultArg()->getSourceRange();
2599 
2600  case DAK_Normal:
2601  if (const Expr *E = getInit())
2602  return E->getSourceRange();
2603 
2604  // Missing an actual expression, may be invalid.
2605  return SourceRange();
2606  }
2607  llvm_unreachable("Invalid default argument kind.");
2608 }
2609 
2611  ParmVarDeclBits.DefaultArgKind = DAK_Uninstantiated;
2612  Init = arg;
2613 }
2614 
2616  assert(hasUninstantiatedDefaultArg() &&
2617  "Wrong kind of initialization expression!");
2618  return cast_or_null<Expr>(Init.get<Stmt *>());
2619 }
2620 
2622  // FIXME: We should just return false for DAK_None here once callers are
2623  // prepared for the case that we encountered an invalid default argument and
2624  // were unable to even build an invalid expression.
2625  return hasUnparsedDefaultArg() || hasUninstantiatedDefaultArg() ||
2626  !Init.isNull();
2627 }
2628 
2630  return isa<PackExpansionType>(getType());
2631 }
2632 
2633 void ParmVarDecl::setParameterIndexLarge(unsigned parameterIndex) {
2634  getASTContext().setParameterIndex(this, parameterIndex);
2635  ParmVarDeclBits.ParameterIndex = ParameterIndexSentinel;
2636 }
2637 
2638 unsigned ParmVarDecl::getParameterIndexLarge() const {
2639  return getASTContext().getParameterIndex(this);
2640 }
2641 
2642 //===----------------------------------------------------------------------===//
2643 // FunctionDecl Implementation
2644 //===----------------------------------------------------------------------===//
2645 
2647  SourceLocation StartLoc,
2648  const DeclarationNameInfo &NameInfo, QualType T,
2649  TypeSourceInfo *TInfo, StorageClass S,
2650  bool isInlineSpecified, bool isConstexprSpecified)
2651  : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo,
2652  StartLoc),
2654  EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) {
2655  assert(T.isNull() || T->isFunctionType());
2656  FunctionDeclBits.SClass = S;
2658  FunctionDeclBits.IsInlineSpecified = isInlineSpecified;
2659  FunctionDeclBits.IsExplicitSpecified = false;
2660  FunctionDeclBits.IsVirtualAsWritten = false;
2661  FunctionDeclBits.IsPure = false;
2662  FunctionDeclBits.HasInheritedPrototype = false;
2663  FunctionDeclBits.HasWrittenPrototype = true;
2664  FunctionDeclBits.IsDeleted = false;
2665  FunctionDeclBits.IsTrivial = false;
2666  FunctionDeclBits.IsTrivialForCall = false;
2667  FunctionDeclBits.IsDefaulted = false;
2668  FunctionDeclBits.IsExplicitlyDefaulted = false;
2669  FunctionDeclBits.HasImplicitReturnZero = false;
2670  FunctionDeclBits.IsLateTemplateParsed = false;
2671  FunctionDeclBits.IsConstexpr = isConstexprSpecified;
2672  FunctionDeclBits.InstantiationIsPending = false;
2673  FunctionDeclBits.UsesSEHTry = false;
2674  FunctionDeclBits.HasSkippedBody = false;
2675  FunctionDeclBits.WillHaveBody = false;
2676  FunctionDeclBits.IsMultiVersion = false;
2677  FunctionDeclBits.IsCopyDeductionCandidate = false;
2678  FunctionDeclBits.HasODRHash = false;
2679 }
2680 
2682  raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
2683  NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
2684  const TemplateArgumentList *TemplateArgs = getTemplateSpecializationArgs();
2685  if (TemplateArgs)
2686  printTemplateArgumentList(OS, TemplateArgs->asArray(), Policy);
2687 }
2688 
2690  if (const auto *FT = getType()->getAs<FunctionProtoType>())
2691  return FT->isVariadic();
2692  return false;
2693 }
2694 
2695 bool FunctionDecl::hasBody(const FunctionDecl *&Definition) const {
2696  for (auto I : redecls()) {
2697  if (I->doesThisDeclarationHaveABody()) {
2698  Definition = I;
2699  return true;
2700  }
2701  }
2702 
2703  return false;
2704 }
2705 
2707 {
2708  Stmt *S = getBody();
2709  if (!S) {
2710  // Since we don't have a body for this function, we don't know if it's
2711  // trivial or not.
2712  return false;
2713  }
2714 
2715  if (isa<CompoundStmt>(S) && cast<CompoundStmt>(S)->body_empty())
2716  return true;
2717  return false;
2718 }
2719 
2720 bool FunctionDecl::isDefined(const FunctionDecl *&Definition) const {
2721  for (auto I : redecls()) {
2722  if (I->isThisDeclarationADefinition()) {
2723  Definition = I;
2724  return true;
2725  }
2726  }
2727 
2728  return false;
2729 }
2730 
2731 Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
2732  if (!hasBody(Definition))
2733  return nullptr;
2734 
2735  if (Definition->Body)
2736  return Definition->Body.get(getASTContext().getExternalSource());
2737 
2738  return nullptr;
2739 }
2740 
2742  Body = B;
2743  if (B)
2744  EndRangeLoc = B->getEndLoc();
2745 }
2746 
2748  FunctionDeclBits.IsPure = P;
2749  if (P)
2750  if (auto *Parent = dyn_cast<CXXRecordDecl>(getDeclContext()))
2751  Parent->markedVirtualFunctionPure();
2752 }
2753 
2754 template<std::size_t Len>
2755 static bool isNamed(const NamedDecl *ND, const char (&Str)[Len]) {
2756  IdentifierInfo *II = ND->getIdentifier();
2757  return II && II->isStr(Str);
2758 }
2759 
2760 bool FunctionDecl::isMain() const {
2761  const TranslationUnitDecl *tunit =
2763  return tunit &&
2764  !tunit->getASTContext().getLangOpts().Freestanding &&
2765  isNamed(this, "main");
2766 }
2767 
2769  const TranslationUnitDecl *TUnit =
2771  if (!TUnit)
2772  return false;
2773 
2774  // Even though we aren't really targeting MSVCRT if we are freestanding,
2775  // semantic analysis for these functions remains the same.
2776 
2777  // MSVCRT entry points only exist on MSVCRT targets.
2778  if (!TUnit->getASTContext().getTargetInfo().getTriple().isOSMSVCRT())
2779  return false;
2780 
2781  // Nameless functions like constructors cannot be entry points.
2782  if (!getIdentifier())
2783  return false;
2784 
2785  return llvm::StringSwitch<bool>(getName())
2786  .Cases("main", // an ANSI console app
2787  "wmain", // a Unicode console App
2788  "WinMain", // an ANSI GUI app
2789  "wWinMain", // a Unicode GUI app
2790  "DllMain", // a DLL
2791  true)
2792  .Default(false);
2793 }
2794 
2796  assert(getDeclName().getNameKind() == DeclarationName::CXXOperatorName);
2797  assert(getDeclName().getCXXOverloadedOperator() == OO_New ||
2798  getDeclName().getCXXOverloadedOperator() == OO_Delete ||
2799  getDeclName().getCXXOverloadedOperator() == OO_Array_New ||
2800  getDeclName().getCXXOverloadedOperator() == OO_Array_Delete);
2801 
2803  return false;
2804 
2805  const auto *proto = getType()->castAs<FunctionProtoType>();
2806  if (proto->getNumParams() != 2 || proto->isVariadic())
2807  return false;
2808 
2809  ASTContext &Context =
2810  cast<TranslationUnitDecl>(getDeclContext()->getRedeclContext())
2811  ->getASTContext();
2812 
2813  // The result type and first argument type are constant across all
2814  // these operators. The second argument must be exactly void*.
2815  return (proto->getParamType(1).getCanonicalType() == Context.VoidPtrTy);
2816 }
2817 
2819  if (getDeclName().getNameKind() != DeclarationName::CXXOperatorName)
2820  return false;
2821  if (getDeclName().getCXXOverloadedOperator() != OO_New &&
2822  getDeclName().getCXXOverloadedOperator() != OO_Delete &&
2823  getDeclName().getCXXOverloadedOperator() != OO_Array_New &&
2824  getDeclName().getCXXOverloadedOperator() != OO_Array_Delete)
2825  return false;
2826 
2827  if (isa<CXXRecordDecl>(getDeclContext()))
2828  return false;
2829 
2830  // This can only fail for an invalid 'operator new' declaration.
2832  return false;
2833 
2834  const auto *FPT = getType()->castAs<FunctionProtoType>();
2835  if (FPT->getNumParams() == 0 || FPT->getNumParams() > 3 || FPT->isVariadic())
2836  return false;
2837 
2838  // If this is a single-parameter function, it must be a replaceable global
2839  // allocation or deallocation function.
2840  if (FPT->getNumParams() == 1)
2841  return true;
2842 
2843  unsigned Params = 1;
2844  QualType Ty = FPT->getParamType(Params);
2845  ASTContext &Ctx = getASTContext();
2846 
2847  auto Consume = [&] {
2848  ++Params;
2849  Ty = Params < FPT->getNumParams() ? FPT->getParamType(Params) : QualType();
2850  };
2851 
2852  // In C++14, the next parameter can be a 'std::size_t' for sized delete.
2853  bool IsSizedDelete = false;
2854  if (Ctx.getLangOpts().SizedDeallocation &&
2855  (getDeclName().getCXXOverloadedOperator() == OO_Delete ||
2856  getDeclName().getCXXOverloadedOperator() == OO_Array_Delete) &&
2857  Ctx.hasSameType(Ty, Ctx.getSizeType())) {
2858  IsSizedDelete = true;
2859  Consume();
2860  }
2861 
2862  // In C++17, the next parameter can be a 'std::align_val_t' for aligned
2863  // new/delete.
2864  if (Ctx.getLangOpts().AlignedAllocation && !Ty.isNull() && Ty->isAlignValT()) {
2865  if (IsAligned)
2866  *IsAligned = true;
2867  Consume();
2868  }
2869 
2870  // Finally, if this is not a sized delete, the final parameter can
2871  // be a 'const std::nothrow_t&'.
2872  if (!IsSizedDelete && !Ty.isNull() && Ty->isReferenceType()) {
2873  Ty = Ty->getPointeeType();
2874  if (Ty.getCVRQualifiers() != Qualifiers::Const)
2875  return false;
2876  const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();
2877  if (RD && isNamed(RD, "nothrow_t") && RD->isInStdNamespace())
2878  Consume();
2879  }
2880 
2881  return Params == FPT->getNumParams();
2882 }
2883 
2885  // C++ P0722:
2886  // Within a class C, a single object deallocation function with signature
2887  // (T, std::destroying_delete_t, <more params>)
2888  // is a destroying operator delete.
2889  if (!isa<CXXMethodDecl>(this) || getOverloadedOperator() != OO_Delete ||
2890  getNumParams() < 2)
2891  return false;
2892 
2893  auto *RD = getParamDecl(1)->getType()->getAsCXXRecordDecl();
2894  return RD && RD->isInStdNamespace() && RD->getIdentifier() &&
2895  RD->getIdentifier()->isStr("destroying_delete_t");
2896 }
2897 
2899  return getDeclLanguageLinkage(*this);
2900 }
2901 
2903  return isDeclExternC(*this);
2904 }
2905 
2908 }
2909 
2912 }
2913 
2915  if (const auto *Method = dyn_cast<CXXMethodDecl>(this))
2916  return Method->isStatic();
2917 
2919  return false;
2920 
2921  for (const DeclContext *DC = getDeclContext();
2922  DC->isNamespace();
2923  DC = DC->getParent()) {
2924  if (const auto *Namespace = cast<NamespaceDecl>(DC)) {
2925  if (!Namespace->getDeclName())
2926  return false;
2927  break;
2928  }
2929  }
2930 
2931  return true;
2932 }
2933 
2935  if (hasAttr<NoReturnAttr>() || hasAttr<CXX11NoReturnAttr>() ||
2936  hasAttr<C11NoReturnAttr>())
2937  return true;
2938 
2939  if (auto *FnTy = getType()->getAs<FunctionType>())
2940  return FnTy->getNoReturnAttr();
2941 
2942  return false;
2943 }
2944 
2945 
2947  if (hasAttr<TargetAttr>())
2948  return MultiVersionKind::Target;
2949  if (hasAttr<CPUDispatchAttr>())
2951  if (hasAttr<CPUSpecificAttr>())
2953  return MultiVersionKind::None;
2954 }
2955 
2957  return isMultiVersion() && hasAttr<CPUDispatchAttr>();
2958 }
2959 
2961  return isMultiVersion() && hasAttr<CPUSpecificAttr>();
2962 }
2963 
2965  return isMultiVersion() && hasAttr<TargetAttr>();
2966 }
2967 
2968 void
2971 
2973  FunctionTemplateDecl *PrevFunTmpl
2974  = PrevDecl? PrevDecl->getDescribedFunctionTemplate() : nullptr;
2975  assert((!PrevDecl || PrevFunTmpl) && "Function/function template mismatch");
2976  FunTmpl->setPreviousDecl(PrevFunTmpl);
2977  }
2978 
2979  if (PrevDecl && PrevDecl->isInlined())
2980  setImplicitlyInline(true);
2981 }
2982 
2984 
2985 /// Returns a value indicating whether this function
2986 /// corresponds to a builtin function.
2987 ///
2988 /// The function corresponds to a built-in function if it is
2989 /// declared at translation scope or within an extern "C" block and
2990 /// its name matches with the name of a builtin. The returned value
2991 /// will be 0 for functions that do not correspond to a builtin, a
2992 /// value of type \c Builtin::ID if in the target-independent range
2993 /// \c [1,Builtin::First), or a target-specific builtin value.
2994 unsigned FunctionDecl::getBuiltinID() const {
2995  if (!getIdentifier())
2996  return 0;
2997 
2998  unsigned BuiltinID = getIdentifier()->getBuiltinID();
2999  if (!BuiltinID)
3000  return 0;
3001 
3002  ASTContext &Context = getASTContext();
3003  if (Context.getLangOpts().CPlusPlus) {
3004  const auto *LinkageDecl =
3006  // In C++, the first declaration of a builtin is always inside an implicit
3007  // extern "C".
3008  // FIXME: A recognised library function may not be directly in an extern "C"
3009  // declaration, for instance "extern "C" { namespace std { decl } }".
3010  if (!LinkageDecl) {
3011  if (BuiltinID == Builtin::BI__GetExceptionInfo &&
3012  Context.getTargetInfo().getCXXABI().isMicrosoft())
3013  return Builtin::BI__GetExceptionInfo;
3014  return 0;
3015  }
3016  if (LinkageDecl->getLanguage() != LinkageSpecDecl::lang_c)
3017  return 0;
3018  }
3019 
3020  // If the function is marked "overloadable", it has a different mangled name
3021  // and is not the C library function.
3022  if (hasAttr<OverloadableAttr>())
3023  return 0;
3024 
3025  if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
3026  return BuiltinID;
3027 
3028  // This function has the name of a known C library
3029  // function. Determine whether it actually refers to the C library
3030  // function or whether it just has the same name.
3031 
3032  // If this is a static function, it's not a builtin.
3033  if (getStorageClass() == SC_Static)
3034  return 0;
3035 
3036  // OpenCL v1.2 s6.9.f - The library functions defined in
3037  // the C99 standard headers are not available.
3038  if (Context.getLangOpts().OpenCL &&
3039  Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
3040  return 0;
3041 
3042  // CUDA does not have device-side standard library. printf and malloc are the
3043  // only special cases that are supported by device-side runtime.
3044  if (Context.getLangOpts().CUDA && hasAttr<CUDADeviceAttr>() &&
3045  !hasAttr<CUDAHostAttr>() &&
3046  !(BuiltinID == Builtin::BIprintf || BuiltinID == Builtin::BImalloc))
3047  return 0;
3048 
3049  return BuiltinID;
3050 }
3051 
3052 /// getNumParams - Return the number of parameters this function must have
3053 /// based on its FunctionType. This is the length of the ParamInfo array
3054 /// after it has been created.
3055 unsigned FunctionDecl::getNumParams() const {
3056  const auto *FPT = getType()->getAs<FunctionProtoType>();
3057  return FPT ? FPT->getNumParams() : 0;
3058 }
3059 
3060 void FunctionDecl::setParams(ASTContext &C,
3061  ArrayRef<ParmVarDecl *> NewParamInfo) {
3062  assert(!ParamInfo && "Already has param info!");
3063  assert(NewParamInfo.size() == getNumParams() && "Parameter count mismatch!");
3064 
3065  // Zero params -> null pointer.
3066  if (!NewParamInfo.empty()) {
3067  ParamInfo = new (C) ParmVarDecl*[NewParamInfo.size()];
3068  std::copy(NewParamInfo.begin(), NewParamInfo.end(), ParamInfo);
3069  }
3070 }
3071 
3072 /// getMinRequiredArguments - Returns the minimum number of arguments
3073 /// needed to call this function. This may be fewer than the number of
3074 /// function parameters, if some of the parameters have default
3075 /// arguments (in C++) or are parameter packs (C++11).
3077  if (!getASTContext().getLangOpts().CPlusPlus)
3078  return getNumParams();
3079 
3080  unsigned NumRequiredArgs = 0;
3081  for (auto *Param : parameters())
3082  if (!Param->isParameterPack() && !Param->hasDefaultArg())
3083  ++NumRequiredArgs;
3084  return NumRequiredArgs;
3085 }
3086 
3087 /// The combination of the extern and inline keywords under MSVC forces
3088 /// the function to be required.
3089 ///
3090 /// Note: This function assumes that we will only get called when isInlined()
3091 /// would return true for this FunctionDecl.
3093  assert(isInlined() && "expected to get called on an inlined function!");
3094 
3095  const ASTContext &Context = getASTContext();
3096  if (!Context.getTargetInfo().getCXXABI().isMicrosoft() &&
3097  !hasAttr<DLLExportAttr>())
3098  return false;
3099 
3100  for (const FunctionDecl *FD = getMostRecentDecl(); FD;
3101  FD = FD->getPreviousDecl())
3102  if (!FD->isImplicit() && FD->getStorageClass() == SC_Extern)
3103  return true;
3104 
3105  return false;
3106 }
3107 
3108 static bool redeclForcesDefMSVC(const FunctionDecl *Redecl) {
3109  if (Redecl->getStorageClass() != SC_Extern)
3110  return false;
3111 
3112  for (const FunctionDecl *FD = Redecl->getPreviousDecl(); FD;
3113  FD = FD->getPreviousDecl())
3114  if (!FD->isImplicit() && FD->getStorageClass() == SC_Extern)
3115  return false;
3116 
3117  return true;
3118 }
3119 
3120 static bool RedeclForcesDefC99(const FunctionDecl *Redecl) {
3121  // Only consider file-scope declarations in this test.
3122  if (!Redecl->getLexicalDeclContext()->isTranslationUnit())
3123  return false;
3124 
3125  // Only consider explicit declarations; the presence of a builtin for a
3126  // libcall shouldn't affect whether a definition is externally visible.
3127  if (Redecl->isImplicit())
3128  return false;
3129 
3130  if (!Redecl->isInlineSpecified() || Redecl->getStorageClass() == SC_Extern)
3131  return true; // Not an inline definition
3132 
3133  return false;
3134 }
3135 
3136 /// For a function declaration in C or C++, determine whether this
3137 /// declaration causes the definition to be externally visible.
3138 ///
3139 /// For instance, this determines if adding the current declaration to the set
3140 /// of redeclarations of the given functions causes
3141 /// isInlineDefinitionExternallyVisible to change from false to true.
3143  assert(!doesThisDeclarationHaveABody() &&
3144  "Must have a declaration without a body.");
3145 
3146  ASTContext &Context = getASTContext();
3147 
3148  if (Context.getLangOpts().MSVCCompat) {
3149  const FunctionDecl *Definition;
3150  if (hasBody(Definition) && Definition->isInlined() &&
3151  redeclForcesDefMSVC(this))
3152  return true;
3153  }
3154 
3155  if (Context.getLangOpts().GNUInline || hasAttr<GNUInlineAttr>()) {
3156  // With GNU inlining, a declaration with 'inline' but not 'extern', forces
3157  // an externally visible definition.
3158  //
3159  // FIXME: What happens if gnu_inline gets added on after the first
3160  // declaration?
3162  return false;
3163 
3164  const FunctionDecl *Prev = this;
3165  bool FoundBody = false;
3166  while ((Prev = Prev->getPreviousDecl())) {
3167  FoundBody |= Prev->Body.isValid();
3168 
3169  if (Prev->Body) {
3170  // If it's not the case that both 'inline' and 'extern' are
3171  // specified on the definition, then it is always externally visible.
3172  if (!Prev->isInlineSpecified() ||
3173  Prev->getStorageClass() != SC_Extern)
3174  return false;
3175  } else if (Prev->isInlineSpecified() &&
3176  Prev->getStorageClass() != SC_Extern) {
3177  return false;
3178  }
3179  }
3180  return FoundBody;
3181  }
3182 
3183  if (Context.getLangOpts().CPlusPlus)
3184  return false;
3185 
3186  // C99 6.7.4p6:
3187  // [...] If all of the file scope declarations for a function in a
3188  // translation unit include the inline function specifier without extern,
3189  // then the definition in that translation unit is an inline definition.
3191  return false;
3192  const FunctionDecl *Prev = this;
3193  bool FoundBody = false;
3194  while ((Prev = Prev->getPreviousDecl())) {
3195  FoundBody |= Prev->Body.isValid();
3196  if (RedeclForcesDefC99(Prev))
3197  return false;
3198  }
3199  return FoundBody;
3200 }
3201 
3203  const TypeSourceInfo *TSI = getTypeSourceInfo();
3204  if (!TSI)
3205  return SourceRange();
3206  FunctionTypeLoc FTL =
3208  if (!FTL)
3209  return SourceRange();
3210 
3211  // Skip self-referential return types.
3213  SourceRange RTRange = FTL.getReturnLoc().getSourceRange();
3214  SourceLocation Boundary = getNameInfo().getBeginLoc();
3215  if (RTRange.isInvalid() || Boundary.isInvalid() ||
3216  !SM.isBeforeInTranslationUnit(RTRange.getEnd(), Boundary))
3217  return SourceRange();
3218 
3219  return RTRange;
3220 }
3221 
3223  const TypeSourceInfo *TSI = getTypeSourceInfo();
3224  if (!TSI)
3225  return SourceRange();
3226  FunctionTypeLoc FTL =
3228  if (!FTL)
3229  return SourceRange();
3230 
3231  return FTL.getExceptionSpecRange();
3232 }
3233 
3234 /// For an inline function definition in C, or for a gnu_inline function
3235 /// in C++, determine whether the definition will be externally visible.
3236 ///
3237 /// Inline function definitions are always available for inlining optimizations.
3238 /// However, depending on the language dialect, declaration specifiers, and
3239 /// attributes, the definition of an inline function may or may not be
3240 /// "externally" visible to other translation units in the program.
3241 ///
3242 /// In C99, inline definitions are not externally visible by default. However,
3243 /// if even one of the global-scope declarations is marked "extern inline", the
3244 /// inline definition becomes externally visible (C99 6.7.4p6).
3245 ///
3246 /// In GNU89 mode, or if the gnu_inline attribute is attached to the function
3247 /// definition, we use the GNU semantics for inline, which are nearly the
3248 /// opposite of C99 semantics. In particular, "inline" by itself will create
3249 /// an externally visible symbol, but "extern inline" will not create an
3250 /// externally visible symbol.
3252  assert((doesThisDeclarationHaveABody() || willHaveBody()) &&
3253  "Must be a function definition");
3254  assert(isInlined() && "Function must be inline");
3255  ASTContext &Context = getASTContext();
3256 
3257  if (Context.getLangOpts().GNUInline || hasAttr<GNUInlineAttr>()) {
3258  // Note: If you change the logic here, please change
3259  // doesDeclarationForceExternallyVisibleDefinition as well.
3260  //
3261  // If it's not the case that both 'inline' and 'extern' are
3262  // specified on the definition, then this inline definition is
3263  // externally visible.
3264  if (!(isInlineSpecified() && getStorageClass() == SC_Extern))
3265  return true;
3266 
3267  // If any declaration is 'inline' but not 'extern', then this definition
3268  // is externally visible.
3269  for (auto Redecl : redecls()) {
3270  if (Redecl->isInlineSpecified() &&
3271  Redecl->getStorageClass() != SC_Extern)
3272  return true;
3273  }
3274 
3275  return false;
3276  }
3277 
3278  // The rest of this function is C-only.
3279  assert(!Context.getLangOpts().CPlusPlus &&
3280  "should not use C inline rules in C++");
3281 
3282  // C99 6.7.4p6:
3283  // [...] If all of the file scope declarations for a function in a
3284  // translation unit include the inline function specifier without extern,
3285  // then the definition in that translation unit is an inline definition.
3286  for (auto Redecl : redecls()) {
3287  if (RedeclForcesDefC99(Redecl))
3288  return true;
3289  }
3290 
3291  // C99 6.7.4p6:
3292  // An inline definition does not provide an external definition for the
3293  // function, and does not forbid an external definition in another
3294  // translation unit.
3295  return false;
3296 }
3297 
3298 /// getOverloadedOperator - Which C++ overloaded operator this
3299 /// function represents, if any.
3301  if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName)
3303  else
3304  return OO_None;
3305 }
3306 
3307 /// getLiteralIdentifier - The literal suffix identifier this function
3308 /// represents, if any.
3312  else
3313  return nullptr;
3314 }
3315 
3317  if (TemplateOrSpecialization.isNull())
3318  return TK_NonTemplate;
3319  if (TemplateOrSpecialization.is<FunctionTemplateDecl *>())
3320  return TK_FunctionTemplate;
3321  if (TemplateOrSpecialization.is<MemberSpecializationInfo *>())
3322  return TK_MemberSpecialization;
3323  if (TemplateOrSpecialization.is<FunctionTemplateSpecializationInfo *>())
3325  if (TemplateOrSpecialization.is
3328 
3329  llvm_unreachable("Did we miss a TemplateOrSpecialization type?");
3330 }
3331 
3334  return cast<FunctionDecl>(Info->getInstantiatedFrom());
3335 
3336  return nullptr;
3337 }
3338 
3340  return TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo *>();
3341 }
3342 
3343 void
3344 FunctionDecl::setInstantiationOfMemberFunction(ASTContext &C,
3345  FunctionDecl *FD,
3347  assert(TemplateOrSpecialization.isNull() &&
3348  "Member function is already a specialization");
3350  = new (C) MemberSpecializationInfo(FD, TSK);
3351  TemplateOrSpecialization = Info;
3352 }
3353 
3355  return TemplateOrSpecialization.dyn_cast<FunctionTemplateDecl *>();
3356 }
3357 
3359  TemplateOrSpecialization = Template;
3360 }
3361 
3363  // If the function is invalid, it can't be implicitly instantiated.
3364  if (isInvalidDecl())
3365  return false;
3366 
3367  switch (getTemplateSpecializationKind()) {
3368  case TSK_Undeclared:
3370  return false;
3371 
3373  return true;
3374 
3375  // It is possible to instantiate TSK_ExplicitSpecialization kind
3376  // if the FunctionDecl has a class scope specialization pattern.
3378  return getClassScopeSpecializationPattern() != nullptr;
3379 
3381  // Handled below.
3382  break;
3383  }
3384 
3385  // Find the actual template from which we will instantiate.
3386  const FunctionDecl *PatternDecl = getTemplateInstantiationPattern();
3387  bool HasPattern = false;
3388  if (PatternDecl)
3389  HasPattern = PatternDecl->hasBody(PatternDecl);
3390 
3391  // C++0x [temp.explicit]p9:
3392  // Except for inline functions, other explicit instantiation declarations
3393  // have the effect of suppressing the implicit instantiation of the entity
3394  // to which they refer.
3395  if (!HasPattern || !PatternDecl)
3396  return true;
3397 
3398  return PatternDecl->isInlined();
3399 }
3400 
3402  switch (getTemplateSpecializationKind()) {
3403  case TSK_Undeclared:
3405  return false;
3409  return true;
3410  }
3411  llvm_unreachable("All TSK values handled.");
3412 }
3413 
3415  // Handle class scope explicit specialization special case.
3417  if (auto *Spec = getClassScopeSpecializationPattern())
3418  return getDefinitionOrSelf(Spec);
3419  return nullptr;
3420  }
3421 
3422  // If this is a generic lambda call operator specialization, its
3423  // instantiation pattern is always its primary template's pattern
3424  // even if its primary template was instantiated from another
3425  // member template (which happens with nested generic lambdas).
3426  // Since a lambda's call operator's body is transformed eagerly,
3427  // we don't have to go hunting for a prototype definition template
3428  // (i.e. instantiated-from-member-template) to use as an instantiation
3429  // pattern.
3430 
3432  dyn_cast<CXXMethodDecl>(this))) {
3433  assert(getPrimaryTemplate() && "not a generic lambda call operator?");
3434  return getDefinitionOrSelf(getPrimaryTemplate()->getTemplatedDecl());
3435  }
3436 
3437  if (FunctionTemplateDecl *Primary = getPrimaryTemplate()) {
3438  while (Primary->getInstantiatedFromMemberTemplate()) {
3439  // If we have hit a point where the user provided a specialization of
3440  // this template, we're done looking.
3441  if (Primary->isMemberSpecialization())
3442  break;
3443  Primary = Primary->getInstantiatedFromMemberTemplate();
3444  }
3445 
3446  return getDefinitionOrSelf(Primary->getTemplatedDecl());
3447  }
3448 
3449  if (auto *MFD = getInstantiatedFromMemberFunction())
3450  return getDefinitionOrSelf(MFD);
3451 
3452  return nullptr;
3453 }
3454 
3457  = TemplateOrSpecialization
3458  .dyn_cast<FunctionTemplateSpecializationInfo*>()) {
3459  return Info->Template.getPointer();
3460  }
3461  return nullptr;
3462 }
3463 
3466 }
3467 
3470  return TemplateOrSpecialization
3471  .dyn_cast<FunctionTemplateSpecializationInfo *>();
3472 }
3473 
3474 const TemplateArgumentList *
3477  = TemplateOrSpecialization
3478  .dyn_cast<FunctionTemplateSpecializationInfo*>()) {
3479  return Info->TemplateArguments;
3480  }
3481  return nullptr;
3482 }
3483 
3487  = TemplateOrSpecialization
3488  .dyn_cast<FunctionTemplateSpecializationInfo*>()) {
3489  return Info->TemplateArgumentsAsWritten;
3490  }
3491  return nullptr;
3492 }
3493 
3494 void
3495 FunctionDecl::setFunctionTemplateSpecialization(ASTContext &C,
3496  FunctionTemplateDecl *Template,
3497  const TemplateArgumentList *TemplateArgs,
3498  void *InsertPos,
3500  const TemplateArgumentListInfo *TemplateArgsAsWritten,
3501  SourceLocation PointOfInstantiation) {
3502  assert(TSK != TSK_Undeclared &&
3503  "Must specify the type of function template specialization");
3505  = TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>();
3506  if (!Info)
3507  Info = FunctionTemplateSpecializationInfo::Create(C, this, Template, TSK,
3508  TemplateArgs,
3509  TemplateArgsAsWritten,
3510  PointOfInstantiation);
3511  TemplateOrSpecialization = Info;
3512  Template->addSpecialization(Info, InsertPos);
3513 }
3514 
3515 void
3517  const UnresolvedSetImpl &Templates,
3518  const TemplateArgumentListInfo &TemplateArgs) {
3519  assert(TemplateOrSpecialization.isNull());
3522  TemplateArgs);
3523  TemplateOrSpecialization = Info;
3524 }
3525 
3528  return TemplateOrSpecialization
3530 }
3531 
3534  ASTContext &Context, const UnresolvedSetImpl &Ts,
3535  const TemplateArgumentListInfo &TArgs) {
3536  void *Buffer = Context.Allocate(
3537  totalSizeToAlloc<TemplateArgumentLoc, FunctionTemplateDecl *>(
3538  TArgs.size(), Ts.size()));
3539  return new (Buffer) DependentFunctionTemplateSpecializationInfo(Ts, TArgs);
3540 }
3541 
3542 DependentFunctionTemplateSpecializationInfo::
3543 DependentFunctionTemplateSpecializationInfo(const UnresolvedSetImpl &Ts,
3544  const TemplateArgumentListInfo &TArgs)
3545  : AngleLocs(TArgs.getLAngleLoc(), TArgs.getRAngleLoc()) {
3546  NumTemplates = Ts.size();
3547  NumArgs = TArgs.size();
3548 
3549  FunctionTemplateDecl **TsArray = getTrailingObjects<FunctionTemplateDecl *>();
3550  for (unsigned I = 0, E = Ts.size(); I != E; ++I)
3551  TsArray[I] = cast<FunctionTemplateDecl>(Ts[I]->getUnderlyingDecl());
3552 
3553  TemplateArgumentLoc *ArgsArray = getTrailingObjects<TemplateArgumentLoc>();
3554  for (unsigned I = 0, E = TArgs.size(); I != E; ++I)
3555  new (&ArgsArray[I]) TemplateArgumentLoc(TArgs[I]);
3556 }
3557 
3559  // For a function template specialization, query the specialization
3560  // information object.
3562  = TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>();
3563  if (FTSInfo)
3564  return FTSInfo->getTemplateSpecializationKind();
3565 
3566  MemberSpecializationInfo *MSInfo
3567  = TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>();
3568  if (MSInfo)
3569  return MSInfo->getTemplateSpecializationKind();
3570 
3571  return TSK_Undeclared;
3572 }
3573 
3574 void
3576  SourceLocation PointOfInstantiation) {
3578  = TemplateOrSpecialization.dyn_cast<
3580  FTSInfo->setTemplateSpecializationKind(TSK);
3581  if (TSK != TSK_ExplicitSpecialization &&
3582  PointOfInstantiation.isValid() &&
3583  FTSInfo->getPointOfInstantiation().isInvalid()) {
3584  FTSInfo->setPointOfInstantiation(PointOfInstantiation);
3586  L->InstantiationRequested(this);
3587  }
3588  } else if (MemberSpecializationInfo *MSInfo
3589  = TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>()) {
3590  MSInfo->setTemplateSpecializationKind(TSK);
3591  if (TSK != TSK_ExplicitSpecialization &&
3592  PointOfInstantiation.isValid() &&
3593  MSInfo->getPointOfInstantiation().isInvalid()) {
3594  MSInfo->setPointOfInstantiation(PointOfInstantiation);
3596  L->InstantiationRequested(this);
3597  }
3598  } else
3599  llvm_unreachable("Function cannot have a template specialization kind");
3600 }
3601 
3604  = TemplateOrSpecialization.dyn_cast<
3606  return FTSInfo->getPointOfInstantiation();
3607  else if (MemberSpecializationInfo *MSInfo
3608  = TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>())
3609  return MSInfo->getPointOfInstantiation();
3610 
3611  return SourceLocation();
3612 }
3613 
3615  if (Decl::isOutOfLine())
3616  return true;
3617 
3618  // If this function was instantiated from a member function of a
3619  // class template, check whether that member function was defined out-of-line.
3621  const FunctionDecl *Definition;
3622  if (FD->hasBody(Definition))
3623  return Definition->isOutOfLine();
3624  }
3625 
3626  // If this function was instantiated from a function template,
3627  // check whether that function template was defined out-of-line.
3628  if (FunctionTemplateDecl *FunTmpl = getPrimaryTemplate()) {
3629  const FunctionDecl *Definition;
3630  if (FunTmpl->getTemplatedDecl()->hasBody(Definition))
3631  return Definition->isOutOfLine();
3632  }
3633 
3634  return false;
3635 }
3636 
3638  return SourceRange(getOuterLocStart(), EndRangeLoc);
3639 }
3640 
3642  IdentifierInfo *FnInfo = getIdentifier();
3643 
3644  if (!FnInfo)
3645  return 0;
3646 
3647  // Builtin handling.
3648  switch (getBuiltinID()) {
3649  case Builtin::BI__builtin_memset:
3650  case Builtin::BI__builtin___memset_chk:
3651  case Builtin::BImemset:
3652  return Builtin::BImemset;
3653 
3654  case Builtin::BI__builtin_memcpy:
3655  case Builtin::BI__builtin___memcpy_chk:
3656  case Builtin::BImemcpy:
3657  return Builtin::BImemcpy;
3658 
3659  case Builtin::BI__builtin_memmove:
3660  case Builtin::BI__builtin___memmove_chk:
3661  case Builtin::BImemmove:
3662  return Builtin::BImemmove;
3663 
3664  case Builtin::BIstrlcpy:
3665  case Builtin::BI__builtin___strlcpy_chk:
3666  return Builtin::BIstrlcpy;
3667 
3668  case Builtin::BIstrlcat:
3669  case Builtin::BI__builtin___strlcat_chk:
3670  return Builtin::BIstrlcat;
3671 
3672  case Builtin::BI__builtin_memcmp:
3673  case Builtin::BImemcmp:
3674  return Builtin::BImemcmp;
3675 
3676  case Builtin::BI__builtin_strncpy:
3677  case Builtin::BI__builtin___strncpy_chk:
3678  case Builtin::BIstrncpy:
3679  return Builtin::BIstrncpy;
3680 
3681  case Builtin::BI__builtin_strncmp:
3682  case Builtin::BIstrncmp:
3683  return Builtin::BIstrncmp;
3684 
3685  case Builtin::BI__builtin_strncasecmp:
3686  case Builtin::BIstrncasecmp:
3687  return Builtin::BIstrncasecmp;
3688 
3689  case Builtin::BI__builtin_strncat:
3690  case Builtin::BI__builtin___strncat_chk:
3691  case Builtin::BIstrncat:
3692  return Builtin::BIstrncat;
3693 
3694  case Builtin::BI__builtin_strndup:
3695  case Builtin::BIstrndup:
3696  return Builtin::BIstrndup;
3697 
3698  case Builtin::BI__builtin_strlen:
3699  case Builtin::BIstrlen:
3700  return Builtin::BIstrlen;
3701 
3702  case Builtin::BI__builtin_bzero:
3703  case Builtin::BIbzero:
3704  return Builtin::BIbzero;
3705 
3706  default:
3707  if (isExternC()) {
3708  if (FnInfo->isStr("memset"))
3709  return Builtin::BImemset;
3710  else if (FnInfo->isStr("memcpy"))
3711  return Builtin::BImemcpy;
3712  else if (FnInfo->isStr("memmove"))
3713  return Builtin::BImemmove;
3714  else if (FnInfo->isStr("memcmp"))
3715  return Builtin::BImemcmp;
3716  else if (FnInfo->isStr("strncpy"))
3717  return Builtin::BIstrncpy;
3718  else if (FnInfo->isStr("strncmp"))
3719  return Builtin::BIstrncmp;
3720  else if (FnInfo->isStr("strncasecmp"))
3721  return Builtin::BIstrncasecmp;
3722  else if (FnInfo->isStr("strncat"))
3723  return Builtin::BIstrncat;
3724  else if (FnInfo->isStr("strndup"))
3725  return Builtin::BIstrndup;
3726  else if (FnInfo->isStr("strlen"))
3727  return Builtin::BIstrlen;
3728  else if (FnInfo->isStr("bzero"))
3729  return Builtin::BIbzero;
3730  }
3731  break;
3732  }
3733  return 0;
3734 }
3735 
3736 unsigned FunctionDecl::getODRHash() const {
3737  assert(hasODRHash());
3738  return ODRHash;
3739 }
3740 
3742  if (hasODRHash())
3743  return ODRHash;
3744 
3745  if (auto *FT = getInstantiatedFromMemberFunction()) {
3746  setHasODRHash(true);
3747  ODRHash = FT->getODRHash();
3748  return ODRHash;
3749  }
3750 
3751  class ODRHash Hash;
3752  Hash.AddFunctionDecl(this);
3753  setHasODRHash(true);
3754  ODRHash = Hash.CalculateHash();
3755  return ODRHash;
3756 }
3757 
3758 //===----------------------------------------------------------------------===//
3759 // FieldDecl Implementation
3760 //===----------------------------------------------------------------------===//
3761 
3763  SourceLocation StartLoc, SourceLocation IdLoc,
3765  TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3766  InClassInitStyle InitStyle) {
3767  return new (C, DC) FieldDecl(Decl::Field, DC, StartLoc, IdLoc, Id, T, TInfo,
3768  BW, Mutable, InitStyle);
3769 }
3770 
3772  return new (C, ID) FieldDecl(Field, nullptr, SourceLocation(),
3773  SourceLocation(), nullptr, QualType(), nullptr,
3774  nullptr, false, ICIS_NoInit);
3775 }
3776 
3778  if (!isImplicit() || getDeclName())
3779  return false;
3780 
3781  if (const auto *Record = getType()->getAs<RecordType>())
3782  return Record->getDecl()->isAnonymousStructOrUnion();
3783 
3784  return false;
3785 }
3786 
3787 unsigned FieldDecl::getBitWidthValue(const ASTContext &Ctx) const {
3788  assert(isBitField() && "not a bitfield");
3789  return getBitWidth()->EvaluateKnownConstInt(Ctx).getZExtValue();
3790 }
3791 
3793  return isUnnamedBitfield() && !getBitWidth()->isValueDependent() &&
3794  getBitWidthValue(Ctx) == 0;
3795 }
3796 
3797 unsigned FieldDecl::getFieldIndex() const {
3798  const FieldDecl *Canonical = getCanonicalDecl();
3799  if (Canonical != this)
3800  return Canonical->getFieldIndex();
3801 
3802  if (CachedFieldIndex) return CachedFieldIndex - 1;
3803 
3804  unsigned Index = 0;
3805  const RecordDecl *RD = getParent()->getDefinition();
3806  assert(RD && "requested index for field of struct with no definition");
3807 
3808  for (auto *Field : RD->fields()) {
3809  Field->getCanonicalDecl()->CachedFieldIndex = Index + 1;
3810  ++Index;
3811  }
3812 
3813  assert(CachedFieldIndex && "failed to find field in parent");
3814  return CachedFieldIndex - 1;
3815 }
3816 
3818  const Expr *FinalExpr = getInClassInitializer();
3819  if (!FinalExpr)
3820  FinalExpr = getBitWidth();
3821  if (FinalExpr)
3822  return SourceRange(getInnerLocStart(), FinalExpr->getEndLoc());
3824 }
3825 
3827  assert((getParent()->isLambda() || getParent()->isCapturedRecord()) &&
3828  "capturing type in non-lambda or captured record.");
3829  assert(InitStorage.getInt() == ISK_NoInit &&
3830  InitStorage.getPointer() == nullptr &&
3831  "bit width, initializer or captured type already set");
3832  InitStorage.setPointerAndInt(const_cast<VariableArrayType *>(VLAType),
3833  ISK_CapturedVLAType);
3834 }
3835 
3836 //===----------------------------------------------------------------------===//
3837 // TagDecl Implementation
3838 //===----------------------------------------------------------------------===//
3839 
3841  SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3842  SourceLocation StartL)
3843  : TypeDecl(DK, DC, L, Id, StartL), DeclContext(DK), redeclarable_base(C),
3844  TypedefNameDeclOrQualifier((TypedefNameDecl *)nullptr) {
3845  assert((DK != Enum || TK == TTK_Enum) &&
3846  "EnumDecl not matched with TTK_Enum");
3847  setPreviousDecl(PrevDecl);
3848  setTagKind(TK);
3849  setCompleteDefinition(false);
3850  setBeingDefined(false);
3851  setEmbeddedInDeclarator(false);
3852  setFreeStanding(false);
3854 }
3855 
3857  return getTemplateOrInnerLocStart(this);
3858 }
3859 
3861  SourceLocation RBraceLoc = BraceRange.getEnd();
3862  SourceLocation E = RBraceLoc.isValid() ? RBraceLoc : getLocation();
3863  return SourceRange(getOuterLocStart(), E);
3864 }
3865 
3867 
3869  TypedefNameDeclOrQualifier = TDD;
3870  if (const Type *T = getTypeForDecl()) {
3871  (void)T;
3872  assert(T->isLinkageValid());
3873  }
3874  assert(isLinkageValid());
3875 }
3876 
3878  setBeingDefined(true);
3879 
3880  if (auto *D = dyn_cast<CXXRecordDecl>(this)) {
3881  struct CXXRecordDecl::DefinitionData *Data =
3882  new (getASTContext()) struct CXXRecordDecl::DefinitionData(D);
3883  for (auto I : redecls())
3884  cast<CXXRecordDecl>(I)->DefinitionData = Data;
3885  }
3886 }
3887 
3889  assert((!isa<CXXRecordDecl>(this) ||
3890  cast<CXXRecordDecl>(this)->hasDefinition()) &&
3891  "definition completed but not started");
3892 
3893  setCompleteDefinition(true);
3894  setBeingDefined(false);
3895 
3897  L->CompletedTagDefinition(this);
3898 }
3899 
3901  if (isCompleteDefinition())
3902  return const_cast<TagDecl *>(this);
3903 
3904  // If it's possible for us to have an out-of-date definition, check now.
3905  if (mayHaveOutOfDateDef()) {
3906  if (IdentifierInfo *II = getIdentifier()) {
3907  if (II->isOutOfDate()) {
3908  updateOutOfDate(*II);
3909  }
3910  }
3911  }
3912 
3913  if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(this))
3914  return CXXRD->getDefinition();
3915 
3916  for (auto R : redecls())
3917  if (R->isCompleteDefinition())
3918  return R;
3919 
3920  return nullptr;
3921 }
3922 
3924  if (QualifierLoc) {
3925  // Make sure the extended qualifier info is allocated.
3926  if (!hasExtInfo())
3927  TypedefNameDeclOrQualifier = new (getASTContext()) ExtInfo;
3928  // Set qualifier info.
3929  getExtInfo()->QualifierLoc = QualifierLoc;
3930  } else {
3931  // Here Qualifier == 0, i.e., we are removing the qualifier (if any).
3932  if (hasExtInfo()) {
3933  if (getExtInfo()->NumTemplParamLists == 0) {
3934  getASTContext().Deallocate(getExtInfo());
3935  TypedefNameDeclOrQualifier = (TypedefNameDecl *)nullptr;
3936  }
3937  else
3938  getExtInfo()->QualifierLoc = QualifierLoc;
3939  }
3940  }
3941 }
3942 
3944  ASTContext &Context, ArrayRef<TemplateParameterList *> TPLists) {
3945  assert(!TPLists.empty());
3946  // Make sure the extended decl info is allocated.
3947  if (!hasExtInfo())
3948  // Allocate external info struct.
3949  TypedefNameDeclOrQualifier = new (getASTContext()) ExtInfo;
3950  // Set the template parameter lists info.
3951  getExtInfo()->setTemplateParameterListsInfo(Context, TPLists);
3952 }
3953 
3954 //===----------------------------------------------------------------------===//
3955 // EnumDecl Implementation
3956 //===----------------------------------------------------------------------===//
3957 
3958 EnumDecl::EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3959  SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
3960  bool Scoped, bool ScopedUsingClassTag, bool Fixed)
3961  : TagDecl(Enum, TTK_Enum, C, DC, IdLoc, Id, PrevDecl, StartLoc) {
3962  assert(Scoped || !ScopedUsingClassTag);
3963  IntegerType = nullptr;
3964  setNumPositiveBits(0);
3965  setNumNegativeBits(0);
3966  setScoped(Scoped);
3967  setScopedUsingClassTag(ScopedUsingClassTag);
3968  setFixed(Fixed);
3969  setHasODRHash(false);
3970  ODRHash = 0;
3971 }
3972 
3973 void EnumDecl::anchor() {}
3974 
3976  SourceLocation StartLoc, SourceLocation IdLoc,
3977  IdentifierInfo *Id,
3978  EnumDecl *PrevDecl, bool IsScoped,
3979  bool IsScopedUsingClassTag, bool IsFixed) {
3980  auto *Enum = new (C, DC) EnumDecl(C, DC, StartLoc, IdLoc, Id, PrevDecl,
3981  IsScoped, IsScopedUsingClassTag, IsFixed);
3982  Enum->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
3983  C.getTypeDeclType(Enum, PrevDecl);
3984  return Enum;
3985 }
3986 
3988  EnumDecl *Enum =
3989  new (C, ID) EnumDecl(C, nullptr, SourceLocation(), SourceLocation(),
3990  nullptr, nullptr, false, false, false);
3991  Enum->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
3992  return Enum;
3993 }
3994 
3996  if (const TypeSourceInfo *TI = getIntegerTypeSourceInfo())
3997  return TI->getTypeLoc().getSourceRange();
3998  return SourceRange();
3999 }
4000 
4002  QualType NewPromotionType,
4003  unsigned NumPositiveBits,
4004  unsigned NumNegativeBits) {
4005  assert(!isCompleteDefinition() && "Cannot redefine enums!");
4006  if (!IntegerType)
4007  IntegerType = NewType.getTypePtr();
4008  PromotionType = NewPromotionType;
4009  setNumPositiveBits(NumPositiveBits);
4010  setNumNegativeBits(NumNegativeBits);
4012 }
4013 
4014 bool EnumDecl::isClosed() const {
4015  if (const auto *A = getAttr<EnumExtensibilityAttr>())
4016  return A->getExtensibility() == EnumExtensibilityAttr::Closed;
4017  return true;
4018 }
4019 
4021  return isClosed() && hasAttr<FlagEnumAttr>();
4022 }
4023 
4025  return isClosed() && !hasAttr<FlagEnumAttr>();
4026 }
4027 
4029  if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo())
4030  return MSI->getTemplateSpecializationKind();
4031 
4032  return TSK_Undeclared;
4033 }
4034 
4036  SourceLocation PointOfInstantiation) {
4037  MemberSpecializationInfo *MSI = getMemberSpecializationInfo();
4038  assert(MSI && "Not an instantiated member enumeration?");
4040  if (TSK != TSK_ExplicitSpecialization &&
4041  PointOfInstantiation.isValid() &&
4043  MSI->setPointOfInstantiation(PointOfInstantiation);
4044 }
4045 
4047  if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) {
4048  if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) {
4049  EnumDecl *ED = getInstantiatedFromMemberEnum();
4050  while (auto *NewED = ED->getInstantiatedFromMemberEnum())
4051  ED = NewED;
4052  return getDefinitionOrSelf(ED);
4053  }
4054  }
4055 
4057  "couldn't find pattern for enum instantiation");
4058  return nullptr;
4059 }
4060 
4062  if (SpecializationInfo)
4063  return cast<EnumDecl>(SpecializationInfo->getInstantiatedFrom());
4064 
4065  return nullptr;
4066 }
4067 
4068 void EnumDecl::setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
4070  assert(!SpecializationInfo && "Member enum is already a specialization");
4071  SpecializationInfo = new (C) MemberSpecializationInfo(ED, TSK);
4072 }
4073 
4075  if (hasODRHash())
4076  return ODRHash;
4077 
4078  class ODRHash Hash;
4079  Hash.AddEnumDecl(this);
4080  setHasODRHash(true);
4081  ODRHash = Hash.CalculateHash();
4082  return ODRHash;
4083 }
4084 
4085 //===----------------------------------------------------------------------===//
4086 // RecordDecl Implementation
4087 //===----------------------------------------------------------------------===//
4088 
4090  DeclContext *DC, SourceLocation StartLoc,
4091  SourceLocation IdLoc, IdentifierInfo *Id,
4092  RecordDecl *PrevDecl)
4093  : TagDecl(DK, TK, C, DC, IdLoc, Id, PrevDecl, StartLoc) {
4094  assert(classof(static_cast<Decl *>(this)) && "Invalid Kind!");
4097  setHasObjectMember(false);
4098  setHasVolatileMember(false);
4105 }
4106 
4108  SourceLocation StartLoc, SourceLocation IdLoc,
4109  IdentifierInfo *Id, RecordDecl* PrevDecl) {
4110  RecordDecl *R = new (C, DC) RecordDecl(Record, TK, C, DC,
4111  StartLoc, IdLoc, Id, PrevDecl);
4112  R->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
4113 
4114  C.getTypeDeclType(R, PrevDecl);
4115  return R;
4116 }
4117 
4119  RecordDecl *R =
4120  new (C, ID) RecordDecl(Record, TTK_Struct, C, nullptr, SourceLocation(),
4121  SourceLocation(), nullptr, nullptr);
4122  R->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
4123  return R;
4124 }
4125 
4127  return isImplicit() && getDeclName() && getDeclContext()->isRecord() &&
4128  cast<RecordDecl>(getDeclContext())->getDeclName() == getDeclName();
4129 }
4130 
4131 bool RecordDecl::isLambda() const {
4132  if (auto RD = dyn_cast<CXXRecordDecl>(this))
4133  return RD->isLambda();
4134  return false;
4135 }
4136 
4138  return hasAttr<CapturedRecordAttr>();
4139 }
4140 
4142  addAttr(CapturedRecordAttr::CreateImplicit(getASTContext()));
4143 }
4144 
4147  LoadFieldsFromExternalStorage();
4148 
4150 }
4151 
4152 /// completeDefinition - Notes that the definition of this type is now
4153 /// complete.
4155  assert(!isCompleteDefinition() && "Cannot redefine record!");
4157 }
4158 
4159 /// isMsStruct - Get whether or not this record uses ms_struct layout.
4160 /// This which can be turned on with an attribute, pragma, or the
4161 /// -mms-bitfields command-line option.
4162 bool RecordDecl::isMsStruct(const ASTContext &C) const {
4163  return hasAttr<MSStructAttr>() || C.getLangOpts().MSBitfields == 1;
4164 }
4165 
4166 void RecordDecl::LoadFieldsFromExternalStorage() const {
4168  assert(hasExternalLexicalStorage() && Source && "No external storage?");
4169 
4170  // Notify that we have a RecordDecl doing some initialization.
4171  ExternalASTSource::Deserializing TheFields(Source);
4172 
4173  SmallVector<Decl*, 64> Decls;
4175  Source->FindExternalLexicalDecls(this, [](Decl::Kind K) {
4177  }, Decls);
4178 
4179 #ifndef NDEBUG
4180  // Check that all decls we got were FieldDecls.
4181  for (unsigned i=0, e=Decls.size(); i != e; ++i)
4182  assert(isa<FieldDecl>(Decls[i]) || isa<IndirectFieldDecl>(Decls[i]));
4183 #endif
4184 
4185  if (Decls.empty())
4186  return;
4187 
4188  std::tie(FirstDecl, LastDecl) = BuildDeclChain(Decls,
4189  /*FieldsAlreadyLoaded=*/false);
4190 }
4191 
4192 bool RecordDecl::mayInsertExtraPadding(bool EmitRemark) const {
4193  ASTContext &Context = getASTContext();
4194  const SanitizerMask EnabledAsanMask = Context.getLangOpts().Sanitize.Mask &
4195  (SanitizerKind::Address | SanitizerKind::KernelAddress);
4196  if (!EnabledAsanMask || !Context.getLangOpts().SanitizeAddressFieldPadding)
4197  return false;
4198  const auto &Blacklist = Context.getSanitizerBlacklist();
4199  const auto *CXXRD = dyn_cast<CXXRecordDecl>(this);
4200  // We may be able to relax some of these requirements.
4201  int ReasonToReject = -1;
4202  if (!CXXRD || CXXRD->isExternCContext())
4203  ReasonToReject = 0; // is not C++.
4204  else if (CXXRD->hasAttr<PackedAttr>())
4205  ReasonToReject = 1; // is packed.
4206  else if (CXXRD->isUnion())
4207  ReasonToReject = 2; // is a union.
4208  else if (CXXRD->isTriviallyCopyable())
4209  ReasonToReject = 3; // is trivially copyable.
4210  else if (CXXRD->hasTrivialDestructor())
4211  ReasonToReject = 4; // has trivial destructor.
4212  else if (CXXRD->isStandardLayout())
4213  ReasonToReject = 5; // is standard layout.
4214  else if (Blacklist.isBlacklistedLocation(EnabledAsanMask, getLocation(),
4215  "field-padding"))
4216  ReasonToReject = 6; // is in a blacklisted file.
4217  else if (Blacklist.isBlacklistedType(EnabledAsanMask,
4219  "field-padding"))
4220  ReasonToReject = 7; // is blacklisted.
4221 
4222  if (EmitRemark) {
4223  if (ReasonToReject >= 0)
4224  Context.getDiagnostics().Report(
4225  getLocation(),
4226  diag::remark_sanitize_address_insert_extra_padding_rejected)
4227  << getQualifiedNameAsString() << ReasonToReject;
4228  else
4229  Context.getDiagnostics().Report(
4230  getLocation(),
4231  diag::remark_sanitize_address_insert_extra_padding_accepted)
4233  }
4234  return ReasonToReject < 0;
4235 }
4236 
4238  for (const auto *I : fields()) {
4239  if (I->getIdentifier())
4240  return I;
4241 
4242  if (const auto *RT = I->getType()->getAs<RecordType>())
4243  if (const FieldDecl *NamedDataMember =
4244  RT->getDecl()->findFirstNamedDataMember())
4245  return NamedDataMember;
4246  }
4247 
4248  // We didn't find a named data member.
4249  return nullptr;
4250 }
4251 
4252 //===----------------------------------------------------------------------===//
4253 // BlockDecl Implementation
4254 //===----------------------------------------------------------------------===//
4255 
4257  : Decl(Block, DC, CaretLoc), DeclContext(Block) {
4258  setIsVariadic(false);
4259  setCapturesCXXThis(false);
4262  setDoesNotEscape(false);
4263 }
4264 
4266  assert(!ParamInfo && "Already has param info!");
4267 
4268  // Zero params -> null pointer.
4269  if (!NewParamInfo.empty()) {
4270  NumParams = NewParamInfo.size();
4271  ParamInfo = new (getASTContext()) ParmVarDecl*[NewParamInfo.size()];
4272  std::copy(NewParamInfo.begin(), NewParamInfo.end(), ParamInfo);
4273  }
4274 }
4275 
4277  bool CapturesCXXThis) {
4278  this->setCapturesCXXThis(CapturesCXXThis);
4279  this->NumCaptures = Captures.size();
4280 
4281  if (Captures.empty()) {
4282  this->Captures = nullptr;
4283  return;
4284  }
4285 
4286  this->Captures = Captures.copy(Context).data();
4287 }
4288 
4289 bool BlockDecl::capturesVariable(const VarDecl *variable) const {
4290  for (const auto &I : captures())
4291  // Only auto vars can be captured, so no redeclaration worries.
4292  if (I.getVariable() == variable)
4293  return true;
4294 
4295  return false;
4296 }
4297 
4299  return SourceRange(getLocation(), Body ? Body->getEndLoc() : getLocation());
4300 }
4301 
4302 //===----------------------------------------------------------------------===//
4303 // Other Decl Allocation/Deallocation Method Implementations
4304 //===----------------------------------------------------------------------===//
4305 
4306 void TranslationUnitDecl::anchor() {}
4307 
4309  return new (C, (DeclContext *)nullptr) TranslationUnitDecl(C);
4310 }
4311 
4312 void PragmaCommentDecl::anchor() {}
4313 
4315  TranslationUnitDecl *DC,
4316  SourceLocation CommentLoc,
4317  PragmaMSCommentKind CommentKind,
4318  StringRef Arg) {
4319  PragmaCommentDecl *PCD =
4320  new (C, DC, additionalSizeToAlloc<char>(Arg.size() + 1))
4321  PragmaCommentDecl(DC, CommentLoc, CommentKind);
4322  memcpy(PCD->getTrailingObjects<char>(), Arg.data(), Arg.size());
4323  PCD->getTrailingObjects<char>()[Arg.size()] = '\0';
4324  return PCD;
4325 }
4326 
4328  unsigned ID,
4329  unsigned ArgSize) {
4330  return new (C, ID, additionalSizeToAlloc<char>(ArgSize + 1))
4332 }
4333 
4334 void PragmaDetectMismatchDecl::anchor() {}
4335 
4338  SourceLocation Loc, StringRef Name,
4339  StringRef Value) {
4340  size_t ValueStart = Name.size() + 1;
4341  PragmaDetectMismatchDecl *PDMD =
4342  new (C, DC, additionalSizeToAlloc<char>(ValueStart + Value.size() + 1))
4343  PragmaDetectMismatchDecl(DC, Loc, ValueStart);
4344  memcpy(PDMD->getTrailingObjects<char>(), Name.data(), Name.size());
4345  PDMD->getTrailingObjects<char>()[Name.size()] = '\0';
4346  memcpy(PDMD->getTrailingObjects<char>() + ValueStart, Value.data(),
4347  Value.size());
4348  PDMD->getTrailingObjects<char>()[ValueStart + Value.size()] = '\0';
4349  return PDMD;
4350 }
4351 
4354  unsigned NameValueSize) {
4355  return new (C, ID, additionalSizeToAlloc<char>(NameValueSize + 1))
4357 }
4358 
4359 void ExternCContextDecl::anchor() {}
4360 
4362  TranslationUnitDecl *DC) {
4363  return new (C, DC) ExternCContextDecl(DC);
4364 }
4365 
4366 void LabelDecl::anchor() {}
4367 
4369  SourceLocation IdentL, IdentifierInfo *II) {
4370  return new (C, DC) LabelDecl(DC, IdentL, II, nullptr, IdentL);
4371 }
4372 
4374  SourceLocation IdentL, IdentifierInfo *II,
4375  SourceLocation GnuLabelL) {
4376  assert(GnuLabelL != IdentL && "Use this only for GNU local labels");
4377  return new (C, DC) LabelDecl(DC, IdentL, II, nullptr, GnuLabelL);
4378 }
4379 
4381  return new (C, ID) LabelDecl(nullptr, SourceLocation(), nullptr, nullptr,
4382  SourceLocation());
4383 }
4384 
4385 void LabelDecl::setMSAsmLabel(StringRef Name) {
4386  char *Buffer = new (getASTContext(), 1) char[Name.size() + 1];
4387  memcpy(Buffer, Name.data(), Name.size());
4388  Buffer[Name.size()] = '\0';
4389  MSAsmName = Buffer;
4390 }
4391 
4392 void ValueDecl::anchor() {}
4393 
4394 bool ValueDecl::isWeak() const {
4395  for (const auto *I : attrs())
4396  if (isa<WeakAttr>(I) || isa<WeakRefAttr>(I))
4397  return true;
4398 
4399  return isWeakImported();
4400 }
4401 
4402 void ImplicitParamDecl::anchor() {}
4403 
4405  SourceLocation IdLoc,
4407  ImplicitParamKind ParamKind) {
4408  return new (C, DC) ImplicitParamDecl(C, DC, IdLoc, Id, Type, ParamKind);
4409 }
4410 
4412  ImplicitParamKind ParamKind) {
4413  return new (C, nullptr) ImplicitParamDecl(C, Type, ParamKind);
4414 }
4415 
4417  unsigned ID) {
4418  return new (C, ID) ImplicitParamDecl(C, QualType(), ImplicitParamKind::Other);
4419 }
4420 
4422  SourceLocation StartLoc,
4423  const DeclarationNameInfo &NameInfo,
4424  QualType T, TypeSourceInfo *TInfo,
4425  StorageClass SC,
4426  bool isInlineSpecified,
4427  bool hasWrittenPrototype,
4428  bool isConstexprSpecified) {
4429  FunctionDecl *New =
4430  new (C, DC) FunctionDecl(Function, C, DC, StartLoc, NameInfo, T, TInfo,
4431  SC, isInlineSpecified, isConstexprSpecified);
4432  New->setHasWrittenPrototype(hasWrittenPrototype);
4433  return New;
4434 }
4435 
4437  return new (C, ID) FunctionDecl(Function, C, nullptr, SourceLocation(),
4438  DeclarationNameInfo(), QualType(), nullptr,
4439  SC_None, false, false);
4440 }
4441 
4443  return new (C, DC) BlockDecl(DC, L);
4444 }
4445 
4447  return new (C, ID) BlockDecl(nullptr, SourceLocation());
4448 }
4449 
4450 CapturedDecl::CapturedDecl(DeclContext *DC, unsigned NumParams)
4451  : Decl(Captured, DC, SourceLocation()), DeclContext(Captured),
4452  NumParams(NumParams), ContextParam(0), BodyAndNothrow(nullptr, false) {}
4453 
4455  unsigned NumParams) {
4456  return new (C, DC, additionalSizeToAlloc<ImplicitParamDecl *>(NumParams))
4457  CapturedDecl(DC, NumParams);
4458 }
4459 
4461  unsigned NumParams) {
4462  return new (C, ID, additionalSizeToAlloc<ImplicitParamDecl *>(NumParams))
4463  CapturedDecl(nullptr, NumParams);
4464 }
4465 
4466 Stmt *CapturedDecl::getBody() const { return BodyAndNothrow.getPointer(); }
4467 void CapturedDecl::setBody(Stmt *B) { BodyAndNothrow.setPointer(B); }
4468 
4469 bool CapturedDecl::isNothrow() const { return BodyAndNothrow.getInt(); }
4470 void CapturedDecl::setNothrow(bool Nothrow) { BodyAndNothrow.setInt(Nothrow); }
4471 
4473  SourceLocation L,
4474  IdentifierInfo *Id, QualType T,
4475  Expr *E, const llvm::APSInt &V) {
4476  return new (C, CD) EnumConstantDecl(CD, L, Id, T, E, V);
4477 }
4478 
4481  return new (C, ID) EnumConstantDecl(nullptr, SourceLocation(), nullptr,
4482  QualType(), nullptr, llvm::APSInt());
4483 }
4484 
4485 void IndirectFieldDecl::anchor() {}
4486 
4487 IndirectFieldDecl::IndirectFieldDecl(ASTContext &C, DeclContext *DC,
4489  QualType T,
4491  : ValueDecl(IndirectField, DC, L, N, T), Chaining(CH.data()),
4492  ChainingSize(CH.size()) {
4493  // In C++, indirect field declarations conflict with tag declarations in the
4494  // same scope, so add them to IDNS_Tag so that tag redeclaration finds them.
4495  if (C.getLangOpts().CPlusPlus)
4497 }
4498 
4501  IdentifierInfo *Id, QualType T,
4503  return new (C, DC) IndirectFieldDecl(C, DC, L, Id, T, CH);
4504 }
4505 
4507  unsigned ID) {
4508  return new (C, ID) IndirectFieldDecl(C, nullptr, SourceLocation(),
4509  DeclarationName(), QualType(), None);
4510 }
4511 
4514  if (Init)
4515  End = Init->getEndLoc();
4516  return SourceRange(getLocation(), End);
4517 }
4518 
4519 void TypeDecl::anchor() {}
4520 
4522  SourceLocation StartLoc, SourceLocation IdLoc,
4523  IdentifierInfo *Id, TypeSourceInfo *TInfo) {
4524  return new (C, DC) TypedefDecl(C, DC, StartLoc, IdLoc, Id, TInfo);
4525 }
4526 
4527 void TypedefNameDecl::anchor() {}
4528 
4530  if (auto *TT = getTypeSourceInfo()->getType()->getAs<TagType>()) {
4531  auto *OwningTypedef = TT->getDecl()->getTypedefNameForAnonDecl();
4532  auto *ThisTypedef = this;
4533  if (AnyRedecl && OwningTypedef) {
4534  OwningTypedef = OwningTypedef->getCanonicalDecl();
4535  ThisTypedef = ThisTypedef->getCanonicalDecl();
4536  }
4537  if (OwningTypedef == ThisTypedef)
4538  return TT->getDecl();
4539  }
4540 
4541  return nullptr;
4542 }
4543 
4544 bool TypedefNameDecl::isTransparentTagSlow() const {
4545  auto determineIsTransparent = [&]() {
4546  if (auto *TT = getUnderlyingType()->getAs<TagType>()) {
4547  if (auto *TD = TT->getDecl()) {
4548  if (TD->getName() != getName())
4549  return false;
4550  SourceLocation TTLoc = getLocation();
4551  SourceLocation TDLoc = TD->getLocation();
4552  if (!TTLoc.isMacroID() || !TDLoc.isMacroID())
4553  return false;
4555  return SM.getSpellingLoc(TTLoc) == SM.getSpellingLoc(TDLoc);
4556  }
4557  }
4558  return false;
4559  };
4560 
4561  bool isTransparent = determineIsTransparent();
4562  MaybeModedTInfo.setInt((isTransparent << 1) | 1);
4563  return isTransparent;
4564 }
4565 
4567  return new (C, ID) TypedefDecl(C, nullptr, SourceLocation(), SourceLocation(),
4568  nullptr, nullptr);
4569 }
4570 
4572  SourceLocation StartLoc,
4573  SourceLocation IdLoc, IdentifierInfo *Id,
4574  TypeSourceInfo *TInfo) {
4575  return new (C, DC) TypeAliasDecl(C, DC, StartLoc, IdLoc, Id, TInfo);
4576 }
4577 
4579  return new (C, ID) TypeAliasDecl(C, nullptr, SourceLocation(),
4580  SourceLocation(), nullptr, nullptr);
4581 }
4582 
4584  SourceLocation RangeEnd = getLocation();
4585  if (TypeSourceInfo *TInfo = getTypeSourceInfo()) {
4586  if (typeIsPostfix(TInfo->getType()))
4587  RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd();
4588  }
4589  return SourceRange(getBeginLoc(), RangeEnd);
4590 }
4591 
4593  SourceLocation RangeEnd = getBeginLoc();
4594  if (TypeSourceInfo *TInfo = getTypeSourceInfo())
4595  RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd();
4596  return SourceRange(getBeginLoc(), RangeEnd);
4597 }
4598 
4599 void FileScopeAsmDecl::anchor() {}
4600 
4602  StringLiteral *Str,
4603  SourceLocation AsmLoc,
4604  SourceLocation RParenLoc) {
4605  return new (C, DC) FileScopeAsmDecl(DC, Str, AsmLoc, RParenLoc);
4606 }
4607 
4609  unsigned ID) {
4610  return new (C, ID) FileScopeAsmDecl(nullptr, nullptr, SourceLocation(),
4611  SourceLocation());
4612 }
4613 
4614 void EmptyDecl::anchor() {}
4615 
4617  return new (C, DC) EmptyDecl(DC, L);
4618 }
4619 
4621  return new (C, ID) EmptyDecl(nullptr, SourceLocation());
4622 }
4623 
4624 //===----------------------------------------------------------------------===//
4625 // ImportDecl Implementation
4626 //===----------------------------------------------------------------------===//
4627 
4628 /// Retrieve the number of module identifiers needed to name the given
4629 /// module.
4630 static unsigned getNumModuleIdentifiers(Module *Mod) {
4631  unsigned Result = 1;
4632  while (Mod->Parent) {
4633  Mod = Mod->Parent;
4634  ++Result;
4635  }
4636  return Result;
4637 }
4638 
4639 ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
4640  Module *Imported,
4641  ArrayRef<SourceLocation> IdentifierLocs)
4642  : Decl(Import, DC, StartLoc), ImportedAndComplete(Imported, true) {
4643  assert(getNumModuleIdentifiers(Imported) == IdentifierLocs.size());
4644  auto *StoredLocs = getTrailingObjects<SourceLocation>();
4645  std::uninitialized_copy(IdentifierLocs.begin(), IdentifierLocs.end(),
4646  StoredLocs);
4647 }
4648 
4649 ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
4650  Module *Imported, SourceLocation EndLoc)
4651  : Decl(Import, DC, StartLoc), ImportedAndComplete(Imported, false) {
4652  *getTrailingObjects<SourceLocation>() = EndLoc;
4653 }
4654 
4656  SourceLocation StartLoc, Module *Imported,
4657  ArrayRef<SourceLocation> IdentifierLocs) {
4658  return new (C, DC,
4659  additionalSizeToAlloc<SourceLocation>(IdentifierLocs.size()))
4660  ImportDecl(DC, StartLoc, Imported, IdentifierLocs);
4661 }
4662 
4664  SourceLocation StartLoc,
4665  Module *Imported,
4666  SourceLocation EndLoc) {
4667  ImportDecl *Import = new (C, DC, additionalSizeToAlloc<SourceLocation>(1))
4668  ImportDecl(DC, StartLoc, Imported, EndLoc);
4669  Import->setImplicit();
4670  return Import;
4671 }
4672 
4674  unsigned NumLocations) {
4675  return new (C, ID, additionalSizeToAlloc<SourceLocation>(NumLocations))
4677 }
4678 
4680  if (!ImportedAndComplete.getInt())
4681  return None;
4682 
4683  const auto *StoredLocs = getTrailingObjects<SourceLocation>();
4684  return llvm::makeArrayRef(StoredLocs,
4685  getNumModuleIdentifiers(getImportedModule()));
4686 }
4687 
4689  if (!ImportedAndComplete.getInt())
4690  return SourceRange(getLocation(), *getTrailingObjects<SourceLocation>());
4691 
4692  return SourceRange(getLocation(), getIdentifierLocs().back());
4693 }
4694 
4695 //===----------------------------------------------------------------------===//
4696 // ExportDecl Implementation
4697 //===----------------------------------------------------------------------===//
4698 
4699 void ExportDecl::anchor() {}
4700 
4702  SourceLocation ExportLoc) {
4703  return new (C, DC) ExportDecl(DC, ExportLoc);
4704 }
4705 
4707  return new (C, ID) ExportDecl(nullptr, SourceLocation());
4708 }
void setLinkage(Linkage L)
Definition: Visibility.h:88
EnumDecl * getTemplateInstantiationPattern() const
Retrieve the enum definition from which this enumeration could be instantiated, if it is an instantia...
Definition: Decl.cpp:4046
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition: Decl.cpp:2454
bool isNoReturn() const
Determines whether this function is known to be &#39;noreturn&#39;, through an attribute on its declaration o...
Definition: Decl.cpp:2934
Defines the clang::ASTContext interface.
void setTemplateOrSpecializationInfo(VarDecl *Inst, TemplateOrSpecializationInfo TSI)
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4583
ObjCStringFormatFamily
static const Decl * getCanonicalDecl(const Decl *D)
void setImplicit(bool I=true)
Definition: DeclBase.h:548
Represents a function declaration or definition.
Definition: Decl.h:1738
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 ...
SourceRange getExceptionSpecRange() const
Definition: TypeLoc.h:1382
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
Definition: Decl.cpp:2795
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
Definition: DeclTemplate.h:550
unsigned getMemoryFunctionKind() const
Identify a memory copying or setting function.
Definition: Decl.cpp:3641
bool isThisDeclarationADemotedDefinition() const
If this definition should pretend to be a declaration.
Definition: Decl.h:1289
void setNonTrivialToPrimitiveDestroy(bool V)
Definition: Decl.h:3712
bool isPredefinedLibFunction(unsigned ID) const
Determines whether this builtin is a predefined libc/libm function, such as "malloc", where we know the signature a priori.
Definition: Builtins.h:141
FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass S, bool isInlineSpecified, bool isConstexprSpecified)
Definition: Decl.cpp:2646
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
Definition: Decl.cpp:2010
bool isClosedNonFlag() const
Returns true if this enum is annotated with neither flag_enum nor enum_extensibility(open).
Definition: Decl.cpp:4024
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:3670
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
Definition: DeclBase.h:752
static ImportDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NumLocations)
Create a new, deserialized module import declaration.
Definition: Decl.cpp:4673
CanQualType VoidPtrTy
Definition: ASTContext.h:1044
bool isInExternCXXContext() const
Determines whether this function&#39;s context is, or is nested within, a C++ extern "C++" linkage spec...
Definition: Decl.cpp:2910
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration, or explicit instantiation definition.
A (possibly-)qualified type.
Definition: Type.h:638
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition: Decl.cpp:3900
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition: Decl.h:3172
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...
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:3127
Internal linkage according to the Modules TS, but can be referred to from other translation units ind...
Definition: Linkage.h:50
bool isExternC() const
Determines whether this function is a function with external, C linkage.
Definition: Decl.cpp:2902
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
static VarDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:1925
This file contains the declaration of the ODRHash class, which calculates a hash based on AST nodes...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4512
bool willHaveBody() const
True if this function will eventually have a body, once it&#39;s fully parsed.
Definition: Decl.h:2221
This declaration has an owning module, but is only visible to lookups that occur within that module...
Module * getOwningModuleForLinkage(bool IgnoreLinkage=false) const
Get the module that owns this declaration for linkage purposes.
Definition: Decl.cpp:1481
void setNonTrivialToPrimitiveDefaultInitialize(bool V)
Definition: Decl.h:3696
static IndirectFieldDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, llvm::MutableArrayRef< NamedDecl *> CH)
Definition: Decl.cpp:4500
Stmt - This represents one statement.
Definition: Stmt.h:66
bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD)
Definition: ASTLambda.h:39
void setPreviousDecl(FunctionDecl *PrevDecl)
Set the previous declaration.
Definition: Decl.h:4289
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3355
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:184
bool IsICE
Whether this statement is an integral constant expression, or in C++11, whether the statement is a co...
Definition: Decl.h:802
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Definition: Decl.cpp:3485
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:505
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program...
Definition: Decl.cpp:2760
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a member function...
Definition: Decl.cpp:3614
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:955
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:2786
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:3199
No linkage, which means that the entity is unique and can only be referred to from within its scope...
Definition: Linkage.h:27
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:3868
Represents the declaration of a typedef-name via the &#39;typedef&#39; type specifier.
Definition: Decl.h:3018
C Language Family Type Representation.
Defines the SourceManager interface.
bool IsEvaluating
Whether this statement is being evaluated.
Definition: Decl.h:789
static PragmaCommentDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned ArgSize)
Definition: Decl.cpp:4327
The template argument is an expression, and we&#39;ve not resolved it to one of the other forms yet...
Definition: TemplateBase.h:87
bool isInExternCContext() const
Determines whether this function&#39;s context is, or is nested within, a C++ extern "C" linkage spec...
Definition: Decl.cpp:2906
bool isInitICE() const
Determines whether the initializer is an integral constant expression, or in C++11, whether the initializer is a constant expression.
Definition: Decl.cpp:2324
static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D)
Determine what kind of template specialization the given declaration is.
Defines the clang::Module class, which describes a module in the source code.
const Type * getTypeForDecl() const
Definition: Decl.h:2898
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:4002
static LinkageInfo getExternalLinkageFor(const NamedDecl *D)
Definition: Decl.cpp:597
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:410
bool isNothrow() const
Definition: Decl.cpp:4469
void setArgPassingRestrictions(ArgPassingKind Kind)
Definition: Decl.h:3727
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4688
Defines the C++ template declaration subclasses.
StringRef P
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
void setPure(bool P=true)
Definition: Decl.cpp:2747
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
void setPreviousDeclaration(FunctionDecl *PrevDecl)
Definition: Decl.cpp:2969
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition: Decl.cpp:3797
static Visibility getVisibilityFromAttr(const T *attr)
Given a visibility attribute, return the explicit visibility associated with it.
Definition: Decl.cpp:208
bool isUninit() const
Definition: APValue.h:233
ImplicitParamKind
Defines the kind of the implicit parameter: is this an implicit parameter with pointer to &#39;this&#39;...
Definition: Decl.h:1493
The base class of the type hierarchy.
Definition: Type.h:1407
Represents an empty-declaration.
Definition: Decl.h:4259
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...
SourceLocation getBeginLoc() const
getBeginLoc - Retrieve the location of the first token.
void setParams(ArrayRef< ParmVarDecl *> NewParamInfo)
Definition: Decl.cpp:4265
DiagnosticsEngine & getDiagnostics() const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1295
Declaration of a variable template.
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:64
Represent a C++ namespace.
Definition: Decl.h:515
static std::enable_if<!std::is_base_of< RedeclarableTemplateDecl, T >::value, bool >::type isExplicitMemberSpecialization(const T *D)
Does the given declaration have member specialization information, and if so, is it an explicit speci...
Definition: Decl.cpp:190
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:4154
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:414
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:690
A container of type source information.
Definition: Decl.h:87
constexpr XRayInstrMask Function
Definition: XRayInstr.h:39
Linkage getLinkage() const
Determine the linkage of this type.
Definition: Type.cpp:3589
SourceRange getIntegerTypeRange() const LLVM_READONLY
Retrieve the source range that covers the underlying type if specified.
Definition: Decl.cpp:3995
bool CheckingICE
Whether we are checking whether this statement is an integral constant expression.
Definition: Decl.h:797
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:2681
SourceLocation getOuterLocStart() const
Return SourceLocation representing start of source range taking into account any outer template decla...
Definition: Decl.cpp:3856
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList *> TPLists)
Sets info about "outer" template parameter lists.
Definition: Decl.cpp:1868
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to...
Definition: Decl.h:1210
bool isImplicitlyInstantiable() const
Determines whether this function is a function template specialization or a member of a class templat...
Definition: Decl.cpp:3362
This is a module that was defined by a module map and built out of header files.
Definition: Module.h:76
static CapturedDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NumParams)
Definition: Decl.cpp:4460
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3169
Represents a #pragma comment line.
Definition: Decl.h:140
LinkageInfo getDeclLinkageAndVisibility(const NamedDecl *D)
Definition: Decl.cpp:1474
void setBeingDefined(bool V=true)
True if this decl is currently being defined.
Definition: Decl.h:3121
void setNothrow(bool Nothrow=true)
Definition: Decl.cpp:4470
This file provides some common utility functions for processing Lambda related AST Constructs...
unsigned getODRHash()
Definition: Decl.cpp:4074
ExplicitVisibilityKind
Kinds of explicit visibility.
Definition: Decl.h:399
Represents a variable declaration or definition.
Definition: Decl.h:813
ASTMutationListener * getASTMutationListener() const
Definition: DeclBase.cpp:380
Objects with "hidden" visibility are not seen by the dynamic linker.
Definition: Visibility.h:37
bool WasEvaluated
Whether this statement was already evaluated.
Definition: Decl.h:786
Declaration of a redeclarable template.
Definition: DeclTemplate.h:737
static LanguageLinkage getDeclLanguageLinkage(const T &D)
Definition: Decl.cpp:1970
unsigned getNumParams() const
Definition: Type.h:3888
void mergeVisibility(Visibility newVis, bool newExplicit)
Merge in the visibility &#39;newVis&#39;.
Definition: Visibility.h:112
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6748
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition: Decl.cpp:2621
Visibility getVisibility() const
Definition: Visibility.h:85
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:553
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:57
Declaration context for names declared as extern "C" in C++.
Definition: Decl.h:222
Represents a variable template specialization, which refers to a variable template with a given set o...
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Definition: DeclBase.cpp:1129
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:432
bool isZeroLengthBitField(const ASTContext &Ctx) const
Is this a zero-length bit-field? Such bit-fields aren&#39;t really bit-fields at all and instead act as a...
Definition: Decl.cpp:3792
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:604
Decl * FirstDecl
FirstDecl - The first declaration stored within this declaration context.
Definition: DeclBase.h:1726
bool isInvalidDecl() const
Definition: DeclBase.h:542
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
Not a TLS variable.
Definition: Decl.h:830
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:630
Represents a parameter to a function.
Definition: Decl.h:1550
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
Definition: Linkage.h:24
Defines the clang::Expr interface and subclasses for C++ expressions.
LinkageInfo getLVForDecl(const NamedDecl *D, LVComputationKind computation)
getLVForDecl - Get the linkage and visibility for the given declaration.
Definition: Decl.cpp:1428
std::string getName(ArrayRef< StringRef > Parts) const
Get the platform-specific name separator.
Provides information about a dependent function-template specialization declaration.
Definition: DeclTemplate.h:672
bool isAnonymousStructOrUnion() const
Determines whether this field is a representative for an anonymous struct or union.
Definition: Decl.cpp:3777
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
Definition: Decl.cpp:4192
ModuleKind Kind
The kind of this module.
Definition: Module.h:87
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type. ...
Definition: Decl.cpp:3202
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
Defines the clang::SanitizerKind enum.
Represents a struct/union/class.
Definition: Decl.h:3593
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:298
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:85
C11 _Thread_local.
Definition: Specifiers.h:202
static bool isRedeclarable(Decl::Kind K)
Definition: Decl.cpp:1633
One of these records is kept for each identifier that is lexed.
Represents a class template specialization, which refers to a class template with a given set of temp...
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:1933
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1024
SourceLocation getOuterLocStart() const
Return start of source range taking into account any outer template declarations. ...
Definition: Decl.cpp:1817
static bool typeIsPostfix(QualType QT)
Definition: Decl.cpp:1823
bool isInAnonymousNamespace() const
Definition: DeclBase.cpp:347
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
bool isCapturedRecord() const
Determine whether this record is a record for captured variables in CapturedStmt construct.
Definition: Decl.cpp:4137
static RecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl=nullptr)
Definition: Decl.cpp:4107
void print(raw_ostream &OS, const SourceManager &SM) const
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:2610
static IndirectFieldDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4506
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
bool hasTrivialBody() const
Returns whether the function has a trivial body that does not require any specific codegen...
Definition: Decl.cpp:2706
A C++ nested-name-specifier augmented with source location information.
static bool redeclForcesDefMSVC(const FunctionDecl *Redecl)
Definition: Decl.cpp:3108
bool CheckedICE
Whether we already checked whether this statement was an integral constant expression.
Definition: Decl.h:793
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:72
static LinkageInfo internal()
Definition: Visibility.h:71
static bool usesTypeVisibility(const NamedDecl *D)
Is the given declaration a "type" or a "value" for the purposes of visibility computation?
Definition: Decl.cpp:180
field_range fields() const
Definition: Decl.h:3784
static unsigned getNumModuleIdentifiers(Module *Mod)
Retrieve the number of module identifiers needed to name the given module.
Definition: Decl.cpp:4630
static const Decl * getOutermostFuncOrBlockContext(const Decl *D)
Definition: Decl.cpp:302
Represents a member of a struct/union/class.
Definition: Decl.h:2579
friend class DeclContext
Definition: DeclBase.h:243
void completeDefinition()
Completes the definition of this tag declaration.
Definition: Decl.cpp:3888
bool isNamespace() const
Definition: DeclBase.h:1832
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:3877
BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
Definition: Decl.cpp:4256
bool isReferenceType() const
Definition: Type.h:6308
SanitizerMask Mask
Bitmask of enabled sanitizers.
Definition: Sanitizers.h:73
Linkage getFormalLinkage(Linkage L)
Definition: Linkage.h:90
This declaration is definitely a definition.
Definition: Decl.h:1153
bool isLinkageValid() const
True if the computed linkage is valid.
Definition: Decl.cpp:1039
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:739
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
bool hasLoadedFieldsFromExternalStorage() const
Definition: Decl.h:3683
Describes a module or submodule.
Definition: Module.h:65
static PragmaCommentDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation CommentLoc, PragmaMSCommentKind CommentKind, StringRef Arg)
Definition: Decl.cpp:4314
specific_decl_iterator< FieldDecl > field_iterator
Definition: Decl.h:3781
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2262
Objects with "default" visibility are seen by the dynamic linker and act like normal objects...
Definition: Visibility.h:46
virtual bool isDefined() const
Definition: Decl.h:1949
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Definition: DeclTemplate.h:508
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:2444
TypedefNameDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this typedef-name.
Definition: Decl.h:2988
VarDecl * getActingDefinition()
Get the tentative definition that acts as the real definition in a TU.
Definition: Decl.cpp:2115
bool isReplaceableGlobalAllocationFunction(bool *IsAligned=nullptr) const
Determines whether this function is one of the replaceable global allocation functions: void *operato...
Definition: Decl.cpp:2818
const TemplateArgumentList * TemplateArguments
The template arguments used to produce the function template specialization from the function templat...
Definition: DeclTemplate.h:540
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:4466
The argument of this type can be passed directly in registers.
Definition: Decl.h:3604
Kinds of LV computation.
Definition: Linkage.h:29
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:4035
QualType getOriginalType() const
Definition: Decl.cpp:2544
static ExternCContextDecl * Create(const ASTContext &C, TranslationUnitDecl *TU)
Definition: Decl.cpp:4361
A convenient class for passing around template argument information.
Definition: TemplateBase.h:555
void setParamDestroyedInCallee(bool V)
Definition: Decl.h:3735
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
void AddFunctionDecl(const FunctionDecl *Function, bool SkipBody=false)
Definition: ODRHash.cpp:509
TagDecl * getAnonDeclWithTypedefName(bool AnyRedecl=false) const
Retrieves the tag declaration for which this is the typedef name for linkage purposes, if any.
Definition: Decl.cpp:4529
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Wrapper for source info for functions.
Definition: TypeLoc.h:1327
ModuleOwnershipKind getModuleOwnershipKind() const
Get the kind of module ownership for this declaration.
Definition: DeclBase.h:779
static EnumConstantDecl * Create(ASTContext &C, EnumDecl *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
Definition: Decl.cpp:4472
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3354
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Definition: DeclTemplate.h:880
ASTContext & getASTContext() const
Definition: Decl.h:120
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:34
DefinitionKind hasDefinition() const
Definition: Decl.h:1166
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:654
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:2434
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:1857
Represents a declaration of a type.
Definition: Decl.h:2874
void setHasObjectMember(bool val)
Definition: Decl.h:3675
A set of unresolved declarations.
Definition: UnresolvedSet.h:61
Module * Parent
The parent of this module.
Definition: Module.h:91
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1382
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition: Decl.cpp:3469
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:1196
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6072
field_iterator field_begin() const
Definition: Decl.cpp:4145
unsigned getBitWidthValue(const ASTContext &Ctx) const
Definition: Decl.cpp:3787
static FileScopeAsmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4608
bool isTargetMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target functionality...
Definition: Decl.cpp:2964
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:3251
bool isCPUSpecificMultiVersion() const
True if this function is a multiversioned processor specific function as a part of the cpu_specific/c...
Definition: Decl.cpp:2960
Defines the Linkage enumeration and various utility functions.
static TypeAliasDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4578
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Definition: DeclBase.h:821
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
Definition: Decl.cpp:1918
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:4679
bool needsCleanup() const
Returns whether the object performed allocations.
Definition: APValue.cpp:257
SourceRange getExceptionSpecSourceRange() const
Attempt to compute an informative source range covering the function exception specification, if any.
Definition: Decl.cpp:3222
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization, retrieves the function from which it was instantiated.
Definition: Decl.cpp:3332
static FunctionTemplateSpecializationInfo * Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs, const TemplateArgumentListInfo *TemplateArgsAsWritten, SourceLocation POI)
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4044
Represents a linkage specification.
Definition: DeclCXX.h:2826
static ParmVarDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:2552
SourceLocation getTypeSpecStartLoc() const
Definition: Decl.cpp:1765
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
LinkageInfo computeLVForDecl(const NamedDecl *D, LVComputationKind computation, bool IgnoreVarTypeLinkage=false)
Definition: Decl.cpp:1306
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization, retrieves the member specialization information.
Definition: Decl.cpp:3339
Decl * getPrimaryMergedDecl(Decl *D)
Definition: ASTContext.h:971
void setCachedLinkage(Linkage L) const
Definition: DeclBase.h:396
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified=false, bool hasWrittenPrototype=true, bool isConstexprSpecified=false)
Definition: Decl.h:1875
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:870
Defines the clang::Visibility enumeration and various utility functions.
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
Definition: Decl.cpp:3455
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
Definition: Decl.cpp:4404
NodeId Parent
Definition: ASTDiff.cpp:192
bool isExternC() const
Determines whether this variable is a variable with external, C linkage.
Definition: Decl.cpp:2014
bool isInExternCContext() const
Determines whether this variable&#39;s context is, or is nested within, a C++ extern "C" linkage spec...
Definition: Decl.cpp:2018
static ImportDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, Module *Imported, ArrayRef< SourceLocation > IdentifierLocs)
Create a new module import declaration.
Definition: Decl.cpp:4655
unsigned getLambdaManglingNumber() const
If this is the closure type of a lambda expression, retrieve the number to be used for name mangling ...
Definition: DeclCXX.h:1904
bool hasAttr() const
Definition: DeclBase.h:531
bool isExternalFormalLinkage(Linkage L)
Definition: Linkage.h:103
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:103
static bool isExportedFromModuleIntefaceUnit(const NamedDecl *D)
Definition: Decl.cpp:571
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3038
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1613
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3687
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition: Decl.h:1194
bool isUsableInConstantExpressions(ASTContext &C) const
Determine whether this variable&#39;s value can be used in a constant expression, according to the releva...
Definition: Decl.cpp:2214
void setImplicitlyInline(bool I=true)
Flag that this function is implicitly inline.
Definition: Decl.h:2351
unsigned MSVCFormatting
Use whitespace and punctuation like MSVC does.
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any...
Definition: Decl.cpp:3300
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:689
TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl, SourceLocation StartL)
Definition: Decl.cpp:3840
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Definition: Linkage.h:56
bool isClosed() const
Returns true if this enum is either annotated with enum_extensibility(closed) or isn&#39;t annotated with...
Definition: Decl.cpp:4014
static EmptyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L)
Definition: Decl.cpp:4616
FunctionDecl * getClassScopeSpecializationPattern() const
Retrieve the class scope template pattern that this function template specialization is instantiated ...
Definition: Decl.cpp:3464
bool isInlineSpecified() const
Definition: Decl.h:1367
Stmt ** getInitAddress()
Retrieve the address of the initializer expression.
Definition: Decl.cpp:2182
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:4162
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:190
unsigned IgnoreExplicitVisibility
Whether explicit visibility attributes should be ignored.
Definition: Linkage.h:35
Defines the TargetCXXABI class, which abstracts details of the C++ ABI that we&#39;re targeting...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:432
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:876
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr...
Definition: Decl.cpp:4394
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2342
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:3858
const FieldDecl * findFirstNamedDataMember() const
Finds the first data member which has a name.
Definition: Decl.cpp:4237
bool isMultiVersion() const
True if this function is considered a multiversioned function.
Definition: Decl.h:2225
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:637
This represents one expression.
Definition: Expr.h:106
Defines the clang::LangOptions interface.
SourceLocation End
bool isTypeVisibility() const
Definition: Linkage.h:50
bool isVariadic() const
Whether this function is variadic.
Definition: Decl.cpp:2689
static bool classofKind(Kind K)
Definition: Decl.h:2870
std::string Label
void mergeExternalVisibility(Linkage L)
Definition: Visibility.h:97
int Id
Definition: ASTDiff.cpp:191
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6811
static bool hasExplicitVisibilityAlready(LVComputationKind computation)
Does this computation kind permit us to consider additional visibility settings from attributes and t...
Definition: Decl.cpp:159
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:68
ObjCStringFormatFamily getObjCFStringFormattingFamily() const
Definition: Decl.cpp:1049
Decl * LastDecl
LastDecl - The last declaration stored within this declaration context.
Definition: DeclBase.h:1732
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:87
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
void setInit(Expr *I)
Definition: Decl.cpp:2205
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:547
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition: Decl.cpp:3475
bool isKnownToBeDefined() const
Definition: Decl.cpp:2463
static Optional< Visibility > getVisibilityOf(const NamedDecl *D, NamedDecl::ExplicitVisibilityKind kind)
Return the explicit visibility of the given declaration.
Definition: Decl.cpp:221
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:166
Linkage getLinkage() const
Definition: Visibility.h:84
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
bool isFileContext() const
Definition: DeclBase.h:1818
DeclContext * getDeclContext()
Definition: DeclBase.h:427
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
Definition: Decl.cpp:2898
bool isCPUDispatchMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the cpu_specific/cpu_dispatc...
Definition: Decl.cpp:2956
This declaration is a tentative definition.
Definition: Decl.h:1150
Decl * getPrimaryMergedDecl(Decl *D)
Get the primary declaration for a declaration from an AST file.
Definition: Decl.cpp:76
TLSKind getTLSKind() const
Definition: Decl.cpp:1936
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2331
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:264
void setCompleteDefinitionRequired(bool V=true)
True if this complete decl is required to be complete for some existing use.
Definition: Decl.h:3184
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy)
Print a template argument list, including the &#39;<&#39; and &#39;>&#39; enclosing the template arguments.
Defines the clang::TypeLoc interface and its subclasses.
TemplateOrSpecializationInfo getTemplateOrSpecializationInfo(const VarDecl *Var)
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition: Decl.cpp:3527
VarDecl * getTemplateInstantiationPattern() const
Retrieve the variable declaration from which this variable could be instantiated, if it is an instant...
Definition: Decl.cpp:2382
static bool RedeclForcesDefC99(const FunctionDecl *Redecl)
Definition: Decl.cpp:3120
static const CXXRecordDecl * getOutermostEnclosingLambda(const CXXRecordDecl *Record)
Definition: Decl.cpp:1294
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:2695
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isInvalid() const
bool isFunctionOrMethod() const
Definition: DeclBase.h:1800
StorageClass
Storage classes.
Definition: Specifiers.h:206
static Optional< Visibility > getExplicitVisibility(const NamedDecl *D, LVComputationKind kind)
Definition: Decl.cpp:171
Objects with "protected" visibility are seen by the dynamic linker but always dynamically resolve to ...
Definition: Visibility.h:42
PragmaMSCommentKind
Definition: PragmaKinds.h:15
unsigned IgnoreAllVisibility
Whether all visibility should be ignored.
Definition: Linkage.h:38
InClassInitStyle
In-class initialization styles for non-static data members.
Definition: Specifiers.h:229
static CapturedDecl * Create(ASTContext &C, DeclContext *DC, unsigned NumParams)
Definition: Decl.cpp:4454
This declaration has an owning module, and is visible when that module is imported.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1752
bool isExternallyVisible(Linkage L)
Definition: Linkage.h:86
SourceLocation getEnd() const
static bool hasDefinition(const ObjCObjectPointerType *ObjPtr)
bool capturesVariable(const VarDecl *var) const
Definition: Decl.cpp:4289
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
Definition: Decl.cpp:2258
bool isValueVisibility() const
Definition: Linkage.h:53
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...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:3817
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:1527
void setStorageClass(StorageClass SC)
Definition: Decl.cpp:1931
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1396
void addDestruction(T *Ptr)
If T isn&#39;t trivially destructible, calls AddDeallocation to register it for destruction.
Definition: ASTContext.h:2720
The result type of a method or function.
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:152
DefinitionKind isThisDeclarationADefinition() const
Definition: Decl.h:1160
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:703
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:170
static LinkageInfo visible_none()
Definition: Visibility.h:80
const SourceManager & SM
Definition: Format.cpp:1490
FunctionDeclBitfields FunctionDeclBits
Definition: DeclBase.h:1693
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList *> TPLists)
Definition: Decl.cpp:3943
void setDoesNotEscape(bool B=true)
Definition: Decl.h:4010
TypeLoc getReturnLoc() const
Definition: TypeLoc.h:1411
static bool isNamed(const NamedDecl *ND, const char(&Str)[Len])
Definition: Decl.cpp:2755
const SanitizerBlacklist & getSanitizerBlacklist() const
Definition: ASTContext.h:709
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:2026
static LinkageInfo external()
Definition: Visibility.h:68
VarDecl * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:216
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:301
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
Definition: Type.h:6105
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4061
void setIsVariadic(bool value)
Definition: Decl.h:3934
Abstract interface for external sources of AST nodes.
bool isAlignValT() const
Definition: Type.cpp:2437
static PragmaDetectMismatchDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NameValueSize)
Definition: Decl.cpp:4353
bool isInjectedClassName() const
Determines whether this declaration represents the injected class name.
Definition: Decl.cpp:4126
virtual void printName(raw_ostream &os) const
Definition: Decl.cpp:1516
Represents a C++ Modules TS module export declaration.
Definition: Decl.h:4214
A struct with extended info about a syntactic name qualifier, to be used for the case of out-of-line ...
Definition: Decl.h:662
APValue * getEvaluatedValue() const
Return the already-evaluated value of this variable&#39;s initializer, or NULL if the value is not yet kn...
Definition: Decl.cpp:2309
Decl::Kind getDeclKind() const
Definition: DeclBase.h:1745
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration, or explicit instantiation definition.
Definition: DeclTemplate.h:564
This declaration has an owning module, but is globally visible (typically because its owning module i...
void setIsConversionFromLambda(bool val=true)
Definition: Decl.h:4005
static bool classof(const Decl *D)
Definition: Decl.h:3799
The "struct" keyword.
Definition: Type.h:5033
static EnumConstantDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4480
Kind
TypeLoc IgnoreParens() const
Definition: TypeLoc.h:1127
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:2558
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:204
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:218
static SourceLocation getTemplateOrInnerLocStart(const DeclT *decl)
Definition: Decl.cpp:1758
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: Redeclarable.h:295
Encodes a location in the source.
static EmptyDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4620
bool isLinkageValid() const
True if the computed linkage is valid.
Definition: Type.cpp:3672
static ExportDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation ExportLoc)
Definition: Decl.cpp:4701
bool mayHaveOutOfDateDef() const
Indicates whether it is possible for declarations of this kind to have an out-of-date definition...
Definition: Decl.h:3215
void setFreeStanding(bool isFreeStanding=true)
True if this tag is free standing, e.g. "struct foo;".
Definition: Decl.h:3207
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3064
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have...
Definition: Linkage.h:65
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:376
bool declarationReplaces(NamedDecl *OldD, bool IsKnownNewer=true) const
Determine whether this declaration, if known to be well-formed within its context, will replace the declaration OldD if introduced into scope.
Definition: Decl.cpp:1644
static QualType getUnderlyingType(const SubRegion *R)
Represents the declaration of a label.
Definition: Decl.h:469
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList *> TPLists)
Definition: Decl.cpp:1801
TemplateSpecializationKind getTemplateSpecializationKind() const
If this enumeration is a member of a specialization of a templated class, determine what kind of temp...
Definition: Decl.cpp:4028
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:3866
MultiVersionKind
Definition: Decl.h:1721
bool isLegalForVariable(StorageClass SC)
Checks whether the given storage class is legal for variables.
Definition: Specifiers.h:224
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition: Decl.cpp:4131
void setHasFlexibleArrayMember(bool V)
Definition: Decl.h:3651
unsigned SuppressUnwrittenScope
Suppress printing parts of scope specifiers that don&#39;t need to be written, e.g., for inline or anonym...
GNU __thread.
Definition: Specifiers.h:196
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
Definition: Decl.h:1078
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2285
This file defines OpenMP nodes for declarative directives.
bool hasCachedLinkage() const
Definition: DeclBase.h:400
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:3860
bool doesDeclarationForceExternallyVisibleDefinition() const
For a function declaration in C or C++, determine whether this declaration causes the definition to b...
Definition: Decl.cpp:3142
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4592
This is a fragment of the global module within some C++ Modules TS module.
Definition: Module.h:83
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2312
Linkage getCachedLinkage() const
Definition: DeclBase.h:392
bool isNonEscapingByref() const
Indicates the capture is a __block variable that is never captured by an escaping block...
Definition: Decl.cpp:2378
void setTagKind(TagKind TK)
Definition: Decl.h:3247
This declaration is only a declaration.
Definition: Decl.h:1147
static FunctionDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4436
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:695
unsigned getODRHash()
Returns ODRHash of the function.
Definition: Decl.cpp:3741
TypeClass getTypeClass() const
Definition: Type.h:1811
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
Definition: Decl.cpp:3076
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:164
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:149
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:1958
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:1901
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:4663
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
FunctionDecl * getClassScopeSpecializationPattern(const FunctionDecl *FD)
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:1973
void addSpecialization(FunctionTemplateSpecializationInfo *Info, void *InsertPos)
Add a specialization of this function template.
bool isValid() const
Whether this pointer is non-NULL.
virtual bool isOutOfLine() const
Determine whether this declaration is declared out of line (outside its semantic context).
Definition: Decl.cpp:99
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
Definition: DeclBase.cpp:685
void AddEnumDecl(const EnumDecl *Enum)
Definition: ODRHash.cpp:592
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1062
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4149
MultiVersionKind getMultiVersionKind() const
Gets the kind of multiversioning attribute this declaration has.
Definition: Decl.cpp:2946
static bool isDeclExternC(const T &D)
Definition: Decl.cpp:1998
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
Definition: DeclTemplate.h:639
C++11 thread_local.
Definition: Specifiers.h:199
static TypeAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.cpp:4571
void setHasWrittenPrototype(bool P=true)
State that this function has a written prototype.
Definition: Decl.h:2077
Defines various enumerations that describe declaration and type specifiers.
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:669
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition: Decl.cpp:1888
decl_iterator - Iterates through the declarations stored within this context.
Definition: DeclBase.h:1954
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:2495
static TypedefDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4566
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2916
TLS with a dynamic initializer.
Definition: Decl.h:836
Represents a template argument.
Definition: TemplateBase.h:51
void setCapturedRecord()
Mark the record as a record for captured variables in CapturedStmt construct.
Definition: Decl.cpp:4141
void setBody(Stmt *B)
Definition: Decl.cpp:2741
TagTypeKind
The kind of a tag type.
Definition: Type.h:5031
RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl)
Definition: Decl.cpp:4089
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:941
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2535
Dataflow Directional Tag Classes.
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:1620
void updateOutOfDate(IdentifierInfo &II) const
Update a potentially out-of-date declaration.
Definition: DeclBase.cpp:63
bool isValid() const
Return true if this is a valid SourceLocation object.
void setHasVolatileMember(bool val)
Definition: Decl.h:3679
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization, retrieves the member specialization information.
Definition: Decl.cpp:2486
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1262
ArrayRef< Capture > captures() const
Definition: Decl.h:3985
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
static PragmaDetectMismatchDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation Loc, StringRef Name, StringRef Value)
Definition: Decl.cpp:4337
bool isVisibilityExplicit() const
Definition: Visibility.h:86
bool isInitKnownICE() const
Determines whether it is already known whether the initializer is an integral constant expression or ...
Definition: Decl.cpp:2317
bool isInExternCXXContext() const
Determines whether this variable&#39;s context is, or is nested within, a C++ extern "C++" linkage spec...
Definition: Decl.cpp:2022
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:80
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:3558
bool isRecord() const
Definition: DeclBase.h:1827
attr_range attrs() const
Definition: DeclBase.h:490
InitType Init
The initializer for this variable or, for a ParmVarDecl, the C++ default argument.
Definition: Decl.h:856
Represents a field injected from an anonymous union/struct into the parent scope. ...
Definition: Decl.h:2825
const Expr * getInit() const
Definition: Decl.h:1220
static bool shouldConsiderTemplateVisibility(const FunctionDecl *fn, const FunctionTemplateSpecializationInfo *specInfo)
Definition: Decl.cpp:368
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:160
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration, or explicit instantiation definition.
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition: DeclBase.h:116
TLSKind
Kinds of thread-local storage.
Definition: Decl.h:828
Do an LV computation for, ultimately, a non-type declaration.
Definition: Decl.h:408
FunctionDecl * getTemplateInstantiationPattern() const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
Definition: Decl.cpp:3414
The name of a declaration.
Expr * getDefaultArg()
Definition: Decl.cpp:2573
Kind getKind() const
Definition: DeclBase.h:421
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:3516
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:1598
ParmVarDeclBitfields ParmVarDeclBits
Definition: Decl.h:976
bool isMSVCRTEntryPoint() const
Determines whether this function is a MSVCRT user defined entry point.
Definition: Decl.cpp:2768
Represents an enum.
Definition: Decl.h:3326
static bool isSingleLineLanguageLinkage(const Decl &D)
Definition: Decl.cpp:564
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:146
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
Definition: Decl.cpp:2374
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition: Decl.cpp:2884
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Tags, declared with &#39;struct foo;&#39; and referenced with &#39;struct foo&#39;.
Definition: DeclBase.h:126
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1083
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
Definition: Decl.cpp:3401
static EnumDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl, bool IsScoped, bool IsScopedUsingClassTag, bool IsFixed)
Definition: Decl.cpp:3975
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer points to.
static FileScopeAsmDecl * Create(ASTContext &C, DeclContext *DC, StringLiteral *Str, SourceLocation AsmLoc, SourceLocation RParenLoc)
Definition: Decl.cpp:4601
static LabelDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4380
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
Definition: DeclBase.h:2017
This declaration is not owned by a module.
static LabelDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II)
Definition: Decl.cpp:4368
void setCapturesCXXThis(bool B=true)
Definition: Decl.h:3991
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:151
uint64_t SanitizerMask
Definition: Sanitizers.h:26
Do an LV computation for, ultimately, a type.
Definition: Decl.h:403
Not an overloaded operator.
Definition: OperatorKinds.h:23
bool isClosedFlag() const
Returns true if this enum is annotated with flag_enum and isn&#39;t annotated with enum_extensibility(ope...
Definition: Decl.cpp:4020
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4370
static ExportDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4706
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:450
static const TypeInfo & getInfo(unsigned id)
Definition: Types.cpp:34
NonParmVarDeclBitfields NonParmVarDeclBits
Definition: Decl.h:977
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:2615
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:3923
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
Definition: Decl.cpp:1070
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:3575
bool checkInitIsICE() const
Determine whether the value of the initializer attached to this declaration is an integral constant e...
Definition: Decl.cpp:2330
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:156
static ImplicitParamDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4416
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1771
T * getAttr() const
Definition: DeclBase.h:527
static RecordDecl * CreateDeserialized(const ASTContext &C, unsigned ID)
Definition: Decl.cpp:4118
bool isFunctionType() const
Definition: Type.h:6292
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition: Decl.cpp:2524
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:716
bool isMSExternInline() const
The combination of the extern and inline keywords under MSVC forces the function to be required...
Definition: Decl.cpp:3092
void print(raw_ostream &OS) const override
Definition: Decl.cpp:80
static EnumDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:3987
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1730
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2269
static LinkageInfo getInternalLinkageFor(const NamedDecl *D)
Definition: Decl.cpp:585
unsigned CalculateHash()
Definition: ODRHash.cpp:199
The template argument is a type.
Definition: TemplateBase.h:60
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:32
static bool classofKind(Kind K)
Definition: Decl.h:2779
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
The template argument is actually a parameter pack.
Definition: TemplateBase.h:91
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Definition: APValue.h:38
NamedDecl::ExplicitVisibilityKind getExplicitVisibilityKind() const
Definition: Linkage.h:46
void merge(LinkageInfo other)
Merge both linkage and visibility.
Definition: Visibility.h:133
SourceManager & getSourceManager()
Definition: ASTContext.h:662
const IdentifierInfo * getLiteralIdentifier() const
getLiteralIdentifier - The literal suffix identifier this function represents, if any...
Definition: Decl.cpp:3309
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
Definition: Decl.h:2356
A template argument list.
Definition: DeclTemplate.h:210
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:238
static bool isFirstInExternCContext(T *D)
Definition: Decl.cpp:559
static BlockDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L)
Definition: Decl.cpp:4442
Optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition: Decl.cpp:1154
NestedNameSpecifierLoc QualifierLoc
Definition: Decl.h:663
static FieldDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:3771
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
void Deallocate(void *Ptr) const
Definition: ASTContext.h:675
Defines the clang::SourceLocation class and associated facilities.
unsigned size() const
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3274
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:2585
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization, returns the templated static data member from which it was instantiated.
Definition: Decl.cpp:2427
bool isValid() const
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:76
unsigned getBuiltinID() const
Returns a value indicating whether this function corresponds to a builtin function.
Definition: Decl.cpp:2994
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2459
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:2189
static TranslationUnitDecl * Create(ASTContext &C)
Definition: Decl.cpp:4308
static std::pair< Decl *, Decl * > BuildDeclChain(ArrayRef< Decl *> Decls, bool FieldsAlreadyLoaded)
Build up a chain of declarations.
Definition: DeclBase.cpp:1240
static TypedefDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.cpp:4521
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:608
No linkage according to the standard, but is visible from other translation units because of types de...
Definition: Linkage.h:45
void setMSAsmLabel(StringRef Name)
Definition: Decl.cpp:4385
Decl(Kind DK, DeclContext *DC, SourceLocation L)
Definition: DeclBase.h:368
VarDecl * getDefinition()
Definition: Decl.h:1182
Builtin::Context & BuiltinInfo
Definition: ASTContext.h:568
The "enum" keyword.
Definition: Type.h:5045
Declaration of a class template.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:61
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
Definition: Decl.h:1069
static DeclT * getDefinitionOrSelf(DeclT *D)
Definition: Decl.cpp:2367
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition: Decl.cpp:3826
void addAttr(Attr *A)
Definition: DeclBase.cpp:840
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
Definition: DeclCXX.cpp:1421
SourceRange getDefaultArgRange() const
Retrieve the source range that covers the entire default argument.
Definition: Decl.cpp:2590
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4298
static BlockDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4446
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1566
Defines the clang::TargetInfo interface.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:154
TLS with a known-constant initializer.
Definition: Decl.h:833
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:3637
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition: Decl.h:1989
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:90
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:3358
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:571
static bool isRedeclarableImpl(Redeclarable< T > *)
Definition: Decl.cpp:1629
std::string getQualifiedNameAsString() const
Definition: Decl.cpp:1520
VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass SC)
Definition: Decl.cpp:1901
__DEVICE__ int max(int __a, int __b)
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:954
VarDeclBitfields VarDeclBits
Definition: Decl.h:975
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:226
The top declaration context.
Definition: Decl.h:108
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2079
NamedDecl * getMostRecentDecl()
Definition: Decl.h:446
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition: Decl.cpp:3316
static bool useInlineVisibilityHidden(const NamedDecl *D)
Definition: Decl.cpp:531
void setHasLoadedFieldsFromExternalStorage(bool val) const
Definition: Decl.h:3687
static DependentFunctionTemplateSpecializationInfo * Create(ASTContext &Context, const UnresolvedSetImpl &Templates, const TemplateArgumentListInfo &TemplateArgs)
Definition: Decl.cpp:3533
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition: Decl.h:1135
IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it...
QualType getType() const
Definition: Decl.h:648
unsigned AllBits
Definition: Decl.h:974
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
Definition: Decl.cpp:4276
A trivial tuple used to represent a source range.
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:2983
This represents a decl that may have a name.
Definition: Decl.h:249
bool isTranslationUnit() const
Definition: DeclBase.h:1823
void mergeMaybeWithVisibility(LinkageInfo other, bool withVis)
Merge linkage and conditionally merge visibility.
Definition: Visibility.h:139
static LinkageInfo none()
Definition: Visibility.h:77
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2971
bool isInline() const
Whether this variable is (C++1z) inline.
Definition: Decl.h:1364
bool hasDefiningAttr() const
Return true if this declaration has an attribute which acts as definition of the entity, such as &#39;alias&#39; or &#39;ifunc&#39;.
Definition: DeclBase.cpp:471
Represents a #pragma detect_mismatch line.
Definition: Decl.h:174
APValue Evaluated
Definition: Decl.h:805
void setBlockMissingReturnType(bool val=true)
Definition: Decl.h:3997
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:648
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:572
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:3762
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:653
bool isInStdNamespace() const
Definition: DeclBase.cpp:357
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:408
NestedNameSpecifier * getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const
Retrieves the "canonical" nested name specifier for a given nested name specifier.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3055
bool hasInit() const
Definition: Decl.cpp:2164
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:730
const LangOptions & getLangOpts() const
Definition: ASTContext.h:707
static LinkageInfo uniqueExternal()
Definition: Visibility.h:74
bool isParameterPack() const
Determine whether this parameter is actually a function parameter pack.
Definition: Decl.cpp:2629
void setNonTrivialToPrimitiveCopy(bool V)
Definition: Decl.h:3704
static Optional< Visibility > getExplicitVisibilityAux(const NamedDecl *ND, NamedDecl::ExplicitVisibilityKind kind, bool IsMostRecent)
Definition: Decl.cpp:1075
static LVComputationKind forLinkageOnly()
Do an LV computation when we only care about the linkage.
Definition: Linkage.h:58
No in-class initializer.
Definition: Specifiers.h:230
bool isExternCXXContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Definition: DeclBase.cpp:1144
This class handles loading and caching of source files into memory.
bool isGlobal() const
Determines whether this is a global function.
Definition: Decl.cpp:2914
Defines enum values for all the target-independent builtin functions.
Declaration of a template function.
Definition: DeclTemplate.h:969
bool hasLinkage() const
Determine whether this declaration has linkage.
Definition: Decl.cpp:1720
void setBody(Stmt *B)
Definition: Decl.cpp:4467
SourceLocation getLocation() const
Definition: DeclBase.h:418
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:98
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form, which contains extra information on the evaluated value of the initializer.
Definition: Decl.cpp:2244
This is a C++ Modules TS module interface unit.
Definition: Module.h:79
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
Definition: Decl.cpp:1738
SourceLocation getPointOfInstantiation() const
Retrieve the (first) point of instantiation of a function template specialization or a member of a cl...
Definition: Decl.cpp:3602
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
Structure used to store a statement, the constant value to which it was evaluated (if any)...
Definition: Decl.h:784
TemplatedKind
The kind of templated function a FunctionDecl can be.
Definition: Decl.h:1745
bool isNoDestroy(const ASTContext &) const
Do we need to emit an exit-time destructor for this variable?
Definition: Decl.cpp:2480