Skip to content

Commit 78b74da

Browse files
authored
Merge pull request #85767 from DougGregor/cxx-exception-personality-6.3
[6.3] Add Embedded Swift Cxx exception personality
2 parents 73ce0af + 71f0649 commit 78b74da

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
@@ -206,12 +206,13 @@ linkEmbeddedRuntimeFunctionByName(#NAME, EFFECT, StringRef(#CC) == "C_CC"); \
206206
}
207207

208208
for (auto *F : Functions) {
209-
auto declRef = SILDeclRef(F, SILDeclRef::Kind::Func);
209+
auto declRef = SILDeclRef(F, SILDeclRef::Kind::Func,
210+
F->hasOnlyCEntryPoint());
210211
auto *Fn = linkUsedFunctionByName(declRef.mangle(), /*Linkage*/{},
211212
/*byAsmName=*/false);
212213

213214
// If we have @_cdecl or @_silgen_name, also link the foreign thunk
214-
if (Fn->hasCReferences()) {
215+
if (Fn->hasCReferences() && !F->hasOnlyCEntryPoint()) {
215216
auto declRef = SILDeclRef(F, SILDeclRef::Kind::Func, /*isForeign*/true);
216217
linkUsedFunctionByName(declRef.mangle(), /*Linkage*/{},
217218
/*byAsmName=*/false);

stdlib/public/core/EmbeddedRuntime.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func isValidPointerForNativeRetain(object: Builtin.RawPointer) -> Bool {
271271
#if _pointerBitWidth(_64)
272272
if unsafe (objectBits & HeapObject.immortalObjectPointerBit) != 0 { return false }
273273
#endif
274-
274+
275275
return true
276276
}
277277

@@ -576,3 +576,19 @@ func _embeddedReportFatalErrorInFile(prefix: StaticString, message: UnsafeBuffer
576576
if message.count > 0 { print(": ", terminator: "") }
577577
unsafe print(message)
578578
}
579+
580+
// CXX Exception Personality
581+
582+
public typealias _Unwind_Action = CInt
583+
public typealias _Unwind_Reason_Code = CInt
584+
585+
@c @used
586+
public func _swift_exceptionPersonality(
587+
version: CInt,
588+
actions: _Unwind_Action,
589+
exceptionClass: UInt64,
590+
exceptionObject: UnsafeMutableRawPointer,
591+
context: UnsafeMutableRawPointer
592+
) -> _Unwind_Reason_Code {
593+
fatalError("C++ exception handling detected but the Embedded Swift runtime does not support exceptions")
594+
}
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)