ODRHash.cpp 35 KB

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