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

SILGen assertion failure when compiling unreachable lazy local variable #73736

Closed
jamieQ opened this issue May 19, 2024 · 2 comments
Closed

SILGen assertion failure when compiling unreachable lazy local variable #73736

jamieQ opened this issue May 19, 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 triage needed This issue needs more specific labels

Comments

@jamieQ
Copy link
Contributor

jamieQ commented May 19, 2024

Description

an assertion failure is hit when compiling a method containing an unreachable lazy local variable.

Reproduction

func repro() -> Int {
    return 0
    lazy var v = 42
}

Stack dump

<source>:3:10: warning: code after 'return' will never be executed
    lazy var v = 42
         ^
swift-frontend: /home/build-user/swift/include/swift/SIL/SILBuilder.h:3002: void swift::SILBuilder::insertImpl(swift::SILInstruction *): Assertion `hasValidInsertionPoint()' 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-5.10/usr/bin/swift-frontend -frontend -S -primary-file <source> -target x86_64-unknown-linux-gnu -disable-objc-interop -g -new-driver-path /opt/compiler-explorer/swift-5.10/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /opt/compiler-explorer/swift-5.10/usr/lib/swift -enable-anonymous-context-mangled-names -Xllvm --x86-asm-syntax=intel -module-name output -plugin-path /opt/compiler-explorer/swift-5.10/usr/lib/swift/host/plugins -plugin-path /opt/compiler-explorer/swift-5.10/usr/local/lib/swift/host/plugins -o /app/output.s
1.	Swift version 5.10-dev (LLVM 5dc9d563e5a6cd2, Swift 9bfe759d7048cb6)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "<source>")
4.	While silgen emitFunction SIL function "@$s6output5reproSiyF".
 for 'repro()' (at <source>:1: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):
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x72c13f3)[0x5db5222b33f3]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x72bf0ee)[0x5db5222b10ee]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x72c176f)[0x5db5222b376f]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7b6b28642520]
/lib/x86_64-linux-gnu/libc.so.6(pthread_kill+0x12c)[0x7b6b286969fc]
/lib/x86_64-linux-gnu/libc.so.6(raise+0x16)[0x7b6b28642476]
/lib/x86_64-linux-gnu/libc.so.6(abort+0xd3)[0x7b6b286287f3]
/lib/x86_64-linux-gnu/libc.so.6(+0x2871b)[0x7b6b2862871b]
/lib/x86_64-linux-gnu/libc.so.6(+0x39e96)[0x7b6b28639e96]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0xcddd2a)[0x5db51bccfd2a]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x128ce42)[0x5db51c27ee42]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x154f0d0)[0x5db51c5410d0]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x154e378)[0x5db51c540378]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x155123a)[0x5db51c54323a]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x154f6d5)[0x5db51c5416d5]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x15577b2)[0x5db51c5497b2]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x2827b2c)[0x5db51d819b2c]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x155006e)[0x5db51c54206e]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x15ffd8c)[0x5db51c5f1d8c]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x15fe8cd)[0x5db51c5f08cd]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x1595729)[0x5db51c587729]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x151ad3d)[0x5db51c50cd3d]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x151bebc)[0x5db51c50debc]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x15191b4)[0x5db51c50b1b4]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x151f167)[0x5db51c511167]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x15fe1fc)[0x5db51c5f01fc]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x15224f0)[0x5db51c5144f0]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0x151ffc8)[0x5db51c511fc8]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0xe331bb)[0x5db51be251bb]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0xe49319)[0x5db51be3b319]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0xe36d0b)[0x5db51be28d0b]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0xe35427)[0x5db51be27427]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0xcc2465)[0x5db51bcb4465]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7b6b28629d90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7b6b28629e40]
/opt/compiler-explorer/swift-5.10/usr/bin/swift-frontend(+0xcc14ce)[0x5db51bcb34ce]

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

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

Thread 0 "swift-frontend" crashed:

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


Registers:

rax 0x0000000000000000  0
rdx 0x00007b6b28976840  40 68 97 28 6b 7b 00 00 60 72 97 28 6b 7b 00 00  @h·(k{··`r·(k{··
rcx 0x00007b6b286969fc  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 0x00007b6b2881be90  01 00 00 00 01 00 00 00 40 68 97 28 6b 7b 00 00  ········@h·(k{··
rsp 0x00007ffe935d9460  20 00 00 00 00 00 00 00 a0 b6 81 28 6b 7b 00 00   ······· ¶·(k{··
 r8 0x0000000000000000  0
 r9 0x0000000000000000  0
r10 0x0000000000000008  8
r11 0x0000000000000246  582
r12 0x00005db52382f464  2f 68 6f 6d 65 2f 62 75 69 6c 64 2d 75 73 65 72  /home/build-user
r13 0x0000000000000bba  3002
r14 0x00005db52382f49a  68 61 73 56 61 6c 69 64 49 6e 73 65 72 74 69 6f  hasValidInsertio
r15 0x00007ffe935da3e8  88 22 ff 22 b5 5d 00 00 f0 57 a3 27 b5 5d 00 00  ·"ÿ"µ]··ðW£'µ]··
rip 0x00007b6b28628898  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 (26 omitted):

0x00007b6b28600000–0x00007b6b287bc341 962015aa9d133c6cbcfb31ec300596d7f44d3348 libc.so.6 /lib/x86_64-linux-gnu/libc.so.6

Backtrace took 0.01s

Program terminated with signal: SIGSEGV
Compiler returned: 139

Expected behavior

assertion should not be hit

Environment

env of repro (compiler explorer):

Swift version 5.10-dev (LLVM 5dc9d563e5a6cd2, Swift 9bfe759d7048cb6)
Target: x86_64-unknown-linux-gnu
Compiler returned: 0

Additional information

repro from compiler explorer can be found here. code appears to compile without issue in swift 5.5 & 5.6, but hits this issue in 5.7+. prior to 5.4 it appears lazy local variables were not supported and would result in a compiler error. possibly related to #66384.

@jamieQ jamieQ 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 19, 2024
@tbkka
Copy link
Contributor

tbkka commented May 28, 2024

CC: @meg-gupta @eeckstein

eeckstein added a commit to eeckstein/swift that referenced this issue Jun 10, 2024
Fixes a crash in case a lazy var is declared after a return statement

apple#73736
@eeckstein
Copy link
Member

#74256

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

3 participants