clang 19.0.0git
ODRHash.cpp
Go to the documentation of this file.
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
21
22using namespace clang;
23
24void ODRHash::AddStmt(const Stmt *S) {
25 assert(S && "Expecting non-null pointer.");
26 S->ProcessODRHash(ID, *this);
27}
28
30 assert(II && "Expecting non-null pointer.");
31 ID.AddString(II->getName());
32}
33
34void ODRHash::AddDeclarationName(DeclarationName Name, bool TreatAsDecl) {
35 if (TreatAsDecl)
36 // Matches the NamedDecl check in AddDecl
37 AddBoolean(true);
38
39 AddDeclarationNameImpl(Name);
40
41 if (TreatAsDecl)
42 // Matches the ClassTemplateSpecializationDecl check in AddDecl
43 AddBoolean(false);
44}
45
46void ODRHash::AddDeclarationNameImpl(DeclarationName Name) {
47 // Index all DeclarationName and use index numbers to refer to them.
48 auto Result = DeclNameMap.insert(std::make_pair(Name, DeclNameMap.size()));
49 ID.AddInteger(Result.first->second);
50 if (!Result.second) {
51 // If found in map, the DeclarationName has previously been processed.
52 return;
53 }
54
55 // First time processing each DeclarationName, also process its details.
56 AddBoolean(Name.isEmpty());
57 if (Name.isEmpty())
58 return;
59
60 auto Kind = Name.getNameKind();
61 ID.AddInteger(Kind);
62 switch (Kind) {
64 AddIdentifierInfo(Name.getAsIdentifierInfo());
65 break;
69 Selector S = Name.getObjCSelector();
70 AddBoolean(S.isNull());
71 AddBoolean(S.isKeywordSelector());
72 AddBoolean(S.isUnarySelector());
73 unsigned NumArgs = S.getNumArgs();
74 ID.AddInteger(NumArgs);
75 // Compare all selector slots. For selectors with arguments it means all arg
76 // slots. And if there are no arguments, compare the first-and-only slot.
77 unsigned SlotsToCheck = NumArgs > 0 ? NumArgs : 1;
78 for (unsigned i = 0; i < SlotsToCheck; ++i) {
79 const IdentifierInfo *II = S.getIdentifierInfoForSlot(i);
80 AddBoolean(II);
81 if (II) {
83 }
84 }
85 break;
86 }
89 AddQualType(Name.getCXXNameType());
90 break;
92 ID.AddInteger(Name.getCXXOverloadedOperator());
93 break;
95 AddIdentifierInfo(Name.getCXXLiteralIdentifier());
96 break;
98 AddQualType(Name.getCXXNameType());
99 break;
101 break;
103 auto *Template = Name.getCXXDeductionGuideTemplate();
104 AddBoolean(Template);
105 if (Template) {
106 AddDecl(Template);
107 }
108 }
109 }
110}
111
113 assert(NNS && "Expecting non-null pointer.");
114 const auto *Prefix = NNS->getPrefix();
115 AddBoolean(Prefix);
116 if (Prefix) {
118 }
119 auto Kind = NNS->getKind();
120 ID.AddInteger(Kind);
121 switch (Kind) {
124 break;
126 AddDecl(NNS->getAsNamespace());
127 break;
130 break;
133 AddType(NNS->getAsType());
134 break;
137 break;
138 }
139}
140
142 auto Kind = Name.getKind();
143 ID.AddInteger(Kind);
144
145 switch (Kind) {
147 AddDecl(Name.getAsTemplateDecl());
148 break;
149 // TODO: Support these cases.
157 break;
158 }
159}
160
162 const auto Kind = TA.getKind();
163 ID.AddInteger(Kind);
164
165 switch (Kind) {
167 llvm_unreachable("Expected valid TemplateArgument");
170 break;
172 AddDecl(TA.getAsDecl());
173 break;
175 ID.AddPointer(nullptr);
176 break;
178 // There are integrals (e.g.: _BitInt(128)) that cannot be represented as
179 // any builtin integral type, so we use the hash of APSInt instead.
180 TA.getAsIntegral().Profile(ID);
181 break;
182 }
186 break;
190 break;
192 AddStmt(TA.getAsExpr());
193 break;
195 ID.AddInteger(TA.pack_size());
196 for (auto SubTA : TA.pack_elements()) {
197 AddTemplateArgument(SubTA);
198 }
199 break;
200 }
201}
202
204 assert(TPL && "Expecting non-null pointer.");
205
206 ID.AddInteger(TPL->size());
207 for (auto *ND : TPL->asArray()) {
208 AddSubDecl(ND);
209 }
210}
211
213 DeclNameMap.clear();
214 Bools.clear();
215 ID.clear();
216}
217
219 // Append the bools to the end of the data segment backwards. This allows
220 // for the bools data to be compressed 32 times smaller compared to using
221 // ID.AddBoolean
222 const unsigned unsigned_bits = sizeof(unsigned) * CHAR_BIT;
223 const unsigned size = Bools.size();
224 const unsigned remainder = size % unsigned_bits;
225 const unsigned loops = size / unsigned_bits;
226 auto I = Bools.rbegin();
227 unsigned value = 0;
228 for (unsigned i = 0; i < remainder; ++i) {
229 value <<= 1;
230 value |= *I;
231 ++I;
232 }
233 ID.AddInteger(value);
234
235 for (unsigned i = 0; i < loops; ++i) {
236 value = 0;
237 for (unsigned j = 0; j < unsigned_bits; ++j) {
238 value <<= 1;
239 value |= *I;
240 ++I;
241 }
242 ID.AddInteger(value);
243 }
244
245 assert(I == Bools.rend());
246 Bools.clear();
247 return ID.ComputeHash();
248}
249
250namespace {
251// Process a Decl pointer. Add* methods call back into ODRHash while Visit*
252// methods process the relevant parts of the Decl.
253class ODRDeclVisitor : public ConstDeclVisitor<ODRDeclVisitor> {
254 typedef ConstDeclVisitor<ODRDeclVisitor> Inherited;
255 llvm::FoldingSetNodeID &ID;
256 ODRHash &Hash;
257
258public:
259 ODRDeclVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
260 : ID(ID), Hash(Hash) {}
261
262 void AddStmt(const Stmt *S) {
263 Hash.AddBoolean(S);
264 if (S) {
265 Hash.AddStmt(S);
266 }
267 }
268
269 void AddIdentifierInfo(const IdentifierInfo *II) {
270 Hash.AddBoolean(II);
271 if (II) {
272 Hash.AddIdentifierInfo(II);
273 }
274 }
275
276 void AddQualType(QualType T) {
277 Hash.AddQualType(T);
278 }
279
280 void AddDecl(const Decl *D) {
281 Hash.AddBoolean(D);
282 if (D) {
283 Hash.AddDecl(D);
284 }
285 }
286
287 void AddTemplateArgument(TemplateArgument TA) {
288 Hash.AddTemplateArgument(TA);
289 }
290
291 void Visit(const Decl *D) {
292 ID.AddInteger(D->getKind());
293 Inherited::Visit(D);
294 }
295
296 void VisitNamedDecl(const NamedDecl *D) {
298 Inherited::VisitNamedDecl(D);
299 }
300
301 void VisitValueDecl(const ValueDecl *D) {
302 if (auto *DD = dyn_cast<DeclaratorDecl>(D); DD && DD->getTypeSourceInfo())
303 AddQualType(DD->getTypeSourceInfo()->getType());
304
305 Inherited::VisitValueDecl(D);
306 }
307
308 void VisitVarDecl(const VarDecl *D) {
309 Hash.AddBoolean(D->isStaticLocal());
310 Hash.AddBoolean(D->isConstexpr());
311 const bool HasInit = D->hasInit();
312 Hash.AddBoolean(HasInit);
313 if (HasInit) {
314 AddStmt(D->getInit());
315 }
316 Inherited::VisitVarDecl(D);
317 }
318
319 void VisitParmVarDecl(const ParmVarDecl *D) {
320 // TODO: Handle default arguments.
321 Inherited::VisitParmVarDecl(D);
322 }
323
324 void VisitAccessSpecDecl(const AccessSpecDecl *D) {
325 ID.AddInteger(D->getAccess());
326 Inherited::VisitAccessSpecDecl(D);
327 }
328
329 void VisitStaticAssertDecl(const StaticAssertDecl *D) {
330 AddStmt(D->getAssertExpr());
331 AddStmt(D->getMessage());
332
333 Inherited::VisitStaticAssertDecl(D);
334 }
335
336 void VisitFieldDecl(const FieldDecl *D) {
337 const bool IsBitfield = D->isBitField();
338 Hash.AddBoolean(IsBitfield);
339
340 if (IsBitfield) {
341 AddStmt(D->getBitWidth());
342 }
343
344 Hash.AddBoolean(D->isMutable());
345 AddStmt(D->getInClassInitializer());
346
347 Inherited::VisitFieldDecl(D);
348 }
349
350 void VisitObjCIvarDecl(const ObjCIvarDecl *D) {
351 ID.AddInteger(D->getCanonicalAccessControl());
352 Inherited::VisitObjCIvarDecl(D);
353 }
354
355 void VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
356 ID.AddInteger(D->getPropertyAttributes());
357 ID.AddInteger(D->getPropertyImplementation());
358 AddQualType(D->getTypeSourceInfo()->getType());
359 AddDecl(D);
360
361 Inherited::VisitObjCPropertyDecl(D);
362 }
363
364 void VisitFunctionDecl(const FunctionDecl *D) {
365 // Handled by the ODRHash for FunctionDecl
366 ID.AddInteger(D->getODRHash());
367
368 Inherited::VisitFunctionDecl(D);
369 }
370
371 void VisitCXXMethodDecl(const CXXMethodDecl *D) {
372 // Handled by the ODRHash for FunctionDecl
373
374 Inherited::VisitCXXMethodDecl(D);
375 }
376
377 void VisitObjCMethodDecl(const ObjCMethodDecl *Method) {
378 ID.AddInteger(Method->getDeclKind());
379 Hash.AddBoolean(Method->isInstanceMethod()); // false if class method
380 Hash.AddBoolean(Method->isVariadic());
382 Hash.AddBoolean(Method->isDefined());
383 Hash.AddBoolean(Method->isDirectMethod());
385 Hash.AddBoolean(Method->hasSkippedBody());
386
387 ID.AddInteger(llvm::to_underlying(Method->getImplementationControl()));
388 ID.AddInteger(Method->getMethodFamily());
389 ImplicitParamDecl *Cmd = Method->getCmdDecl();
390 Hash.AddBoolean(Cmd);
391 if (Cmd)
392 ID.AddInteger(llvm::to_underlying(Cmd->getParameterKind()));
393
395 Hash.AddBoolean(Self);
396 if (Self)
397 ID.AddInteger(llvm::to_underlying(Self->getParameterKind()));
398
399 AddDecl(Method);
400
401 if (Method->getReturnTypeSourceInfo())
402 AddQualType(Method->getReturnTypeSourceInfo()->getType());
403
404 ID.AddInteger(Method->param_size());
405 for (auto Param : Method->parameters())
406 Hash.AddSubDecl(Param);
407
408 if (Method->hasBody()) {
409 const bool IsDefinition = Method->isThisDeclarationADefinition();
410 Hash.AddBoolean(IsDefinition);
411 if (IsDefinition) {
412 Stmt *Body = Method->getBody();
413 Hash.AddBoolean(Body);
414 if (Body)
415 AddStmt(Body);
416
417 // Filter out sub-Decls which will not be processed in order to get an
418 // accurate count of Decl's.
420 for (Decl *SubDecl : Method->decls())
421 if (ODRHash::isSubDeclToBeProcessed(SubDecl, Method))
422 Decls.push_back(SubDecl);
423
424 ID.AddInteger(Decls.size());
425 for (auto SubDecl : Decls)
426 Hash.AddSubDecl(SubDecl);
427 }
428 } else {
429 Hash.AddBoolean(false);
430 }
431
432 Inherited::VisitObjCMethodDecl(Method);
433 }
434
435 void VisitTypedefNameDecl(const TypedefNameDecl *D) {
436 AddQualType(D->getUnderlyingType());
437
438 Inherited::VisitTypedefNameDecl(D);
439 }
440
441 void VisitTypedefDecl(const TypedefDecl *D) {
442 Inherited::VisitTypedefDecl(D);
443 }
444
445 void VisitTypeAliasDecl(const TypeAliasDecl *D) {
446 Inherited::VisitTypeAliasDecl(D);
447 }
448
449 void VisitFriendDecl(const FriendDecl *D) {
450 TypeSourceInfo *TSI = D->getFriendType();
451 Hash.AddBoolean(TSI);
452 if (TSI) {
453 AddQualType(TSI->getType());
454 } else {
455 AddDecl(D->getFriendDecl());
456 }
457 }
458
459 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
460 // Only care about default arguments as part of the definition.
461 const bool hasDefaultArgument =
463 Hash.AddBoolean(hasDefaultArgument);
464 if (hasDefaultArgument) {
465 AddTemplateArgument(D->getDefaultArgument());
466 }
467 Hash.AddBoolean(D->isParameterPack());
468
469 const TypeConstraint *TC = D->getTypeConstraint();
470 Hash.AddBoolean(TC != nullptr);
471 if (TC)
473
474 Inherited::VisitTemplateTypeParmDecl(D);
475 }
476
477 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
478 // Only care about default arguments as part of the definition.
479 const bool hasDefaultArgument =
481 Hash.AddBoolean(hasDefaultArgument);
482 if (hasDefaultArgument) {
483 AddStmt(D->getDefaultArgument());
484 }
485 Hash.AddBoolean(D->isParameterPack());
486
487 Inherited::VisitNonTypeTemplateParmDecl(D);
488 }
489
490 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) {
491 // Only care about default arguments as part of the definition.
492 const bool hasDefaultArgument =
494 Hash.AddBoolean(hasDefaultArgument);
495 if (hasDefaultArgument) {
496 AddTemplateArgument(D->getDefaultArgument().getArgument());
497 }
498 Hash.AddBoolean(D->isParameterPack());
499
500 Inherited::VisitTemplateTemplateParmDecl(D);
501 }
502
503 void VisitTemplateDecl(const TemplateDecl *D) {
505
506 Inherited::VisitTemplateDecl(D);
507 }
508
509 void VisitRedeclarableTemplateDecl(const RedeclarableTemplateDecl *D) {
511 Inherited::VisitRedeclarableTemplateDecl(D);
512 }
513
514 void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
515 AddDecl(D->getTemplatedDecl());
516 ID.AddInteger(D->getTemplatedDecl()->getODRHash());
517 Inherited::VisitFunctionTemplateDecl(D);
518 }
519
520 void VisitEnumConstantDecl(const EnumConstantDecl *D) {
521 AddStmt(D->getInitExpr());
522 Inherited::VisitEnumConstantDecl(D);
523 }
524};
525} // namespace
526
527// Only allow a small portion of Decl's to be processed. Remove this once
528// all Decl's can be handled.
530 if (D->isImplicit()) return false;
531 if (D->getDeclContext() != Parent) return false;
532
533 switch (D->getKind()) {
534 default:
535 return false;
536 case Decl::AccessSpec:
537 case Decl::CXXConstructor:
538 case Decl::CXXDestructor:
539 case Decl::CXXMethod:
540 case Decl::EnumConstant: // Only found in EnumDecl's.
541 case Decl::Field:
542 case Decl::Friend:
543 case Decl::FunctionTemplate:
544 case Decl::StaticAssert:
545 case Decl::TypeAlias:
546 case Decl::Typedef:
547 case Decl::Var:
548 case Decl::ObjCMethod:
549 case Decl::ObjCIvar:
550 case Decl::ObjCProperty:
551 return true;
552 }
553}
554
555void ODRHash::AddSubDecl(const Decl *D) {
556 assert(D && "Expecting non-null pointer.");
557
558 ODRDeclVisitor(ID, *this).Visit(D);
559}
560
562 assert(Record && Record->hasDefinition() &&
563 "Expected non-null record to be a definition.");
564
565 const DeclContext *DC = Record;
566 while (DC) {
567 if (isa<ClassTemplateSpecializationDecl>(DC)) {
568 return;
569 }
570 DC = DC->getParent();
571 }
572
573 AddDecl(Record);
574
575 // Filter out sub-Decls which will not be processed in order to get an
576 // accurate count of Decl's.
578 for (Decl *SubDecl : Record->decls()) {
579 if (isSubDeclToBeProcessed(SubDecl, Record)) {
580 Decls.push_back(SubDecl);
581 if (auto *Function = dyn_cast<FunctionDecl>(SubDecl)) {
582 // Compute/Preload ODRHash into FunctionDecl.
583 Function->getODRHash();
584 }
585 }
586 }
587
588 ID.AddInteger(Decls.size());
589 for (auto SubDecl : Decls) {
590 AddSubDecl(SubDecl);
591 }
592
593 const ClassTemplateDecl *TD = Record->getDescribedClassTemplate();
594 AddBoolean(TD);
595 if (TD) {
597 }
598
599 ID.AddInteger(Record->getNumBases());
600 auto Bases = Record->bases();
601 for (const auto &Base : Bases) {
602 AddQualType(Base.getTypeSourceInfo()->getType());
603 ID.AddInteger(Base.isVirtual());
604 ID.AddInteger(Base.getAccessSpecifierAsWritten());
605 }
606}
607
609 assert(!isa<CXXRecordDecl>(Record) &&
610 "For CXXRecordDecl should call AddCXXRecordDecl.");
611 AddDecl(Record);
612
613 // Filter out sub-Decls which will not be processed in order to get an
614 // accurate count of Decl's.
616 for (Decl *SubDecl : Record->decls()) {
617 if (isSubDeclToBeProcessed(SubDecl, Record))
618 Decls.push_back(SubDecl);
619 }
620
621 ID.AddInteger(Decls.size());
622 for (const Decl *SubDecl : Decls)
623 AddSubDecl(SubDecl);
624}
625
627 AddDecl(IF);
628
629 auto *SuperClass = IF->getSuperClass();
630 AddBoolean(SuperClass);
631 if (SuperClass)
632 ID.AddInteger(SuperClass->getODRHash());
633
634 // Hash referenced protocols.
635 ID.AddInteger(IF->getReferencedProtocols().size());
636 for (const ObjCProtocolDecl *RefP : IF->protocols()) {
637 // Hash the name only as a referenced protocol can be a forward declaration.
638 AddDeclarationName(RefP->getDeclName());
639 }
640
641 // Filter out sub-Decls which will not be processed in order to get an
642 // accurate count of Decl's.
644 for (Decl *SubDecl : IF->decls())
645 if (isSubDeclToBeProcessed(SubDecl, IF))
646 Decls.push_back(SubDecl);
647
648 ID.AddInteger(Decls.size());
649 for (auto *SubDecl : Decls)
650 AddSubDecl(SubDecl);
651}
652
654 bool SkipBody) {
655 assert(Function && "Expecting non-null pointer.");
656
657 // Skip functions that are specializations or in specialization context.
658 const DeclContext *DC = Function;
659 while (DC) {
660 if (isa<ClassTemplateSpecializationDecl>(DC)) return;
661 if (auto *F = dyn_cast<FunctionDecl>(DC)) {
662 if (F->isFunctionTemplateSpecialization()) {
663 if (!isa<CXXMethodDecl>(DC)) return;
664 if (DC->getLexicalParent()->isFileContext()) return;
665 // Skip class scope explicit function template specializations,
666 // as they have not yet been instantiated.
667 if (F->getDependentSpecializationInfo())
668 return;
669 // Inline method specializations are the only supported
670 // specialization for now.
671 }
672 }
673 DC = DC->getParent();
674 }
675
676 ID.AddInteger(Function->getDeclKind());
677
678 const auto *SpecializationArgs = Function->getTemplateSpecializationArgs();
679 AddBoolean(SpecializationArgs);
680 if (SpecializationArgs) {
681 ID.AddInteger(SpecializationArgs->size());
682 for (const TemplateArgument &TA : SpecializationArgs->asArray()) {
684 }
685 }
686
687 if (const auto *Method = dyn_cast<CXXMethodDecl>(Function)) {
688 AddBoolean(Method->isConst());
689 AddBoolean(Method->isVolatile());
690 }
691
692 ID.AddInteger(Function->getStorageClass());
693 AddBoolean(Function->isInlineSpecified());
694 AddBoolean(Function->isVirtualAsWritten());
695 AddBoolean(Function->isPureVirtual());
696 AddBoolean(Function->isDeletedAsWritten());
697 AddBoolean(Function->isExplicitlyDefaulted());
698
700
701 AddQualType(Function->getReturnType());
702
703 ID.AddInteger(Function->param_size());
704 for (auto *Param : Function->parameters())
705 AddSubDecl(Param);
706
707 if (SkipBody) {
708 AddBoolean(false);
709 return;
710 }
711
712 const bool HasBody = Function->isThisDeclarationADefinition() &&
713 !Function->isDefaulted() && !Function->isDeleted() &&
714 !Function->isLateTemplateParsed();
715 AddBoolean(HasBody);
716 if (!HasBody) {
717 return;
718 }
719
720 auto *Body = Function->getBody();
721 AddBoolean(Body);
722 if (Body)
723 AddStmt(Body);
724
725 // Filter out sub-Decls which will not be processed in order to get an
726 // accurate count of Decl's.
728 for (Decl *SubDecl : Function->decls()) {
729 if (isSubDeclToBeProcessed(SubDecl, Function)) {
730 Decls.push_back(SubDecl);
731 }
732 }
733
734 ID.AddInteger(Decls.size());
735 for (auto SubDecl : Decls) {
736 AddSubDecl(SubDecl);
737 }
738}
739
741 assert(Enum);
742 AddDeclarationName(Enum->getDeclName());
743
744 AddBoolean(Enum->isScoped());
745 if (Enum->isScoped())
746 AddBoolean(Enum->isScopedUsingClassTag());
747
748 if (Enum->getIntegerTypeSourceInfo())
749 AddQualType(Enum->getIntegerType().getCanonicalType());
750
751 // Filter out sub-Decls which will not be processed in order to get an
752 // accurate count of Decl's.
754 for (Decl *SubDecl : Enum->decls()) {
755 if (isSubDeclToBeProcessed(SubDecl, Enum)) {
756 assert(isa<EnumConstantDecl>(SubDecl) && "Unexpected Decl");
757 Decls.push_back(SubDecl);
758 }
759 }
760
761 ID.AddInteger(Decls.size());
762 for (auto SubDecl : Decls) {
763 AddSubDecl(SubDecl);
764 }
765
766}
767
769 AddDecl(P);
770
771 // Hash referenced protocols.
772 ID.AddInteger(P->getReferencedProtocols().size());
773 for (const ObjCProtocolDecl *RefP : P->protocols()) {
774 // Hash the name only as a referenced protocol can be a forward declaration.
775 AddDeclarationName(RefP->getDeclName());
776 }
777
778 // Filter out sub-Decls which will not be processed in order to get an
779 // accurate count of Decl's.
781 for (Decl *SubDecl : P->decls()) {
782 if (isSubDeclToBeProcessed(SubDecl, P)) {
783 Decls.push_back(SubDecl);
784 }
785 }
786
787 ID.AddInteger(Decls.size());
788 for (auto *SubDecl : Decls) {
789 AddSubDecl(SubDecl);
790 }
791}
792
793void ODRHash::AddDecl(const Decl *D) {
794 assert(D && "Expecting non-null pointer.");
795 D = D->getCanonicalDecl();
796
797 const NamedDecl *ND = dyn_cast<NamedDecl>(D);
798 AddBoolean(ND);
799 if (!ND) {
800 ID.AddInteger(D->getKind());
801 return;
802 }
803
805
806 const auto *Specialization =
807 dyn_cast<ClassTemplateSpecializationDecl>(D);
809 if (Specialization) {
810 const TemplateArgumentList &List = Specialization->getTemplateArgs();
811 ID.AddInteger(List.size());
812 for (const TemplateArgument &TA : List.asArray())
814 }
815}
816
817namespace {
818// Process a Type pointer. Add* methods call back into ODRHash while Visit*
819// methods process the relevant parts of the Type.
820class ODRTypeVisitor : public TypeVisitor<ODRTypeVisitor> {
821 typedef TypeVisitor<ODRTypeVisitor> Inherited;
822 llvm::FoldingSetNodeID &ID;
823 ODRHash &Hash;
824
825public:
826 ODRTypeVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
827 : ID(ID), Hash(Hash) {}
828
829 void AddStmt(Stmt *S) {
830 Hash.AddBoolean(S);
831 if (S) {
832 Hash.AddStmt(S);
833 }
834 }
835
836 void AddDecl(const Decl *D) {
837 Hash.AddBoolean(D);
838 if (D) {
839 Hash.AddDecl(D);
840 }
841 }
842
843 void AddQualType(QualType T) {
844 Hash.AddQualType(T);
845 }
846
847 void AddType(const Type *T) {
848 Hash.AddBoolean(T);
849 if (T) {
850 Hash.AddType(T);
851 }
852 }
853
854 void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
855 Hash.AddBoolean(NNS);
856 if (NNS) {
857 Hash.AddNestedNameSpecifier(NNS);
858 }
859 }
860
861 void AddIdentifierInfo(const IdentifierInfo *II) {
862 Hash.AddBoolean(II);
863 if (II) {
864 Hash.AddIdentifierInfo(II);
865 }
866 }
867
868 void VisitQualifiers(Qualifiers Quals) {
869 ID.AddInteger(Quals.getAsOpaqueValue());
870 }
871
872 // Return the RecordType if the typedef only strips away a keyword.
873 // Otherwise, return the original type.
874 static const Type *RemoveTypedef(const Type *T) {
875 const auto *TypedefT = dyn_cast<TypedefType>(T);
876 if (!TypedefT) {
877 return T;
878 }
879
880 const TypedefNameDecl *D = TypedefT->getDecl();
881 QualType UnderlyingType = D->getUnderlyingType();
882
883 if (UnderlyingType.hasLocalQualifiers()) {
884 return T;
885 }
886
887 const auto *ElaboratedT = dyn_cast<ElaboratedType>(UnderlyingType);
888 if (!ElaboratedT) {
889 return T;
890 }
891
892 if (ElaboratedT->getQualifier() != nullptr) {
893 return T;
894 }
895
896 QualType NamedType = ElaboratedT->getNamedType();
897 if (NamedType.hasLocalQualifiers()) {
898 return T;
899 }
900
901 const auto *RecordT = dyn_cast<RecordType>(NamedType);
902 if (!RecordT) {
903 return T;
904 }
905
906 const IdentifierInfo *TypedefII = TypedefT->getDecl()->getIdentifier();
907 const IdentifierInfo *RecordII = RecordT->getDecl()->getIdentifier();
908 if (!TypedefII || !RecordII ||
909 TypedefII->getName() != RecordII->getName()) {
910 return T;
911 }
912
913 return RecordT;
914 }
915
916 void Visit(const Type *T) {
917 T = RemoveTypedef(T);
918 ID.AddInteger(T->getTypeClass());
919 Inherited::Visit(T);
920 }
921
922 void VisitType(const Type *T) {}
923
924 void VisitAdjustedType(const AdjustedType *T) {
925 AddQualType(T->getOriginalType());
926
927 VisitType(T);
928 }
929
930 void VisitDecayedType(const DecayedType *T) {
931 // getDecayedType and getPointeeType are derived from getAdjustedType
932 // and don't need to be separately processed.
933 VisitAdjustedType(T);
934 }
935
936 void VisitArrayType(const ArrayType *T) {
937 AddQualType(T->getElementType());
938 ID.AddInteger(llvm::to_underlying(T->getSizeModifier()));
939 VisitQualifiers(T->getIndexTypeQualifiers());
940 VisitType(T);
941 }
942 void VisitConstantArrayType(const ConstantArrayType *T) {
943 T->getSize().Profile(ID);
944 VisitArrayType(T);
945 }
946
947 void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
948 AddStmt(T->getSizeExpr());
949 VisitArrayType(T);
950 }
951
952 void VisitIncompleteArrayType(const IncompleteArrayType *T) {
953 VisitArrayType(T);
954 }
955
956 void VisitVariableArrayType(const VariableArrayType *T) {
957 AddStmt(T->getSizeExpr());
958 VisitArrayType(T);
959 }
960
961 void VisitAttributedType(const AttributedType *T) {
962 ID.AddInteger(T->getAttrKind());
963 AddQualType(T->getModifiedType());
964
965 VisitType(T);
966 }
967
968 void VisitBlockPointerType(const BlockPointerType *T) {
969 AddQualType(T->getPointeeType());
970 VisitType(T);
971 }
972
973 void VisitBuiltinType(const BuiltinType *T) {
974 ID.AddInteger(T->getKind());
975 VisitType(T);
976 }
977
978 void VisitComplexType(const ComplexType *T) {
979 AddQualType(T->getElementType());
980 VisitType(T);
981 }
982
983 void VisitDecltypeType(const DecltypeType *T) {
984 AddStmt(T->getUnderlyingExpr());
985 VisitType(T);
986 }
987
988 void VisitDependentDecltypeType(const DependentDecltypeType *T) {
989 VisitDecltypeType(T);
990 }
991
992 void VisitDeducedType(const DeducedType *T) {
993 AddQualType(T->getDeducedType());
994 VisitType(T);
995 }
996
997 void VisitAutoType(const AutoType *T) {
998 ID.AddInteger((unsigned)T->getKeyword());
999 ID.AddInteger(T->isConstrained());
1000 if (T->isConstrained()) {
1001 AddDecl(T->getTypeConstraintConcept());
1002 ID.AddInteger(T->getTypeConstraintArguments().size());
1003 for (const auto &TA : T->getTypeConstraintArguments())
1004 Hash.AddTemplateArgument(TA);
1005 }
1006 VisitDeducedType(T);
1007 }
1008
1009 void VisitDeducedTemplateSpecializationType(
1012 VisitDeducedType(T);
1013 }
1014
1015 void VisitDependentAddressSpaceType(const DependentAddressSpaceType *T) {
1016 AddQualType(T->getPointeeType());
1017 AddStmt(T->getAddrSpaceExpr());
1018 VisitType(T);
1019 }
1020
1021 void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T) {
1022 AddQualType(T->getElementType());
1023 AddStmt(T->getSizeExpr());
1024 VisitType(T);
1025 }
1026
1027 void VisitFunctionType(const FunctionType *T) {
1028 AddQualType(T->getReturnType());
1029 T->getExtInfo().Profile(ID);
1030 Hash.AddBoolean(T->isConst());
1031 Hash.AddBoolean(T->isVolatile());
1032 Hash.AddBoolean(T->isRestrict());
1033 VisitType(T);
1034 }
1035
1036 void VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1037 VisitFunctionType(T);
1038 }
1039
1040 void VisitFunctionProtoType(const FunctionProtoType *T) {
1041 ID.AddInteger(T->getNumParams());
1042 for (auto ParamType : T->getParamTypes())
1043 AddQualType(ParamType);
1044
1045 VisitFunctionType(T);
1046 }
1047
1048 void VisitInjectedClassNameType(const InjectedClassNameType *T) {
1049 AddDecl(T->getDecl());
1050 VisitType(T);
1051 }
1052
1053 void VisitMemberPointerType(const MemberPointerType *T) {
1054 AddQualType(T->getPointeeType());
1055 AddType(T->getClass());
1056 VisitType(T);
1057 }
1058
1059 void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1060 AddQualType(T->getPointeeType());
1061 VisitType(T);
1062 }
1063
1064 void VisitObjCObjectType(const ObjCObjectType *T) {
1065 AddDecl(T->getInterface());
1066
1067 auto TypeArgs = T->getTypeArgsAsWritten();
1068 ID.AddInteger(TypeArgs.size());
1069 for (auto Arg : TypeArgs) {
1070 AddQualType(Arg);
1071 }
1072
1073 auto Protocols = T->getProtocols();
1074 ID.AddInteger(Protocols.size());
1075 for (auto *Protocol : Protocols) {
1076 AddDecl(Protocol);
1077 }
1078
1079 Hash.AddBoolean(T->isKindOfType());
1080
1081 VisitType(T);
1082 }
1083
1084 void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1085 // This type is handled by the parent type ObjCObjectType.
1086 VisitObjCObjectType(T);
1087 }
1088
1089 void VisitObjCTypeParamType(const ObjCTypeParamType *T) {
1090 AddDecl(T->getDecl());
1091 auto Protocols = T->getProtocols();
1092 ID.AddInteger(Protocols.size());
1093 for (auto *Protocol : Protocols) {
1094 AddDecl(Protocol);
1095 }
1096
1097 VisitType(T);
1098 }
1099
1100 void VisitPackExpansionType(const PackExpansionType *T) {
1101 AddQualType(T->getPattern());
1102 VisitType(T);
1103 }
1104
1105 void VisitParenType(const ParenType *T) {
1106 AddQualType(T->getInnerType());
1107 VisitType(T);
1108 }
1109
1110 void VisitPipeType(const PipeType *T) {
1111 AddQualType(T->getElementType());
1112 Hash.AddBoolean(T->isReadOnly());
1113 VisitType(T);
1114 }
1115
1116 void VisitPointerType(const PointerType *T) {
1117 AddQualType(T->getPointeeType());
1118 VisitType(T);
1119 }
1120
1121 void VisitReferenceType(const ReferenceType *T) {
1122 AddQualType(T->getPointeeTypeAsWritten());
1123 VisitType(T);
1124 }
1125
1126 void VisitLValueReferenceType(const LValueReferenceType *T) {
1127 VisitReferenceType(T);
1128 }
1129
1130 void VisitRValueReferenceType(const RValueReferenceType *T) {
1131 VisitReferenceType(T);
1132 }
1133
1134 void
1135 VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T) {
1136 AddDecl(T->getAssociatedDecl());
1138 VisitType(T);
1139 }
1140
1141 void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
1142 AddDecl(T->getAssociatedDecl());
1143 AddQualType(T->getReplacementType());
1144 VisitType(T);
1145 }
1146
1147 void VisitTagType(const TagType *T) {
1148 AddDecl(T->getDecl());
1149 VisitType(T);
1150 }
1151
1152 void VisitRecordType(const RecordType *T) { VisitTagType(T); }
1153 void VisitEnumType(const EnumType *T) { VisitTagType(T); }
1154
1155 void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
1156 ID.AddInteger(T->template_arguments().size());
1157 for (const auto &TA : T->template_arguments()) {
1158 Hash.AddTemplateArgument(TA);
1159 }
1161 VisitType(T);
1162 }
1163
1164 void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
1165 ID.AddInteger(T->getDepth());
1166 ID.AddInteger(T->getIndex());
1167 Hash.AddBoolean(T->isParameterPack());
1168 AddDecl(T->getDecl());
1169 }
1170
1171 void VisitTypedefType(const TypedefType *T) {
1172 AddDecl(T->getDecl());
1173 VisitType(T);
1174 }
1175
1176 void VisitTypeOfExprType(const TypeOfExprType *T) {
1177 AddStmt(T->getUnderlyingExpr());
1178 Hash.AddBoolean(T->isSugared());
1179
1180 VisitType(T);
1181 }
1182 void VisitTypeOfType(const TypeOfType *T) {
1183 AddQualType(T->getUnmodifiedType());
1184 VisitType(T);
1185 }
1186
1187 void VisitTypeWithKeyword(const TypeWithKeyword *T) {
1188 ID.AddInteger(llvm::to_underlying(T->getKeyword()));
1189 VisitType(T);
1190 };
1191
1192 void VisitDependentNameType(const DependentNameType *T) {
1193 AddNestedNameSpecifier(T->getQualifier());
1194 AddIdentifierInfo(T->getIdentifier());
1195 VisitTypeWithKeyword(T);
1196 }
1197
1198 void VisitDependentTemplateSpecializationType(
1200 AddIdentifierInfo(T->getIdentifier());
1201 AddNestedNameSpecifier(T->getQualifier());
1202 ID.AddInteger(T->template_arguments().size());
1203 for (const auto &TA : T->template_arguments()) {
1204 Hash.AddTemplateArgument(TA);
1205 }
1206 VisitTypeWithKeyword(T);
1207 }
1208
1209 void VisitElaboratedType(const ElaboratedType *T) {
1210 AddNestedNameSpecifier(T->getQualifier());
1211 AddQualType(T->getNamedType());
1212 VisitTypeWithKeyword(T);
1213 }
1214
1215 void VisitUnaryTransformType(const UnaryTransformType *T) {
1216 AddQualType(T->getUnderlyingType());
1217 AddQualType(T->getBaseType());
1218 VisitType(T);
1219 }
1220
1221 void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
1222 AddDecl(T->getDecl());
1223 VisitType(T);
1224 }
1225
1226 void VisitVectorType(const VectorType *T) {
1227 AddQualType(T->getElementType());
1228 ID.AddInteger(T->getNumElements());
1229 ID.AddInteger(llvm::to_underlying(T->getVectorKind()));
1230 VisitType(T);
1231 }
1232
1233 void VisitExtVectorType(const ExtVectorType * T) {
1234 VisitVectorType(T);
1235 }
1236};
1237} // namespace
1238
1239void ODRHash::AddType(const Type *T) {
1240 assert(T && "Expecting non-null pointer.");
1241 ODRTypeVisitor(ID, *this).Visit(T);
1242}
1243
1245 AddBoolean(T.isNull());
1246 if (T.isNull())
1247 return;
1248 SplitQualType split = T.split();
1249 ID.AddInteger(split.Quals.getAsOpaqueValue());
1250 AddType(split.Ty);
1251}
1252
1254 Bools.push_back(Value);
1255}
1256
1258 ID.AddInteger(Value.getKind());
1259
1260 // 'APValue::Profile' uses pointer values to make hash for LValue and
1261 // MemberPointer, but they differ from one compiler invocation to another.
1262 // So, handle them explicitly here.
1263
1264 switch (Value.getKind()) {
1265 case APValue::LValue: {
1266 const APValue::LValueBase &Base = Value.getLValueBase();
1267 if (!Base) {
1268 ID.AddInteger(Value.getLValueOffset().getQuantity());
1269 break;
1270 }
1271
1272 assert(Base.is<const ValueDecl *>());
1273 AddDecl(Base.get<const ValueDecl *>());
1274 ID.AddInteger(Value.getLValueOffset().getQuantity());
1275
1276 bool OnePastTheEnd = Value.isLValueOnePastTheEnd();
1277 if (Value.hasLValuePath()) {
1278 QualType TypeSoFar = Base.getType();
1279 for (APValue::LValuePathEntry E : Value.getLValuePath()) {
1280 if (const auto *AT = TypeSoFar->getAsArrayTypeUnsafe()) {
1281 if (const auto *CAT = dyn_cast<ConstantArrayType>(AT))
1282 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
1283 TypeSoFar = AT->getElementType();
1284 } else {
1285 const Decl *D = E.getAsBaseOrMember().getPointer();
1286 if (const auto *FD = dyn_cast<FieldDecl>(D)) {
1287 if (FD->getParent()->isUnion())
1288 ID.AddInteger(FD->getFieldIndex());
1289 TypeSoFar = FD->getType();
1290 } else {
1291 TypeSoFar =
1292 D->getASTContext().getRecordType(cast<CXXRecordDecl>(D));
1293 }
1294 }
1295 }
1296 }
1297 unsigned Val = 0;
1298 if (Value.isNullPointer())
1299 Val |= 1 << 0;
1300 if (OnePastTheEnd)
1301 Val |= 1 << 1;
1302 if (Value.hasLValuePath())
1303 Val |= 1 << 2;
1304 ID.AddInteger(Val);
1305 break;
1306 }
1308 const ValueDecl *D = Value.getMemberPointerDecl();
1309 assert(D);
1310 AddDecl(D);
1311 ID.AddInteger(
1313 break;
1314 }
1315 default:
1316 Value.Profile(ID);
1317 }
1318}
NodeId Parent
Definition: ASTDiff.cpp:191
StringRef P
static char ID
Definition: Arena.cpp:183
CompileCommand Cmd
This file contains the declaration of the ODRHash class, which calculates a hash based on AST nodes,...
A non-discriminated union of a base, field, or array index.
Definition: APValue.h:208
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
CharUnits getMemberPointerPathAdjustment(const APValue &MP) const
Find the 'this' offset for the member path in a pointer-to-member APValue.
QualType getRecordType(const RecordDecl *Decl) const
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:86
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:2926
QualType getOriginalType() const
Definition: Type.h:2939
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3146
ArraySizeModifier getSizeModifier() const
Definition: Type.h:3160
Qualifiers getIndexTypeQualifiers() const
Definition: Type.h:3164
QualType getElementType() const
Definition: Type.h:3158
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:5146
QualType getModifiedType() const
Definition: Type.h:5168
Kind getAttrKind() const
Definition: Type.h:5164
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:5523
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:5533
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:5538
AutoTypeKeyword getKeyword() const
Definition: Type.h:5554
bool isConstrained() const
Definition: Type.h:5542
Pointer to a block type.
Definition: Type.h:2977
QualType getPointeeType() const
Definition: Type.h:2989
This class is used for builtin types like 'int'.
Definition: Type.h:2739
Kind getKind() const
Definition: Type.h:2781
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2053
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:185
Declaration of a class template.
Complex values, per C99 6.2.5p11.
Definition: Type.h:2844
QualType getElementType() const
Definition: Type.h:2854
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:74
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3185
const llvm::APInt & getSize() const
Definition: Type.h:3206
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2960
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2066
bool isFileContext() const
Definition: DeclBase.h:2136
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
Definition: DeclBase.h:2082
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2321
Decl::Kind getDeclKind() const
Definition: DeclBase.h:2059
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:598
DeclContext * getDeclContext()
Definition: DeclBase.h:453
AccessSpecifier getAccess() const
Definition: DeclBase.h:512
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:968
Kind getKind() const
Definition: DeclBase.h:447
The name of a declaration.
Represents the type decltype(expr) (C++11).
Definition: Type.h:4900
Expr * getUnderlyingExpr() const
Definition: Type.h:4910
Represents a C++17 deduced template specialization type.
Definition: Type.h:5571
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
Definition: Type.h:5591
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Definition: Type.h:5489
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: Type.h:5510
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3401
Expr * getAddrSpaceExpr() const
Definition: Type.h:3412
QualType getPointeeType() const
Definition: Type.h:3413
Internal representation of canonical, dependent decltype(expr) types.
Definition: Type.h:4928
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:5994
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:6012
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:6019
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3343
Expr * getSizeExpr() const
Definition: Type.h:3363
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3441
QualType getElementType() const
Definition: Type.h:3456
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:6046
const IdentifierInfo * getIdentifier() const
Definition: Type.h:6063
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:6065
NestedNameSpecifier * getQualifier() const
Definition: Type.h:6062
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:5913
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:5948
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:5951
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3265
const Expr * getInitExpr() const
Definition: Decl.h:3283
Represents an enum.
Definition: Decl.h:3832
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5117
ExtVectorType - Extended vector type.
Definition: Type.h:3603
Represents a member of a struct/union/class.
Definition: Decl.h:3025
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:3113
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4527
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:3116
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition: Decl.h:3129
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition: DeclFriend.h:54
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition: DeclFriend.h:137
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:122
Represents a function declaration or definition.
Definition: Decl.h:1959
unsigned getODRHash()
Returns ODRHash of the function.
Definition: Decl.cpp:4481
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4153
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4198
unsigned getNumParams() const
Definition: Type.h:4431
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:4438
Declaration of a template function.
Definition: DeclTemplate.h:958
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:4028
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3798
ExtInfo getExtInfo() const
Definition: Type.h:4127
bool isConst() const
Definition: Type.h:4133
bool isRestrict() const
Definition: Type.h:4135
QualType getReturnType() const
Definition: Type.h:4115
bool isVolatile() const
Definition: Type.h:4134
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
Represents a C array with an unspecified size.
Definition: Type.h:3245
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:5763
CXXRecordDecl * getDecl() const
Definition: Type.cpp:4000
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3052
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3088
QualType getPointeeType() const
Definition: Type.h:3104
const Type * getClass() const
Definition: Type.h:3118
This represents a decl that may have a name.
Definition: Decl.h:249
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:315
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
void AddDecl(const Decl *D)
Definition: ODRHash.cpp:793
void AddStmt(const Stmt *S)
Definition: ODRHash.cpp:24
void AddStructuralValue(const APValue &)
Definition: ODRHash.cpp:1257
void AddCXXRecordDecl(const CXXRecordDecl *Record)
Definition: ODRHash.cpp:561
void clear()
Definition: ODRHash.cpp:212
void AddIdentifierInfo(const IdentifierInfo *II)
Definition: ODRHash.cpp:29
void AddObjCProtocolDecl(const ObjCProtocolDecl *P)
Definition: ODRHash.cpp:768
void AddDeclarationName(DeclarationName Name, bool TreatAsDecl=false)
Definition: ODRHash.cpp:34
void AddObjCInterfaceDecl(const ObjCInterfaceDecl *Record)
Definition: ODRHash.cpp:626
void AddType(const Type *T)
Definition: ODRHash.cpp:1239
void AddEnumDecl(const EnumDecl *Enum)
Definition: ODRHash.cpp:740
void AddNestedNameSpecifier(const NestedNameSpecifier *NNS)
Definition: ODRHash.cpp:112
void AddFunctionDecl(const FunctionDecl *Function, bool SkipBody=false)
Definition: ODRHash.cpp:653
void AddBoolean(bool value)
Definition: ODRHash.cpp:1253
void AddTemplateName(TemplateName Name)
Definition: ODRHash.cpp:141
void AddRecordDecl(const RecordDecl *Record)
Definition: ODRHash.cpp:608
void AddSubDecl(const Decl *D)
Definition: ODRHash.cpp:555
void AddQualType(QualType T)
Definition: ODRHash.cpp:1244
void AddTemplateParameterList(const TemplateParameterList *TPL)
Definition: ODRHash.cpp:203
void AddTemplateArgument(TemplateArgument TA)
Definition: ODRHash.cpp:161
unsigned CalculateHash()
Definition: ODRHash.cpp:218
static bool isSubDeclToBeProcessed(const Decl *D, const DeclContext *Parent)
Definition: ODRHash.cpp:529
Represents an ObjC class declaration.
Definition: DeclObjC.h:1150
protocol_range protocols() const
Definition: DeclObjC.h:1355
const ObjCProtocolList & getReferencedProtocols() const
Definition: DeclObjC.h:1330
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:351
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:6494
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1947
AccessControl getCanonicalAccessControl() const
Definition: DeclObjC.h:1998
unsigned size() const
Definition: DeclObjC.h:70
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
ImplicitParamDecl * getSelfDecl() const
Definition: DeclObjC.h:418
bool hasBody() const override
Determine whether this method has a body.
Definition: DeclObjC.h:523
ArrayRef< ParmVarDecl * > parameters() const
Definition: DeclObjC.h:373
unsigned param_size() const
Definition: DeclObjC.h:347
bool isVariadic() const
Definition: DeclObjC.h:431
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Definition: DeclObjC.cpp:909
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition: DeclObjC.h:343
bool isSynthesizedAccessorStub() const
Definition: DeclObjC.h:444
bool isDirectMethod() const
True if the method is tagged as objc_direct.
Definition: DeclObjC.cpp:871
ImplicitParamDecl * getCmdDecl() const
Definition: DeclObjC.h:420
bool isInstanceMethod() const
Definition: DeclObjC.h:426
bool isThisDeclarationADefinition() const
Returns whether this specific method is a definition.
Definition: DeclObjC.h:534
bool isThisDeclarationADesignatedInitializer() const
Returns true if this specific method declaration is marked with the designated initializer attribute.
Definition: DeclObjC.cpp:876
bool isDefined() const
Definition: DeclObjC.h:452
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
Definition: DeclObjC.cpp:1053
ObjCImplementationControl getImplementationControl() const
Definition: DeclObjC.h:500
bool hasSkippedBody() const
True if the method was a definition but its body was skipped.
Definition: DeclObjC.h:477
Represents a pointer to an Objective C object.
Definition: Type.h:6550
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:6562
Represents a class type in Objective C.
Definition: Type.h:6296
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:6406
bool isKindOfType() const
Whether this ia a "__kindof" type (semantically).
Definition: Type.cpp:814
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface.
Definition: Type.h:6529
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:729
TypeSourceInfo * getTypeSourceInfo() const
Definition: DeclObjC.h:798
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition: DeclObjC.h:811
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:908
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2079
ArrayRef< ObjCProtocolDecl * > getProtocols() const
Retrieve all of the protocol qualifiers.
Definition: Type.h:6213
Represents a type parameter type in Objective C.
Definition: Type.h:6222
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:6264
Represents a pack expansion of types.
Definition: Type.h:6111
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:6132
Sugar for parentheses used when specifying types.
Definition: Type.h:2871
QualType getInnerType() const
Definition: Type.h:2880
Represents a parameter to a function.
Definition: Decl.h:1749
PipeType - OpenCL20.
Definition: Type.h:6750
QualType getElementType() const
Definition: Type.h:6761
bool isReadOnly() const
Definition: Type.h:6780
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2897
QualType getPointeeType() const
Definition: Type.h:2907
A (possibly-)qualified type.
Definition: Type.h:737
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
Definition: Type.h:864
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:804
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:6922
The collection of all-type qualifiers we support.
Definition: Type.h:147
unsigned getAsOpaqueValue() const
Definition: Type.h:260
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3070
Represents a struct/union/class.
Definition: Decl.h:4133
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5091
Declaration of a redeclarable template.
Definition: DeclTemplate.h:717
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Definition: DeclTemplate.h:861
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3008
QualType getPointeeTypeAsWritten() const
Definition: Type.h:3024
Smart pointer class that efficiently represents Objective-C method names.
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:4051
Stmt - This represents one statement.
Definition: Stmt.h:84
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:5431
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: Type.cpp:4050
TemplateArgument getArgumentPack() const
Definition: Type.cpp:4067
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:5361
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: Type.h:5382
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:5373
TagDecl * getDecl() const
Definition: Type.cpp:3900
A template argument list.
Definition: DeclTemplate.h:244
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
Represents a template argument.
Definition: TemplateBase.h:61
QualType getStructuralValueType() const
Get the type of a StructuralValue.
Definition: TemplateBase.h:399
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:408
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:319
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:363
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:438
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:326
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:432
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
Definition: TemplateBase.h:350
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:396
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:394
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:413
Represents a C++ template name within the type system.
Definition: TemplateName.h:202
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
Definition: TemplateName.h:247
@ OverloadedTemplate
A set of overloaded template declarations.
Definition: TemplateName.h:222
@ Template
A single template declaration.
Definition: TemplateName.h:219
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:234
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:238
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
Definition: TemplateName.h:243
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
Definition: TemplateName.h:230
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
Definition: TemplateName.h:226
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:139
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:5631
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:5699
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:5697
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Declaration of a template type parameter.
QualType getDefaultArgument() const
Retrieve the default argument, if any.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
bool isParameterPack() const
Returns whether this is a parameter pack.
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:5324
bool isParameterPack() const
Definition: Type.h:5322
unsigned getIndex() const
Definition: Type.h:5321
unsigned getDepth() const
Definition: Type.h:5320
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3521
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition: ASTConcept.h:231
Expr * getImmediatelyDeclaredConstraint() const
Get the immediately-declared constraint expression introduced by this type-constraint,...
Definition: ASTConcept.h:246
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition: Type.h:4816
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.cpp:3769
Expr * getUnderlyingExpr() const
Definition: Type.h:4825
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:4864
QualType getUnmodifiedType() const
Definition: Type.h:4879
A container of type source information.
Definition: Type.h:6872
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6883
An operation on a type.
Definition: TypeVisitor.h:64
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition: Type.h:5862
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:5871
The base class of the type hierarchy.
Definition: Type.h:1606
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:7705
TypeClass getTypeClass() const
Definition: Type.h:2074
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3501
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3399
QualType getUnderlyingType() const
Definition: Decl.h:3454
TypedefNameDecl * getDecl() const
Definition: Type.h:4759
A unary type transform, which is a type constructed from another.
Definition: Type.h:5008
QualType getUnderlyingType() const
Definition: Type.h:5034
QualType getBaseType() const
Definition: Type.h:5035
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:4686
UnresolvedUsingTypenameDecl * getDecl() const
Definition: Type.h:4697
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:706
Kind getKind() const
Definition: Value.h:135
Represents a variable declaration or definition.
Definition: Decl.h:918
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1546
bool hasInit() const
Definition: Decl.cpp:2395
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
Definition: Decl.h:1192
const Expr * getInit() const
Definition: Decl.h:1352
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3289
Expr * getSizeExpr() const
Definition: Type.h:3308
Represents a GCC generic vector type.
Definition: Type.h:3511
unsigned getNumElements() const
Definition: Type.h:3526
VectorKind getVectorKind() const
Definition: Type.h:3531
QualType getElementType() const
Definition: Type.h:3525
#define CHAR_BIT
Definition: limits.h:67
The JSON file list parser is used to communicate input to InstallAPI.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
@ Result
The result type of a method or function.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:670
const Type * Ty
The locally-unqualified type.
Definition: Type.h:672
Qualifiers Quals
The local qualifiers.
Definition: Type.h:675
#define remainder(__x, __y)
Definition: tgmath.h:1090