@@ -1443,8 +1443,11 @@ std::string SILDeclRef::mangle(ManglingKind MKind) const {
14431443 return NameA->Name .str ();
14441444 }
14451445
1446- // Use a given cdecl name for native-to-foreign thunks.
1447- if (getDecl ()->getAttrs ().hasAttribute <CDeclAttr>())
1446+ // Use a given cdecl name for native-to-foreign thunks. Don't do this
1447+ // for functions that only have a C entrypoint.
1448+ if (getDecl ()->getAttrs ().hasAttribute <CDeclAttr>() &&
1449+ !(getDecl ()->hasOnlyCEntryPoint () &&
1450+ !getDecl ()->getImplementedObjCDecl ())) {
14481451 if (isNativeToForeignThunk () || isForeign) {
14491452 // If this is an @implementation @_cdecl, mangle it like the clang
14501453 // function it implements.
@@ -1455,6 +1458,7 @@ std::string SILDeclRef::mangle(ManglingKind MKind) const {
14551458 }
14561459 return getDecl ()->getCDeclName ().str ();
14571460 }
1461+ }
14581462
14591463 if (SKind == ASTMangler::SymbolKind::DistributedThunk) {
14601464 return mangler.mangleDistributedThunk (cast<FuncDecl>(getDecl ()));
@@ -1543,6 +1547,19 @@ std::string SILDeclRef::mangle(ManglingKind MKind) const {
15431547 llvm_unreachable (" bad entity kind!" );
15441548}
15451549
1550+ std::optional<StringRef> SILDeclRef::getAsmName () const {
1551+ if (isForeign && isFunc ()) {
1552+ auto func = getFuncDecl ();
1553+ if (auto *EA = ExternAttr::find (func->getAttrs (), ExternKind::C))
1554+ return EA->getCName (func);
1555+ if (func->hasOnlyCEntryPoint () && !func->getImplementedObjCDecl ())
1556+ return func->getCDeclName ();
1557+ }
1558+
1559+ return std::nullopt ;
1560+ }
1561+
1562+
15461563// Returns true if the given JVP/VJP SILDeclRef requires a new vtable entry.
15471564// FIXME(https://github.com/apple/swift/issues/54833): Also consider derived declaration `@derivative` attributes.
15481565static bool derivativeFunctionRequiresNewVTableEntry (SILDeclRef declRef) {
0 commit comments