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 Found outside of lifetime use?! #78447

Open
hjyamauchi opened this issue Jan 6, 2025 · 1 comment
Open

Compiler crash Found outside of lifetime use?! #78447

hjyamauchi opened this issue Jan 6, 2025 · 1 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 macOS Platform: macOS SIL ownership Area → compiler → SIL: SIL ownership SIL Windows Platform: Windows

Comments

@hjyamauchi
Copy link
Contributor

hjyamauchi commented Jan 6, 2025

Description

On macOS, the dev snapshot build https://download.swift.org/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a-osx.pkg crashes with

error: compile command failed due to signal 6 (use -v to see invocation)
Begin Error in Function: '$s5crash1BC3barSSSgyF'
Found outside of lifetime use?!
Value:   %4 = begin_borrow %3 : $A                       // users: %7, %5
Consuming User:   end_borrow %4 : $A                              // id: %7
Non Consuming User:   %11 = mark_dependence %10 : $*_xmlNs on %5 : $*UnsafeMutablePointer<_xmlNs> // user: %12
Block: bb0

End Error in Function: '$s5crash1BC3barSSSgyF'
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.

A local windows build from the main branch at head 1/6/2025 snapshot crashes with:

error: compile command failed due to exception 3 (use -v to see invocation)
Begin Error in Function: '$s5crash1BC3barSSSgyF'
Found outside of lifetime use?!
Value:   %4 = begin_borrow %3 : $A                       // users: %7, %5
Consuming User:   end_borrow %4 : $A                              // id: %7
Non Consuming User:   %11 = mark_dependence %10 : $*_xmlNs on %5 : $*UnsafeMutablePointer<_xmlNs> // user: %12
Block: bb0

End Error in Function: '$s5crash1BC3barSSSgyF'
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

Reproduction

Here's a command line log with a small reduced test.

>cat crash.swift
import C

func foo<T> (ptr: UnsafePointer<T>?) -> String? {
  return nil
}

class A {
  internal let ptr: xmlNsPtr
  internal init(ptr: xmlNsPtr) {
    self.ptr = ptr
  }
}

class B : A {
  func bar() -> String? {
    return foo(ptr: ptr.pointee.prefix)
  }
}

>cat header.h
typedef struct _xmlNs {
    const char *prefix;
} *xmlNsPtr;

>cat module.modulemap
module C {
  header "header.h"
}

>swiftc crash.swift -I .
error: compile command failed due to exception 3 (use -v to see invocation)
Begin Error in Function: '$s5crash1BC3barSSSgyF'
Found outside of lifetime use?!
Value:   %4 = begin_borrow %3 : $A                       // users: %7, %5
Consuming User:   end_borrow %4 : $A                              // id: %7
Non Consuming User:   %11 = mark_dependence %10 : $*_xmlNs on %5 : $*UnsafeMutablePointer<_xmlNs> // user: %12
Block: bb0

End Error in Function: '$s5crash1BC3barSSSgyF'
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

Stack dump

macOS with https://download.swift.org/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a-osx.pkg

Stack dump:
0.	Program arguments: /Users/hiroshi/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file crash.swift -target arm64-apple-macosx15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -I . -color-diagnostics -empty-abi-descriptor -resource-dir /Users/hiroshi/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a.xctoolchain/usr/lib/swift -module-name crash -in-process-plugin-server-path /Users/hiroshi/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Users/hiroshi/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Users/hiroshi/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a.xctoolchain/usr/local/lib/swift/host/plugins -o /var/folders/ww/kxcj3hm12kd92gcwr9t3y7k40000gq/T/TemporaryDirectory.sSqMVR/crash-1.o
1.	Apple Swift version 6.2-dev (LLVM 06a77c5cc0ff511, Swift f7fb0991b79fcda)
2.	Compiling with effective version 5.10
3.	While verifying SIL function "@$s5crash1BC3barSSSgyF".
 for 'bar()' (at crash.swift:15:3)
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           0x00000001064b2020 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001064b0704 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001064b267c SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000018fa1ae04 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018f9e3f70 pthread_kill + 288
5  libsystem_c.dylib        0x000000018f8f0908 abort + 128
6  swift-frontend           0x00000001008d1154 swift::DiagnosticHelper::create(swift::CompilerInstance&, swift::CompilerInvocation const&, llvm::ArrayRef<char const*>, llvm::raw_pwrite_stream&, bool) + 0
7  swift-frontend           0x000000010642e644 llvm::report_fatal_error(llvm::Twine const&, bool) + 256
8  swift-frontend           0x000000010642e544 llvm::report_fatal_error(llvm::Twine const&, bool) + 0
9  swift-frontend           0x00000001016b4924 swift::LinearLifetimeChecker::ErrorBuilder::tryDumpErrorCounter() const + 0
10 swift-frontend           0x00000001016b2460 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           0x00000001016b3594 swift::LinearLifetimeChecker::checkValue(swift::SILValue, llvm::ArrayRef<swift::Operand*>, llvm::ArrayRef<swift::Operand*>, swift::LinearLifetimeChecker::ErrorBuilder&) + 44
12 swift-frontend           0x00000001016baae4 swift::SILValueOwnershipChecker::check() + 636
13 swift-frontend           0x00000001016bcc04 verifySILValueHelper(swift::SILFunction const*, swift::SILValue, swift::LinearLifetimeChecker::ErrorBuilder&, swift::DeadEndBlocks*, swift::GuaranteedPhiVerifier&) + 156
14 swift-frontend           0x00000001016bcad0 swift::SILValue::verifyOwnership(swift::DeadEndBlocks*) const + 288
15 swift-frontend           0x00000001016dfa4c (anonymous namespace)::SILVerifier::checkValueBaseOwnership(swift::ValueBase*) + 164
16 swift-frontend           0x00000001016e2c18 (anonymous namespace)::SILVerifier::visitSILInstruction(swift::SILInstruction*) + 6640
17 swift-frontend           0x00000001016cf708 swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) + 36180
18 swift-frontend           0x00000001016c68b4 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 28
19 swift-frontend           0x00000001016c501c (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) + 10840
20 swift-frontend           0x00000001016bedf4 swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const + 224
21 swift-frontend           0x00000001016c1b4c swift::SILModule::verify(swift::CalleeCache*, bool, bool) const + 192
22 swift-frontend           0x00000001016c1a24 swift::SILModule::verify(bool, bool) const + 140
23 swift-frontend           0x00000001008e7420 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 148
24 swift-frontend           0x0000000100698914 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*) + 820
25 swift-frontend           0x0000000100697f98 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 656
26 swift-frontend           0x00000001006a3f10 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
27 swift-frontend           0x0000000100699ca4 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 716
28 swift-frontend           0x00000001006994c0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2208
29 swift-frontend           0x000000010044d2dc swift::mainEntry(int, char const**) + 3100
30 dyld                     0x000000018f664274 start + 2840

Windows main branch on 1/6/2025

1.      compnerd.org Swift version 6.2-dev (LLVM 06a77c5cc0ff511, Swift f7fb0991b79fcda)
2.      Compiling with effective version 5.10
3.      While verifying SIL function "@$s4Fuzi10XMLElementC9namespaceSSSgvgAEyXEfU_".
 for expression at [C:\Users\hiroshi\arc\build\boost-debug-none\_deps\fuzi-src\Sources\Element.swift:29:55 - line:31:3] RangeText="{
    return ^-^(self.cNode.pointee.ns != nil ?self.cNode.pointee.ns.pointee.prefix :nil)
  "
Exception Code: 0x80000003
 #0 0x00007ff7d369f305 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x6d7f305)
 #1 0x00007ff9f66ce6d5 (C:\Windows\System32\ucrtbase.dll+0x7e6d5)
 #2 0x00007ff9f66cf6e1 (C:\Windows\System32\ucrtbase.dll+0x7f6e1)
 #3 0x00007ff7cd1e8958 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x8c8958)
 #4 0x00007ff7d3621f7a (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x6d01f7a)
 #5 0x00007ff7d3622121 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x6d02121)
 #6 0x00007ff7ce003c71 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x16e3c71)
 #7 0x00007ff7ce18964a (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x186964a)
 #8 0x00007ff7ce1888f4 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x18688f4)
 #9 0x00007ff7ce18840f (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x186840f)
#10 0x00007ff7ce001b3a (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x16e1b3a)
#11 0x00007ff7ce004787 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x16e4787)
#12 0x00007ff7ce00464c (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x16e464c)
#13 0x00007ff7cdfdb6b4 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x16bb6b4)
#14 0x00007ff7cdfd61c1 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x16b61c1)
#15 0x00007ff7cdfdac6b (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x16bac6b)
#16 0x00007ff7cdfdb3df (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x16bb3df)
#17 0x00007ff7cdfcba24 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x16aba24)
#18 0x00007ff7cdfcc95c (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x16ac95c)
#19 0x00007ff7cd1bf029 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x89f029)
#20 0x00007ff7ccf31c0d (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-
frontend.exe+0x611c0d)
#21 0x00007ff7ccf326ef (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x6126ef)
#22 0x00007ff7ccf31377 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x611377)
#23 0x00007ff7ccf3190b (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x61190b)
#24 0x00007ff7ccf337e1 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x6137e1)
#25 0x00007ff7ccd80950 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x460950)
#26 0x00007ff7ccd80413 (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x460413)
#27 0x00007ff7d36fe44c (C:\Users\hiroshi\AppData\Local\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x6dde44c)
#28 0x00007ff9f7e8259d (C:\Windows\System32\KERNEL32.DLL+0x1259d)
#29 0x00007ff9f8acaf38 (C:\Windows\SYSTEM32\ntdll.dll+0x5af38)

Expected behavior

No crash

Environment

macos

https://download.swift.org/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a/swift-DEVELOPMENT-SNAPSHOT-2025-01-05-a-osx.pkg

windows, our main branch build on 1/6/2025

compnerd.org Swift version 6.2-dev (LLVM 06a77c5cc0ff511, Swift f7fb0991b79fcda)
Target: x86_64-unknown-windows-msvc

Additional information

This seems pretty recent. The crash didn't happen on 12/31/2024 and started around ~1/4/2025.

@hjyamauchi hjyamauchi 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 compnerd added Windows Platform: Windows macOS Platform: macOS SIL ownership Area → compiler → SIL: SIL ownership SIL and removed triage needed This issue needs more specific labels labels Jan 7, 2025
@compnerd
Copy link
Member

compnerd commented Jan 7, 2025

CC: @gottesmm

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 macOS Platform: macOS SIL ownership Area → compiler → SIL: SIL ownership SIL Windows Platform: Windows
Projects
None yet
Development

No branches or pull requests

2 participants