swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

[SR-12208] SILOptimizer crash #54634

Closed swift-ci closed 3 years ago

swift-ci commented 4 years ago
Previous ID SR-12208
Radar rdar://problem/59496025
Original Reporter shoffmann (JIRA User)
Type Bug
Status Closed
Resolution Cannot Reproduce
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CompilerCrash, OptimizedOnly | |Assignee | None | |Priority | Medium | md5: cadb596f45c3bc703433d49e41d8e31a

Issue Description:

Debug configuration builds just fine while release fails with:

swift build -c release

swift: /home/buildnode/jenkins/workspace/oss-swift-5.1-package-linux-ubuntu-18_04/swift/lib/SILOptimizer/Analysis/EscapeAnalysis.cpp:1763: bool swift::EscapeAnalysis::mergeCalleeGraph(swift::SILInstruction *, swift::EscapeAnalysis::ConnectionGraph *, swift::EscapeAnalysis::ConnectionGraph *): AssertionnumCalleeArgs >= numCallerArgs' failed.swift: /home/buildnode/jenkins/workspace/oss-swift-5.1-package-linux-ubuntu-18_04/swift/lib/SILOptimizer/Analysis/EscapeAnalysis.cpp:1763: bool swift::EscapeAnalysis::mergeCalleeGraph(swift::SILInstruction , swift::EscapeAnalysis::ConnectionGraph , swift::EscapeAnalysis::ConnectionGraph *): Assertion numCalleeArgs >= numCallerArgs' failed.Stack dump:0. Program arguments: ... -frontend -c ... -supplementary-output-file-map /tmp/supplementaryOutputs-df1651 -target x86_64-unknown-linux -disable-objc-interop -sdk / -I /... -swift-version 5 -O -D SWIFT_PACKAGE -color-diagnostics -Xcc -fmodule-map-file=... -parse-as-library -module-name Core -num-threads 4 -o ...

While running pass #​21558 SILFunctionTransform "EarlyRedundantLoadElimination" on SILFunction "@$s4Core7AnyNodeC016processAndNotifyB033_07275164D393B8F91FD801749F4C4154LLyyypF". for 'processAndNotifyAny(_:)' (at .../Node.swift:68:11)/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x451a3b4]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x451800e]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x451a7c8]/lib/x86_64-linux-gnu/libpthread.so.0(+0x12890)[0x7f2e60acf890]/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7)[0x7f2e5ef32e97]/lib/x86_64-linux-gnu/libc.so.6(abort+0x141)[0x7f2e5ef34801]/lib/x86_64-linux-gnu/libc.so.6(+0x3039a)[0x7f2e5ef2439a]/lib/x86_64-linux-gnu/libc.so.6(+0x30412)[0x7f2e5ef24412]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0xb6e7da]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0xb6ddf6]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0xb6eb69]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0xb89bd0]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0xb87c48]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0xb877b6]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x9fad16]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x9f1cab]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x935a8d]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x936822]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x93793f]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x550048]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x93fb6c]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x749052]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x4d4ad4]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x4d0cde]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x473b16]/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f2e5ef15b97]/home/eth/swift/swift-5.1.1-RELEASE-ubuntu18.04/usr/bin/swift[0x47377a]

The code in question:

fileprivate func processAny(_ : Any) throws -> Any? { fatalError("AnyNode.processAny() has not been implemented") }

/// Notfies any outNodes that we are done and passes our result fileprivate func notifyAny(_ result: Any) { for node in outNodes { node.queue.async { node.processAndNotifyAny(result) } } }

private func processAndNotifyAny(_ input: Any) { do { let result = try processAny(input) if result != nil { notifyAny(result!) } } catch { logger.error("Errror during processing of node (name): (error)") } }

swift-ci commented 4 years ago

Comment by Sebastian Hoffmann (JIRA)

Also crashes with 5.1.4

theblixguy commented 4 years ago

cc @eeckstein

beccadax commented 4 years ago

@swift-ci create

atrick commented 4 years ago

shoffmann (JIRA User)I haven't been able to reproduce a crash yet just by filling in placeholders where the code is incomplete. It's not surprising because what happens inside the optimizer is very sensitive so small changes in the surrounding code. Can you provide a test case that builds and reproduces the problem, or at least as much context as possible?

swift-ci commented 4 years ago

Comment by Sebastian Hoffmann (JIRA)

@atrick Yes indeed. I did some small refactoring to the code in question and now the crash is gone. I will try to come up with a minimal reproduceable example based on the old revision within in the next days. Unfortunately I can't disclose the whole codebase. Should I be unable to do so: Are there any intermediary files which would be helpful? I know that swiftc comes with alot of flags to provide output of various compilation stages.

atrick commented 4 years ago

These are always good flags to use for compiler asserts:

-Xllvm -sil-print-on-error -Xfrontend -sil-verify-all

Something got inlined into `processAndNotifyAny` and caused a problem, but I'm not sure what.

To reduce it, I would try to remove as many of the calls as possible from `processAndNotifyAny`, without changing anything else. Then you know what got inlined. From there, I would replace any types that are still referenced with dummy proxies. It takes time to reduce problems, but it's really helpful to have that test case. The compiler code around that assert looks very sketchy to me, but I don't know how to contrive a test case that would break it.

atrick commented 3 years ago

It's likely that this crash occurred while the EscapeAnalysis code was still in flux. It's been a year since anyone was able to reproduce it. If it happens again though please reopen.