Coverage Report

Created: 2020-02-15 09:57

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/ASTStructuralEquivalence.cpp
Line
Count
Source (jump to first uncovered line)
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
67
#include "clang/AST/ASTStructuralEquivalence.h"
68
#include "clang/AST/ASTContext.h"
69
#include "clang/AST/ASTDiagnostic.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"
76
#include "clang/AST/ExprCXX.h"
77
#include "clang/AST/NestedNameSpecifier.h"
78
#include "clang/AST/TemplateBase.h"
79
#include "clang/AST/TemplateName.h"
80
#include "clang/AST/Type.h"
81
#include "clang/Basic/ExceptionSpecificationType.h"
82
#include "clang/Basic/IdentifierTable.h"
83
#include "clang/Basic/LLVM.h"
84
#include "clang/Basic/SourceLocation.h"
85
#include "llvm/ADT/APInt.h"
86
#include "llvm/ADT/APSInt.h"
87
#include "llvm/ADT/None.h"
88
#include "llvm/ADT/Optional.h"
89
#include "llvm/Support/Casting.h"
90
#include "llvm/Support/Compiler.h"
91
#include "llvm/Support/ErrorHandling.h"
92
#include <cassert>
93
#include <utility>
94
95
using namespace clang;
96
97
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
98
                                     QualType T1, QualType T2);
99
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
100
                                     Decl *D1, Decl *D2);
101
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
102
                                     const TemplateArgument &Arg1,
103
                                     const TemplateArgument &Arg2);
104
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
105
                                     NestedNameSpecifier *NNS1,
106
                                     NestedNameSpecifier *NNS2);
107
static bool IsStructurallyEquivalent(const IdentifierInfo *Name1,
108
                                     const IdentifierInfo *Name2);
109
110
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
111
                                     const DeclarationName Name1,
112
6
                                     const DeclarationName Name2) {
113
6
  if (Name1.getNameKind() != Name2.getNameKind())
114
0
    return false;
115
6
116
6
  switch (Name1.getNameKind()) {
117
0
118
6
  case DeclarationName::Identifier:
119
6
    return IsStructurallyEquivalent(Name1.getAsIdentifierInfo(),
120
6
                                    Name2.getAsIdentifierInfo());
121
0
122
0
  case DeclarationName::CXXConstructorName:
123
0
  case DeclarationName::CXXDestructorName:
124
0
  case DeclarationName::CXXConversionFunctionName:
125
0
    return IsStructurallyEquivalent(Context, Name1.getCXXNameType(),
126
0
                                    Name2.getCXXNameType());
127
0
128
0
  case DeclarationName::CXXDeductionGuideName: {
129
0
    if (!IsStructurallyEquivalent(
130
0
            Context, Name1.getCXXDeductionGuideTemplate()->getDeclName(),
131
0
            Name2.getCXXDeductionGuideTemplate()->getDeclName()))
132
0
      return false;
133
0
    return IsStructurallyEquivalent(Context,
134
0
                                    Name1.getCXXDeductionGuideTemplate(),
135
0
                                    Name2.getCXXDeductionGuideTemplate());
136
0
  }
137
0
138
0
  case DeclarationName::CXXOperatorName:
139
0
    return Name1.getCXXOverloadedOperator() == Name2.getCXXOverloadedOperator();
140
0
141
0
  case DeclarationName::CXXLiteralOperatorName:
142
0
    return IsStructurallyEquivalent(Name1.getCXXLiteralIdentifier(),
143
0
                                    Name2.getCXXLiteralIdentifier());
144
0
145
0
  case DeclarationName::CXXUsingDirective:
146
0
    return true; // FIXME When do we consider two using directives equal?
147
0
148
0
  case DeclarationName::ObjCZeroArgSelector:
149
0
  case DeclarationName::ObjCOneArgSelector:
150
0
  case DeclarationName::ObjCMultiArgSelector:
151
0
    return true; // FIXME
152
0
  }
153
0
154
0
  llvm_unreachable("Unhandled kind of DeclarationName");
155
0
  return true;
156
0
}
157
158
/// Determine structural equivalence of two expressions.
159
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
160
20
                                     const Expr *E1, const Expr *E2) {
161
20
  if (!E1 || !E2)
162
0
    return E1 == E2;
163
20
164
20
  if (auto *DE1 = dyn_cast<DependentScopeDeclRefExpr>(E1)) {
165
6
    auto *DE2 = dyn_cast<DependentScopeDeclRefExpr>(E2);
166
6
    if (!DE2)
167
0
      return false;
168
6
    if (!IsStructurallyEquivalent(Context, DE1->getDeclName(),
169
6
                                  DE2->getDeclName()))
170
2
      return false;
171
4
    return IsStructurallyEquivalent(Context, DE1->getQualifier(),
172
4
                                    DE2->getQualifier());
173
14
  } else if (auto CastE1 = dyn_cast<ImplicitCastExpr>(E1)) {
174
6
    auto *CastE2 = dyn_cast<ImplicitCastExpr>(E2);
175
6
    if (!CastE2)
176
0
      return false;
177
6
    if (!IsStructurallyEquivalent(Context, CastE1->getType(),
178
6
                                  CastE2->getType()))
179
0
      return false;
180
6
    return IsStructurallyEquivalent(Context, CastE1->getSubExpr(),
181
6
                                    CastE2->getSubExpr());
182
6
  }
183
8
  // FIXME: Handle other kind of expressions!
184
8
  return true;
185
8
}
186
187
/// Determine whether two identifiers are equivalent.
188
static bool IsStructurallyEquivalent(const IdentifierInfo *Name1,
189
70.6k
                                     const IdentifierInfo *Name2) {
190
70.6k
  if (!Name1 || 
!Name252.3k
)
191
18.2k
    return Name1 == Name2;
192
52.3k
193
52.3k
  return Name1->getName() == Name2->getName();
194
52.3k
}
195
196
/// Determine whether two nested-name-specifiers are equivalent.
197
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
198
                                     NestedNameSpecifier *NNS1,
199
14
                                     NestedNameSpecifier *NNS2) {
200
14
  if (NNS1->getKind() != NNS2->getKind())
201
0
    return false;
202
14
203
14
  NestedNameSpecifier *Prefix1 = NNS1->getPrefix(),
204
14
                      *Prefix2 = NNS2->getPrefix();
205
14
  if ((bool)Prefix1 != (bool)Prefix2)
206
0
    return false;
207
14
208
14
  if (Prefix1)
209
0
    if (!IsStructurallyEquivalent(Context, Prefix1, Prefix2))
210
0
      return false;
211
14
212
14
  switch (NNS1->getKind()) {
213
0
  case NestedNameSpecifier::Identifier:
214
0
    return IsStructurallyEquivalent(NNS1->getAsIdentifier(),
215
0
                                    NNS2->getAsIdentifier());
216
0
  case NestedNameSpecifier::Namespace:
217
0
    return IsStructurallyEquivalent(Context, NNS1->getAsNamespace(),
218
0
                                    NNS2->getAsNamespace());
219
0
  case NestedNameSpecifier::NamespaceAlias:
220
0
    return IsStructurallyEquivalent(Context, NNS1->getAsNamespaceAlias(),
221
0
                                    NNS2->getAsNamespaceAlias());
222
14
  case NestedNameSpecifier::TypeSpec:
223
14
  case NestedNameSpecifier::TypeSpecWithTemplate:
224
14
    return IsStructurallyEquivalent(Context, QualType(NNS1->getAsType(), 0),
225
14
                                    QualType(NNS2->getAsType(), 0));
226
14
  case NestedNameSpecifier::Global:
227
0
    return true;
228
14
  case NestedNameSpecifier::Super:
229
0
    return IsStructurallyEquivalent(Context, NNS1->getAsRecordDecl(),
230
0
                                    NNS2->getAsRecordDecl());
231
0
  }
232
0
  return false;
233
0
}
234
235
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
236
                                     const TemplateName &N1,
237
28
                                     const TemplateName &N2) {
238
28
  TemplateDecl *TemplateDeclN1 = N1.getAsTemplateDecl();
239
28
  TemplateDecl *TemplateDeclN2 = N2.getAsTemplateDecl();
240
28
  if (TemplateDeclN1 && TemplateDeclN2) {
241
28
    if (!IsStructurallyEquivalent(Context, TemplateDeclN1, TemplateDeclN2))
242
0
      return false;
243
28
    // If the kind is different we compare only the template decl.
244
28
    if (N1.getKind() != N2.getKind())
245
8
      return true;
246
0
  } else if (TemplateDeclN1 || TemplateDeclN2)
247
0
    return false;
248
0
  else if (N1.getKind() != N2.getKind())
249
0
    return false;
250
20
251
20
  // Check for special case incompatibilities.
252
20
  switch (N1.getKind()) {
253
0
254
0
  case TemplateName::OverloadedTemplate: {
255
0
    OverloadedTemplateStorage *OS1 = N1.getAsOverloadedTemplate(),
256
0
                              *OS2 = N2.getAsOverloadedTemplate();
257
0
    OverloadedTemplateStorage::iterator I1 = OS1->begin(), I2 = OS2->begin(),
258
0
                                        E1 = OS1->end(), E2 = OS2->end();
259
0
    for (; I1 != E1 && I2 != E2; ++I1, ++I2)
260
0
      if (!IsStructurallyEquivalent(Context, *I1, *I2))
261
0
        return false;
262
0
    return I1 == E1 && I2 == E2;
263
0
  }
264
0
265
0
  case TemplateName::AssumedTemplate: {
266
0
    AssumedTemplateStorage *TN1 = N1.getAsAssumedTemplateName(),
267
0
                           *TN2 = N1.getAsAssumedTemplateName();
268
0
    return TN1->getDeclName() == TN2->getDeclName();
269
0
  }
270
0
271
0
  case TemplateName::DependentTemplate: {
272
0
    DependentTemplateName *DN1 = N1.getAsDependentTemplateName(),
273
0
                          *DN2 = N2.getAsDependentTemplateName();
274
0
    if (!IsStructurallyEquivalent(Context, DN1->getQualifier(),
275
0
                                  DN2->getQualifier()))
276
0
      return false;
277
0
    if (DN1->isIdentifier() && DN2->isIdentifier())
278
0
      return IsStructurallyEquivalent(DN1->getIdentifier(),
279
0
                                      DN2->getIdentifier());
280
0
    else if (DN1->isOverloadedOperator() && DN2->isOverloadedOperator())
281
0
      return DN1->getOperator() == DN2->getOperator();
282
0
    return false;
283
0
  }
284
0
285
0
  case TemplateName::SubstTemplateTemplateParmPack: {
286
0
    SubstTemplateTemplateParmPackStorage
287
0
        *P1 = N1.getAsSubstTemplateTemplateParmPack(),
288
0
        *P2 = N2.getAsSubstTemplateTemplateParmPack();
289
0
    return IsStructurallyEquivalent(Context, P1->getArgumentPack(),
290
0
                                    P2->getArgumentPack()) &&
291
0
           IsStructurallyEquivalent(Context, P1->getParameterPack(),
292
0
                                    P2->getParameterPack());
293
0
  }
294
0
295
20
   case TemplateName::Template:
296
20
   case TemplateName::QualifiedTemplate:
297
20
   case TemplateName::SubstTemplateTemplateParm:
298
20
     // It is sufficient to check value of getAsTemplateDecl.
299
20
     break;
300
20
301
20
  }
302
20
303
20
  return true;
304
20
}
305
306
/// Determine whether two template arguments are equivalent.
307
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
308
                                     const TemplateArgument &Arg1,
309
14.8k
                                     const TemplateArgument &Arg2) {
310
14.8k
  if (Arg1.getKind() != Arg2.getKind())
311
0
    return false;
312
14.8k
313
14.8k
  switch (Arg1.getKind()) {
314
0
  case TemplateArgument::Null:
315
0
    return true;
316
0
317
10.2k
  case TemplateArgument::Type:
318
10.2k
    return IsStructurallyEquivalent(Context, Arg1.getAsType(), Arg2.getAsType());
319
0
320
4.56k
  case TemplateArgument::Integral:
321
4.56k
    if (!IsStructurallyEquivalent(Context, Arg1.getIntegralType(),
322
4.56k
                                          Arg2.getIntegralType()))
323
0
      return false;
324
4.56k
325
4.56k
    return llvm::APSInt::isSameValue(Arg1.getAsIntegral(),
326
4.56k
                                     Arg2.getAsIntegral());
327
4.56k
328
4.56k
  case TemplateArgument::Declaration:
329
0
    return IsStructurallyEquivalent(Context, Arg1.getAsDecl(), Arg2.getAsDecl());
330
4.56k
331
4.56k
  case TemplateArgument::NullPtr:
332
0
    return true; // FIXME: Is this correct?
333
4.56k
334
4.56k
  case TemplateArgument::Template:
335
10
    return IsStructurallyEquivalent(Context, Arg1.getAsTemplate(),
336
10
                                    Arg2.getAsTemplate());
337
4.56k
338
4.56k
  case TemplateArgument::TemplateExpansion:
339
0
    return IsStructurallyEquivalent(Context,
340
0
                                    Arg1.getAsTemplateOrTemplatePattern(),
341
0
                                    Arg2.getAsTemplateOrTemplatePattern());
342
4.56k
343
4.56k
  case TemplateArgument::Expression:
344
12
    return IsStructurallyEquivalent(Context, Arg1.getAsExpr(),
345
12
                                    Arg2.getAsExpr());
346
4.56k
347
4.56k
  case TemplateArgument::Pack:
348
0
    if (Arg1.pack_size() != Arg2.pack_size())
349
0
      return false;
350
0
351
0
    for (unsigned I = 0, N = Arg1.pack_size(); I != N; ++I)
352
0
      if (!IsStructurallyEquivalent(Context, Arg1.pack_begin()[I],
353
0
                                    Arg2.pack_begin()[I]))
354
0
        return false;
355
0
356
0
    return true;
357
0
  }
358
0
359
0
  llvm_unreachable("Invalid template argument kind");
360
0
}
361
362
/// Determine structural equivalence for the common part of array
363
/// types.
364
static bool IsArrayStructurallyEquivalent(StructuralEquivalenceContext &Context,
365
                                          const ArrayType *Array1,
366
1.38k
                                          const ArrayType *Array2) {
367
1.38k
  if (!IsStructurallyEquivalent(Context, Array1->getElementType(),
368
1.38k
                                Array2->getElementType()))
369
0
    return false;
370
1.38k
  if (Array1->getSizeModifier() != Array2->getSizeModifier())
371
0
    return false;
372
1.38k
  if (Array1->getIndexTypeQualifiers() != Array2->getIndexTypeQualifiers())
373
0
    return false;
374
1.38k
375
1.38k
  return true;
376
1.38k
}
377
378
/// Determine structural equivalence based on the ExtInfo of functions. This
379
/// is inspired by ASTContext::mergeFunctionTypes(), we compare calling
380
/// conventions bits but must not compare some other bits.
381
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
382
                                     FunctionType::ExtInfo EI1,
383
5.05k
                                     FunctionType::ExtInfo EI2) {
384
5.05k
  // Compatible functions must have compatible calling conventions.
385
5.05k
  if (EI1.getCC() != EI2.getCC())
386
2
    return false;
387
5.05k
388
5.05k
  // Regparm is part of the calling convention.
389
5.05k
  if (EI1.getHasRegParm() != EI2.getHasRegParm())
390
0
    return false;
391
5.05k
  if (EI1.getRegParm() != EI2.getRegParm())
392
0
    return false;
393
5.05k
394
5.05k
  if (EI1.getProducesResult() != EI2.getProducesResult())
395
0
    return false;
396
5.05k
  if (EI1.getNoCallerSavedRegs() != EI2.getNoCallerSavedRegs())
397
2
    return false;
398
5.05k
  if (EI1.getNoCfCheck() != EI2.getNoCfCheck())
399
0
    return false;
400
5.05k
401
5.05k
  return true;
402
5.05k
}
403
404
/// Check the equivalence of exception specifications.
405
static bool IsEquivalentExceptionSpec(StructuralEquivalenceContext &Context,
406
                                      const FunctionProtoType *Proto1,
407
5.12k
                                      const FunctionProtoType *Proto2) {
408
5.12k
409
5.12k
  auto Spec1 = Proto1->getExceptionSpecType();
410
5.12k
  auto Spec2 = Proto2->getExceptionSpecType();
411
5.12k
412
5.12k
  if (isUnresolvedExceptionSpec(Spec1) || 
isUnresolvedExceptionSpec(Spec2)5.02k
)
413
121
    return true;
414
5.00k
415
5.00k
  if (Spec1 != Spec2)
416
87
    return false;
417
4.91k
  if (Spec1 == EST_Dynamic) {
418
0
    if (Proto1->getNumExceptions() != Proto2->getNumExceptions())
419
0
      return false;
420
0
    for (unsigned I = 0, N = Proto1->getNumExceptions(); I != N; ++I) {
421
0
      if (!IsStructurallyEquivalent(Context, Proto1->getExceptionType(I),
422
0
                                    Proto2->getExceptionType(I)))
423
0
        return false;
424
0
    }
425
4.91k
  } else if (isComputedNoexcept(Spec1)) {
426
2
    if (!IsStructurallyEquivalent(Context, Proto1->getNoexceptExpr(),
427
2
                                  Proto2->getNoexceptExpr()))
428
0
      return false;
429
4.91k
  }
430
4.91k
431
4.91k
  return true;
432
4.91k
}
433
434
/// Determine structural equivalence of two types.
435
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
436
108k
                                     QualType T1, QualType T2) {
437
108k
  if (T1.isNull() || T2.isNull())
438
0
    return T1.isNull() && T2.isNull();
439
108k
440
108k
  QualType OrigT1 = T1;
441
108k
  QualType OrigT2 = T2;
442
108k
443
108k
  if (!Context.StrictTypeSpelling) {
444
108k
    // We aren't being strict about token-to-token equivalence of types,
445
108k
    // so map down to the canonical type.
446
108k
    T1 = Context.FromCtx.getCanonicalType(T1);
447
108k
    T2 = Context.ToCtx.getCanonicalType(T2);
448
108k
  }
449
108k
450
108k
  if (T1.getQualifiers() != T2.getQualifiers())
451
406
    return false;
452
108k
453
108k
  Type::TypeClass TC = T1->getTypeClass();
454
108k
455
108k
  if (T1->getTypeClass() != T2->getTypeClass()) {
456
10.2k
    // Compare function types with prototypes vs. without prototypes as if
457
10.2k
    // both did not have prototypes.
458
10.2k
    if (T1->getTypeClass() == Type::FunctionProto &&
459
10.2k
        
T2->getTypeClass() == Type::FunctionNoProto2
)
460
2
      TC = Type::FunctionNoProto;
461
10.2k
    else if (T1->getTypeClass() == Type::FunctionNoProto &&
462
10.2k
             
T2->getTypeClass() == Type::FunctionProto0
)
463
0
      TC = Type::FunctionNoProto;
464
10.2k
    else
465
10.2k
      return false;
466
98.2k
  }
467
98.2k
468
98.2k
  switch (TC) {
469
27.5k
  case Type::Builtin:
470
27.5k
    // FIXME: Deal with Char_S/Char_U.
471
27.5k
    if (cast<BuiltinType>(T1)->getKind() != cast<BuiltinType>(T2)->getKind())
472
189
      return false;
473
27.3k
    break;
474
27.3k
475
27.3k
  case Type::Complex:
476
0
    if (!IsStructurallyEquivalent(Context,
477
0
                                  cast<ComplexType>(T1)->getElementType(),
478
0
                                  cast<ComplexType>(T2)->getElementType()))
479
0
      return false;
480
0
    break;
481
0
482
0
  case Type::Adjusted:
483
0
  case Type::Decayed:
484
0
    if (!IsStructurallyEquivalent(Context,
485
0
                                  cast<AdjustedType>(T1)->getOriginalType(),
486
0
                                  cast<AdjustedType>(T2)->getOriginalType()))
487
0
      return false;
488
0
    break;
489
0
490
3.40k
  case Type::Pointer:
491
3.40k
    if (!IsStructurallyEquivalent(Context,
492
3.40k
                                  cast<PointerType>(T1)->getPointeeType(),
493
3.40k
                                  cast<PointerType>(T2)->getPointeeType()))
494
2
      return false;
495
3.40k
    break;
496
3.40k
497
3.40k
  case Type::BlockPointer:
498
0
    if (!IsStructurallyEquivalent(Context,
499
0
                                  cast<BlockPointerType>(T1)->getPointeeType(),
500
0
                                  cast<BlockPointerType>(T2)->getPointeeType()))
501
0
      return false;
502
0
    break;
503
0
504
4.16k
  case Type::LValueReference:
505
4.16k
  case Type::RValueReference: {
506
4.16k
    const auto *Ref1 = cast<ReferenceType>(T1);
507
4.16k
    const auto *Ref2 = cast<ReferenceType>(T2);
508
4.16k
    if (Ref1->isSpelledAsLValue() != Ref2->isSpelledAsLValue())
509
0
      return false;
510
4.16k
    if (Ref1->isInnerRef() != Ref2->isInnerRef())
511
0
      return false;
512
4.16k
    if (!IsStructurallyEquivalent(Context, Ref1->getPointeeTypeAsWritten(),
513
4.16k
                                  Ref2->getPointeeTypeAsWritten()))
514
667
      return false;
515
3.49k
    break;
516
3.49k
  }
517
3.49k
518
3.49k
  case Type::MemberPointer: {
519
0
    const auto *MemPtr1 = cast<MemberPointerType>(T1);
520
0
    const auto *MemPtr2 = cast<MemberPointerType>(T2);
521
0
    if (!IsStructurallyEquivalent(Context, MemPtr1->getPointeeType(),
522
0
                                  MemPtr2->getPointeeType()))
523
0
      return false;
524
0
    if (!IsStructurallyEquivalent(Context, QualType(MemPtr1->getClass(), 0),
525
0
                                  QualType(MemPtr2->getClass(), 0)))
526
0
      return false;
527
0
    break;
528
0
  }
529
0
530
1.38k
  case Type::ConstantArray: {
531
1.38k
    const auto *Array1 = cast<ConstantArrayType>(T1);
532
1.38k
    const auto *Array2 = cast<ConstantArrayType>(T2);
533
1.38k
    if (!llvm::APInt::isSameValue(Array1->getSize(), Array2->getSize()))
534
1
      return false;
535
1.38k
536
1.38k
    if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
537
0
      return false;
538
1.38k
    break;
539
1.38k
  }
540
1.38k
541
1.38k
  case Type::IncompleteArray:
542
0
    if (!IsArrayStructurallyEquivalent(Context, cast<ArrayType>(T1),
543
0
                                       cast<ArrayType>(T2)))
544
0
      return false;
545
0
    break;
546
0
547
0
  case Type::VariableArray: {
548
0
    const auto *Array1 = cast<VariableArrayType>(T1);
549
0
    const auto *Array2 = cast<VariableArrayType>(T2);
550
0
    if (!IsStructurallyEquivalent(Context, Array1->getSizeExpr(),
551
0
                                  Array2->getSizeExpr()))
552
0
      return false;
553
0
554
0
    if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
555
0
      return false;
556
0
557
0
    break;
558
0
  }
559
0
560
0
  case Type::DependentSizedArray: {
561
0
    const auto *Array1 = cast<DependentSizedArrayType>(T1);
562
0
    const auto *Array2 = cast<DependentSizedArrayType>(T2);
563
0
    if (!IsStructurallyEquivalent(Context, Array1->getSizeExpr(),
564
0
                                  Array2->getSizeExpr()))
565
0
      return false;
566
0
567
0
    if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
568
0
      return false;
569
0
570
0
    break;
571
0
  }
572
0
573
0
  case Type::DependentAddressSpace: {
574
0
    const auto *DepAddressSpace1 = cast<DependentAddressSpaceType>(T1);
575
0
    const auto *DepAddressSpace2 = cast<DependentAddressSpaceType>(T2);
576
0
    if (!IsStructurallyEquivalent(Context, DepAddressSpace1->getAddrSpaceExpr(),
577
0
                                  DepAddressSpace2->getAddrSpaceExpr()))
578
0
      return false;
579
0
    if (!IsStructurallyEquivalent(Context, DepAddressSpace1->getPointeeType(),
580
0
                                  DepAddressSpace2->getPointeeType()))
581
0
      return false;
582
0
583
0
    break;
584
0
  }
585
0
586
0
  case Type::DependentSizedExtVector: {
587
0
    const auto *Vec1 = cast<DependentSizedExtVectorType>(T1);
588
0
    const auto *Vec2 = cast<DependentSizedExtVectorType>(T2);
589
0
    if (!IsStructurallyEquivalent(Context, Vec1->getSizeExpr(),
590
0
                                  Vec2->getSizeExpr()))
591
0
      return false;
592
0
    if (!IsStructurallyEquivalent(Context, Vec1->getElementType(),
593
0
                                  Vec2->getElementType()))
594
0
      return false;
595
0
    break;
596
0
  }
597
0
598
0
  case Type::DependentVector: {
599
0
    const auto *Vec1 = cast<DependentVectorType>(T1);
600
0
    const auto *Vec2 = cast<DependentVectorType>(T2);
601
0
    if (Vec1->getVectorKind() != Vec2->getVectorKind())
602
0
      return false;
603
0
    if (!IsStructurallyEquivalent(Context, Vec1->getSizeExpr(),
604
0
                                  Vec2->getSizeExpr()))
605
0
      return false;
606
0
    if (!IsStructurallyEquivalent(Context, Vec1->getElementType(),
607
0
                                  Vec2->getElementType()))
608
0
      return false;
609
0
    break;
610
0
  }
611
0
612
0
  case Type::Vector:
613
0
  case Type::ExtVector: {
614
0
    const auto *Vec1 = cast<VectorType>(T1);
615
0
    const auto *Vec2 = cast<VectorType>(T2);
616
0
    if (!IsStructurallyEquivalent(Context, Vec1->getElementType(),
617
0
                                  Vec2->getElementType()))
618
0
      return false;
619
0
    if (Vec1->getNumElements() != Vec2->getNumElements())
620
0
      return false;
621
0
    if (Vec1->getVectorKind() != Vec2->getVectorKind())
622
0
      return false;
623
0
    break;
624
0
  }
625
0
626
39.3k
  case Type::FunctionProto: {
627
39.3k
    const auto *Proto1 = cast<FunctionProtoType>(T1);
628
39.3k
    const auto *Proto2 = cast<FunctionProtoType>(T2);
629
39.3k
630
39.3k
    if (Proto1->getNumParams() != Proto2->getNumParams())
631
21.6k
      return false;
632
26.9k
    
for (unsigned I = 0, N = Proto1->getNumParams(); 17.7k
I != N;
++I9.16k
) {
633
21.7k
      if (!IsStructurallyEquivalent(Context, Proto1->getParamType(I),
634
21.7k
                                    Proto2->getParamType(I)))
635
12.6k
        return false;
636
21.7k
    }
637
17.7k
    
if (5.12k
Proto1->isVariadic() != Proto2->isVariadic()5.12k
)
638
2
      return false;
639
5.12k
640
5.12k
    if (Proto1->getMethodQuals() != Proto2->getMethodQuals())
641
0
      return false;
642
5.12k
643
5.12k
    // Check exceptions, this information is lost in canonical type.
644
5.12k
    const auto *OrigProto1 =
645
5.12k
        cast<FunctionProtoType>(OrigT1.getDesugaredType(Context.FromCtx));
646
5.12k
    const auto *OrigProto2 =
647
5.12k
        cast<FunctionProtoType>(OrigT2.getDesugaredType(Context.ToCtx));
648
5.12k
    if (!IsEquivalentExceptionSpec(Context, OrigProto1, OrigProto2))
649
87
      return false;
650
5.03k
651
5.03k
    // Fall through to check the bits common with FunctionNoProtoType.
652
5.03k
    LLVM_FALLTHROUGH;
653
5.03k
  }
654
5.03k
655
5.06k
  case Type::FunctionNoProto: {
656
5.06k
    const auto *Function1 = cast<FunctionType>(T1);
657
5.06k
    const auto *Function2 = cast<FunctionType>(T2);
658
5.06k
    if (!IsStructurallyEquivalent(Context, Function1->getReturnType(),
659
5.06k
                                  Function2->getReturnType()))
660
6
      return false;
661
5.05k
    if (!IsStructurallyEquivalent(Context, Function1->getExtInfo(),
662
5.05k
                                  Function2->getExtInfo()))
663
4
      return false;
664
5.05k
    break;
665
5.05k
  }
666
5.05k
667
5.05k
  case Type::UnresolvedUsing:
668
0
    if (!IsStructurallyEquivalent(Context,
669
0
                                  cast<UnresolvedUsingType>(T1)->getDecl(),
670
0
                                  cast<UnresolvedUsingType>(T2)->getDecl()))
671
0
      return false;
672
0
    break;
673
0
674
0
  case Type::Attributed:
675
0
    if (!IsStructurallyEquivalent(Context,
676
0
                                  cast<AttributedType>(T1)->getModifiedType(),
677
0
                                  cast<AttributedType>(T2)->getModifiedType()))
678
0
      return false;
679
0
    if (!IsStructurallyEquivalent(
680
0
            Context, cast<AttributedType>(T1)->getEquivalentType(),
681
0
            cast<AttributedType>(T2)->getEquivalentType()))
682
0
      return false;
683
0
    break;
684
0
685
0
  case Type::Paren:
686
0
    if (!IsStructurallyEquivalent(Context, cast<ParenType>(T1)->getInnerType(),
687
0
                                  cast<ParenType>(T2)->getInnerType()))
688
0
      return false;
689
0
    break;
690
0
691
0
  case Type::MacroQualified:
692
0
    if (!IsStructurallyEquivalent(
693
0
            Context, cast<MacroQualifiedType>(T1)->getUnderlyingType(),
694
0
            cast<MacroQualifiedType>(T2)->getUnderlyingType()))
695
0
      return false;
696
0
    break;
697
0
698
0
  case Type::Typedef:
699
0
    if (!IsStructurallyEquivalent(Context, cast<TypedefType>(T1)->getDecl(),
700
0
                                  cast<TypedefType>(T2)->getDecl()))
701
0
      return false;
702
0
    break;
703
0
704
0
  case Type::TypeOfExpr:
705
0
    if (!IsStructurallyEquivalent(
706
0
            Context, cast<TypeOfExprType>(T1)->getUnderlyingExpr(),
707
0
            cast<TypeOfExprType>(T2)->getUnderlyingExpr()))
708
0
      return false;
709
0
    break;
710
0
711
0
  case Type::TypeOf:
712
0
    if (!IsStructurallyEquivalent(Context,
713
0
                                  cast<TypeOfType>(T1)->getUnderlyingType(),
714
0
                                  cast<TypeOfType>(T2)->getUnderlyingType()))
715
0
      return false;
716
0
    break;
717
0
718
0
  case Type::UnaryTransform:
719
0
    if (!IsStructurallyEquivalent(
720
0
            Context, cast<UnaryTransformType>(T1)->getUnderlyingType(),
721
0
            cast<UnaryTransformType>(T2)->getUnderlyingType()))
722
0
      return false;
723
0
    break;
724
0
725
0
  case Type::Decltype:
726
0
    if (!IsStructurallyEquivalent(Context,
727
0
                                  cast<DecltypeType>(T1)->getUnderlyingExpr(),
728
0
                                  cast<DecltypeType>(T2)->getUnderlyingExpr()))
729
0
      return false;
730
0
    break;
731
0
732
0
  case Type::Auto: {
733
0
    auto *Auto1 = cast<AutoType>(T1);
734
0
    auto *Auto2 = cast<AutoType>(T2);
735
0
    if (!IsStructurallyEquivalent(Context, Auto1->getDeducedType(),
736
0
                                  Auto2->getDeducedType()))
737
0
      return false;
738
0
    if (Auto1->isConstrained() != Auto2->isConstrained())
739
0
      return false;
740
0
    if (Auto1->isConstrained()) {
741
0
      if (Auto1->getTypeConstraintConcept() !=
742
0
          Auto2->getTypeConstraintConcept())
743
0
        return false;
744
0
      ArrayRef<TemplateArgument> Auto1Args =
745
0
          Auto1->getTypeConstraintArguments();
746
0
      ArrayRef<TemplateArgument> Auto2Args =
747
0
          Auto2->getTypeConstraintArguments();
748
0
      if (Auto1Args.size() != Auto2Args.size())
749
0
        return false;
750
0
      for (unsigned I = 0, N = Auto1Args.size(); I != N; ++I) {
751
0
        if (!IsStructurallyEquivalent(Context, Auto1Args[I], Auto2Args[I]))
752
0
          return false;
753
0
      }
754
0
    }
755
0
    break;
756
0
  }
757
0
758
0
  case Type::DeducedTemplateSpecialization: {
759
0
    const auto *DT1 = cast<DeducedTemplateSpecializationType>(T1);
760
0
    const auto *DT2 = cast<DeducedTemplateSpecializationType>(T2);
761
0
    if (!IsStructurallyEquivalent(Context, DT1->getTemplateName(),
762
0
                                  DT2->getTemplateName()))
763
0
      return false;
764
0
    if (!IsStructurallyEquivalent(Context, DT1->getDeducedType(),
765
0
                                  DT2->getDeducedType()))
766
0
      return false;
767
0
    break;
768
0
  }
769
0
770
20.7k
  case Type::Record:
771
20.7k
  case Type::Enum:
772
20.7k
    if (!IsStructurallyEquivalent(Context, cast<TagType>(T1)->getDecl(),
773
20.7k
                                  cast<TagType>(T2)->getDecl()))
774
1.89k
      return false;
775
18.8k
    break;
776
18.8k
777
18.8k
  case Type::TemplateTypeParm: {
778
141
    const auto *Parm1 = cast<TemplateTypeParmType>(T1);
779
141
    const auto *Parm2 = cast<TemplateTypeParmType>(T2);
780
141
    if (Parm1->getDepth() != Parm2->getDepth())
781
0
      return false;
782
141
    if (Parm1->getIndex() != Parm2->getIndex())
783
0
      return false;
784
141
    if (Parm1->isParameterPack() != Parm2->isParameterPack())
785
0
      return false;
786
141
787
141
    // Names of template type parameters are never significant.
788
141
    break;
789
141
  }
790
141
791
141
  case Type::SubstTemplateTypeParm: {
792
0
    const auto *Subst1 = cast<SubstTemplateTypeParmType>(T1);
793
0
    const auto *Subst2 = cast<SubstTemplateTypeParmType>(T2);
794
0
    if (!IsStructurallyEquivalent(Context,
795
0
                                  QualType(Subst1->getReplacedParameter(), 0),
796
0
                                  QualType(Subst2->getReplacedParameter(), 0)))
797
0
      return false;
798
0
    if (!IsStructurallyEquivalent(Context, Subst1->getReplacementType(),
799
0
                                  Subst2->getReplacementType()))
800
0
      return false;
801
0
    break;
802
0
  }
803
0
804
0
  case Type::SubstTemplateTypeParmPack: {
805
0
    const auto *Subst1 = cast<SubstTemplateTypeParmPackType>(T1);
806
0
    const auto *Subst2 = cast<SubstTemplateTypeParmPackType>(T2);
807
0
    if (!IsStructurallyEquivalent(Context,
808
0
                                  QualType(Subst1->getReplacedParameter(), 0),
809
0
                                  QualType(Subst2->getReplacedParameter(), 0)))
810
0
      return false;
811
0
    if (!IsStructurallyEquivalent(Context, Subst1->getArgumentPack(),
812
0
                                  Subst2->getArgumentPack()))
813
0
      return false;
814
0
    break;
815
0
  }
816
0
817
18
  case Type::TemplateSpecialization: {
818
18
    const auto *Spec1 = cast<TemplateSpecializationType>(T1);
819
18
    const auto *Spec2 = cast<TemplateSpecializationType>(T2);
820
18
    if (!IsStructurallyEquivalent(Context, Spec1->getTemplateName(),
821
18
                                  Spec2->getTemplateName()))
822
0
      return false;
823
18
    if (Spec1->getNumArgs() != Spec2->getNumArgs())
824
0
      return false;
825
34
    
for (unsigned I = 0, N = Spec1->getNumArgs(); 18
I != N;
++I16
) {
826
18
      if (!IsStructurallyEquivalent(Context, Spec1->getArg(I),
827
18
                                    Spec2->getArg(I)))
828
2
        return false;
829
18
    }
830
18
    
break16
;
831
18
  }
832
18
833
18
  case Type::Elaborated: {
834
0
    const auto *Elab1 = cast<ElaboratedType>(T1);
835
0
    const auto *Elab2 = cast<ElaboratedType>(T2);
836
0
    // CHECKME: what if a keyword is ETK_None or ETK_typename ?
837
0
    if (Elab1->getKeyword() != Elab2->getKeyword())
838
0
      return false;
839
0
    if (!IsStructurallyEquivalent(Context, Elab1->getQualifier(),
840
0
                                  Elab2->getQualifier()))
841
0
      return false;
842
0
    if (!IsStructurallyEquivalent(Context, Elab1->getNamedType(),
843
0
                                  Elab2->getNamedType()))
844
0
      return false;
845
0
    break;
846
0
  }
847
0
848
0
  case Type::InjectedClassName: {
849
0
    const auto *Inj1 = cast<InjectedClassNameType>(T1);
850
0
    const auto *Inj2 = cast<InjectedClassNameType>(T2);
851
0
    if (!IsStructurallyEquivalent(Context,
852
0
                                  Inj1->getInjectedSpecializationType(),
853
0
                                  Inj2->getInjectedSpecializationType()))
854
0
      return false;
855
0
    break;
856
0
  }
857
0
858
10
  case Type::DependentName: {
859
10
    const auto *Typename1 = cast<DependentNameType>(T1);
860
10
    const auto *Typename2 = cast<DependentNameType>(T2);
861
10
    if (!IsStructurallyEquivalent(Context, Typename1->getQualifier(),
862
10
                                  Typename2->getQualifier()))
863
2
      return false;
864
8
    if (!IsStructurallyEquivalent(Typename1->getIdentifier(),
865
8
                                  Typename2->getIdentifier()))
866
0
      return false;
867
8
868
8
    break;
869
8
  }
870
8
871
8
  case Type::DependentTemplateSpecialization: {
872
0
    const auto *Spec1 = cast<DependentTemplateSpecializationType>(T1);
873
0
    const auto *Spec2 = cast<DependentTemplateSpecializationType>(T2);
874
0
    if (!IsStructurallyEquivalent(Context, Spec1->getQualifier(),
875
0
                                  Spec2->getQualifier()))
876
0
      return false;
877
0
    if (!IsStructurallyEquivalent(Spec1->getIdentifier(),
878
0
                                  Spec2->getIdentifier()))
879
0
      return false;
880
0
    if (Spec1->getNumArgs() != Spec2->getNumArgs())
881
0
      return false;
882
0
    for (unsigned I = 0, N = Spec1->getNumArgs(); I != N; ++I) {
883
0
      if (!IsStructurallyEquivalent(Context, Spec1->getArg(I),
884
0
                                    Spec2->getArg(I)))
885
0
        return false;
886
0
    }
887
0
    break;
888
0
  }
889
0
890
0
  case Type::PackExpansion:
891
0
    if (!IsStructurallyEquivalent(Context,
892
0
                                  cast<PackExpansionType>(T1)->getPattern(),
893
0
                                  cast<PackExpansionType>(T2)->getPattern()))
894
0
      return false;
895
0
    break;
896
0
897
12
  case Type::ObjCInterface: {
898
12
    const auto *Iface1 = cast<ObjCInterfaceType>(T1);
899
12
    const auto *Iface2 = cast<ObjCInterfaceType>(T2);
900
12
    if (!IsStructurallyEquivalent(Context, Iface1->getDecl(),
901
12
                                  Iface2->getDecl()))
902
0
      return false;
903
12
    break;
904
12
  }
905
12
906
12
  case Type::ObjCTypeParam: {
907
0
    const auto *Obj1 = cast<ObjCTypeParamType>(T1);
908
0
    const auto *Obj2 = cast<ObjCTypeParamType>(T2);
909
0
    if (!IsStructurallyEquivalent(Context, Obj1->getDecl(), Obj2->getDecl()))
910
0
      return false;
911
0
912
0
    if (Obj1->getNumProtocols() != Obj2->getNumProtocols())
913
0
      return false;
914
0
    for (unsigned I = 0, N = Obj1->getNumProtocols(); I != N; ++I) {
915
0
      if (!IsStructurallyEquivalent(Context, Obj1->getProtocol(I),
916
0
                                    Obj2->getProtocol(I)))
917
0
        return false;
918
0
    }
919
0
    break;
920
0
  }
921
0
922
729
  case Type::ObjCObject: {
923
729
    const auto *Obj1 = cast<ObjCObjectType>(T1);
924
729
    const auto *Obj2 = cast<ObjCObjectType>(T2);
925
729
    if (!IsStructurallyEquivalent(Context, Obj1->getBaseType(),
926
729
                                  Obj2->getBaseType()))
927
0
      return false;
928
729
    if (Obj1->getNumProtocols() != Obj2->getNumProtocols())
929
0
      return false;
930
729
    for (unsigned I = 0, N = Obj1->getNumProtocols(); I != N; 
++I0
) {
931
0
      if (!IsStructurallyEquivalent(Context, Obj1->getProtocol(I),
932
0
                                    Obj2->getProtocol(I)))
933
0
        return false;
934
0
    }
935
729
    break;
936
729
  }
937
729
938
741
  case Type::ObjCObjectPointer: {
939
741
    const auto *Ptr1 = cast<ObjCObjectPointerType>(T1);
940
741
    const auto *Ptr2 = cast<ObjCObjectPointerType>(T2);
941
741
    if (!IsStructurallyEquivalent(Context, Ptr1->getPointeeType(),
942
741
                                  Ptr2->getPointeeType()))
943
0
      return false;
944
741
    break;
945
741
  }
946
741
947
741
  case Type::Atomic:
948
0
    if (!IsStructurallyEquivalent(Context, cast<AtomicType>(T1)->getValueType(),
949
0
                                  cast<AtomicType>(T2)->getValueType()))
950
0
      return false;
951
0
    break;
952
0
953
0
  case Type::Pipe:
954
0
    if (!IsStructurallyEquivalent(Context, cast<PipeType>(T1)->getElementType(),
955
0
                                  cast<PipeType>(T2)->getElementType()))
956
0
      return false;
957
0
    break;
958
61.1k
  } // end switch
959
61.1k
960
61.1k
  return true;
961
61.1k
}
962
963
/// Determine structural equivalence of two fields.
964
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
965
10.8k
                                     FieldDecl *Field1, FieldDecl *Field2) {
966
10.8k
  const auto *Owner2 = cast<RecordDecl>(Field2->getDeclContext());
967
10.8k
968
10.8k
  // For anonymous structs/unions, match up the anonymous struct/union type
969
10.8k
  // declarations directly, so that we don't go off searching for anonymous
970
10.8k
  // types
971
10.8k
  if (Field1->isAnonymousStructOrUnion() &&
972
10.8k
      
Field2->isAnonymousStructOrUnion()1.39k
) {
973
1.39k
    RecordDecl *D1 = Field1->getType()->castAs<RecordType>()->getDecl();
974
1.39k
    RecordDecl *D2 = Field2->getType()->castAs<RecordType>()->getDecl();
975
1.39k
    return IsStructurallyEquivalent(Context, D1, D2);
976
1.39k
  }
977
9.48k
978
9.48k
  // Check for equivalent field names.
979
9.48k
  IdentifierInfo *Name1 = Field1->getIdentifier();
980
9.48k
  IdentifierInfo *Name2 = Field2->getIdentifier();
981
9.48k
  if (!::IsStructurallyEquivalent(Name1, Name2)) {
982
36
    if (Context.Complain) {
983
14
      Context.Diag2(
984
14
          Owner2->getLocation(),
985
14
          Context.getApplicableDiagnostic(diag::err_odr_tag_type_inconsistent))
986
14
          << Context.ToCtx.getTypeDeclType(Owner2);
987
14
      Context.Diag2(Field2->getLocation(), diag::note_odr_field_name)
988
14
          << Field2->getDeclName();
989
14
      Context.Diag1(Field1->getLocation(), diag::note_odr_field_name)
990
14
          << Field1->getDeclName();
991
14
    }
992
36
    return false;
993
36
  }
994
9.45k
995
9.45k
  if (!IsStructurallyEquivalent(Context, Field1->getType(),
996
9.45k
                                Field2->getType())) {
997
28
    if (Context.Complain) {
998
19
      Context.Diag2(
999
19
          Owner2->getLocation(),
1000
19
          Context.getApplicableDiagnostic(diag::err_odr_tag_type_inconsistent))
1001
19
          << Context.ToCtx.getTypeDeclType(Owner2);
1002
19
      Context.Diag2(Field2->getLocation(), diag::note_odr_field)
1003
19
          << Field2->getDeclName() << Field2->getType();
1004
19
      Context.Diag1(Field1->getLocation(), diag::note_odr_field)
1005
19
          << Field1->getDeclName() << Field1->getType();
1006
19
    }
1007
28
    return false;
1008
28
  }
1009
9.42k
1010
9.42k
  if (Field1->isBitField() != Field2->isBitField()) {
1011
1
    if (Context.Complain) {
1012
1
      Context.Diag2(
1013
1
          Owner2->getLocation(),
1014
1
          Context.getApplicableDiagnostic(diag::err_odr_tag_type_inconsistent))
1015
1
          << Context.ToCtx.getTypeDeclType(Owner2);
1016
1
      if (Field1->isBitField()) {
1017
0
        Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field)
1018
0
            << Field1->getDeclName() << Field1->getType()
1019
0
            << Field1->getBitWidthValue(Context.FromCtx);
1020
0
        Context.Diag2(Field2->getLocation(), diag::note_odr_not_bit_field)
1021
0
            << Field2->getDeclName();
1022
1
      } else {
1023
1
        Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field)
1024
1
            << Field2->getDeclName() << Field2->getType()
1025
1
            << Field2->getBitWidthValue(Context.ToCtx);
1026
1
        Context.Diag1(Field1->getLocation(), diag::note_odr_not_bit_field)
1027
1
            << Field1->getDeclName();
1028
1
      }
1029
1
    }
1030
1
    return false;
1031
1
  }
1032
9.42k
1033
9.42k
  if (Field1->isBitField()) {
1034
7
    // Make sure that the bit-fields are the same length.
1035
7
    unsigned Bits1 = Field1->getBitWidthValue(Context.FromCtx);
1036
7
    unsigned Bits2 = Field2->getBitWidthValue(Context.ToCtx);
1037
7
1038
7
    if (Bits1 != Bits2) {
1039
1
      if (Context.Complain) {
1040
1
        Context.Diag2(Owner2->getLocation(),
1041
1
                      Context.getApplicableDiagnostic(
1042
1
                          diag::err_odr_tag_type_inconsistent))
1043
1
            << Context.ToCtx.getTypeDeclType(Owner2);
1044
1
        Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field)
1045
1
            << Field2->getDeclName() << Field2->getType() << Bits2;
1046
1
        Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field)
1047
1
            << Field1->getDeclName() << Field1->getType() << Bits1;
1048
1
      }
1049
1
      return false;
1050
1
    }
1051
9.42k
  }
1052
9.42k
1053
9.42k
  return true;
1054
9.42k
}
1055
1056
/// Determine structural equivalence of two methods.
1057
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1058
                                     CXXMethodDecl *Method1,
1059
48.8k
                                     CXXMethodDecl *Method2) {
1060
48.8k
  bool PropertiesEqual =
1061
48.8k
      Method1->getDeclKind() == Method2->getDeclKind() &&
1062
48.8k
      
Method1->getRefQualifier() == Method2->getRefQualifier()48.8k
&&
1063
48.8k
      
Method1->getAccess() == Method2->getAccess()48.8k
&&
1064
48.8k
      
Method1->getOverloadedOperator() == Method2->getOverloadedOperator()48.3k
&&
1065
48.8k
      
Method1->isStatic() == Method2->isStatic()48.3k
&&
1066
48.8k
      
Method1->isConst() == Method2->isConst()48.2k
&&
1067
48.8k
      
Method1->isVolatile() == Method2->isVolatile()43.5k
&&
1068
48.8k
      
Method1->isVirtual() == Method2->isVirtual()43.5k
&&
1069
48.8k
      
Method1->isPure() == Method2->isPure()43.5k
&&
1070
48.8k
      
Method1->isDefaulted() == Method2->isDefaulted()43.5k
&&
1071
48.8k
      
Method1->isDeleted() == Method2->isDeleted()43.4k
;
1072
48.8k
  if (!PropertiesEqual)
1073
5.42k
    return false;
1074
43.4k
  // FIXME: Check for 'final'.
1075
43.4k
1076
43.4k
  if (auto *Constructor1 = dyn_cast<CXXConstructorDecl>(Method1)) {
1077
18.6k
    auto *Constructor2 = cast<CXXConstructorDecl>(Method2);
1078
18.6k
    if (!Constructor1->getExplicitSpecifier().isEquivalent(
1079
18.6k
            Constructor2->getExplicitSpecifier()))
1080
5.18k
      return false;
1081
38.2k
  }
1082
38.2k
1083
38.2k
  if (auto *Conversion1 = dyn_cast<CXXConversionDecl>(Method1)) {
1084
15
    auto *Conversion2 = cast<CXXConversionDecl>(Method2);
1085
15
    if (!Conversion1->getExplicitSpecifier().isEquivalent(
1086
15
            Conversion2->getExplicitSpecifier()))
1087
0
      return false;
1088
15
    if (!IsStructurallyEquivalent(Context, Conversion1->getConversionType(),
1089
15
                                  Conversion2->getConversionType()))
1090
2
      return false;
1091
38.2k
  }
1092
38.2k
1093
38.2k
  const IdentifierInfo *Name1 = Method1->getIdentifier();
1094
38.2k
  const IdentifierInfo *Name2 = Method2->getIdentifier();
1095
38.2k
  if (!::IsStructurallyEquivalent(Name1, Name2)) {
1096
0
    return false;
1097
0
    // TODO: Names do not match, add warning like at check for FieldDecl.
1098
0
  }
1099
38.2k
1100
38.2k
  // Check the prototypes.
1101
38.2k
  if (!::IsStructurallyEquivalent(Context,
1102
38.2k
                                  Method1->getType(), Method2->getType()))
1103
34.0k
    return false;
1104
4.22k
1105
4.22k
  return true;
1106
4.22k
}
1107
1108
/// Determine structural equivalence of two lambda classes.
1109
static bool
1110
IsStructurallyEquivalentLambdas(StructuralEquivalenceContext &Context,
1111
8
                                CXXRecordDecl *D1, CXXRecordDecl *D2) {
1112
8
  assert(D1->isLambda() && D2->isLambda() &&
1113
8
         "Must be called on lambda classes");
1114
8
  if (!IsStructurallyEquivalent(Context, D1->getLambdaCallOperator(),
1115
8
                                D2->getLambdaCallOperator()))
1116
2
    return false;
1117
6
1118
6
  return true;
1119
6
}
1120
1121
/// Determine structural equivalence of two records.
1122
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1123
20.9k
                                     RecordDecl *D1, RecordDecl *D2) {
1124
20.9k
  if (D1->isUnion() != D2->isUnion()) {
1125
3
    if (Context.Complain) {
1126
1
      Context.Diag2(D2->getLocation(), Context.getApplicableDiagnostic(
1127
1
                                           diag::err_odr_tag_type_inconsistent))
1128
1
          << Context.ToCtx.getTypeDeclType(D2);
1129
1
      Context.Diag1(D1->getLocation(), diag::note_odr_tag_kind_here)
1130
1
          << D1->getDeclName() << (unsigned)D1->getTagKind();
1131
1
    }
1132
3
    return false;
1133
3
  }
1134
20.9k
1135
20.9k
  if (!D1->getDeclName() && 
!D2->getDeclName()1.53k
) {
1136
1.53k
    // If both anonymous structs/unions are in a record context, make sure
1137
1.53k
    // they occur in the same location in the context records.
1138
1.53k
    if (Optional<unsigned> Index1 =
1139
1.50k
            StructuralEquivalenceContext::findUntaggedStructOrUnionIndex(D1)) {
1140
1.50k
      if (Optional<unsigned> Index2 =
1141
1.50k
              StructuralEquivalenceContext::findUntaggedStructOrUnionIndex(
1142
1.50k
                  D2)) {
1143
1.50k
        if (*Index1 != *Index2)
1144
47
          return false;
1145
20.9k
      }
1146
1.50k
    }
1147
1.53k
  }
1148
20.9k
1149
20.9k
  // If both declarations are class template specializations, we know
1150
20.9k
  // the ODR applies, so check the template and template arguments.
1151
20.9k
  const auto *Spec1 = dyn_cast<ClassTemplateSpecializationDecl>(D1);
1152
20.9k
  const auto *Spec2 = dyn_cast<ClassTemplateSpecializationDecl>(D2);
1153
20.9k
  if (Spec1 && 
Spec28.07k
) {
1154
8.07k
    // Check that the specialized templates are the same.
1155
8.07k
    if (!IsStructurallyEquivalent(Context, Spec1->getSpecializedTemplate(),
1156
8.07k
                                  Spec2->getSpecializedTemplate()))
1157
6
      return false;
1158
8.06k
1159
8.06k
    // Check that the template arguments are the same.
1160
8.06k
    if (Spec1->getTemplateArgs().size() != Spec2->getTemplateArgs().size())
1161
0
      return false;
1162
8.06k
1163
22.5k
    
for (unsigned I = 0, N = Spec1->getTemplateArgs().size(); 8.06k
I != N;
++I14.4k
)
1164
14.8k
      if (!IsStructurallyEquivalent(Context, Spec1->getTemplateArgs().get(I),
1165
14.8k
                                    Spec2->getTemplateArgs().get(I)))
1166
371
        return false;
1167
8.06k
  }
1168
12.8k
  // If one is a class template specialization and the other is not, these
1169
12.8k
  // structures are different.
1170
12.8k
  else if (Spec1 || Spec2)
1171
0
    return false;
1172
20.5k
1173
20.5k
  // Compare the definitions of these two records. If either or both are
1174
20.5k
  // incomplete (i.e. it is a forward decl), we assume that they are
1175
20.5k
  // equivalent.
1176
20.5k
  D1 = D1->getDefinition();
1177
20.5k
  D2 = D2->getDefinition();
1178
20.5k
  if (!D1 || 
!D212.3k
)
1179
9.48k
    return true;
1180
11.0k
1181
11.0k
  // If any of the records has external storage and we do a minimal check (or
1182
11.0k
  // AST import) we assume they are equivalent. (If we didn't have this
1183
11.0k
  // assumption then `RecordDecl::LoadFieldsFromExternalStorage` could trigger
1184
11.0k
  // another AST import which in turn would call the structural equivalency
1185
11.0k
  // check again and finally we'd have an improper result.)
1186
11.0k
  if (Context.EqKind == StructuralEquivalenceKind::Minimal)
1187
10.1k
    if (D1->hasExternalLexicalStorage() || 
D2->hasExternalLexicalStorage()10.1k
)
1188
1.39k
      return true;
1189
9.66k
1190
9.66k
  // If one definition is currently being defined, we do not compare for
1191
9.66k
  // equality and we assume that the decls are equal.
1192
9.66k
  if (D1->isBeingDefined() || 
D2->isBeingDefined()9.42k
)
1193
321
    return true;
1194
9.34k
1195
9.34k
  if (auto *D1CXX = dyn_cast<CXXRecordDecl>(D1)) {
1196
9.20k
    if (auto *D2CXX = dyn_cast<CXXRecordDecl>(D2)) {
1197
9.20k
      if (D1CXX->hasExternalLexicalStorage() &&
1198
9.20k
          
!D1CXX->isCompleteDefinition()62
) {
1199
0
        D1CXX->getASTContext().getExternalSource()->CompleteType(D1CXX);
1200
0
      }
1201
9.20k
1202
9.20k
      if (D1CXX->isLambda() != D2CXX->isLambda())
1203
0
        return false;
1204
9.20k
      if (D1CXX->isLambda()) {
1205
8
        if (!IsStructurallyEquivalentLambdas(Context, D1CXX, D2CXX))
1206
2
          return false;
1207
9.20k
      }
1208
9.20k
1209
9.20k
      if (D1CXX->getNumBases() != D2CXX->getNumBases()) {
1210
0
        if (Context.Complain) {
1211
0
          Context.Diag2(D2->getLocation(),
1212
0
                        Context.getApplicableDiagnostic(
1213
0
                            diag::err_odr_tag_type_inconsistent))
1214
0
              << Context.ToCtx.getTypeDeclType(D2);
1215
0
          Context.Diag2(D2->getLocation(), diag::note_odr_number_of_bases)
1216
0
              << D2CXX->getNumBases();
1217
0
          Context.Diag1(D1->getLocation(), diag::note_odr_number_of_bases)
1218
0
              << D1CXX->getNumBases();
1219
0
        }
1220
0
        return false;
1221
0
      }
1222
9.20k
1223
9.20k
      // Check the base classes.
1224
9.20k
      for (CXXRecordDecl::base_class_iterator Base1 = D1CXX->bases_begin(),
1225
9.20k
                                              BaseEnd1 = D1CXX->bases_end(),
1226
9.20k
                                              Base2 = D2CXX->bases_begin();
1227
12.4k
           Base1 != BaseEnd1; 
++Base1, ++Base23.21k
) {
1228
3.21k
        if (!IsStructurallyEquivalent(Context, Base1->getType(),
1229
3.21k
                                      Base2->getType())) {
1230
0
          if (Context.Complain) {
1231
0
            Context.Diag2(D2->getLocation(),
1232
0
                          Context.getApplicableDiagnostic(
1233
0
                              diag::err_odr_tag_type_inconsistent))
1234
0
                << Context.ToCtx.getTypeDeclType(D2);
1235
0
            Context.Diag2(Base2->getBeginLoc(), diag::note_odr_base)
1236
0
                << Base2->getType() << Base2->getSourceRange();
1237
0
            Context.Diag1(Base1->getBeginLoc(), diag::note_odr_base)
1238
0
                << Base1->getType() << Base1->getSourceRange();
1239
0
          }
1240
0
          return false;
1241
0
        }
1242
3.21k
1243
3.21k
        // Check virtual vs. non-virtual inheritance mismatch.
1244
3.21k
        if (Base1->isVirtual() != Base2->isVirtual()) {
1245
2
          if (Context.Complain) {
1246
0
            Context.Diag2(D2->getLocation(),
1247
0
                          Context.getApplicableDiagnostic(
1248
0
                              diag::err_odr_tag_type_inconsistent))
1249
0
                << Context.ToCtx.getTypeDeclType(D2);
1250
0
            Context.Diag2(Base2->getBeginLoc(), diag::note_odr_virtual_base)
1251
0
                << Base2->isVirtual() << Base2->getSourceRange();
1252
0
            Context.Diag1(Base1->getBeginLoc(), diag::note_odr_base)
1253
0
                << Base1->isVirtual() << Base1->getSourceRange();
1254
0
          }
1255
2
          return false;
1256
2
        }
1257
3.21k
      }
1258
9.20k
1259
9.20k
      // Check the friends for consistency.
1260
9.20k
      CXXRecordDecl::friend_iterator Friend2 = D2CXX->friend_begin(),
1261
9.20k
                                     Friend2End = D2CXX->friend_end();
1262
9.20k
      for (CXXRecordDecl::friend_iterator Friend1 = D1CXX->friend_begin(),
1263
9.20k
                                          Friend1End = D1CXX->friend_end();
1264
9.22k
           Friend1 != Friend1End; 
++Friend1, ++Friend221
) {
1265
21
        if (Friend2 == Friend2End) {
1266
0
          if (Context.Complain) {
1267
0
            Context.Diag2(D2->getLocation(),
1268
0
                          Context.getApplicableDiagnostic(
1269
0
                              diag::err_odr_tag_type_inconsistent))
1270
0
                << Context.ToCtx.getTypeDeclType(D2CXX);
1271
0
            Context.Diag1((*Friend1)->getFriendLoc(), diag::note_odr_friend);
1272
0
            Context.Diag2(D2->getLocation(), diag::note_odr_missing_friend);
1273
0
          }
1274
0
          return false;
1275
0
        }
1276
21
1277
21
        if (!IsStructurallyEquivalent(Context, *Friend1, *Friend2)) {
1278
0
          if (Context.Complain) {
1279
0
            Context.Diag2(D2->getLocation(),
1280
0
                          Context.getApplicableDiagnostic(
1281
0
                              diag::err_odr_tag_type_inconsistent))
1282
0
                << Context.ToCtx.getTypeDeclType(D2CXX);
1283
0
            Context.Diag1((*Friend1)->getFriendLoc(), diag::note_odr_friend);
1284
0
            Context.Diag2((*Friend2)->getFriendLoc(), diag::note_odr_friend);
1285
0
          }
1286
0
          return false;
1287
0
        }
1288
21
      }
1289
9.20k
1290
9.20k
      if (Friend2 != Friend2End) {
1291
4
        if (Context.Complain) {
1292
4
          Context.Diag2(D2->getLocation(),
1293
4
                        Context.getApplicableDiagnostic(
1294
4
                            diag::err_odr_tag_type_inconsistent))
1295
4
              << Context.ToCtx.getTypeDeclType(D2);
1296
4
          Context.Diag2((*Friend2)->getFriendLoc(), diag::note_odr_friend);
1297
4
          Context.Diag1(D1->getLocation(), diag::note_odr_missing_friend);
1298
4
        }
1299
4
        return false;
1300
4
      }
1301
0
    } else if (D1CXX->getNumBases() > 0) {
1302
0
      if (Context.Complain) {
1303
0
        Context.Diag2(D2->getLocation(),
1304
0
                      Context.getApplicableDiagnostic(
1305
0
                          diag::err_odr_tag_type_inconsistent))
1306
0
            << Context.ToCtx.getTypeDeclType(D2);
1307
0
        const CXXBaseSpecifier *Base1 = D1CXX->bases_begin();
1308
0
        Context.Diag1(Base1->getBeginLoc(), diag::note_odr_base)
1309
0
            << Base1->getType() << Base1->getSourceRange();
1310
0
        Context.Diag2(D2->getLocation(), diag::note_odr_missing_base);
1311
0
      }
1312
0
      return false;
1313
0
    }
1314
9.33k
  }
1315
9.33k
1316
9.33k
  // Check the fields for consistency.
1317
9.33k
  RecordDecl::field_iterator Field2 = D2->field_begin(),
1318
9.33k
                             Field2End = D2->field_end();
1319
9.33k
  for (RecordDecl::field_iterator Field1 = D1->field_begin(),
1320
9.33k
                                  Field1End = D1->field_end();
1321
20.1k
       Field1 != Field1End; 
++Field1, ++Field210.8k
) {
1322
10.9k
    if (Field2 == Field2End) {
1323
26
      if (Context.Complain) {
1324
25
        Context.Diag2(D2->getLocation(),
1325
25
                      Context.getApplicableDiagnostic(
1326
25
                          diag::err_odr_tag_type_inconsistent))
1327
25
            << Context.ToCtx.getTypeDeclType(D2);
1328
25
        Context.Diag1(Field1->getLocation(), diag::note_odr_field)
1329
25
            << Field1->getDeclName() << Field1->getType();
1330
25
        Context.Diag2(D2->getLocation(), diag::note_odr_missing_field);
1331
25
      }
1332
26
      return false;
1333
26
    }
1334
10.8k
1335
10.8k
    if (!IsStructurallyEquivalent(Context, *Field1, *Field2))
1336
66
      return false;
1337
10.8k
  }
1338
9.33k
1339
9.33k
  
if (9.24k
Field2 != Field2End9.24k
) {
1340
4
    if (Context.Complain) {
1341
3
      Context.Diag2(D2->getLocation(), Context.getApplicableDiagnostic(
1342
3
                                           diag::err_odr_tag_type_inconsistent))
1343
3
          << Context.ToCtx.getTypeDeclType(D2);
1344
3
      Context.Diag2(Field2->getLocation(), diag::note_odr_field)
1345
3
          << Field2->getDeclName() << Field2->getType();
1346
3
      Context.Diag1(D1->getLocation(), diag::note_odr_missing_field);
1347
3
    }
1348
4
    return false;
1349
4
  }
1350
9.24k
1351
9.24k
  return true;
1352
9.24k
}
1353
1354
/// Determine structural equivalence of two enums.
1355
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1356
65
                                     EnumDecl *D1, EnumDecl *D2) {
1357
65
1358
65
  // Compare the definitions of these two enums. If either or both are
1359
65
  // incomplete (i.e. forward declared), we assume that they are equivalent.
1360
65
  D1 = D1->getDefinition();
1361
65
  D2 = D2->getDefinition();
1362
65
  if (!D1 || 
!D262
)
1363
4
    return true;
1364
61
1365
61
  EnumDecl::enumerator_iterator EC2 = D2->enumerator_begin(),
1366
61
                                EC2End = D2->enumerator_end();
1367
61
  for (EnumDecl::enumerator_iterator EC1 = D1->enumerator_begin(),
1368
61
                                     EC1End = D1->enumerator_end();
1369
143
       EC1 != EC1End; 
++EC1, ++EC282
) {
1370
107
    if (EC2 == EC2End) {
1371
9
      if (Context.Complain) {
1372
9
        Context.Diag2(D2->getLocation(),
1373
9
                      Context.getApplicableDiagnostic(
1374
9
                          diag::err_odr_tag_type_inconsistent))
1375
9
            << Context.ToCtx.getTypeDeclType(D2);
1376
9
        Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator)
1377
9
            << EC1->getDeclName() << EC1->getInitVal().toString(10);
1378
9
        Context.Diag2(D2->getLocation(), diag::note_odr_missing_enumerator);
1379
9
      }
1380
9
      return false;
1381
9
    }
1382
98
1383
98
    llvm::APSInt Val1 = EC1->getInitVal();
1384
98
    llvm::APSInt Val2 = EC2->getInitVal();
1385
98
    if (!llvm::APSInt::isSameValue(Val1, Val2) ||
1386
98
        
!IsStructurallyEquivalent(EC1->getIdentifier(), EC2->getIdentifier())85
) {
1387
16
      if (Context.Complain) {
1388
14
        Context.Diag2(D2->getLocation(),
1389
14
                      Context.getApplicableDiagnostic(
1390
14
                          diag::err_odr_tag_type_inconsistent))
1391
14
            << Context.ToCtx.getTypeDeclType(D2);
1392
14
        Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator)
1393
14
            << EC2->getDeclName() << EC2->getInitVal().toString(10);
1394
14
        Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator)
1395
14
            << EC1->getDeclName() << EC1->getInitVal().toString(10);
1396
14
      }
1397
16
      return false;
1398
16
    }
1399
98
  }
1400
61
1401
61
  
if (36
EC2 != EC2End36
) {
1402
1
    if (Context.Complain) {
1403
1
      Context.Diag2(D2->getLocation(), Context.getApplicableDiagnostic(
1404
1
                                           diag::err_odr_tag_type_inconsistent))
1405
1
          << Context.ToCtx.getTypeDeclType(D2);
1406
1
      Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator)
1407
1
          << EC2->getDeclName() << EC2->getInitVal().toString(10);
1408
1
      Context.Diag1(D1->getLocation(), diag::note_odr_missing_enumerator);
1409
1
    }
1410
1
    return false;
1411
1
  }
1412
35
1413
35
  return true;
1414
35
}
1415
1416
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1417
                                     TemplateParameterList *Params1,
1418
8.01k
                                     TemplateParameterList *Params2) {
1419
8.01k
  if (Params1->size() != Params2->size()) {
1420
0
    if (Context.Complain) {
1421
0
      Context.Diag2(Params2->getTemplateLoc(),
1422
0
                    Context.getApplicableDiagnostic(
1423
0
                        diag::err_odr_different_num_template_parameters))
1424
0
          << Params1->size() << Params2->size();
1425
0
      Context.Diag1(Params1->getTemplateLoc(),
1426
0
                    diag::note_odr_template_parameter_list);
1427
0
    }
1428
0
    return false;
1429
0
  }
1430
8.01k
1431
20.9k
  
for (unsigned I = 0, N = Params1->size(); 8.01k
I != N;
++I12.9k
) {
1432
12.9k
    if (Params1->getParam(I)->getKind() != Params2->getParam(I)->getKind()) {
1433
60
      if (Context.Complain) {
1434
58
        Context.Diag2(Params2->getParam(I)->getLocation(),
1435
58
                      Context.getApplicableDiagnostic(
1436
58
                          diag::err_odr_different_template_parameter_kind));
1437
58
        Context.Diag1(Params1->getParam(I)->getLocation(),
1438
58
                      diag::note_odr_template_parameter_here);
1439
58
      }
1440
60
      return false;
1441
60
    }
1442
12.9k
1443
12.9k
    if (!IsStructurallyEquivalent(Context, Params1->getParam(I),
1444
12.9k
                                  Params2->getParam(I)))
1445
6
      return false;
1446
12.9k
  }
1447
8.01k
1448
8.01k
  
return true7.94k
;
1449
8.01k
}
1450
1451
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1452
                                     TemplateTypeParmDecl *D1,
1453
10.0k
                                     TemplateTypeParmDecl *D2) {
1454
10.0k
  if (D1->isParameterPack() != D2->isParameterPack()) {
1455
0
    if (Context.Complain) {
1456
0
      Context.Diag2(D2->getLocation(),
1457
0
                    Context.getApplicableDiagnostic(
1458
0
                        diag::err_odr_parameter_pack_non_pack))
1459
0
          << D2->isParameterPack();
1460
0
      Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
1461
0
          << D1->isParameterPack();
1462
0
    }
1463
0
    return false;
1464
0
  }
1465
10.0k
1466
10.0k
  return true;
1467
10.0k
}
1468
1469
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1470
                                     NonTypeTemplateParmDecl *D1,
1471
2.80k
                                     NonTypeTemplateParmDecl *D2) {
1472
2.80k
  if (D1->isParameterPack() != D2->isParameterPack()) {
1473
0
    if (Context.Complain) {
1474
0
      Context.Diag2(D2->getLocation(),
1475
0
                    Context.getApplicableDiagnostic(
1476
0
                        diag::err_odr_parameter_pack_non_pack))
1477
0
          << D2->isParameterPack();
1478
0
      Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
1479
0
          << D1->isParameterPack();
1480
0
    }
1481
0
    return false;
1482
0
  }
1483
2.80k
1484
2.80k
  // Check types.
1485
2.80k
  if (!IsStructurallyEquivalent(Context, D1->getType(), D2->getType())) {
1486
10
    if (Context.Complain) {
1487
8
      Context.Diag2(D2->getLocation(),
1488
8
                    Context.getApplicableDiagnostic(
1489
8
                        diag::err_odr_non_type_parameter_type_inconsistent))
1490
8
          << D2->getType() << D1->getType();
1491
8
      Context.Diag1(D1->getLocation(), diag::note_odr_value_here)
1492
8
          << D1->getType();
1493
8
    }
1494
10
    return false;
1495
10
  }
1496
2.79k
1497
2.79k
  return true;
1498
2.79k
}
1499
1500
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1501
                                     TemplateTemplateParmDecl *D1,
1502
8
                                     TemplateTemplateParmDecl *D2) {
1503
8
  if (D1->isParameterPack() != D2->isParameterPack()) {
1504
0
    if (Context.Complain) {
1505
0
      Context.Diag2(D2->getLocation(),
1506
0
                    Context.getApplicableDiagnostic(
1507
0
                        diag::err_odr_parameter_pack_non_pack))
1508
0
          << D2->isParameterPack();
1509
0
      Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
1510
0
          << D1->isParameterPack();
1511
0
    }
1512
0
    return false;
1513
0
  }
1514
8
1515
8
  // Check template parameter lists.
1516
8
  return IsStructurallyEquivalent(Context, D1->getTemplateParameters(),
1517
8
                                  D2->getTemplateParameters());
1518
8
}
1519
1520
static bool IsTemplateDeclCommonStructurallyEquivalent(
1521
8.00k
    StructuralEquivalenceContext &Ctx, TemplateDecl *D1, TemplateDecl *D2) {
1522
8.00k
  if (!IsStructurallyEquivalent(D1->getIdentifier(), D2->getIdentifier()))
1523
4
    return false;
1524
8.00k
  if (!D1->getIdentifier()) // Special name
1525
0
    if (D1->getNameAsString() != D2->getNameAsString())
1526
0
      return false;
1527
8.00k
  return IsStructurallyEquivalent(Ctx, D1->getTemplateParameters(),
1528
8.00k
                                  D2->getTemplateParameters());
1529
8.00k
}
1530
1531
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1532
                                     ClassTemplateDecl *D1,
1533
7.65k
                                     ClassTemplateDecl *D2) {
1534
7.65k
  // Check template parameters.
1535
7.65k
  if (!IsTemplateDeclCommonStructurallyEquivalent(Context, D1, D2))
1536
70
    return false;
1537
7.58k
1538
7.58k
  // Check the templated declaration.
1539
7.58k
  return IsStructurallyEquivalent(Context, D1->getTemplatedDecl(),
1540
7.58k
                                  D2->getTemplatedDecl());
1541
7.58k
}
1542
1543
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1544
                                     FunctionTemplateDecl *D1,
1545
354
                                     FunctionTemplateDecl *D2) {
1546
354
  // Check template parameters.
1547
354
  if (!IsTemplateDeclCommonStructurallyEquivalent(Context, D1, D2))
1548
0
    return false;
1549
354
1550
354
  // Check the templated declaration.
1551
354
  return IsStructurallyEquivalent(Context, D1->getTemplatedDecl()->getType(),
1552
354
                                  D2->getTemplatedDecl()->getType());
1553
354
}
1554
1555
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1556
                                     ConceptDecl *D1,
1557
0
                                     ConceptDecl *D2) {
1558
0
  // Check template parameters.
1559
0
  if (!IsTemplateDeclCommonStructurallyEquivalent(Context, D1, D2))
1560
0
    return false;
1561
0
1562
0
  // Check the constraint expression.
1563
0
  return IsStructurallyEquivalent(Context, D1->getConstraintExpr(),
1564
0
                                  D2->getConstraintExpr());
1565
0
}
1566
1567
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1568
13
                                     FriendDecl *D1, FriendDecl *D2) {
1569
13
  if ((D1->getFriendType() && 
D2->getFriendDecl()2
) ||
1570
13
      (D1->getFriendDecl() && 
D2->getFriendType()11
)) {
1571
0
      return false;
1572
0
  }
1573
13
  if (D1->getFriendType() && 
D2->getFriendType()2
)
1574
2
    return IsStructurallyEquivalent(Context,
1575
2
                                    D1->getFriendType()->getType(),
1576
2
                                    D2->getFriendType()->getType());
1577
11
  if (D1->getFriendDecl() && D2->getFriendDecl())
1578
11
    return IsStructurallyEquivalent(Context, D1->getFriendDecl(),
1579
11
                                    D2->getFriendDecl());
1580
0
  return false;
1581
0
}
1582
1583
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1584
797
                                     FunctionDecl *D1, FunctionDecl *D2) {
1585
797
  // FIXME: Consider checking for function attributes as well.
1586
797
  if (!IsStructurallyEquivalent(Context, D1->getType(), D2->getType()))
1587
320
    return false;
1588
477
1589
477
  return true;
1590
477
}
1591
1592
/// Determine structural equivalence of two declarations.
1593
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
1594
95.5k
                                     Decl *D1, Decl *D2) {
1595
95.5k
  // FIXME: Check for known structural equivalences via a callback of some sort.
1596
95.5k
1597
95.5k
  D1 = D1->getCanonicalDecl();
1598
95.5k
  D2 = D2->getCanonicalDecl();
1599
95.5k
  std::pair<Decl *, Decl *> P{D1, D2};
1600
95.5k
1601
95.5k
  // Check whether we already know that these two declarations are not
1602
95.5k
  // structurally equivalent.
1603
95.5k
  if (Context.NonEquivalentDecls.count(P))
1604
2.02k
    return false;
1605
93.5k
1606
93.5k
  // Check if a check for these declarations is already pending.
1607
93.5k
  // If yes D1 and D2 will be checked later (from DeclsToCheck),
1608
93.5k
  // or these are already checked (and equivalent).
1609
93.5k
  bool Inserted = Context.VisitedDecls.insert(P).second;
1610
93.5k
  if (!Inserted)
1611
5.77k
    return true;
1612
87.7k
1613
87.7k
  Context.DeclsToCheck.push(P);
1614
87.7k
1615
87.7k
  return true;
1616
87.7k
}
1617
1618
DiagnosticBuilder StructuralEquivalenceContext::Diag1(SourceLocation Loc,
1619
158
                                                      unsigned DiagID) {
1620
158
  assert(Complain && "Not allowed to complain");
1621
158
  if (LastDiagFromC2)
1622
158
    FromCtx.getDiagnostics().notePriorDiagnosticFrom(ToCtx.getDiagnostics());
1623
158
  LastDiagFromC2 = false;
1624
158
  return FromCtx.getDiagnostics().Report(Loc, DiagID);
1625
158
}
1626
1627
DiagnosticBuilder StructuralEquivalenceContext::Diag2(SourceLocation Loc,
1628
249
                                                      unsigned DiagID) {
1629
249
  assert(Complain && "Not allowed to complain");
1630
249
  if (!LastDiagFromC2)
1631
192
    ToCtx.getDiagnostics().notePriorDiagnosticFrom(FromCtx.getDiagnostics());
1632
249
  LastDiagFromC2 = true;
1633
249
  return ToCtx.getDiagnostics().Report(Loc, DiagID);
1634
249
}
1635
1636
Optional<unsigned>
1637
3.03k
StructuralEquivalenceContext::findUntaggedStructOrUnionIndex(RecordDecl *Anon) {
1638
3.03k
  ASTContext &Context = Anon->getASTContext();
1639
3.03k
  QualType AnonTy = Context.getRecordType(Anon);
1640
3.03k
1641
3.03k
  const auto *Owner = dyn_cast<RecordDecl>(Anon->getDeclContext());
1642
3.03k
  if (!Owner)
1643
32
    return None;
1644
3.00k
1645
3.00k
  unsigned Index = 0;
1646
6.27k
  for (const auto *D : Owner->noload_decls()) {
1647
6.27k
    const auto *F = dyn_cast<FieldDecl>(D);
1648
6.27k
    if (!F)
1649
3.16k
      continue;
1650
3.11k
1651
3.11k
    if (F->isAnonymousStructOrUnion()) {
1652
2.87k
      if (Context.hasSameType(F->getType(), AnonTy))
1653
2.83k
        break;
1654
40
      ++Index;
1655
40
      continue;
1656
40
    }
1657
241
1658
241
    // If the field looks like this:
1659
241
    // struct { ... } A;
1660
241
    QualType FieldType = F->getType();
1661
241
    // In case of nested structs.
1662
452
    while (const auto *ElabType = dyn_cast<ElaboratedType>(FieldType))
1663
211
      FieldType = ElabType->getNamedType();
1664
241
1665
241
    if (const auto *RecType = dyn_cast<RecordType>(FieldType)) {
1666
241
      const RecordDecl *RecDecl = RecType->getDecl();
1667
241
      if (RecDecl->getDeclContext() == Owner && !RecDecl->getIdentifier()) {
1668
241
        if (Context.hasSameType(FieldType, AnonTy))
1669
168
          break;
1670
73
        ++Index;
1671
73
        continue;
1672
73
      }
1673
241
    }
1674
241
  }
1675
3.00k
1676
3.00k
  return Index;
1677
3.00k
}
1678
1679
unsigned StructuralEquivalenceContext::getApplicableDiagnostic(
1680
158
    unsigned ErrorDiagnostic) {
1681
158
  if (ErrorOnTagTypeMismatch)
1682
4
    return ErrorDiagnostic;
1683
154
1684
154
  switch (ErrorDiagnostic) {
1685
0
  case diag::err_odr_variable_type_inconsistent:
1686
0
    return diag::warn_odr_variable_type_inconsistent;
1687
0
  case diag::err_odr_variable_multiple_def:
1688
0
    return diag::warn_odr_variable_multiple_def;
1689
0
  case diag::err_odr_function_type_inconsistent:
1690
0
    return diag::warn_odr_function_type_inconsistent;
1691
88
  case diag::err_odr_tag_type_inconsistent:
1692
88
    return diag::warn_odr_tag_type_inconsistent;
1693
0
  case diag::err_odr_field_type_inconsistent:
1694
0
    return diag::warn_odr_field_type_inconsistent;
1695
0
  case diag::err_odr_ivar_type_inconsistent:
1696
0
    return diag::warn_odr_ivar_type_inconsistent;
1697
0
  case diag::err_odr_objc_superclass_inconsistent:
1698
0
    return diag::warn_odr_objc_superclass_inconsistent;
1699
0
  case diag::err_odr_objc_method_result_type_inconsistent:
1700
0
    return diag::warn_odr_objc_method_result_type_inconsistent;
1701
0
  case diag::err_odr_objc_method_num_params_inconsistent:
1702
0
    return diag::warn_odr_objc_method_num_params_inconsistent;
1703
0
  case diag::err_odr_objc_method_param_type_inconsistent:
1704
0
    return diag::warn_odr_objc_method_param_type_inconsistent;
1705
0
  case diag::err_odr_objc_method_variadic_inconsistent:
1706
0
    return diag::warn_odr_objc_method_variadic_inconsistent;
1707
0
  case diag::err_odr_objc_property_type_inconsistent:
1708
0
    return diag::warn_odr_objc_property_type_inconsistent;
1709
0
  case diag::err_odr_objc_property_impl_kind_inconsistent:
1710
0
    return diag::warn_odr_objc_property_impl_kind_inconsistent;
1711
0
  case diag::err_odr_objc_synthesize_ivar_inconsistent:
1712
0
    return diag::warn_odr_objc_synthesize_ivar_inconsistent;
1713
0
  case diag::err_odr_different_num_template_parameters:
1714
0
    return diag::warn_odr_different_num_template_parameters;
1715
58
  case diag::err_odr_different_template_parameter_kind:
1716
58
    return diag::warn_odr_different_template_parameter_kind;
1717
0
  case diag::err_odr_parameter_pack_non_pack:
1718
0
    return diag::warn_odr_parameter_pack_non_pack;
1719
8
  case diag::err_odr_non_type_parameter_type_inconsistent:
1720
8
    return diag::warn_odr_non_type_parameter_type_inconsistent;
1721
0
  }
1722
0
  llvm_unreachable("Diagnostic kind not handled in preceding switch");
1723
0
}
1724
1725
52.1k
bool StructuralEquivalenceContext::IsEquivalent(Decl *D1, Decl *D2) {
1726
52.1k
1727
52.1k
  // Ensure that the implementation functions (all static functions in this TU)
1728
52.1k
  // never call the public ASTStructuralEquivalence::IsEquivalent() functions,
1729
52.1k
  // because that will wreak havoc the internal state (DeclsToCheck and
1730
52.1k
  // VisitedDecls members) and can cause faulty behaviour.
1731
52.1k
  // In other words: Do not start a graph search from a new node with the
1732
52.1k
  // internal data of another search in progress.
1733
52.1k
  // FIXME: Better encapsulation and separation of internal and public
1734
52.1k
  // functionality.
1735
52.1k
  assert(DeclsToCheck.empty());
1736
52.1k
  assert(VisitedDecls.empty());
1737
52.1k
1738
52.1k
  if (!::IsStructurallyEquivalent(*this, D1, D2))
1739
84
    return false;
1740
52.0k
1741
52.0k
  return !Finish();
1742
52.0k
}
1743
1744
1.92k
bool StructuralEquivalenceContext::IsEquivalent(QualType T1, QualType T2) {
1745
1.92k
  assert(DeclsToCheck.empty());
1746
1.92k
  assert(VisitedDecls.empty());
1747
1.92k
  if (!::IsStructurallyEquivalent(*this, T1, T2))
1748
77
    return false;
1749
1.85k
1750
1.85k
  return !Finish();
1751
1.85k
}
1752
1753
84.5k
bool StructuralEquivalenceContext::CheckCommonEquivalence(Decl *D1, Decl *D2) {
1754
84.5k
  // Check for equivalent described template.
1755
84.5k
  TemplateDecl *Template1 = D1->getDescribedTemplate();
1756
84.5k
  TemplateDecl *Template2 = D2->getDescribedTemplate();
1757
84.5k
  if ((Template1 != nullptr) != (Template2 != nullptr))
1758
14
    return false;
1759
84.5k
  if (Template1 && 
!IsStructurallyEquivalent(*this, Template1, Template2)309
)
1760
40
    return false;
1761
84.5k
1762
84.5k
  // FIXME: Move check for identifier names into this function.
1763
84.5k
1764
84.5k
  return true;
1765
84.5k
}
1766
1767
bool StructuralEquivalenceContext::CheckKindSpecificEquivalence(
1768
84.5k
    Decl *D1, Decl *D2) {
1769
84.5k
  // FIXME: Switch on all declaration kinds. For now, we're just going to
1770
84.5k
  // check the obvious ones.
1771
84.5k
  if (auto *Record1 = dyn_cast<RecordDecl>(D1)) {
1772
13.9k
    if (auto *Record2 = dyn_cast<RecordDecl>(D2)) {
1773
13.9k
      // Check for equivalent structure names.
1774
13.9k
      IdentifierInfo *Name1 = Record1->getIdentifier();
1775
13.9k
      if (!Name1 && 
Record1->getTypedefNameForAnonDecl()1.53k
)
1776
9
        Name1 = Record1->getTypedefNameForAnonDecl()->getIdentifier();
1777
13.9k
      IdentifierInfo *Name2 = Record2->getIdentifier();
1778
13.9k
      if (!Name2 && 
Record2->getTypedefNameForAnonDecl()1.53k
)
1779
11
        Name2 = Record2->getTypedefNameForAnonDecl()->getIdentifier();
1780
13.9k
      if (!::IsStructurallyEquivalent(Name1, Name2) ||
1781
13.9k
          
!::IsStructurallyEquivalent(*this, Record1, Record2)13.3k
)
1782
1.04k
        return false;
1783
0
    } else {
1784
0
      // Record/non-record mismatch.
1785
0
      return false;
1786
0
    }
1787
70.6k
  } else if (auto *Enum1 = dyn_cast<EnumDecl>(D1)) {
1788
65
    if (auto *Enum2 = dyn_cast<EnumDecl>(D2)) {
1789
65
      // Check for equivalent enum names.
1790
65
      IdentifierInfo *Name1 = Enum1->getIdentifier();
1791
65
      if (!Name1 && 
Enum1->getTypedefNameForAnonDecl()15
)
1792
15
        Name1 = Enum1->getTypedefNameForAnonDecl()->getIdentifier();
1793
65
      IdentifierInfo *Name2 = Enum2->getIdentifier();
1794
65
      if (!Name2 && 
Enum2->getTypedefNameForAnonDecl()15
)
1795
15
        Name2 = Enum2->getTypedefNameForAnonDecl()->getIdentifier();
1796
65
      if (!::IsStructurallyEquivalent(Name1, Name2) ||
1797
65
          !::IsStructurallyEquivalent(*this, Enum1, Enum2))
1798
26
        return false;
1799
0
    } else {
1800
0
      // Enum/non-enum mismatch
1801
0
      return false;
1802
0
    }
1803
70.5k
  } else if (const auto *Typedef1 = dyn_cast<TypedefNameDecl>(D1)) {
1804
0
    if (const auto *Typedef2 = dyn_cast<TypedefNameDecl>(D2)) {
1805
0
      if (!::IsStructurallyEquivalent(Typedef1->getIdentifier(),
1806
0
                                      Typedef2->getIdentifier()) ||
1807
0
          !::IsStructurallyEquivalent(*this, Typedef1->getUnderlyingType(),
1808
0
                                      Typedef2->getUnderlyingType()))
1809
0
        return false;
1810
0
    } else {
1811
0
      // Typedef/non-typedef mismatch.
1812
0
      return false;
1813
0
    }
1814
70.5k
  } else if (auto *ClassTemplate1 = dyn_cast<ClassTemplateDecl>(D1)) {
1815
7.65k
    if (auto *ClassTemplate2 = dyn_cast<ClassTemplateDecl>(D2)) {
1816
7.65k
      if (!::IsStructurallyEquivalent(*this, ClassTemplate1,
1817
7.65k
                                      ClassTemplate2))
1818
84
        return false;
1819
0
    } else {
1820
0
      // Class template/non-class-template mismatch.
1821
0
      return false;
1822
0
    }
1823
62.8k
  } else if (auto *FunctionTemplate1 = dyn_cast<FunctionTemplateDecl>(D1)) {
1824
355
    if (auto *FunctionTemplate2 = dyn_cast<FunctionTemplateDecl>(D2)) {
1825
354
      if (!::IsStructurallyEquivalent(*this, FunctionTemplate1,
1826
354
                                      FunctionTemplate2))
1827
8
        return false;
1828
1
    } else {
1829
1
      // Class template/non-class-template mismatch.
1830
1
      return false;
1831
1
    }
1832
62.5k
  } else if (auto *ConceptDecl1 = dyn_cast<ConceptDecl>(D1)) {
1833
0
    if (auto *ConceptDecl2 = dyn_cast<ConceptDecl>(D2)) {
1834
0
      if (!::IsStructurallyEquivalent(*this, ConceptDecl1, ConceptDecl2))
1835
0
        return false;
1836
0
    } else {
1837
0
      // Concept/non-concept mismatch.
1838
0
      return false;
1839
0
    }
1840
62.5k
  } else if (auto *TTP1 = dyn_cast<TemplateTypeParmDecl>(D1)) {
1841
10.0k
    if (auto *TTP2 = dyn_cast<TemplateTypeParmDecl>(D2)) {
1842
10.0k
      if (!::IsStructurallyEquivalent(*this, TTP1, TTP2))
1843
0
        return false;
1844
0
    } else {
1845
0
      // Kind mismatch.
1846
0
      return false;
1847
0
    }
1848
52.4k
  } else if (auto *NTTP1 = dyn_cast<NonTypeTemplateParmDecl>(D1)) {
1849
2.80k
    if (auto *NTTP2 = dyn_cast<NonTypeTemplateParmDecl>(D2)) {
1850
2.80k
      if (!::IsStructurallyEquivalent(*this, NTTP1, NTTP2))
1851
10
        return false;
1852
0
    } else {
1853
0
      // Kind mismatch.
1854
0
      return false;
1855
0
    }
1856
49.6k
  } else if (auto *TTP1 = dyn_cast<TemplateTemplateParmDecl>(D1)) {
1857
8
    if (auto *TTP2 = dyn_cast<TemplateTemplateParmDecl>(D2)) {
1858
8
      if (!::IsStructurallyEquivalent(*this, TTP1, TTP2))
1859
0
        return false;
1860
0
    } else {
1861
0
      // Kind mismatch.
1862
0
      return false;
1863
0
    }
1864
49.6k
  } else if (auto *MD1 = dyn_cast<CXXMethodDecl>(D1)) {
1865
48.8k
    if (auto *MD2 = dyn_cast<CXXMethodDecl>(D2)) {
1866
48.8k
      if (!::IsStructurallyEquivalent(*this, MD1, MD2))
1867
44.6k
        return false;
1868
1
    } else {
1869
1
      // Kind mismatch.
1870
1
      return false;
1871
1
    }
1872
822
  } else if (FunctionDecl *FD1 = dyn_cast<FunctionDecl>(D1)) {
1873
803
    if (FunctionDecl *FD2 = dyn_cast<FunctionDecl>(D2)) {
1874
802
      if (FD1->isOverloadedOperator()) {
1875
240
        if (!FD2->isOverloadedOperator())
1876
0
          return false;
1877
240
        if (FD1->getOverloadedOperator() != FD2->getOverloadedOperator())
1878
2
          return false;
1879
800
      }
1880
800
      if (!::IsStructurallyEquivalent(FD1->getIdentifier(),
1881
800
                                      FD2->getIdentifier()))
1882
3
        return false;
1883
797
      if (!::IsStructurallyEquivalent(*this, FD1, FD2))
1884
320
        return false;
1885
1
    } else {
1886
1
      // Kind mismatch.
1887
1
      return false;
1888
1
    }
1889
19
  } else if (FriendDecl *FrD1 = dyn_cast<FriendDecl>(D1)) {
1890
13
    if (FriendDecl *FrD2 = dyn_cast<FriendDecl>(D2)) {
1891
13
        if (!::IsStructurallyEquivalent(*this, FrD1, FrD2))
1892
0
          return false;
1893
0
    } else {
1894
0
      // Kind mismatch.
1895
0
      return false;
1896
0
    }
1897
38.3k
  }
1898
38.3k
1899
38.3k
  return true;
1900
38.3k
}
1901
1902
53.8k
bool StructuralEquivalenceContext::Finish() {
1903
92.2k
  while (!DeclsToCheck.empty()) {
1904
84.5k
    // Check the next declaration.
1905
84.5k
    std::pair<Decl *, Decl *> P = DeclsToCheck.front();
1906
84.5k
    DeclsToCheck.pop();
1907
84.5k
1908
84.5k
    Decl *D1 = P.first;
1909
84.5k
    Decl *D2 = P.second;
1910
84.5k
1911
84.5k
    bool Equivalent =
1912
84.5k
        CheckCommonEquivalence(D1, D2) && 
CheckKindSpecificEquivalence(D1, D2)84.5k
;
1913
84.5k
1914
84.5k
    if (!Equivalent) {
1915
46.1k
      // Note that these two declarations are not equivalent (and we already
1916
46.1k
      // know about it).
1917
46.1k
      NonEquivalentDecls.insert(P);
1918
46.1k
1919
46.1k
      return true;
1920
46.1k
    }
1921
84.5k
  }
1922
53.8k
1923
53.8k
  
return false7.68k
;
1924
53.8k
}