clang  9.0.0svn
ASTStructuralEquivalence.cpp
Go to the documentation of this file.
1 //===- ASTStructuralEquivalence.cpp ---------------------------------------===//
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 // This file implement StructuralEquivalenceContext class and helper functions
10 // for layout matching.
11 //
12 // The structural equivalence check could have been implemented as a parallel
13 // BFS on a pair of graphs. That must have been the original approach at the
14 // beginning.
15 // Let's consider this simple BFS algorithm from the `s` source:
16 // ```
17 // void bfs(Graph G, int s)
18 // {
19 // Queue<Integer> queue = new Queue<Integer>();
20 // marked[s] = true; // Mark the source
21 // queue.enqueue(s); // and put it on the queue.
22 // while (!q.isEmpty()) {
23 // int v = queue.dequeue(); // Remove next vertex from the queue.
24 // for (int w : G.adj(v))
25 // if (!marked[w]) // For every unmarked adjacent vertex,
26 // {
27 // marked[w] = true;
28 // queue.enqueue(w);
29 // }
30 // }
31 // }
32 // ```
33 // Indeed, it has it's queue, which holds pairs of nodes, one from each graph,
34 // this is the `DeclsToCheck` and it's pair is in `TentativeEquivalences`.
35 // `TentativeEquivalences` also plays the role of the marking (`marked`)
36 // functionality above, we use it to check whether we've already seen a pair of
37 // nodes.
38 //
39 // We put in the elements into the queue only in the toplevel decl check
40 // function:
41 // ```
42 // static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
43 // Decl *D1, Decl *D2);
44 // ```
45 // The `while` loop where we iterate over the children is implemented in
46 // `Finish()`. And `Finish` is called only from the two **member** functions
47 // which check the equivalency of two Decls or two Types. ASTImporter (and
48 // other clients) call only these functions.
49 //
50 // The `static` implementation functions are called from `Finish`, these push
51 // the children nodes to the queue via `static bool
52 // IsStructurallyEquivalent(StructuralEquivalenceContext &Context, Decl *D1,
53 // Decl *D2)`. So far so good, this is almost like the BFS. However, if we
54 // let a static implementation function to call `Finish` via another **member**
55 // function that means we end up with two nested while loops each of them
56 // working on the same queue. This is wrong and nobody can reason about it's
57 // doing. Thus, static implementation functions must not call the **member**
58 // functions.
59 //
60 // So, now `TentativeEquivalences` plays two roles. It is used to store the
61 // second half of the decls which we want to compare, plus it plays a role in
62 // closing the recursion. On a long term, we could refactor structural
63 // equivalency to be more alike to the traditional BFS.
64 //
65 //===----------------------------------------------------------------------===//
66 
68 #include "clang/AST/ASTContext.h"
70 #include "clang/AST/Decl.h"
71 #include "clang/AST/DeclBase.h"
72 #include "clang/AST/DeclCXX.h"
73 #include "clang/AST/DeclFriend.h"
74 #include "clang/AST/DeclObjC.h"
75 #include "clang/AST/DeclTemplate.h"
77 #include "clang/AST/TemplateBase.h"
78 #include "clang/AST/TemplateName.h"
79 #include "clang/AST/Type.h"
82 #include "clang/Basic/LLVM.h"
84 #include "llvm/ADT/APInt.h"
85 #include "llvm/ADT/APSInt.h"
86 #include "llvm/ADT/None.h"
87 #include "llvm/ADT/Optional.h"
88 #include "llvm/Support/Casting.h"
89 #include "llvm/Support/Compiler.h"
90 #include "llvm/Support/ErrorHandling.h"
91 #include <cassert>
92 #include <utility>
93 
94 using namespace clang;
95 
97  QualType T1, QualType T2);
99  Decl *D1, Decl *D2);
101  const TemplateArgument &Arg1,
102  const TemplateArgument &Arg2);
103 
104 /// Determine structural equivalence of two expressions.
106  const Expr *E1, const Expr *E2) {
107  if (!E1 || !E2)
108  return E1 == E2;
109 
110  // FIXME: Actually perform a structural comparison!
111  return true;
112 }
113 
114 /// Determine whether two identifiers are equivalent.
115 static bool IsStructurallyEquivalent(const IdentifierInfo *Name1,
116  const IdentifierInfo *Name2) {
117  if (!Name1 || !Name2)
118  return Name1 == Name2;
119 
120  return Name1->getName() == Name2->getName();
121 }
122 
123 /// Determine whether two nested-name-specifiers are equivalent.
125  NestedNameSpecifier *NNS1,
126  NestedNameSpecifier *NNS2) {
127  if (NNS1->getKind() != NNS2->getKind())
128  return false;
129 
130  NestedNameSpecifier *Prefix1 = NNS1->getPrefix(),
131  *Prefix2 = NNS2->getPrefix();
132  if ((bool)Prefix1 != (bool)Prefix2)
133  return false;
134 
135  if (Prefix1)
136  if (!IsStructurallyEquivalent(Context, Prefix1, Prefix2))
137  return false;
138 
139  switch (NNS1->getKind()) {
142  NNS2->getAsIdentifier());
144  return IsStructurallyEquivalent(Context, NNS1->getAsNamespace(),
145  NNS2->getAsNamespace());
147  return IsStructurallyEquivalent(Context, NNS1->getAsNamespaceAlias(),
148  NNS2->getAsNamespaceAlias());
151  return IsStructurallyEquivalent(Context, QualType(NNS1->getAsType(), 0),
152  QualType(NNS2->getAsType(), 0));
154  return true;
156  return IsStructurallyEquivalent(Context, NNS1->getAsRecordDecl(),
157  NNS2->getAsRecordDecl());
158  }
159  return false;
160 }
161 
163  const TemplateName &N1,
164  const TemplateName &N2) {
165  if (N1.getKind() != N2.getKind())
166  return false;
167  switch (N1.getKind()) {
169  return IsStructurallyEquivalent(Context, N1.getAsTemplateDecl(),
170  N2.getAsTemplateDecl());
171 
174  *OS2 = N2.getAsOverloadedTemplate();
175  OverloadedTemplateStorage::iterator I1 = OS1->begin(), I2 = OS2->begin(),
176  E1 = OS1->end(), E2 = OS2->end();
177  for (; I1 != E1 && I2 != E2; ++I1, ++I2)
178  if (!IsStructurallyEquivalent(Context, *I1, *I2))
179  return false;
180  return I1 == E1 && I2 == E2;
181  }
182 
185  *QN2 = N2.getAsQualifiedTemplateName();
186  return IsStructurallyEquivalent(Context, QN1->getDecl(), QN2->getDecl()) &&
187  IsStructurallyEquivalent(Context, QN1->getQualifier(),
188  QN2->getQualifier());
189  }
190 
193  *DN2 = N2.getAsDependentTemplateName();
194  if (!IsStructurallyEquivalent(Context, DN1->getQualifier(),
195  DN2->getQualifier()))
196  return false;
197  if (DN1->isIdentifier() && DN2->isIdentifier())
199  DN2->getIdentifier());
200  else if (DN1->isOverloadedOperator() && DN2->isOverloadedOperator())
201  return DN1->getOperator() == DN2->getOperator();
202  return false;
203  }
204 
207  *TS2 = N2.getAsSubstTemplateTemplateParm();
208  return IsStructurallyEquivalent(Context, TS1->getParameter(),
209  TS2->getParameter()) &&
211  TS2->getReplacement());
212  }
213 
218  return IsStructurallyEquivalent(Context, P1->getArgumentPack(),
219  P2->getArgumentPack()) &&
221  P2->getParameterPack());
222  }
223  }
224  return false;
225 }
226 
227 /// Determine whether two template arguments are equivalent.
229  const TemplateArgument &Arg1,
230  const TemplateArgument &Arg2) {
231  if (Arg1.getKind() != Arg2.getKind())
232  return false;
233 
234  switch (Arg1.getKind()) {
236  return true;
237 
239  return IsStructurallyEquivalent(Context, Arg1.getAsType(), Arg2.getAsType());
240 
242  if (!IsStructurallyEquivalent(Context, Arg1.getIntegralType(),
243  Arg2.getIntegralType()))
244  return false;
245 
246  return llvm::APSInt::isSameValue(Arg1.getAsIntegral(),
247  Arg2.getAsIntegral());
248 
250  return IsStructurallyEquivalent(Context, Arg1.getAsDecl(), Arg2.getAsDecl());
251 
253  return true; // FIXME: Is this correct?
254 
256  return IsStructurallyEquivalent(Context, Arg1.getAsTemplate(),
257  Arg2.getAsTemplate());
258 
260  return IsStructurallyEquivalent(Context,
263 
265  return IsStructurallyEquivalent(Context, Arg1.getAsExpr(),
266  Arg2.getAsExpr());
267 
269  if (Arg1.pack_size() != Arg2.pack_size())
270  return false;
271 
272  for (unsigned I = 0, N = Arg1.pack_size(); I != N; ++I)
273  if (!IsStructurallyEquivalent(Context, Arg1.pack_begin()[I],
274  Arg2.pack_begin()[I]))
275  return false;
276 
277  return true;
278  }
279 
280  llvm_unreachable("Invalid template argument kind");
281 }
282 
283 /// Determine structural equivalence for the common part of array
284 /// types.
286  const ArrayType *Array1,
287  const ArrayType *Array2) {
288  if (!IsStructurallyEquivalent(Context, Array1->getElementType(),
289  Array2->getElementType()))
290  return false;
291  if (Array1->getSizeModifier() != Array2->getSizeModifier())
292  return false;
293  if (Array1->getIndexTypeQualifiers() != Array2->getIndexTypeQualifiers())
294  return false;
295 
296  return true;
297 }
298 
299 /// Determine structural equivalence based on the ExtInfo of functions. This
300 /// is inspired by ASTContext::mergeFunctionTypes(), we compare calling
301 /// conventions bits but must not compare some other bits.
304  FunctionType::ExtInfo EI2) {
305  // Compatible functions must have compatible calling conventions.
306  if (EI1.getCC() != EI2.getCC())
307  return false;
308 
309  // Regparm is part of the calling convention.
310  if (EI1.getHasRegParm() != EI2.getHasRegParm())
311  return false;
312  if (EI1.getRegParm() != EI2.getRegParm())
313  return false;
314 
315  if (EI1.getProducesResult() != EI2.getProducesResult())
316  return false;
317  if (EI1.getNoCallerSavedRegs() != EI2.getNoCallerSavedRegs())
318  return false;
319  if (EI1.getNoCfCheck() != EI2.getNoCfCheck())
320  return false;
321 
322  return true;
323 }
324 
325 /// Determine structural equivalence of two types.
327  QualType T1, QualType T2) {
328  if (T1.isNull() || T2.isNull())
329  return T1.isNull() && T2.isNull();
330 
331  QualType OrigT1 = T1;
332  QualType OrigT2 = T2;
333 
334  if (!Context.StrictTypeSpelling) {
335  // We aren't being strict about token-to-token equivalence of types,
336  // so map down to the canonical type.
337  T1 = Context.FromCtx.getCanonicalType(T1);
338  T2 = Context.ToCtx.getCanonicalType(T2);
339  }
340 
341  if (T1.getQualifiers() != T2.getQualifiers())
342  return false;
343 
344  Type::TypeClass TC = T1->getTypeClass();
345 
346  if (T1->getTypeClass() != T2->getTypeClass()) {
347  // Compare function types with prototypes vs. without prototypes as if
348  // both did not have prototypes.
349  if (T1->getTypeClass() == Type::FunctionProto &&
350  T2->getTypeClass() == Type::FunctionNoProto)
351  TC = Type::FunctionNoProto;
352  else if (T1->getTypeClass() == Type::FunctionNoProto &&
353  T2->getTypeClass() == Type::FunctionProto)
354  TC = Type::FunctionNoProto;
355  else
356  return false;
357  }
358 
359  switch (TC) {
360  case Type::Builtin:
361  // FIXME: Deal with Char_S/Char_U.
362  if (cast<BuiltinType>(T1)->getKind() != cast<BuiltinType>(T2)->getKind())
363  return false;
364  break;
365 
366  case Type::Complex:
367  if (!IsStructurallyEquivalent(Context,
368  cast<ComplexType>(T1)->getElementType(),
369  cast<ComplexType>(T2)->getElementType()))
370  return false;
371  break;
372 
373  case Type::Adjusted:
374  case Type::Decayed:
375  if (!IsStructurallyEquivalent(Context,
376  cast<AdjustedType>(T1)->getOriginalType(),
377  cast<AdjustedType>(T2)->getOriginalType()))
378  return false;
379  break;
380 
381  case Type::Pointer:
382  if (!IsStructurallyEquivalent(Context,
383  cast<PointerType>(T1)->getPointeeType(),
384  cast<PointerType>(T2)->getPointeeType()))
385  return false;
386  break;
387 
388  case Type::BlockPointer:
389  if (!IsStructurallyEquivalent(Context,
390  cast<BlockPointerType>(T1)->getPointeeType(),
391  cast<BlockPointerType>(T2)->getPointeeType()))
392  return false;
393  break;
394 
395  case Type::LValueReference:
396  case Type::RValueReference: {
397  const auto *Ref1 = cast<ReferenceType>(T1);
398  const auto *Ref2 = cast<ReferenceType>(T2);
399  if (Ref1->isSpelledAsLValue() != Ref2->isSpelledAsLValue())
400  return false;
401  if (Ref1->isInnerRef() != Ref2->isInnerRef())
402  return false;
403  if (!IsStructurallyEquivalent(Context, Ref1->getPointeeTypeAsWritten(),
404  Ref2->getPointeeTypeAsWritten()))
405  return false;
406  break;
407  }
408 
409  case Type::MemberPointer: {
410  const auto *MemPtr1 = cast<MemberPointerType>(T1);
411  const auto *MemPtr2 = cast<MemberPointerType>(T2);
412  if (!IsStructurallyEquivalent(Context, MemPtr1->getPointeeType(),
413  MemPtr2->getPointeeType()))
414  return false;
415  if (!IsStructurallyEquivalent(Context, QualType(MemPtr1->getClass(), 0),
416  QualType(MemPtr2->getClass(), 0)))
417  return false;
418  break;
419  }
420 
421  case Type::ConstantArray: {
422  const auto *Array1 = cast<ConstantArrayType>(T1);
423  const auto *Array2 = cast<ConstantArrayType>(T2);
424  if (!llvm::APInt::isSameValue(Array1->getSize(), Array2->getSize()))
425  return false;
426 
427  if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
428  return false;
429  break;
430  }
431 
432  case Type::IncompleteArray:
433  if (!IsArrayStructurallyEquivalent(Context, cast<ArrayType>(T1),
434  cast<ArrayType>(T2)))
435  return false;
436  break;
437 
438  case Type::VariableArray: {
439  const auto *Array1 = cast<VariableArrayType>(T1);
440  const auto *Array2 = cast<VariableArrayType>(T2);
441  if (!IsStructurallyEquivalent(Context, Array1->getSizeExpr(),
442  Array2->getSizeExpr()))
443  return false;
444 
445  if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
446  return false;
447 
448  break;
449  }
450 
451  case Type::DependentSizedArray: {
452  const auto *Array1 = cast<DependentSizedArrayType>(T1);
453  const auto *Array2 = cast<DependentSizedArrayType>(T2);
454  if (!IsStructurallyEquivalent(Context, Array1->getSizeExpr(),
455  Array2->getSizeExpr()))
456  return false;
457 
458  if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
459  return false;
460 
461  break;
462  }
463 
464  case Type::DependentAddressSpace: {
465  const auto *DepAddressSpace1 = cast<DependentAddressSpaceType>(T1);
466  const auto *DepAddressSpace2 = cast<DependentAddressSpaceType>(T2);
467  if (!IsStructurallyEquivalent(Context, DepAddressSpace1->getAddrSpaceExpr(),
468  DepAddressSpace2->getAddrSpaceExpr()))
469  return false;
470  if (!IsStructurallyEquivalent(Context, DepAddressSpace1->getPointeeType(),
471  DepAddressSpace2->getPointeeType()))
472  return false;
473 
474  break;
475  }
476 
477  case Type::DependentSizedExtVector: {
478  const auto *Vec1 = cast<DependentSizedExtVectorType>(T1);
479  const auto *Vec2 = cast<DependentSizedExtVectorType>(T2);
480  if (!IsStructurallyEquivalent(Context, Vec1->getSizeExpr(),
481  Vec2->getSizeExpr()))
482  return false;
483  if (!IsStructurallyEquivalent(Context, Vec1->getElementType(),
484  Vec2->getElementType()))
485  return false;
486  break;
487  }
488 
489  case Type::DependentVector: {
490  const auto *Vec1 = cast<DependentVectorType>(T1);
491  const auto *Vec2 = cast<DependentVectorType>(T2);
492  if (Vec1->getVectorKind() != Vec2->getVectorKind())
493  return false;
494  if (!IsStructurallyEquivalent(Context, Vec1->getSizeExpr(),
495  Vec2->getSizeExpr()))
496  return false;
497  if (!IsStructurallyEquivalent(Context, Vec1->getElementType(),
498  Vec2->getElementType()))
499  return false;
500  break;
501  }
502 
503  case Type::Vector:
504  case Type::ExtVector: {
505  const auto *Vec1 = cast<VectorType>(T1);
506  const auto *Vec2 = cast<VectorType>(T2);
507  if (!IsStructurallyEquivalent(Context, Vec1->getElementType(),
508  Vec2->getElementType()))
509  return false;
510  if (Vec1->getNumElements() != Vec2->getNumElements())
511  return false;
512  if (Vec1->getVectorKind() != Vec2->getVectorKind())
513  return false;
514  break;
515  }
516 
517  case Type::FunctionProto: {
518  const auto *Proto1 = cast<FunctionProtoType>(T1);
519  const auto *Proto2 = cast<FunctionProtoType>(T2);
520 
521  if (Proto1->getNumParams() != Proto2->getNumParams())
522  return false;
523  for (unsigned I = 0, N = Proto1->getNumParams(); I != N; ++I) {
524  if (!IsStructurallyEquivalent(Context, Proto1->getParamType(I),
525  Proto2->getParamType(I)))
526  return false;
527  }
528  if (Proto1->isVariadic() != Proto2->isVariadic())
529  return false;
530 
531  if (Proto1->getMethodQuals() != Proto2->getMethodQuals())
532  return false;
533 
534  // Check exceptions, this information is lost in canonical type.
535  const auto *OrigProto1 =
536  cast<FunctionProtoType>(OrigT1.getDesugaredType(Context.FromCtx));
537  const auto *OrigProto2 =
538  cast<FunctionProtoType>(OrigT2.getDesugaredType(Context.ToCtx));
539  auto Spec1 = OrigProto1->getExceptionSpecType();
540  auto Spec2 = OrigProto2->getExceptionSpecType();
541 
542  if (Spec1 != Spec2)
543  return false;
544  if (Spec1 == EST_Dynamic) {
545  if (OrigProto1->getNumExceptions() != OrigProto2->getNumExceptions())
546  return false;
547  for (unsigned I = 0, N = OrigProto1->getNumExceptions(); I != N; ++I) {
548  if (!IsStructurallyEquivalent(Context, OrigProto1->getExceptionType(I),
549  OrigProto2->getExceptionType(I)))
550  return false;
551  }
552  } else if (isComputedNoexcept(Spec1)) {
553  if (!IsStructurallyEquivalent(Context, OrigProto1->getNoexceptExpr(),
554  OrigProto2->getNoexceptExpr()))
555  return false;
556  }
557 
558  // Fall through to check the bits common with FunctionNoProtoType.
559  LLVM_FALLTHROUGH;
560  }
561 
562  case Type::FunctionNoProto: {
563  const auto *Function1 = cast<FunctionType>(T1);
564  const auto *Function2 = cast<FunctionType>(T2);
565  if (!IsStructurallyEquivalent(Context, Function1->getReturnType(),
566  Function2->getReturnType()))
567  return false;
568  if (!IsStructurallyEquivalent(Context, Function1->getExtInfo(),
569  Function2->getExtInfo()))
570  return false;
571  break;
572  }
573 
574  case Type::UnresolvedUsing:
575  if (!IsStructurallyEquivalent(Context,
576  cast<UnresolvedUsingType>(T1)->getDecl(),
577  cast<UnresolvedUsingType>(T2)->getDecl()))
578  return false;
579  break;
580 
581  case Type::Attributed:
582  if (!IsStructurallyEquivalent(Context,
583  cast<AttributedType>(T1)->getModifiedType(),
584  cast<AttributedType>(T2)->getModifiedType()))
585  return false;
587  Context, cast<AttributedType>(T1)->getEquivalentType(),
588  cast<AttributedType>(T2)->getEquivalentType()))
589  return false;
590  break;
591 
592  case Type::Paren:
593  if (!IsStructurallyEquivalent(Context, cast<ParenType>(T1)->getInnerType(),
594  cast<ParenType>(T2)->getInnerType()))
595  return false;
596  break;
597 
598  case Type::Typedef:
599  if (!IsStructurallyEquivalent(Context, cast<TypedefType>(T1)->getDecl(),
600  cast<TypedefType>(T2)->getDecl()))
601  return false;
602  break;
603 
604  case Type::TypeOfExpr:
606  Context, cast<TypeOfExprType>(T1)->getUnderlyingExpr(),
607  cast<TypeOfExprType>(T2)->getUnderlyingExpr()))
608  return false;
609  break;
610 
611  case Type::TypeOf:
612  if (!IsStructurallyEquivalent(Context,
613  cast<TypeOfType>(T1)->getUnderlyingType(),
614  cast<TypeOfType>(T2)->getUnderlyingType()))
615  return false;
616  break;
617 
618  case Type::UnaryTransform:
620  Context, cast<UnaryTransformType>(T1)->getUnderlyingType(),
621  cast<UnaryTransformType>(T2)->getUnderlyingType()))
622  return false;
623  break;
624 
625  case Type::Decltype:
626  if (!IsStructurallyEquivalent(Context,
627  cast<DecltypeType>(T1)->getUnderlyingExpr(),
628  cast<DecltypeType>(T2)->getUnderlyingExpr()))
629  return false;
630  break;
631 
632  case Type::Auto:
633  if (!IsStructurallyEquivalent(Context, cast<AutoType>(T1)->getDeducedType(),
634  cast<AutoType>(T2)->getDeducedType()))
635  return false;
636  break;
637 
638  case Type::DeducedTemplateSpecialization: {
639  const auto *DT1 = cast<DeducedTemplateSpecializationType>(T1);
640  const auto *DT2 = cast<DeducedTemplateSpecializationType>(T2);
641  if (!IsStructurallyEquivalent(Context, DT1->getTemplateName(),
642  DT2->getTemplateName()))
643  return false;
644  if (!IsStructurallyEquivalent(Context, DT1->getDeducedType(),
645  DT2->getDeducedType()))
646  return false;
647  break;
648  }
649 
650  case Type::Record:
651  case Type::Enum:
652  if (!IsStructurallyEquivalent(Context, cast<TagType>(T1)->getDecl(),
653  cast<TagType>(T2)->getDecl()))
654  return false;
655  break;
656 
657  case Type::TemplateTypeParm: {
658  const auto *Parm1 = cast<TemplateTypeParmType>(T1);
659  const auto *Parm2 = cast<TemplateTypeParmType>(T2);
660  if (Parm1->getDepth() != Parm2->getDepth())
661  return false;
662  if (Parm1->getIndex() != Parm2->getIndex())
663  return false;
664  if (Parm1->isParameterPack() != Parm2->isParameterPack())
665  return false;
666 
667  // Names of template type parameters are never significant.
668  break;
669  }
670 
671  case Type::SubstTemplateTypeParm: {
672  const auto *Subst1 = cast<SubstTemplateTypeParmType>(T1);
673  const auto *Subst2 = cast<SubstTemplateTypeParmType>(T2);
674  if (!IsStructurallyEquivalent(Context,
675  QualType(Subst1->getReplacedParameter(), 0),
676  QualType(Subst2->getReplacedParameter(), 0)))
677  return false;
678  if (!IsStructurallyEquivalent(Context, Subst1->getReplacementType(),
679  Subst2->getReplacementType()))
680  return false;
681  break;
682  }
683 
684  case Type::SubstTemplateTypeParmPack: {
685  const auto *Subst1 = cast<SubstTemplateTypeParmPackType>(T1);
686  const auto *Subst2 = cast<SubstTemplateTypeParmPackType>(T2);
687  if (!IsStructurallyEquivalent(Context,
688  QualType(Subst1->getReplacedParameter(), 0),
689  QualType(Subst2->getReplacedParameter(), 0)))
690  return false;
691  if (!IsStructurallyEquivalent(Context, Subst1->getArgumentPack(),
692  Subst2->getArgumentPack()))
693  return false;
694  break;
695  }
696 
697  case Type::TemplateSpecialization: {
698  const auto *Spec1 = cast<TemplateSpecializationType>(T1);
699  const auto *Spec2 = cast<TemplateSpecializationType>(T2);
700  if (!IsStructurallyEquivalent(Context, Spec1->getTemplateName(),
701  Spec2->getTemplateName()))
702  return false;
703  if (Spec1->getNumArgs() != Spec2->getNumArgs())
704  return false;
705  for (unsigned I = 0, N = Spec1->getNumArgs(); I != N; ++I) {
706  if (!IsStructurallyEquivalent(Context, Spec1->getArg(I),
707  Spec2->getArg(I)))
708  return false;
709  }
710  break;
711  }
712 
713  case Type::Elaborated: {
714  const auto *Elab1 = cast<ElaboratedType>(T1);
715  const auto *Elab2 = cast<ElaboratedType>(T2);
716  // CHECKME: what if a keyword is ETK_None or ETK_typename ?
717  if (Elab1->getKeyword() != Elab2->getKeyword())
718  return false;
719  if (!IsStructurallyEquivalent(Context, Elab1->getQualifier(),
720  Elab2->getQualifier()))
721  return false;
722  if (!IsStructurallyEquivalent(Context, Elab1->getNamedType(),
723  Elab2->getNamedType()))
724  return false;
725  break;
726  }
727 
728  case Type::InjectedClassName: {
729  const auto *Inj1 = cast<InjectedClassNameType>(T1);
730  const auto *Inj2 = cast<InjectedClassNameType>(T2);
731  if (!IsStructurallyEquivalent(Context,
732  Inj1->getInjectedSpecializationType(),
733  Inj2->getInjectedSpecializationType()))
734  return false;
735  break;
736  }
737 
738  case Type::DependentName: {
739  const auto *Typename1 = cast<DependentNameType>(T1);
740  const auto *Typename2 = cast<DependentNameType>(T2);
741  if (!IsStructurallyEquivalent(Context, Typename1->getQualifier(),
742  Typename2->getQualifier()))
743  return false;
744  if (!IsStructurallyEquivalent(Typename1->getIdentifier(),
745  Typename2->getIdentifier()))
746  return false;
747 
748  break;
749  }
750 
751  case Type::DependentTemplateSpecialization: {
752  const auto *Spec1 = cast<DependentTemplateSpecializationType>(T1);
753  const auto *Spec2 = cast<DependentTemplateSpecializationType>(T2);
754  if (!IsStructurallyEquivalent(Context, Spec1->getQualifier(),
755  Spec2->getQualifier()))
756  return false;
757  if (!IsStructurallyEquivalent(Spec1->getIdentifier(),
758  Spec2->getIdentifier()))
759  return false;
760  if (Spec1->getNumArgs() != Spec2->getNumArgs())
761  return false;
762  for (unsigned I = 0, N = Spec1->getNumArgs(); I != N; ++I) {
763  if (!IsStructurallyEquivalent(Context, Spec1->getArg(I),
764  Spec2->getArg(I)))
765  return false;
766  }
767  break;
768  }
769 
770  case Type::PackExpansion:
771  if (!IsStructurallyEquivalent(Context,
772  cast<PackExpansionType>(T1)->getPattern(),
773  cast<PackExpansionType>(T2)->getPattern()))
774  return false;
775  break;
776 
777  case Type::ObjCInterface: {
778  const auto *Iface1 = cast<ObjCInterfaceType>(T1);
779  const auto *Iface2 = cast<ObjCInterfaceType>(T2);
780  if (!IsStructurallyEquivalent(Context, Iface1->getDecl(),
781  Iface2->getDecl()))
782  return false;
783  break;
784  }
785 
786  case Type::ObjCTypeParam: {
787  const auto *Obj1 = cast<ObjCTypeParamType>(T1);
788  const auto *Obj2 = cast<ObjCTypeParamType>(T2);
789  if (!IsStructurallyEquivalent(Context, Obj1->getDecl(), Obj2->getDecl()))
790  return false;
791 
792  if (Obj1->getNumProtocols() != Obj2->getNumProtocols())
793  return false;
794  for (unsigned I = 0, N = Obj1->getNumProtocols(); I != N; ++I) {
795  if (!IsStructurallyEquivalent(Context, Obj1->getProtocol(I),
796  Obj2->getProtocol(I)))
797  return false;
798  }
799  break;
800  }
801 
802  case Type::ObjCObject: {
803  const auto *Obj1 = cast<ObjCObjectType>(T1);
804  const auto *Obj2 = cast<ObjCObjectType>(T2);
805  if (!IsStructurallyEquivalent(Context, Obj1->getBaseType(),
806  Obj2->getBaseType()))
807  return false;
808  if (Obj1->getNumProtocols() != Obj2->getNumProtocols())
809  return false;
810  for (unsigned I = 0, N = Obj1->getNumProtocols(); I != N; ++I) {
811  if (!IsStructurallyEquivalent(Context, Obj1->getProtocol(I),
812  Obj2->getProtocol(I)))
813  return false;
814  }
815  break;
816  }
817 
818  case Type::ObjCObjectPointer: {
819  const auto *Ptr1 = cast<ObjCObjectPointerType>(T1);
820  const auto *Ptr2 = cast<ObjCObjectPointerType>(T2);
821  if (!IsStructurallyEquivalent(Context, Ptr1->getPointeeType(),
822  Ptr2->getPointeeType()))
823  return false;
824  break;
825  }
826 
827  case Type::Atomic:
828  if (!IsStructurallyEquivalent(Context, cast<AtomicType>(T1)->getValueType(),
829  cast<AtomicType>(T2)->getValueType()))
830  return false;
831  break;
832 
833  case Type::Pipe:
834  if (!IsStructurallyEquivalent(Context, cast<PipeType>(T1)->getElementType(),
835  cast<PipeType>(T2)->getElementType()))
836  return false;
837  break;
838  } // end switch
839 
840  return true;
841 }
842 
843 /// Determine structural equivalence of two fields.
845  FieldDecl *Field1, FieldDecl *Field2) {
846  const auto *Owner2 = cast<RecordDecl>(Field2->getDeclContext());
847 
848  // For anonymous structs/unions, match up the anonymous struct/union type
849  // declarations directly, so that we don't go off searching for anonymous
850  // types
851  if (Field1->isAnonymousStructOrUnion() &&
852  Field2->isAnonymousStructOrUnion()) {
853  RecordDecl *D1 = Field1->getType()->castAs<RecordType>()->getDecl();
854  RecordDecl *D2 = Field2->getType()->castAs<RecordType>()->getDecl();
855  return IsStructurallyEquivalent(Context, D1, D2);
856  }
857 
858  // Check for equivalent field names.
859  IdentifierInfo *Name1 = Field1->getIdentifier();
860  IdentifierInfo *Name2 = Field2->getIdentifier();
861  if (!::IsStructurallyEquivalent(Name1, Name2)) {
862  if (Context.Complain) {
863  Context.Diag2(Owner2->getLocation(),
864  Context.ErrorOnTagTypeMismatch
865  ? diag::err_odr_tag_type_inconsistent
866  : diag::warn_odr_tag_type_inconsistent)
867  << Context.ToCtx.getTypeDeclType(Owner2);
868  Context.Diag2(Field2->getLocation(), diag::note_odr_field_name)
869  << Field2->getDeclName();
870  Context.Diag1(Field1->getLocation(), diag::note_odr_field_name)
871  << Field1->getDeclName();
872  }
873  return false;
874  }
875 
876  if (!IsStructurallyEquivalent(Context, Field1->getType(),
877  Field2->getType())) {
878  if (Context.Complain) {
879  Context.Diag2(Owner2->getLocation(),
880  Context.ErrorOnTagTypeMismatch
881  ? diag::err_odr_tag_type_inconsistent
882  : diag::warn_odr_tag_type_inconsistent)
883  << Context.ToCtx.getTypeDeclType(Owner2);
884  Context.Diag2(Field2->getLocation(), diag::note_odr_field)
885  << Field2->getDeclName() << Field2->getType();
886  Context.Diag1(Field1->getLocation(), diag::note_odr_field)
887  << Field1->getDeclName() << Field1->getType();
888  }
889  return false;
890  }
891 
892  if (Field1->isBitField() != Field2->isBitField()) {
893  if (Context.Complain) {
894  Context.Diag2(Owner2->getLocation(),
895  Context.ErrorOnTagTypeMismatch
896  ? diag::err_odr_tag_type_inconsistent
897  : diag::warn_odr_tag_type_inconsistent)
898  << Context.ToCtx.getTypeDeclType(Owner2);
899  if (Field1->isBitField()) {
900  Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field)
901  << Field1->getDeclName() << Field1->getType()
902  << Field1->getBitWidthValue(Context.FromCtx);
903  Context.Diag2(Field2->getLocation(), diag::note_odr_not_bit_field)
904  << Field2->getDeclName();
905  } else {
906  Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field)
907  << Field2->getDeclName() << Field2->getType()
908  << Field2->getBitWidthValue(Context.ToCtx);
909  Context.Diag1(Field1->getLocation(), diag::note_odr_not_bit_field)
910  << Field1->getDeclName();
911  }
912  }
913  return false;
914  }
915 
916  if (Field1->isBitField()) {
917  // Make sure that the bit-fields are the same length.
918  unsigned Bits1 = Field1->getBitWidthValue(Context.FromCtx);
919  unsigned Bits2 = Field2->getBitWidthValue(Context.ToCtx);
920 
921  if (Bits1 != Bits2) {
922  if (Context.Complain) {
923  Context.Diag2(Owner2->getLocation(),
924  Context.ErrorOnTagTypeMismatch
925  ? diag::err_odr_tag_type_inconsistent
926  : diag::warn_odr_tag_type_inconsistent)
927  << Context.ToCtx.getTypeDeclType(Owner2);
928  Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field)
929  << Field2->getDeclName() << Field2->getType() << Bits2;
930  Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field)
931  << Field1->getDeclName() << Field1->getType() << Bits1;
932  }
933  return false;
934  }
935  }
936 
937  return true;
938 }
939 
940 /// Determine structural equivalence of two methods.
942  CXXMethodDecl *Method1,
943  CXXMethodDecl *Method2) {
944  bool PropertiesEqual =
945  Method1->getDeclKind() == Method2->getDeclKind() &&
946  Method1->getRefQualifier() == Method2->getRefQualifier() &&
947  Method1->getAccess() == Method2->getAccess() &&
948  Method1->getOverloadedOperator() == Method2->getOverloadedOperator() &&
949  Method1->isStatic() == Method2->isStatic() &&
950  Method1->isConst() == Method2->isConst() &&
951  Method1->isVolatile() == Method2->isVolatile() &&
952  Method1->isVirtual() == Method2->isVirtual() &&
953  Method1->isPure() == Method2->isPure() &&
954  Method1->isDefaulted() == Method2->isDefaulted() &&
955  Method1->isDeleted() == Method2->isDeleted();
956  if (!PropertiesEqual)
957  return false;
958  // FIXME: Check for 'final'.
959 
960  if (auto *Constructor1 = dyn_cast<CXXConstructorDecl>(Method1)) {
961  auto *Constructor2 = cast<CXXConstructorDecl>(Method2);
962  if (Constructor1->isExplicit() != Constructor2->isExplicit())
963  return false;
964  }
965 
966  if (auto *Conversion1 = dyn_cast<CXXConversionDecl>(Method1)) {
967  auto *Conversion2 = cast<CXXConversionDecl>(Method2);
968  if (Conversion1->isExplicit() != Conversion2->isExplicit())
969  return false;
970  if (!IsStructurallyEquivalent(Context, Conversion1->getConversionType(),
971  Conversion2->getConversionType()))
972  return false;
973  }
974 
975  const IdentifierInfo *Name1 = Method1->getIdentifier();
976  const IdentifierInfo *Name2 = Method2->getIdentifier();
977  if (!::IsStructurallyEquivalent(Name1, Name2)) {
978  return false;
979  // TODO: Names do not match, add warning like at check for FieldDecl.
980  }
981 
982  // Check the prototypes.
983  if (!::IsStructurallyEquivalent(Context,
984  Method1->getType(), Method2->getType()))
985  return false;
986 
987  return true;
988 }
989 
990 /// Determine structural equivalence of two records.
992  RecordDecl *D1, RecordDecl *D2) {
993  if (D1->isUnion() != D2->isUnion()) {
994  if (Context.Complain) {
995  Context.Diag2(D2->getLocation(),
996  Context.ErrorOnTagTypeMismatch
997  ? diag::err_odr_tag_type_inconsistent
998  : diag::warn_odr_tag_type_inconsistent)
999  << Context.ToCtx.getTypeDeclType(D2);
1000  Context.Diag1(D1->getLocation(), diag::note_odr_tag_kind_here)
1001  << D1->getDeclName() << (unsigned)D1->getTagKind();
1002  }
1003  return false;
1004  }
1005 
1006  if (!D1->getDeclName() && !D2->getDeclName()) {
1007  // If both anonymous structs/unions are in a record context, make sure
1008  // they occur in the same location in the context records.
1009  if (Optional<unsigned> Index1 =
1011  if (Optional<unsigned> Index2 =
1013  D2)) {
1014  if (*Index1 != *Index2)
1015  return false;
1016  }
1017  }
1018  }
1019 
1020  // If both declarations are class template specializations, we know
1021  // the ODR applies, so check the template and template arguments.
1022  const auto *Spec1 = dyn_cast<ClassTemplateSpecializationDecl>(D1);
1023  const auto *Spec2 = dyn_cast<ClassTemplateSpecializationDecl>(D2);
1024  if (Spec1 && Spec2) {
1025  // Check that the specialized templates are the same.
1026  if (!IsStructurallyEquivalent(Context, Spec1->getSpecializedTemplate(),
1027  Spec2->getSpecializedTemplate()))
1028  return false;
1029 
1030  // Check that the template arguments are the same.
1031  if (Spec1->getTemplateArgs().size() != Spec2->getTemplateArgs().size())
1032  return false;
1033 
1034  for (unsigned I = 0, N = Spec1->getTemplateArgs().size(); I != N; ++I)
1035  if (!IsStructurallyEquivalent(Context, Spec1->getTemplateArgs().get(I),
1036  Spec2->getTemplateArgs().get(I)))
1037  return false;
1038  }
1039  // If one is a class template specialization and the other is not, these
1040  // structures are different.
1041  else if (Spec1 || Spec2)
1042  return false;
1043 
1044  // Compare the definitions of these two records. If either or both are
1045  // incomplete (i.e. it is a forward decl), we assume that they are
1046  // equivalent.
1047  D1 = D1->getDefinition();
1048  D2 = D2->getDefinition();
1049  if (!D1 || !D2)
1050  return true;
1051 
1052  // If any of the records has external storage and we do a minimal check (or
1053  // AST import) we assume they are equivalent. (If we didn't have this
1054  // assumption then `RecordDecl::LoadFieldsFromExternalStorage` could trigger
1055  // another AST import which in turn would call the structural equivalency
1056  // check again and finally we'd have an improper result.)
1059  return true;
1060 
1061  // If one definition is currently being defined, we do not compare for
1062  // equality and we assume that the decls are equal.
1063  if (D1->isBeingDefined() || D2->isBeingDefined())
1064  return true;
1065 
1066  if (auto *D1CXX = dyn_cast<CXXRecordDecl>(D1)) {
1067  if (auto *D2CXX = dyn_cast<CXXRecordDecl>(D2)) {
1068  if (D1CXX->hasExternalLexicalStorage() &&
1069  !D1CXX->isCompleteDefinition()) {
1070  D1CXX->getASTContext().getExternalSource()->CompleteType(D1CXX);
1071  }
1072 
1073  if (D1CXX->getNumBases() != D2CXX->getNumBases()) {
1074  if (Context.Complain) {
1075  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1076  << Context.ToCtx.getTypeDeclType(D2);
1077  Context.Diag2(D2->getLocation(), diag::note_odr_number_of_bases)
1078  << D2CXX->getNumBases();
1079  Context.Diag1(D1->getLocation(), diag::note_odr_number_of_bases)
1080  << D1CXX->getNumBases();
1081  }
1082  return false;
1083  }
1084 
1085  // Check the base classes.
1086  for (CXXRecordDecl::base_class_iterator Base1 = D1CXX->bases_begin(),
1087  BaseEnd1 = D1CXX->bases_end(),
1088  Base2 = D2CXX->bases_begin();
1089  Base1 != BaseEnd1; ++Base1, ++Base2) {
1090  if (!IsStructurallyEquivalent(Context, Base1->getType(),
1091  Base2->getType())) {
1092  if (Context.Complain) {
1093  Context.Diag2(D2->getLocation(),
1094  diag::warn_odr_tag_type_inconsistent)
1095  << Context.ToCtx.getTypeDeclType(D2);
1096  Context.Diag2(Base2->getBeginLoc(), diag::note_odr_base)
1097  << Base2->getType() << Base2->getSourceRange();
1098  Context.Diag1(Base1->getBeginLoc(), diag::note_odr_base)
1099  << Base1->getType() << Base1->getSourceRange();
1100  }
1101  return false;
1102  }
1103 
1104  // Check virtual vs. non-virtual inheritance mismatch.
1105  if (Base1->isVirtual() != Base2->isVirtual()) {
1106  if (Context.Complain) {
1107  Context.Diag2(D2->getLocation(),
1108  diag::warn_odr_tag_type_inconsistent)
1109  << Context.ToCtx.getTypeDeclType(D2);
1110  Context.Diag2(Base2->getBeginLoc(), diag::note_odr_virtual_base)
1111  << Base2->isVirtual() << Base2->getSourceRange();
1112  Context.Diag1(Base1->getBeginLoc(), diag::note_odr_base)
1113  << Base1->isVirtual() << Base1->getSourceRange();
1114  }
1115  return false;
1116  }
1117  }
1118 
1119  // Check the friends for consistency.
1120  CXXRecordDecl::friend_iterator Friend2 = D2CXX->friend_begin(),
1121  Friend2End = D2CXX->friend_end();
1122  for (CXXRecordDecl::friend_iterator Friend1 = D1CXX->friend_begin(),
1123  Friend1End = D1CXX->friend_end();
1124  Friend1 != Friend1End; ++Friend1, ++Friend2) {
1125  if (Friend2 == Friend2End) {
1126  if (Context.Complain) {
1127  Context.Diag2(D2->getLocation(),
1128  diag::warn_odr_tag_type_inconsistent)
1129  << Context.ToCtx.getTypeDeclType(D2CXX);
1130  Context.Diag1((*Friend1)->getFriendLoc(), diag::note_odr_friend);
1131  Context.Diag2(D2->getLocation(), diag::note_odr_missing_friend);
1132  }
1133  return false;
1134  }
1135 
1136  if (!IsStructurallyEquivalent(Context, *Friend1, *Friend2)) {
1137  if (Context.Complain) {
1138  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1139  << Context.ToCtx.getTypeDeclType(D2CXX);
1140  Context.Diag1((*Friend1)->getFriendLoc(), diag::note_odr_friend);
1141  Context.Diag2((*Friend2)->getFriendLoc(), diag::note_odr_friend);
1142  }
1143  return false;
1144  }
1145  }
1146 
1147  if (Friend2 != Friend2End) {
1148  if (Context.Complain) {
1149  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1150  << Context.ToCtx.getTypeDeclType(D2);
1151  Context.Diag2((*Friend2)->getFriendLoc(), diag::note_odr_friend);
1152  Context.Diag1(D1->getLocation(), diag::note_odr_missing_friend);
1153  }
1154  return false;
1155  }
1156  } else if (D1CXX->getNumBases() > 0) {
1157  if (Context.Complain) {
1158  Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
1159  << Context.ToCtx.getTypeDeclType(D2);
1160  const CXXBaseSpecifier *Base1 = D1CXX->bases_begin();
1161  Context.Diag1(Base1->getBeginLoc(), diag::note_odr_base)
1162  << Base1->getType() << Base1->getSourceRange();
1163  Context.Diag2(D2->getLocation(), diag::note_odr_missing_base);
1164  }
1165  return false;
1166  }
1167  }
1168 
1169  // Check the fields for consistency.
1170  RecordDecl::field_iterator Field2 = D2->field_begin(),
1171  Field2End = D2->field_end();
1172  for (RecordDecl::field_iterator Field1 = D1->field_begin(),
1173  Field1End = D1->field_end();
1174  Field1 != Field1End; ++Field1, ++Field2) {
1175  if (Field2 == Field2End) {
1176  if (Context.Complain) {
1177  Context.Diag2(D2->getLocation(),
1178  Context.ErrorOnTagTypeMismatch
1179  ? diag::err_odr_tag_type_inconsistent
1180  : diag::warn_odr_tag_type_inconsistent)
1181  << Context.ToCtx.getTypeDeclType(D2);
1182  Context.Diag1(Field1->getLocation(), diag::note_odr_field)
1183  << Field1->getDeclName() << Field1->getType();
1184  Context.Diag2(D2->getLocation(), diag::note_odr_missing_field);
1185  }
1186  return false;
1187  }
1188 
1189  if (!IsStructurallyEquivalent(Context, *Field1, *Field2))
1190  return false;
1191  }
1192 
1193  if (Field2 != Field2End) {
1194  if (Context.Complain) {
1195  Context.Diag2(D2->getLocation(),
1196  Context.ErrorOnTagTypeMismatch
1197  ? diag::err_odr_tag_type_inconsistent
1198  : diag::warn_odr_tag_type_inconsistent)
1199  << Context.ToCtx.getTypeDeclType(D2);
1200  Context.Diag2(Field2->getLocation(), diag::note_odr_field)
1201  << Field2->getDeclName() << Field2->getType();
1202  Context.Diag1(D1->getLocation(), diag::note_odr_missing_field);
1203  }
1204  return false;
1205  }
1206 
1207  return true;
1208 }
1209 
1210 /// Determine structural equivalence of two enums.
1212  EnumDecl *D1, EnumDecl *D2) {
1213 
1214  // Compare the definitions of these two enums. If either or both are
1215  // incomplete (i.e. forward declared), we assume that they are equivalent.
1216  D1 = D1->getDefinition();
1217  D2 = D2->getDefinition();
1218  if (!D1 || !D2)
1219  return true;
1220 
1222  EC2End = D2->enumerator_end();
1224  EC1End = D1->enumerator_end();
1225  EC1 != EC1End; ++EC1, ++EC2) {
1226  if (EC2 == EC2End) {
1227  if (Context.Complain) {
1228  Context.Diag2(D2->getLocation(),
1229  Context.ErrorOnTagTypeMismatch
1230  ? diag::err_odr_tag_type_inconsistent
1231  : diag::warn_odr_tag_type_inconsistent)
1232  << Context.ToCtx.getTypeDeclType(D2);
1233  Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator)
1234  << EC1->getDeclName() << EC1->getInitVal().toString(10);
1235  Context.Diag2(D2->getLocation(), diag::note_odr_missing_enumerator);
1236  }
1237  return false;
1238  }
1239 
1240  llvm::APSInt Val1 = EC1->getInitVal();
1241  llvm::APSInt Val2 = EC2->getInitVal();
1242  if (!llvm::APSInt::isSameValue(Val1, Val2) ||
1243  !IsStructurallyEquivalent(EC1->getIdentifier(), EC2->getIdentifier())) {
1244  if (Context.Complain) {
1245  Context.Diag2(D2->getLocation(),
1246  Context.ErrorOnTagTypeMismatch
1247  ? diag::err_odr_tag_type_inconsistent
1248  : diag::warn_odr_tag_type_inconsistent)
1249  << Context.ToCtx.getTypeDeclType(D2);
1250  Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator)
1251  << EC2->getDeclName() << EC2->getInitVal().toString(10);
1252  Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator)
1253  << EC1->getDeclName() << EC1->getInitVal().toString(10);
1254  }
1255  return false;
1256  }
1257  }
1258 
1259  if (EC2 != EC2End) {
1260  if (Context.Complain) {
1261  Context.Diag2(D2->getLocation(),
1262  Context.ErrorOnTagTypeMismatch
1263  ? diag::err_odr_tag_type_inconsistent
1264  : diag::warn_odr_tag_type_inconsistent)
1265  << Context.ToCtx.getTypeDeclType(D2);
1266  Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator)
1267  << EC2->getDeclName() << EC2->getInitVal().toString(10);
1268  Context.Diag1(D1->getLocation(), diag::note_odr_missing_enumerator);
1269  }
1270  return false;
1271  }
1272 
1273  return true;
1274 }
1275 
1277  TemplateParameterList *Params1,
1278  TemplateParameterList *Params2) {
1279  if (Params1->size() != Params2->size()) {
1280  if (Context.Complain) {
1281  Context.Diag2(Params2->getTemplateLoc(),
1282  diag::err_odr_different_num_template_parameters)
1283  << Params1->size() << Params2->size();
1284  Context.Diag1(Params1->getTemplateLoc(),
1285  diag::note_odr_template_parameter_list);
1286  }
1287  return false;
1288  }
1289 
1290  for (unsigned I = 0, N = Params1->size(); I != N; ++I) {
1291  if (Params1->getParam(I)->getKind() != Params2->getParam(I)->getKind()) {
1292  if (Context.Complain) {
1293  Context.Diag2(Params2->getParam(I)->getLocation(),
1294  diag::err_odr_different_template_parameter_kind);
1295  Context.Diag1(Params1->getParam(I)->getLocation(),
1296  diag::note_odr_template_parameter_here);
1297  }
1298  return false;
1299  }
1300 
1301  if (!IsStructurallyEquivalent(Context, Params1->getParam(I),
1302  Params2->getParam(I)))
1303  return false;
1304  }
1305 
1306  return true;
1307 }
1308 
1311  TemplateTypeParmDecl *D2) {
1312  if (D1->isParameterPack() != D2->isParameterPack()) {
1313  if (Context.Complain) {
1314  Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack)
1315  << D2->isParameterPack();
1316  Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
1317  << D1->isParameterPack();
1318  }
1319  return false;
1320  }
1321 
1322  return true;
1323 }
1324 
1328  if (D1->isParameterPack() != D2->isParameterPack()) {
1329  if (Context.Complain) {
1330  Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack)
1331  << D2->isParameterPack();
1332  Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
1333  << D1->isParameterPack();
1334  }
1335  return false;
1336  }
1337 
1338  // Check types.
1339  if (!IsStructurallyEquivalent(Context, D1->getType(), D2->getType())) {
1340  if (Context.Complain) {
1341  Context.Diag2(D2->getLocation(),
1342  diag::err_odr_non_type_parameter_type_inconsistent)
1343  << D2->getType() << D1->getType();
1344  Context.Diag1(D1->getLocation(), diag::note_odr_value_here)
1345  << D1->getType();
1346  }
1347  return false;
1348  }
1349 
1350  return true;
1351 }
1352 
1356  if (D1->isParameterPack() != D2->isParameterPack()) {
1357  if (Context.Complain) {
1358  Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack)
1359  << D2->isParameterPack();
1360  Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
1361  << D1->isParameterPack();
1362  }
1363  return false;
1364  }
1365 
1366  // Check template parameter lists.
1367  return IsStructurallyEquivalent(Context, D1->getTemplateParameters(),
1368  D2->getTemplateParameters());
1369 }
1370 
1374  return false;
1375  if (!D1->getIdentifier()) // Special name
1376  if (D1->getNameAsString() != D2->getNameAsString())
1377  return false;
1379  D2->getTemplateParameters());
1380 }
1381 
1383  ClassTemplateDecl *D1,
1384  ClassTemplateDecl *D2) {
1385  // Check template parameters.
1386  if (!IsTemplateDeclCommonStructurallyEquivalent(Context, D1, D2))
1387  return false;
1388 
1389  // Check the templated declaration.
1390  return IsStructurallyEquivalent(Context, D1->getTemplatedDecl(),
1391  D2->getTemplatedDecl());
1392 }
1393 
1396  FunctionTemplateDecl *D2) {
1397  // Check template parameters.
1398  if (!IsTemplateDeclCommonStructurallyEquivalent(Context, D1, D2))
1399  return false;
1400 
1401  // Check the templated declaration.
1402  return IsStructurallyEquivalent(Context, D1->getTemplatedDecl()->getType(),
1403  D2->getTemplatedDecl()->getType());
1404 }
1405 
1407  FriendDecl *D1, FriendDecl *D2) {
1408  if ((D1->getFriendType() && D2->getFriendDecl()) ||
1409  (D1->getFriendDecl() && D2->getFriendType())) {
1410  return false;
1411  }
1412  if (D1->getFriendType() && D2->getFriendType())
1413  return IsStructurallyEquivalent(Context,
1414  D1->getFriendType()->getType(),
1415  D2->getFriendType()->getType());
1416  if (D1->getFriendDecl() && D2->getFriendDecl())
1417  return IsStructurallyEquivalent(Context, D1->getFriendDecl(),
1418  D2->getFriendDecl());
1419  return false;
1420 }
1421 
1423  FunctionDecl *D1, FunctionDecl *D2) {
1424  // FIXME: Consider checking for function attributes as well.
1425  if (!IsStructurallyEquivalent(Context, D1->getType(), D2->getType()))
1426  return false;
1427 
1428  return true;
1429 }
1430 
1431 /// Determine structural equivalence of two declarations.
1433  Decl *D1, Decl *D2) {
1434  // FIXME: Check for known structural equivalences via a callback of some sort.
1435 
1436  // Check whether we already know that these two declarations are not
1437  // structurally equivalent.
1438  if (Context.NonEquivalentDecls.count(
1439  std::make_pair(D1->getCanonicalDecl(), D2->getCanonicalDecl())))
1440  return false;
1441 
1442  // Determine whether we've already produced a tentative equivalence for D1.
1443  Decl *&EquivToD1 = Context.TentativeEquivalences[D1->getCanonicalDecl()];
1444  if (EquivToD1)
1445  return EquivToD1 == D2->getCanonicalDecl();
1446 
1447  // Produce a tentative equivalence D1 <-> D2, which will be checked later.
1448  EquivToD1 = D2->getCanonicalDecl();
1449  Context.DeclsToCheck.push_back(D1->getCanonicalDecl());
1450  return true;
1451 }
1452 
1454  unsigned DiagID) {
1455  assert(Complain && "Not allowed to complain");
1456  if (LastDiagFromC2)
1458  LastDiagFromC2 = false;
1459  return FromCtx.getDiagnostics().Report(Loc, DiagID);
1460 }
1461 
1463  unsigned DiagID) {
1464  assert(Complain && "Not allowed to complain");
1465  if (!LastDiagFromC2)
1467  LastDiagFromC2 = true;
1468  return ToCtx.getDiagnostics().Report(Loc, DiagID);
1469 }
1470 
1473  ASTContext &Context = Anon->getASTContext();
1474  QualType AnonTy = Context.getRecordType(Anon);
1475 
1476  const auto *Owner = dyn_cast<RecordDecl>(Anon->getDeclContext());
1477  if (!Owner)
1478  return None;
1479 
1480  unsigned Index = 0;
1481  for (const auto *D : Owner->noload_decls()) {
1482  const auto *F = dyn_cast<FieldDecl>(D);
1483  if (!F)
1484  continue;
1485 
1486  if (F->isAnonymousStructOrUnion()) {
1487  if (Context.hasSameType(F->getType(), AnonTy))
1488  break;
1489  ++Index;
1490  continue;
1491  }
1492 
1493  // If the field looks like this:
1494  // struct { ... } A;
1495  QualType FieldType = F->getType();
1496  // In case of nested structs.
1497  while (const auto *ElabType = dyn_cast<ElaboratedType>(FieldType))
1498  FieldType = ElabType->getNamedType();
1499 
1500  if (const auto *RecType = dyn_cast<RecordType>(FieldType)) {
1501  const RecordDecl *RecDecl = RecType->getDecl();
1502  if (RecDecl->getDeclContext() == Owner && !RecDecl->getIdentifier()) {
1503  if (Context.hasSameType(FieldType, AnonTy))
1504  break;
1505  ++Index;
1506  continue;
1507  }
1508  }
1509  }
1510 
1511  return Index;
1512 }
1513 
1515 
1516  // Ensure that the implementation functions (all static functions in this TU)
1517  // never call the public ASTStructuralEquivalence::IsEquivalent() functions,
1518  // because that will wreak havoc the internal state (DeclsToCheck and
1519  // TentativeEquivalences members) and can cause faulty behaviour. For
1520  // instance, some leaf declarations can be stated and cached as inequivalent
1521  // as a side effect of one inequivalent element in the DeclsToCheck list.
1522  assert(DeclsToCheck.empty());
1523  assert(TentativeEquivalences.empty());
1524 
1525  if (!::IsStructurallyEquivalent(*this, D1, D2))
1526  return false;
1527 
1528  return !Finish();
1529 }
1530 
1532  assert(DeclsToCheck.empty());
1533  assert(TentativeEquivalences.empty());
1534  if (!::IsStructurallyEquivalent(*this, T1, T2))
1535  return false;
1536 
1537  return !Finish();
1538 }
1539 
1540 bool StructuralEquivalenceContext::CheckCommonEquivalence(Decl *D1, Decl *D2) {
1541  // Check for equivalent described template.
1542  TemplateDecl *Template1 = D1->getDescribedTemplate();
1543  TemplateDecl *Template2 = D2->getDescribedTemplate();
1544  if ((Template1 != nullptr) != (Template2 != nullptr))
1545  return false;
1546  if (Template1 && !IsStructurallyEquivalent(*this, Template1, Template2))
1547  return false;
1548 
1549  // FIXME: Move check for identifier names into this function.
1550 
1551  return true;
1552 }
1553 
1554 bool StructuralEquivalenceContext::CheckKindSpecificEquivalence(
1555  Decl *D1, Decl *D2) {
1556  // FIXME: Switch on all declaration kinds. For now, we're just going to
1557  // check the obvious ones.
1558  if (auto *Record1 = dyn_cast<RecordDecl>(D1)) {
1559  if (auto *Record2 = dyn_cast<RecordDecl>(D2)) {
1560  // Check for equivalent structure names.
1561  IdentifierInfo *Name1 = Record1->getIdentifier();
1562  if (!Name1 && Record1->getTypedefNameForAnonDecl())
1563  Name1 = Record1->getTypedefNameForAnonDecl()->getIdentifier();
1564  IdentifierInfo *Name2 = Record2->getIdentifier();
1565  if (!Name2 && Record2->getTypedefNameForAnonDecl())
1566  Name2 = Record2->getTypedefNameForAnonDecl()->getIdentifier();
1567  if (!::IsStructurallyEquivalent(Name1, Name2) ||
1568  !::IsStructurallyEquivalent(*this, Record1, Record2))
1569  return false;
1570  } else {
1571  // Record/non-record mismatch.
1572  return false;
1573  }
1574  } else if (auto *Enum1 = dyn_cast<EnumDecl>(D1)) {
1575  if (auto *Enum2 = dyn_cast<EnumDecl>(D2)) {
1576  // Check for equivalent enum names.
1577  IdentifierInfo *Name1 = Enum1->getIdentifier();
1578  if (!Name1 && Enum1->getTypedefNameForAnonDecl())
1579  Name1 = Enum1->getTypedefNameForAnonDecl()->getIdentifier();
1580  IdentifierInfo *Name2 = Enum2->getIdentifier();
1581  if (!Name2 && Enum2->getTypedefNameForAnonDecl())
1582  Name2 = Enum2->getTypedefNameForAnonDecl()->getIdentifier();
1583  if (!::IsStructurallyEquivalent(Name1, Name2) ||
1584  !::IsStructurallyEquivalent(*this, Enum1, Enum2))
1585  return false;
1586  } else {
1587  // Enum/non-enum mismatch
1588  return false;
1589  }
1590  } else if (const auto *Typedef1 = dyn_cast<TypedefNameDecl>(D1)) {
1591  if (const auto *Typedef2 = dyn_cast<TypedefNameDecl>(D2)) {
1592  if (!::IsStructurallyEquivalent(Typedef1->getIdentifier(),
1593  Typedef2->getIdentifier()) ||
1594  !::IsStructurallyEquivalent(*this, Typedef1->getUnderlyingType(),
1595  Typedef2->getUnderlyingType()))
1596  return false;
1597  } else {
1598  // Typedef/non-typedef mismatch.
1599  return false;
1600  }
1601  } else if (auto *ClassTemplate1 = dyn_cast<ClassTemplateDecl>(D1)) {
1602  if (auto *ClassTemplate2 = dyn_cast<ClassTemplateDecl>(D2)) {
1603  if (!::IsStructurallyEquivalent(*this, ClassTemplate1,
1604  ClassTemplate2))
1605  return false;
1606  } else {
1607  // Class template/non-class-template mismatch.
1608  return false;
1609  }
1610  } else if (auto *FunctionTemplate1 = dyn_cast<FunctionTemplateDecl>(D1)) {
1611  if (auto *FunctionTemplate2 = dyn_cast<FunctionTemplateDecl>(D2)) {
1612  if (!::IsStructurallyEquivalent(*this, FunctionTemplate1,
1613  FunctionTemplate2))
1614  return false;
1615  } else {
1616  // Class template/non-class-template mismatch.
1617  return false;
1618  }
1619  } else if (auto *TTP1 = dyn_cast<TemplateTypeParmDecl>(D1)) {
1620  if (auto *TTP2 = dyn_cast<TemplateTypeParmDecl>(D2)) {
1621  if (!::IsStructurallyEquivalent(*this, TTP1, TTP2))
1622  return false;
1623  } else {
1624  // Kind mismatch.
1625  return false;
1626  }
1627  } else if (auto *NTTP1 = dyn_cast<NonTypeTemplateParmDecl>(D1)) {
1628  if (auto *NTTP2 = dyn_cast<NonTypeTemplateParmDecl>(D2)) {
1629  if (!::IsStructurallyEquivalent(*this, NTTP1, NTTP2))
1630  return false;
1631  } else {
1632  // Kind mismatch.
1633  return false;
1634  }
1635  } else if (auto *TTP1 = dyn_cast<TemplateTemplateParmDecl>(D1)) {
1636  if (auto *TTP2 = dyn_cast<TemplateTemplateParmDecl>(D2)) {
1637  if (!::IsStructurallyEquivalent(*this, TTP1, TTP2))
1638  return false;
1639  } else {
1640  // Kind mismatch.
1641  return false;
1642  }
1643  } else if (auto *MD1 = dyn_cast<CXXMethodDecl>(D1)) {
1644  if (auto *MD2 = dyn_cast<CXXMethodDecl>(D2)) {
1645  if (!::IsStructurallyEquivalent(*this, MD1, MD2))
1646  return false;
1647  } else {
1648  // Kind mismatch.
1649  return false;
1650  }
1651  } else if (FunctionDecl *FD1 = dyn_cast<FunctionDecl>(D1)) {
1652  if (FunctionDecl *FD2 = dyn_cast<FunctionDecl>(D2)) {
1653  if (FD1->isOverloadedOperator()) {
1654  if (!FD2->isOverloadedOperator())
1655  return false;
1656  if (FD1->getOverloadedOperator() != FD2->getOverloadedOperator())
1657  return false;
1658  }
1659  if (!::IsStructurallyEquivalent(FD1->getIdentifier(),
1660  FD2->getIdentifier()))
1661  return false;
1662  if (!::IsStructurallyEquivalent(*this, FD1, FD2))
1663  return false;
1664  } else {
1665  // Kind mismatch.
1666  return false;
1667  }
1668  } else if (FriendDecl *FrD1 = dyn_cast<FriendDecl>(D1)) {
1669  if (FriendDecl *FrD2 = dyn_cast<FriendDecl>(D2)) {
1670  if (!::IsStructurallyEquivalent(*this, FrD1, FrD2))
1671  return false;
1672  } else {
1673  // Kind mismatch.
1674  return false;
1675  }
1676  }
1677 
1678  return true;
1679 }
1680 
1681 bool StructuralEquivalenceContext::Finish() {
1682  while (!DeclsToCheck.empty()) {
1683  // Check the next declaration.
1684  Decl *D1 = DeclsToCheck.front();
1685  DeclsToCheck.pop_front();
1686 
1687  Decl *D2 = TentativeEquivalences[D1];
1688  assert(D2 && "Unrecorded tentative equivalence?");
1689 
1690  bool Equivalent =
1691  CheckCommonEquivalence(D1, D2) && CheckKindSpecificEquivalence(D1, D2);
1692 
1693  if (!Equivalent) {
1694  // Note that these two declarations are not equivalent (and we already
1695  // know about it).
1696  NonEquivalentDecls.insert(
1697  std::make_pair(D1->getCanonicalDecl(), D2->getCanonicalDecl()));
1698  return true;
1699  }
1700  }
1701 
1702  return false;
1703 }
TemplateTemplateParmDecl * getParameterPack() const
Retrieve the template template parameter pack being substituted.
Definition: TemplateName.h:135
Defines the clang::ASTContext interface.
enumerator_iterator enumerator_end() const
Definition: Decl.h:3463
Represents a function declaration or definition.
Definition: Decl.h:1737
A (possibly-)qualified type.
Definition: Type.h:639
static llvm::Optional< unsigned > findUntaggedStructOrUnionIndex(RecordDecl *Anon)
Find the index of the given anonymous struct/union within its context.
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:494
bool getNoCfCheck() const
Definition: Type.h:3525
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:478
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
Definition: Type.h:939
C Language Family Type Representation.
Microsoft&#39;s &#39;__super&#39; specifier, stored as a CXXRecordDecl* of the class it appeared in...
The template argument is an expression, and we&#39;ve not resolved it to one of the other forms yet...
Definition: TemplateBase.h:86
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
bool isVirtual() const
Definition: DeclCXX.h:2093
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
Defines the C++ template declaration subclasses.
DiagnosticsEngine & getDiagnostics() const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1296
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2822
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:63
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:132
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:206
QualType getElementType() const
Definition: Type.h:2857
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:484
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:53
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:56
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
ASTContext & FromCtx
AST contexts for which we are checking structural equivalence.
A namespace, stored as a NamespaceDecl*.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:67
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
bool isStatic() const
Definition: DeclCXX.cpp:1882
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:314
DiagnosticBuilder Diag1(SourceLocation Loc, unsigned DiagID)
bool isAnonymousStructOrUnion() const
Determines whether this field is a representative for an anonymous struct or union.
Definition: Decl.cpp:3786
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:269
Represents a struct/union/class.
Definition: Decl.h:3592
An iterator over the friend declarations of a class.
Definition: DeclFriend.h:187
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:297
Represents a class template specialization, which refers to a class template with a given set of temp...
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:123
bool isConst() const
Definition: DeclCXX.h:2090
unsigned getRegParm() const
Definition: Type.h:3528
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:329
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:422
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:71
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:3773
bool ErrorOnTagTypeMismatch
Whether warn or error on tag type mismatches.
Represents a member of a struct/union/class.
Definition: Decl.h:2578
bool isVolatile() const
Definition: DeclCXX.h:2091
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
Defines the ExceptionSpecificationType enumeration and various utility functions. ...
DiagnosticBuilder Diag2(SourceLocation Loc, unsigned DiagID)
NamedDecl * getFriendDecl() const
If this friend declaration doesn&#39;t name a type, return the inner declaration.
Definition: DeclFriend.h:138
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:171
bool getProducesResult() const
Definition: Type.h:3523
bool StrictTypeSpelling
Whether we&#39;re being strict about the spelling of types when unifying two types.
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2656
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
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this method.
Definition: DeclCXX.h:2210
TagKind getTagKind() const
Definition: Decl.h:3242
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
field_iterator field_begin() const
Definition: Decl.cpp:4154
unsigned getBitWidthValue(const ASTContext &Ctx) const
Definition: Decl.cpp:3796
TemplateTemplateParmDecl * getParameter() const
Definition: TemplateName.h:338
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
bool getNoCallerSavedRegs() const
Definition: Type.h:3524
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:872
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1044
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any...
Definition: Decl.cpp:3303
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:202
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:263
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclCXX.h:235
static bool IsTemplateDeclCommonStructurallyEquivalent(StructuralEquivalenceContext &Ctx, TemplateDecl *D1, TemplateDecl *D2)
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:431
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
This represents one expression.
Definition: Expr.h:108
bool isDefaulted() const
Whether this function is defaulted per C++0x.
Definition: Decl.h:2033
Declaration of a template type parameter.
bool LastDiagFromC2
true if the last diagnostic came from ToCtx.
bool getHasRegParm() const
Definition: Type.h:3526
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6829
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:67
field_iterator field_end() const
Definition: Decl.h:3786
DeclContext * getDeclContext()
Definition: DeclBase.h:429
A structure for storing the information associated with a substituted template template parameter...
Definition: TemplateName.h:325
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
Definition: TemplateName.h:178
EnumDecl * getDefinition() const
Definition: Decl.h:3426
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:481
A namespace alias, stored as a NamespaceAliasDecl*.
static bool IsArrayStructurallyEquivalent(StructuralEquivalenceContext &Context, const ArrayType *Array1, const ArrayType *Array2)
Determine structural equivalence for the common part of array types.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
enumerator_iterator enumerator_begin() const
Definition: Decl.h:3456
QualType getRecordType(const RecordDecl *Decl) const
ArraySizeModifier getSizeModifier() const
Definition: Type.h:2859
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1395
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:704
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:388
A template template parameter pack that has been substituted for a template template argument pack...
Definition: TemplateName.h:211
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
Decl::Kind getDeclKind() const
Definition: DeclBase.h:1753
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template.
bool isParameterPack() const
Returns whether this is a parameter pack.
Encodes a location in the source.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
bool isPure() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2008
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, QualType T1, QualType T2)
Determine structural equivalence of two types.
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:121
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Definition: Decl.h:291
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:375
CallingConv getCC() const
Definition: Type.h:3535
static QualType getUnderlyingType(const SubRegion *R)
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2048
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
bool isOverloadedOperator() const
Determine whether this template name refers to an overloaded operator.
Definition: TemplateName.h:491
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:359
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2320
Qualifiers getIndexTypeQualifiers() const
Definition: Type.h:2863
TypeClass getTypeClass() const
Definition: Type.h:1818
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:300
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
StringRef getName() const
Return the actual identifier string.
Represents a template argument.
Definition: TemplateBase.h:50
Represents a template name that was expressed as a qualified name.
Definition: TemplateName.h:366
Dataflow Directional Tag Classes.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:398
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:79
AccessSpecifier getAccess() const
Definition: DeclBase.h:464
Kind getKind() const
Definition: DeclBase.h:423
Represents an enum.
Definition: Decl.h:3325
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1082
A type that was preceded by the &#39;template&#39; keyword, stored as a Type*.
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
Definition: TemplateBase.h:339
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
Definition: DeclBase.h:2025
bool IsEquivalent(Decl *D1, Decl *D2)
Determine whether the two declarations are structurally equivalent.
llvm::DenseSet< std::pair< Decl *, Decl * > > & NonEquivalentDecls
Declaration (from, to) pairs that are known not to be equivalent (which we have already complained ab...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4380
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2282
The template argument is a type.
Definition: TemplateBase.h:59
The template argument is actually a parameter pack.
Definition: TemplateBase.h:90
Represents a base class of a C++ class.
Definition: DeclCXX.h:191
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2266
llvm::DenseMap< Decl *, Decl * > TentativeEquivalences
The set of "tentative" equivalences between two canonical declarations, mapping from a declaration in...
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:234
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Defines the clang::SourceLocation class and associated facilities.
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:75
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6109
A structure for storing the information associated with an overloaded template name.
Definition: TemplateName.h:95
std::deque< Decl * > DeclsToCheck
Queue of declarations in the first context whose equivalence with a declaration in the second context...
Declaration of a class template.
NameKind getKind() const
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:957
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:256
bool isUnion() const
Definition: Decl.h:3251
TemplateDecl * getDecl() const
The template declaration that this qualified name refers to.
Definition: TemplateName.h:396
bool isDeleted() const
Whether this function has been deleted.
Definition: Decl.h:2135
bool Complain
Whether to complain about failures.
QualType getType() const
Definition: Decl.h:647
TemplateArgument getArgumentPack() const
Retrieve the template template argument pack with which this parameter was substituted.
A set of overloaded template declarations.
Definition: TemplateName.h:194
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration...
Definition: DeclBase.cpp:229
SourceRange getSourceRange() const LLVM_READONLY
Retrieves the source range that contains the entire base specifier.
Definition: DeclCXX.h:234
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:280
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:287
Declaration of a template function.
Definition: DeclTemplate.h:968
A class which abstracts out some details necessary for making a call.
Definition: Type.h:3476
SourceLocation getLocation() const
Definition: DeclBase.h:420
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:97
A single template declaration.
Definition: TemplateName.h:191
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3188
QualType getType() const
Retrieves the type of the base class.
Definition: DeclCXX.h:290
void notePriorDiagnosticFrom(const DiagnosticsEngine &Other)
Note that the prior diagnostic was emitted by some other DiagnosticsEngine, and we may be attaching a...
Definition: Diagnostic.h:800