Skip to content
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

LinearLifetimeCheckerPrivate.h: Error! Found a leaked owned value that was never consumed. #71608

Closed
tayloraswift opened this issue Feb 14, 2024 · 2 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 SILGen Area → compiler: The SIL generation stage

Comments

@tayloraswift
Copy link
Member

Description

the horror

Reproduction

func f(x:[Int]?)
{
}
func g()
{
    let x:[Int]? = nil
    return f(x: consume x)
}

Stack dump

Begin Error in Function: '$s4main1gyyF'
Error! Found a leaked owned value that was never consumed.
Value:   %2 = move_value [allows_diagnostics] %0 : $Optional<Array<Int>> // user: %4
End Error in Function: '$s4main1gyyF'
Found ownership error?!
triggering standard assertion failure routine
UNREACHABLE executed at /home/build-user/swift/lib/SIL/Verifier/LinearLifetimeCheckerPrivate.h:211!
Stack dump:
0.      Program arguments: /usr/bin/swift-frontend -frontend -interpret - -disable-objc-interop -I swiftfiddle.com/_Packages/.build/release -new-driver-path /usr/bin/swift-driver -empty-abi-descriptor -resource-dir /usr/lib/swift -module-name main -plugin-path /usr/lib/swift/host/plugins -plugin-path /usr/local/lib/swift/host/plugins -l_Packages
1.      Swift version 5.10-dev (LLVM dbfaba0078e9380, Swift 63c8b551eb2f613)
2.      Compiling with the current language version
3.      While evaluating request ASTLoweringRequest(Lowering AST to SIL for module main)
4.      While silgen emitFunction SIL function "@$s4main1gyyF".
 for 'g()' (at <stdin>:5:1)
5.      While verifying SIL function "@$s4main1gyyF".
 for 'g()' (at <stdin>:5: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):
/usr/bin/swift-frontend(+0x7307d73)[0x55ab79230d73]
/usr/bin/swift-frontend(+0x7305abe)[0x55ab7922eabe]
/usr/bin/swift-frontend(+0x73080ea)[0x55ab792310ea]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7fdbbb03e520]
/lib/x86_64-linux-gnu/libc.so.6(pthread_kill+0x12c)[0x7fdbbb0929fc]
/lib/x86_64-linux-gnu/libc.so.6(raise+0x16)[0x7fdbbb03e476]
/lib/x86_64-linux-gnu/libc.so.6(abort+0xd3)[0x7fdbbb0247f3]
/usr/bin/swift-frontend(+0x722811f)[0x55ab7915111f]
/usr/bin/swift-frontend(+0x1fdd0ae)[0x55ab73f060ae]
/usr/bin/swift-frontend(+0x1fe134b)[0x55ab73f0a34b]
/usr/bin/swift-frontend(+0x1fdfabd)[0x55ab73f08abd]
/usr/bin/swift-frontend(+0x1fdf782)[0x55ab73f08782]
/usr/bin/swift-frontend(+0x1fe1ad6)[0x55ab73f0aad6]
/usr/bin/swift-frontend(+0x1fe1969)[0x55ab73f0a969]
/usr/bin/swift-frontend(+0x2009bf2)[0x55ab73f32bf2]
/usr/bin/swift-frontend(+0x200cec4)[0x55ab73f35ec4]
/usr/bin/swift-frontend(+0x1ff1cbf)[0x55ab73f1acbf]
/usr/bin/swift-frontend(+0x1fec2f0)[0x55ab73f152f0]
/usr/bin/swift-frontend(+0x1fea9c9)[0x55ab73f139c9]
/usr/bin/swift-frontend(+0x1fe3462)[0x55ab73f0c462]
/usr/bin/swift-frontend(+0x1518ace)[0x55ab73441ace]
/usr/bin/swift-frontend(+0x15182a3)[0x55ab734412a3]
/usr/bin/swift-frontend(+0x151931c)[0x55ab7344231c]
/usr/bin/swift-frontend(+0x15166f4)[0x55ab7343f6f4]
/usr/bin/swift-frontend(+0x151c5c7)[0x55ab734455c7]
/usr/bin/swift-frontend(+0x15fca8c)[0x55ab73525a8c]
/usr/bin/swift-frontend(+0x151f8df)[0x55ab734488df]
/usr/bin/swift-frontend(+0x151cfdf)[0x55ab73445fdf]
/usr/bin/swift-frontend(+0xe34965)[0x55ab72d5d965]
/usr/bin/swift-frontend(+0xe4a7f5)[0x55ab72d737f5]
/usr/bin/swift-frontend(+0xe382ad)[0x55ab72d612ad]
/usr/bin/swift-frontend(+0xe369db)[0x55ab72d5f9db]
/usr/bin/swift-frontend(+0xcc3315)[0x55ab72bec315]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7fdbbb025d90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7fdbbb025e40]
/usr/bin/swift-frontend(+0xcc2375)[0x55ab72beb375]
*** Signal 11: Backtracing from 0x7fdbbb024898... done ***
*** Program crashed: Bad pointer dereference at 0x0000000000000000 ***
Thread 0 "swift-frontend" crashed:
0  0x00007fdbbb024898 <unknown> in libc.so.6
Registers:
rax 0x0000000000000000  0
rdx 0x00007fdbbaefb840  40 b8 ef ba db 7f 00 00 60 c2 ef ba db 7f 00 00  @¸ïºÛ···`ÂïºÛ···
rcx 0x00007fdbbb0929fc  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 0x00007fdbbb217e90  01 00 00 00 01 00 00 00 40 b8 ef ba db 7f 00 00  ········@¸ïºÛ···
rsp 0x00007ffd594be900  20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ···············
 r8 0x0000000000000000  0
 r9 0x0000000000000000  0
r10 0x0000000000000008  8
r11 0x0000000000000246  582
r12 0x0000000000000046  70
r13 0x00007ffd594bedb0  00 00 00 00 00 00 00 00 00 66 5f 7e ab 55 00 00  ·········f_~«U··
r14 0x00000000000000d3  211
r15 0x000055ab7ad0d545  2f 68 6f 6d 65 2f 62 75 69 6c 64 2d 75 73 65 72  /home/build-user
rip 0x00007fdbbb024898  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 (23 omitted):
0x00007fdbbaffc000–0x00007fdbbb1b8341 c289da5071a3399de893d2af81d6a30c62646e1e libc.so.6 /usr/lib/x86_64-linux-gnu/libc.so.6
Backtrace took 0.00s

Expected behavior

it worked in 5.9

Environment

Swift version 5.10-dev (LLVM dbfaba0078e9380, Swift 63c8b55)
Target: x86_64-unknown-linux-gnu

Additional information

it also crashes on main

the crash can be mitigated, but not worked around, by making the parameter consuming instead of borrowing

- func f(x:[Int]?)
+ func f(x:consuming [Int]?)
{
}
func g()
{
    let x:[Int]? = nil
    return f(x: consume x)
}
@tayloraswift tayloraswift 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 Feb 14, 2024
@MaxDesiatov MaxDesiatov added SILGen Area → compiler: The SIL generation stage and removed triage needed This issue needs more specific labels labels Feb 19, 2024
jckarter added a commit to jckarter/swift that referenced this issue Feb 29, 2024
If the value being moved was a trivial value of a nontrivial type (like nil
for Optional<T>) then the lifetime checker would complain that there was
no `destroy_value` ending the consumed value's lifetime. Partial fix
for swiftlang#71608.
@jckarter
Copy link
Contributor

jckarter commented Feb 29, 2024

#71964 addresses the crash, though after addressing the crash I still get an unhelpful diagnostic, so it's not a complete fix:

/Users/jgroff/test2.swift:7:10: error: 'consume' applied to value that the compiler does not support. This is a compiler bug. Please file a bug with a small example of the bug
 5 │ {
 6 │     let x:[Int]? = nil
 7 │     f(x: consume x)
   │          ╰─ error: 'consume' applied to value that the compiler does not support. This is a compiler bug. Please file a bug with a small example of the bug

@nate-chandler
Copy link
Contributor

Fixed by 373cc84

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 SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

4 participants