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