clang  7.0.0
ODRHash.cpp
Go to the documentation of this file.
1 //===-- ODRHash.cpp - Hashing to diagnose ODR failures ----------*- C++ -*-===//
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 /// \file
11 /// This file implements the ODRHash class, which calculates a hash based
12 /// on AST nodes, which is stable across different runs.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #include "clang/AST/ODRHash.h"
17 
18 #include "clang/AST/DeclVisitor.h"
20 #include "clang/AST/StmtVisitor.h"
21 #include "clang/AST/TypeVisitor.h"
22 
23 using namespace clang;
24 
25 void ODRHash::AddStmt(const Stmt *S) {
26  assert(S && "Expecting non-null pointer.");
27  S->ProcessODRHash(ID, *this);
28 }
29 
31  assert(II && "Expecting non-null pointer.");
32  ID.AddString(II->getName());
33 }
34 
36  // Index all DeclarationName and use index numbers to refer to them.
37  auto Result = DeclNameMap.insert(std::make_pair(Name, DeclNameMap.size()));
38  ID.AddInteger(Result.first->second);
39  if (!Result.second) {
40  // If found in map, the the DeclarationName has previously been processed.
41  return;
42  }
43 
44  // First time processing each DeclarationName, also process its details.
45  AddBoolean(Name.isEmpty());
46  if (Name.isEmpty())
47  return;
48 
49  auto Kind = Name.getNameKind();
50  ID.AddInteger(Kind);
51  switch (Kind) {
54  break;
58  Selector S = Name.getObjCSelector();
59  AddBoolean(S.isNull());
62  unsigned NumArgs = S.getNumArgs();
63  for (unsigned i = 0; i < NumArgs; ++i) {
65  }
66  break;
67  }
71  break;
73  ID.AddInteger(Name.getCXXOverloadedOperator());
74  break;
77  break;
80  break;
82  break;
84  auto *Template = Name.getCXXDeductionGuideTemplate();
85  AddBoolean(Template);
86  if (Template) {
87  AddDecl(Template);
88  }
89  }
90  }
91 }
92 
94  assert(NNS && "Expecting non-null pointer.");
95  const auto *Prefix = NNS->getPrefix();
96  AddBoolean(Prefix);
97  if (Prefix) {
98  AddNestedNameSpecifier(Prefix);
99  }
100  auto Kind = NNS->getKind();
101  ID.AddInteger(Kind);
102  switch (Kind) {
105  break;
107  AddDecl(NNS->getAsNamespace());
108  break;
111  break;
114  AddType(NNS->getAsType());
115  break;
118  break;
119  }
120 }
121 
123  auto Kind = Name.getKind();
124  ID.AddInteger(Kind);
125 
126  switch (Kind) {
128  AddDecl(Name.getAsTemplateDecl());
129  break;
130  // TODO: Support these cases.
136  break;
137  }
138 }
139 
141  const auto Kind = TA.getKind();
142  ID.AddInteger(Kind);
143 
144  switch (Kind) {
146  llvm_unreachable("Expected valid TemplateArgument");
148  AddQualType(TA.getAsType());
149  break;
151  AddDecl(TA.getAsDecl());
152  break;
155  break;
159  break;
161  AddStmt(TA.getAsExpr());
162  break;
164  ID.AddInteger(TA.pack_size());
165  for (auto SubTA : TA.pack_elements()) {
166  AddTemplateArgument(SubTA);
167  }
168  break;
169  }
170 }
171 
173  assert(TPL && "Expecting non-null pointer.");
174 
175  ID.AddInteger(TPL->size());
176  for (auto *ND : TPL->asArray()) {
177  AddSubDecl(ND);
178  }
179 }
180 
182  DeclNameMap.clear();
183  Bools.clear();
184  ID.clear();
185 }
186 
188  // Append the bools to the end of the data segment backwards. This allows
189  // for the bools data to be compressed 32 times smaller compared to using
190  // ID.AddBoolean
191  const unsigned unsigned_bits = sizeof(unsigned) * CHAR_BIT;
192  const unsigned size = Bools.size();
193  const unsigned remainder = size % unsigned_bits;
194  const unsigned loops = size / unsigned_bits;
195  auto I = Bools.rbegin();
196  unsigned value = 0;
197  for (unsigned i = 0; i < remainder; ++i) {
198  value <<= 1;
199  value |= *I;
200  ++I;
201  }
202  ID.AddInteger(value);
203 
204  for (unsigned i = 0; i < loops; ++i) {
205  value = 0;
206  for (unsigned j = 0; j < unsigned_bits; ++j) {
207  value <<= 1;
208  value |= *I;
209  ++I;
210  }
211  ID.AddInteger(value);
212  }
213 
214  assert(I == Bools.rend());
215  Bools.clear();
216  return ID.ComputeHash();
217 }
218 
219 namespace {
220 // Process a Decl pointer. Add* methods call back into ODRHash while Visit*
221 // methods process the relevant parts of the Decl.
222 class ODRDeclVisitor : public ConstDeclVisitor<ODRDeclVisitor> {
223  typedef ConstDeclVisitor<ODRDeclVisitor> Inherited;
224  llvm::FoldingSetNodeID &ID;
225  ODRHash &Hash;
226 
227 public:
228  ODRDeclVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
229  : ID(ID), Hash(Hash) {}
230 
231  void AddStmt(const Stmt *S) {
232  Hash.AddBoolean(S);
233  if (S) {
234  Hash.AddStmt(S);
235  }
236  }
237 
238  void AddIdentifierInfo(const IdentifierInfo *II) {
239  Hash.AddBoolean(II);
240  if (II) {
241  Hash.AddIdentifierInfo(II);
242  }
243  }
244 
245  void AddQualType(QualType T) {
246  Hash.AddQualType(T);
247  }
248 
249  void AddDecl(const Decl *D) {
250  Hash.AddBoolean(D);
251  if (D) {
252  Hash.AddDecl(D);
253  }
254  }
255 
257  Hash.AddTemplateArgument(TA);
258  }
259 
260  void Visit(const Decl *D) {
261  ID.AddInteger(D->getKind());
262  Inherited::Visit(D);
263  }
264 
265  void VisitNamedDecl(const NamedDecl *D) {
266  Hash.AddDeclarationName(D->getDeclName());
267  Inherited::VisitNamedDecl(D);
268  }
269 
270  void VisitValueDecl(const ValueDecl *D) {
271  if (!isa<FunctionDecl>(D)) {
272  AddQualType(D->getType());
273  }
274  Inherited::VisitValueDecl(D);
275  }
276 
277  void VisitVarDecl(const VarDecl *D) {
278  Hash.AddBoolean(D->isStaticLocal());
279  Hash.AddBoolean(D->isConstexpr());
280  const bool HasInit = D->hasInit();
281  Hash.AddBoolean(HasInit);
282  if (HasInit) {
283  AddStmt(D->getInit());
284  }
285  Inherited::VisitVarDecl(D);
286  }
287 
288  void VisitParmVarDecl(const ParmVarDecl *D) {
289  // TODO: Handle default arguments.
290  Inherited::VisitParmVarDecl(D);
291  }
292 
293  void VisitAccessSpecDecl(const AccessSpecDecl *D) {
294  ID.AddInteger(D->getAccess());
295  Inherited::VisitAccessSpecDecl(D);
296  }
297 
298  void VisitStaticAssertDecl(const StaticAssertDecl *D) {
299  AddStmt(D->getAssertExpr());
300  AddStmt(D->getMessage());
301 
302  Inherited::VisitStaticAssertDecl(D);
303  }
304 
305  void VisitFieldDecl(const FieldDecl *D) {
306  const bool IsBitfield = D->isBitField();
307  Hash.AddBoolean(IsBitfield);
308 
309  if (IsBitfield) {
310  AddStmt(D->getBitWidth());
311  }
312 
313  Hash.AddBoolean(D->isMutable());
315 
316  Inherited::VisitFieldDecl(D);
317  }
318 
319  void VisitFunctionDecl(const FunctionDecl *D) {
320  // Handled by the ODRHash for FunctionDecl
321  ID.AddInteger(D->getODRHash());
322 
323  Inherited::VisitFunctionDecl(D);
324  }
325 
326  void VisitCXXMethodDecl(const CXXMethodDecl *D) {
327  // Handled by the ODRHash for FunctionDecl
328 
329  Inherited::VisitCXXMethodDecl(D);
330  }
331 
332  void VisitTypedefNameDecl(const TypedefNameDecl *D) {
334 
335  Inherited::VisitTypedefNameDecl(D);
336  }
337 
338  void VisitTypedefDecl(const TypedefDecl *D) {
339  Inherited::VisitTypedefDecl(D);
340  }
341 
342  void VisitTypeAliasDecl(const TypeAliasDecl *D) {
343  Inherited::VisitTypeAliasDecl(D);
344  }
345 
346  void VisitFriendDecl(const FriendDecl *D) {
347  TypeSourceInfo *TSI = D->getFriendType();
348  Hash.AddBoolean(TSI);
349  if (TSI) {
350  AddQualType(TSI->getType());
351  } else {
352  AddDecl(D->getFriendDecl());
353  }
354  }
355 
356  void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
357  // Only care about default arguments as part of the definition.
358  const bool hasDefaultArgument =
360  Hash.AddBoolean(hasDefaultArgument);
361  if (hasDefaultArgument) {
363  }
364  Hash.AddBoolean(D->isParameterPack());
365 
366  Inherited::VisitTemplateTypeParmDecl(D);
367  }
368 
369  void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
370  // Only care about default arguments as part of the definition.
371  const bool hasDefaultArgument =
373  Hash.AddBoolean(hasDefaultArgument);
374  if (hasDefaultArgument) {
376  }
377  Hash.AddBoolean(D->isParameterPack());
378 
379  Inherited::VisitNonTypeTemplateParmDecl(D);
380  }
381 
382  void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) {
383  // Only care about default arguments as part of the definition.
384  const bool hasDefaultArgument =
386  Hash.AddBoolean(hasDefaultArgument);
387  if (hasDefaultArgument) {
389  }
390  Hash.AddBoolean(D->isParameterPack());
391 
392  Inherited::VisitTemplateTemplateParmDecl(D);
393  }
394 
395  void VisitTemplateDecl(const TemplateDecl *D) {
397 
398  Inherited::VisitTemplateDecl(D);
399  }
400 
401  void VisitRedeclarableTemplateDecl(const RedeclarableTemplateDecl *D) {
403  Inherited::VisitRedeclarableTemplateDecl(D);
404  }
405 
406  void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
408  Inherited::VisitFunctionTemplateDecl(D);
409  }
410 
411  void VisitEnumConstantDecl(const EnumConstantDecl *D) {
412  AddStmt(D->getInitExpr());
413  Inherited::VisitEnumConstantDecl(D);
414  }
415 };
416 } // namespace
417 
418 // Only allow a small portion of Decl's to be processed. Remove this once
419 // all Decl's can be handled.
421  if (D->isImplicit()) return false;
422  if (D->getDeclContext() != Parent) return false;
423 
424  switch (D->getKind()) {
425  default:
426  return false;
427  case Decl::AccessSpec:
428  case Decl::CXXConstructor:
429  case Decl::CXXDestructor:
430  case Decl::CXXMethod:
431  case Decl::EnumConstant: // Only found in EnumDecl's.
432  case Decl::Field:
433  case Decl::Friend:
434  case Decl::FunctionTemplate:
435  case Decl::StaticAssert:
436  case Decl::TypeAlias:
437  case Decl::Typedef:
438  case Decl::Var:
439  return true;
440  }
441 }
442 
443 void ODRHash::AddSubDecl(const Decl *D) {
444  assert(D && "Expecting non-null pointer.");
445 
446  ODRDeclVisitor(ID, *this).Visit(D);
447 }
448 
450  assert(Record && Record->hasDefinition() &&
451  "Expected non-null record to be a definition.");
452 
453  const DeclContext *DC = Record;
454  while (DC) {
455  if (isa<ClassTemplateSpecializationDecl>(DC)) {
456  return;
457  }
458  DC = DC->getParent();
459  }
460 
461  AddDecl(Record);
462 
463  // Filter out sub-Decls which will not be processed in order to get an
464  // accurate count of Decl's.
466  for (Decl *SubDecl : Record->decls()) {
467  if (isWhitelistedDecl(SubDecl, Record)) {
468  Decls.push_back(SubDecl);
469  if (auto *Function = dyn_cast<FunctionDecl>(SubDecl)) {
470  // Compute/Preload ODRHash into FunctionDecl.
471  Function->getODRHash();
472  }
473  }
474  }
475 
476  ID.AddInteger(Decls.size());
477  for (auto SubDecl : Decls) {
478  AddSubDecl(SubDecl);
479  }
480 
481  const ClassTemplateDecl *TD = Record->getDescribedClassTemplate();
482  AddBoolean(TD);
483  if (TD) {
485  }
486 
487  ID.AddInteger(Record->getNumBases());
488  auto Bases = Record->bases();
489  for (auto Base : Bases) {
490  AddQualType(Base.getType());
491  ID.AddInteger(Base.isVirtual());
492  ID.AddInteger(Base.getAccessSpecifierAsWritten());
493  }
494 }
495 
497  bool SkipBody) {
498  assert(Function && "Expecting non-null pointer.");
499 
500  // Skip functions that are specializations or in specialization context.
501  const DeclContext *DC = Function;
502  while (DC) {
503  if (isa<ClassTemplateSpecializationDecl>(DC)) return;
504  if (auto *F = dyn_cast<FunctionDecl>(DC)) {
505  if (F->isFunctionTemplateSpecialization()) {
506  if (!isa<CXXMethodDecl>(DC)) return;
507  if (DC->getLexicalParent()->isFileContext()) return;
508  // Inline method specializations are the only supported
509  // specialization for now.
510  }
511  }
512  DC = DC->getParent();
513  }
514 
515  ID.AddInteger(Function->getDeclKind());
516 
517  const auto *SpecializationArgs = Function->getTemplateSpecializationArgs();
518  AddBoolean(SpecializationArgs);
519  if (SpecializationArgs) {
520  ID.AddInteger(SpecializationArgs->size());
521  for (const TemplateArgument &TA : SpecializationArgs->asArray()) {
523  }
524  }
525 
526  if (const auto *Method = dyn_cast<CXXMethodDecl>(Function)) {
527  AddBoolean(Method->isConst());
528  AddBoolean(Method->isVolatile());
529  }
530 
531  ID.AddInteger(Function->getStorageClass());
532  AddBoolean(Function->isInlineSpecified());
533  AddBoolean(Function->isVirtualAsWritten());
534  AddBoolean(Function->isPure());
535  AddBoolean(Function->isDeletedAsWritten());
536  AddBoolean(Function->isExplicitlyDefaulted());
537 
538  AddDecl(Function);
539 
540  AddQualType(Function->getReturnType());
541 
542  ID.AddInteger(Function->param_size());
543  for (auto Param : Function->parameters())
544  AddSubDecl(Param);
545 
546  if (SkipBody) {
547  AddBoolean(false);
548  return;
549  }
550 
551  const bool HasBody = Function->isThisDeclarationADefinition() &&
552  !Function->isDefaulted() && !Function->isDeleted() &&
553  !Function->isLateTemplateParsed();
554  AddBoolean(HasBody);
555  if (HasBody) {
556  auto *Body = Function->getBody();
557  AddBoolean(Body);
558  if (Body)
559  AddStmt(Body);
560  }
561 }
562 
563 void ODRHash::AddEnumDecl(const EnumDecl *Enum) {
564  assert(Enum);
566 
567  AddBoolean(Enum->isScoped());
568  if (Enum->isScoped())
570 
571  if (Enum->getIntegerTypeSourceInfo())
572  AddQualType(Enum->getIntegerType());
573 
574  // Filter out sub-Decls which will not be processed in order to get an
575  // accurate count of Decl's.
577  for (Decl *SubDecl : Enum->decls()) {
578  if (isWhitelistedDecl(SubDecl, Enum)) {
579  assert(isa<EnumConstantDecl>(SubDecl) && "Unexpected Decl");
580  Decls.push_back(SubDecl);
581  }
582  }
583 
584  ID.AddInteger(Decls.size());
585  for (auto SubDecl : Decls) {
586  AddSubDecl(SubDecl);
587  }
588 
589 }
590 
591 void ODRHash::AddDecl(const Decl *D) {
592  assert(D && "Expecting non-null pointer.");
593  D = D->getCanonicalDecl();
594 
595  if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
596  AddDeclarationName(ND->getDeclName());
597  return;
598  }
599 
600  ID.AddInteger(D->getKind());
601  // TODO: Handle non-NamedDecl here.
602 }
603 
604 namespace {
605 // Process a Type pointer. Add* methods call back into ODRHash while Visit*
606 // methods process the relevant parts of the Type.
607 class ODRTypeVisitor : public TypeVisitor<ODRTypeVisitor> {
608  typedef TypeVisitor<ODRTypeVisitor> Inherited;
609  llvm::FoldingSetNodeID &ID;
610  ODRHash &Hash;
611 
612 public:
613  ODRTypeVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
614  : ID(ID), Hash(Hash) {}
615 
616  void AddStmt(Stmt *S) {
617  Hash.AddBoolean(S);
618  if (S) {
619  Hash.AddStmt(S);
620  }
621  }
622 
623  void AddDecl(Decl *D) {
624  Hash.AddBoolean(D);
625  if (D) {
626  Hash.AddDecl(D);
627  }
628  }
629 
630  void AddQualType(QualType T) {
631  Hash.AddQualType(T);
632  }
633 
634  void AddType(const Type *T) {
635  Hash.AddBoolean(T);
636  if (T) {
637  Hash.AddType(T);
638  }
639  }
640 
642  Hash.AddBoolean(NNS);
643  if (NNS) {
644  Hash.AddNestedNameSpecifier(NNS);
645  }
646  }
647 
648  void AddIdentifierInfo(const IdentifierInfo *II) {
649  Hash.AddBoolean(II);
650  if (II) {
651  Hash.AddIdentifierInfo(II);
652  }
653  }
654 
655  void VisitQualifiers(Qualifiers Quals) {
656  ID.AddInteger(Quals.getAsOpaqueValue());
657  }
658 
659  void Visit(const Type *T) {
660  ID.AddInteger(T->getTypeClass());
661  Inherited::Visit(T);
662  }
663 
664  void VisitType(const Type *T) {}
665 
666  void VisitAdjustedType(const AdjustedType *T) {
669  VisitType(T);
670  }
671 
672  void VisitDecayedType(const DecayedType *T) {
675  VisitAdjustedType(T);
676  }
677 
678  void VisitArrayType(const ArrayType *T) {
680  ID.AddInteger(T->getSizeModifier());
681  VisitQualifiers(T->getIndexTypeQualifiers());
682  VisitType(T);
683  }
684  void VisitConstantArrayType(const ConstantArrayType *T) {
685  T->getSize().Profile(ID);
686  VisitArrayType(T);
687  }
688 
689  void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
690  AddStmt(T->getSizeExpr());
691  VisitArrayType(T);
692  }
693 
694  void VisitIncompleteArrayType(const IncompleteArrayType *T) {
695  VisitArrayType(T);
696  }
697 
698  void VisitVariableArrayType(const VariableArrayType *T) {
699  AddStmt(T->getSizeExpr());
700  VisitArrayType(T);
701  }
702 
703  void VisitBuiltinType(const BuiltinType *T) {
704  ID.AddInteger(T->getKind());
705  VisitType(T);
706  }
707 
708  void VisitFunctionType(const FunctionType *T) {
710  T->getExtInfo().Profile(ID);
711  Hash.AddBoolean(T->isConst());
712  Hash.AddBoolean(T->isVolatile());
713  Hash.AddBoolean(T->isRestrict());
714  VisitType(T);
715  }
716 
717  void VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
718  VisitFunctionType(T);
719  }
720 
721  void VisitFunctionProtoType(const FunctionProtoType *T) {
722  ID.AddInteger(T->getNumParams());
723  for (auto ParamType : T->getParamTypes())
724  AddQualType(ParamType);
725 
726  VisitFunctionType(T);
727  }
728 
729  void VisitPointerType(const PointerType *T) {
731  VisitType(T);
732  }
733 
734  void VisitReferenceType(const ReferenceType *T) {
736  VisitType(T);
737  }
738 
739  void VisitLValueReferenceType(const LValueReferenceType *T) {
740  VisitReferenceType(T);
741  }
742 
743  void VisitRValueReferenceType(const RValueReferenceType *T) {
744  VisitReferenceType(T);
745  }
746 
747  void VisitTypedefType(const TypedefType *T) {
748  AddDecl(T->getDecl());
749  QualType UnderlyingType = T->getDecl()->getUnderlyingType();
750  VisitQualifiers(UnderlyingType.getQualifiers());
751  while (true) {
752  if (const TypedefType *Underlying =
753  dyn_cast<TypedefType>(UnderlyingType.getTypePtr())) {
754  UnderlyingType = Underlying->getDecl()->getUnderlyingType();
755  continue;
756  }
757  if (const ElaboratedType *Underlying =
758  dyn_cast<ElaboratedType>(UnderlyingType.getTypePtr())) {
759  UnderlyingType = Underlying->getNamedType();
760  continue;
761  }
762 
763  break;
764  }
765  AddType(UnderlyingType.getTypePtr());
766  VisitType(T);
767  }
768 
769  void VisitTagType(const TagType *T) {
770  AddDecl(T->getDecl());
771  VisitType(T);
772  }
773 
774  void VisitRecordType(const RecordType *T) { VisitTagType(T); }
775  void VisitEnumType(const EnumType *T) { VisitTagType(T); }
776 
777  void VisitTypeWithKeyword(const TypeWithKeyword *T) {
778  ID.AddInteger(T->getKeyword());
779  VisitType(T);
780  };
781 
782  void VisitDependentNameType(const DependentNameType *T) {
785  VisitTypeWithKeyword(T);
786  }
787 
788  void VisitDependentTemplateSpecializationType(
792  ID.AddInteger(T->getNumArgs());
793  for (const auto &TA : T->template_arguments()) {
794  Hash.AddTemplateArgument(TA);
795  }
796  VisitTypeWithKeyword(T);
797  }
798 
799  void VisitElaboratedType(const ElaboratedType *T) {
802  VisitTypeWithKeyword(T);
803  }
804 
805  void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
806  ID.AddInteger(T->getNumArgs());
807  for (const auto &TA : T->template_arguments()) {
808  Hash.AddTemplateArgument(TA);
809  }
810  Hash.AddTemplateName(T->getTemplateName());
811  VisitType(T);
812  }
813 
814  void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
815  ID.AddInteger(T->getDepth());
816  ID.AddInteger(T->getIndex());
817  Hash.AddBoolean(T->isParameterPack());
818  AddDecl(T->getDecl());
819  }
820 };
821 } // namespace
822 
823 void ODRHash::AddType(const Type *T) {
824  assert(T && "Expecting non-null pointer.");
825  ODRTypeVisitor(ID, *this).Visit(T);
826 }
827 
829  AddBoolean(T.isNull());
830  if (T.isNull())
831  return;
832  SplitQualType split = T.split();
833  ID.AddInteger(split.Quals.getAsOpaqueValue());
834  AddType(split.Ty);
835 }
836 
838  Bools.push_back(Value);
839 }
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Definition: Type.h:4945
const Type * Ty
The locally-unqualified type.
Definition: Type.h:596
Represents a function declaration or definition.
Definition: Decl.h:1716
Smart pointer class that efficiently represents Objective-C method names.
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2393
QualType getPointeeType() const
Definition: Type.h:2406
A (possibly-)qualified type.
Definition: Type.h:655
base_class_range bases()
Definition: DeclCXX.h:825
void AddBoolean(bool value)
Definition: ODRHash.cpp:837
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:819
QualType getDecayedType() const
Definition: Type.h:2485
This file contains the declaration of the ODRHash class, which calculates a hash based on AST nodes...
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:3345
Stmt - This represents one statement.
Definition: Stmt.h:66
Expr * getBitWidth() const
Definition: Decl.h:2623
void AddQualType(QualType T)
Definition: ODRHash.cpp:828
Kind getKind() const
Definition: Type.h:2274
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3211
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:2741
Represents the declaration of a typedef-name via the &#39;typedef&#39; type specifier.
Definition: Decl.h:2974
Microsoft&#39;s &#39;__super&#39; specifier, stored as a CXXRecordDecl* of the class it appeared in...
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:5020
The template argument is an expression, and we&#39;ve not resolved it to one of the other forms yet...
Definition: TemplateBase.h:87
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:5039
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
TagDecl * getDecl() const
Definition: Type.cpp:3148
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:126
Selector getObjCSelector() const
getObjCSelector - Get the Objective-C selector stored in this declaration name.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
The base class of the type hierarchy.
Definition: Type.h:1428
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2668
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:64
A container of type source information.
Definition: Decl.h:86
bool isEmpty() const
Evaluates true when this declaration name is empty.
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:4383
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:206
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:2036
size_t param_size() const
Definition: Decl.h:2247
QualType getElementType() const
Definition: Type.h:2703
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
An identifier, stored as an IdentifierInfo*.
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
Definition: DeclFriend.h:54
Represents a variable declaration or definition.
Definition: Decl.h:814
Declaration of a redeclarable template.
Definition: DeclTemplate.h:737
QualType getReturnType() const
Definition: Decl.h:2271
unsigned getNumParams() const
Definition: Type.h:3668
QualType getCXXNameType() const
getCXXNameType - If this name is one of the C++ names (of a constructor, destructor, or conversion function), return the type associated with that name.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:57
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:1588
A namespace, stored as a NamespaceDecl*.
bool isConst() const
Definition: Type.h:3377
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
void AddTemplateArgument(TemplateArgument TA)
Definition: ODRHash.cpp:140
bool hasDefinition() const
Definition: DeclCXX.h:778
Represents a parameter to a function.
Definition: Decl.h:1535
The collection of all-type qualifiers we support.
Definition: Type.h:154
void clear()
Definition: ODRHash.cpp:181
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:297
QualType getOriginalType() const
Definition: Type.h:2457
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists...
Definition: Decl.h:3458
One of these records is kept for each identifier that is lexed.
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:124
StringLiteral * getMessage()
Definition: DeclCXX.h:3780
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:330
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:3675
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:72
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
Represents a member of a struct/union/class.
Definition: Decl.h:2534
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:4724
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
An operation on a type.
Definition: TypeVisitor.h:65
NamedDecl * getFriendDecl() const
If this friend declaration doesn&#39;t name a type, return the inner declaration.
Definition: DeclFriend.h:139
void AddTemplateParameterList(const TemplateParameterList *TPL)
Definition: ODRHash.cpp:172
Represents an access specifier followed by colon &#39;:&#39;.
Definition: DeclCXX.h:132
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name...
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2231
bool isUnarySelector() const
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2594
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2612
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
A qualified template name, where the qualification is kept to describe the source code as written...
Definition: TemplateName.h:198
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:2662
void AddDecl(const Decl *D)
Definition: ODRHash.cpp:591
void AddFunctionDecl(const FunctionDecl *Function, bool SkipBody=false)
Definition: ODRHash.cpp:496
#define CHAR_BIT
Definition: limits.h:79
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Definition: DeclTemplate.h:879
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1383
#define remainder(__x, __y)
Definition: tgmath.h:1106
QualType getPointeeType() const
Definition: Type.h:6614
Expr * getSizeExpr() const
Definition: Type.h:2847
const Expr * getInitExpr() const
Definition: Decl.h:2760
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
Expr * getSizeExpr() const
Definition: Type.h:2904
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2548
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:877
void AddTemplateName(TemplateName Name)
Definition: ODRHash.cpp:122
Represents a K&R-style &#39;int foo()&#39; function, which has no information available about its arguments...
Definition: Type.h:3397
NodeId Parent
Definition: ASTDiff.cpp:192
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:2994
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3432
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:202
OverloadedOperatorKind getCXXOverloadedOperator() const
getCXXOverloadedOperator - If this name is the name of an overloadable operator in C++ (e...
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:264
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:2882
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:432
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
Definition: DeclBase.h:1359
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2305
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:5111
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:637
bool isDefaulted() const
Whether this function is defaulted per C++0x.
Definition: Decl.h:2060
unsigned getAsOpaqueValue() const
Definition: Type.h:267
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3498
Declaration of a template type parameter.
unsigned getIndex() const
Definition: Type.h:4380
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:68
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
Definition: Decl.h:2019
void AddDeclarationName(DeclarationName Name)
Definition: ODRHash.cpp:35
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:554
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition: Decl.cpp:3405
bool isFileContext() const
Definition: DeclBase.h:1409
DeclContext * getDeclContext()
Definition: DeclBase.h:428
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:5046
void ProcessODRHash(llvm::FoldingSetNodeID &ID, ODRHash &Hash) const
Calculate a unique representation for a statement that is stable across compiler invocations.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2301
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
Definition: TemplateName.h:178
A namespace alias, stored as a NamespaceAliasDecl*.
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn&#39;t a simple identifier.
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:594
Qualifiers Quals
The local qualifiers.
Definition: Type.h:599
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1343
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition: Type.h:4894
ArraySizeModifier getSizeModifier() const
Definition: Type.h:2705
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2576
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
unsigned getNumArgs() const
The result type of a method or function.
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:720
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:5897
A template template parameter pack that has been substituted for a template template argument pack...
Definition: TemplateName.h:211
Decl::Kind getDeclKind() const
Definition: DeclBase.h:1336
IdentifierInfo * getCXXLiteralIdentifier() const
getCXXLiteralIdentifier - If this name is the name of a literal operator, retrieve the identifier ass...
Kind
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:4906
IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isParameterPack() const
Returns whether this is a parameter pack.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
QualType getAdjustedType() const
Definition: Type.h:2458
QualType getReturnType() const
Definition: Type.h:3365
bool isPure() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2041
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:4161
void AddType(const Type *T)
Definition: ODRHash.cpp:823
void AddIdentifierInfo(const IdentifierInfo *II)
Definition: ODRHash.cpp:30
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
Definition: Decl.h:2676
bool isRestrict() const
Definition: Type.h:3379
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2045
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
bool isParameterPack() const
Definition: Type.h:4381
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:360
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3493
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:4975
unsigned getODRHash()
Returns ODRHash of the function.
Definition: Decl.cpp:3671
Qualifiers getIndexTypeQualifiers() const
Definition: Type.h:2709
TypeClass getTypeClass() const
Definition: Type.h:1691
void AddNestedNameSpecifier(const NestedNameSpecifier *NNS)
Definition: ODRHash.cpp:93
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:5115
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted per C++0x.
Definition: Decl.h:2065
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3754
void AddSubDecl(const Decl *D)
Definition: ODRHash.cpp:443
void AddEnumDecl(const EnumDecl *Enum)
Definition: ODRHash.cpp:563
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2478
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:354
StringRef getName() const
Return the actual identifier string.
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2872
Represents a template argument.
Definition: TemplateBase.h:51
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons...
Definition: Type.h:2441
Dataflow Directional Tag Classes.
ExtInfo getExtInfo() const
Definition: Type.h:3376
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:499
bool isLateTemplateParsed() const
Whether this templated function will be late parsed.
Definition: Decl.h:2045
NestedNameSpecifier * getQualifier() const
Definition: Type.h:5102
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1264
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:80
QualType getUnderlyingType() const
Definition: Decl.h:2927
AccessSpecifier getAccess() const
Definition: DeclBase.h:463
const Expr * getInit() const
Definition: Decl.h:1219
void AddCXXRecordDecl(const CXXRecordDecl *Record)
Definition: ODRHash.cpp:449
DeclarationName - The name of a declaration.
Kind getKind() const
Definition: DeclBase.h:422
bool isKeywordSelector() const
Represents an enum.
Definition: Decl.h:3313
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
A type that was preceded by the &#39;template&#39; keyword, stored as a Type*.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4135
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:4732
const llvm::APInt & getSize() const
Definition: Type.h:2746
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
Definition: Decl.h:1059
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2529
bool isVolatile() const
Definition: Type.h:3378
unsigned CalculateHash()
Definition: ODRHash.cpp:187
The template argument is a type.
Definition: TemplateBase.h:60
The template argument is actually a parameter pack.
Definition: TemplateBase.h:91
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
Definition: DeclCXX.cpp:1585
TypedefNameDecl * getDecl() const
Definition: Type.h:3932
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:235
unsigned getDepth() const
Definition: Type.h:4379
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:2609
Represents a C++ struct/union/class.
Definition: DeclCXX.h:302
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:5072
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:4738
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:76
Represents a C array with an unspecified size.
Definition: Type.h:2782
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:4978
bool isNull() const
Determine whether this is the empty selector.
Declaration of a class template.
This class is used for builtin types like &#39;int&#39;.
Definition: Type.h:2250
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:3442
void AddStmt(const Stmt *S)
Definition: ODRHash.cpp:25
NameKind getKind() const
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:257
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4654
bool isDeleted() const
Whether this function has been deleted.
Definition: Decl.h:2125
static bool isWhitelistedDecl(const Decl *D, const DeclContext *Parent)
Definition: ODRHash.cpp:420
QualType getDefaultArgument() const
Retrieve the default argument, if any.
QualType getType() const
Definition: Decl.h:648
A set of overloaded template declarations.
Definition: TemplateName.h:194
This represents a decl that may have a name.
Definition: Decl.h:248
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2827
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:77
The global specifier &#39;::&#39;. There is no stored value.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
Definition: TemplateBase.h:288
bool hasInit() const
Definition: Decl.cpp:2144
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:2728
Declaration of a template function.
Definition: DeclTemplate.h:968
bool isDeletedAsWritten() const
Definition: Decl.h:2126
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:97
A single template declaration.
Definition: TemplateName.h:191
const IdentifierInfo * getIdentifier() const
Definition: Type.h:5103