Skip to content

Commit 27ebe4d

Browse files
authored
Merge pull request #85492 from swiftlang/rauhul/cxx-exception-personality
2 parents bf760aa + 47bc712 commit 27ebe4d

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

lib/SILOptimizer/UtilityPasses/Link.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,13 @@ linkEmbeddedRuntimeFunctionByName(#NAME, EFFECT, StringRef(#CC) == "C_CC"); \
225225
}
226226

227227
for (auto *F : Functions) {
228-
auto declRef = SILDeclRef(F, SILDeclRef::Kind::Func);
228+
auto declRef = SILDeclRef(F, SILDeclRef::Kind::Func,
229+
F->hasOnlyCEntryPoint());
229230
auto *Fn = linkUsedFunctionByName(declRef.mangle(), /*Linkage*/{},
230231
/*byAsmName=*/false);
231232

232233
// If we have @_cdecl or @_silgen_name, also link the foreign thunk
233-
if (Fn->hasCReferences()) {
234+
if (Fn->hasCReferences() && !F->hasOnlyCEntryPoint()) {
234235
auto declRef = SILDeclRef(F, SILDeclRef::Kind::Func, /*isForeign*/true);
235236
linkUsedFunctionByName(declRef.mangle(), /*Linkage*/{},
236237
/*byAsmName=*/false);

stdlib/public/core/EmbeddedRuntime.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func isValidPointerForNativeRetain(object: Builtin.RawPointer) -> Bool {
432432
#if _pointerBitWidth(_64)
433433
if unsafe (objectBits & HeapObject.immortalObjectPointerBit) != 0 { return false }
434434
#endif
435-
435+
436436
return true
437437
}
438438

@@ -750,3 +750,19 @@ func _embeddedReportFatalErrorInFile(prefix: StaticString, message: UnsafeBuffer
750750
if message.count > 0 { print(": ", terminator: "") }
751751
unsafe print(message)
752752
}
753+
754+
// CXX Exception Personality
755+
756+
public typealias _Unwind_Action = CInt
757+
public typealias _Unwind_Reason_Code = CInt
758+
759+
@c @used
760+
public func _swift_exceptionPersonality(
761+
version: CInt,
762+
actions: _Unwind_Action,
763+
exceptionClass: UInt64,
764+
exceptionObject: UnsafeMutableRawPointer,
765+
context: UnsafeMutableRawPointer
766+
) -> _Unwind_Reason_Code {
767+
fatalError("C++ exception handling detected but the Embedded Swift runtime does not support exceptions")
768+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -enable-experimental-feature Embedded -O -c -o %t/main.o -cxx-interoperability-mode=default
3+
// RUN: %target-clang %target-clang-resource-dir-opt %t/main.o -o %t/a.out -dead_strip
4+
// RUN: %target-run %t/a.out | %FileCheck %s
5+
6+
// REQUIRES: swift_in_compiler
7+
// REQUIRES: executable_test
8+
// REQUIRES: swift_feature_Embedded
9+
10+
@_expose(Cxx)
11+
func f1() {
12+
print("OK!")
13+
}
14+
15+
f1()
16+
17+
// CHECK: OK!

0 commit comments

Comments
 (0)