@@ -1476,6 +1476,27 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
1476
1476
}
1477
1477
}
1478
1478
1479
+ static bool checkDuplicatedMethodName (StringRef funcName,
1480
+ const AccessorDecl *AD,
1481
+ DeclAndTypePrinter &declAndTypePrinter,
1482
+ raw_ostream &os) {
1483
+ auto *&decl = declAndTypePrinter.getCxxDeclEmissionScope ()
1484
+ .emittedAccessorMethodNames [funcName];
1485
+
1486
+ if (!decl) {
1487
+ // This is the first time an accessor with this name has been emitted.
1488
+ decl = AD;
1489
+ } else if (decl != AD) {
1490
+ // An accessor for another property had the same name.
1491
+ os << " // skip emitting accessor method for \' "
1492
+ << AD->getStorage ()->getBaseIdentifier ().str () << " \' . \' " << funcName
1493
+ << " \' already declared.\n " ;
1494
+ return false ;
1495
+ }
1496
+
1497
+ return true ;
1498
+ }
1499
+
1479
1500
void DeclAndTypeClangFunctionPrinter::printCxxMethod (
1480
1501
DeclAndTypePrinter &declAndTypePrinter,
1481
1502
const NominalTypeDecl *typeDeclContext, const AbstractFunctionDecl *FD,
@@ -1552,6 +1573,12 @@ void DeclAndTypeClangFunctionPrinter::printCxxPropertyAccessorMethod(
1552
1573
Type resultTy, bool isStatic, bool isDefinition,
1553
1574
std::optional<IRABIDetailsProvider::MethodDispatchInfo> dispatchInfo) {
1554
1575
assert (accessor->isSetter () || accessor->getParameters ()->size () == 0 );
1576
+ std::string accessorName = remapPropertyName (accessor, resultTy);
1577
+
1578
+ if (!checkDuplicatedMethodName (accessorName, accessor, declAndTypePrinter,
1579
+ os))
1580
+ return ;
1581
+
1555
1582
os << " " ;
1556
1583
1557
1584
FunctionSignatureModifiers modifiers;
@@ -1563,9 +1590,9 @@ void DeclAndTypeClangFunctionPrinter::printCxxPropertyAccessorMethod(
1563
1590
!isStatic && accessor->isGetter () && !isa<ClassDecl>(typeDeclContext);
1564
1591
modifiers.hasSymbolUSR = !isDefinition;
1565
1592
modifiers.symbolUSROverride = accessor->getStorage ();
1566
- auto result = printFunctionSignature (
1567
- accessor, signature, remapPropertyName (accessor, resultTy) , resultTy,
1568
- FunctionSignatureKind::CxxInlineThunk, modifiers);
1593
+ auto result =
1594
+ printFunctionSignature ( accessor, signature, accessorName , resultTy,
1595
+ FunctionSignatureKind::CxxInlineThunk, modifiers);
1569
1596
assert (!result.isUnsupported () && " C signature should be unsupported too!" );
1570
1597
declAndTypePrinter.printAvailability (os, accessor->getStorage ());
1571
1598
if (!isDefinition) {
0 commit comments