blob: 05bed658f3fcc52f93cc8454aa959f08b390400c [file] [log] [blame]
Richard Trieue7f7ed22017-02-22 01:11:25 +00001//===-- 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
23using namespace clang;
24
Richard Trieu639d7b62017-02-22 22:22:42 +000025void ODRHash::AddStmt(const Stmt *S) {
26 assert(S && "Expecting non-null pointer.");
27 S->ProcessODRHash(ID, *this);
28}
Richard Trieud0786092017-02-23 00:23:01 +000029
30void ODRHash::AddIdentifierInfo(const IdentifierInfo *II) {
31 assert(II && "Expecting non-null pointer.");
32 ID.AddString(II->getName());
33}
34
Richard Trieu8459ddf2017-02-24 02:59:12 +000035void 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
Richard Trieuce81b192017-05-17 03:23:35 +000084void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
Richard Trieuf21b8032017-06-09 20:11:51 +000085 // Unlike the other pointer handling functions, allow null pointers here.
86 if (!NNS) {
87 AddBoolean(false);
88 return;
Richard Trieuce81b192017-05-17 03:23:35 +000089 }
Richard Trieuf21b8032017-06-09 20:11:51 +000090
91 // Skip inlined namespaces.
Richard Trieuce81b192017-05-17 03:23:35 +000092 auto Kind = NNS->getKind();
Richard Trieuf21b8032017-06-09 20:11:51 +000093 if (Kind == NestedNameSpecifier::Namespace) {
94 if (NNS->getAsNamespace()->isInline()) {
95 return AddNestedNameSpecifier(NNS->getPrefix());
96 }
97 }
98
99 AddBoolean(true);
100
101 // Process prefix
102 AddNestedNameSpecifier(NNS->getPrefix());
103
Richard Trieuce81b192017-05-17 03:23:35 +0000104 ID.AddInteger(Kind);
105 switch (Kind) {
106 case NestedNameSpecifier::Identifier:
107 AddIdentifierInfo(NNS->getAsIdentifier());
108 break;
109 case NestedNameSpecifier::Namespace:
110 AddDecl(NNS->getAsNamespace());
111 break;
112 case NestedNameSpecifier::NamespaceAlias:
113 AddDecl(NNS->getAsNamespaceAlias());
114 break;
115 case NestedNameSpecifier::TypeSpec:
116 case NestedNameSpecifier::TypeSpecWithTemplate:
117 AddType(NNS->getAsType());
118 break;
119 case NestedNameSpecifier::Global:
120 case NestedNameSpecifier::Super:
121 break;
122 }
123}
124
Richard Trieu96b49622017-05-31 00:31:58 +0000125void ODRHash::AddTemplateName(TemplateName Name) {
126 auto Kind = Name.getKind();
127 ID.AddInteger(Kind);
128
129 switch (Kind) {
130 case TemplateName::Template:
131 AddDecl(Name.getAsTemplateDecl());
132 break;
133 // TODO: Support these cases.
134 case TemplateName::OverloadedTemplate:
135 case TemplateName::QualifiedTemplate:
136 case TemplateName::DependentTemplate:
137 case TemplateName::SubstTemplateTemplateParm:
138 case TemplateName::SubstTemplateTemplateParmPack:
139 break;
140 }
141}
142
Richard Trieu3b261bb72017-06-13 22:21:18 +0000143void ODRHash::AddTemplateArgument(TemplateArgument TA) {
144 const auto Kind = TA.getKind();
145 ID.AddInteger(Kind);
Richard Trieu1dcb4052017-06-14 01:28:00 +0000146
147 switch (Kind) {
148 case TemplateArgument::Null:
149 case TemplateArgument::Type:
150 case TemplateArgument::Declaration:
151 case TemplateArgument::NullPtr:
152 case TemplateArgument::Integral:
Richard Trieuee132d62017-06-14 03:17:26 +0000153 break;
Richard Trieu1dcb4052017-06-14 01:28:00 +0000154 case TemplateArgument::Template:
155 case TemplateArgument::TemplateExpansion:
Richard Trieuee132d62017-06-14 03:17:26 +0000156 AddTemplateName(TA.getAsTemplateOrTemplatePattern());
Richard Trieu1dcb4052017-06-14 01:28:00 +0000157 break;
158 case TemplateArgument::Expression:
159 AddStmt(TA.getAsExpr());
160 break;
161 case TemplateArgument::Pack:
Richard Trieud9201d02017-06-15 01:35:06 +0000162 ID.AddInteger(TA.pack_size());
163 for (auto SubTA : TA.pack_elements()) {
164 AddTemplateArgument(SubTA);
165 }
Richard Trieu1dcb4052017-06-14 01:28:00 +0000166 break;
167 }
Richard Trieu3b261bb72017-06-13 22:21:18 +0000168}
169
Richard Trieue7f7ed22017-02-22 01:11:25 +0000170void ODRHash::AddTemplateParameterList(const TemplateParameterList *TPL) {}
171
172void ODRHash::clear() {
173 DeclMap.clear();
174 TypeMap.clear();
175 Bools.clear();
176 ID.clear();
177}
178
179unsigned ODRHash::CalculateHash() {
180 // Append the bools to the end of the data segment backwards. This allows
181 // for the bools data to be compressed 32 times smaller compared to using
182 // ID.AddBoolean
183 const unsigned unsigned_bits = sizeof(unsigned) * CHAR_BIT;
184 const unsigned size = Bools.size();
185 const unsigned remainder = size % unsigned_bits;
186 const unsigned loops = size / unsigned_bits;
187 auto I = Bools.rbegin();
188 unsigned value = 0;
189 for (unsigned i = 0; i < remainder; ++i) {
190 value <<= 1;
191 value |= *I;
192 ++I;
193 }
194 ID.AddInteger(value);
195
196 for (unsigned i = 0; i < loops; ++i) {
197 value = 0;
198 for (unsigned j = 0; j < unsigned_bits; ++j) {
199 value <<= 1;
200 value |= *I;
201 ++I;
202 }
203 ID.AddInteger(value);
204 }
205
206 assert(I == Bools.rend());
207 Bools.clear();
208 return ID.ComputeHash();
209}
210
211// Process a Decl pointer. Add* methods call back into ODRHash while Visit*
212// methods process the relevant parts of the Decl.
213class ODRDeclVisitor : public ConstDeclVisitor<ODRDeclVisitor> {
214 typedef ConstDeclVisitor<ODRDeclVisitor> Inherited;
215 llvm::FoldingSetNodeID &ID;
Richard Trieu639d7b62017-02-22 22:22:42 +0000216 ODRHash &Hash;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000217
218public:
Richard Trieu639d7b62017-02-22 22:22:42 +0000219 ODRDeclVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
220 : ID(ID), Hash(Hash) {}
221
222 void AddStmt(const Stmt *S) {
223 Hash.AddBoolean(S);
224 if (S) {
225 Hash.AddStmt(S);
226 }
227 }
Richard Trieue7f7ed22017-02-22 01:11:25 +0000228
Richard Trieud0786092017-02-23 00:23:01 +0000229 void AddIdentifierInfo(const IdentifierInfo *II) {
230 Hash.AddBoolean(II);
231 if (II) {
232 Hash.AddIdentifierInfo(II);
233 }
234 }
235
Richard Trieubcaaf962017-02-23 03:25:57 +0000236 void AddQualType(QualType T) {
237 Hash.AddQualType(T);
238 }
239
Richard Trieue7f7ed22017-02-22 01:11:25 +0000240 void Visit(const Decl *D) {
241 ID.AddInteger(D->getKind());
242 Inherited::Visit(D);
243 }
244
Richard Trieud0786092017-02-23 00:23:01 +0000245 void VisitNamedDecl(const NamedDecl *D) {
Richard Trieu583e2c12017-03-04 00:08:58 +0000246 Hash.AddDeclarationName(D->getDeclName());
Richard Trieud0786092017-02-23 00:23:01 +0000247 Inherited::VisitNamedDecl(D);
248 }
249
Richard Trieubcaaf962017-02-23 03:25:57 +0000250 void VisitValueDecl(const ValueDecl *D) {
251 AddQualType(D->getType());
252 Inherited::VisitValueDecl(D);
253 }
254
Richard Trieu6e13ff32017-06-16 02:44:29 +0000255 void VisitVarDecl(const VarDecl *D) {
256 Hash.AddBoolean(D->isStaticLocal());
257 Hash.AddBoolean(D->isConstexpr());
258 const bool HasInit = D->hasInit();
259 Hash.AddBoolean(HasInit);
260 if (HasInit) {
261 AddStmt(D->getInit());
262 }
263 Inherited::VisitVarDecl(D);
264 }
265
Richard Trieu02552272017-05-02 23:58:52 +0000266 void VisitParmVarDecl(const ParmVarDecl *D) {
267 // TODO: Handle default arguments.
268 Inherited::VisitParmVarDecl(D);
269 }
270
Richard Trieue7f7ed22017-02-22 01:11:25 +0000271 void VisitAccessSpecDecl(const AccessSpecDecl *D) {
272 ID.AddInteger(D->getAccess());
273 Inherited::VisitAccessSpecDecl(D);
274 }
Richard Trieu639d7b62017-02-22 22:22:42 +0000275
276 void VisitStaticAssertDecl(const StaticAssertDecl *D) {
277 AddStmt(D->getAssertExpr());
278 AddStmt(D->getMessage());
279
280 Inherited::VisitStaticAssertDecl(D);
281 }
Richard Trieud0786092017-02-23 00:23:01 +0000282
283 void VisitFieldDecl(const FieldDecl *D) {
Richard Trieu93772fc2017-02-24 20:59:28 +0000284 const bool IsBitfield = D->isBitField();
285 Hash.AddBoolean(IsBitfield);
286
287 if (IsBitfield) {
288 AddStmt(D->getBitWidth());
289 }
Richard Trieu8d543e22017-02-24 23:35:37 +0000290
291 Hash.AddBoolean(D->isMutable());
292 AddStmt(D->getInClassInitializer());
Richard Trieuff60e0f2017-02-25 01:29:34 +0000293
294 Inherited::VisitFieldDecl(D);
Richard Trieud0786092017-02-23 00:23:01 +0000295 }
Richard Trieu48143742017-02-28 21:24:38 +0000296
297 void VisitFunctionDecl(const FunctionDecl *D) {
Richard Trieu583e2c12017-03-04 00:08:58 +0000298 ID.AddInteger(D->getStorageClass());
299 Hash.AddBoolean(D->isInlineSpecified());
300 Hash.AddBoolean(D->isVirtualAsWritten());
301 Hash.AddBoolean(D->isPure());
302 Hash.AddBoolean(D->isDeletedAsWritten());
303
Richard Trieu02552272017-05-02 23:58:52 +0000304 ID.AddInteger(D->param_size());
305
306 for (auto *Param : D->parameters()) {
307 Hash.AddSubDecl(Param);
308 }
309
Richard Trieu48143742017-02-28 21:24:38 +0000310 Inherited::VisitFunctionDecl(D);
311 }
312
313 void VisitCXXMethodDecl(const CXXMethodDecl *D) {
Richard Trieu583e2c12017-03-04 00:08:58 +0000314 Hash.AddBoolean(D->isConst());
315 Hash.AddBoolean(D->isVolatile());
316
Richard Trieu48143742017-02-28 21:24:38 +0000317 Inherited::VisitCXXMethodDecl(D);
318 }
Richard Trieu33562c22017-03-08 00:13:19 +0000319
320 void VisitTypedefNameDecl(const TypedefNameDecl *D) {
321 AddQualType(D->getUnderlyingType());
322
323 Inherited::VisitTypedefNameDecl(D);
324 }
325
326 void VisitTypedefDecl(const TypedefDecl *D) {
327 Inherited::VisitTypedefDecl(D);
328 }
329
330 void VisitTypeAliasDecl(const TypeAliasDecl *D) {
331 Inherited::VisitTypeAliasDecl(D);
332 }
Richard Trieue7f7ed22017-02-22 01:11:25 +0000333};
334
335// Only allow a small portion of Decl's to be processed. Remove this once
336// all Decl's can be handled.
337bool ODRHash::isWhitelistedDecl(const Decl *D, const CXXRecordDecl *Parent) {
338 if (D->isImplicit()) return false;
339 if (D->getDeclContext() != Parent) return false;
340
341 switch (D->getKind()) {
342 default:
343 return false;
344 case Decl::AccessSpec:
Richard Trieu48143742017-02-28 21:24:38 +0000345 case Decl::CXXMethod:
Richard Trieud0786092017-02-23 00:23:01 +0000346 case Decl::Field:
Richard Trieu639d7b62017-02-22 22:22:42 +0000347 case Decl::StaticAssert:
Richard Trieu33562c22017-03-08 00:13:19 +0000348 case Decl::TypeAlias:
349 case Decl::Typedef:
Richard Trieu6e13ff32017-06-16 02:44:29 +0000350 case Decl::Var:
Richard Trieue7f7ed22017-02-22 01:11:25 +0000351 return true;
352 }
353}
354
355void ODRHash::AddSubDecl(const Decl *D) {
356 assert(D && "Expecting non-null pointer.");
357 AddDecl(D);
358
Richard Trieu639d7b62017-02-22 22:22:42 +0000359 ODRDeclVisitor(ID, *this).Visit(D);
Richard Trieue7f7ed22017-02-22 01:11:25 +0000360}
361
362void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) {
363 assert(Record && Record->hasDefinition() &&
364 "Expected non-null record to be a definition.");
Richard Trieu02552272017-05-02 23:58:52 +0000365
366 if (isa<ClassTemplateSpecializationDecl>(Record)) {
367 return;
368 }
369
Richard Trieue7f7ed22017-02-22 01:11:25 +0000370 AddDecl(Record);
371
372 // Filter out sub-Decls which will not be processed in order to get an
373 // accurate count of Decl's.
374 llvm::SmallVector<const Decl *, 16> Decls;
375 for (const Decl *SubDecl : Record->decls()) {
376 if (isWhitelistedDecl(SubDecl, Record)) {
377 Decls.push_back(SubDecl);
378 }
379 }
380
381 ID.AddInteger(Decls.size());
382 for (auto SubDecl : Decls) {
383 AddSubDecl(SubDecl);
384 }
385}
386
387void ODRHash::AddDecl(const Decl *D) {
388 assert(D && "Expecting non-null pointer.");
389 auto Result = DeclMap.insert(std::make_pair(D, DeclMap.size()));
390 ID.AddInteger(Result.first->second);
391 // On first encounter of a Decl pointer, process it. Every time afterwards,
392 // only the index value is needed.
393 if (!Result.second) {
394 return;
395 }
396
397 ID.AddInteger(D->getKind());
Richard Trieu8459ddf2017-02-24 02:59:12 +0000398
399 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
400 AddDeclarationName(ND->getDeclName());
401 }
Richard Trieue7f7ed22017-02-22 01:11:25 +0000402}
403
Richard Trieubcaaf962017-02-23 03:25:57 +0000404// Process a Type pointer. Add* methods call back into ODRHash while Visit*
405// methods process the relevant parts of the Type.
406class ODRTypeVisitor : public TypeVisitor<ODRTypeVisitor> {
407 typedef TypeVisitor<ODRTypeVisitor> Inherited;
408 llvm::FoldingSetNodeID &ID;
409 ODRHash &Hash;
410
411public:
412 ODRTypeVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
413 : ID(ID), Hash(Hash) {}
414
415 void AddStmt(Stmt *S) {
416 Hash.AddBoolean(S);
417 if (S) {
418 Hash.AddStmt(S);
419 }
420 }
421
Richard Trieu8459ddf2017-02-24 02:59:12 +0000422 void AddDecl(Decl *D) {
423 Hash.AddBoolean(D);
424 if (D) {
425 Hash.AddDecl(D);
426 }
427 }
428
Richard Trieu02552272017-05-02 23:58:52 +0000429 void AddQualType(QualType T) {
430 Hash.AddQualType(T);
431 }
432
Richard Trieu58bb7bd2017-05-17 02:29:02 +0000433 void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
Richard Trieuf21b8032017-06-09 20:11:51 +0000434 Hash.AddNestedNameSpecifier(NNS);
Richard Trieu58bb7bd2017-05-17 02:29:02 +0000435 }
436
437 void AddIdentifierInfo(const IdentifierInfo *II) {
438 Hash.AddBoolean(II);
439 if (II) {
440 Hash.AddIdentifierInfo(II);
441 }
442 }
443
Richard Trieu02552272017-05-02 23:58:52 +0000444 void VisitQualifiers(Qualifiers Quals) {
445 ID.AddInteger(Quals.getAsOpaqueValue());
446 }
447
Richard Trieubcaaf962017-02-23 03:25:57 +0000448 void Visit(const Type *T) {
449 ID.AddInteger(T->getTypeClass());
450 Inherited::Visit(T);
451 }
452
453 void VisitType(const Type *T) {}
454
Richard Trieu02552272017-05-02 23:58:52 +0000455 void VisitAdjustedType(const AdjustedType *T) {
456 AddQualType(T->getOriginalType());
457 AddQualType(T->getAdjustedType());
458 VisitType(T);
459 }
460
461 void VisitDecayedType(const DecayedType *T) {
462 AddQualType(T->getDecayedType());
463 AddQualType(T->getPointeeType());
464 VisitAdjustedType(T);
465 }
466
467 void VisitArrayType(const ArrayType *T) {
468 AddQualType(T->getElementType());
469 ID.AddInteger(T->getSizeModifier());
470 VisitQualifiers(T->getIndexTypeQualifiers());
471 VisitType(T);
472 }
473 void VisitConstantArrayType(const ConstantArrayType *T) {
474 T->getSize().Profile(ID);
475 VisitArrayType(T);
476 }
477
478 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
479 AddStmt(T->getSizeExpr());
480 VisitArrayType(T);
481 }
482
483 void VisitIncompleteArrayType(const IncompleteArrayType *T) {
484 VisitArrayType(T);
485 }
486
487 void VisitVariableArrayType(const VariableArrayType *T) {
488 AddStmt(T->getSizeExpr());
489 VisitArrayType(T);
490 }
491
Richard Trieubcaaf962017-02-23 03:25:57 +0000492 void VisitBuiltinType(const BuiltinType *T) {
493 ID.AddInteger(T->getKind());
494 VisitType(T);
495 }
Richard Trieu8459ddf2017-02-24 02:59:12 +0000496
Richard Trieu02552272017-05-02 23:58:52 +0000497 void VisitFunctionType(const FunctionType *T) {
498 AddQualType(T->getReturnType());
499 T->getExtInfo().Profile(ID);
500 Hash.AddBoolean(T->isConst());
501 Hash.AddBoolean(T->isVolatile());
502 Hash.AddBoolean(T->isRestrict());
503 VisitType(T);
504 }
505
506 void VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
507 VisitFunctionType(T);
508 }
509
510 void VisitFunctionProtoType(const FunctionProtoType *T) {
511 ID.AddInteger(T->getNumParams());
512 for (auto ParamType : T->getParamTypes())
513 AddQualType(ParamType);
514
515 VisitFunctionType(T);
516 }
517
Richard Trieu8459ddf2017-02-24 02:59:12 +0000518 void VisitTypedefType(const TypedefType *T) {
519 AddDecl(T->getDecl());
Richard Trieub35ef2a2017-05-09 03:24:34 +0000520 AddQualType(T->getDecl()->getUnderlyingType().getCanonicalType());
Richard Trieu8459ddf2017-02-24 02:59:12 +0000521 VisitType(T);
522 }
Richard Trieu58bb7bd2017-05-17 02:29:02 +0000523
524 void VisitTagType(const TagType *T) {
525 AddDecl(T->getDecl());
526 VisitType(T);
527 }
528
529 void VisitRecordType(const RecordType *T) { VisitTagType(T); }
530 void VisitEnumType(const EnumType *T) { VisitTagType(T); }
531
532 void VisitTypeWithKeyword(const TypeWithKeyword *T) {
533 ID.AddInteger(T->getKeyword());
534 VisitType(T);
535 };
536
537 void VisitDependentNameType(const DependentNameType *T) {
538 AddNestedNameSpecifier(T->getQualifier());
539 AddIdentifierInfo(T->getIdentifier());
540 VisitTypeWithKeyword(T);
541 }
542
543 void VisitDependentTemplateSpecializationType(
544 const DependentTemplateSpecializationType *T) {
545 AddIdentifierInfo(T->getIdentifier());
546 AddNestedNameSpecifier(T->getQualifier());
547 ID.AddInteger(T->getNumArgs());
548 for (const auto &TA : T->template_arguments()) {
549 Hash.AddTemplateArgument(TA);
550 }
551 VisitTypeWithKeyword(T);
552 }
553
554 void VisitElaboratedType(const ElaboratedType *T) {
555 AddNestedNameSpecifier(T->getQualifier());
556 AddQualType(T->getNamedType());
557 VisitTypeWithKeyword(T);
558 }
Richard Trieu96b49622017-05-31 00:31:58 +0000559
560 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
561 ID.AddInteger(T->getNumArgs());
562 for (const auto &TA : T->template_arguments()) {
563 Hash.AddTemplateArgument(TA);
564 }
565 Hash.AddTemplateName(T->getTemplateName());
566 VisitType(T);
567 }
Richard Trieud9201d02017-06-15 01:35:06 +0000568
569 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
570 ID.AddInteger(T->getDepth());
571 ID.AddInteger(T->getIndex());
572 Hash.AddBoolean(T->isParameterPack());
573 AddDecl(T->getDecl());
574 }
Richard Trieubcaaf962017-02-23 03:25:57 +0000575};
576
577void ODRHash::AddType(const Type *T) {
578 assert(T && "Expecting non-null pointer.");
579 auto Result = TypeMap.insert(std::make_pair(T, TypeMap.size()));
580 ID.AddInteger(Result.first->second);
581 // On first encounter of a Type pointer, process it. Every time afterwards,
582 // only the index value is needed.
583 if (!Result.second) {
584 return;
585 }
586
587 ODRTypeVisitor(ID, *this).Visit(T);
588}
589
590void ODRHash::AddQualType(QualType T) {
591 AddBoolean(T.isNull());
592 if (T.isNull())
593 return;
594 SplitQualType split = T.split();
595 ID.AddInteger(split.Quals.getAsOpaqueValue());
596 AddType(split.Ty);
597}
598
Richard Trieue7f7ed22017-02-22 01:11:25 +0000599void ODRHash::AddBoolean(bool Value) {
600 Bools.push_back(Value);
601}