I found a problem with the latest Xcode 13.2/13.2.1 when compiling SwiftUI if-#available
structure. When building with Release mode, the app always crashes on an older system.
import SwiftUI
struct ContentView: View {
var body: some View {
List {
if #available(iOS 15.0, *) {
Text("Hello").badge(1)
} else {
Text("Hello") // 💥 always crash: iOS 14 + release mode
}
}
}
}
Sample crash log:
OS Version: iPhone OS 14.8.1 (18H107)
Release Type: User
Baseband Version: n/a
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
VM Region Info: 0 is not in any region. Bytes before following region: 4328914944
...
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [54802]
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 libswiftCore.dylib 0x00000001b0a74750 swift::ResolveAsSymbolicReference::operator()(swift::Demangle::__runtime::SymbolicReferenceKind, swift::Demangle::__runtime::Directness, int, void const*) + 124 (MetadataValues.h:1263)
1 libswiftCore.dylib 0x00000001b0a96018 swift::Demangle::__runtime::Demangler::demangleSymbolicReference(unsigned char) + 212 (functional:1880)
2 libswiftCore.dylib 0x00000001b0a92d04 swift::Demangle::__runtime::Demangler::demangleType(__swift::__runtime::llvm::StringRef, std::__1::function<swift::Demangle::__runtime::Node* (swift::Demangle::__runtime::SymbolicReferenceKind, swi... + 200 (Demangler.cpp:589)
3 libswiftCore.dylib 0x00000001b0a7a660 swift_getTypeByMangledNameImpl(swift::MetadataRequest, __swift::__runtime::llvm::StringRef, void const* const*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsi... + 496 (MetadataLookup.cpp:69)
4 libswiftCore.dylib 0x00000001b0a77ab0 swift::swift_getTypeByMangledName(swift::MetadataRequest, __swift::__runtime::llvm::StringRef, void const* const*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, u... + 604 (CompatibilityOverride.def:153)
...
I tested this in the 13.3 beta (13E5086k) and this issue is not longer happening although I didn't find anything about this in the release notes https://developer.apple.com/documentation/xcode-release-notes/xcode-13_3-release-notes