Skip to content

Compiler crash with lifetime issue with latest January trunk snapshots #78444

Open
@marcprux

Description

@marcprux

Description

While getting a Swift package working on Android (tayloraswift/swift-jpeg#30), I encountered a crash when cross-compiling from to Android using the 6.0.2 Android SDK.

The curious thing is that it only crashes when using the macOS OSS 6.0.2 toolchain to perform the cross-compilation, whereas it does not crash when using the Linux 6.0.2 toolchain (with the exact same Android SDK). You can see this in the Action run at https://github.com/marcprux/swift-property-crash/actions/runs/12638581877/job/35215154371.

Reproduction

On an macOS 15 machine, set up the Android cross-compiler either manually (https://github.com/finagolfin/swift-android-sdk/blob/main/README.md) or using Skip's support (brew install skiptools/skip/skip then skip android sdk install --version 6.0.2), then checkout https://github.com/marcprux/swift-property-crash.git and attempt to build.

E.g.:

$ git clone https://github.com/marcprux/swift-property-crash.git
$ cd swift-property-crash
$ skip android build

…
[54/114] Compiling JPEGFuzzer main.swift
error: compile command failed due to signal 6 (use -v to see invocation)
Begin Error in Function: '$s6Rotate6rotate_5input6outputyAA8RotationO_S2StKF'
Found outside of lifetime use?!
Value:   %427 = load_borrow %426 : $*JPEG.Data.Spectral<JPEG.Common> // users: %435, %429
Consuming User:   end_borrow %427 : $JPEG.Data.Spectral<JPEG.Common> // id: %435
Non Consuming User:   end_borrow %429 : $*JPEG.Data.Spectral<JPEG.Common> // id: %445
Block: bb9

End Error in Function: '$s6Rotate6rotate_5input6outputyAA8RotationO_S2StKF'
Found ownership error?!
triggering standard assertion failure routine
UNREACHABLE executed at /Users/ec2-user/jenkins/workspace/oss-swift-6.0.2-package-macos/swift/lib/SIL/Verifier/LinearLifetimeCheckerPrivate.h:211!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:

… see Stack Dump section for full stack…

I haven't narrowed this down to a small test case, but the crash is resolved by changing:

 public
     subscript(p:Int) -> Plane
     {
        _read
        {
            yield  self.planes[p]
        }
        _modify
        {
             yield &self.planes[p]
         }
     }

to:

public
     subscript(p:Int) -> Plane
     {
         get
         {
             self.planes[p]
         }
         set
         {
             self.planes[p] = newValue
         }
     }

Stack dump

[40/90] Emitting module Rotate
error: compile command failed due to signal 6 (use -v to see invocation)
Begin Error in Function: '$s6Rotate6rotate_5input6outputyAA8RotationO_S2StKF'
Found outside of lifetime use?!
Value:   %427 = load_borrow %426 : $*JPEG.Data.Spectral<JPEG.Common> // users: %435, %429
Consuming User:   end_borrow %427 : $JPEG.Data.Spectral<JPEG.Common> // id: %435
Non Consuming User:   end_borrow %429 : $*JPEG.Data.Spectral<JPEG.Common> // id: %445
Block: bb9
End Error in Function: '$s6Rotate6rotate_5input6outputyAA8RotationO_S2StKF'
Found ownership error?!
triggering standard assertion failure routine
UNREACHABLE executed at /Users/ec2-user/jenkins/workspace/oss-swift-6.0.2-package-macos/swift/lib/SIL/Verifier/LinearLifetimeCheckerPrivate.h:211!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Users/runner/Library/Developer/Toolchains/swift-6.0.2-RELEASE.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/runner/work/swift-property-crash/swift-property-crash/Snippets/Rotate.swift -emit-dependencies-path /Users/runner/work/swift-property-crash/swift-property-crash/.build/aarch64-unknown-linux-android24/debug/Rotate.build/Rotate.d -emit-reference-dependencies-path /Users/runner/work/swift-property-crash/swift-property-crash/.build/aarch64-unknown-linux-android24/debug/Rotate.build/Rotate.swiftdeps -target aarch64-unknown-linux-android24 -Xllvm -aarch64-use-tbi -disable-objc-interop -sdk /Users/runner/Library/org.swift.swiftpm/swift-sdks/swift-6.0.2-RELEASE-android-24-0.1.artifactbundle/swift-6.0.2-release-android-24-sdk/android-27c-sysroot -I /Users/runner/work/swift-property-crash/swift-property-crash/.build/aarch64-unknown-linux-android24/debug/Modules -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/runner/work/swift-pro
1.	Apple Swift version 6.0.2 (swift-6.0.2-RELEASE)
2.	Compiling with effective version 5.10
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/runner/work/swift-property-crash/swift-property-crash/Snippets/Rotate.swift")
4.	While silgen emitFunction SIL function "@$s6Rotate6rotate_5input6outputyAA8RotationO_S2StKF".
 for 'rotate(_:input:output:)' (at /Users/runner/work/swift-property-crash/swift-property-crash/Snippets/Rotate.swift:92:1)
5.	While verifying SIL function "@$s6Rotate6rotate_5input6outputyAA8RotationO_S2StKF".
 for 'rotate(_:input:output:)' (at /Users/runner/work/swift-property-crash/swift-property-crash/Snippets/Rotate.swift:92: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           0x0000000107e910d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000107e8f8a4 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000107e91720 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000018978e584 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018975dc20 pthread_kill + 288
5  libsystem_c.dylib        0x000000018966aa30 abort + 180
6  swift-frontend           0x0000000107e0fe70 llvm::install_out_of_memory_new_handler() + 0
7  swift-frontend           0x0000000103950af8 swift::LinearLifetimeChecker::ErrorBuilder::tryDumpErrorCounter() const + 0
8  swift-frontend           0x000000010394e598 swift::LinearLifetimeChecker::checkValueImpl(swift::SILValue, llvm::ArrayRef<swift::Operand*>, llvm::ArrayRef<swift::Operand*>, swift::LinearLifetimeChecker::ErrorBuilder&, std::__1::optional<llvm::function_ref<void (swift::SILBasicBlock*)>>, std::__1::optional<llvm::function_ref<void (swift::Operand*)>>) + 1560
9  swift-frontend           0x000000010394f508 swift::LinearLifetimeChecker::checkValue(swift::SILValue, llvm::ArrayRef<swift::Operand*>, llvm::ArrayRef<swift::Operand*>, swift::LinearLifetimeChecker::ErrorBuilder&) + 44
10 swift-frontend           0x0000000103956e40 swift::SILValueOwnershipChecker::check() + 544
11 swift-frontend           0x0000000103958a3c verifySILValueHelper(swift::SILFunction const*, swift::SILValue, swift::LinearLifetimeChecker::ErrorBuilder&, swift::DeadEndBlocks*, swift::GuaranteedPhiVerifier&) + 144
12 swift-frontend           0x000000010395891c swift::SILValue::verifyOwnership(swift::DeadEndBlocks*) const + 216
13 swift-frontend           0x00000001039797ac (anonymous namespace)::SILVerifier::checkValueBaseOwnership(swift::ValueBase*) + 164
14 swift-frontend           0x000000010397c6d4 (anonymous namespace)::SILVerifier::visitSILInstruction(swift::SILInstruction*) + 6264
15 swift-frontend           0x0000000103965c10 swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) + 13704
16 swift-frontend           0x0000000103962588 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 28
17 swift-frontend           0x0000000103960d34 (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 10556
18 swift-frontend           0x000000010395a390 swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const + 204
19 swift-frontend           0x0000000102ff59e4 swift::Lowering::SILGenModule::postEmitFunction(swift::SILDeclRef, swift::SILFunction*) + 312
20 swift-frontend           0x0000000102ff50f4 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 6296
21 swift-frontend           0x0000000102ff5f64 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 256
22 swift-frontend           0x0000000102ff3824 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 184
23 swift-frontend           0x0000000102ff8890 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 880
24 swift-frontend           0x00000001030f64ec swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 148
25 swift-frontend           0x0000000102ffe16c swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) + 340
26 swift-frontend           0x0000000102ff917c swift::performASTLowering(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) + 96
27 swift-frontend           0x00000001029db774 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 612
28 swift-frontend           0x00000001029e74ac withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
29 swift-frontend           0x00000001029dd678 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
30 swift-frontend           0x00000001029dcd4c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2344
31 swift-frontend           0x00000001027f3384 swift::mainEntry(int, char const**) + 3096
32 dyld                     0x00000001893d3154 start + 2476

Expected behavior

The compiler should not crash.

Environment

zap marcprux/swift-property-crash % sw_vers 
ProductName:		macOS
ProductVersion:		15.2
BuildVersion:		24C101

zap marcprux/swift-property-crash % ls ~/Library/Developer/Toolchains/    
swift-6.0.2-RELEASE.xctoolchain		swift-latest.xctoolchain

zap marcprux/swift-property-crash % ls ~/.swiftpm/swift-sdks 
swift-6.0.2-RELEASE-android-24-0.1.artifactbundle

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILSIL ownershipArea → compiler → SIL: SIL ownershipassertion failureBug → crash: An assertion failurebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwareswift 5.10

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions