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