Merge pull request #85492 from swiftlang/rauhul/cxx-exception-personality

This commit is contained in:
Rauhul Varma
2025-12-01 08:25:25 -08:00
committed by GitHub
3 changed files with 37 additions and 3 deletions

View File

@@ -225,12 +225,13 @@ linkEmbeddedRuntimeFunctionByName(#NAME, EFFECT, StringRef(#CC) == "C_CC"); \
}
for (auto *F : Functions) {
auto declRef = SILDeclRef(F, SILDeclRef::Kind::Func);
auto declRef = SILDeclRef(F, SILDeclRef::Kind::Func,
F->hasOnlyCEntryPoint());
auto *Fn = linkUsedFunctionByName(declRef.mangle(), /*Linkage*/{},
/*byAsmName=*/false);
// If we have @_cdecl or @_silgen_name, also link the foreign thunk
if (Fn->hasCReferences()) {
if (Fn->hasCReferences() && !F->hasOnlyCEntryPoint()) {
auto declRef = SILDeclRef(F, SILDeclRef::Kind::Func, /*isForeign*/true);
linkUsedFunctionByName(declRef.mangle(), /*Linkage*/{},
/*byAsmName=*/false);

View File

@@ -432,7 +432,7 @@ func isValidPointerForNativeRetain(object: Builtin.RawPointer) -> Bool {
#if _pointerBitWidth(_64)
if unsafe (objectBits & HeapObject.immortalObjectPointerBit) != 0 { return false }
#endif
return true
}
@@ -750,3 +750,19 @@ func _embeddedReportFatalErrorInFile(prefix: StaticString, message: UnsafeBuffer
if message.count > 0 { print(": ", terminator: "") }
unsafe print(message)
}
// CXX Exception Personality
public typealias _Unwind_Action = CInt
public typealias _Unwind_Reason_Code = CInt
@c @used
public func _swift_exceptionPersonality(
version: CInt,
actions: _Unwind_Action,
exceptionClass: UInt64,
exceptionObject: UnsafeMutableRawPointer,
context: UnsafeMutableRawPointer
) -> _Unwind_Reason_Code {
fatalError("C++ exception handling detected but the Embedded Swift runtime does not support exceptions")
}

View File

@@ -0,0 +1,17 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -enable-experimental-feature Embedded -O -c -o %t/main.o -cxx-interoperability-mode=default
// RUN: %target-clang %target-clang-resource-dir-opt %t/main.o -o %t/a.out -dead_strip
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: swift_feature_Embedded
@_expose(Cxx)
func f1() {
print("OK!")
}
f1()
// CHECK: OK!