clang  7.0.0svn
ODRHash.cpp
Go to the documentation of this file.
1 //===-- ODRHash.cpp - Hashing to diagnose ODR failures ----------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file implements the ODRHash class, which calculates a hash based
12 /// on AST nodes, which is stable across different runs.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #include "clang/AST/ODRHash.h"
17 
18 #include "clang/AST/DeclVisitor.h"
20 #include "clang/AST/StmtVisitor.h"
21 #include "clang/AST/TypeVisitor.h"
22 
23 using namespace clang;
24 
25 void ODRHash::AddStmt(const Stmt *S) {
26  assert(S && "Expecting non-null pointer.");
27  S->ProcessODRHash(ID, *this);
28 }
29 
31  assert(II && "Expecting non-null pointer.");
32  ID.AddString(II->getName());
33 }
34 
36  // Index all DeclarationName and use index numbers to refer to them.
37  auto Result = DeclNameMap.insert(std::make_pair(Name, DeclNameMap.size()));
38  ID.AddInteger(Result.first->second);
39  if (!Result.second) {
40  // If found in map, the the DeclarationName has previously been processed.
41  return;
42  }
43 
44  // First time processing each DeclarationName, also process its details.
45  AddBoolean(Name.isEmpty());
46  if (Name.isEmpty())
47  return;
48 
49  auto Kind = Name.getNameKind();
50  ID.AddInteger(Kind);
51  switch (Kind) {
54  break;
58  Selector S = Name.getObjCSelector();
59  AddBoolean(S.isNull());
62  unsigned NumArgs = S.getNumArgs();
63  for (unsigned i = 0; i < NumArgs; ++i) {
65  }
66  break;
67  }
71  break;
73  ID.AddInteger(Name.getCXXOverloadedOperator());
74  break;
77  break;
80  break;
82  break;
84  auto *Template = Name.getCXXDeductionGuideTemplate();
85  AddBoolean(Template);
86  if (Template) {
87  AddDecl(Template);
88  }
89  }
90  }
91 }
92 
94  assert(NNS && "Expecting non-null pointer.");
95  const auto *Prefix = NNS->getPrefix();
96  AddBoolean(Prefix);
97  if (Prefix) {
98  AddNestedNameSpecifier(Prefix);
99  }
100  auto Kind = NNS->getKind();
101  ID.AddInteger(Kind);
102  switch (Kind) {
105  break;
107  AddDecl(NNS->getAsNamespace());
108  break;
111  break;
114  AddType(NNS->getAsType());
115  break;
118  break;
119  }
120 }
121 
123  auto Kind = Name.getKind();
124  ID.AddInteger(Kind);
125 
126  switch (Kind) {
128  AddDecl(Name.getAsTemplateDecl());
129  break;
130  // TODO: Support these cases.
136  break;
137  }
138 }
139 
141  const auto Kind = TA.getKind();
142  ID.AddInteger(Kind);
143 
144  switch (Kind) {
146  llvm_unreachable("Expected valid TemplateArgument");
148  AddQualType(TA.getAsType());
149  break;
151  AddDecl(TA.getAsDecl());
152  break;
155  break;
159  break;
161  AddStmt(TA.getAsExpr());
162  break;
164  ID.AddInteger(TA.pack_size());
165  for (auto SubTA : TA.pack_elements()) {
166  AddTemplateArgument(SubTA);
167  }
168  break;
169  }
170 }
171 
173  assert(TPL && "Expecting non-null pointer.");
174 
175  ID.AddInteger(TPL->size());
176  for (auto *ND : TPL->asArray()) {
177  AddSubDecl(ND);
178  }
179 }
180 
182  DeclNameMap.clear();
183  TypeMap.clear();
184  Bools.clear();
185  ID.clear();
186 }
187 
189  // Append the bools to the end of the data segment backwards. This allows
190  // for the bools data to be compressed 32 times smaller compared to using
191  // ID.AddBoolean
192  const unsigned unsigned_bits = sizeof(unsigned) * CHAR_BIT;
193  const unsigned size = Bools.size();
194  const unsigned remainder = size % unsigned_bits;
195  const unsigned loops = size / unsigned_bits;
196  auto I = Bools.rbegin();
197  unsigned value = 0;
198  for (unsigned i = 0; i < remainder; ++i) {
199  value <<= 1;
200  value |= *I;
201  ++I;
202  }
203  ID.AddInteger(value);
204 
205  for (unsigned i = 0; i < loops; ++i) {
206  value = 0;
207  for (unsigned j = 0; j < unsigned_bits; ++j) {
208  value <<= 1;
209  value |= *I;
210  ++I;
211  }
212  ID.AddInteger(value);
213  }
214 
215  assert(I == Bools.rend());
216  Bools.clear();
217  return ID.ComputeHash();
218 }
219 
220 namespace {
221 // Process a Decl pointer. Add* methods call back into ODRHash while Visit*
222 // methods process the relevant parts of the Decl.
223 class ODRDeclVisitor : public ConstDeclVisitor<ODRDeclVisitor> {
224  typedef ConstDeclVisitor<ODRDeclVisitor> Inherited;
225  llvm::FoldingSetNodeID &ID;
226  ODRHash &Hash;
227 
228 public:
229  ODRDeclVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
230  : ID(ID), Hash(Hash) {}
231 
232  void AddStmt(const Stmt *S) {
233  Hash.AddBoolean(S);
234  if (S) {
235  Hash.AddStmt(S);
236  }
237  }
238 
239  void AddIdentifierInfo(const IdentifierInfo *II) {
240  Hash.AddBoolean(II);
241  if (II) {
242  Hash.AddIdentifierInfo(II);
243  }
244  }
245 
246  void AddQualType(QualType T) {
247  Hash.AddQualType(T);
248  }
249 
250  void AddDecl(const Decl *D) {
251  Hash.AddBoolean(D);
252  if (D) {
253  Hash.AddDecl(D);
254  }
255  }
256 
258  Hash.AddTemplateArgument(TA);
259  }
260 
261  void Visit(const Decl *D) {
262  ID.AddInteger(D->getKind());
263  Inherited::Visit(D);
264  }
265 
266  void VisitNamedDecl(const NamedDecl *D) {
267  Hash.AddDeclarationName(D->getDeclName());
268  Inherited::VisitNamedDecl(D);
269  }
270 
271  void VisitValueDecl(const ValueDecl *D) {
272  if (!isa<FunctionDecl>(D)) {
273  AddQualType(D->getType());
274  }
275  Inherited::VisitValueDecl(D);
276  }
277 
278  void VisitVarDecl(const VarDecl *D) {
279  Hash.AddBoolean(D->isStaticLocal());
280  Hash.AddBoolean(D->isConstexpr());
281  const bool HasInit = D->hasInit();
282  Hash.AddBoolean(HasInit);
283  if (HasInit) {
284  AddStmt(D->getInit());
285  }
286  Inherited::VisitVarDecl(D);
287  }
288 
289  void VisitParmVarDecl(const ParmVarDecl *D) {
290  // TODO: Handle default arguments.
291  Inherited::VisitParmVarDecl(D);
292  }
293 
294  void VisitAccessSpecDecl(const AccessSpecDecl *D) {
295  ID.AddInteger(D->getAccess());
296  Inherited::VisitAccessSpecDecl(D);
297  }
298 
299  void VisitStaticAssertDecl(const StaticAssertDecl *D) {
300  AddStmt(D->getAssertExpr());
301  AddStmt(D->getMessage());
302 
303  Inherited::VisitStaticAssertDecl(D);
304  }
305 
306  void VisitFieldDecl(const FieldDecl *D) {
307  const bool IsBitfield = D->isBitField();
308  Hash.AddBoolean(IsBitfield);
309 
310  if (IsBitfield) {
311  AddStmt(D->getBitWidth());
312  }
313 
314  Hash.AddBoolean(D->isMutable());
316 
317  Inherited::VisitFieldDecl(D);
318  }
319 
320  void VisitFunctionDecl(const FunctionDecl *D) {
321  ID.AddInteger(D->getStorageClass());
322  Hash.AddBoolean(D->isInlineSpecified());
323  Hash.AddBoolean(D->isVirtualAsWritten());
324  Hash.AddBoolean(D->isPure());
325  Hash.AddBoolean(D->isDeletedAsWritten());
326 
327  ID.AddInteger(D->param_size());
328 
329  for (auto *Param : D->parameters()) {
330  Hash.AddSubDecl(Param);
331  }
332 
334 
335  const auto* SpecializationArgs = D->getTemplateSpecializationArgs();
336  Hash.AddBoolean(SpecializationArgs);
337  if (SpecializationArgs) {
338  ID.AddInteger(SpecializationArgs->size());
339  for (const TemplateArgument &TA : SpecializationArgs->asArray()) {
340  Hash.AddTemplateArgument(TA);
341  }
342  }
343 
344  Inherited::VisitFunctionDecl(D);
345  }
346 
347  void VisitCXXMethodDecl(const CXXMethodDecl *D) {
348  Hash.AddBoolean(D->isConst());
349  Hash.AddBoolean(D->isVolatile());
350 
351  Inherited::VisitCXXMethodDecl(D);
352  }
353 
354  void VisitTypedefNameDecl(const TypedefNameDecl *D) {
356 
357  Inherited::VisitTypedefNameDecl(D);
358  }
359 
360  void VisitTypedefDecl(const TypedefDecl *D) {
361  Inherited::VisitTypedefDecl(D);
362  }
363 
364  void VisitTypeAliasDecl(const TypeAliasDecl *D) {
365  Inherited::VisitTypeAliasDecl(D);
366  }
367 
368  void VisitFriendDecl(const FriendDecl *D) {
369  TypeSourceInfo *TSI = D->getFriendType();
370  Hash.AddBoolean(TSI);
371  if (TSI) {
372  AddQualType(TSI->getType());
373  } else {
374  AddDecl(D->getFriendDecl());
375  }
376  }
377 
378  void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
379  // Only care about default arguments as part of the definition.
380  const bool hasDefaultArgument =
382  Hash.AddBoolean(hasDefaultArgument);
383  if (hasDefaultArgument) {
385  }
386  Hash.AddBoolean(D->isParameterPack());
387 
388  Inherited::VisitTemplateTypeParmDecl(D);
389  }
390 
391  void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
392  // Only care about default arguments as part of the definition.
393  const bool hasDefaultArgument =
395  Hash.AddBoolean(hasDefaultArgument);
396  if (hasDefaultArgument) {
398  }
399  Hash.AddBoolean(D->isParameterPack());
400 
401  Inherited::VisitNonTypeTemplateParmDecl(D);
402  }
403 
404  void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) {
405  // Only care about default arguments as part of the definition.
406  const bool hasDefaultArgument =
408  Hash.AddBoolean(hasDefaultArgument);
409  if (hasDefaultArgument) {
411  }
412  Hash.AddBoolean(D->isParameterPack());
413 
414  Inherited::VisitTemplateTemplateParmDecl(D);
415  }
416 
417  void VisitTemplateDecl(const TemplateDecl *D) {
419 
420  Inherited::VisitTemplateDecl(D);
421  }
422 
423  void VisitRedeclarableTemplateDecl(const RedeclarableTemplateDecl *D) {
425  Inherited::VisitRedeclarableTemplateDecl(D);
426  }
427 
428  void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
429  Visit(D->getTemplatedDecl());
431  Inherited::VisitFunctionTemplateDecl(D);
432  }
433 };
434 } // namespace
435 
436 // Only allow a small portion of Decl's to be processed. Remove this once
437 // all Decl's can be handled.
439  if (D->isImplicit()) return false;
440  if (D->getDeclContext() != Parent) return false;
441 
442  switch (D->getKind()) {
443  default:
444  return false;
445  case Decl::AccessSpec:
446  case Decl::CXXConstructor:
447  case Decl::CXXDestructor:
448  case Decl::CXXMethod:
449  case Decl::Field:
450  case Decl::Friend:
451  case Decl::FunctionTemplate:
452  case Decl::StaticAssert:
453  case Decl::TypeAlias:
454  case Decl::Typedef:
455  case Decl::Var:
456  return true;
457  }
458 }
459 
460 void ODRHash::AddSubDecl(const Decl *D) {
461  assert(D && "Expecting non-null pointer.");
462 
463  ODRDeclVisitor(ID, *this).Visit(D);
464 }
465 
467  assert(Record && Record->hasDefinition() &&
468  "Expected non-null record to be a definition.");
469 
470  const DeclContext *DC = Record;
471  while (DC) {
472  if (isa<ClassTemplateSpecializationDecl>(DC)) {
473  return;
474  }
475  DC = DC->getParent();
476  }
477 
478  AddDecl(Record);
479 
480  // Filter out sub-Decls which will not be processed in order to get an
481  // accurate count of Decl's.
483  for (const Decl *SubDecl : Record->decls()) {
484  if (isWhitelistedDecl(SubDecl, Record)) {
485  Decls.push_back(SubDecl);
486  }
487  }
488 
489  ID.AddInteger(Decls.size());
490  for (auto SubDecl : Decls) {
491  AddSubDecl(SubDecl);
492  }
493 
494  const ClassTemplateDecl *TD = Record->getDescribedClassTemplate();
495  AddBoolean(TD);
496  if (TD) {
498  }
499 
500  ID.AddInteger(Record->getNumBases());
501  auto Bases = Record->bases();
502  for (auto Base : Bases) {
503  AddQualType(Base.getType());
504  ID.AddInteger(Base.isVirtual());
505  ID.AddInteger(Base.getAccessSpecifierAsWritten());
506  }
507 }
508 
509 void ODRHash::AddFunctionDecl(const FunctionDecl *Function) {
510  assert(Function && "Expecting non-null pointer.");
511 
512  // Skip hashing these kinds of function.
513  if (Function->isImplicit()) return;
514  if (Function->isDefaulted()) return;
515  if (Function->isDeleted()) return;
516  if (!Function->hasBody()) return;
517  if (!Function->getBody()) return;
518 
519  // Skip functions that are specializations or in specialization context.
520  const DeclContext *DC = Function;
521  while (DC) {
522  if (isa<ClassTemplateSpecializationDecl>(DC)) return;
523  if (auto *F = dyn_cast<FunctionDecl>(DC))
524  if (F->isFunctionTemplateSpecialization()) return;
525  DC = DC->getParent();
526  }
527 
528  AddDecl(Function);
529 
530  AddQualType(Function->getReturnType());
531 
532  ID.AddInteger(Function->param_size());
533  for (auto Param : Function->parameters())
534  AddSubDecl(Param);
535 
536  AddStmt(Function->getBody());
537 }
538 
539 void ODRHash::AddDecl(const Decl *D) {
540  assert(D && "Expecting non-null pointer.");
541  D = D->getCanonicalDecl();
542 
543  if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
544  AddDeclarationName(ND->getDeclName());
545  return;
546  }
547 
548  ID.AddInteger(D->getKind());
549  // TODO: Handle non-NamedDecl here.
550 }
551 
552 namespace {
553 // Process a Type pointer. Add* methods call back into ODRHash while Visit*
554 // methods process the relevant parts of the Type.
555 class ODRTypeVisitor : public TypeVisitor<ODRTypeVisitor> {
556  typedef TypeVisitor<ODRTypeVisitor> Inherited;
557  llvm::FoldingSetNodeID &ID;
558  ODRHash &Hash;
559 
560 public:
561  ODRTypeVisitor(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
562  : ID(ID), Hash(Hash) {}
563 
564  void AddStmt(Stmt *S) {
565  Hash.AddBoolean(S);
566  if (S) {
567  Hash.AddStmt(S);
568  }
569  }
570 
571  void AddDecl(Decl *D) {
572  Hash.AddBoolean(D);
573  if (D) {
574  Hash.AddDecl(D);
575  }
576  }
577 
578  void AddQualType(QualType T) {
579  Hash.AddQualType(T);
580  }
581 
582  void AddType(const Type *T) {
583  Hash.AddBoolean(T);
584  if (T) {
585  Hash.AddType(T);
586  }
587  }
588 
590  Hash.AddBoolean(NNS);
591  if (NNS) {
592  Hash.AddNestedNameSpecifier(NNS);
593  }
594  }
595 
596  void AddIdentifierInfo(const IdentifierInfo *II) {
597  Hash.AddBoolean(II);
598  if (II) {
599  Hash.AddIdentifierInfo(II);
600  }
601  }
602 
603  void VisitQualifiers(Qualifiers Quals) {
604  ID.AddInteger(Quals.getAsOpaqueValue());
605  }
606 
607  void Visit(const Type *T) {
608  ID.AddInteger(T->getTypeClass());
609  Inherited::Visit(T);
610  }
611 
612  void VisitType(const Type *T) {}
613 
614  void VisitAdjustedType(const AdjustedType *T) {
617  VisitType(T);
618  }
619 
620  void VisitDecayedType(const DecayedType *T) {
623  VisitAdjustedType(T);
624  }
625 
626  void VisitArrayType(const ArrayType *T) {
628  ID.AddInteger(T->getSizeModifier());
629  VisitQualifiers(T->getIndexTypeQualifiers());
630  VisitType(T);
631  }
632  void VisitConstantArrayType(const ConstantArrayType *T) {
633  T->getSize().Profile(ID);
634  VisitArrayType(T);
635  }
636 
637  void VisitDependentSizedArrayType(const DependentSizedArrayType *T) {
638  AddStmt(T->getSizeExpr());
639  VisitArrayType(T);
640  }
641 
642  void VisitIncompleteArrayType(const IncompleteArrayType *T) {
643  VisitArrayType(T);
644  }
645 
646  void VisitVariableArrayType(const VariableArrayType *T) {
647  AddStmt(T->getSizeExpr());
648  VisitArrayType(T);
649  }
650 
651  void VisitBuiltinType(const BuiltinType *T) {
652  ID.AddInteger(T->getKind());
653  VisitType(T);
654  }
655 
656  void VisitFunctionType(const FunctionType *T) {
658  T->getExtInfo().Profile(ID);
659  Hash.AddBoolean(T->isConst());
660  Hash.AddBoolean(T->isVolatile());
661  Hash.AddBoolean(T->isRestrict());
662  VisitType(T);
663  }
664 
665  void VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
666  VisitFunctionType(T);
667  }
668 
669  void VisitFunctionProtoType(const FunctionProtoType *T) {
670  ID.AddInteger(T->getNumParams());
671  for (auto ParamType : T->getParamTypes())
672  AddQualType(ParamType);
673 
674  VisitFunctionType(T);
675  }
676 
677  void VisitPointerType(const PointerType *T) {
679  VisitType(T);
680  }
681 
682  void VisitReferenceType(const ReferenceType *T) {
684  VisitType(T);
685  }
686 
687  void VisitLValueReferenceType(const LValueReferenceType *T) {
688  VisitReferenceType(T);
689  }
690 
691  void VisitRValueReferenceType(const RValueReferenceType *T) {
692  VisitReferenceType(T);
693  }
694 
695  void VisitTypedefType(const TypedefType *T) {
696  AddDecl(T->getDecl());
697  QualType UnderlyingType = T->getDecl()->getUnderlyingType();
698  VisitQualifiers(UnderlyingType.getQualifiers());
699  while (true) {
700  if (const TypedefType *Underlying =
701  dyn_cast<TypedefType>(UnderlyingType.getTypePtr())) {
702  UnderlyingType = Underlying->getDecl()->getUnderlyingType();
703  continue;
704  }
705  if (const ElaboratedType *Underlying =
706  dyn_cast<ElaboratedType>(UnderlyingType.getTypePtr())) {
707  UnderlyingType = Underlying->getNamedType();
708  continue;
709  }
710 
711  break;
712  }
713  AddType(UnderlyingType.getTypePtr());
714  VisitType(T);
715  }
716 
717  void VisitTagType(const TagType *T) {
718  AddDecl(T->getDecl());
719  VisitType(T);
720  }
721 
722  void VisitRecordType(const RecordType *T) { VisitTagType(T); }
723  void VisitEnumType(const EnumType *T) { VisitTagType(T); }
724 
725  void VisitTypeWithKeyword(const TypeWithKeyword *T) {
726  ID.AddInteger(T->getKeyword());
727  VisitType(T);
728  };
729 
730  void VisitDependentNameType(const DependentNameType *T) {
733  VisitTypeWithKeyword(T);
734  }
735 
736  void VisitDependentTemplateSpecializationType(
740  ID.AddInteger(T->getNumArgs());
741  for (const auto &TA : T->template_arguments()) {
742  Hash.AddTemplateArgument(TA);
743  }
744  VisitTypeWithKeyword(T);
745  }
746 
747  void VisitElaboratedType(const ElaboratedType *T) {
750  VisitTypeWithKeyword(T);
751  }
752 
753  void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
754  ID.AddInteger(T->getNumArgs());
755  for (const auto &TA : T->template_arguments()) {
756  Hash.AddTemplateArgument(TA);
757  }
758  Hash.AddTemplateName(T->getTemplateName());
759  VisitType(T);
760  }
761 
762  void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
763  ID.AddInteger(T->getDepth());
764  ID.AddInteger(T->getIndex());
765  Hash.AddBoolean(T->isParameterPack());
766  AddDecl(T->getDecl());
767  }
768 };
769 } // namespace
770 
771 void ODRHash::AddType(const Type *T) {
772  assert(T && "Expecting non-null pointer.");
773  auto Result = TypeMap.insert(std::make_pair(T, TypeMap.size()));
774  ID.AddInteger(Result.first->second);
775  // On first encounter of a Type pointer, process it. Every time afterwards,
776  // only the index value is needed.
777  if (!Result.second) {
778  return;
779  }
780 
781  ODRTypeVisitor(ID, *this).Visit(T);
782 }
783 
785  AddBoolean(T.isNull());
786  if (T.isNull())
787  return;
788  SplitQualType split = T.split();
789  ID.AddInteger(split.Quals.getAsOpaqueValue());
790  AddType(split.Ty);
791 }
792 
794  Bools.push_back(Value);
795 }
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Definition: Type.h:4880
const Type * Ty
The locally-unqualified type.
Definition: Type.h:595
Represents a function declaration or definition.
Definition: Decl.h:1714
Smart pointer class that efficiently represents Objective-C method names.
void AddFunctionDecl(const FunctionDecl *Function)
Definition: ODRHash.cpp:509
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2374
QualType getPointeeType() const
Definition: Type.h:2387
A (possibly-)qualified type.
Definition: Type.h:654
base_class_range bases()
Definition: DeclCXX.h:811
void AddBoolean(bool value)
Definition: ODRHash.cpp:793
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:805
QualType getDecayedType() const
Definition: Type.h:2466
This file contains the declaration of the ODRHash class, which calculates a hash based on AST nodes...
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:3281
Stmt - This represents one statement.
Definition: Stmt.h:66
Expr * getBitWidth() const
Definition: Decl.h:2610
void AddQualType(QualType T)
Definition: ODRHash.cpp:784
Kind getKind() const
Definition: Type.h:2255
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3147
Represents the declaration of a typedef-name via the &#39;typedef&#39; type specifier.
Definition: Decl.h:2960
Microsoft&#39;s &#39;__super&#39; specifier, stored as a CXXRecordDecl* of the class it appeared in...
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:4955
The template argument is an expression, and we&#39;ve not resolved it to one of the other forms yet...
Definition: TemplateBase.h:87
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:4974
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
TagDecl * getDecl() const
Definition: Type.cpp:3107
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:126
Selector getObjCSelector() const
getObjCSelector - Get the Objective-C selector stored in this declaration name.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
The base class of the type hierarchy.
Definition: Type.h:1420
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2649
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:64
A container of type source information.
Definition: Decl.h:86
bool isEmpty() const
Evaluates true when this declaration name is empty.
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:4318
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:206
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:2034
size_t param_size() const
Definition: Decl.h:2238
QualType getElementType() const
Definition: Type.h:2684
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
An identifier, stored as an IdentifierInfo*.
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
Definition: DeclFriend.h:54
Represents a variable declaration or definition.
Definition: Decl.h:812
Declaration of a redeclarable template.
Definition: DeclTemplate.h:737
QualType getReturnType() const
Definition: Decl.h:2262
unsigned getNumParams() const
Definition: Type.h:3604
QualType getCXXNameType() const
getCXXNameType - If this name is one of the C++ names (of a constructor, destructor, or conversion function), return the type associated with that name.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:57
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:1586
A namespace, stored as a NamespaceDecl*.
bool isConst() const
Definition: Type.h:3313
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
void AddTemplateArgument(TemplateArgument TA)
Definition: ODRHash.cpp:140
bool hasDefinition() const
Definition: DeclCXX.h:776
Represents a parameter to a function.
Definition: Decl.h:1533
The collection of all-type qualifiers we support.
Definition: Type.h:153
void clear()
Definition: ODRHash.cpp:181
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:297
QualType getOriginalType() const
Definition: Type.h:2438
static bool isWhitelistedDecl(const Decl *D, const CXXRecordDecl *Record)
Definition: ODRHash.cpp:438
One of these records is kept for each identifier that is lexed.
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:124
bool isConst() const
Definition: DeclCXX.h:2073
StringLiteral * getMessage()
Definition: DeclCXX.h:3765
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:330
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:3611
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:72
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
Represents a member of a struct/union/class.
Definition: Decl.h:2521
bool isVolatile() const
Definition: DeclCXX.h:2074
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:4659
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
An operation on a type.
Definition: TypeVisitor.h:65
NamedDecl * getFriendDecl() const
If this friend declaration doesn&#39;t name a type, return the inner declaration.
Definition: DeclFriend.h:139
void AddTemplateParameterList(const TemplateParameterList *TPL)
Definition: ODRHash.cpp:172
Represents an access specifier followed by colon &#39;:&#39;.
Definition: DeclCXX.h:132
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name...
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2222
bool isUnarySelector() const
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2575
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2599
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
A qualified template name, where the qualification is kept to describe the source code as written...
Definition: TemplateName.h:198
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:2662
void AddDecl(const Decl *D)
Definition: ODRHash.cpp:539
#define CHAR_BIT
Definition: limits.h:79
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Definition: DeclTemplate.h:879
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1381
#define remainder(__x, __y)
Definition: tgmath.h:1106
QualType getPointeeType() const
Definition: Type.h:6543
Expr * getSizeExpr() const
Definition: Type.h:2828
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
Expr * getSizeExpr() const
Definition: Type.h:2885
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2529
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:875
void AddTemplateName(TemplateName Name)
Definition: ODRHash.cpp:122
Represents a K&R-style &#39;int foo()&#39; function, which has no information available about its arguments...
Definition: Type.h:3333
NodeId Parent
Definition: ASTDiff.cpp:192
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:2980
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3368
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:202
OverloadedOperatorKind getCXXOverloadedOperator() const
getCXXOverloadedOperator - If this name is the name of an overloadable operator in C++ (e...
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:264
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:2863
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:432
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2296
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:5046
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
bool isDefaulted() const
Whether this function is defaulted per C++0x.
Definition: Decl.h:2058
unsigned getAsOpaqueValue() const
Definition: Type.h:266
const FunctionProtoType * T
Declaration of a template type parameter.
unsigned getIndex() const
Definition: Type.h:4315
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:68
void AddDeclarationName(DeclarationName Name)
Definition: ODRHash.cpp:35
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:552
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition: Decl.cpp:3400
DeclContext * getDeclContext()
Definition: DeclBase.h:426
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:4981
void ProcessODRHash(llvm::FoldingSetNodeID &ID, ODRHash &Hash) const
Calculate a unique representation for a statement that is stable across compiler invocations.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2292
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
Definition: TemplateName.h:178
A namespace alias, stored as a NamespaceAliasDecl*.
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn&#39;t a simple identifier.
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:593
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:2626
Qualifiers Quals
The local qualifiers.
Definition: Type.h:598
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1341
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition: Type.h:4829
ArraySizeModifier getSizeModifier() const
Definition: Type.h:2686
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2557
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
unsigned getNumArgs() const
The result type of a method or function.
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:719
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:5832
A template template parameter pack that has been substituted for a template template argument pack...
Definition: TemplateName.h:211
IdentifierInfo * getCXXLiteralIdentifier() const
getCXXLiteralIdentifier - If this name is the name of a literal operator, retrieve the identifier ass...
Kind
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:4841
IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isParameterPack() const
Returns whether this is a parameter pack.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
QualType getAdjustedType() const
Definition: Type.h:2439
QualType getReturnType() const
Definition: Type.h:3301
bool isPure() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2039
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:4097
void AddType(const Type *T)
Definition: ODRHash.cpp:771
void AddIdentifierInfo(const IdentifierInfo *II)
Definition: ODRHash.cpp:30
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
Definition: Decl.h:2663
bool isRestrict() const
Definition: Type.h:3315
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2031
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
bool isParameterPack() const
Definition: Type.h:4316
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:360
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:4910
Qualifiers getIndexTypeQualifiers() const
Definition: Type.h:2690
TypeClass getTypeClass() const
Definition: Type.h:1682
void AddNestedNameSpecifier(const NestedNameSpecifier *NNS)
Definition: ODRHash.cpp:93
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:5050
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3739
void AddSubDecl(const Decl *D)
Definition: ODRHash.cpp:460
Represents a pointer type decayed from an array or function type.
Definition: Type.h:2459
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:354
StringRef getName() const
Return the actual identifier string.
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2858
Represents a template argument.
Definition: TemplateBase.h:51
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons...
Definition: Type.h:2422
Dataflow Directional Tag Classes.
ExtInfo getExtInfo() const
Definition: Type.h:3312
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:493
NestedNameSpecifier * getQualifier() const
Definition: Type.h:5037
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1262
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:80
QualType getUnderlyingType() const
Definition: Decl.h:2913
AccessSpecifier getAccess() const
Definition: DeclBase.h:461
const Expr * getInit() const
Definition: Decl.h:1217
void AddCXXRecordDecl(const CXXRecordDecl *Record)
Definition: ODRHash.cpp:466
DeclarationName - The name of a declaration.
Kind getKind() const
Definition: DeclBase.h:420
bool isKeywordSelector() const
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
A type that was preceded by the &#39;template&#39; keyword, stored as a Type*.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4071
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:4667
const llvm::APInt & getSize() const
Definition: Type.h:2727
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
Definition: Decl.h:1057
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2510
bool isVolatile() const
Definition: Type.h:3314
unsigned CalculateHash()
Definition: ODRHash.cpp:188
The template argument is a type.
Definition: TemplateBase.h:60
The template argument is actually a parameter pack.
Definition: TemplateBase.h:91
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
Definition: DeclCXX.cpp:1585
TypedefNameDecl * getDecl() const
Definition: Type.h:3868
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:235
unsigned getDepth() const
Definition: Type.h:4314
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:2596
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:5007
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:4673
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:76
Represents a C array with an unspecified size.
Definition: Type.h:2763
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:4913
bool isNull() const
Determine whether this is the empty selector.
Declaration of a class template.
This class is used for builtin types like &#39;int&#39;.
Definition: Type.h:2234
void AddStmt(const Stmt *S)
Definition: ODRHash.cpp:25
NameKind getKind() const
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:257
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4589
bool isDeleted() const
Whether this function has been deleted.
Definition: Decl.h:2123
QualType getDefaultArgument() const
Retrieve the default argument, if any.
QualType getType() const
Definition: Decl.h:647
A set of overloaded template declarations.
Definition: TemplateName.h:194
This represents a decl that may have a name.
Definition: Decl.h:248
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2808
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:77
The global specifier &#39;::&#39;. There is no stored value.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
Definition: TemplateBase.h:288
bool hasInit() const
Definition: Decl.cpp:2144
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:2709
Declaration of a template function.
Definition: DeclTemplate.h:968
bool isDeletedAsWritten() const
Definition: Decl.h:2124
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:97
A single template declaration.
Definition: TemplateName.h:191
const IdentifierInfo * getIdentifier() const
Definition: Type.h:5038