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

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

Open
marcprux opened this issue Jan 6, 2025 · 10 comments
Open
Labels
assertion failure Bug → crash: An assertion failure bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software SIL ownership Area → compiler → SIL: SIL ownership SIL swift 5.10

Comments

@marcprux
Copy link
Contributor

marcprux commented Jan 6, 2025

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

@marcprux marcprux 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 Jan 6, 2025
@compnerd
Copy link
Member

Can you test this again at main? I wonder if the recent change for the dependency tracking had an impact here.

@marcprux
Copy link
Contributor Author

marcprux commented Jan 10, 2025

Can you test this again at main?

Using latest main toolchain (from https://download.swift.org/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a-osx.pkg) combined with the Android SDK at https://github.com/finagolfin/swift-android-sdk/actions/runs/12667390143/artifacts/2400255677, it crashes with the same error.

I wonder if the recent change for the dependency tracking had an impact here.

If it is more recent than 2025-01-05, I can test again once a new toolchain is posted and the corresponding Android SDK is built.

zap marcprux/swift-property-crash % ~/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a.xctoolchain/usr/bin/swift build --swift-sdk swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a-android-24-0.1

warning: multiple Swift SDKs match ID `swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a-android-24-0.1` and host triple arm64-apple-macosx15.0, selected one at /Users/marc/Library/org.swift.swiftpm/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a-android-24-0.1.artifactbundle/swift-DEVELOPMENT-trunk-android-24-sdk
warning: multiple Swift SDKs match ID `swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a-android-24-0.1` and host triple arm64-apple-macosx15.0, selected one at /Users/marc/Library/org.swift.swiftpm/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a-android-24-0.1.artifactbundle/swift-DEVELOPMENT-trunk-android-24-sdk
warning: 'swift-property-crash': Invalid Exclude '/opt/src/github/marcprux/swift-property-crash/tests/fuzz/data': File not found.
Building for debugging...
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:   %429 = load_borrow %428 : $*JPEG.Data.Spectral<JPEG.Common> // users: %437, %431
Consuming User:   end_borrow %429 : $JPEG.Data.Spectral<JPEG.Common> // id: %437
Non Consuming User:   end_borrow %431 : $*JPEG.Data.Spectral<JPEG.Common> // id: %448
Block: bb9

End Error in Function: '$s6Rotate6rotate_5input6outputyAA8RotationO_S2StKF'
Found ownership error?!
<unknown>:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
<unknown>:0: note: triggering standard assertion failure routine
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Users/marc/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /opt/src/github/marcprux/swift-property-crash/Snippets/Rotate.swift -emit-dependencies-path /opt/src/github/marcprux/swift-property-crash/.build/x86_64-unknown-linux-android24/debug/Rotate.build/Rotate.d -emit-reference-dependencies-path /opt/src/github/marcprux/swift-property-crash/.build/x86_64-unknown-linux-android24/debug/Rotate.build/Rotate.swiftdeps -target x86_64-unknown-linux-android24 -disable-objc-interop -sdk /Users/marc/Library/org.swift.swiftpm/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a-android-24-0.1.artifactbundle/swift-DEVELOPMENT-trunk-android-24-sdk/android-27c-sysroot -I /opt/src/github/marcprux/swift-property-crash/.build/x86_64-unknown-linux-android24/debug/Modules -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /opt/src/github/marcprux/swift-property-crash/.build/x86_64-unknown-linux-android24/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -entry-point-function-name Rotate_main -empty-abi-descriptor -resource-dir /Users/marc/Library/org.swift.swiftpm/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a-android-24-0.1.artifactbundle/swift-DEVELOPMENT-trunk-android-24-sdk/android-27c-sysroot/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /opt/src/github/marcprux/swift-property-crash -Xcc --sysroot -Xcc /Users/marc/Library/org.swift.swiftpm/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a-android-24-0.1.artifactbundle/swift-DEVELOPMENT-trunk-android-24-sdk/android-27c-sysroot -Xcc -fPIC -Xcc -g -Xcc -fno-omit-frame-pointer -module-name Rotate -in-process-plugin-server-path /Users/marc/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Users/marc/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Users/marc/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a.xctoolchain/usr/local/lib/swift/host/plugins -o /opt/src/github/marcprux/swift-property-crash/.build/x86_64-unknown-linux-android24/debug/Rotate.build/Rotate.swift.o -index-store-path /opt/src/github/marcprux/swift-property-crash/.build/x86_64-unknown-linux-android24/debug/index/store -index-system-modules
1.	Apple Swift version 6.2-dev (LLVM 06a77c5cc0ff511, Swift f7fb0991b79fcda)
2.	Compiling with effective version 5.10
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/opt/src/github/marcprux/swift-property-crash/Snippets/Rotate.swift")
4.	While silgen emitFunction SIL function "@$s6Rotate6rotate_5input6outputyAA8RotationO_S2StKF".
 for 'rotate(_:input:output:)' (at /opt/src/github/marcprux/swift-property-crash/Snippets/Rotate.swift:92:1)
5.	While verifying SIL function "@$s6Rotate6rotate_5input6outputyAA8RotationO_S2StKF".
 for 'rotate(_:input:output:)' (at /opt/src/github/marcprux/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           0x0000000108f96020 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000108f94704 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000108f9667c SignalHandler(int) + 304
3  libsystem_platform.dylib 0x00000001841b6e04 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018417ff70 pthread_kill + 288
5  libsystem_c.dylib        0x000000018408c908 abort + 128
6  swift-frontend           0x00000001033b5154 swift::DiagnosticHelper::create(swift::CompilerInstance&, swift::CompilerInvocation const&, llvm::ArrayRef<char const*>, llvm::raw_pwrite_stream&, bool) + 0
7  swift-frontend           0x0000000108f12644 llvm::report_fatal_error(llvm::Twine const&, bool) + 256
8  swift-frontend           0x0000000108f12544 llvm::report_fatal_error(llvm::Twine const&, bool) + 0
9  swift-frontend           0x0000000104198924 swift::LinearLifetimeChecker::ErrorBuilder::tryDumpErrorCounter() const + 0
10 swift-frontend           0x0000000104196460 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*)>>) + 1748
11 swift-frontend           0x0000000104197594 swift::LinearLifetimeChecker::checkValue(swift::SILValue, llvm::ArrayRef<swift::Operand*>, llvm::ArrayRef<swift::Operand*>, swift::LinearLifetimeChecker::ErrorBuilder&) + 44
12 swift-frontend           0x000000010419eae4 swift::SILValueOwnershipChecker::check() + 636
13 swift-frontend           0x00000001041a0c04 verifySILValueHelper(swift::SILFunction const*, swift::SILValue, swift::LinearLifetimeChecker::ErrorBuilder&, swift::DeadEndBlocks*, swift::GuaranteedPhiVerifier&) + 156
14 swift-frontend           0x00000001041a0ad0 swift::SILValue::verifyOwnership(swift::DeadEndBlocks*) const + 288
15 swift-frontend           0x00000001041c3a4c (anonymous namespace)::SILVerifier::checkValueBaseOwnership(swift::ValueBase*) + 164
16 swift-frontend           0x00000001041c6c18 (anonymous namespace)::SILVerifier::visitSILInstruction(swift::SILInstruction*) + 6640
17 swift-frontend           0x00000001041b2774 swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) + 32192
18 swift-frontend           0x00000001041aa8b4 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 28
19 swift-frontend           0x00000001041a901c (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 10840
20 swift-frontend           0x00000001041a2df4 swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const + 224
21 swift-frontend           0x00000001037d75ac swift::Lowering::SILGenModule::postEmitFunction(swift::SILDeclRef, swift::SILFunction*) + 312
22 swift-frontend           0x00000001037d6cb4 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 6164
23 swift-frontend           0x00000001037d7ea0 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 268
24 swift-frontend           0x00000001037d5468 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 184
25 swift-frontend           0x00000001037da644 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 176
26 swift-frontend           0x00000001037dab60 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 632
27 swift-frontend           0x00000001038ddedc swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 148
28 swift-frontend           0x00000001037e0070 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
29 swift-frontend           0x00000001037db198 swift::performASTLowering(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) + 96
30 swift-frontend           0x000000010317bf6c swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 612
31 swift-frontend           0x0000000103187f10 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
32 swift-frontend           0x000000010317dca4 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 716
33 swift-frontend           0x000000010317d4c0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2208
34 swift-frontend           0x0000000102f312dc swift::mainEntry(int, char const**) + 3100
35 dyld                     0x0000000183e00274 start + 2840
[54/108] Emitting module EncodeAdvanced

@finagolfin
Copy link
Member

Try it again with the Jan. 10 trunk tag, which has the fix for the similar error in #78447.

@marcprux
Copy link
Contributor Author

No, it still crashes for me with the same stack trace, even without specifying any custom SDK. For the record, it is also crashing with the earlier swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a.xctoolchain without any custom SDK as well.

You can try for yourself by attempting to build https://github.com/marcprux/swift-property-crash.git (which is just a snapshot of https://github.com/tayloraswift/swift-jpeg.git from before I submitted the patch to work around the crash).

zap marcprux/swift-property-crash % ~/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.xctoolchain/usr/bin/swift build

warning: 'swift-property-crash': Invalid Exclude '/opt/src/github/marcprux/swift-property-crash/tests/fuzz/data': File not found.
Building for debugging...
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:   %429 = load_borrow %428 : $*JPEG.Data.Spectral<JPEG.Common> // users: %437, %431
Consuming User:   end_borrow %429 : $JPEG.Data.Spectral<JPEG.Common> // id: %437
Non Consuming User:   end_borrow %431 : $*JPEG.Data.Spectral<JPEG.Common> // id: %448
Block: bb9

End Error in Function: '$s6Rotate6rotate_5input6outputyAA8RotationO_S2StKF'
Found ownership error?!
<unknown>:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
<unknown>:0: note: triggering standard assertion failure routine
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
… same stack as above …

@finagolfin
Copy link
Member

OK, I'm able to reproduce by simply compiling your repo for linux x86_64 with the latest Jan. 10 trunk snapshot tag, so this is clearly not specific to any platform, updating title and labels to show that.

@finagolfin finagolfin changed the title Compiler crash when cross-compiling from macOS to Android when using _modify and yield Compiler crash with lifetime issue with latest January trunk snapshots Jan 14, 2025
@finagolfin finagolfin added SIL ownership Area → compiler → SIL: SIL ownership and removed triage needed This issue needs more specific labels labels Jan 14, 2025
@finagolfin
Copy link
Member

@gottesmm, please refer this to the right person.

@fibrechannelscsi
Copy link
Contributor

I have a reproducer for a similar, if not, the same issue. It does produce a stack trace containing llvm::install_out_of_memory_new_handler, but it isn't identical.

I'm compiling the following in Release mode with 6.0.3 Release 2024-12-10a. The build fails there.
It does not fail to compile with 6.1 Development Snapshot 2025-01-10a.
The stack trace specific to this reproducer is listed at the bottom.

import Foundation
public enum H: Hashable, RawRepresentable { // Has to be both Hashable, RawRepresentable for the build to fail
    case cc(String) // Has to be present for the build to fail.
    case bb // We have to use "bb" and not "cc" in line 12, or the build will succeed.
    public init?(rawValue: String) {fatalError()} // Needed for conformance to RawRepresentable
    public var rawValue: String {fatalError()} // Needed for conformance to RawRepresentable
    public func hash(into hasher: inout Hasher) {fatalError()} // Needed for conformance to Hashable
}
public protocol G {}
public extension G { // Has to be public for the build to fail.
    func j(of m: H, to d: Date) {
        guard m != .bb else { return }; // Need this line and the line below for the build to fail.
        self.l(of: m, to: d) // Need this line and the line above for the build to fail.
    }
    func l(of key: H, to date: Date) {
        if let self = self as? E {self.j(of: key, to: date)}
        else {print(key)} // Has to be present for the build to fail. Printing "date" also causes the build to fail.
    }
}
protocol E {func j(of: H, to: Date)}
enum F {}
extension F {final class X: G {init() {fatalError()}}} //At least one of classes X or Y have to be "final" for the build to fail.
extension F.X: E {}
extension F {final class Y: G {init() {fatalError()}}}
extension F.Y: E {} // We need this plus the line above for the build to fail. Deleting both will make it succeed.
1.	Apple Swift version 6.0.3 (swift-6.0.3-RELEASE)
2.	Compiling with effective version 5.10
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 a)
4.	While running pass #9655 SILFunctionTransform "OwnershipModelEliminator" on SILFunction "@$s4a1FO1XCAA1EA2aFP1j2of2toyAA1HO_10Foundation4DateVtFTW".
 for 'j(of:to:)' (at /Users/user/a/main.swift:11:5)
5.	Found verification error when verifying before lowering ownership. Please re-run with -sil-verify-all to identify the actual pass that introduced the verification error.
6.	While verifying SIL function "@$s4a1FO1XCAA1EA2aFP1j2of2toyAA1HO_10Foundation4DateVtFTW".
 for 'j(of:to:)' (at /Users/user/a/main.swift:11:5)
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           0x0000000109fcc0f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109fca8c4 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000109fcc740 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x0000000184029a24 _sigtramp + 56
4  libsystem_pthread.dylib  0x0000000183ff9cc0 pthread_kill + 288
5  libsystem_c.dylib        0x0000000183f05a40 abort + 180
6  swift-frontend           0x0000000109f4ae90 llvm::install_out_of_memory_new_handler() + 0
7  swift-frontend           0x0000000105a576a8 swift::LinearLifetimeChecker::ErrorBuilder::tryDumpErrorCounter() const + 0
8  swift-frontend           0x0000000105a5f05c swift::SILValueOwnershipChecker::checkValueWithoutLifetimeEndingUses(llvm::ArrayRef<swift::Operand*>) + 516
9  swift-frontend           0x0000000105a5db60 swift::SILValueOwnershipChecker::checkUses() + 248
10 swift-frontend           0x0000000105a5d8a8 swift::SILValueOwnershipChecker::check() + 216
11 swift-frontend           0x0000000105a5f5ec verifySILValueHelper(swift::SILFunction const*, swift::SILValue, swift::LinearLifetimeChecker::ErrorBuilder&, swift::DeadEndBlocks*, swift::GuaranteedPhiVerifier&) + 144
12 swift-frontend           0x0000000105a5f4cc swift::SILValue::verifyOwnership(swift::DeadEndBlocks*) const + 216
13 swift-frontend           0x0000000105a8035c (anonymous namespace)::SILVerifier::checkValueBaseOwnership(swift::ValueBase*) + 164
14 swift-frontend           0x0000000105a83284 (anonymous namespace)::SILVerifier::visitSILInstruction(swift::SILInstruction*) + 6264
15 swift-frontend           0x0000000105a6c038 swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) + 11776
16 swift-frontend           0x0000000105a69138 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 28
17 swift-frontend           0x0000000105a678e4 (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 10556
18 swift-frontend           0x0000000105a60f40 swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const + 204
19 swift-frontend           0x00000001054e3190 (anonymous namespace)::OwnershipModelEliminator::run() + 268
20 swift-frontend           0x00000001054e99fc swift::SILPassManager::runPassOnFunction(unsigned int, swift::SILFunction*) + 1432
21 swift-frontend           0x00000001054ea868 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 1060
22 swift-frontend           0x00000001054e7a38 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
23 swift-frontend           0x00000001054e79b8 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68
24 swift-frontend           0x0000000105522130 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28
25 swift-frontend           0x0000000105502788 swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) + 204
26 swift-frontend           0x00000001054e7c14 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 64
27 swift-frontend           0x0000000105504d08 swift::runSILOptimizationPasses(swift::SILModule&) + 156
28 swift-frontend           0x0000000104d23068 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 636
29 swift-frontend           0x0000000104ae2a84 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 796
30 swift-frontend           0x0000000104ae2380 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1216
31 swift-frontend           0x0000000104aede5c withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
32 swift-frontend           0x0000000104ae4028 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 708
33 swift-frontend           0x0000000104ae36fc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2344
34 swift-frontend           0x00000001048f9edc swift::mainEntry(int, char const**) + 3096
35 dyld                     0x0000000183c790e0 start + 2360

@finagolfin
Copy link
Member

I tried to find when this assertion failure was introduced and I see it on all linux snapshot builds going back to the 5.10 snapshot from Jan. 2 last year. If I go back to the 2023 builds, the repro repo has other compilation failures for those older compilers, so it doesn't even get to this snippet that causes a compiler crash. I don't see the crash with the Swift 6.0.3 release, presumably because those simply have these assertions turned off.

Looks like this is one of four "Found outside of lifetime use?!" crashes reported going back more than two years, with another four closed. @atrick, can you take a look at this?

@tayloraswift, you may want to start running your repos through a CI including the snapshot builds, as you could've reported this at least a year ago.

@fibrechannelscsi, that appears to be a different issue, if you cannot reproduce with the Swift 6.1 snapshot from this month. I suggest you bisect the 6.1 snapshots and see if you can find what pull fixed that, then check if it's already backported to the release/6.0 branch or needs to be for the next patch release.

@finagolfin finagolfin added swift 5.10 assertion failure Bug → crash: An assertion failure labels Jan 23, 2025
@tayloraswift
Copy link
Member

imo, this should be the responsibility of the Swift Source Compatibility Suite. that project desperately needs to be revived.

https://forums.swift.org/t/is-the-swift-source-compatibility-suite-still-maintained/77191

@fibrechannelscsi
Copy link
Contributor

I've made a new ticket for this issue here:
#78923

This appears to be a 6.0-only issue; I haven't found any 6.1-series toolchains with this crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assertion failure Bug → crash: An assertion failure bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software SIL ownership Area → compiler → SIL: SIL ownership SIL swift 5.10
Projects
None yet
Development

No branches or pull requests

6 participants