0Day Forums
Swift compiler segmentation fault when building - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: Swift (https://0day.red/Forum-Swift)
+--- Thread: Swift compiler segmentation fault when building (/Thread-Swift-compiler-segmentation-fault-when-building)

Pages: 1 2 3 4 5 6


Swift compiler segmentation fault when building - archprelatichtyzmrwz - 07-18-2023

Adding a (convenient) computed `height` property to `UIView` in my `UIViewExtension.swift` file is causing the Swift compiler to segfault... What could possibly be going wrong here?

0 swift 0x00000001061e5608 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x00000001061e5af4 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff894da5aa _sigtramp + 26
3 libsystem_platform.dylib 0xb03939841e997c88 _sigtramp + 2504775416
4 swift 0x00000001064c8bb9 swift::NominalTypeDecl::getMembers(bool) const + 41
5 swift 0x00000001055efab9 swift::irgen::ClassMetadataLayout<(anonymous namespace)::FindClassMethodIndex>::addClassMembers(swift::ClassDecl*) + 329
6 swift 0x00000001055e97b2 swift::irgen::emitVirtualMethodValue(swift::irgen::IRGenFunction&, llvm::Value*, swift::SILType, swift::SILDeclRef, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ResilienceExpansion) + 434
7 swift 0x00000001056550d3 swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 42611
8 swift 0x000000010564a266 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8678
9 swift 0x00000001055cb6f8 swift::irgen::IRGenModule::emitGlobalTopLevel() + 184
10 swift 0x00000001056376e3 performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1859
11 swift 0x0000000105638033 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51
12 swift 0x00000001055aa65a frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 4842
13 swift 0x00000001055a935d main + 1533
14 libdyld.dylib 0x00007fff8a82e5fd start + 1

 

1. While emitting IR SIL function @_TFCSo6UIViewg6heightSd for 'anonname=0x7ff422892fd0' at <path redacted>/UIViewExtension.swift:60:5
<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)
Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254

If more information is needed to crack this, just comment. Thanks!

### Edit:
Here's a related .xcodeproj that returns this question's compiler error. [**Download here**](

[To see links please register here]

)


RE: Swift compiler segmentation fault when building - impactors759163 - 07-18-2023

Segmentation faults can happen because of many reasons including compiler issues. I noticed in most cases using of protocols are involved and causes confusion in the compiler or sometimes module optimization process during compiler will lead to such an error.

I contacted Apple for one of these cases and they gave me a hidden attribute `@_optimize(none)` that you can add it to the initializer of your class to tell the compiler ignore the class from module optimization. I suggest give it a try if other methods suggested on the thread did not work for you.

@_optimize(none)
override init() {

super.init()
}




RE: Swift compiler segmentation fault when building - baniwa341520 - 07-18-2023

Follow this process:

1) Update pods of existing project
2) Go to edit and select convert > current swift syntax
3) In build setting enable bitcode to "NO"
4) Add run the project


RE: Swift compiler segmentation fault when building - antisyphilitic759878 - 07-18-2023

I have had this error because my class does not conform to `Equatable`


RE: Swift compiler segmentation fault when building - basins20838 - 07-18-2023

Just got this error because I was using a feature of Swift 5.1 in a target that was not setup for Swift 5.1. Specifically, I was using `Self.` to access a static function instead of `ClassName.` which works in Swift 5.1 but trying to use it in an older target caused this same error.


RE: Swift compiler segmentation fault when building - berkeleianism676 - 07-18-2023

I was moving from Xcode 9 to 10.2. And here's a problem place

```swift
struct AbstractField<T>: ValidatableField {
var name: String
var value: Observable<Validated<T>>
var setValue: (Validated<T>) -> Void
var hint: Variable<String?>
var error: Variable<AviaFieldError?>
var isHidden: Binder<Bool>
var isBeingEdited: Observable<Bool>
var silentMode: Variable<Bool>
}
```

To solve a problem I replaced var to let for setValue closure.

```swift
struct AbstractField<T>: ValidatableField {
var name: String
var value: Observable<Validated<T>>
let setValue: (Validated<T>) -> Void
var hint: Variable<String?>
var error: Variable<AviaFieldError?>
var isHidden: Binder<Bool>
var isBeingEdited: Observable<Bool>
var silentMode: Variable<Bool>
}
```

Seems it was very hard to parse this construction for the compiler.


RE: Swift compiler segmentation fault when building - Mrtorah134 - 07-18-2023

In my case the issue was in making extension with `UITextFieldDelegate` protocol to my class:
```
extension LoginPresenter: UITextFieldDelegate {}
```

To solve a problem I moved it to a class definition:

```
class LoginPresenter<T: LoginInteractionProtocol>: BasePresenter<T>, LoginPresenterProtocol, UITextFieldDelegate {
}
```


RE: Swift compiler segmentation fault when building - recency812 - 07-18-2023

In my case the culprit was accidentally overloading a function expecting an **array** argument with one with a **variadic** argument:

public required init(_ args: Node...) {
}

When the superclass had it defined as an array:

public required init(_ args: [Node]) {
}


RE: Swift compiler segmentation fault when building - nooscopic577847 - 07-18-2023

Apple should fix this in Xcode to give a better experience to us all.
I recommend you log a bug with apple here:

[To see links please register here]

and reference bug: `32707221` so they see how many people its affecting.

For me it was unwrapping 2 objects out of order

eg:

if let passengers = car?.passengers,
let car = car {
}

instead of

if let car = car,
let passengers = car.passengers
{
}

hard to find!


RE: Swift compiler segmentation fault when building - schenck266 - 07-18-2023

You can also have this problem if you declare a condition with an unwrapped Bool as a property