# Debugging a crash on Linux

**URL:** <https://forums.swift.org/t/debugging-a-crash-on-linux/67926>\
**Category:** Using Swift\
**Tags:** linux, crash, server\
**Created:** [October 18, 2023, 11:46am UTC](https://forums.swift.org/t/debugging-a-crash-on-linux/67926 "2023-10-18T11:46:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lassejansen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lassejansen/32/4712_2.png) [@lassejansen](https://forums.swift.org/u/lassejansen)\
**Post date:** [October 18, 2023, 11:46am UTC](https://forums.swift.org/t/debugging-a-crash-on-linux/67926/1 "2023-10-18T11:46:33Z")

</div>

I'm getting this crash on Ubuntu 22.04. I've isolated a few lines in my project that seem to cause it. Commenting out the lines prevents the crash, but the code doesn't do anything memory or concurrency related, it's mostly nested resultBuilder code. I haven't been able to reproduce the crash in a sample project. Any ideas?

```swift
Thread 0:

0 0x00007f89b130982d <unknown> in libc.so.6

Thread 1:

0 0x00007f89b127f117 <unknown> in libc.so.6

Thread 2 crashed:

0 0x00007f89b2643388 swift_retain + 56 in libswiftCore.so

Registers:

rax 0x00000000801f0fff 2149519359
rdx 0x00007f89ab499900 a0 fe 6f 94 44 56 00 00 00 00 00 00 00 00 00 00 þo·DV··········
rcx 0x0000564493243978 ff 0f 1f 80 00 00 00 00 55 48 89 e5 48 8b 05 75 ÿ·······UH·åH··u
rbx 0x0000000200000000 8589934592
rsi 0x0000564493243970 49 8b 7d 10 e9 57 f1 ff ff 0f 1f 80 00 00 00 00 I·}·éWñÿÿ·······
rdi 0x00000002801f0fff 10739453951
rbp 0x0000000000000000 0
rsp 0x00007f89ab4995a8 27 ff 23 93 44 56 00 00 00 00 00 00 02 00 00 00 'ÿ#·DV··········
 r8 0x0000000000000000 0
 r9 0x80000000ffffffff 9223372041149743103
r10 0x0000000100000000 4294967296
r11 0x6378b1b0fbd84080 7167674180657758336
r12 0x0000000000000000 0
r13 0x0000000000000000 0
r14 0x0000000000000000 0
r15 0x0000000000000000 0
rip 0x00007f89b2643388 f0 48 0f b1 31 75 f1 48 89 f8 c3 83 f8 ff 74 f7 ðH·±1uñH·øÃ·øÿt÷

rflags 0x0000000000010206 PF

cs 0x0033 fs 0x0000 gs 0x0000

Images (70 omitted):

0x00007f89b11ee000–0x00007f89b13aa541 a43bfc8428df6623cd498c9c0caeb91aec9be4f9 libc.so.6 /usr/lib/x86_64-linux-gnu/libc.so.6
0x00007f89b224a000–0x00007f89b2787d68 <no build ID> libswiftCore.so /opt/swift-5.9/usr/lib/swift/linux/libswiftCore.so

```

---

<div class="post-metadata">

**Author:** ![segfault](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@segfault](https://forums.swift.org/u/segfault)\
**Post date:** [October 18, 2023, 5:44pm UTC](https://forums.swift.org/t/debugging-a-crash-on-linux/67926/2 "2023-10-18T17:44:11Z")

</div>

Can you provide a very small code sample that demonstrates the issue? I'm not using x86 Linux but who knows, maybe it would also happen on my aarch64 Linux system. BTW which version of swiftc are you using?

---

<div class="post-metadata">

**Author:** ![lassejansen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lassejansen/32/4712_2.png) [@lassejansen](https://forums.swift.org/u/lassejansen)\
**Post date:** [October 18, 2023, 6:50pm UTC](https://forums.swift.org/t/debugging-a-crash-on-linux/67926/3 "2023-10-18T18:50:35Z")

</div>

I wasn't able yet to reproduce the issue outside of my project unfortunately.

---

<div class="post-metadata">

**Author:** ![Finagolfin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finagolfin/32/34388_2.png) [@Finagolfin](https://forums.swift.org/u/Finagolfin)\
**Post date:** [October 19, 2023, 4:31am UTC](https://forums.swift.org/t/debugging-a-crash-on-linux/67926/4 "2023-10-19T04:31:43Z")

</div>

You could try [linking your code against some of the LLVM sanitizers](https://www.swift.org/blog/tsan-support-on-linux/) and see if that turns up anything.

---

<div class="post-metadata">

**Author:** ![lassejansen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lassejansen/32/4712_2.png) [@lassejansen](https://forums.swift.org/u/lassejansen)\
**Post date:** [October 19, 2023, 9:01am UTC](https://forums.swift.org/t/debugging-a-crash-on-linux/67926/5 "2023-10-19T09:01:58Z")

</div>

I found the issue, it seems to be a miscompile related to result builders and structs memberwise initializers.

Changing this code

```swift
struct MyType {
    let object: MyObject
    @MyBuilder
    let value: MyValue
}

```

to this

```swift
struct MyType {
    let object: MyObject
    @MyBuilder
    let value: MyValue

    init(object: MyObject, @MyBuilder value: () -> MyValue) {
        self.object = object
        self.value = value
    }
}

```

fixes the crash.

---

<div class="post-metadata">

**Author:** ![lassejansen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lassejansen/32/4712_2.png) [@lassejansen](https://forums.swift.org/u/lassejansen)\
**Post date:** [October 19, 2023, 9:18am UTC](https://forums.swift.org/t/debugging-a-crash-on-linux/67926/6 "2023-10-19T09:18:51Z")

</div>

There is a related compiler crash. For another type this crash went away after writing out the initializer:

```swift
IntToPtr source must be an integral
  %5 = inttoptr i8* %0 to %swift.bridge*, !dbg !256
IntToPtr source must be an integral
  %6 = inttoptr i8* %2 to %swift.bridge*, !dbg !256
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:

```

```swift
1.	Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
2.	Compiling with the current language version
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 swift-frontend 0x000000010554714c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x00000001080c5f2c llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000103e0710c SignalHandler(int) + 352
3 libsystem_platform.dylib 0x00000001a4dfaa24 _sigtramp + 56
4 libsystem_pthread.dylib 0x00000001a4dcbc28 pthread_kill + 288
5 libsystem_c.dylib 0x00000001a4cd9ae8 abort + 180
6 swift-frontend 0x000000010806f374 llvm::vfs::recursive_directory_iterator::increment(std::__1::error_code&) + 0
7 swift-frontend 0x00000001054f7890 llvm::report_fatal_error(llvm::Twine const&, bool) + 280
8 swift-frontend 0x00000001054f7778 llvm::report_fatal_error(llvm::Twine const&, bool) + 0
9 swift-frontend 0x00000001070da5a4 std:: __1::__ function::__func<llvm::CombinerHelper::matchCombineFAddFpExtFMulToFMadOrFMAAggressive(llvm::MachineInstr&, std::__1::function<void (llvm::MachineIRBuilder&)>&)::$_52, std::__1::allocator<llvm::CombinerHelper::matchCombineFAddFpExtFMulToFMadOrFMAAggressive(llvm::MachineInstr&, std::__1::function<void (llvm::MachineIRBuilder&)>&)::$_52>, void (llvm::MachineIRBuilder&)>::operator()(llvm::MachineIRBuilder&) + 0
10 swift-frontend 0x0000000107d76490 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 224
11 swift-frontend 0x0000000106ee0990 swift::performLLVMOptimizations(swift::IRGenOptions const&, llvm::Module*, llvm::TargetMachine*, llvm::raw_pwrite_stream*) + 4252
12 swift-frontend 0x0000000103a0e5bc swift::performLLVM(swift::IRGenOptions const&, swift::DiagnosticEngine&, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, llvm::StringRef, swift::UnifiedStatsReporter*) + 2736
13 swift-frontend 0x0000000108078c74 generateCode(swift::CompilerInstance&, llvm::StringRef, llvm::Module*, llvm::GlobalVariable*) + 252
14 swift-frontend 0x000000010795b618 performCompileStepsPostSILGen(swift::CompilerInstance&, std:: __1::unique_ptr<swift::SILModule, std::__ 1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1708
15 swift-frontend 0x000000010807d91c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1748
16 swift-frontend 0x0000000108081474 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4568
17 swift-frontend 0x00000001079c74e0 swift::mainEntry(int, char const**) + 4116
18 dyld 0x00000001a4a73f28 start + 2236

```

---

<div class="post-metadata">

**Author:** ![Max\_Desiatov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/max_desiatov/32/20654_2.png) [@Max\_Desiatov](https://forums.swift.org/u/Max_Desiatov)\
**Post date:** [October 19, 2023, 9:24am UTC](https://forums.swift.org/t/debugging-a-crash-on-linux/67926/7 "2023-10-19T09:24:01Z")

</div>

Have you found a corresponding issue on [github.com/apple/swift/issue](http://github.com/apple/swift/issue), or would you mind filing one a self-contained snippet and repro steps otherwise?

---

<div class="post-metadata">

**Author:** ![lassejansen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lassejansen/32/4712_2.png) [@lassejansen](https://forums.swift.org/u/lassejansen)\
**Post date:** [October 19, 2023, 9:34am UTC](https://forums.swift.org/t/debugging-a-crash-on-linux/67926/8 "2023-10-19T09:34:02Z")

</div>

I filed a bug here: [Compiler and runtime crashes when combining result builders with memberwise initializer · Issue #69272 · apple/swift · GitHub](https://github.com/apple/swift/issues/69272)

If I'm able to reproduce the issue in a snippet, I'll attach it to the ticket.

---

<div class="post-metadata">

**Author:** ![lassejansen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lassejansen/32/4712_2.png) [@lassejansen](https://forums.swift.org/u/lassejansen)\
**Post date:** [October 19, 2023, 9:42am UTC](https://forums.swift.org/t/debugging-a-crash-on-linux/67926/9 "2023-10-19T09:42:05Z")

</div>

The compiler crash can be reproduced easily:

```swift
@resultBuilder
enum MyBuilder {
    static func buildBlock(_ components: String...) -> [String] {
        components
    }
}

struct MyType {
    @MyBuilder
    let first: [String]
    @MyBuilder
    let second: [String]
}

```
