Swift compiler crash - anyone seen this? - swift

I have an Obj-C class extending NSObject. One of its properties is an NS_ENUM; let's call it direction.
Then I have a Swift class with an optional property of this Obj-C class; let's call that message.
The following example code is fine:
switch message?.direction
{
case .Inbound:
...
case .OutBound:
...
case nil:
...
}
However, if I then introduce:
guard let message = self.message else { return }
and remove the ? in the code above, the compiler crashes; see below.
It seems to get confused by case nil:, because the crash disappears if I delete it; it's of course no longer needed.
Just curious, has anyone seen this Swift compiler crash?
1. Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
2. While emitting IR SIL function "#$s7SomeFunction...".
for 'update()' (at /Users/.../SomeFile.swift:83:11)
0 swift 0x00000001133554ea PrintStackTraceSignalHandler(void*) + 42
1 swift 0x0000000113354cc0 SignalHandler(int) + 352
2 libsystem_platform.dylib 0x00007fff6b8d75fd _sigtramp + 29
3 swift 0x000000010f1aaa4c (anonymous namespace)::SinglePayloadEnumImplStrategy::consume(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Atomicity) const + 1244
4 swift 0x00000001131d082c llvm::IRBuilderBase::CreateLifetimeEnd(llvm::Value*, llvm::ConstantInt*) + 28
5 swift 0x000000010f2105a1 swift::irgen::FixedTypeInfo::deallocateStack(swift::irgen::IRGenFunction&, swift::irgen::StackAddress, swift::SILType) const + 81
6 swift 0x000000010f2e8244 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 33828
7 swift 0x000000010f2dc8e3 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8835
8 swift 0x000000010f190032 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1410
9 swift 0x000000010f2baed9 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 1097
10 swift 0x000000010f0b236f performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 4255
11 swift 0x000000010f0a77c0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48416
12 swift 0x000000010f01f4d3 main + 1283
13 libdyld.dylib 0x00007fff6b6decc9 start + 1
error: Segmentation fault: 11 (in target 'SomeApp' from project 'SomeApp')

Related

Segmentation fault on a simple swift script

I have a very simple script written in swift and running this with swift file.swift
import Foundation
let url = URL(string: "www.google.com")
and this gives me a segfault error with this message
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret file.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name file
1. Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
2. While running user code "file.swift"
0 swift 0x00000001101354ea PrintStackTraceSignalHandler(void*) + 42
1 swift 0x0000000110134cc0 SignalHandler(int) + 352
2 libsystem_platform.dylib 0x00007fff6c0aa5fd _sigtramp + 29
3 libsystem_platform.dylib 0x00007ffee3e196a8 _sigtramp + 2010575048
4 swift 0x000000010beb89ba llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 458
5 swift 0x000000010bebfa2b llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 2011
6 swift 0x000000010be94aea performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 14362
7 swift 0x000000010be894a5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 55813
8 swift 0x000000010bdff4d3 main + 1283
9 libdyld.dylib 0x00007fff6beb1cc9 start + 1
zsh: segmentation fault swift file.swift
any ideas as to where the problem is? Thanks!
EDIT: I have tried putting the code to Xcode and it works as it should.
I had a script which was working and suddenly stopped. Exactly on the line where I have created an URL. It was working on Xcode but not from terminal.
Looks like, it is bug.
If you first compile by using swiftc then run it, it is working.
I have found the answer in the following page:
https://blog.kulman.sk/workaround-for-swift-scripts-crash/

Xcode 11 Segmentation fault: 11 during Archive

I'm receiving a segmentation fault in Xcode 11 when I do an Archive of Generic iOS Device. The file this apparently is occurring in, "InformationMenu", hasn't been touched in months so I have no idea what's causing this.
I've tried making changes to the Optimization Level with no luck. The app builds on devices and simulators which makes this all the more frustrating.
Everything is written in Swift 4, target is iOS 11 and above.
Not sure where to go from here.
InformationMenu.bc
1. While running pass #111377 SILModuleTransform "OwnershipModelEliminator".
0 swift 0x0000000110142eb3 PrintStackTraceSignalHandler(void*) + 51
1 swift 0x0000000110142686 SignalHandler(int) + 358
2 libsystem_platform.dylib 0x00007fff6b1b3b5d _sigtramp + 29
3 libsystem_malloc.dylib 0x00007fff6b174401 tiny_malloc_should_clear + 256
4 swift 0x000000010c4d1cbb (anonymous namespace)::OwnershipModelEliminator::run() + 267
5 swift 0x000000010c441849 swift::SILPassManager::execute() + 7305
6 swift 0x000000010c445c1b swift::runSILDiagnosticPasses(swift::SILModule&) + 2539
7 swift 0x000000010c09de06 swift::CompilerInstance::performSILProcessing(swift::SILModule*, swift::UnifiedStatsReporter*) + 70
8 swift 0x000000010bd99ae5 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 33925
9 swift 0x000000010bd8de54 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
10 swift 0x000000010bd1b3c3 main + 1219
11 libdyld.dylib 0x00007fff6afc83d5 start + 1
12 libdyld.dylib 0x00000000000001ab start + 2500034007

How to fix Swift compile issue trap6

The issue happen in Swift3 with XCode10.That maybe be a Swift bug。 Actually,clean and rebuild can solve the issue,but that wast too much time。Any body know a effect way to solve or avoid the issue。Thank you
** DESERIALIZATION FAILURE (please include this section in any bug report) ***
could not deserialize type for '_': could not deserialize type for 'operImageView': top-level value not found
Cross-reference to module 'LKImageKit'
... LKImageView
0 swift 0x000000010460f59a PrintStackTraceSignalHandler(void*) + 42
1 swift 0x000000010460ed4e SignalHandler(int) + 302
2 libsystem_platform.dylib 0x00007fff5e91df5a _sigtramp + 26
3 libsystem_platform.dylib 0x00007fe96482b200 _sigtramp + 99668672
4 libsystem_c.dylib 0x00007fff5e6bb1ae abort + 127
5 swift 0x0000000101a74feb swift::ModuleFile::fatal(llvm::Error) + 1915
6 swift 0x0000000101aac643 getSILDeclRef(swift::ModuleFile*, llvm::ArrayRef<unsigned long long>, unsigned int&) + 307
7 swift 0x0000000101aae984 swift::SILDeserializer::readVTable(llvm::PointerEmbeddedInt<unsigned int, 31>) + 740
8 swift 0x0000000101b5576b swift::SerializedSILLoader::getAllForModule(swift::Identifier, swift::FileUnit*) + 331
9 swift 0x000000010089d92e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 34558
10 swift 0x0000000100891d35 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7717
11 swift 0x0000000100837965 main + 1349
12 libdyld.dylib 0x00007fff5e60f015 start + 1
WSRecommendHeaderCollectionReusableView~partial.swiftmodule
/Users/levinyang/Library/Developer/Xcode/DerivedData/myProject-hgotlvyrysfhcyeakqaatptobuxm/Build/Intermediates.noindex/myProject.build/Debug-iphoneos/myProject.build/Objects-normal/arm64/WSActionSheetRecommendFlowHandler~partial.swiftmodule
---
2. While deserializing SIL vtable for 'WSNotificationOperCell' in module 'myProject'
** DESERIALIZATION FAILURE (please include this section in any bug report) ***
could not deserialize type for '_': could not deserialize type for 'operImageView': top-level value not found
Cross-reference to module 'LKImageKit'
... LKImageView
0 swift 0x000000010460f59a PrintStackTraceSignalHandler(void*) + 42
1 swift 0x000000010460ed4e SignalHandler(int) + 302
2 libsystem_platform.dylib 0x00007fff5e91df5a _sigtramp + 26
3 libsystem_platform.dylib 0x00007fe96482b200 _sigtramp + 99668672
4 libsystem_c.dylib 0x00007fff5e6bb1ae abort + 127
5 swift 0x0000000101a74feb swift::ModuleFile::fatal(llvm::Error) + 1915
6 swift 0x0000000101aac643 getSILDeclRef(swift::ModuleFile*, llvm::ArrayRef<unsigned long long>, unsigned int&) + 307
7 swift 0x0000000101aae984 swift::SILDeserializer::readVTable(llvm::PointerEmbeddedInt<unsigned int, 31>) + 740
8 swift 0x0000000101b5576b swift::SerializedSILLoader::getAllForModule(swift::Identifier, swift::FileUnit*) + 331
9 swift 0x000000010089d92e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 34558
10 swift 0x0000000100891d35 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7717
11 swift 0x0000000100837965 main + 1349
12 libdyld.dylib 0x00007fff5e60f015 start + 1
WSRecommendHeaderCollectionReusableView~partial.swiftmodule
/Users/levinyang/Library/Developer/Xcode/DerivedData/myProject-hgotlvyrysfhcyeakqaatptobuxm/Build/Intermediates.noindex/myProject.build/Debug-iphoneos/myProject.build/Objects-normal/arm64/WSActionSheetRecommendFlowHandler~partial.swiftmodule
---
2. While deserializing SIL vtable for 'WSNotificationOperCell' in module 'myProject'
error: Abort trap: 6
This is a Swift compiler bug. It's possible that you're triggering it by linking modules that were compiled by different versions of the compiler, or some other unsupported behavior, but it probably still shouldn't crash.
However, you say it's a Swift 3 problem. The Swift developers no longer support Swift 3. They are working on Swift 5. If you can reproduce the problem in Swift 5, you can file a bug report at https://bugs.swift.org.

Cast to a class with a protocol as its generic type in Swift

I have several classes all conforming to a protocol called DataObject. I have another class that receives a generic type that also conforms to DataObject, e.g.:
protocol DataObject {
func foo()
//...
}
class A : DataObject {
//...
}
class B : DataObject {
//...
}
class C : DataObject {
//...
}
class SomeClass<T: DataObject> {
//...
}
Later in my code I have an object of type AnyObject that I need to cast to SomeClass. I don't know the specific type of the object inside SomeClass (and don't care). However, whenever I do:
var someClass = obj as? SomeClass<DataObject>
The compiler gives an error of what seems to be a crash in the compiling process - "Command failed due to signal: Segmentation Fault: 11".
Somewhere in the middle of the error details there's a call stack of the crash:
0 swift 0x000000010fecb2b8 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x000000010fecb794 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff87563f1a _sigtramp + 26
3 swift 0x00000001112b0637 llvm::DenseMapAPIntKeyInfo::getHashValue(llvm::DenseMapAPIntKeyInfo::KeyTy const&) + 151
4 swift 0x000000010f84db39 swift::irgen::emitWitnessTableRefs(swift::irgen::IRGenFunction&, swift::Substitution const&, llvm::SmallVectorImpl<llvm::Value*>&) + 329
5 swift 0x000000010f8280be emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType) + 1310
6 swift 0x000000010f81a3d4 getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t) + 580
7 swift 0x000000010f813526 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 54
8 swift 0x000000010f7dca9f swift::irgen::emitClassDowncast(swift::irgen::IRGenFunction&, llvm::Value*, swift::SILType, swift::irgen::CheckedCastMode) + 143
9 swift 0x000000010f89ac89 emitValueCheckedCast((anonymous namespace)::IRGenSILFunction&, swift::SILValue, swift::SILType, swift::irgen::CheckedCastMode, swift::irgen::Explosion&) + 1065
10 swift 0x000000010f894bfa swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 23626
11 swift 0x000000010f88e39d swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9901
12 swift 0x000000010f7f8f4f swift::irgen::IRGenModule::emitGlobalTopLevel() + 159
13 swift 0x000000010f878c59 performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 2121
14 swift 0x000000010f879693 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51
15 swift 0x000000010f7b5087 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 6647
16 swift 0x000000010f7b34e6 main + 1814
17 libdyld.dylib 0x00007fff8db4d5c9 start + 1
I'm really stuck as I cannot use the object the way I should... Any explanations to why this happens, or better yet, any workarounds?

Swift compiler error in for loop

When I try to list the available fonts in the system with the code below, I get the error message attached. Is anything wrong with my code or is this a compiler bug?
for fontFamilyName: String! in UIFont.familyNames() {
for fontName: String! in UIFont.fontNamesForFamilyName(fontFamilyName) {
println("font: \(fontName)")
}
}
Error message:
0 swift 0x0000000101678e08 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x00000001016792f4 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff8968a5aa _sigtramp + 26
3 libsystem_platform.dylib 0x0000000102a79a00 _sigtramp + 2034168944
4 swift 0x00000001015759b7 llvm::StoreInst::StoreInst(llvm::Value*, llvm::Value*, bool, llvm::Instruction*) + 55
5 swift 0x0000000100aca412 swift::irgen::IRBuilder::CreateStore(llvm::Value*, llvm::Value*, swift::irgen::Alignment) + 66
6 swift 0x0000000100a9737c (anonymous namespace)::PayloadEnumImplStrategyBase::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address) const + 124
7 swift 0x0000000100abd070 swift::irgen::SequentialTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address) const + 224
8 swift 0x0000000100abd070 swift::irgen::SequentialTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address) const + 224
9 swift 0x0000000100ae5a48 swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 31240
10 swift 0x0000000100add846 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8678
11 swift 0x0000000100a5ecd8 swift::irgen::IRGenModule::emitGlobalTopLevel() + 184
12 swift 0x0000000100acacc3 performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1859
13 swift 0x0000000100acb613 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51
14 swift 0x0000000100a3d95a frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 4842
15 swift 0x0000000100a3c65d main + 1533
16 libdyld.dylib 0x00007fff889d05fd start + 1
1. While emitting IR SIL function #_TFC10SwiftTests11AppDelegate11applicationfS0_FTCSo13UIApplication29didFinishLaunchingWithOptionsGSqCSo12NSDictionary__Sb for 'application' at /Users/hb/Developer/martsys/SwiftTests/SwiftTests/AppDelegate.swift:15:3
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)
You will be better off by casting the arrays returned from your class methods, like so:
for fontFamilyName in UIFont.familyNames() as Array<String!> {
for fontName in UIFont.fontNamesForFamilyName(fontFamilyName) as Array<String!> {
println("font: \(fontName)")
}
}
// prints fontFamilyName: Marion,
// font: Marion-Italic
// font: Marion-Bold
// font: Marion-Regular
// fontFamilyName: Copperplate
// font: Copperplate-Light
// etc.
Both, I think. Your code is wrong in such a way that it exposes a compiler bug. It appears to be blowing up on the type assertion String!. I think that this is because the return type of UIFont.familyNames() is AnyObject[]!. The ! here means it is forcibly unwrapped, so you expect to get back an AnyObject[] not a Optional<AnyObject>. So String! isn't Optional, which should be an error with a nice message, not something that crashes Xcode.
What you need to do instead is tell the compiler that the AnyObject[] it is getting back is of type String[]:
for fontFamilyName in UIFont.familyNames() as String[] {
for fontName in UIFont.fontNamesForFamilyName(fontFamilyName) as String[] {
println("font: \(fontName)")
}
}