Skip to content

compiler crash when stack-promoting array literals inside specialized @inlinable generic functions #63775

Open
@tayloraswift

Description

@tayloraswift

this crash occurs when clients monomorphize imported @inlinable functions that contain array literals.

it happens on swift-5.8-DEVELOPMENT-SNAPSHOT-2023-02-09-a with a nightly-5.8-amazonlinux2 docker container.

public 
enum A
{
    @inlinable public static 
    func a<T>(_ x:Int) -> T where T:BinaryFloatingPoint
    {
        [1][x]
    }
}
import A

public
func test(_ x:Int)
{
    let _:Double = A.a(x)
}
$ swift build -c release --target B
Building for production...
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
error: compile command failed due to signal 6 (use -v to see invocation)
swift-frontend: /home/build-user/llvm-project/llvm/include/llvm/ADT/SmallVector.h:273: llvm::SmallVectorTemplateCommon::reference llvm::SmallVectorTemplateCommon<swift::StackNesting::StackLoc, void>::operator[](llvm::SmallVectorTemplateCommon::size_type) [T = swift::StackNesting::StackLoc]: Assertion `idx < size()' failed.
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 /swift/crash-inlinable-stack-promotion/Sources/B/B.swift -emit-module-path /swift/crash-inlinable-stack-promotion/.build/x86_64-unknown-linux-gnu/release/B.swiftmodule -emit-module-doc-path /swift/crash-inlinable-stack-promotion/.build/x86_64-unknown-linux-gnu/release/B.swiftdoc -emit-module-source-info-path /swift/crash-inlinable-stack-promotion/.build/x86_64-unknown-linux-gnu/release/B.swiftsourceinfo -emit-dependencies-path /swift/crash-inlinable-stack-promotion/.build/x86_64-unknown-linux-gnu/release/B.build/B.d -target x86_64-unknown-linux-gnu -disable-objc-interop -I /swift/crash-inlinable-stack-promotion/.build/x86_64-unknown-linux-gnu/release -color-diagnostics -g -module-cache-path /swift/crash-inlinable-stack-promotion/.build/x86_64-unknown-linux-gnu/release/ModuleCache -swift-version 5 -O -D SWIFT_PACKAGE -new-driver-path /usr/bin/swift-driver -empty-abi-descriptor -resource-dir /usr/lib/swift -module-name B -enable-default-cmo -parse-as-library -num-threads 12 -o /swift/crash-inlinable-stack-promotion/.build/x86_64-unknown-linux-gnu/release/B.build/B.swift.o
1.      Swift version 5.8-dev (LLVM 44d4f9d4b49845f, Swift 40e02c02ad5b3bb)
2.      Compiling with the current language version
3.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { PrepareOptimizationPasses, EarlyModulePasses, HighLevel,Function+EarlyLoopOpt, HighLevel,Module+StackPromote, MidLevel,Function, ClosureSpecialize, LowLevel,Function, LateLoopOpt, SIL Debug Info Generator } on SIL for B)
4.      While running pass #2787 SILFunctionTransform "StackPromotion" on SILFunction "@$s1B4testyySiF".
 for 'test(_:)' (at /swift/crash-inlinable-stack-promotion/Sources/B/B.swift:4:1)

the crash doesn’t occur when test(_:) is instead defined within module A.

crash-inlinable-stack-promotion.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    @inlinableFeature → attributes: the @inlinable attributebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareliteralsFeature → expressions: Literals such as an integer or string literaloptimized onlyFlag: An issue whose reproduction requires optimized compilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions