swift icon indicating copy to clipboard operation
swift copied to clipboard

[6.0] Mutex with enum value inside non-copyable crashes on linux

Open sliemeobn opened this issue 9 months ago • 2 comments

Description

I was chasing after the strangest problem that only showed up in linux release builds (6.0.3, official docker image, ARM) for me. Debug builds and macOS were fine.

I was able to shrink it down to the example below, but I have no idea what is going on. The enum must have both cases for the problem to show (with associated values). It also seems to matter that it is inside a non-copyable struct (class works).

Reproduction

import Synchronization

struct Foo: ~Copyable {
    enum State {
        case bar([Int:Int])
        case foo(Int)
    }

    let mutex = Mutex<State>(.bar([:]))
}

Stack dump

error: compile command failed due to signal 6 (use -v to see invocation)
Invalid indices for GEP pointer type!
  %13 = getelementptr inbounds %T15Synchronization5_CellVy4test3FooV5StateOG, ptr %11, i32 0, i32 1
Invalid indices for GEP pointer type!
  %16 = getelementptr inbounds %T15Synchronization5_CellVy4test3FooV5StateOG, ptr %10, i32 0, i32 1
Invalid indices for GEP pointer type!
  %18 = getelementptr inbounds %T15Synchronization5_CellVy4test3FooV5StateOG, ptr %10, i32 0, i32 1
<unknown>:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
<unknown>:0: note: Broken module found, compilation aborted!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /usr/bin/swift-frontend -frontend -c -primary-file test.swift -target aarch64-unknown-linux-gnu -Xllvm -aarch64-use-tbi -disable-objc-interop -color-diagnostics -O -empty-abi-descriptor -resource-dir /usr/lib/swift -module-name test -plugin-path /usr/lib/swift/host/plugins -plugin-path /usr/local/lib/swift/host/plugins -enable-default-cmo -o /tmp/TemporaryDirectory.vjRwT2/test-1.o
1.      Swift version 6.0.3 (swift-6.0.3-RELEASE)
2.      Compiling with effective version 5.10
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  0x0000aaaad162bf9c
1  swift-frontend  0x0000aaaad162a1a8
2  swift-frontend  0x0000aaaad162c6a0
3  linux-vdso.so.1 0x0000ffffb299b7a0 __kernel_rt_sigreturn + 0
4  libc.so.6       0x0000ffffb0ac7608
5  libc.so.6       0x0000ffffb0a7cb3c gsignal + 28
6  libc.so.6       0x0000ffffb0a67e00 abort + 244
7  swift-frontend  0x0000aaaacc3ba88c
8  swift-frontend  0x0000aaaad159069c
9  swift-frontend  0x0000aaaad1590580
10 swift-frontend  0x0000aaaad136af4c
11 swift-frontend  0x0000aaaad134123c
12 swift-frontend  0x0000aaaacc4b6ccc
13 swift-frontend  0x0000aaaacc4b7fb0
14 swift-frontend  0x0000aaaacc173cd4
15 swift-frontend  0x0000aaaacc170754
16 swift-frontend  0x0000aaaacc16f6f8
17 swift-frontend  0x0000aaaacc171a60
18 swift-frontend  0x0000aaaacc171008
19 swift-frontend  0x0000aaaacbfabd24
20 libc.so.6       0x0000ffffb0a684c4
21 libc.so.6       0x0000ffffb0a68598 __libc_start_main + 152
22 swift-frontend  0x0000aaaacbfaa8b0

Expected behavior

no crashers

Environment

Swift version 6.0.3 (swift-6.0.3-RELEASE) Target: aarch64-unknown-linux-gnu

Additional information

No response

sliemeobn avatar Mar 20 '25 20:03 sliemeobn

I believe this is fixed in the 6.1 toolchain.

aschwaighofer avatar Mar 21 '25 14:03 aschwaighofer