Skip to content

Commit 5dff8e3

Browse files
authored
Merge pull request #62516 from hyp/eng/fix-record-metadata
[interop][SwiftToCxx] only emit metadata references for record types
2 parents 36f2eb1 + 7c2ee16 commit 5dff8e3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/PrintAsClang/ModuleContentsWriter.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,14 @@ class ModuleWriter {
280280
if (!isa<clang::TypeDecl>(typeDecl->getClangDecl()))
281281
return;
282282
// Get the underlying clang type from a type alias decl or record decl.
283-
clang::QualType clangType(
284-
cast<clang::TypeDecl>(typeDecl->getClangDecl())->getTypeForDecl(), 0);
285-
auto it = seenClangTypes.insert(clangType.getCanonicalType().getTypePtr());
283+
auto clangType =
284+
clang::QualType(
285+
cast<clang::TypeDecl>(typeDecl->getClangDecl())->getTypeForDecl(),
286+
0)
287+
.getCanonicalType();
288+
if (!isa<clang::RecordType>(clangType.getTypePtr()))
289+
return;
290+
auto it = seenClangTypes.insert(clangType.getTypePtr());
286291
if (it.second)
287292
ClangValueTypePrinter::printClangTypeSwiftGenericTraits(os, typeDecl, &M);
288293
}

test/Interop/CxxToSwiftToCxx/bridge-cxx-struct-back-to-cxx.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ namespace ns {
7373
using NonTrivialTemplateTrivial = NonTrivialTemplate<TrivialinNS>;
7474
}
7575

76+
using SimpleTypedef = int;
77+
7678
//--- module.modulemap
7779
module CxxTest {
7880
header "header.h"
@@ -112,6 +114,11 @@ public func retNonTrivialTypeAlias() -> ns.TypeAlias {
112114
return ns.TypeAlias()
113115
}
114116

117+
@_expose(Cxx)
118+
public func retSimpleTypedef() -> SimpleTypedef {
119+
return SimpleTypedef()
120+
}
121+
115122
@_expose(Cxx)
116123
public func retTrivial() -> Trivial {
117124
return Trivial()

0 commit comments

Comments
 (0)