blob: 3f66e58eb868c7cc11b1d1d0c0560316ef4e4d83 [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 Trieu96b41642017-07-01 02:00:05 +000085 assert(NNS && "Expecting non-null pointer.");
86 const auto *Prefix = NNS->getPrefix();
87 AddBoolean(Prefix);
88 if (Prefix) {
89 AddNestedNameSpecifier(Prefix);
Richard Trieuce81b192017-05-17 03:23:35 +000090 }
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
Richard Trieu96b49622017-05-31 00:31:58 +0000113void 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
Richard Trieu3b261bb72017-06-13 22:21:18 +0000131void ODRHash::AddTemplateArgument(TemplateArgument TA) {
132 const auto Kind = TA.getKind();
133 ID.AddInteger(Kind);
Richard Trieu1dcb4052017-06-14 01:28:00 +0000134
135 switch (Kind) {
136 case TemplateArgument::Null:
Richard Trieu8844c522017-06-30 22:40:33 +0000137 llvm_unreachable("Expected valid TemplateArgument");
Richard Trieu1dcb4052017-06-14 01:28:00 +0000138 case TemplateArgument::Type:
Richard Trieu8844c522017-06-30 22:40:33 +0000139 AddQualType(TA.getAsType());
140 break;
Richard Trieu1dcb4052017-06-14 01:28:00 +0000141 case TemplateArgument::Declaration:
142 case TemplateArgument::NullPtr:
143 case TemplateArgument::Integral:
Richard Trieuee132d62017-06-14 03:17:26 +0000144 break;
Richard Trieu1dcb4052017-06-14 01:28:00 +0000145 case TemplateArgument::Template:
146 case TemplateArgument::TemplateExpansion:
Richard Trieuee132d62017-06-14 03:17:26 +0000147 AddTemplateName(TA.getAsTemplateOrTemplatePattern());
Richard Trieu1dcb4052017-06-14 01:28:00 +0000148 break;
149 case TemplateArgument::Expression:
150 AddStmt(TA.getAsExpr());
151 break;
152 case TemplateArgument::Pack:
Richard Trieud9201d02017-06-15 01:35:06 +0000153 ID.AddInteger(TA.pack_size());
154 for (auto SubTA : TA.pack_elements()) {
155 AddTemplateArgument(SubTA);
156 }
Richard Trieu1dcb4052017-06-14 01:28:00 +0000157 break;
158 }
Richard Trieu3b261bb72017-06-13 22:21:18 +0000159}
160
Richard Trieue7f7ed22017-02-22 01:11:25 +0000161void ODRHash::AddTemplateParameterList(const TemplateParameterList *TPL) {}
162
163void ODRHash::clear() {
164 DeclMap.clear();
165 TypeMap.clear();
166 Bools.clear();
167 ID.clear();
168}
169
170unsigned ODRHash::CalculateHash() {
171 // Append the bools to the end of the data segment backwards. This allows
172 // for the bools data to be compressed 32 times smaller compared to using
173 // ID.AddBoolean
174 const unsigned unsigned_bits = sizeof(unsigned) * CHAR_BIT;
175 const unsigned size = Bools.size();
176 const unsigned remainder = size % unsigned_bits;
177 const unsigned loops = size / unsigned_bits;
178 auto I = Bools.rbegin();
179 unsigned value = 0;
180 for (unsigned i = 0; i < remainder; ++i) {
181 value <<= 1;
182 value |= *I;
183 ++I;
184 }
185 ID.AddInteger(value);
186
187 for (unsigned i = 0; i < loops; ++i) {
188 value = 0;
189 for (unsigned j = 0; j < unsigned_bits; ++j) {
190 value <<= 1;
191 value |= *I;
192 ++I;
193 }
194 ID.AddInteger(value);
195 }
196
197 assert(I == Bools.rend());
198 Bools.clear();
199 return ID.ComputeHash();
200}
201
202// Process a Decl pointer. Add* methods call back into ODRHash while Visit*
203// methods process the relevant parts of the Decl.
204class ODRDeclVisitor : public ConstDeclVisitor<ODRDeclVisitor> {
205 typedef ConstDeclVisitor<ODRDeclVisitor> Inherited;
206 llvm::FoldingSetNodeID &ID;
Richard Trieu639d7b62017-02-22 22:22:42 +0000207 ODRHash &Hash;
Richard Trieue7f7ed22017-02-22 01:11:25 +0000208
209public:
Richard Trieu639d7b62017-02-22 22:22:42 +0000210 ODRDeclVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
211 : ID(ID), Hash(Hash) {}
212
213 void AddStmt(const Stmt *S) {
214 Hash.AddBoolean(S);
215 if (S) {
216 Hash.AddStmt(S);
217 }
218 }
Richard Trieue7f7ed22017-02-22 01:11:25 +0000219
Richard Trieud0786092017-02-23 00:23:01 +0000220 void AddIdentifierInfo(const IdentifierInfo *II) {
221 Hash.AddBoolean(II);
222 if (II) {
223 Hash.AddIdentifierInfo(II);
224 }
225 }
226
Richard Trieubcaaf962017-02-23 03:25:57 +0000227 void AddQualType(QualType T) {
228 Hash.AddQualType(T);
229 }
230
Richard Trieue7f7ed22017-02-22 01:11:25 +0000231 void Visit(const Decl *D) {
232 ID.AddInteger(D->getKind());
233 Inherited::Visit(D);
234 }
235
Richard Trieud0786092017-02-23 00:23:01 +0000236 void VisitNamedDecl(const NamedDecl *D) {
Richard Trieu583e2c12017-03-04 00:08:58 +0000237 Hash.AddDeclarationName(D->getDeclName());
Richard Trieud0786092017-02-23 00:23:01 +0000238 Inherited::VisitNamedDecl(D);
239 }
240
Richard Trieubcaaf962017-02-23 03:25:57 +0000241 void VisitValueDecl(const ValueDecl *D) {
242 AddQualType(D->getType());
243 Inherited::VisitValueDecl(D);
244 }
245
Richard Trieu6e13ff32017-06-16 02:44:29 +0000246 void VisitVarDecl(const VarDecl *D) {
247 Hash.AddBoolean(D->isStaticLocal());
248 Hash.AddBoolean(D->isConstexpr());
249 const bool HasInit = D->hasInit();
250 Hash.AddBoolean(HasInit);
251 if (HasInit) {
252 AddStmt(D->getInit());
253 }
254 Inherited::VisitVarDecl(D);
255 }
256
Richard Trieu02552272017-05-02 23:58:52 +0000257 void VisitParmVarDecl(const ParmVarDecl *D) {
258 // TODO: Handle default arguments.
259 Inherited::VisitParmVarDecl(D);
260 }
261
Richard Trieue7f7ed22017-02-22 01:11:25 +0000262 void VisitAccessSpecDecl(const AccessSpecDecl *D) {
263 ID.AddInteger(D->getAccess());
264 Inherited::VisitAccessSpecDecl(D);
265 }
Richard Trieu639d7b62017-02-22 22:22:42 +0000266
267 void VisitStaticAssertDecl(const StaticAssertDecl *D) {
268 AddStmt(D->getAssertExpr());
269 AddStmt(D->getMessage());
270
271 Inherited::VisitStaticAssertDecl(D);
272 }
Richard Trieud0786092017-02-23 00:23:01 +0000273
274 void VisitFieldDecl(const FieldDecl *D) {
Richard Trieu93772fc2017-02-24 20:59:28 +0000275 const bool IsBitfield = D->isBitField();
276 Hash.AddBoolean(IsBitfield);
277
278 if (IsBitfield) {
279 AddStmt(D->getBitWidth());
280 }
Richard Trieu8d543e22017-02-24 23:35:37 +0000281
282 Hash.AddBoolean(D->isMutable());
283 AddStmt(D->getInClassInitializer());
Richard Trieuff60e0f2017-02-25 01:29:34 +0000284
285 Inherited::VisitFieldDecl(D);
Richard Trieud0786092017-02-23 00:23:01 +0000286 }
Richard Trieu48143742017-02-28 21:24:38 +0000287
288 void VisitFunctionDecl(const FunctionDecl *D) {
Richard Trieu583e2c12017-03-04 00:08:58 +0000289 ID.AddInteger(D->getStorageClass());
290 Hash.AddBoolean(D->isInlineSpecified());
291 Hash.AddBoolean(D->isVirtualAsWritten());
292 Hash.AddBoolean(D->isPure());
293 Hash.AddBoolean(D->isDeletedAsWritten());
294
Richard Trieu02552272017-05-02 23:58:52 +0000295 ID.AddInteger(D->param_size());
296
297 for (auto *Param : D->parameters()) {
298 Hash.AddSubDecl(Param);
299 }
300
Richard Trieu48143742017-02-28 21:24:38 +0000301 Inherited::VisitFunctionDecl(D);
302 }
303
304 void VisitCXXMethodDecl(const CXXMethodDecl *D) {
Richard Trieu583e2c12017-03-04 00:08:58 +0000305 Hash.AddBoolean(D->isConst());
306 Hash.AddBoolean(D->isVolatile());
307
Richard Trieu48143742017-02-28 21:24:38 +0000308 Inherited::VisitCXXMethodDecl(D);
309 }
Richard Trieu33562c22017-03-08 00:13:19 +0000310
311 void VisitTypedefNameDecl(const TypedefNameDecl *D) {
312 AddQualType(D->getUnderlyingType());
313
314 Inherited::VisitTypedefNameDecl(D);
315 }
316
317 void VisitTypedefDecl(const TypedefDecl *D) {
318 Inherited::VisitTypedefDecl(D);
319 }
320
321 void VisitTypeAliasDecl(const TypeAliasDecl *D) {
322 Inherited::VisitTypeAliasDecl(D);
323 }
Richard Trieue7f7ed22017-02-22 01:11:25 +0000324};
325
326// Only allow a small portion of Decl's to be processed. Remove this once
327// all Decl's can be handled.
328bool ODRHash::isWhitelistedDecl(const Decl *D, const CXXRecordDecl *Parent) {
329 if (D->isImplicit()) return false;
330 if (D->getDeclContext() != Parent) return false;
331
332 switch (D->getKind()) {
333 default:
334 return false;
335 case Decl::AccessSpec:
Richard Trieu48143742017-02-28 21:24:38 +0000336 case Decl::CXXMethod:
Richard Trieud0786092017-02-23 00:23:01 +0000337 case Decl::Field:
Richard Trieu639d7b62017-02-22 22:22:42 +0000338 case Decl::StaticAssert:
Richard Trieu33562c22017-03-08 00:13:19 +0000339 case Decl::TypeAlias:
340 case Decl::Typedef:
Richard Trieu6e13ff32017-06-16 02:44:29 +0000341 case Decl::Var:
Richard Trieue7f7ed22017-02-22 01:11:25 +0000342 return true;
343 }
344}
345
346void ODRHash::AddSubDecl(const Decl *D) {
347 assert(D && "Expecting non-null pointer.");
348 AddDecl(D);
349
Richard Trieu639d7b62017-02-22 22:22:42 +0000350 ODRDeclVisitor(ID, *this).Visit(D);
Richard Trieue7f7ed22017-02-22 01:11:25 +0000351}
352
353void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) {
354 assert(Record && Record->hasDefinition() &&
355 "Expected non-null record to be a definition.");
Richard Trieu02552272017-05-02 23:58:52 +0000356
357 if (isa<ClassTemplateSpecializationDecl>(Record)) {
358 return;
359 }
360
Richard Trieue7f7ed22017-02-22 01:11:25 +0000361 AddDecl(Record);
362
363 // Filter out sub-Decls which will not be processed in order to get an
364 // accurate count of Decl's.
365 llvm::SmallVector<const Decl *, 16> Decls;
366 for (const Decl *SubDecl : Record->decls()) {
367 if (isWhitelistedDecl(SubDecl, Record)) {
368 Decls.push_back(SubDecl);
369 }
370 }
371
372 ID.AddInteger(Decls.size());
373 for (auto SubDecl : Decls) {
374 AddSubDecl(SubDecl);
375 }
376}
377
378void ODRHash::AddDecl(const Decl *D) {
379 assert(D && "Expecting non-null pointer.");
380 auto Result = DeclMap.insert(std::make_pair(D, DeclMap.size()));
381 ID.AddInteger(Result.first->second);
382 // On first encounter of a Decl pointer, process it. Every time afterwards,
383 // only the index value is needed.
384 if (!Result.second) {
385 return;
386 }
387
388 ID.AddInteger(D->getKind());
Richard Trieu8459ddf2017-02-24 02:59:12 +0000389
390 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
391 AddDeclarationName(ND->getDeclName());
392 }
Richard Trieue7f7ed22017-02-22 01:11:25 +0000393}
394
Richard Trieubcaaf962017-02-23 03:25:57 +0000395// Process a Type pointer. Add* methods call back into ODRHash while Visit*
396// methods process the relevant parts of the Type.
397class ODRTypeVisitor : public TypeVisitor<ODRTypeVisitor> {
398 typedef TypeVisitor<ODRTypeVisitor> Inherited;
399 llvm::FoldingSetNodeID &ID;
400 ODRHash &Hash;
401
402public:
403 ODRTypeVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
404 : ID(ID), Hash(Hash) {}
405
406 void AddStmt(Stmt *S) {
407 Hash.AddBoolean(S);
408 if (S) {
409 Hash.AddStmt(S);
410 }
411 }
412
Richard Trieu8459ddf2017-02-24 02:59:12 +0000413 void AddDecl(Decl *D) {
414 Hash.AddBoolean(D);
415 if (D) {
416 Hash.AddDecl(D);
417 }
418 }
419
Richard Trieu02552272017-05-02 23:58:52 +0000420 void AddQualType(QualType T) {
421 Hash.AddQualType(T);
422 }
423
Richard Trieu3e03d3e2017-06-29 22:53:04 +0000424 void AddType(const Type *T) {
425 Hash.AddBoolean(T);
426 if (T) {
427 Hash.AddType(T);
428 }
429 }
430
Richard Trieu58bb7bd2017-05-17 02:29:02 +0000431 void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
Richard Trieu96b41642017-07-01 02:00:05 +0000432 Hash.AddBoolean(NNS);
433 if (NNS) {
434 Hash.AddNestedNameSpecifier(NNS);
435 }
Richard Trieu58bb7bd2017-05-17 02:29:02 +0000436 }
437
438 void AddIdentifierInfo(const IdentifierInfo *II) {
439 Hash.AddBoolean(II);
440 if (II) {
441 Hash.AddIdentifierInfo(II);
442 }
443 }
444
Richard Trieu02552272017-05-02 23:58:52 +0000445 void VisitQualifiers(Qualifiers Quals) {
446 ID.AddInteger(Quals.getAsOpaqueValue());
447 }
448
Richard Trieubcaaf962017-02-23 03:25:57 +0000449 void Visit(const Type *T) {
450 ID.AddInteger(T->getTypeClass());
451 Inherited::Visit(T);
452 }
453
454 void VisitType(const Type *T) {}
455
Richard Trieu02552272017-05-02 23:58:52 +0000456 void VisitAdjustedType(const AdjustedType *T) {
457 AddQualType(T->getOriginalType());
458 AddQualType(T->getAdjustedType());
459 VisitType(T);
460 }
461
462 void VisitDecayedType(const DecayedType *T) {
463 AddQualType(T->getDecayedType());
464 AddQualType(T->getPointeeType());
465 VisitAdjustedType(T);
466 }
467
468 void VisitArrayType(const ArrayType *T) {
469 AddQualType(T->getElementType());
470 ID.AddInteger(T->getSizeModifier());
471 VisitQualifiers(T->getIndexTypeQualifiers());
472 VisitType(T);
473 }
474 void VisitConstantArrayType(const ConstantArrayType *T) {
475 T->getSize().Profile(ID);
476 VisitArrayType(T);
477 }
478
479 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
480 AddStmt(T->getSizeExpr());
481 VisitArrayType(T);
482 }
483
484 void VisitIncompleteArrayType(const IncompleteArrayType *T) {
485 VisitArrayType(T);
486 }
487
488 void VisitVariableArrayType(const VariableArrayType *T) {
489 AddStmt(T->getSizeExpr());
490 VisitArrayType(T);
491 }
492
Richard Trieubcaaf962017-02-23 03:25:57 +0000493 void VisitBuiltinType(const BuiltinType *T) {
494 ID.AddInteger(T->getKind());
495 VisitType(T);
496 }
Richard Trieu8459ddf2017-02-24 02:59:12 +0000497
Richard Trieu02552272017-05-02 23:58:52 +0000498 void VisitFunctionType(const FunctionType *T) {
499 AddQualType(T->getReturnType());
500 T->getExtInfo().Profile(ID);
501 Hash.AddBoolean(T->isConst());
502 Hash.AddBoolean(T->isVolatile());
503 Hash.AddBoolean(T->isRestrict());
504 VisitType(T);
505 }
506
507 void VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
508 VisitFunctionType(T);
509 }
510
511 void VisitFunctionProtoType(const FunctionProtoType *T) {
512 ID.AddInteger(T->getNumParams());
513 for (auto ParamType : T->getParamTypes())
514 AddQualType(ParamType);
515
516 VisitFunctionType(T);
517 }
518
Richard Trieu8459ddf2017-02-24 02:59:12 +0000519 void VisitTypedefType(const TypedefType *T) {
520 AddDecl(T->getDecl());
Richard Trieu3e03d3e2017-06-29 22:53:04 +0000521 QualType UnderlyingType = T->getDecl()->getUnderlyingType();
522 VisitQualifiers(UnderlyingType.getQualifiers());
523 while (const TypedefType *Underlying =
524 dyn_cast<TypedefType>(UnderlyingType.getTypePtr())) {
525 UnderlyingType = Underlying->getDecl()->getUnderlyingType();
526 }
527 AddType(UnderlyingType.getTypePtr());
Richard Trieu8459ddf2017-02-24 02:59:12 +0000528 VisitType(T);
529 }
Richard Trieu58bb7bd2017-05-17 02:29:02 +0000530
531 void VisitTagType(const TagType *T) {
532 AddDecl(T->getDecl());
533 VisitType(T);
534 }
535
536 void VisitRecordType(const RecordType *T) { VisitTagType(T); }
537 void VisitEnumType(const EnumType *T) { VisitTagType(T); }
538
539 void VisitTypeWithKeyword(const TypeWithKeyword *T) {
540 ID.AddInteger(T->getKeyword());
541 VisitType(T);
542 };
543
544 void VisitDependentNameType(const DependentNameType *T) {
545 AddNestedNameSpecifier(T->getQualifier());
546 AddIdentifierInfo(T->getIdentifier());
547 VisitTypeWithKeyword(T);
548 }
549
550 void VisitDependentTemplateSpecializationType(
551 const DependentTemplateSpecializationType *T) {
552 AddIdentifierInfo(T->getIdentifier());
553 AddNestedNameSpecifier(T->getQualifier());
554 ID.AddInteger(T->getNumArgs());
555 for (const auto &TA : T->template_arguments()) {
556 Hash.AddTemplateArgument(TA);
557 }
558 VisitTypeWithKeyword(T);
559 }
560
561 void VisitElaboratedType(const ElaboratedType *T) {
562 AddNestedNameSpecifier(T->getQualifier());
563 AddQualType(T->getNamedType());
564 VisitTypeWithKeyword(T);
565 }
Richard Trieu96b49622017-05-31 00:31:58 +0000566
567 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
568 ID.AddInteger(T->getNumArgs());
569 for (const auto &TA : T->template_arguments()) {
570 Hash.AddTemplateArgument(TA);
571 }
572 Hash.AddTemplateName(T->getTemplateName());
573 VisitType(T);
574 }
Richard Trieud9201d02017-06-15 01:35:06 +0000575
576 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
577 ID.AddInteger(T->getDepth());
578 ID.AddInteger(T->getIndex());
579 Hash.AddBoolean(T->isParameterPack());
580 AddDecl(T->getDecl());
581 }
Richard Trieubcaaf962017-02-23 03:25:57 +0000582};
583
584void ODRHash::AddType(const Type *T) {
585 assert(T && "Expecting non-null pointer.");
586 auto Result = TypeMap.insert(std::make_pair(T, TypeMap.size()));
587 ID.AddInteger(Result.first->second);
588 // On first encounter of a Type pointer, process it. Every time afterwards,
589 // only the index value is needed.
590 if (!Result.second) {
591 return;
592 }
593
594 ODRTypeVisitor(ID, *this).Visit(T);
595}
596
597void ODRHash::AddQualType(QualType T) {
598 AddBoolean(T.isNull());
599 if (T.isNull())
600 return;
601 SplitQualType split = T.split();
602 ID.AddInteger(split.Quals.getAsOpaqueValue());
603 AddType(split.Ty);
604}
605
Richard Trieue7f7ed22017-02-22 01:11:25 +0000606void ODRHash::AddBoolean(bool Value) {
607 Bools.push_back(Value);
608}