Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/ODRHash.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- ODRHash.cpp - Hashing to diagnose ODR failures ----------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
///
9
/// \file
10
/// This file implements the ODRHash class, which calculates a hash based
11
/// on AST nodes, which is stable across different runs.
12
///
13
//===----------------------------------------------------------------------===//
14
15
#include "clang/AST/ODRHash.h"
16
17
#include "clang/AST/DeclVisitor.h"
18
#include "clang/AST/NestedNameSpecifier.h"
19
#include "clang/AST/StmtVisitor.h"
20
#include "clang/AST/TypeVisitor.h"
21
22
using namespace clang;
23
24
518k
void ODRHash::AddStmt(const Stmt *S) {
25
518k
  assert(S && "Expecting non-null pointer.");
26
518k
  S->ProcessODRHash(ID, *this);
27
518k
}
28
29
3.62M
void ODRHash::AddIdentifierInfo(const IdentifierInfo *II) {
30
3.62M
  assert(II && "Expecting non-null pointer.");
31
3.62M
  ID.AddString(II->getName());
32
3.62M
}
33
34
6.77M
void ODRHash::AddDeclarationName(DeclarationName Name, bool TreatAsDecl) {
35
6.77M
  if (TreatAsDecl)
36
49.6k
    // Matches the NamedDecl check in AddDecl
37
49.6k
    AddBoolean(true);
38
6.77M
39
6.77M
  AddDeclarationNameImpl(Name);
40
6.77M
41
6.77M
  if (TreatAsDecl)
42
49.6k
    // Matches the ClassTemplateSpecializationDecl check in AddDecl
43
49.6k
    AddBoolean(false);
44
6.77M
}
45
46
6.77M
void ODRHash::AddDeclarationNameImpl(DeclarationName Name) {
47
6.77M
  // Index all DeclarationName and use index numbers to refer to them.
48
6.77M
  auto Result = DeclNameMap.insert(std::make_pair(Name, DeclNameMap.size()));
49
6.77M
  ID.AddInteger(Result.first->second);
50
6.77M
  if (!Result.second) {
51
3.06M
    // If found in map, the DeclarationName has previously been processed.
52
3.06M
    return;
53
3.06M
  }
54
3.70M
55
3.70M
  // First time processing each DeclarationName, also process its details.
56
3.70M
  AddBoolean(Name.isEmpty());
57
3.70M
  if (Name.isEmpty())
58
192k
    return;
59
3.51M
60
3.51M
  auto Kind = Name.getNameKind();
61
3.51M
  ID.AddInteger(Kind);
62
3.51M
  switch (Kind) {
63
3.39M
  case DeclarationName::Identifier:
64
3.39M
    AddIdentifierInfo(Name.getAsIdentifierInfo());
65
3.39M
    break;
66
37
  case DeclarationName::ObjCZeroArgSelector:
67
37
  case DeclarationName::ObjCOneArgSelector:
68
37
  case DeclarationName::ObjCMultiArgSelector: {
69
37
    Selector S = Name.getObjCSelector();
70
37
    AddBoolean(S.isNull());
71
37
    AddBoolean(S.isKeywordSelector());
72
37
    AddBoolean(S.isUnarySelector());
73
37
    unsigned NumArgs = S.getNumArgs();
74
37
    ID.AddInteger(NumArgs);
75
60
    for (unsigned i = 0; i < NumArgs; 
++i23
) {
76
23
      const IdentifierInfo *II = S.getIdentifierInfoForSlot(i);
77
23
      AddBoolean(II);
78
23
      if (II) {
79
20
        AddIdentifierInfo(II);
80
20
      }
81
23
    }
82
37
    break;
83
37
  }
84
60.6k
  case DeclarationName::CXXConstructorName:
85
60.6k
  case DeclarationName::CXXDestructorName:
86
60.6k
    AddQualType(Name.getCXXNameType());
87
60.6k
    break;
88
60.6k
  case DeclarationName::CXXOperatorName:
89
56.4k
    ID.AddInteger(Name.getCXXOverloadedOperator());
90
56.4k
    break;
91
60.6k
  case DeclarationName::CXXLiteralOperatorName:
92
54
    AddIdentifierInfo(Name.getCXXLiteralIdentifier());
93
54
    break;
94
60.6k
  case DeclarationName::CXXConversionFunctionName:
95
1.26k
    AddQualType(Name.getCXXNameType());
96
1.26k
    break;
97
60.6k
  case DeclarationName::CXXUsingDirective:
98
180
    break;
99
60.6k
  case DeclarationName::CXXDeductionGuideName: {
100
818
    auto *Template = Name.getCXXDeductionGuideTemplate();
101
818
    AddBoolean(Template);
102
818
    if (Template) {
103
818
      AddDecl(Template);
104
818
    }
105
818
  }
106
3.51M
  }
107
3.51M
}
108
109
390k
void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
110
390k
  assert(NNS && "Expecting non-null pointer.");
111
390k
  const auto *Prefix = NNS->getPrefix();
112
390k
  AddBoolean(Prefix);
113
390k
  if (Prefix) {
114
39.4k
    AddNestedNameSpecifier(Prefix);
115
39.4k
  }
116
390k
  auto Kind = NNS->getKind();
117
390k
  ID.AddInteger(Kind);
118
390k
  switch (Kind) {
119
568
  case NestedNameSpecifier::Identifier:
120
568
    AddIdentifierInfo(NNS->getAsIdentifier());
121
568
    break;
122
78.0k
  case NestedNameSpecifier::Namespace:
123
78.0k
    AddDecl(NNS->getAsNamespace());
124
78.0k
    break;
125
12
  case NestedNameSpecifier::NamespaceAlias:
126
12
    AddDecl(NNS->getAsNamespaceAlias());
127
12
    break;
128
308k
  case NestedNameSpecifier::TypeSpec:
129
308k
  case NestedNameSpecifier::TypeSpecWithTemplate:
130
308k
    AddType(NNS->getAsType());
131
308k
    break;
132
308k
  case NestedNameSpecifier::Global:
133
3.17k
  case NestedNameSpecifier::Super:
134
3.17k
    break;
135
390k
  }
136
390k
}
137
138
440k
void ODRHash::AddTemplateName(TemplateName Name) {
139
440k
  auto Kind = Name.getKind();
140
440k
  ID.AddInteger(Kind);
141
440k
142
440k
  switch (Kind) {
143
439k
  case TemplateName::Template:
144
439k
    AddDecl(Name.getAsTemplateDecl());
145
439k
    break;
146
0
  // TODO: Support these cases.
147
275
  case TemplateName::OverloadedTemplate:
148
275
  case TemplateName::AssumedTemplate:
149
275
  case TemplateName::QualifiedTemplate:
150
275
  case TemplateName::DependentTemplate:
151
275
  case TemplateName::SubstTemplateTemplateParm:
152
275
  case TemplateName::SubstTemplateTemplateParmPack:
153
275
    break;
154
440k
  }
155
440k
}
156
157
771k
void ODRHash::AddTemplateArgument(TemplateArgument TA) {
158
771k
  const auto Kind = TA.getKind();
159
771k
  ID.AddInteger(Kind);
160
771k
161
771k
  switch (Kind) {
162
0
    case TemplateArgument::Null:
163
0
      llvm_unreachable("Expected valid TemplateArgument");
164
706k
    case TemplateArgument::Type:
165
706k
      AddQualType(TA.getAsType());
166
706k
      break;
167
76
    case TemplateArgument::Declaration:
168
76
      AddDecl(TA.getAsDecl());
169
76
      break;
170
8.11k
    case TemplateArgument::NullPtr:
171
8.11k
    case TemplateArgument::Integral:
172
8.11k
      break;
173
8.11k
    case TemplateArgument::Template:
174
271
    case TemplateArgument::TemplateExpansion:
175
271
      AddTemplateName(TA.getAsTemplateOrTemplatePattern());
176
271
      break;
177
55.1k
    case TemplateArgument::Expression:
178
55.1k
      AddStmt(TA.getAsExpr());
179
55.1k
      break;
180
835
    case TemplateArgument::Pack:
181
835
      ID.AddInteger(TA.pack_size());
182
1.12k
      for (auto SubTA : TA.pack_elements()) {
183
1.12k
        AddTemplateArgument(SubTA);
184
1.12k
      }
185
835
      break;
186
771k
  }
187
771k
}
188
189
27.7k
void ODRHash::AddTemplateParameterList(const TemplateParameterList *TPL) {
190
27.7k
  assert(TPL && "Expecting non-null pointer.");
191
27.7k
192
27.7k
  ID.AddInteger(TPL->size());
193
41.1k
  for (auto *ND : TPL->asArray()) {
194
41.1k
    AddSubDecl(ND);
195
41.1k
  }
196
27.7k
}
197
198
957
void ODRHash::clear() {
199
957
  DeclNameMap.clear();
200
957
  Bools.clear();
201
957
  ID.clear();
202
957
}
203
204
709k
unsigned ODRHash::CalculateHash() {
205
709k
  // Append the bools to the end of the data segment backwards.  This allows
206
709k
  // for the bools data to be compressed 32 times smaller compared to using
207
709k
  // ID.AddBoolean
208
709k
  const unsigned unsigned_bits = sizeof(unsigned) * CHAR_BIT;
209
709k
  const unsigned size = Bools.size();
210
709k
  const unsigned remainder = size % unsigned_bits;
211
709k
  const unsigned loops = size / unsigned_bits;
212
709k
  auto I = Bools.rbegin();
213
709k
  unsigned value = 0;
214
9.14M
  for (unsigned i = 0; i < remainder; 
++i8.43M
) {
215
8.43M
    value <<= 1;
216
8.43M
    value |= *I;
217
8.43M
    ++I;
218
8.43M
  }
219
709k
  ID.AddInteger(value);
220
709k
221
1.43M
  for (unsigned i = 0; i < loops; 
++i725k
) {
222
725k
    value = 0;
223
23.9M
    for (unsigned j = 0; j < unsigned_bits; 
++j23.2M
) {
224
23.2M
      value <<= 1;
225
23.2M
      value |= *I;
226
23.2M
      ++I;
227
23.2M
    }
228
725k
    ID.AddInteger(value);
229
725k
  }
230
709k
231
709k
  assert(I == Bools.rend());
232
709k
  Bools.clear();
233
709k
  return ID.ComputeHash();
234
709k
}
235
236
namespace {
237
// Process a Decl pointer.  Add* methods call back into ODRHash while Visit*
238
// methods process the relevant parts of the Decl.
239
class ODRDeclVisitor : public ConstDeclVisitor<ODRDeclVisitor> {
240
  typedef ConstDeclVisitor<ODRDeclVisitor> Inherited;
241
  llvm::FoldingSetNodeID &ID;
242
  ODRHash &Hash;
243
244
public:
245
  ODRDeclVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
246
1.45M
      : ID(ID), Hash(Hash) {}
247
248
441k
  void AddStmt(const Stmt *S) {
249
441k
    Hash.AddBoolean(S);
250
441k
    if (S) {
251
267k
      Hash.AddStmt(S);
252
267k
    }
253
441k
  }
254
255
0
  void AddIdentifierInfo(const IdentifierInfo *II) {
256
0
    Hash.AddBoolean(II);
257
0
    if (II) {
258
0
      Hash.AddIdentifierInfo(II);
259
0
    }
260
0
  }
261
262
1.30M
  void AddQualType(QualType T) {
263
1.30M
    Hash.AddQualType(T);
264
1.30M
  }
265
266
21.7k
  void AddDecl(const Decl *D) {
267
21.7k
    Hash.AddBoolean(D);
268
21.7k
    if (D) {
269
21.7k
      Hash.AddDecl(D);
270
21.7k
    }
271
21.7k
  }
272
273
3.13k
  void AddTemplateArgument(TemplateArgument TA) {
274
3.13k
    Hash.AddTemplateArgument(TA);
275
3.13k
  }
276
277
1.45M
  void Visit(const Decl *D) {
278
1.45M
    ID.AddInteger(D->getKind());
279
1.45M
    Inherited::Visit(D);
280
1.45M
  }
281
282
1.43M
  void VisitNamedDecl(const NamedDecl *D) {
283
1.43M
    Hash.AddDeclarationName(D->getDeclName());
284
1.43M
    Inherited::VisitNamedDecl(D);
285
1.43M
  }
286
287
1.34M
  void VisitValueDecl(const ValueDecl *D) {
288
1.34M
    if (!isa<FunctionDecl>(D)) {
289
1.26M
      AddQualType(D->getType());
290
1.26M
    }
291
1.34M
    Inherited::VisitValueDecl(D);
292
1.34M
  }
293
294
921k
  void VisitVarDecl(const VarDecl *D) {
295
921k
    Hash.AddBoolean(D->isStaticLocal());
296
921k
    Hash.AddBoolean(D->isConstexpr());
297
921k
    const bool HasInit = D->hasInit();
298
921k
    Hash.AddBoolean(HasInit);
299
921k
    if (HasInit) {
300
86.6k
      AddStmt(D->getInit());
301
86.6k
    }
302
921k
    Inherited::VisitVarDecl(D);
303
921k
  }
304
305
832k
  void VisitParmVarDecl(const ParmVarDecl *D) {
306
832k
    // TODO: Handle default arguments.
307
832k
    Inherited::VisitParmVarDecl(D);
308
832k
  }
309
310
15.1k
  void VisitAccessSpecDecl(const AccessSpecDecl *D) {
311
15.1k
    ID.AddInteger(D->getAccess());
312
15.1k
    Inherited::VisitAccessSpecDecl(D);
313
15.1k
  }
314
315
3.64k
  void VisitStaticAssertDecl(const StaticAssertDecl *D) {
316
3.64k
    AddStmt(D->getAssertExpr());
317
3.64k
    AddStmt(D->getMessage());
318
3.64k
319
3.64k
    Inherited::VisitStaticAssertDecl(D);
320
3.64k
  }
321
322
165k
  void VisitFieldDecl(const FieldDecl *D) {
323
165k
    const bool IsBitfield = D->isBitField();
324
165k
    Hash.AddBoolean(IsBitfield);
325
165k
326
165k
    if (IsBitfield) {
327
3.25k
      AddStmt(D->getBitWidth());
328
3.25k
    }
329
165k
330
165k
    Hash.AddBoolean(D->isMutable());
331
165k
    AddStmt(D->getInClassInitializer());
332
165k
333
165k
    Inherited::VisitFieldDecl(D);
334
165k
  }
335
336
79.0k
  void VisitFunctionDecl(const FunctionDecl *D) {
337
79.0k
    // Handled by the ODRHash for FunctionDecl
338
79.0k
    ID.AddInteger(D->getODRHash());
339
79.0k
340
79.0k
    Inherited::VisitFunctionDecl(D);
341
79.0k
  }
342
343
79.0k
  void VisitCXXMethodDecl(const CXXMethodDecl *D) {
344
79.0k
    // Handled by the ODRHash for FunctionDecl
345
79.0k
346
79.0k
    Inherited::VisitCXXMethodDecl(D);
347
79.0k
  }
348
349
35.3k
  void VisitTypedefNameDecl(const TypedefNameDecl *D) {
350
35.3k
    AddQualType(D->getUnderlyingType());
351
35.3k
352
35.3k
    Inherited::VisitTypedefNameDecl(D);
353
35.3k
  }
354
355
34.1k
  void VisitTypedefDecl(const TypedefDecl *D) {
356
34.1k
    Inherited::VisitTypedefDecl(D);
357
34.1k
  }
358
359
1.17k
  void VisitTypeAliasDecl(const TypeAliasDecl *D) {
360
1.17k
    Inherited::VisitTypeAliasDecl(D);
361
1.17k
  }
362
363
8.38k
  void VisitFriendDecl(const FriendDecl *D) {
364
8.38k
    TypeSourceInfo *TSI = D->getFriendType();
365
8.38k
    Hash.AddBoolean(TSI);
366
8.38k
    if (TSI) {
367
692
      AddQualType(TSI->getType());
368
7.69k
    } else {
369
7.69k
      AddDecl(D->getFriendDecl());
370
7.69k
    }
371
8.38k
  }
372
373
35.5k
  void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
374
35.5k
    // Only care about default arguments as part of the definition.
375
35.5k
    const bool hasDefaultArgument =
376
35.5k
        D->hasDefaultArgument() && 
!D->defaultArgumentWasInherited()3.62k
;
377
35.5k
    Hash.AddBoolean(hasDefaultArgument);
378
35.5k
    if (hasDefaultArgument) {
379
3.09k
      AddTemplateArgument(D->getDefaultArgument());
380
3.09k
    }
381
35.5k
    Hash.AddBoolean(D->isParameterPack());
382
35.5k
383
35.5k
    const TypeConstraint *TC = D->getTypeConstraint();
384
35.5k
    Hash.AddBoolean(TC != nullptr);
385
35.5k
    if (TC)
386
0
      AddStmt(TC->getImmediatelyDeclaredConstraint());
387
35.5k
388
35.5k
    Inherited::VisitTemplateTypeParmDecl(D);
389
35.5k
  }
390
391
5.46k
  void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
392
5.46k
    // Only care about default arguments as part of the definition.
393
5.46k
    const bool hasDefaultArgument =
394
5.46k
        D->hasDefaultArgument() && 
!D->defaultArgumentWasInherited()2.62k
;
395
5.46k
    Hash.AddBoolean(hasDefaultArgument);
396
5.46k
    if (hasDefaultArgument) {
397
2.58k
      AddStmt(D->getDefaultArgument());
398
2.58k
    }
399
5.46k
    Hash.AddBoolean(D->isParameterPack());
400
5.46k
401
5.46k
    Inherited::VisitNonTypeTemplateParmDecl(D);
402
5.46k
  }
403
404
196
  void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) {
405
196
    // Only care about default arguments as part of the definition.
406
196
    const bool hasDefaultArgument =
407
196
        D->hasDefaultArgument() && 
!D->defaultArgumentWasInherited()40
;
408
196
    Hash.AddBoolean(hasDefaultArgument);
409
196
    if (hasDefaultArgument) {
410
40
      AddTemplateArgument(D->getDefaultArgument().getArgument());
411
40
    }
412
196
    Hash.AddBoolean(D->isParameterPack());
413
196
414
196
    Inherited::VisitTemplateTemplateParmDecl(D);
415
196
  }
416
417
14.2k
  void VisitTemplateDecl(const TemplateDecl *D) {
418
14.2k
    Hash.AddTemplateParameterList(D->getTemplateParameters());
419
14.2k
420
14.2k
    Inherited::VisitTemplateDecl(D);
421
14.2k
  }
422
423
14.1k
  void VisitRedeclarableTemplateDecl(const RedeclarableTemplateDecl *D) {
424
14.1k
    Hash.AddBoolean(D->isMemberSpecialization());
425
14.1k
    Inherited::VisitRedeclarableTemplateDecl(D);
426
14.1k
  }
427
428
14.1k
  void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
429
14.1k
    AddDecl(D->getTemplatedDecl());
430
14.1k
    ID.AddInteger(D->getTemplatedDecl()->getODRHash());
431
14.1k
    Inherited::VisitFunctionTemplateDecl(D);
432
14.1k
  }
433
434
176k
  void VisitEnumConstantDecl(const EnumConstantDecl *D) {
435
176k
    AddStmt(D->getInitExpr());
436
176k
    Inherited::VisitEnumConstantDecl(D);
437
176k
  }
438
};
439
} // namespace
440
441
// Only allow a small portion of Decl's to be processed.  Remove this once
442
// all Decl's can be handled.
443
1.01M
bool ODRHash::isWhitelistedDecl(const Decl *D, const DeclContext *Parent) {
444
1.01M
  if (D->isImplicit()) 
return false100k
;
445
916k
  if (D->getDeclContext() != Parent) 
return false1.98k
;
446
914k
447
914k
  switch (D->getKind()) {
448
328k
    default:
449
328k
      return false;
450
586k
    case Decl::AccessSpec:
451
586k
    case Decl::CXXConstructor:
452
586k
    case Decl::CXXDestructor:
453
586k
    case Decl::CXXMethod:
454
586k
    case Decl::EnumConstant: // Only found in EnumDecl's.
455
586k
    case Decl::Field:
456
586k
    case Decl::Friend:
457
586k
    case Decl::FunctionTemplate:
458
586k
    case Decl::StaticAssert:
459
586k
    case Decl::TypeAlias:
460
586k
    case Decl::Typedef:
461
586k
    case Decl::Var:
462
586k
      return true;
463
914k
  }
464
914k
}
465
466
1.45M
void ODRHash::AddSubDecl(const Decl *D) {
467
1.45M
  assert(D && "Expecting non-null pointer.");
468
1.45M
469
1.45M
  ODRDeclVisitor(ID, *this).Visit(D);
470
1.45M
}
471
472
151k
void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) {
473
151k
  assert(Record && Record->hasDefinition() &&
474
151k
         "Expected non-null record to be a definition.");
475
151k
476
151k
  const DeclContext *DC = Record;
477
426k
  while (DC) {
478
355k
    if (isa<ClassTemplateSpecializationDecl>(DC)) {
479
80.6k
      return;
480
80.6k
    }
481
275k
    DC = DC->getParent();
482
275k
  }
483
151k
484
151k
  AddDecl(Record);
485
70.6k
486
70.6k
  // Filter out sub-Decls which will not be processed in order to get an
487
70.6k
  // accurate count of Decl's.
488
70.6k
  llvm::SmallVector<const Decl *, 16> Decls;
489
394k
  for (Decl *SubDecl : Record->decls()) {
490
394k
    if (isWhitelistedDecl(SubDecl, Record)) {
491
312k
      Decls.push_back(SubDecl);
492
312k
      if (auto *Function = dyn_cast<FunctionDecl>(SubDecl)) {
493
78.8k
        // Compute/Preload ODRHash into FunctionDecl.
494
78.8k
        Function->getODRHash();
495
78.8k
      }
496
312k
    }
497
394k
  }
498
70.6k
499
70.6k
  ID.AddInteger(Decls.size());
500
312k
  for (auto SubDecl : Decls) {
501
312k
    AddSubDecl(SubDecl);
502
312k
  }
503
70.6k
504
70.6k
  const ClassTemplateDecl *TD = Record->getDescribedClassTemplate();
505
70.6k
  AddBoolean(TD);
506
70.6k
  if (TD) {
507
13.4k
    AddTemplateParameterList(TD->getTemplateParameters());
508
13.4k
  }
509
70.6k
510
70.6k
  ID.AddInteger(Record->getNumBases());
511
70.6k
  auto Bases = Record->bases();
512
70.6k
  for (auto Base : Bases) {
513
7.45k
    AddQualType(Base.getType());
514
7.45k
    ID.AddInteger(Base.isVirtual());
515
7.45k
    ID.AddInteger(Base.getAccessSpecifierAsWritten());
516
7.45k
  }
517
70.6k
}
518
519
void ODRHash::AddFunctionDecl(const FunctionDecl *Function,
520
532k
                              bool SkipBody) {
521
532k
  assert(Function && "Expecting non-null pointer.");
522
532k
523
532k
  // Skip functions that are specializations or in specialization context.
524
532k
  const DeclContext *DC = Function;
525
2.19M
  while (DC) {
526
1.74M
    if (isa<ClassTemplateSpecializationDecl>(DC)) 
return69.1k
;
527
1.67M
    if (auto *F = dyn_cast<FunctionDecl>(DC)) {
528
535k
      if (F->isFunctionTemplateSpecialization()) {
529
20.3k
        if (!isa<CXXMethodDecl>(DC)) 
return11.4k
;
530
8.94k
        if (DC->getLexicalParent()->isFileContext()) 
return28
;
531
1.65M
        // Inline method specializations are the only supported
532
1.65M
        // specialization for now.
533
1.65M
      }
534
535k
    }
535
1.65M
    DC = DC->getParent();
536
1.65M
  }
537
532k
538
532k
  ID.AddInteger(Function->getDeclKind());
539
451k
540
451k
  const auto *SpecializationArgs = Function->getTemplateSpecializationArgs();
541
451k
  AddBoolean(SpecializationArgs);
542
451k
  if (SpecializationArgs) {
543
5.03k
    ID.AddInteger(SpecializationArgs->size());
544
5.47k
    for (const TemplateArgument &TA : SpecializationArgs->asArray()) {
545
5.47k
      AddTemplateArgument(TA);
546
5.47k
    }
547
5.03k
  }
548
451k
549
451k
  if (const auto *Method = dyn_cast<CXXMethodDecl>(Function)) {
550
133k
    AddBoolean(Method->isConst());
551
133k
    AddBoolean(Method->isVolatile());
552
133k
  }
553
451k
554
451k
  ID.AddInteger(Function->getStorageClass());
555
451k
  AddBoolean(Function->isInlineSpecified());
556
451k
  AddBoolean(Function->isVirtualAsWritten());
557
451k
  AddBoolean(Function->isPure());
558
451k
  AddBoolean(Function->isDeletedAsWritten());
559
451k
  AddBoolean(Function->isExplicitlyDefaulted());
560
451k
561
451k
  AddDecl(Function);
562
451k
563
451k
  AddQualType(Function->getReturnType());
564
451k
565
451k
  ID.AddInteger(Function->param_size());
566
451k
  for (auto Param : Function->parameters())
567
832k
    AddSubDecl(Param);
568
451k
569
451k
  if (SkipBody) {
570
14
    AddBoolean(false);
571
14
    return;
572
14
  }
573
451k
574
451k
  const bool HasBody = Function->isThisDeclarationADefinition() &&
575
451k
                       
!Function->isDefaulted()202k
&&
!Function->isDeleted()192k
&&
576
451k
                       
!Function->isLateTemplateParsed()191k
;
577
451k
  AddBoolean(HasBody);
578
451k
  if (!HasBody) {
579
260k
    return;
580
260k
  }
581
191k
582
191k
  auto *Body = Function->getBody();
583
191k
  AddBoolean(Body);
584
191k
  if (Body)
585
191k
    AddStmt(Body);
586
191k
587
191k
  // Filter out sub-Decls which will not be processed in order to get an
588
191k
  // accurate count of Decl's.
589
191k
  llvm::SmallVector<const Decl *, 16> Decls;
590
445k
  for (Decl *SubDecl : Function->decls()) {
591
445k
    if (isWhitelistedDecl(SubDecl, Function)) {
592
97.1k
      Decls.push_back(SubDecl);
593
97.1k
    }
594
445k
  }
595
191k
596
191k
  ID.AddInteger(Decls.size());
597
191k
  for (auto SubDecl : Decls) {
598
97.1k
    AddSubDecl(SubDecl);
599
97.1k
  }
600
191k
}
601
602
24.6k
void ODRHash::AddEnumDecl(const EnumDecl *Enum) {
603
24.6k
  assert(Enum);
604
24.6k
  AddDeclarationName(Enum->getDeclName());
605
24.6k
606
24.6k
  AddBoolean(Enum->isScoped());
607
24.6k
  if (Enum->isScoped())
608
307
    AddBoolean(Enum->isScopedUsingClassTag());
609
24.6k
610
24.6k
  if (Enum->getIntegerTypeSourceInfo())
611
6.75k
    AddQualType(Enum->getIntegerType());
612
24.6k
613
24.6k
  // Filter out sub-Decls which will not be processed in order to get an
614
24.6k
  // accurate count of Decl's.
615
24.6k
  llvm::SmallVector<const Decl *, 16> Decls;
616
176k
  for (Decl *SubDecl : Enum->decls()) {
617
176k
    if (isWhitelistedDecl(SubDecl, Enum)) {
618
176k
      assert(isa<EnumConstantDecl>(SubDecl) && "Unexpected Decl");
619
176k
      Decls.push_back(SubDecl);
620
176k
    }
621
176k
  }
622
24.6k
623
24.6k
  ID.AddInteger(Decls.size());
624
176k
  for (auto SubDecl : Decls) {
625
176k
    AddSubDecl(SubDecl);
626
176k
  }
627
24.6k
628
24.6k
}
629
630
5.02M
void ODRHash::AddDecl(const Decl *D) {
631
5.02M
  assert(D && "Expecting non-null pointer.");
632
5.02M
  D = D->getCanonicalDecl();
633
5.02M
634
5.02M
  const NamedDecl *ND = dyn_cast<NamedDecl>(D);
635
5.02M
  AddBoolean(ND);
636
5.02M
  if (!ND) {
637
2.07k
    ID.AddInteger(D->getKind());
638
2.07k
    return;
639
2.07k
  }
640
5.02M
641
5.02M
  AddDeclarationName(ND->getDeclName());
642
5.02M
643
5.02M
  const auto *Specialization =
644
5.02M
            dyn_cast<ClassTemplateSpecializationDecl>(D);
645
5.02M
  AddBoolean(Specialization);
646
5.02M
  if (Specialization) {
647
15.8k
    const TemplateArgumentList &List = Specialization->getTemplateArgs();
648
15.8k
    ID.AddInteger(List.size());
649
15.8k
    for (const TemplateArgument &TA : List.asArray())
650
28.3k
      AddTemplateArgument(TA);
651
15.8k
  }
652
5.02M
}
653
654
namespace {
655
// Process a Type pointer.  Add* methods call back into ODRHash while Visit*
656
// methods process the relevant parts of the Type.
657
class ODRTypeVisitor : public TypeVisitor<ODRTypeVisitor> {
658
  typedef TypeVisitor<ODRTypeVisitor> Inherited;
659
  llvm::FoldingSetNodeID &ID;
660
  ODRHash &Hash;
661
662
public:
663
  ODRTypeVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
664
6.18M
      : ID(ID), Hash(Hash) {}
665
666
5.10k
  void AddStmt(Stmt *S) {
667
5.10k
    Hash.AddBoolean(S);
668
5.10k
    if (S) {
669
5.09k
      Hash.AddStmt(S);
670
5.09k
    }
671
5.10k
  }
672
673
2.77M
  void AddDecl(Decl *D) {
674
2.77M
    Hash.AddBoolean(D);
675
2.77M
    if (D) {
676
2.77M
      Hash.AddDecl(D);
677
2.77M
    }
678
2.77M
  }
679
680
1.40M
  void AddQualType(QualType T) {
681
1.40M
    Hash.AddQualType(T);
682
1.40M
  }
683
684
1.63M
  void AddType(const Type *T) {
685
1.63M
    Hash.AddBoolean(T);
686
1.63M
    if (T) {
687
1.63M
      Hash.AddType(T);
688
1.63M
    }
689
1.63M
  }
690
691
352k
  void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
692
352k
    Hash.AddBoolean(NNS);
693
352k
    if (NNS) {
694
238k
      Hash.AddNestedNameSpecifier(NNS);
695
238k
    }
696
352k
  }
697
698
222k
  void AddIdentifierInfo(const IdentifierInfo *II) {
699
222k
    Hash.AddBoolean(II);
700
222k
    if (II) {
701
222k
      Hash.AddIdentifierInfo(II);
702
222k
    }
703
222k
  }
704
705
1.65M
  void VisitQualifiers(Qualifiers Quals) {
706
1.65M
    ID.AddInteger(Quals.getAsOpaqueValue());
707
1.65M
  }
708
709
  // Return the RecordType if the typedef only strips away a keyword.
710
  // Otherwise, return the original type.
711
6.18M
  static const Type *RemoveTypedef(const Type *T) {
712
6.18M
    const auto *TypedefT = dyn_cast<TypedefType>(T);
713
6.18M
    if (!TypedefT) {
714
4.53M
      return T;
715
4.53M
    }
716
1.65M
717
1.65M
    const TypedefNameDecl *D = TypedefT->getDecl();
718
1.65M
    QualType UnderlyingType = D->getUnderlyingType();
719
1.65M
720
1.65M
    if (UnderlyingType.hasLocalQualifiers()) {
721
147
      return T;
722
147
    }
723
1.65M
724
1.65M
    const auto *ElaboratedT = dyn_cast<ElaboratedType>(UnderlyingType);
725
1.65M
    if (!ElaboratedT) {
726
1.54M
      return T;
727
1.54M
    }
728
105k
729
105k
    if (ElaboratedT->getQualifier() != nullptr) {
730
14.7k
      return T;
731
14.7k
    }
732
90.9k
733
90.9k
    QualType NamedType = ElaboratedT->getNamedType();
734
90.9k
    if (NamedType.hasLocalQualifiers()) {
735
0
      return T;
736
0
    }
737
90.9k
738
90.9k
    const auto *RecordT = dyn_cast<RecordType>(NamedType);
739
90.9k
    if (!RecordT) {
740
8.22k
      return T;
741
8.22k
    }
742
82.6k
743
82.6k
    const IdentifierInfo *TypedefII = TypedefT->getDecl()->getIdentifier();
744
82.6k
    const IdentifierInfo *RecordII = RecordT->getDecl()->getIdentifier();
745
82.6k
    if (!TypedefII || !RecordII ||
746
82.6k
        
TypedefII->getName() != RecordII->getName()38.5k
) {
747
64.0k
      return T;
748
64.0k
    }
749
18.6k
750
18.6k
    return RecordT;
751
18.6k
  }
752
753
6.18M
  void Visit(const Type *T) {
754
6.18M
    T = RemoveTypedef(T);
755
6.18M
    ID.AddInteger(T->getTypeClass());
756
6.18M
    Inherited::Visit(T);
757
6.18M
  }
758
759
5.53M
  void VisitType(const Type *T) {}
760
761
4.79k
  void VisitAdjustedType(const AdjustedType *T) {
762
4.79k
    QualType Original = T->getOriginalType();
763
4.79k
    QualType Adjusted = T->getAdjustedType();
764
4.79k
765
4.79k
    // The original type and pointee type can be the same, as in the case of
766
4.79k
    // function pointers decaying to themselves.  Set a bool and only process
767
4.79k
    // the type once, to prevent doubling the work.
768
4.79k
    SplitQualType split = Adjusted.split();
769
4.79k
    if (auto Pointer = dyn_cast<PointerType>(split.Ty)) {
770
4.59k
      if (Pointer->getPointeeType() == Original) {
771
242
        Hash.AddBoolean(true);
772
242
        ID.AddInteger(split.Quals.getAsOpaqueValue());
773
242
        AddQualType(Original);
774
242
        VisitType(T);
775
242
        return;
776
242
      }
777
4.55k
    }
778
4.55k
779
4.55k
    // The original type and pointee type are different, such as in the case
780
4.55k
    // of a array decaying to an element pointer.  Set a bool to false and
781
4.55k
    // process both types.
782
4.55k
    Hash.AddBoolean(false);
783
4.55k
    AddQualType(Original);
784
4.55k
    AddQualType(Adjusted);
785
4.55k
786
4.55k
    VisitType(T);
787
4.55k
  }
788
789
4.79k
  void VisitDecayedType(const DecayedType *T) {
790
4.79k
    // getDecayedType and getPointeeType are derived from getAdjustedType
791
4.79k
    // and don't need to be separately processed.
792
4.79k
    VisitAdjustedType(T);
793
4.79k
  }
794
795
20.2k
  void VisitArrayType(const ArrayType *T) {
796
20.2k
    AddQualType(T->getElementType());
797
20.2k
    ID.AddInteger(T->getSizeModifier());
798
20.2k
    VisitQualifiers(T->getIndexTypeQualifiers());
799
20.2k
    VisitType(T);
800
20.2k
  }
801
15.9k
  void VisitConstantArrayType(const ConstantArrayType *T) {
802
15.9k
    T->getSize().Profile(ID);
803
15.9k
    VisitArrayType(T);
804
15.9k
  }
805
806
872
  void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
807
872
    AddStmt(T->getSizeExpr());
808
872
    VisitArrayType(T);
809
872
  }
810
811
2.14k
  void VisitIncompleteArrayType(const IncompleteArrayType *T) {
812
2.14k
    VisitArrayType(T);
813
2.14k
  }
814
815
1.19k
  void VisitVariableArrayType(const VariableArrayType *T) {
816
1.19k
    AddStmt(T->getSizeExpr());
817
1.19k
    VisitArrayType(T);
818
1.19k
  }
819
820
55.2k
  void VisitAttributedType(const AttributedType *T) {
821
55.2k
    ID.AddInteger(T->getAttrKind());
822
55.2k
    AddQualType(T->getModifiedType());
823
55.2k
    AddQualType(T->getEquivalentType());
824
55.2k
825
55.2k
    VisitType(T);
826
55.2k
  }
827
828
1.91k
  void VisitBlockPointerType(const BlockPointerType *T) {
829
1.91k
    AddQualType(T->getPointeeType());
830
1.91k
    VisitType(T);
831
1.91k
  }
832
833
1.46M
  void VisitBuiltinType(const BuiltinType *T) {
834
1.46M
    ID.AddInteger(T->getKind());
835
1.46M
    VisitType(T);
836
1.46M
  }
837
838
5.45k
  void VisitComplexType(const ComplexType *T) {
839
5.45k
    AddQualType(T->getElementType());
840
5.45k
    VisitType(T);
841
5.45k
  }
842
843
2.97k
  void VisitDecltypeType(const DecltypeType *T) {
844
2.97k
    AddStmt(T->getUnderlyingExpr());
845
2.97k
    AddQualType(T->getUnderlyingType());
846
2.97k
    VisitType(T);
847
2.97k
  }
848
849
0
  void VisitDependentDecltypeType(const DependentDecltypeType *T) {
850
0
    VisitDecltypeType(T);
851
0
  }
852
853
795
  void VisitDeducedType(const DeducedType *T) {
854
795
    AddQualType(T->getDeducedType());
855
795
    VisitType(T);
856
795
  }
857
858
789
  void VisitAutoType(const AutoType *T) {
859
789
    ID.AddInteger((unsigned)T->getKeyword());
860
789
    ID.AddInteger(T->isConstrained());
861
789
    if (T->isConstrained()) {
862
0
      AddDecl(T->getTypeConstraintConcept());
863
0
      ID.AddInteger(T->getNumArgs());
864
0
      for (const auto &TA : T->getTypeConstraintArguments())
865
0
        Hash.AddTemplateArgument(TA);
866
0
    }
867
789
    VisitDeducedType(T);
868
789
  }
869
870
  void VisitDeducedTemplateSpecializationType(
871
6
      const DeducedTemplateSpecializationType *T) {
872
6
    Hash.AddTemplateName(T->getTemplateName());
873
6
    VisitDeducedType(T);
874
6
  }
875
876
10
  void VisitDependentAddressSpaceType(const DependentAddressSpaceType *T) {
877
10
    AddQualType(T->getPointeeType());
878
10
    AddStmt(T->getAddrSpaceExpr());
879
10
    VisitType(T);
880
10
  }
881
882
6
  void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T) {
883
6
    AddQualType(T->getElementType());
884
6
    AddStmt(T->getSizeExpr());
885
6
    VisitType(T);
886
6
  }
887
888
25.7k
  void VisitFunctionType(const FunctionType *T) {
889
25.7k
    AddQualType(T->getReturnType());
890
25.7k
    T->getExtInfo().Profile(ID);
891
25.7k
    Hash.AddBoolean(T->isConst());
892
25.7k
    Hash.AddBoolean(T->isVolatile());
893
25.7k
    Hash.AddBoolean(T->isRestrict());
894
25.7k
    VisitType(T);
895
25.7k
  }
896
897
3
  void VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
898
3
    VisitFunctionType(T);
899
3
  }
900
901
25.7k
  void VisitFunctionProtoType(const FunctionProtoType *T) {
902
25.7k
    ID.AddInteger(T->getNumParams());
903
25.7k
    for (auto ParamType : T->getParamTypes())
904
65.1k
      AddQualType(ParamType);
905
25.7k
906
25.7k
    VisitFunctionType(T);
907
25.7k
  }
908
909
59.5k
  void VisitInjectedClassNameType(const InjectedClassNameType *T) {
910
59.5k
    AddDecl(T->getDecl());
911
59.5k
    VisitType(T);
912
59.5k
  }
913
914
827
  void VisitMemberPointerType(const MemberPointerType *T) {
915
827
    AddQualType(T->getPointeeType());
916
827
    AddType(T->getClass());
917
827
    VisitType(T);
918
827
  }
919
920
8.35k
  void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
921
8.35k
    AddQualType(T->getPointeeType());
922
8.35k
    VisitType(T);
923
8.35k
  }
924
925
8.38k
  void VisitObjCObjectType(const ObjCObjectType *T) {
926
8.38k
    AddDecl(T->getInterface());
927
8.38k
928
8.38k
    auto TypeArgs = T->getTypeArgsAsWritten();
929
8.38k
    ID.AddInteger(TypeArgs.size());
930
8.38k
    for (auto Arg : TypeArgs) {
931
52
      AddQualType(Arg);
932
52
    }
933
8.38k
934
8.38k
    auto Protocols = T->getProtocols();
935
8.38k
    ID.AddInteger(Protocols.size());
936
8.38k
    for (auto Protocol : Protocols) {
937
3.25k
      AddDecl(Protocol);
938
3.25k
    }
939
8.38k
940
8.38k
    Hash.AddBoolean(T->isKindOfType());
941
8.38k
942
8.38k
    VisitType(T);
943
8.38k
  }
944
945
1.89k
  void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
946
1.89k
    // This type is handled by the parent type ObjCObjectType.
947
1.89k
    VisitObjCObjectType(T);
948
1.89k
  }
949
950
8
  void VisitObjCTypeParamType(const ObjCTypeParamType *T) {
951
8
    AddDecl(T->getDecl());
952
8
    auto Protocols = T->getProtocols();
953
8
    ID.AddInteger(Protocols.size());
954
8
    for (auto Protocol : Protocols) {
955
7
      AddDecl(Protocol);
956
7
    }
957
8
958
8
    VisitType(T);
959
8
  }
960
961
6.92k
  void VisitPackExpansionType(const PackExpansionType *T) {
962
6.92k
    AddQualType(T->getPattern());
963
6.92k
    VisitType(T);
964
6.92k
  }
965
966
25.0k
  void VisitParenType(const ParenType *T) {
967
25.0k
    AddQualType(T->getInnerType());
968
25.0k
    VisitType(T);
969
25.0k
  }
970
971
12
  void VisitPipeType(const PipeType *T) {
972
12
    AddQualType(T->getElementType());
973
12
    Hash.AddBoolean(T->isReadOnly());
974
12
    VisitType(T);
975
12
  }
976
977
404k
  void VisitPointerType(const PointerType *T) {
978
404k
    AddQualType(T->getPointeeType());
979
404k
    VisitType(T);
980
404k
  }
981
982
147k
  void VisitReferenceType(const ReferenceType *T) {
983
147k
    AddQualType(T->getPointeeTypeAsWritten());
984
147k
    VisitType(T);
985
147k
  }
986
987
130k
  void VisitLValueReferenceType(const LValueReferenceType *T) {
988
130k
    VisitReferenceType(T);
989
130k
  }
990
991
17.2k
  void VisitRValueReferenceType(const RValueReferenceType *T) {
992
17.2k
    VisitReferenceType(T);
993
17.2k
  }
994
995
  void
996
0
  VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T) {
997
0
    AddType(T->getReplacedParameter());
998
0
    Hash.AddTemplateArgument(T->getArgumentPack());
999
0
    VisitType(T);
1000
0
  }
1001
1002
6.04k
  void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
1003
6.04k
    AddType(T->getReplacedParameter());
1004
6.04k
    AddQualType(T->getReplacementType());
1005
6.04k
    VisitType(T);
1006
6.04k
  }
1007
1008
425k
  void VisitTagType(const TagType *T) {
1009
425k
    AddDecl(T->getDecl());
1010
425k
    VisitType(T);
1011
425k
  }
1012
1013
326k
  void VisitRecordType(const RecordType *T) { VisitTagType(T); }
1014
98.4k
  void VisitEnumType(const EnumType *T) { VisitTagType(T); }
1015
1016
439k
  void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
1017
439k
    ID.AddInteger(T->getNumArgs());
1018
733k
    for (const auto &TA : T->template_arguments()) {
1019
733k
      Hash.AddTemplateArgument(TA);
1020
733k
    }
1021
439k
    Hash.AddTemplateName(T->getTemplateName());
1022
439k
    VisitType(T);
1023
439k
  }
1024
1025
650k
  void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
1026
650k
    ID.AddInteger(T->getDepth());
1027
650k
    ID.AddInteger(T->getIndex());
1028
650k
    Hash.AddBoolean(T->isParameterPack());
1029
650k
    AddDecl(T->getDecl());
1030
650k
  }
1031
1032
1.63M
  void VisitTypedefType(const TypedefType *T) {
1033
1.63M
    AddDecl(T->getDecl());
1034
1.63M
    QualType UnderlyingType = T->getDecl()->getUnderlyingType();
1035
1.63M
    VisitQualifiers(UnderlyingType.getQualifiers());
1036
1.98M
    while (true) {
1037
1.98M
      if (const TypedefType *Underlying =
1038
260k
              dyn_cast<TypedefType>(UnderlyingType.getTypePtr())) {
1039
260k
        UnderlyingType = Underlying->getDecl()->getUnderlyingType();
1040
260k
        continue;
1041
260k
      }
1042
1.72M
      if (const ElaboratedType *Underlying =
1043
96.2k
              dyn_cast<ElaboratedType>(UnderlyingType.getTypePtr())) {
1044
96.2k
        UnderlyingType = Underlying->getNamedType();
1045
96.2k
        continue;
1046
96.2k
      }
1047
1.63M
1048
1.63M
      break;
1049
1.63M
    }
1050
1.63M
    AddType(UnderlyingType.getTypePtr());
1051
1.63M
    VisitType(T);
1052
1.63M
  }
1053
1054
38
  void VisitTypeOfExprType(const TypeOfExprType *T) {
1055
38
    AddStmt(T->getUnderlyingExpr());
1056
38
    Hash.AddBoolean(T->isSugared());
1057
38
    if (T->isSugared())
1058
37
      AddQualType(T->desugar());
1059
38
1060
38
    VisitType(T);
1061
38
  }
1062
20
  void VisitTypeOfType(const TypeOfType *T) {
1063
20
    AddQualType(T->getUnderlyingType());
1064
20
    VisitType(T);
1065
20
  }
1066
1067
352k
  void VisitTypeWithKeyword(const TypeWithKeyword *T) {
1068
352k
    ID.AddInteger(T->getKeyword());
1069
352k
    VisitType(T);
1070
352k
  };
1071
1072
222k
  void VisitDependentNameType(const DependentNameType *T) {
1073
222k
    AddNestedNameSpecifier(T->getQualifier());
1074
222k
    AddIdentifierInfo(T->getIdentifier());
1075
222k
    VisitTypeWithKeyword(T);
1076
222k
  }
1077
1078
  void VisitDependentTemplateSpecializationType(
1079
228
      const DependentTemplateSpecializationType *T) {
1080
228
    AddIdentifierInfo(T->getIdentifier());
1081
228
    AddNestedNameSpecifier(T->getQualifier());
1082
228
    ID.AddInteger(T->getNumArgs());
1083
228
    for (const auto &TA : T->template_arguments()) {
1084
228
      Hash.AddTemplateArgument(TA);
1085
228
    }
1086
228
    VisitTypeWithKeyword(T);
1087
228
  }
1088
1089
129k
  void VisitElaboratedType(const ElaboratedType *T) {
1090
129k
    AddNestedNameSpecifier(T->getQualifier());
1091
129k
    AddQualType(T->getNamedType());
1092
129k
    VisitTypeWithKeyword(T);
1093
129k
  }
1094
1095
687
  void VisitUnaryTransformType(const UnaryTransformType *T) {
1096
687
    AddQualType(T->getUnderlyingType());
1097
687
    AddQualType(T->getBaseType());
1098
687
    VisitType(T);
1099
687
  }
1100
1101
223
  void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
1102
223
    AddDecl(T->getDecl());
1103
223
    VisitType(T);
1104
223
  }
1105
1106
437k
  void VisitVectorType(const VectorType *T) {
1107
437k
    AddQualType(T->getElementType());
1108
437k
    ID.AddInteger(T->getNumElements());
1109
437k
    ID.AddInteger(T->getVectorKind());
1110
437k
    VisitType(T);
1111
437k
  }
1112
1113
83.9k
  void VisitExtVectorType(const ExtVectorType * T) {
1114
83.9k
    VisitVectorType(T);
1115
83.9k
  }
1116
};
1117
} // namespace
1118
1119
6.18M
void ODRHash::AddType(const Type *T) {
1120
6.18M
  assert(T && "Expecting non-null pointer.");
1121
6.18M
  ODRTypeVisitor(ID, *this).Visit(T);
1122
6.18M
}
1123
1124
4.24M
void ODRHash::AddQualType(QualType T) {
1125
4.24M
  AddBoolean(T.isNull());
1126
4.24M
  if (T.isNull())
1127
1.77k
    return;
1128
4.24M
  SplitQualType split = T.split();
1129
4.24M
  ID.AddInteger(split.Quals.getAsOpaqueValue());
1130
4.24M
  AddType(split.Ty);
1131
4.24M
}
1132
1133
31.6M
void ODRHash::AddBoolean(bool Value) {
1134
31.6M
  Bools.push_back(Value);
1135
31.6M
}