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