1 //===-- ODRHash.cpp - Hashing to diagnose ODR failures ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This file implements the ODRHash class, which calculates a hash based
12 /// on AST nodes, which is stable across different runs.
14 //===----------------------------------------------------------------------===//
16 #include "clang/AST/ODRHash.h"
18 #include "clang/AST/DeclVisitor.h"
19 #include "clang/AST/NestedNameSpecifier.h"
20 #include "clang/AST/StmtVisitor.h"
21 #include "clang/AST/TypeVisitor.h"
23 using namespace clang;
25 void ODRHash::AddStmt(const Stmt *S) {
26 assert(S && "Expecting non-null pointer.");
27 S->ProcessODRHash(ID, *this);
30 void ODRHash::AddIdentifierInfo(const IdentifierInfo *II) {
31 assert(II && "Expecting non-null pointer.");
32 ID.AddString(II->getName());
35 void ODRHash::AddDeclarationName(DeclarationName Name, bool TreatAsDecl) {
37 // Matches the NamedDecl check in AddDecl
40 AddDeclarationNameImpl(Name);
43 // Matches the ClassTemplateSpecializationDecl check in AddDecl
47 void ODRHash::AddDeclarationNameImpl(DeclarationName Name) {
48 // Index all DeclarationName and use index numbers to refer to them.
49 auto Result = DeclNameMap.insert(std::make_pair(Name, DeclNameMap.size()));
50 ID.AddInteger(Result.first->second);
52 // If found in map, the DeclarationName has previously been processed.
56 // First time processing each DeclarationName, also process its details.
57 AddBoolean(Name.isEmpty());
61 auto Kind = Name.getNameKind();
64 case DeclarationName::Identifier:
65 AddIdentifierInfo(Name.getAsIdentifierInfo());
67 case DeclarationName::ObjCZeroArgSelector:
68 case DeclarationName::ObjCOneArgSelector:
69 case DeclarationName::ObjCMultiArgSelector: {
70 Selector S = Name.getObjCSelector();
71 AddBoolean(S.isNull());
72 AddBoolean(S.isKeywordSelector());
73 AddBoolean(S.isUnarySelector());
74 unsigned NumArgs = S.getNumArgs();
75 for (unsigned i = 0; i < NumArgs; ++i) {
76 AddIdentifierInfo(S.getIdentifierInfoForSlot(i));
80 case DeclarationName::CXXConstructorName:
81 case DeclarationName::CXXDestructorName:
82 AddQualType(Name.getCXXNameType());
84 case DeclarationName::CXXOperatorName:
85 ID.AddInteger(Name.getCXXOverloadedOperator());
87 case DeclarationName::CXXLiteralOperatorName:
88 AddIdentifierInfo(Name.getCXXLiteralIdentifier());
90 case DeclarationName::CXXConversionFunctionName:
91 AddQualType(Name.getCXXNameType());
93 case DeclarationName::CXXUsingDirective:
95 case DeclarationName::CXXDeductionGuideName: {
96 auto *Template = Name.getCXXDeductionGuideTemplate();
105 void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
106 assert(NNS && "Expecting non-null pointer.");
107 const auto *Prefix = NNS->getPrefix();
110 AddNestedNameSpecifier(Prefix);
112 auto Kind = NNS->getKind();
115 case NestedNameSpecifier::Identifier:
116 AddIdentifierInfo(NNS->getAsIdentifier());
118 case NestedNameSpecifier::Namespace:
119 AddDecl(NNS->getAsNamespace());
121 case NestedNameSpecifier::NamespaceAlias:
122 AddDecl(NNS->getAsNamespaceAlias());
124 case NestedNameSpecifier::TypeSpec:
125 case NestedNameSpecifier::TypeSpecWithTemplate:
126 AddType(NNS->getAsType());
128 case NestedNameSpecifier::Global:
129 case NestedNameSpecifier::Super:
134 void ODRHash::AddTemplateName(TemplateName Name) {
135 auto Kind = Name.getKind();
139 case TemplateName::Template:
140 AddDecl(Name.getAsTemplateDecl());
142 // TODO: Support these cases.
143 case TemplateName::OverloadedTemplate:
144 case TemplateName::QualifiedTemplate:
145 case TemplateName::DependentTemplate:
146 case TemplateName::SubstTemplateTemplateParm:
147 case TemplateName::SubstTemplateTemplateParmPack:
152 void ODRHash::AddTemplateArgument(TemplateArgument TA) {
153 const auto Kind = TA.getKind();
157 case TemplateArgument::Null:
158 llvm_unreachable("Expected valid TemplateArgument");
159 case TemplateArgument::Type:
160 AddQualType(TA.getAsType());
162 case TemplateArgument::Declaration:
163 AddDecl(TA.getAsDecl());
165 case TemplateArgument::NullPtr:
166 case TemplateArgument::Integral:
168 case TemplateArgument::Template:
169 case TemplateArgument::TemplateExpansion:
170 AddTemplateName(TA.getAsTemplateOrTemplatePattern());
172 case TemplateArgument::Expression:
173 AddStmt(TA.getAsExpr());
175 case TemplateArgument::Pack:
176 ID.AddInteger(TA.pack_size());
177 for (auto SubTA : TA.pack_elements()) {
178 AddTemplateArgument(SubTA);
184 void ODRHash::AddTemplateParameterList(const TemplateParameterList *TPL) {
185 assert(TPL && "Expecting non-null pointer.");
187 ID.AddInteger(TPL->size());
188 for (auto *ND : TPL->asArray()) {
193 void ODRHash::clear() {
199 unsigned ODRHash::CalculateHash() {
200 // Append the bools to the end of the data segment backwards. This allows
201 // for the bools data to be compressed 32 times smaller compared to using
203 const unsigned unsigned_bits = sizeof(unsigned) * CHAR_BIT;
204 const unsigned size = Bools.size();
205 const unsigned remainder = size % unsigned_bits;
206 const unsigned loops = size / unsigned_bits;
207 auto I = Bools.rbegin();
209 for (unsigned i = 0; i < remainder; ++i) {
214 ID.AddInteger(value);
216 for (unsigned i = 0; i < loops; ++i) {
218 for (unsigned j = 0; j < unsigned_bits; ++j) {
223 ID.AddInteger(value);
226 assert(I == Bools.rend());
228 return ID.ComputeHash();
232 // Process a Decl pointer. Add* methods call back into ODRHash while Visit*
233 // methods process the relevant parts of the Decl.
234 class ODRDeclVisitor : public ConstDeclVisitor<ODRDeclVisitor> {
235 typedef ConstDeclVisitor<ODRDeclVisitor> Inherited;
236 llvm::FoldingSetNodeID &ID;
240 ODRDeclVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
241 : ID(ID), Hash(Hash) {}
243 void AddStmt(const Stmt *S) {
250 void AddIdentifierInfo(const IdentifierInfo *II) {
253 Hash.AddIdentifierInfo(II);
257 void AddQualType(QualType T) {
261 void AddDecl(const Decl *D) {
268 void AddTemplateArgument(TemplateArgument TA) {
269 Hash.AddTemplateArgument(TA);
272 void Visit(const Decl *D) {
273 ID.AddInteger(D->getKind());
277 void VisitNamedDecl(const NamedDecl *D) {
278 Hash.AddDeclarationName(D->getDeclName());
279 Inherited::VisitNamedDecl(D);
282 void VisitValueDecl(const ValueDecl *D) {
283 if (!isa<FunctionDecl>(D)) {
284 AddQualType(D->getType());
286 Inherited::VisitValueDecl(D);
289 void VisitVarDecl(const VarDecl *D) {
290 Hash.AddBoolean(D->isStaticLocal());
291 Hash.AddBoolean(D->isConstexpr());
292 const bool HasInit = D->hasInit();
293 Hash.AddBoolean(HasInit);
295 AddStmt(D->getInit());
297 Inherited::VisitVarDecl(D);
300 void VisitParmVarDecl(const ParmVarDecl *D) {
301 // TODO: Handle default arguments.
302 Inherited::VisitParmVarDecl(D);
305 void VisitAccessSpecDecl(const AccessSpecDecl *D) {
306 ID.AddInteger(D->getAccess());
307 Inherited::VisitAccessSpecDecl(D);
310 void VisitStaticAssertDecl(const StaticAssertDecl *D) {
311 AddStmt(D->getAssertExpr());
312 AddStmt(D->getMessage());
314 Inherited::VisitStaticAssertDecl(D);
317 void VisitFieldDecl(const FieldDecl *D) {
318 const bool IsBitfield = D->isBitField();
319 Hash.AddBoolean(IsBitfield);
322 AddStmt(D->getBitWidth());
325 Hash.AddBoolean(D->isMutable());
326 AddStmt(D->getInClassInitializer());
328 Inherited::VisitFieldDecl(D);
331 void VisitFunctionDecl(const FunctionDecl *D) {
332 // Handled by the ODRHash for FunctionDecl
333 ID.AddInteger(D->getODRHash());
335 Inherited::VisitFunctionDecl(D);
338 void VisitCXXMethodDecl(const CXXMethodDecl *D) {
339 // Handled by the ODRHash for FunctionDecl
341 Inherited::VisitCXXMethodDecl(D);
344 void VisitTypedefNameDecl(const TypedefNameDecl *D) {
345 AddQualType(D->getUnderlyingType());
347 Inherited::VisitTypedefNameDecl(D);
350 void VisitTypedefDecl(const TypedefDecl *D) {
351 Inherited::VisitTypedefDecl(D);
354 void VisitTypeAliasDecl(const TypeAliasDecl *D) {
355 Inherited::VisitTypeAliasDecl(D);
358 void VisitFriendDecl(const FriendDecl *D) {
359 TypeSourceInfo *TSI = D->getFriendType();
360 Hash.AddBoolean(TSI);
362 AddQualType(TSI->getType());
364 AddDecl(D->getFriendDecl());
368 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
369 // Only care about default arguments as part of the definition.
370 const bool hasDefaultArgument =
371 D->hasDefaultArgument() && !D->defaultArgumentWasInherited();
372 Hash.AddBoolean(hasDefaultArgument);
373 if (hasDefaultArgument) {
374 AddTemplateArgument(D->getDefaultArgument());
376 Hash.AddBoolean(D->isParameterPack());
378 Inherited::VisitTemplateTypeParmDecl(D);
381 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
382 // Only care about default arguments as part of the definition.
383 const bool hasDefaultArgument =
384 D->hasDefaultArgument() && !D->defaultArgumentWasInherited();
385 Hash.AddBoolean(hasDefaultArgument);
386 if (hasDefaultArgument) {
387 AddStmt(D->getDefaultArgument());
389 Hash.AddBoolean(D->isParameterPack());
391 Inherited::VisitNonTypeTemplateParmDecl(D);
394 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) {
395 // Only care about default arguments as part of the definition.
396 const bool hasDefaultArgument =
397 D->hasDefaultArgument() && !D->defaultArgumentWasInherited();
398 Hash.AddBoolean(hasDefaultArgument);
399 if (hasDefaultArgument) {
400 AddTemplateArgument(D->getDefaultArgument().getArgument());
402 Hash.AddBoolean(D->isParameterPack());
404 Inherited::VisitTemplateTemplateParmDecl(D);
407 void VisitTemplateDecl(const TemplateDecl *D) {
408 Hash.AddTemplateParameterList(D->getTemplateParameters());
410 Inherited::VisitTemplateDecl(D);
413 void VisitRedeclarableTemplateDecl(const RedeclarableTemplateDecl *D) {
414 Hash.AddBoolean(D->isMemberSpecialization());
415 Inherited::VisitRedeclarableTemplateDecl(D);
418 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
419 AddDecl(D->getTemplatedDecl());
420 ID.AddInteger(D->getTemplatedDecl()->getODRHash());
421 Inherited::VisitFunctionTemplateDecl(D);
424 void VisitEnumConstantDecl(const EnumConstantDecl *D) {
425 AddStmt(D->getInitExpr());
426 Inherited::VisitEnumConstantDecl(D);
431 // Only allow a small portion of Decl's to be processed. Remove this once
432 // all Decl's can be handled.
433 bool ODRHash::isWhitelistedDecl(const Decl *D, const DeclContext *Parent) {
434 if (D->isImplicit()) return false;
435 if (D->getDeclContext() != Parent) return false;
437 switch (D->getKind()) {
440 case Decl::AccessSpec:
441 case Decl::CXXConstructor:
442 case Decl::CXXDestructor:
443 case Decl::CXXMethod:
444 case Decl::EnumConstant: // Only found in EnumDecl's.
447 case Decl::FunctionTemplate:
448 case Decl::StaticAssert:
449 case Decl::TypeAlias:
456 void ODRHash::AddSubDecl(const Decl *D) {
457 assert(D && "Expecting non-null pointer.");
459 ODRDeclVisitor(ID, *this).Visit(D);
462 void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) {
463 assert(Record && Record->hasDefinition() &&
464 "Expected non-null record to be a definition.");
466 const DeclContext *DC = Record;
468 if (isa<ClassTemplateSpecializationDecl>(DC)) {
471 DC = DC->getParent();
476 // Filter out sub-Decls which will not be processed in order to get an
477 // accurate count of Decl's.
478 llvm::SmallVector<const Decl *, 16> Decls;
479 for (Decl *SubDecl : Record->decls()) {
480 if (isWhitelistedDecl(SubDecl, Record)) {
481 Decls.push_back(SubDecl);
482 if (auto *Function = dyn_cast<FunctionDecl>(SubDecl)) {
483 // Compute/Preload ODRHash into FunctionDecl.
484 Function->getODRHash();
489 ID.AddInteger(Decls.size());
490 for (auto SubDecl : Decls) {
494 const ClassTemplateDecl *TD = Record->getDescribedClassTemplate();
497 AddTemplateParameterList(TD->getTemplateParameters());
500 ID.AddInteger(Record->getNumBases());
501 auto Bases = Record->bases();
502 for (auto Base : Bases) {
503 AddQualType(Base.getType());
504 ID.AddInteger(Base.isVirtual());
505 ID.AddInteger(Base.getAccessSpecifierAsWritten());
509 void ODRHash::AddFunctionDecl(const FunctionDecl *Function,
511 assert(Function && "Expecting non-null pointer.");
513 // Skip functions that are specializations or in specialization context.
514 const DeclContext *DC = Function;
516 if (isa<ClassTemplateSpecializationDecl>(DC)) return;
517 if (auto *F = dyn_cast<FunctionDecl>(DC)) {
518 if (F->isFunctionTemplateSpecialization()) {
519 if (!isa<CXXMethodDecl>(DC)) return;
520 if (DC->getLexicalParent()->isFileContext()) return;
521 // Inline method specializations are the only supported
522 // specialization for now.
525 DC = DC->getParent();
528 ID.AddInteger(Function->getDeclKind());
530 const auto *SpecializationArgs = Function->getTemplateSpecializationArgs();
531 AddBoolean(SpecializationArgs);
532 if (SpecializationArgs) {
533 ID.AddInteger(SpecializationArgs->size());
534 for (const TemplateArgument &TA : SpecializationArgs->asArray()) {
535 AddTemplateArgument(TA);
539 if (const auto *Method = dyn_cast<CXXMethodDecl>(Function)) {
540 AddBoolean(Method->isConst());
541 AddBoolean(Method->isVolatile());
544 ID.AddInteger(Function->getStorageClass());
545 AddBoolean(Function->isInlineSpecified());
546 AddBoolean(Function->isVirtualAsWritten());
547 AddBoolean(Function->isPure());
548 AddBoolean(Function->isDeletedAsWritten());
549 AddBoolean(Function->isExplicitlyDefaulted());
553 AddQualType(Function->getReturnType());
555 ID.AddInteger(Function->param_size());
556 for (auto Param : Function->parameters())
564 const bool HasBody = Function->isThisDeclarationADefinition() &&
565 !Function->isDefaulted() && !Function->isDeleted() &&
566 !Function->isLateTemplateParsed();
572 auto *Body = Function->getBody();
577 // Filter out sub-Decls which will not be processed in order to get an
578 // accurate count of Decl's.
579 llvm::SmallVector<const Decl *, 16> Decls;
580 for (Decl *SubDecl : Function->decls()) {
581 if (isWhitelistedDecl(SubDecl, Function)) {
582 Decls.push_back(SubDecl);
586 ID.AddInteger(Decls.size());
587 for (auto SubDecl : Decls) {
592 void ODRHash::AddEnumDecl(const EnumDecl *Enum) {
594 AddDeclarationName(Enum->getDeclName());
596 AddBoolean(Enum->isScoped());
597 if (Enum->isScoped())
598 AddBoolean(Enum->isScopedUsingClassTag());
600 if (Enum->getIntegerTypeSourceInfo())
601 AddQualType(Enum->getIntegerType());
603 // Filter out sub-Decls which will not be processed in order to get an
604 // accurate count of Decl's.
605 llvm::SmallVector<const Decl *, 16> Decls;
606 for (Decl *SubDecl : Enum->decls()) {
607 if (isWhitelistedDecl(SubDecl, Enum)) {
608 assert(isa<EnumConstantDecl>(SubDecl) && "Unexpected Decl");
609 Decls.push_back(SubDecl);
613 ID.AddInteger(Decls.size());
614 for (auto SubDecl : Decls) {
620 void ODRHash::AddDecl(const Decl *D) {
621 assert(D && "Expecting non-null pointer.");
622 D = D->getCanonicalDecl();
624 const NamedDecl *ND = dyn_cast<NamedDecl>(D);
627 ID.AddInteger(D->getKind());
631 AddDeclarationName(ND->getDeclName());
633 const auto *Specialization =
634 dyn_cast<ClassTemplateSpecializationDecl>(D);
635 AddBoolean(Specialization);
636 if (Specialization) {
637 const TemplateArgumentList &List = Specialization->getTemplateArgs();
638 ID.AddInteger(List.size());
639 for (const TemplateArgument &TA : List.asArray())
640 AddTemplateArgument(TA);
645 // Process a Type pointer. Add* methods call back into ODRHash while Visit*
646 // methods process the relevant parts of the Type.
647 class ODRTypeVisitor : public TypeVisitor<ODRTypeVisitor> {
648 typedef TypeVisitor<ODRTypeVisitor> Inherited;
649 llvm::FoldingSetNodeID &ID;
653 ODRTypeVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
654 : ID(ID), Hash(Hash) {}
656 void AddStmt(Stmt *S) {
663 void AddDecl(Decl *D) {
670 void AddQualType(QualType T) {
674 void AddType(const Type *T) {
681 void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
682 Hash.AddBoolean(NNS);
684 Hash.AddNestedNameSpecifier(NNS);
688 void AddIdentifierInfo(const IdentifierInfo *II) {
691 Hash.AddIdentifierInfo(II);
695 void VisitQualifiers(Qualifiers Quals) {
696 ID.AddInteger(Quals.getAsOpaqueValue());
699 void Visit(const Type *T) {
700 ID.AddInteger(T->getTypeClass());
704 void VisitType(const Type *T) {}
706 void VisitAdjustedType(const AdjustedType *T) {
707 AddQualType(T->getOriginalType());
708 AddQualType(T->getAdjustedType());
712 void VisitDecayedType(const DecayedType *T) {
713 AddQualType(T->getDecayedType());
714 AddQualType(T->getPointeeType());
715 VisitAdjustedType(T);
718 void VisitArrayType(const ArrayType *T) {
719 AddQualType(T->getElementType());
720 ID.AddInteger(T->getSizeModifier());
721 VisitQualifiers(T->getIndexTypeQualifiers());
724 void VisitConstantArrayType(const ConstantArrayType *T) {
725 T->getSize().Profile(ID);
729 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
730 AddStmt(T->getSizeExpr());
734 void VisitIncompleteArrayType(const IncompleteArrayType *T) {
738 void VisitVariableArrayType(const VariableArrayType *T) {
739 AddStmt(T->getSizeExpr());
743 void VisitAttributedType(const AttributedType *T) {
744 ID.AddInteger(T->getAttrKind());
745 AddQualType(T->getModifiedType());
746 AddQualType(T->getEquivalentType());
751 void VisitBlockPointerType(const BlockPointerType *T) {
752 AddQualType(T->getPointeeType());
756 void VisitBuiltinType(const BuiltinType *T) {
757 ID.AddInteger(T->getKind());
761 void VisitComplexType(const ComplexType *T) {
762 AddQualType(T->getElementType());
766 void VisitDecltypeType(const DecltypeType *T) {
767 AddStmt(T->getUnderlyingExpr());
768 AddQualType(T->getUnderlyingType());
772 void VisitDependentDecltypeType(const DependentDecltypeType *T) {
773 VisitDecltypeType(T);
776 void VisitDeducedType(const DeducedType *T) {
777 AddQualType(T->getDeducedType());
781 void VisitAutoType(const AutoType *T) {
782 ID.AddInteger((unsigned)T->getKeyword());
786 void VisitDeducedTemplateSpecializationType(
787 const DeducedTemplateSpecializationType *T) {
788 Hash.AddTemplateName(T->getTemplateName());
792 void VisitDependentAddressSpaceType(const DependentAddressSpaceType *T) {
793 AddQualType(T->getPointeeType());
794 AddStmt(T->getAddrSpaceExpr());
798 void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T) {
799 AddQualType(T->getElementType());
800 AddStmt(T->getSizeExpr());
804 void VisitFunctionType(const FunctionType *T) {
805 AddQualType(T->getReturnType());
806 T->getExtInfo().Profile(ID);
807 Hash.AddBoolean(T->isConst());
808 Hash.AddBoolean(T->isVolatile());
809 Hash.AddBoolean(T->isRestrict());
813 void VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
814 VisitFunctionType(T);
817 void VisitFunctionProtoType(const FunctionProtoType *T) {
818 ID.AddInteger(T->getNumParams());
819 for (auto ParamType : T->getParamTypes())
820 AddQualType(ParamType);
822 VisitFunctionType(T);
825 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
826 AddDecl(T->getDecl());
830 void VisitMemberPointerType(const MemberPointerType *T) {
831 AddQualType(T->getPointeeType());
832 AddType(T->getClass());
836 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
837 AddQualType(T->getPointeeType());
841 void VisitObjCObjectType(const ObjCObjectType *T) {
842 AddDecl(T->getInterface());
844 auto TypeArgs = T->getTypeArgsAsWritten();
845 ID.AddInteger(TypeArgs.size());
846 for (auto Arg : TypeArgs) {
850 auto Protocols = T->getProtocols();
851 ID.AddInteger(Protocols.size());
852 for (auto Protocol : Protocols) {
856 Hash.AddBoolean(T->isKindOfType());
861 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
862 // This type is handled by the parent type ObjCObjectType.
863 VisitObjCObjectType(T);
866 void VisitObjCTypeParamType(const ObjCTypeParamType *T) {
867 AddDecl(T->getDecl());
868 auto Protocols = T->getProtocols();
869 ID.AddInteger(Protocols.size());
870 for (auto Protocol : Protocols) {
877 void VisitPackExpansionType(const PackExpansionType *T) {
878 AddQualType(T->getPattern());
882 void VisitParenType(const ParenType *T) {
883 AddQualType(T->getInnerType());
887 void VisitPipeType(const PipeType *T) {
888 AddQualType(T->getElementType());
889 Hash.AddBoolean(T->isReadOnly());
893 void VisitPointerType(const PointerType *T) {
894 AddQualType(T->getPointeeType());
898 void VisitReferenceType(const ReferenceType *T) {
899 AddQualType(T->getPointeeTypeAsWritten());
903 void VisitLValueReferenceType(const LValueReferenceType *T) {
904 VisitReferenceType(T);
907 void VisitRValueReferenceType(const RValueReferenceType *T) {
908 VisitReferenceType(T);
912 VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T) {
913 AddType(T->getReplacedParameter());
914 Hash.AddTemplateArgument(T->getArgumentPack());
918 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
919 AddType(T->getReplacedParameter());
920 AddQualType(T->getReplacementType());
924 void VisitTagType(const TagType *T) {
925 AddDecl(T->getDecl());
929 void VisitRecordType(const RecordType *T) { VisitTagType(T); }
930 void VisitEnumType(const EnumType *T) { VisitTagType(T); }
932 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
933 ID.AddInteger(T->getNumArgs());
934 for (const auto &TA : T->template_arguments()) {
935 Hash.AddTemplateArgument(TA);
937 Hash.AddTemplateName(T->getTemplateName());
941 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
942 ID.AddInteger(T->getDepth());
943 ID.AddInteger(T->getIndex());
944 Hash.AddBoolean(T->isParameterPack());
945 AddDecl(T->getDecl());
948 void VisitTypedefType(const TypedefType *T) {
949 AddDecl(T->getDecl());
950 QualType UnderlyingType = T->getDecl()->getUnderlyingType();
951 VisitQualifiers(UnderlyingType.getQualifiers());
953 if (const TypedefType *Underlying =
954 dyn_cast<TypedefType>(UnderlyingType.getTypePtr())) {
955 UnderlyingType = Underlying->getDecl()->getUnderlyingType();
958 if (const ElaboratedType *Underlying =
959 dyn_cast<ElaboratedType>(UnderlyingType.getTypePtr())) {
960 UnderlyingType = Underlying->getNamedType();
966 AddType(UnderlyingType.getTypePtr());
970 void VisitTypeOfExprType(const TypeOfExprType *T) {
971 AddStmt(T->getUnderlyingExpr());
972 Hash.AddBoolean(T->isSugared());
974 AddQualType(T->desugar());
978 void VisitTypeOfType(const TypeOfType *T) {
979 AddQualType(T->getUnderlyingType());
983 void VisitTypeWithKeyword(const TypeWithKeyword *T) {
984 ID.AddInteger(T->getKeyword());
988 void VisitDependentNameType(const DependentNameType *T) {
989 AddNestedNameSpecifier(T->getQualifier());
990 AddIdentifierInfo(T->getIdentifier());
991 VisitTypeWithKeyword(T);
994 void VisitDependentTemplateSpecializationType(
995 const DependentTemplateSpecializationType *T) {
996 AddIdentifierInfo(T->getIdentifier());
997 AddNestedNameSpecifier(T->getQualifier());
998 ID.AddInteger(T->getNumArgs());
999 for (const auto &TA : T->template_arguments()) {
1000 Hash.AddTemplateArgument(TA);
1002 VisitTypeWithKeyword(T);
1005 void VisitElaboratedType(const ElaboratedType *T) {
1006 AddNestedNameSpecifier(T->getQualifier());
1007 AddQualType(T->getNamedType());
1008 VisitTypeWithKeyword(T);
1011 void VisitUnaryTransformType(const UnaryTransformType *T) {
1012 AddQualType(T->getUnderlyingType());
1013 AddQualType(T->getBaseType());
1017 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
1018 AddDecl(T->getDecl());
1022 void VisitVectorType(const VectorType *T) {
1023 AddQualType(T->getElementType());
1024 ID.AddInteger(T->getNumElements());
1025 ID.AddInteger(T->getVectorKind());
1029 void VisitExtVectorType(const ExtVectorType * T) {
1035 void ODRHash::AddType(const Type *T) {
1036 assert(T && "Expecting non-null pointer.");
1037 ODRTypeVisitor(ID, *this).Visit(T);
1040 void ODRHash::AddQualType(QualType T) {
1041 AddBoolean(T.isNull());
1044 SplitQualType split = T.split();
1045 ID.AddInteger(split.Quals.getAsOpaqueValue());
1049 void ODRHash::AddBoolean(bool Value) {
1050 Bools.push_back(Value);