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"
19 #include "clang/AST/NestedNameSpecifier.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 
30 void ODRHash::AddIdentifierInfo(const IdentifierInfo *II) {
31   assert(II && "Expecting non-null pointer.");
32   ID.AddString(II->getName());
33 }
34 
35 void ODRHash::AddDeclarationName(DeclarationName Name) {
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) {
52   case DeclarationName::Identifier:
53     AddIdentifierInfo(Name.getAsIdentifierInfo());
54     break;
55   case DeclarationName::ObjCZeroArgSelector:
56   case DeclarationName::ObjCOneArgSelector:
57   case DeclarationName::ObjCMultiArgSelector: {
58     Selector S = Name.getObjCSelector();
59     AddBoolean(S.isNull());
60     AddBoolean(S.isKeywordSelector());
61     AddBoolean(S.isUnarySelector());
62     unsigned NumArgs = S.getNumArgs();
63     for (unsigned i = 0; i < NumArgs; ++i) {
64       AddIdentifierInfo(S.getIdentifierInfoForSlot(i));
65     }
66     break;
67   }
68   case DeclarationName::CXXConstructorName:
69   case DeclarationName::CXXDestructorName:
70     AddQualType(Name.getCXXNameType());
71     break;
72   case DeclarationName::CXXOperatorName:
73     ID.AddInteger(Name.getCXXOverloadedOperator());
74     break;
75   case DeclarationName::CXXLiteralOperatorName:
76     AddIdentifierInfo(Name.getCXXLiteralIdentifier());
77     break;
78   case DeclarationName::CXXConversionFunctionName:
79     AddQualType(Name.getCXXNameType());
80     break;
81   case DeclarationName::CXXUsingDirective:
82     break;
83   case DeclarationName::CXXDeductionGuideName: {
84     auto *Template = Name.getCXXDeductionGuideTemplate();
85     AddBoolean(Template);
86     if (Template) {
87       AddDecl(Template);
88     }
89   }
90   }
91 }
92 
93 void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
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) {
103   case NestedNameSpecifier::Identifier:
104     AddIdentifierInfo(NNS->getAsIdentifier());
105     break;
106   case NestedNameSpecifier::Namespace:
107     AddDecl(NNS->getAsNamespace());
108     break;
109   case NestedNameSpecifier::NamespaceAlias:
110     AddDecl(NNS->getAsNamespaceAlias());
111     break;
112   case NestedNameSpecifier::TypeSpec:
113   case NestedNameSpecifier::TypeSpecWithTemplate:
114     AddType(NNS->getAsType());
115     break;
116   case NestedNameSpecifier::Global:
117   case NestedNameSpecifier::Super:
118     break;
119   }
120 }
121 
122 void ODRHash::AddTemplateName(TemplateName Name) {
123   auto Kind = Name.getKind();
124   ID.AddInteger(Kind);
125 
126   switch (Kind) {
127   case TemplateName::Template:
128     AddDecl(Name.getAsTemplateDecl());
129     break;
130   // TODO: Support these cases.
131   case TemplateName::OverloadedTemplate:
132   case TemplateName::QualifiedTemplate:
133   case TemplateName::DependentTemplate:
134   case TemplateName::SubstTemplateTemplateParm:
135   case TemplateName::SubstTemplateTemplateParmPack:
136     break;
137   }
138 }
139 
140 void ODRHash::AddTemplateArgument(TemplateArgument TA) {
141   const auto Kind = TA.getKind();
142   ID.AddInteger(Kind);
143 
144   switch (Kind) {
145     case TemplateArgument::Null:
146       llvm_unreachable("Expected valid TemplateArgument");
147     case TemplateArgument::Type:
148       AddQualType(TA.getAsType());
149       break;
150     case TemplateArgument::Declaration:
151     case TemplateArgument::NullPtr:
152     case TemplateArgument::Integral:
153       break;
154     case TemplateArgument::Template:
155     case TemplateArgument::TemplateExpansion:
156       AddTemplateName(TA.getAsTemplateOrTemplatePattern());
157       break;
158     case TemplateArgument::Expression:
159       AddStmt(TA.getAsExpr());
160       break;
161     case TemplateArgument::Pack:
162       ID.AddInteger(TA.pack_size());
163       for (auto SubTA : TA.pack_elements()) {
164         AddTemplateArgument(SubTA);
165       }
166       break;
167   }
168 }
169 
170 void ODRHash::AddTemplateParameterList(const TemplateParameterList *TPL) {
171   assert(TPL && "Expecting non-null pointer.");
172 
173   ID.AddInteger(TPL->size());
174   for (auto *ND : TPL->asArray()) {
175     AddSubDecl(ND);
176   }
177 }
178 
179 void ODRHash::clear() {
180   DeclNameMap.clear();
181   TypeMap.clear();
182   Bools.clear();
183   ID.clear();
184 }
185 
186 unsigned ODRHash::CalculateHash() {
187   // Append the bools to the end of the data segment backwards.  This allows
188   // for the bools data to be compressed 32 times smaller compared to using
189   // ID.AddBoolean
190   const unsigned unsigned_bits = sizeof(unsigned) * CHAR_BIT;
191   const unsigned size = Bools.size();
192   const unsigned remainder = size % unsigned_bits;
193   const unsigned loops = size / unsigned_bits;
194   auto I = Bools.rbegin();
195   unsigned value = 0;
196   for (unsigned i = 0; i < remainder; ++i) {
197     value <<= 1;
198     value |= *I;
199     ++I;
200   }
201   ID.AddInteger(value);
202 
203   for (unsigned i = 0; i < loops; ++i) {
204     value = 0;
205     for (unsigned j = 0; j < unsigned_bits; ++j) {
206       value <<= 1;
207       value |= *I;
208       ++I;
209     }
210     ID.AddInteger(value);
211   }
212 
213   assert(I == Bools.rend());
214   Bools.clear();
215   return ID.ComputeHash();
216 }
217 
218 namespace {
219 // Process a Decl pointer.  Add* methods call back into ODRHash while Visit*
220 // methods process the relevant parts of the Decl.
221 class ODRDeclVisitor : public ConstDeclVisitor<ODRDeclVisitor> {
222   typedef ConstDeclVisitor<ODRDeclVisitor> Inherited;
223   llvm::FoldingSetNodeID &ID;
224   ODRHash &Hash;
225 
226 public:
227   ODRDeclVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
228       : ID(ID), Hash(Hash) {}
229 
230   void AddStmt(const Stmt *S) {
231     Hash.AddBoolean(S);
232     if (S) {
233       Hash.AddStmt(S);
234     }
235   }
236 
237   void AddIdentifierInfo(const IdentifierInfo *II) {
238     Hash.AddBoolean(II);
239     if (II) {
240       Hash.AddIdentifierInfo(II);
241     }
242   }
243 
244   void AddQualType(QualType T) {
245     Hash.AddQualType(T);
246   }
247 
248   void AddDecl(const Decl *D) {
249     Hash.AddBoolean(D);
250     if (D) {
251       Hash.AddDecl(D);
252     }
253   }
254 
255   void AddTemplateArgument(TemplateArgument TA) {
256     Hash.AddTemplateArgument(TA);
257   }
258 
259   void Visit(const Decl *D) {
260     ID.AddInteger(D->getKind());
261     Inherited::Visit(D);
262   }
263 
264   void VisitNamedDecl(const NamedDecl *D) {
265     Hash.AddDeclarationName(D->getDeclName());
266     Inherited::VisitNamedDecl(D);
267   }
268 
269   void VisitValueDecl(const ValueDecl *D) {
270     if (!isa<FunctionDecl>(D)) {
271       AddQualType(D->getType());
272     }
273     Inherited::VisitValueDecl(D);
274   }
275 
276   void VisitVarDecl(const VarDecl *D) {
277     Hash.AddBoolean(D->isStaticLocal());
278     Hash.AddBoolean(D->isConstexpr());
279     const bool HasInit = D->hasInit();
280     Hash.AddBoolean(HasInit);
281     if (HasInit) {
282       AddStmt(D->getInit());
283     }
284     Inherited::VisitVarDecl(D);
285   }
286 
287   void VisitParmVarDecl(const ParmVarDecl *D) {
288     // TODO: Handle default arguments.
289     Inherited::VisitParmVarDecl(D);
290   }
291 
292   void VisitAccessSpecDecl(const AccessSpecDecl *D) {
293     ID.AddInteger(D->getAccess());
294     Inherited::VisitAccessSpecDecl(D);
295   }
296 
297   void VisitStaticAssertDecl(const StaticAssertDecl *D) {
298     AddStmt(D->getAssertExpr());
299     AddStmt(D->getMessage());
300 
301     Inherited::VisitStaticAssertDecl(D);
302   }
303 
304   void VisitFieldDecl(const FieldDecl *D) {
305     const bool IsBitfield = D->isBitField();
306     Hash.AddBoolean(IsBitfield);
307 
308     if (IsBitfield) {
309       AddStmt(D->getBitWidth());
310     }
311 
312     Hash.AddBoolean(D->isMutable());
313     AddStmt(D->getInClassInitializer());
314 
315     Inherited::VisitFieldDecl(D);
316   }
317 
318   void VisitFunctionDecl(const FunctionDecl *D) {
319     ID.AddInteger(D->getStorageClass());
320     Hash.AddBoolean(D->isInlineSpecified());
321     Hash.AddBoolean(D->isVirtualAsWritten());
322     Hash.AddBoolean(D->isPure());
323     Hash.AddBoolean(D->isDeletedAsWritten());
324 
325     ID.AddInteger(D->param_size());
326 
327     for (auto *Param : D->parameters()) {
328       Hash.AddSubDecl(Param);
329     }
330 
331     AddQualType(D->getReturnType());
332 
333     Inherited::VisitFunctionDecl(D);
334   }
335 
336   void VisitCXXMethodDecl(const CXXMethodDecl *D) {
337     Hash.AddBoolean(D->isConst());
338     Hash.AddBoolean(D->isVolatile());
339 
340     Inherited::VisitCXXMethodDecl(D);
341   }
342 
343   void VisitTypedefNameDecl(const TypedefNameDecl *D) {
344     AddQualType(D->getUnderlyingType());
345 
346     Inherited::VisitTypedefNameDecl(D);
347   }
348 
349   void VisitTypedefDecl(const TypedefDecl *D) {
350     Inherited::VisitTypedefDecl(D);
351   }
352 
353   void VisitTypeAliasDecl(const TypeAliasDecl *D) {
354     Inherited::VisitTypeAliasDecl(D);
355   }
356 
357   void VisitFriendDecl(const FriendDecl *D) {
358     TypeSourceInfo *TSI = D->getFriendType();
359     Hash.AddBoolean(TSI);
360     if (TSI) {
361       AddQualType(TSI->getType());
362     } else {
363       AddDecl(D->getFriendDecl());
364     }
365   }
366 
367   void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
368     // Only care about default arguments as part of the definition.
369     const bool hasDefaultArgument =
370         D->hasDefaultArgument() && !D->defaultArgumentWasInherited();
371     Hash.AddBoolean(hasDefaultArgument);
372     if (hasDefaultArgument) {
373       AddTemplateArgument(D->getDefaultArgument());
374     }
375 
376     Inherited::VisitTemplateTypeParmDecl(D);
377   }
378 
379   void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
380     // Only care about default arguments as part of the definition.
381     const bool hasDefaultArgument =
382         D->hasDefaultArgument() && !D->defaultArgumentWasInherited();
383     Hash.AddBoolean(hasDefaultArgument);
384     if (hasDefaultArgument) {
385       AddStmt(D->getDefaultArgument());
386     }
387 
388     Inherited::VisitNonTypeTemplateParmDecl(D);
389   }
390 
391   void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) {
392     // Only care about default arguments as part of the definition.
393     const bool hasDefaultArgument =
394         D->hasDefaultArgument() && !D->defaultArgumentWasInherited();
395     Hash.AddBoolean(hasDefaultArgument);
396     if (hasDefaultArgument) {
397       AddTemplateArgument(D->getDefaultArgument().getArgument());
398     }
399 
400     Inherited::VisitTemplateTemplateParmDecl(D);
401   }
402 };
403 } // namespace
404 
405 // Only allow a small portion of Decl's to be processed.  Remove this once
406 // all Decl's can be handled.
407 bool ODRHash::isWhitelistedDecl(const Decl *D, const CXXRecordDecl *Parent) {
408   if (D->isImplicit()) return false;
409   if (D->getDeclContext() != Parent) return false;
410 
411   switch (D->getKind()) {
412     default:
413       return false;
414     case Decl::AccessSpec:
415     case Decl::CXXConstructor:
416     case Decl::CXXDestructor:
417     case Decl::CXXMethod:
418     case Decl::Field:
419     case Decl::Friend:
420     case Decl::StaticAssert:
421     case Decl::TypeAlias:
422     case Decl::Typedef:
423     case Decl::Var:
424       return true;
425   }
426 }
427 
428 void ODRHash::AddSubDecl(const Decl *D) {
429   assert(D && "Expecting non-null pointer.");
430 
431   ODRDeclVisitor(ID, *this).Visit(D);
432 }
433 
434 void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) {
435   assert(Record && Record->hasDefinition() &&
436          "Expected non-null record to be a definition.");
437 
438   const DeclContext *DC = Record;
439   while (DC) {
440     if (isa<ClassTemplateSpecializationDecl>(DC)) {
441       return;
442     }
443     DC = DC->getParent();
444   }
445 
446   AddDecl(Record);
447 
448   // Filter out sub-Decls which will not be processed in order to get an
449   // accurate count of Decl's.
450   llvm::SmallVector<const Decl *, 16> Decls;
451   for (const Decl *SubDecl : Record->decls()) {
452     if (isWhitelistedDecl(SubDecl, Record)) {
453       Decls.push_back(SubDecl);
454     }
455   }
456 
457   ID.AddInteger(Decls.size());
458   for (auto SubDecl : Decls) {
459     AddSubDecl(SubDecl);
460   }
461 
462   const ClassTemplateDecl *TD = Record->getDescribedClassTemplate();
463   AddBoolean(TD);
464   if (TD) {
465     AddTemplateParameterList(TD->getTemplateParameters());
466   }
467 
468   ID.AddInteger(Record->getNumBases());
469   auto Bases = Record->bases();
470   for (auto Base : Bases) {
471     AddQualType(Base.getType());
472     ID.AddInteger(Base.isVirtual());
473     ID.AddInteger(Base.getAccessSpecifierAsWritten());
474   }
475 }
476 
477 void ODRHash::AddFunctionDecl(const FunctionDecl *Function) {
478   assert(Function && "Expecting non-null pointer.");
479 
480   // Skip hashing these kinds of function.
481   if (Function->isImplicit()) return;
482   if (Function->isDefaulted()) return;
483   if (Function->isDeleted()) return;
484   if (!Function->hasBody()) return;
485   if (!Function->getBody()) return;
486 
487   // Skip functions that are specializations or in specialization context.
488   const DeclContext *DC = Function;
489   while (DC) {
490     if (isa<ClassTemplateSpecializationDecl>(DC)) return;
491     if (auto *F = dyn_cast<FunctionDecl>(DC))
492       if (F->isFunctionTemplateSpecialization()) return;
493     DC = DC->getParent();
494   }
495 
496   AddDecl(Function);
497 
498   AddQualType(Function->getReturnType());
499 
500   ID.AddInteger(Function->param_size());
501   for (auto Param : Function->parameters())
502     AddSubDecl(Param);
503 
504   AddStmt(Function->getBody());
505 }
506 
507 void ODRHash::AddDecl(const Decl *D) {
508   assert(D && "Expecting non-null pointer.");
509   D = D->getCanonicalDecl();
510 
511   if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
512     AddDeclarationName(ND->getDeclName());
513     return;
514   }
515 
516   ID.AddInteger(D->getKind());
517   // TODO: Handle non-NamedDecl here.
518 }
519 
520 namespace {
521 // Process a Type pointer.  Add* methods call back into ODRHash while Visit*
522 // methods process the relevant parts of the Type.
523 class ODRTypeVisitor : public TypeVisitor<ODRTypeVisitor> {
524   typedef TypeVisitor<ODRTypeVisitor> Inherited;
525   llvm::FoldingSetNodeID &ID;
526   ODRHash &Hash;
527 
528 public:
529   ODRTypeVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
530       : ID(ID), Hash(Hash) {}
531 
532   void AddStmt(Stmt *S) {
533     Hash.AddBoolean(S);
534     if (S) {
535       Hash.AddStmt(S);
536     }
537   }
538 
539   void AddDecl(Decl *D) {
540     Hash.AddBoolean(D);
541     if (D) {
542       Hash.AddDecl(D);
543     }
544   }
545 
546   void AddQualType(QualType T) {
547     Hash.AddQualType(T);
548   }
549 
550   void AddType(const Type *T) {
551     Hash.AddBoolean(T);
552     if (T) {
553       Hash.AddType(T);
554     }
555   }
556 
557   void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
558     Hash.AddBoolean(NNS);
559     if (NNS) {
560       Hash.AddNestedNameSpecifier(NNS);
561     }
562   }
563 
564   void AddIdentifierInfo(const IdentifierInfo *II) {
565     Hash.AddBoolean(II);
566     if (II) {
567       Hash.AddIdentifierInfo(II);
568     }
569   }
570 
571   void VisitQualifiers(Qualifiers Quals) {
572     ID.AddInteger(Quals.getAsOpaqueValue());
573   }
574 
575   void Visit(const Type *T) {
576     ID.AddInteger(T->getTypeClass());
577     Inherited::Visit(T);
578   }
579 
580   void VisitType(const Type *T) {}
581 
582   void VisitAdjustedType(const AdjustedType *T) {
583     AddQualType(T->getOriginalType());
584     AddQualType(T->getAdjustedType());
585     VisitType(T);
586   }
587 
588   void VisitDecayedType(const DecayedType *T) {
589     AddQualType(T->getDecayedType());
590     AddQualType(T->getPointeeType());
591     VisitAdjustedType(T);
592   }
593 
594   void VisitArrayType(const ArrayType *T) {
595     AddQualType(T->getElementType());
596     ID.AddInteger(T->getSizeModifier());
597     VisitQualifiers(T->getIndexTypeQualifiers());
598     VisitType(T);
599   }
600   void VisitConstantArrayType(const ConstantArrayType *T) {
601     T->getSize().Profile(ID);
602     VisitArrayType(T);
603   }
604 
605   void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
606     AddStmt(T->getSizeExpr());
607     VisitArrayType(T);
608   }
609 
610   void VisitIncompleteArrayType(const IncompleteArrayType *T) {
611     VisitArrayType(T);
612   }
613 
614   void VisitVariableArrayType(const VariableArrayType *T) {
615     AddStmt(T->getSizeExpr());
616     VisitArrayType(T);
617   }
618 
619   void VisitBuiltinType(const BuiltinType *T) {
620     ID.AddInteger(T->getKind());
621     VisitType(T);
622   }
623 
624   void VisitFunctionType(const FunctionType *T) {
625     AddQualType(T->getReturnType());
626     T->getExtInfo().Profile(ID);
627     Hash.AddBoolean(T->isConst());
628     Hash.AddBoolean(T->isVolatile());
629     Hash.AddBoolean(T->isRestrict());
630     VisitType(T);
631   }
632 
633   void VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
634     VisitFunctionType(T);
635   }
636 
637   void VisitFunctionProtoType(const FunctionProtoType *T) {
638     ID.AddInteger(T->getNumParams());
639     for (auto ParamType : T->getParamTypes())
640       AddQualType(ParamType);
641 
642     VisitFunctionType(T);
643   }
644 
645   void VisitTypedefType(const TypedefType *T) {
646     AddDecl(T->getDecl());
647     QualType UnderlyingType = T->getDecl()->getUnderlyingType();
648     VisitQualifiers(UnderlyingType.getQualifiers());
649     while (true) {
650       if (const TypedefType *Underlying =
651               dyn_cast<TypedefType>(UnderlyingType.getTypePtr())) {
652         UnderlyingType = Underlying->getDecl()->getUnderlyingType();
653         continue;
654       }
655       if (const ElaboratedType *Underlying =
656               dyn_cast<ElaboratedType>(UnderlyingType.getTypePtr())) {
657         UnderlyingType = Underlying->getNamedType();
658         continue;
659       }
660 
661       break;
662     }
663     AddType(UnderlyingType.getTypePtr());
664     VisitType(T);
665   }
666 
667   void VisitTagType(const TagType *T) {
668     AddDecl(T->getDecl());
669     VisitType(T);
670   }
671 
672   void VisitRecordType(const RecordType *T) { VisitTagType(T); }
673   void VisitEnumType(const EnumType *T) { VisitTagType(T); }
674 
675   void VisitTypeWithKeyword(const TypeWithKeyword *T) {
676     ID.AddInteger(T->getKeyword());
677     VisitType(T);
678   };
679 
680   void VisitDependentNameType(const DependentNameType *T) {
681     AddNestedNameSpecifier(T->getQualifier());
682     AddIdentifierInfo(T->getIdentifier());
683     VisitTypeWithKeyword(T);
684   }
685 
686   void VisitDependentTemplateSpecializationType(
687       const DependentTemplateSpecializationType *T) {
688     AddIdentifierInfo(T->getIdentifier());
689     AddNestedNameSpecifier(T->getQualifier());
690     ID.AddInteger(T->getNumArgs());
691     for (const auto &TA : T->template_arguments()) {
692       Hash.AddTemplateArgument(TA);
693     }
694     VisitTypeWithKeyword(T);
695   }
696 
697   void VisitElaboratedType(const ElaboratedType *T) {
698     AddNestedNameSpecifier(T->getQualifier());
699     AddQualType(T->getNamedType());
700     VisitTypeWithKeyword(T);
701   }
702 
703   void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
704     ID.AddInteger(T->getNumArgs());
705     for (const auto &TA : T->template_arguments()) {
706       Hash.AddTemplateArgument(TA);
707     }
708     Hash.AddTemplateName(T->getTemplateName());
709     VisitType(T);
710   }
711 
712   void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
713     ID.AddInteger(T->getDepth());
714     ID.AddInteger(T->getIndex());
715     Hash.AddBoolean(T->isParameterPack());
716     AddDecl(T->getDecl());
717   }
718 };
719 } // namespace
720 
721 void ODRHash::AddType(const Type *T) {
722   assert(T && "Expecting non-null pointer.");
723   auto Result = TypeMap.insert(std::make_pair(T, TypeMap.size()));
724   ID.AddInteger(Result.first->second);
725   // On first encounter of a Type pointer, process it.  Every time afterwards,
726   // only the index value is needed.
727   if (!Result.second) {
728     return;
729   }
730 
731   ODRTypeVisitor(ID, *this).Visit(T);
732 }
733 
734 void ODRHash::AddQualType(QualType T) {
735   AddBoolean(T.isNull());
736   if (T.isNull())
737     return;
738   SplitQualType split = T.split();
739   ID.AddInteger(split.Quals.getAsOpaqueValue());
740   AddType(split.Ty);
741 }
742 
743 void ODRHash::AddBoolean(bool Value) {
744   Bools.push_back(Value);
745 }
746