Skip to content

Compiler crash: "Require PartitionOp's argument should already be tracked" #81500

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

Open
pusewicz opened this issue May 14, 2025 · 1 comment
Open
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 triage needed This issue needs more specific labels

Comments

@pusewicz
Copy link

Description

Using Unmanaged<T>.fromOpaque(userData!) with a passed template protocol type causes the crash.

Reproduction

func cRegisterSystem(
  _ callback: @convention(c) (UnsafeMutableRawPointer?) -> Void,
) {
  // no-op
}

func registerSystem<T: AnyObject>(system: T) {
  cRegisterSystem(
    { (userData) in
      Unmanaged<T>.fromOpaque(userData!)  // FIX: Crash!
    }
  )
}

Stack dump

Building for debugging...
error: compile command failed due to signal 6 (use -v to see invocation)
Assertion failed: (p.isTrackingElement(op.getOpArgs()[0]) && "Require PartitionOp's argument should already be tracked"), function apply, file PartitionUtils.h, line 1385.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /Users/piotr/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/piotr/Work/GitHub/UnmanagedCrash/Sources/main.swift -emit-dependencies-path /Users/piotr/Work/GitHub/UnmanagedCrash/.build/arm64-apple-macosx/debug/UnmanagedCrash.build/main.d -emit-reference-dependencies-path /Users/piotr/Work/GitHub/UnmanagedCrash/.build/arm64-apple-macosx/debug/UnmanagedCrash.build/main.swiftdeps -target arm64-apple-macosx10.13 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.4.sdk -I /Users/piotr/Work/GitHub/UnmanagedCrash/.build/arm64-apple-macosx/debug/Modules -I /Users/piotr/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/lib/swift/macosx/testing -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/piotr/Work/GitHub/UnmanagedCrash/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 6 -Onone -D SWIFT_PACKAGE -D DEBUG -entry-point-function-name UnmanagedCrash_main -empty-abi-descriptor -plugin-path /Users/piotr/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/lib/swift/host/plugins/testing -resource-dir /Users/piotr/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/piotr/Work/GitHub/UnmanagedCrash -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.4.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/PrivateFrameworks -Xcc -fPIC -Xcc -g -module-name UnmanagedCrash -package-name unmanagedcrash -in-process-plugin-server-path /Users/piotr/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Users/piotr/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Users/piotr/Library/Developer/Toolchains/swift-6.1-RELEASE.xctoolchain/usr/local/lib/swift/host/plugins -target-sdk-version 15.4 -target-sdk-name macosx15.4 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -o /Users/piotr/Work/GitHub/UnmanagedCrash/.build/arm64-apple-macosx/debug/UnmanagedCrash.build/main.swift.o -index-store-path /Users/piotr/Work/GitHub/UnmanagedCrash/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.      Apple Swift version 6.1 (swift-6.1-RELEASE)
2.      Compiling with the current language version
3.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for UnmanagedCrash)
4.      While running pass #50 SILFunctionTransform "SendNonSendable" on SILFunction "@$s14UnmanagedCrash14registerSystem6systemyx_tRlzClF".
 for 'registerSystem(system:)' (at /Users/piotr/Work/GitHub/UnmanagedCrash/Sources/main.swift:7: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           0x000000010994b884 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109949fb0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010994bec8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x00000001993d4624 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000019939a88c pthread_kill + 296
5  libsystem_c.dylib        0x00000001992a3c60 abort + 124
6  libsystem_c.dylib        0x00000001992a2eec err + 0
7  swift-frontend           0x0000000109a07408 swift::regionanalysisimpl::BlockPartitionState::recomputeExitFromEntry(swift::regionanalysisimpl::PartitionOpTranslator&) (.cold.48) + 0
8  swift-frontend           0x0000000104d65b60 swift::regionanalysisimpl::BlockPartitionState::recomputeExitFromEntry(swift::regionanalysisimpl::PartitionOpTranslator&) + 4980
9  swift-frontend           0x0000000104d66870 swift::RegionAnalysisFunctionInfo::runDataflow() + 1716
10 swift-frontend           0x0000000104d66170 swift::RegionAnalysisFunctionInfo::RegionAnalysisFunctionInfo(swift::SILFunction*, swift::PostOrderFunctionInfo*) + 992
11 swift-frontend           0x0000000104d67308 swift::RegionAnalysis::newFunctionAnalysis(swift::SILFunction*) + 56
12 swift-frontend           0x0000000104f9e590 swift::FunctionAnalysisBase<swift::RegionAnalysisFunctionInfo>::get(swift::SILFunction*) + 80
13 swift-frontend           0x0000000104f9cb4c (anonymous namespace)::SendNonSendable::run() + 140
14 swift-frontend           0x0000000104fbf054 swift::SILPassManager::runPassOnFunction(unsigned int, swift::SILFunction*) + 1452
15 swift-frontend           0x0000000104fbfdd8 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 1060
16 swift-frontend           0x0000000104fc250c swift::SILPassManager::execute() + 596
17 swift-frontend           0x0000000104fbcfd0 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72                                                                                  18 swift-frontend           0x0000000104fbcf50 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68
19 swift-frontend           0x0000000105008d90 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28                                                                                                                                                                    20 swift-frontend           0x0000000104fd9154 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
21 swift-frontend           0x0000000104fbd1c0 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 64
22 swift-frontend           0x0000000104febef8 swift::runSILDiagnosticPasses(swift::SILModule&) + 192                                                                                                                  23 swift-frontend           0x0000000104890758 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 80
24 swift-frontend           0x000000010465d3ac 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           0x000000010465ca3c swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 468
26 swift-frontend           0x0000000104668b50 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 164
27 swift-frontend           0x000000010465e74c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 716
28 swift-frontend           0x000000010465df68 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2228
29 swift-frontend           0x00000001044418f0 swift::mainEntry(int, char const**) + 3064
30 dyld                     0x0000000198ffab98 start + 6076

Expected behavior

A pointer gets de-referenced and a correct value gets returned.

Environment

Apple Swift version 6.1 (swift-6.1-RELEASE)
Target: arm64-apple-macosx15.0

Additional information

This is when passing a closure to a C function as a callback. I modeled the cRegisterSystem after what gets imported from pico_ecs.h C library.

@pusewicz pusewicz 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 May 14, 2025
@jamieQ
Copy link
Contributor

jamieQ commented May 14, 2025

similar error as reported in #81187. cc @hborla @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 triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants