Skip to content

Crash Analyzing Escapability in Autoclosure Argument #81595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
filip-sakel opened this issue May 18, 2025 · 0 comments
Open

Crash Analyzing Escapability in Autoclosure Argument #81595

filip-sakel opened this issue May 18, 2025 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@filip-sakel
Copy link
Contributor

Description

Using a non-escapable value in an autoclosure appears to crash the compiler.

Reproduction

With the following flags: -Xfrontend -enable-experimental-feature -Xfrontend Embedded -wmo -Xfrontend -enable-experimental-feature -Xfrontend SymbolLinkageMarkers -Xfrontend -enable-experimental-feature -Xfrontend LifetimeDependence

I don't think Embedded makes a difference but that's how I ran it.

struct MyBox {
    struct Value: ~Copyable, ~Escapable {
        @usableFromInline
        @_transparent
        init(a: borrowing Int) {}
    }

    public var value: Value? {
        @lifetime(borrow self)
        _read {
            let val = Value(a: 1)
            yield val
        }
        @lifetime(borrow self)
        nonmutating _modify {
            var val: Value? = Value(a: 1)
            yield &val
        }
    }
}

@_used
func main() {
    let myBox = MyBox()
    precondition(myBox.value != nil, "No nil")
}

Or in godbolt.

Stack dump

swift-frontend: /home/build-user/swift/lib/SILOptimizer/Utils/SILInliner.cpp:276: void (anonymous namespace)::BeginApplySite::complete(): Assertion `!BeginApply->hasUsesOfAnyResult()' failed.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend -frontend -S <source> -target x86_64-unknown-linux-gnu -disable-objc-interop -no-color-diagnostics -Xcc -fno-color-diagnostics -g -debug-info-format=dwarf -dwarf-version=4 -enable-experimental-feature Embedded -enable-experimental-feature SymbolLinkageMarkers -enable-experimental-feature LifetimeDependence -empty-abi-descriptor -enable-anonymous-context-mangled-names -file-compilation-dir /app -Xllvm --x86-asm-syntax=intel -no-auto-bridging-header-chaining -module-name output -in-process-plugin-server-path /opt/compiler-explorer/swift-nightly/usr/lib/swift/host/libSwiftInProcPluginServer.so -plugin-path /opt/compiler-explorer/swift-nightly/usr/lib/swift/host/plugins -plugin-path /opt/compiler-explorer/swift-nightly/usr/local/lib/swift/host/plugins -o /app/output.s
1.	Swift version 6.2-dev (LLVM be9c1978c3677f1, Swift 749e9ee090b6443)
2.	Compiling with effective version 5.10
3.	While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for output)
4.	While running pass #421 SILModuleTransform "MandatoryPerformanceOptimizations".
5.	While inlining SIL function "@$e6output5MyBoxV5valueAC5ValueVSgvr".
 for read for value (at <source>:8:16)
6.	While ...into SIL function "@$e6output4mainyyF".
 for 'main()' (at <source>:23:1)
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 0x00006144188f7488
1  swift-frontend 0x00006144188f4f5e
2  swift-frontend 0x00006144188f7b26
3  libc.so.6      0x0000753c95442520
4  libc.so.6      0x0000753c954969fc pthread_kill + 300
5  libc.so.6      0x0000753c95442476 raise + 22
6  libc.so.6      0x0000753c954287f3 abort + 211
7  libc.so.6      0x0000753c9542871b
8  libc.so.6      0x0000753c95439e96
9  swift-frontend 0x0000614411c72694
10 swift-frontend 0x0000614411c744a3
11 swift-frontend 0x0000614411c708b3
12 swift-frontend 0x0000614411c6f81e
13 swift-frontend 0x0000614411c6e749
14 swift-frontend 0x0000614411c6fd77
15 swift-frontend 0x0000614411cb3df3
16 swift-frontend 0x0000614410ac293e
17 swift-frontend 0x0000614410ac03a8
18 swift-frontend 0x0000614411683277
19 swift-frontend 0x0000614411685d6b
20 swift-frontend 0x000061441167f2e8
21 swift-frontend 0x000061441167f29d
22 swift-frontend 0x00006144119f7bfa
23 swift-frontend 0x000061441168d5a6
24 swift-frontend 0x000061441167f4ef
25 swift-frontend 0x00006144119e4771
26 swift-frontend 0x00006144110120a8
27 swift-frontend 0x0000614410c9ac0e
28 swift-frontend 0x0000614410c99d53
29 swift-frontend 0x0000614410cab93e
30 swift-frontend 0x0000614410c9cb2e
31 swift-frontend 0x0000614410c9bb8a
32 swift-frontend 0x0000614410a06e4c
33 libc.so.6      0x0000753c95429d90
34 libc.so.6      0x0000753c95429e40 __libc_start_main + 128
35 swift-frontend 0x0000614410a05e6e

*** Signal 11: Backtracing from 0x753c95428898... done ***

*** Program crashed: Bad pointer dereference at 0x0000000000000000 ***

Platform: x86_64 Linux (Ubuntu 22.04.5 LTS)

Thread 0 "swift-frontend" crashed:

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


Registers:

rax 0x0000000000000000  0
rdx 0x0000753c95a7b880  80 b8 a7 95 3c 75 00 00 a0 c2 a7 95 3c 75 00 00  ·¸§·<u·· §·<u··
rcx 0x0000753c954969fc  41 89 c5 41 f7 dd 3d 00 f0 ff ff b8 00 00 00 00  A·ÅA÷Ý=·ðÿÿ¸····
rbx 0x0000000000000006  6
rsi 0x0000000000000001  1
rdi 0x0000000000000001  1
rbp 0x0000753c9561be90  01 00 00 00 01 00 00 00 80 b8 a7 95 3c 75 00 00  ·········¸§·<u··
rsp 0x00007fff5c9dce60  20 00 00 00 00 00 00 00 a0 b6 61 95 3c 75 00 00   ······· ¶a·<u··
 r8 0x0000000000000000  0
 r9 0x0000000000000000  0
r10 0x0000000000000008  8
r11 0x0000000000000246  582
r12 0x000061441ab63771  2f 68 6f 6d 65 2f 62 75 69 6c 64 2d 75 73 65 72  /home/build-user
r13 0x0000000000000114  276
r14 0x0000614419307ff8  21 42 65 67 69 6e 41 70 70 6c 79 2d 3e 68 61 73  !BeginApply->has
r15 0x000061444428aae0  50 8b 2c 44 44 61 00 00 30 43 08 44 44 61 00 00  P·,DDa··0C·DDa··
rip 0x0000753c95428898  f4 83 3d 00 36 1f 00 05 75 14 c7 05 f4 35 1f 00  ô·=·6···u·Ç·ô5··

rflags 0x0000000000010246  ZF PF

cs 0x0033  fs 0x0000  gs 0x0000


Images (30 omitted):

0x0000753c95400000–0x0000753c955bc341 cd410b710f0f094c6832edd95931006d883af48e libc.so.6 /lib/x86_64-linux-gnu/libc.so.6

Backtrace took 0.02s

Program terminated with signal: SIGSEGV
Compiler returned: 139

Expected behavior

An error instead of a crash, although I don't think the value actually escapes.

Environment

Swift version 6.2-dev (LLVM be9c1978c3677f1, Swift 749e9ee)
Target: x86_64-unknown-linux-gnu
Build config: +assertions
Compiler returned: 0

Additional information

No response

@filip-sakel filip-sakel added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels May 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant