clang  19.0.0git
ODRHash.cpp
Go to the documentation of this file.
1 //===-- ODRHash.cpp - Hashing to diagnose ODR failures ----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file implements the ODRHash class, which calculates a hash based
11 /// on AST nodes, which is stable across different runs.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #include "clang/AST/ODRHash.h"
16 
17 #include "clang/AST/DeclVisitor.h"
19 #include "clang/AST/StmtVisitor.h"
20 #include "clang/AST/TypeVisitor.h"
21 
22 using namespace clang;
23 
24 void ODRHash::AddStmt(const Stmt *S) {
25  assert(S && "Expecting non-null pointer.");
26  S->ProcessODRHash(ID, *this);
27 }
28 
30  assert(II && "Expecting non-null pointer.");
31  ID.AddString(II->getName());
32 }
33 
34 void ODRHash::AddDeclarationName(DeclarationName Name, bool TreatAsDecl) {
35  if (TreatAsDecl)
36  // Matches the NamedDecl check in AddDecl
37  AddBoolean(true);
38 
39  AddDeclarationNameImpl(Name);
40 
41  if (TreatAsDecl)
42  // Matches the ClassTemplateSpecializationDecl check in AddDecl
43  AddBoolean(false);
44 }
45 
46 void ODRHash::AddDeclarationNameImpl(DeclarationName Name) {
47  // Index all DeclarationName and use index numbers to refer to them.
48  auto Result = DeclNameMap.insert(std::make_pair(Name, DeclNameMap.size()));
49  ID.AddInteger(Result.first->second);
50  if (!Result.second) {
51  // If found in map, the DeclarationName has previously been processed.
52  return;
53  }
54 
55  // First time processing each DeclarationName, also process its details.
56  AddBoolean(Name.isEmpty());
57  if (Name.isEmpty())
58  return;
59 
60  auto Kind = Name.getNameKind();
61  ID.AddInteger(Kind);
62  switch (Kind) {
64  AddIdentifierInfo(Name.getAsIdentifierInfo());
65  break;
69  Selector S = Name.getObjCSelector();
70  AddBoolean(S.isNull());
71  AddBoolean(S.isKeywordSelector());
72  AddBoolean(S.isUnarySelector());
73  unsigned NumArgs = S.getNumArgs();
74  ID.AddInteger(NumArgs);
75  // Compare all selector slots. For selectors with arguments it means all arg
76  // slots. And if there are no arguments, compare the first-and-only slot.
77  unsigned SlotsToCheck = NumArgs > 0 ? NumArgs : 1;
78  for (unsigned i = 0; i < SlotsToCheck; ++i) {
79  const IdentifierInfo *II = S.getIdentifierInfoForSlot(i);
80  AddBoolean(II);
81  if (II) {
83  }
84  }
85  break;
86  }
89  AddQualType(Name.getCXXNameType());
90  break;
92  ID.AddInteger(Name.getCXXOverloadedOperator());
93  break;
95  AddIdentifierInfo(Name.getCXXLiteralIdentifier());
96  break;
98  AddQualType(Name.getCXXNameType());
99  break;
101  break;
103  auto *Template = Name.getCXXDeductionGuideTemplate();
104  AddBoolean(Template);
105  if (Template) {
106  AddDecl(Template);
107  }
108  }
109  }
110 }
111 
113  assert(NNS && "Expecting non-null pointer.");
114  const auto *Prefix = NNS->getPrefix();
115  AddBoolean(Prefix);
116  if (Prefix) {
117  AddNestedNameSpecifier(Prefix);
118  }
119  auto Kind = NNS->getKind();
120  ID.AddInteger(Kind);
121  switch (Kind) {
124  break;
126  AddDecl(NNS->getAsNamespace());
127  break;
130  break;
133  AddType(NNS->getAsType());
134  break;
137  break;
138  }
139 }
140 
142  auto Kind = Name.getKind();
143  ID.AddInteger(Kind);
144 
145  switch (Kind) {
147  AddDecl(Name.getAsTemplateDecl());
148  break;
149  // TODO: Support these cases.
157  break;
158  }
159 }
160 
162  const auto Kind = TA.getKind();
163  ID.AddInteger(Kind);
164 
165  switch (Kind) {
167  llvm_unreachable("Expected valid TemplateArgument");
169  AddQualType(TA.getAsType());
170  break;
172  AddDecl(TA.getAsDecl());
173  break;
175  ID.AddPointer(nullptr);
176  break;
178  // There are integrals (e.g.: _BitInt(128)) that cannot be represented as
179  // any builtin integral type, so we use the hash of APSInt instead.
180  TA.getAsIntegral().Profile(ID);
181  break;
182  }
186  break;
190  break;
192  AddStmt(TA.getAsExpr());
193  break;
195  ID.AddInteger(TA.pack_size());
196  for (auto SubTA : TA.pack_elements()) {
197  AddTemplateArgument(SubTA);
198  }
199  break;
200  }
201 }
202 
204  assert(TPL && "Expecting non-null pointer.");
205 
206  ID.AddInteger(TPL->size());
207  for (auto *ND : TPL->asArray()) {
208  AddSubDecl(ND);
209  }
210 }
211 
213  DeclNameMap.clear();
214  Bools.clear();
215  ID.clear();
216 }
217 
219  // Append the bools to the end of the data segment backwards. This allows
220  // for the bools data to be compressed 32 times smaller compared to using
221  // ID.AddBoolean
222  const unsigned unsigned_bits = sizeof(unsigned) * CHAR_BIT;
223  const unsigned size = Bools.size();
224  const unsigned remainder = size % unsigned_bits;
225  const unsigned loops = size / unsigned_bits;
226  auto I = Bools.rbegin();
227  unsigned value = 0;
228  for (unsigned i = 0; i < remainder; ++i) {
229  value <<= 1;
230  value |= *I;
231  ++I;
232  }
233  ID.AddInteger(value);
234 
235  for (unsigned i = 0; i < loops; ++i) {
236  value = 0;
237  for (unsigned j = 0; j < unsigned_bits; ++j) {
238  value <<= 1;
239  value |= *I;
240  ++I;
241  }
242  ID.AddInteger(value);
243  }
244 
245  assert(I == Bools.rend());
246  Bools.clear();
247  return ID.ComputeHash();
248 }
249 
250 namespace {
251 // Process a Decl pointer. Add* methods call back into ODRHash while Visit*
252 // methods process the relevant parts of the Decl.
253 class ODRDeclVisitor : public ConstDeclVisitor<ODRDeclVisitor> {
254  typedef ConstDeclVisitor<ODRDeclVisitor> Inherited;
255  llvm::FoldingSetNodeID &ID;
256  ODRHash &Hash;
257 
258 public:
259  ODRDeclVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
260  : ID(ID), Hash(Hash) {}
261 
262  void AddStmt(const Stmt *S) {
263  Hash.AddBoolean(S);
264  if (S) {
265  Hash.AddStmt(S);
266  }
267  }
268 
269  void AddIdentifierInfo(const IdentifierInfo *II) {
270  Hash.AddBoolean(II);
271  if (II) {
272  Hash.AddIdentifierInfo(II);
273  }
274  }
275 
276  void AddQualType(QualType T) {
277  Hash.AddQualType(T);
278  }
279 
280  void AddDecl(const Decl *D) {
281  Hash.AddBoolean(D);
282  if (D) {
283  Hash.AddDecl(D);
284  }
285  }
286 
287  void AddTemplateArgument(TemplateArgument TA) {
288  Hash.AddTemplateArgument(TA);
289  }
290 
291  void Visit(const Decl *D) {
292  ID.AddInteger(D->getKind());
293  Inherited::Visit(D);
294  }
295 
296  void VisitNamedDecl(const NamedDecl *D) {
297  Hash.AddDeclarationName(D->getDeclName());
298  Inherited::VisitNamedDecl(D);
299  }
300 
301  void VisitValueDecl(const ValueDecl *D) {
302  if (auto *DD = dyn_cast<DeclaratorDecl>(D); DD && DD->getTypeSourceInfo())
303  AddQualType(DD->getTypeSourceInfo()->getType());
304 
305  Inherited::VisitValueDecl(D);
306  }
307 
308  void VisitVarDecl(const VarDecl *D) {
309  Hash.AddBoolean(D->isStaticLocal());
310  Hash.AddBoolean(D->isConstexpr());
311  const bool HasInit = D->hasInit();
312  Hash.AddBoolean(HasInit);
313  if (HasInit) {
314  AddStmt(D->getInit());
315  }
316  Inherited::VisitVarDecl(D);
317  }
318 
319  void VisitParmVarDecl(const ParmVarDecl *D) {
320  // TODO: Handle default arguments.
321  Inherited::VisitParmVarDecl(D);
322  }
323 
324  void VisitAccessSpecDecl(const AccessSpecDecl *D) {
325  ID.AddInteger(D->getAccess());
326  Inherited::VisitAccessSpecDecl(D);
327  }
328 
329  void VisitStaticAssertDecl(const StaticAssertDecl *D) {
330  AddStmt(D->getAssertExpr());
331  AddStmt(D->getMessage());
332 
333  Inherited::VisitStaticAssertDecl(D);
334  }
335 
336  void VisitFieldDecl(const FieldDecl *D) {
337  const bool IsBitfield = D->isBitField();
338  Hash.AddBoolean(IsBitfield);
339 
340  if (IsBitfield) {
341  AddStmt(D->getBitWidth());
342  }
343 
344  Hash.AddBoolean(D->isMutable());
345  AddStmt(D->getInClassInitializer());
346 
347  Inherited::VisitFieldDecl(D);
348  }
349 
350  void VisitObjCIvarDecl(const ObjCIvarDecl *D) {
351  ID.AddInteger(D->getCanonicalAccessControl());
352  Inherited::VisitObjCIvarDecl(D);
353  }
354 
355  void VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
356  ID.AddInteger(D->getPropertyAttributes());
357  ID.AddInteger(D->getPropertyImplementation());
358  AddQualType(D->getTypeSourceInfo()->getType());
359  AddDecl(D);
360 
361  Inherited::VisitObjCPropertyDecl(D);
362  }
363 
364  void VisitFunctionDecl(const FunctionDecl *D) {
365  // Handled by the ODRHash for FunctionDecl
366  ID.AddInteger(D->getODRHash());
367 
368  Inherited::VisitFunctionDecl(D);
369  }
370 
371  void VisitCXXMethodDecl(const CXXMethodDecl *D) {
372  // Handled by the ODRHash for FunctionDecl
373 
374  Inherited::VisitCXXMethodDecl(D);
375  }
376 
377  void VisitObjCMethodDecl(const ObjCMethodDecl *Method) {
378  ID.AddInteger(Method->getDeclKind());
379  Hash.AddBoolean(Method->isInstanceMethod()); // false if class method
380  Hash.AddBoolean(Method->isVariadic());
381  Hash.AddBoolean(Method->isSynthesizedAccessorStub());
382  Hash.AddBoolean(Method->isDefined());
383  Hash.AddBoolean(Method->isDirectMethod());
385  Hash.AddBoolean(Method->hasSkippedBody());
386 
387  ID.AddInteger(llvm::to_underlying(Method->getImplementationControl()));
388  ID.AddInteger(Method->getMethodFamily());
389  ImplicitParamDecl *Cmd = Method->getCmdDecl();
390  Hash.AddBoolean(Cmd);
391  if (Cmd)
392  ID.AddInteger(llvm::to_underlying(Cmd->getParameterKind()));
393 
394  ImplicitParamDecl *Self = Method->getSelfDecl();
395  Hash.AddBoolean(Self);
396  if (Self)
397  ID.AddInteger(llvm::to_underlying(Self->getParameterKind()));
398 
399  AddDecl(Method);
400 
401  if (Method->getReturnTypeSourceInfo())
402  AddQualType(Method->getReturnTypeSourceInfo()->getType());
403 
404  ID.AddInteger(Method->param_size());
405  for (auto Param : Method->parameters())
406  Hash.AddSubDecl(Param);
407 
408  if (Method->hasBody()) {
409  const bool IsDefinition = Method->isThisDeclarationADefinition();
410  Hash.AddBoolean(IsDefinition);
411  if (IsDefinition) {
412  Stmt *Body = Method->getBody();
413  Hash.AddBoolean(Body);
414  if (Body)
415  AddStmt(Body);
416 
417  // Filter out sub-Decls which will not be processed in order to get an
418  // accurate count of Decl's.
420  for (Decl *SubDecl : Method->decls())
421  if (ODRHash::isSubDeclToBeProcessed(SubDecl, Method))
422  Decls.push_back(SubDecl);
423 
424  ID.AddInteger(Decls.size());
425  for (auto SubDecl : Decls)
426  Hash.AddSubDecl(SubDecl);
427  }
428  } else {
429  Hash.AddBoolean(false);
430  }
431 
432  Inherited::VisitObjCMethodDecl(Method);
433  }
434 
435  void VisitTypedefNameDecl(const TypedefNameDecl *D) {
436  AddQualType(D->getUnderlyingType());
437 
438  Inherited::VisitTypedefNameDecl(D);
439  }
440 
441  void VisitTypedefDecl(const TypedefDecl *D) {
442  Inherited::VisitTypedefDecl(D);
443  }
444 
445  void VisitTypeAliasDecl(const TypeAliasDecl *D) {
446  Inherited::VisitTypeAliasDecl(D);
447  }
448 
449  void VisitFriendDecl(const FriendDecl *D) {
450  TypeSourceInfo *TSI = D->getFriendType();
451  Hash.AddBoolean(TSI);
452  if (TSI) {
453  AddQualType(TSI->getType());
454  } else {
455  AddDecl(D->getFriendDecl());
456  }
457  }
458 
459  void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
460  // Only care about default arguments as part of the definition.
461  const bool hasDefaultArgument =
463  Hash.AddBoolean(hasDefaultArgument);
464  if (hasDefaultArgument) {
465  AddTemplateArgument(D->getDefaultArgument().getArgument());
466  }
467  Hash.AddBoolean(D->isParameterPack());
468 
469  const TypeConstraint *TC = D->getTypeConstraint();
470  Hash.AddBoolean(TC != nullptr);
471  if (TC)
472  AddStmt(TC->getImmediatelyDeclaredConstraint());
473 
474  Inherited::VisitTemplateTypeParmDecl(D);
475  }
476 
477  void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
478  // Only care about default arguments as part of the definition.
479  const bool hasDefaultArgument =
481  Hash.AddBoolean(hasDefaultArgument);
482  if (hasDefaultArgument) {
483  AddTemplateArgument(D->getDefaultArgument().getArgument());
484  }
485  Hash.AddBoolean(D->isParameterPack());
486 
487  Inherited::VisitNonTypeTemplateParmDecl(D);
488  }
489 
490  void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) {
491  // Only care about default arguments as part of the definition.
492  const bool hasDefaultArgument =
494  Hash.AddBoolean(hasDefaultArgument);
495  if (hasDefaultArgument) {
496  AddTemplateArgument(D->getDefaultArgument().getArgument());
497  }
498  Hash.AddBoolean(D->isParameterPack());
499 
500  Inherited::VisitTemplateTemplateParmDecl(D);
501  }
502 
503  void VisitTemplateDecl(const TemplateDecl *D) {
505 
506  Inherited::VisitTemplateDecl(D);
507  }
508 
509  void VisitRedeclarableTemplateDecl(const RedeclarableTemplateDecl *D) {
511  Inherited::VisitRedeclarableTemplateDecl(D);
512  }
513 
514  void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
515  AddDecl(D->getTemplatedDecl());
516  ID.AddInteger(D->getTemplatedDecl()->getODRHash());
517  Inherited::VisitFunctionTemplateDecl(D);
518  }
519 
520  void VisitEnumConstantDecl(const EnumConstantDecl *D) {
521  AddStmt(D->getInitExpr());
522  Inherited::VisitEnumConstantDecl(D);
523  }
524 };
525 } // namespace
526 
527 // Only allow a small portion of Decl's to be processed. Remove this once
528 // all Decl's can be handled.
530  if (D->isImplicit()) return false;
531  if (D->getDeclContext() != Parent) return false;
532 
533  switch (D->getKind()) {
534  default:
535  return false;
536  case Decl::AccessSpec:
537  case Decl::CXXConstructor:
538  case Decl::CXXDestructor:
539  case Decl::CXXMethod:
540  case Decl::EnumConstant: // Only found in EnumDecl's.
541  case Decl::Field:
542  case Decl::Friend:
543  case Decl::FunctionTemplate:
544  case Decl::StaticAssert:
545  case Decl::TypeAlias:
546  case Decl::Typedef:
547  case Decl::Var:
548  case Decl::ObjCMethod:
549  case Decl::ObjCIvar:
550  case Decl::ObjCProperty:
551  return true;
552  }
553 }
554 
555 void ODRHash::AddSubDecl(const Decl *D) {
556  assert(D && "Expecting non-null pointer.");
557 
558  ODRDeclVisitor(ID, *this).Visit(D);
559 }
560 
562  assert(Record && Record->hasDefinition() &&
563  "Expected non-null record to be a definition.");
564 
565  const DeclContext *DC = Record;
566  while (DC) {
567  if (isa<ClassTemplateSpecializationDecl>(DC)) {
568  return;
569  }
570  DC = DC->getParent();
571  }
572 
573  AddDecl(Record);
574 
575  // Filter out sub-Decls which will not be processed in order to get an
576  // accurate count of Decl's.
578  for (Decl *SubDecl : Record->decls()) {
579  if (isSubDeclToBeProcessed(SubDecl, Record)) {
580  Decls.push_back(SubDecl);
581  if (auto *Function = dyn_cast<FunctionDecl>(SubDecl)) {
582  // Compute/Preload ODRHash into FunctionDecl.
583  Function->getODRHash();
584  }
585  }
586  }
587 
588  ID.AddInteger(Decls.size());
589  for (auto SubDecl : Decls) {
590  AddSubDecl(SubDecl);
591  }
592 
593  const ClassTemplateDecl *TD = Record->getDescribedClassTemplate();
594  AddBoolean(TD);
595  if (TD) {
597  }
598 
599  ID.AddInteger(Record->getNumBases());
600  auto Bases = Record->bases();
601  for (const auto &Base : Bases) {
602  AddQualType(Base.getTypeSourceInfo()->getType());
603  ID.AddInteger(Base.isVirtual());
604  ID.AddInteger(Base.getAccessSpecifierAsWritten());
605  }
606 }
607 
609  assert(!isa<CXXRecordDecl>(Record) &&
610  "For CXXRecordDecl should call AddCXXRecordDecl.");
611  AddDecl(Record);
612 
613  // Filter out sub-Decls which will not be processed in order to get an
614  // accurate count of Decl's.
616  for (Decl *SubDecl : Record->decls()) {
617  if (isSubDeclToBeProcessed(SubDecl, Record))
618  Decls.push_back(SubDecl);
619  }
620 
621  ID.AddInteger(Decls.size());
622  for (const Decl *SubDecl : Decls)
623  AddSubDecl(SubDecl);
624 }
625 
627  AddDecl(IF);
628 
629  auto *SuperClass = IF->getSuperClass();
630  AddBoolean(SuperClass);
631  if (SuperClass)
632  ID.AddInteger(SuperClass->getODRHash());
633 
634  // Hash referenced protocols.
635  ID.AddInteger(IF->getReferencedProtocols().size());
636  for (const ObjCProtocolDecl *RefP : IF->protocols()) {
637  // Hash the name only as a referenced protocol can be a forward declaration.
638  AddDeclarationName(RefP->getDeclName());
639  }
640 
641  // Filter out sub-Decls which will not be processed in order to get an
642  // accurate count of Decl's.
644  for (Decl *SubDecl : IF->decls())
645  if (isSubDeclToBeProcessed(SubDecl, IF))
646  Decls.push_back(SubDecl);
647 
648  ID.AddInteger(Decls.size());
649  for (auto *SubDecl : Decls)
650  AddSubDecl(SubDecl);
651 }
652 
654  bool SkipBody) {
655  assert(Function && "Expecting non-null pointer.");
656 
657  // Skip functions that are specializations or in specialization context.
658  const DeclContext *DC = Function;
659  while (DC) {
660  if (isa<ClassTemplateSpecializationDecl>(DC)) return;
661  if (auto *F = dyn_cast<FunctionDecl>(DC)) {
662  if (F->isFunctionTemplateSpecialization()) {
663  if (!isa<CXXMethodDecl>(DC)) return;
664  if (DC->getLexicalParent()->isFileContext()) return;
665  // Skip class scope explicit function template specializations,
666  // as they have not yet been instantiated.
667  if (F->getDependentSpecializationInfo())
668  return;
669  // Inline method specializations are the only supported
670  // specialization for now.
671  }
672  }
673  DC = DC->getParent();
674  }
675 
676  ID.AddInteger(Function->getDeclKind());
677 
678  const auto *SpecializationArgs = Function->getTemplateSpecializationArgs();
679  AddBoolean(SpecializationArgs);
680  if (SpecializationArgs) {
681  ID.AddInteger(SpecializationArgs->size());
682  for (const TemplateArgument &TA : SpecializationArgs->asArray()) {
684  }
685  }
686 
687  if (const auto *Method = dyn_cast<CXXMethodDecl>(Function)) {
688  AddBoolean(Method->isConst());
689  AddBoolean(Method->isVolatile());
690  }
691 
692  ID.AddInteger(Function->getStorageClass());
693  AddBoolean(Function->isInlineSpecified());
694  AddBoolean(Function->isVirtualAsWritten());
695  AddBoolean(Function->isPureVirtual());
696  AddBoolean(Function->isDeletedAsWritten());
697  AddBoolean(Function->isExplicitlyDefaulted());
698 
699  StringLiteral *DeletedMessage = Function->getDeletedMessage();
700  AddBoolean(DeletedMessage);
701 
702  if (DeletedMessage)
703  ID.AddString(DeletedMessage->getBytes());
704 
705  AddDecl(Function);
706 
707  AddQualType(Function->getReturnType());
708 
709  ID.AddInteger(Function->param_size());
710  for (auto *Param : Function->parameters())
711  AddSubDecl(Param);
712 
713  if (SkipBody) {
714  AddBoolean(false);
715  return;
716  }
717 
718  const bool HasBody = Function->isThisDeclarationADefinition() &&
719  !Function->isDefaulted() && !Function->isDeleted() &&
720  !Function->isLateTemplateParsed();
721  AddBoolean(HasBody);
722  if (!HasBody) {
723  return;
724  }
725 
726  auto *Body = Function->getBody();
727  AddBoolean(Body);
728  if (Body)
729  AddStmt(Body);
730 
731  // Filter out sub-Decls which will not be processed in order to get an
732  // accurate count of Decl's.
734  for (Decl *SubDecl : Function->decls()) {
735  if (isSubDeclToBeProcessed(SubDecl, Function)) {
736  Decls.push_back(SubDecl);
737  }
738  }
739 
740  ID.AddInteger(Decls.size());
741  for (auto SubDecl : Decls) {
742  AddSubDecl(SubDecl);
743  }
744 }
745 
746 void ODRHash::AddEnumDecl(const EnumDecl *Enum) {
747  assert(Enum);
748  AddDeclarationName(Enum->getDeclName());
749 
750  AddBoolean(Enum->isScoped());
751  if (Enum->isScoped())
752  AddBoolean(Enum->isScopedUsingClassTag());
753 
754  if (Enum->getIntegerTypeSourceInfo())
755  AddQualType(Enum->getIntegerType().getCanonicalType());
756 
757  // Filter out sub-Decls which will not be processed in order to get an
758  // accurate count of Decl's.
760  for (Decl *SubDecl : Enum->decls()) {
761  if (isSubDeclToBeProcessed(SubDecl, Enum)) {
762  assert(isa<EnumConstantDecl>(SubDecl) && "Unexpected Decl");
763  Decls.push_back(SubDecl);
764  }
765  }
766 
767  ID.AddInteger(Decls.size());
768  for (auto SubDecl : Decls) {
769  AddSubDecl(SubDecl);
770  }
771 
772 }
773 
775  AddDecl(P);
776 
777  // Hash referenced protocols.
778  ID.AddInteger(P->getReferencedProtocols().size());
779  for (const ObjCProtocolDecl *RefP : P->protocols()) {
780  // Hash the name only as a referenced protocol can be a forward declaration.
781  AddDeclarationName(RefP->getDeclName());
782  }
783 
784  // Filter out sub-Decls which will not be processed in order to get an
785  // accurate count of Decl's.
787  for (Decl *SubDecl : P->decls()) {
788  if (isSubDeclToBeProcessed(SubDecl, P)) {
789  Decls.push_back(SubDecl);
790  }
791  }
792 
793  ID.AddInteger(Decls.size());
794  for (auto *SubDecl : Decls) {
795  AddSubDecl(SubDecl);
796  }
797 }
798 
799 void ODRHash::AddDecl(const Decl *D) {
800  assert(D && "Expecting non-null pointer.");
801  D = D->getCanonicalDecl();
802 
803  const NamedDecl *ND = dyn_cast<NamedDecl>(D);
804  AddBoolean(ND);
805  if (!ND) {
806  ID.AddInteger(D->getKind());
807  return;
808  }
809 
811 
812  const auto *Specialization =
813  dyn_cast<ClassTemplateSpecializationDecl>(D);
815  if (Specialization) {
816  const TemplateArgumentList &List = Specialization->getTemplateArgs();
817  ID.AddInteger(List.size());
818  for (const TemplateArgument &TA : List.asArray())
820  }
821 }
822 
823 namespace {
824 // Process a Type pointer. Add* methods call back into ODRHash while Visit*
825 // methods process the relevant parts of the Type.
826 class ODRTypeVisitor : public TypeVisitor<ODRTypeVisitor> {
827  typedef TypeVisitor<ODRTypeVisitor> Inherited;
828  llvm::FoldingSetNodeID &ID;
829  ODRHash &Hash;
830 
831 public:
832  ODRTypeVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
833  : ID(ID), Hash(Hash) {}
834 
835  void AddStmt(Stmt *S) {
836  Hash.AddBoolean(S);
837  if (S) {
838  Hash.AddStmt(S);
839  }
840  }
841 
842  void AddDecl(const Decl *D) {
843  Hash.AddBoolean(D);
844  if (D) {
845  Hash.AddDecl(D);
846  }
847  }
848 
849  void AddQualType(QualType T) {
850  Hash.AddQualType(T);
851  }
852 
853  void AddType(const Type *T) {
854  Hash.AddBoolean(T);
855  if (T) {
856  Hash.AddType(T);
857  }
858  }
859 
860  void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
861  Hash.AddBoolean(NNS);
862  if (NNS) {
863  Hash.AddNestedNameSpecifier(NNS);
864  }
865  }
866 
867  void AddIdentifierInfo(const IdentifierInfo *II) {
868  Hash.AddBoolean(II);
869  if (II) {
870  Hash.AddIdentifierInfo(II);
871  }
872  }
873 
874  void VisitQualifiers(Qualifiers Quals) {
875  ID.AddInteger(Quals.getAsOpaqueValue());
876  }
877 
878  // Return the RecordType if the typedef only strips away a keyword.
879  // Otherwise, return the original type.
880  static const Type *RemoveTypedef(const Type *T) {
881  const auto *TypedefT = dyn_cast<TypedefType>(T);
882  if (!TypedefT) {
883  return T;
884  }
885 
886  const TypedefNameDecl *D = TypedefT->getDecl();
887  QualType UnderlyingType = D->getUnderlyingType();
888 
889  if (UnderlyingType.hasLocalQualifiers()) {
890  return T;
891  }
892 
893  const auto *ElaboratedT = dyn_cast<ElaboratedType>(UnderlyingType);
894  if (!ElaboratedT) {
895  return T;
896  }
897 
898  if (ElaboratedT->getQualifier() != nullptr) {
899  return T;
900  }
901 
902  QualType NamedType = ElaboratedT->getNamedType();
903  if (NamedType.hasLocalQualifiers()) {
904  return T;
905  }
906 
907  const auto *RecordT = dyn_cast<RecordType>(NamedType);
908  if (!RecordT) {
909  return T;
910  }
911 
912  const IdentifierInfo *TypedefII = TypedefT->getDecl()->getIdentifier();
913  const IdentifierInfo *RecordII = RecordT->getDecl()->getIdentifier();
914  if (!TypedefII || !RecordII ||
915  TypedefII->getName() != RecordII->getName()) {
916  return T;
917  }
918 
919  return RecordT;
920  }
921 
922  void Visit(const Type *T) {
923  T = RemoveTypedef(T);
924  ID.AddInteger(T->getTypeClass());
925  Inherited::Visit(T);
926  }
927 
928  void VisitType(const Type *T) {}
929 
930  void VisitAdjustedType(const AdjustedType *T) {
931  AddQualType(T->getOriginalType());
932 
933  VisitType(T);
934  }
935 
936  void VisitDecayedType(const DecayedType *T) {
937  // getDecayedType and getPointeeType are derived from getAdjustedType
938  // and don't need to be separately processed.
939  VisitAdjustedType(T);
940  }
941 
942  void VisitArrayType(const ArrayType *T) {
943  AddQualType(T->getElementType());
944  ID.AddInteger(llvm::to_underlying(T->getSizeModifier()));
945  VisitQualifiers(T->getIndexTypeQualifiers());
946  VisitType(T);
947  }
948  void VisitConstantArrayType(const ConstantArrayType *T) {
949  T->getSize().Profile(ID);
950  VisitArrayType(T);
951  }
952 
953  void VisitArrayParameterType(const ArrayParameterType *T) {
954  VisitConstantArrayType(T);
955  }
956 
957  void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
958  AddStmt(T->getSizeExpr());
959  VisitArrayType(T);
960  }
961 
962  void VisitIncompleteArrayType(const IncompleteArrayType *T) {
963  VisitArrayType(T);
964  }
965 
966  void VisitVariableArrayType(const VariableArrayType *T) {
967  AddStmt(T->getSizeExpr());
968  VisitArrayType(T);
969  }
970 
971  void VisitAttributedType(const AttributedType *T) {
972  ID.AddInteger(T->getAttrKind());
973  AddQualType(T->getModifiedType());
974 
975  VisitType(T);
976  }
977 
978  void VisitBlockPointerType(const BlockPointerType *T) {
979  AddQualType(T->getPointeeType());
980  VisitType(T);
981  }
982 
983  void VisitBuiltinType(const BuiltinType *T) {
984  ID.AddInteger(T->getKind());
985  VisitType(T);
986  }
987 
988  void VisitComplexType(const ComplexType *T) {
989  AddQualType(T->getElementType());
990  VisitType(T);
991  }
992 
993  void VisitDecltypeType(const DecltypeType *T) {
994  AddStmt(T->getUnderlyingExpr());
995  VisitType(T);
996  }
997 
998  void VisitDependentDecltypeType(const DependentDecltypeType *T) {
999  VisitDecltypeType(T);
1000  }
1001 
1002  void VisitDeducedType(const DeducedType *T) {
1003  AddQualType(T->getDeducedType());
1004  VisitType(T);
1005  }
1006 
1007  void VisitAutoType(const AutoType *T) {
1008  ID.AddInteger((unsigned)T->getKeyword());
1009  ID.AddInteger(T->isConstrained());
1010  if (T->isConstrained()) {
1011  AddDecl(T->getTypeConstraintConcept());
1012  ID.AddInteger(T->getTypeConstraintArguments().size());
1013  for (const auto &TA : T->getTypeConstraintArguments())
1014  Hash.AddTemplateArgument(TA);
1015  }
1016  VisitDeducedType(T);
1017  }
1018 
1019  void VisitDeducedTemplateSpecializationType(
1021  Hash.AddTemplateName(T->getTemplateName());
1022  VisitDeducedType(T);
1023  }
1024 
1025  void VisitDependentAddressSpaceType(const DependentAddressSpaceType *T) {
1026  AddQualType(T->getPointeeType());
1027  AddStmt(T->getAddrSpaceExpr());
1028  VisitType(T);
1029  }
1030 
1031  void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T) {
1032  AddQualType(T->getElementType());
1033  AddStmt(T->getSizeExpr());
1034  VisitType(T);
1035  }
1036 
1037  void VisitFunctionType(const FunctionType *T) {
1038  AddQualType(T->getReturnType());
1039  T->getExtInfo().Profile(ID);
1040  Hash.AddBoolean(T->isConst());
1041  Hash.AddBoolean(T->isVolatile());
1042  Hash.AddBoolean(T->isRestrict());
1043  VisitType(T);
1044  }
1045 
1046  void VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1047  VisitFunctionType(T);
1048  }
1049 
1050  void VisitFunctionProtoType(const FunctionProtoType *T) {
1051  ID.AddInteger(T->getNumParams());
1052  for (auto ParamType : T->getParamTypes())
1053  AddQualType(ParamType);
1054 
1055  VisitFunctionType(T);
1056  }
1057 
1058  void VisitInjectedClassNameType(const InjectedClassNameType *T) {
1059  AddDecl(T->getDecl());
1060  VisitType(T);
1061  }
1062 
1063  void VisitMemberPointerType(const MemberPointerType *T) {
1064  AddQualType(T->getPointeeType());
1065  AddType(T->getClass());
1066  VisitType(T);
1067  }
1068 
1069  void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1070  AddQualType(T->getPointeeType());
1071  VisitType(T);
1072  }
1073 
1074  void VisitObjCObjectType(const ObjCObjectType *T) {
1075  AddDecl(T->getInterface());
1076 
1077  auto TypeArgs = T->getTypeArgsAsWritten();
1078  ID.AddInteger(TypeArgs.size());
1079  for (auto Arg : TypeArgs) {
1080  AddQualType(Arg);
1081  }
1082 
1083  auto Protocols = T->getProtocols();
1084  ID.AddInteger(Protocols.size());
1085  for (auto *Protocol : Protocols) {
1086  AddDecl(Protocol);
1087  }
1088 
1089  Hash.AddBoolean(T->isKindOfType());
1090 
1091  VisitType(T);
1092  }
1093 
1094  void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1095  // This type is handled by the parent type ObjCObjectType.
1096  VisitObjCObjectType(T);
1097  }
1098 
1099  void VisitObjCTypeParamType(const ObjCTypeParamType *T) {
1100  AddDecl(T->getDecl());
1101  auto Protocols = T->getProtocols();
1102  ID.AddInteger(Protocols.size());
1103  for (auto *Protocol : Protocols) {
1104  AddDecl(Protocol);
1105  }
1106 
1107  VisitType(T);
1108  }
1109 
1110  void VisitPackExpansionType(const PackExpansionType *T) {
1111  AddQualType(T->getPattern());
1112  VisitType(T);
1113  }
1114 
1115  void VisitParenType(const ParenType *T) {
1116  AddQualType(T->getInnerType());
1117  VisitType(T);
1118  }
1119 
1120  void VisitPipeType(const PipeType *T) {
1121  AddQualType(T->getElementType());
1122  Hash.AddBoolean(T->isReadOnly());
1123  VisitType(T);
1124  }
1125 
1126  void VisitPointerType(const PointerType *T) {
1127  AddQualType(T->getPointeeType());
1128  VisitType(T);
1129  }
1130 
1131  void VisitReferenceType(const ReferenceType *T) {
1132  AddQualType(T->getPointeeTypeAsWritten());
1133  VisitType(T);
1134  }
1135 
1136  void VisitLValueReferenceType(const LValueReferenceType *T) {
1137  VisitReferenceType(T);
1138  }
1139 
1140  void VisitRValueReferenceType(const RValueReferenceType *T) {
1141  VisitReferenceType(T);
1142  }
1143 
1144  void
1145  VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T) {
1146  AddDecl(T->getAssociatedDecl());
1147  Hash.AddTemplateArgument(T->getArgumentPack());
1148  VisitType(T);
1149  }
1150 
1151  void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
1152  AddDecl(T->getAssociatedDecl());
1153  AddQualType(T->getReplacementType());
1154  VisitType(T);
1155  }
1156 
1157  void VisitTagType(const TagType *T) {
1158  AddDecl(T->getDecl());
1159  VisitType(T);
1160  }
1161 
1162  void VisitRecordType(const RecordType *T) { VisitTagType(T); }
1163  void VisitEnumType(const EnumType *T) { VisitTagType(T); }
1164 
1165  void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
1166  ID.AddInteger(T->template_arguments().size());
1167  for (const auto &TA : T->template_arguments()) {
1168  Hash.AddTemplateArgument(TA);
1169  }
1170  Hash.AddTemplateName(T->getTemplateName());
1171  VisitType(T);
1172  }
1173 
1174  void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
1175  ID.AddInteger(T->getDepth());
1176  ID.AddInteger(T->getIndex());
1177  Hash.AddBoolean(T->isParameterPack());
1178  AddDecl(T->getDecl());
1179  }
1180 
1181  void VisitTypedefType(const TypedefType *T) {
1182  AddDecl(T->getDecl());
1183  VisitType(T);
1184  }
1185 
1186  void VisitTypeOfExprType(const TypeOfExprType *T) {
1187  AddStmt(T->getUnderlyingExpr());
1188  Hash.AddBoolean(T->isSugared());
1189 
1190  VisitType(T);
1191  }
1192  void VisitTypeOfType(const TypeOfType *T) {
1193  AddQualType(T->getUnmodifiedType());
1194  VisitType(T);
1195  }
1196 
1197  void VisitTypeWithKeyword(const TypeWithKeyword *T) {
1198  ID.AddInteger(llvm::to_underlying(T->getKeyword()));
1199  VisitType(T);
1200  };
1201 
1202  void VisitDependentNameType(const DependentNameType *T) {
1203  AddNestedNameSpecifier(T->getQualifier());
1204  AddIdentifierInfo(T->getIdentifier());
1205  VisitTypeWithKeyword(T);
1206  }
1207 
1208  void VisitDependentTemplateSpecializationType(
1210  AddIdentifierInfo(T->getIdentifier());
1211  AddNestedNameSpecifier(T->getQualifier());
1212  ID.AddInteger(T->template_arguments().size());
1213  for (const auto &TA : T->template_arguments()) {
1214  Hash.AddTemplateArgument(TA);
1215  }
1216  VisitTypeWithKeyword(T);
1217  }
1218 
1219  void VisitElaboratedType(const ElaboratedType *T) {
1220  AddNestedNameSpecifier(T->getQualifier());
1221  AddQualType(T->getNamedType());
1222  VisitTypeWithKeyword(T);
1223  }
1224 
1225  void VisitUnaryTransformType(const UnaryTransformType *T) {
1226  AddQualType(T->getUnderlyingType());
1227  AddQualType(T->getBaseType());
1228  VisitType(T);
1229  }
1230 
1231  void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
1232  AddDecl(T->getDecl());
1233  VisitType(T);
1234  }
1235 
1236  void VisitVectorType(const VectorType *T) {
1237  AddQualType(T->getElementType());
1238  ID.AddInteger(T->getNumElements());
1239  ID.AddInteger(llvm::to_underlying(T->getVectorKind()));
1240  VisitType(T);
1241  }
1242 
1243  void VisitExtVectorType(const ExtVectorType * T) {
1244  VisitVectorType(T);
1245  }
1246 };
1247 } // namespace
1248 
1249 void ODRHash::AddType(const Type *T) {
1250  assert(T && "Expecting non-null pointer.");
1251  ODRTypeVisitor(ID, *this).Visit(T);
1252 }
1253 
1255  AddBoolean(T.isNull());
1256  if (T.isNull())
1257  return;
1258  SplitQualType split = T.split();
1259  ID.AddInteger(split.Quals.getAsOpaqueValue());
1260  AddType(split.Ty);
1261 }
1262 
1264  Bools.push_back(Value);
1265 }
1266 
1268  ID.AddInteger(Value.getKind());
1269 
1270  // 'APValue::Profile' uses pointer values to make hash for LValue and
1271  // MemberPointer, but they differ from one compiler invocation to another.
1272  // So, handle them explicitly here.
1273 
1274  switch (Value.getKind()) {
1275  case APValue::LValue: {
1276  const APValue::LValueBase &Base = Value.getLValueBase();
1277  if (!Base) {
1278  ID.AddInteger(Value.getLValueOffset().getQuantity());
1279  break;
1280  }
1281 
1282  assert(Base.is<const ValueDecl *>());
1283  AddDecl(Base.get<const ValueDecl *>());
1284  ID.AddInteger(Value.getLValueOffset().getQuantity());
1285 
1286  bool OnePastTheEnd = Value.isLValueOnePastTheEnd();
1287  if (Value.hasLValuePath()) {
1288  QualType TypeSoFar = Base.getType();
1289  for (APValue::LValuePathEntry E : Value.getLValuePath()) {
1290  if (const auto *AT = TypeSoFar->getAsArrayTypeUnsafe()) {
1291  if (const auto *CAT = dyn_cast<ConstantArrayType>(AT))
1292  OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
1293  TypeSoFar = AT->getElementType();
1294  } else {
1295  const Decl *D = E.getAsBaseOrMember().getPointer();
1296  if (const auto *FD = dyn_cast<FieldDecl>(D)) {
1297  if (FD->getParent()->isUnion())
1298  ID.AddInteger(FD->getFieldIndex());
1299  TypeSoFar = FD->getType();
1300  } else {
1301  TypeSoFar =
1302  D->getASTContext().getRecordType(cast<CXXRecordDecl>(D));
1303  }
1304  }
1305  }
1306  }
1307  unsigned Val = 0;
1308  if (Value.isNullPointer())
1309  Val |= 1 << 0;
1310  if (OnePastTheEnd)
1311  Val |= 1 << 1;
1312  if (Value.hasLValuePath())
1313  Val |= 1 << 2;
1314  ID.AddInteger(Val);
1315  break;
1316  }
1317  case APValue::MemberPointer: {
1318  const ValueDecl *D = Value.getMemberPointerDecl();
1319  assert(D);
1320  AddDecl(D);
1321  ID.AddInteger(
1323  break;
1324  }
1325  default:
1326  Value.Profile(ID);
1327  }
1328 }
NodeId Parent
Definition: ASTDiff.cpp:191
StringRef P
static char ID
Definition: Arena.cpp:183
CompileCommand Cmd
llvm::MachO::Record Record
Definition: MachO.h:31
This file contains the declaration of the ODRHash class, which calculates a hash based on AST nodes,...
A non-discriminated union of a base, field, or array index.
Definition: APValue.h:208
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
CharUnits getMemberPointerPathAdjustment(const APValue &MP) const
Find the 'this' offset for the member path in a pointer-to-member APValue.
QualType getRecordType(const RecordDecl *Decl) const
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:86
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:3310
Represents a constant array type that does not decay to a pointer when used as a function parameter.
Definition: Type.h:3700
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3530
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:5616
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:5993
Pointer to a block type.
Definition: Type.h:3361
This class is used for builtin types like 'int'.
Definition: Type.h:2989
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:185
Declaration of a class template.
Complex values, per C99 6.2.5p11.
Definition: Type.h:3098
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:74
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3568
Represents a pointer type decayed from an array or function type.
Definition: Type.h:3344
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
bool isFileContext() const
Definition: DeclBase.h:2137
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2066
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
Definition: DeclBase.h:2082
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2322
Decl::Kind getDeclKind() const
Definition: DeclBase.h:2059
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:599
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:968
AccessSpecifier getAccess() const
Definition: DeclBase.h:513
Kind getKind() const
Definition: DeclBase.h:448
DeclContext * getDeclContext()
Definition: DeclBase.h:454
The name of a declaration.
Represents the type decltype(expr) (C++11).
Definition: Type.h:5370
Represents a C++17 deduced template specialization type.
Definition: Type.h:6041
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Definition: Type.h:5959
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3871
Internal representation of canonical, dependent decltype(expr) types.
Definition: Type.h:5398
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:6464
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3813
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3911
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:6516
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6383
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3300
const Expr * getInitExpr() const
Definition: Decl.h:3318
Represents an enum.
Definition: Decl.h:3870
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5587
ExtVectorType - Extended vector type.
Definition: Type.h:4073
Represents a member of a struct/union/class.
Definition: Decl.h:3060
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:3148
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4574
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:3151
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition: Decl.h:3164
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition: DeclFriend.h:54
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition: DeclFriend.h:137
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:122
Represents a function declaration or definition.
Definition: Decl.h:1972
unsigned getODRHash()
Returns ODRHash of the function.
Definition: Decl.cpp:4528
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4623
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4668
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:4908
unsigned getNumParams() const
Definition: Type.h:4901
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.cpp:3799
bool isSugared() const
Definition: Type.h:5134
Declaration of a template function.
Definition: DeclTemplate.h:957
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:4498
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:4268
ExtInfo getExtInfo() const
Definition: Type.h:4597
bool isConst() const
Definition: Type.h:4603
bool isRestrict() const
Definition: Type.h:4605
QualType getReturnType() const
Definition: Type.h:4585
bool isVolatile() const
Definition: Type.h:4604
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
Represents a C array with an unspecified size.
Definition: Type.h:3715
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:6233
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3436
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3472
This represents a decl that may have a name.
Definition: Decl.h:249
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:315
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
void AddDecl(const Decl *D)
Definition: ODRHash.cpp:799
void AddStmt(const Stmt *S)
Definition: ODRHash.cpp:24
void AddStructuralValue(const APValue &)
Definition: ODRHash.cpp:1267
void AddCXXRecordDecl(const CXXRecordDecl *Record)
Definition: ODRHash.cpp:561
void clear()
Definition: ODRHash.cpp:212
void AddIdentifierInfo(const IdentifierInfo *II)
Definition: ODRHash.cpp:29
void AddObjCProtocolDecl(const ObjCProtocolDecl *P)
Definition: ODRHash.cpp:774
void AddDeclarationName(DeclarationName Name, bool TreatAsDecl=false)
Definition: ODRHash.cpp:34
void AddObjCInterfaceDecl(const ObjCInterfaceDecl *Record)
Definition: ODRHash.cpp:626
void AddType(const Type *T)
Definition: ODRHash.cpp:1249
void AddEnumDecl(const EnumDecl *Enum)
Definition: ODRHash.cpp:746
void AddNestedNameSpecifier(const NestedNameSpecifier *NNS)
Definition: ODRHash.cpp:112
void AddFunctionDecl(const FunctionDecl *Function, bool SkipBody=false)
Definition: ODRHash.cpp:653
void AddBoolean(bool value)
Definition: ODRHash.cpp:1263
void AddTemplateName(TemplateName Name)
Definition: ODRHash.cpp:141
void AddRecordDecl(const RecordDecl *Record)
Definition: ODRHash.cpp:608
void AddSubDecl(const Decl *D)
Definition: ODRHash.cpp:555
void AddQualType(QualType T)
Definition: ODRHash.cpp:1254
void AddTemplateParameterList(const TemplateParameterList *TPL)
Definition: ODRHash.cpp:203
void AddTemplateArgument(TemplateArgument TA)
Definition: ODRHash.cpp:161
unsigned CalculateHash()
Definition: ODRHash.cpp:218
static bool isSubDeclToBeProcessed(const Decl *D, const DeclContext *Parent)
Definition: ODRHash.cpp:529
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
protocol_range protocols() const
Definition: DeclObjC.h:1358
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:352
const ObjCProtocolList & getReferencedProtocols() const
Definition: DeclObjC.h:1332
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:6964
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1950
AccessControl getCanonicalAccessControl() const
Definition: DeclObjC.h:2000
unsigned size() const
Definition: DeclObjC.h:70
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
bool hasBody() const override
Determine whether this method has a body.
Definition: DeclObjC.h:523
unsigned param_size() const
Definition: DeclObjC.h:347
bool isVariadic() const
Definition: DeclObjC.h:431
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Definition: DeclObjC.cpp:909
ImplicitParamDecl * getCmdDecl() const
Definition: DeclObjC.h:420
bool isSynthesizedAccessorStub() const
Definition: DeclObjC.h:444
ImplicitParamDecl * getSelfDecl() const
Definition: DeclObjC.h:418
bool isDirectMethod() const
True if the method is tagged as objc_direct.
Definition: DeclObjC.cpp:871
bool isInstanceMethod() const
Definition: DeclObjC.h:426
bool isThisDeclarationADefinition() const
Returns whether this specific method is a definition.
Definition: DeclObjC.h:534
bool isThisDeclarationADesignatedInitializer() const
Returns true if this specific method declaration is marked with the designated initializer attribute.
Definition: DeclObjC.cpp:876
bool isDefined() const
Definition: DeclObjC.h:452
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
Definition: DeclObjC.cpp:1053
ObjCImplementationControl getImplementationControl() const
Definition: DeclObjC.h:500
bool hasSkippedBody() const
True if the method was a definition but its body was skipped.
Definition: DeclObjC.h:477
ArrayRef< ParmVarDecl * > parameters() const
Definition: DeclObjC.h:373
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition: DeclObjC.h:343
Represents a pointer to an Objective C object.
Definition: Type.h:7020
Represents a class type in Objective C.
Definition: Type.h:6766
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition: DeclObjC.h:814
TypeSourceInfo * getTypeSourceInfo() const
Definition: DeclObjC.h:801
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:911
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2082
Represents a type parameter type in Objective C.
Definition: Type.h:6692
Represents a pack expansion of types.
Definition: Type.h:6581
Sugar for parentheses used when specifying types.
Definition: Type.h:3125
Represents a parameter to a function.
Definition: Decl.h:1762
PipeType - OpenCL20.
Definition: Type.h:7220
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3151
A (possibly-)qualified type.
Definition: Type.h:940
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
Definition: Type.h:1067
The collection of all-type qualifiers we support.
Definition: Type.h:318
uint64_t getAsOpaqueValue() const
Definition: Type.h:441
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3454
Represents a struct/union/class.
Definition: Decl.h:4171
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5561
Declaration of a redeclarable template.
Definition: DeclTemplate.h:716
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Definition: DeclTemplate.h:860
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3392
Smart pointer class that efficiently represents Objective-C method names.
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:4058
Stmt - This represents one statement.
Definition: Stmt.h:84
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1773
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition: Expr.h:1858
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:5901
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:5831
A template argument list.
Definition: DeclTemplate.h:244
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
Represents a template argument.
Definition: TemplateBase.h:61
QualType getStructuralValueType() const
Get the type of a StructuralValue.
Definition: TemplateBase.h:399
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:319
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:363
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:396
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:438
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:326
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:408
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:432
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
Definition: TemplateBase.h:350
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:394
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:413
Represents a C++ template name within the type system.
Definition: TemplateName.h:202
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
Definition: TemplateName.h:247
@ OverloadedTemplate
A set of overloaded template declarations.
Definition: TemplateName.h:222
@ Template
A single template declaration.
Definition: TemplateName.h:219
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:234
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:238
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
Definition: TemplateName.h:243
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
Definition: TemplateName.h:230
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
Definition: TemplateName.h:226
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:139
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6101
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Declaration of a template type parameter.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
bool isParameterPack() const
Returns whether this is a parameter pack.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3558
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition: ASTConcept.h:231
Expr * getImmediatelyDeclaredConstraint() const
Get the immediately-declared constraint expression introduced by this type-constraint,...
Definition: ASTConcept.h:246
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition: Type.h:5286
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:5334
A container of type source information.
Definition: Type.h:7342
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7353
An operation on a type.
Definition: TypeVisitor.h:64
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition: Type.h:6332
The base class of the type hierarchy.
Definition: Type.h:1813
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:8213
TypeClass getTypeClass() const
Definition: Type.h:2300
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3537
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3435
QualType getUnderlyingType() const
Definition: Decl.h:3490
A unary type transform, which is a type constructed from another.
Definition: Type.h:5478
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5156
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:707
Kind getKind() const
Definition: Value.h:136
Represents a variable declaration or definition.
Definition: Decl.h:919
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1550
bool hasInit() const
Definition: Decl.cpp:2399
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
Definition: Decl.h:1196
const Expr * getInit() const
Definition: Decl.h:1356
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3759
Represents a GCC generic vector type.
Definition: Type.h:3981
#define CHAR_BIT
Definition: limits.h:71
The JSON file list parser is used to communicate input to InstallAPI.
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
const FunctionProtoType * T
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:873
const Type * Ty
The locally-unqualified type.
Definition: Type.h:875
Qualifiers Quals
The local qualifiers.
Definition: Type.h:878
#define remainder(__x, __y)
Definition: tgmath.h:1090