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