Skip to content

Commit 5424ddd

Browse files
authored
Merge pull request #75644 from swiftlang/gaborh/embedded-swift
[cxx-interop] Fix crash with reverse interop in Embedded Swift
2 parents df9ff6c + a05b305 commit 5424ddd

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lib/PrintAsClang/PrintSwiftToClangCoreScaffold.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,22 @@ void printPrimitiveGenericTypeTraits(raw_ostream &os, ASTContext &astContext,
186186
if (!(isSwiftIntLong && !isInt64Long))
187187
primTypesArray = primTypesArray.drop_back(2);
188188

189+
// We do not have metadata for primitive types in Embedded Swift.
190+
bool embedded = astContext.LangOpts.hasFeature(Feature::Embedded);
191+
189192
for (Type type : primTypesArray) {
190193
auto typeInfo = *typeMapping.getKnownCxxTypeInfo(
191194
type->getNominalOrBoundGenericNominal());
192195

196+
if (!isCForwardDefinition) {
197+
os << "template<>\n";
198+
os << "static inline const constexpr bool isUsableInGenericContext<"
199+
<< typeInfo.name << "> = true;\n\n";
200+
}
201+
202+
if (embedded)
203+
continue;
204+
193205
auto typeMetadataFunc = irgen::LinkEntity::forTypeMetadata(
194206
type->getCanonicalType(), irgen::TypeMetadataAddress::AddressPoint);
195207
std::string typeMetadataVarName = typeMetadataFunc.mangleAsString();
@@ -201,10 +213,6 @@ void printPrimitiveGenericTypeTraits(raw_ostream &os, ASTContext &astContext,
201213
continue;
202214
}
203215

204-
os << "template<>\n";
205-
os << "static inline const constexpr bool isUsableInGenericContext<"
206-
<< typeInfo.name << "> = true;\n\n";
207-
208216
os << "template<>\nstruct TypeMetadataTrait<" << typeInfo.name << "> {\n"
209217
<< " static ";
210218
ClangSyntaxPrinter(os).printInlineForThunk();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -typecheck -module-name Core -target arm64-apple-macos15.0 -enable-experimental-feature Embedded -clang-header-expose-decls=all-public -emit-clang-header-path %t/core.h
3+
// RUN: %FileCheck %s < %t/core.h
4+
5+
// REQUIRES: OS=macosx
6+
7+
public func id(_ x: Int) -> Int {
8+
return x
9+
}
10+
11+
// CHECK-NOT: TypeMetadataTrait<bool>

0 commit comments

Comments
 (0)