-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[cxx-interop] SIL verifier crash in Unmanaged.passUnretained() on SWIFT_UNSAFE_REFERENCE type #80065
Comments
Reduction: Test.h: #pragma once
#include <swift/bridging>
class S {
} SWIFT_UNSAFE_REFERENCE; module.modulemap
main.swift import MyCxx
extension MyCxx.S : Equatable {
public static func == (lhs: MyCxx.S, rhs: MyCxx.S) -> Bool {
Unmanaged.passUnretained(lhs).toOpaque() == Unmanaged.passUnretained(rhs).toOpaque()
}
} Test command (linux+swiftly): On macOS it will probably work to just Backtrace: error: compile command failed due to signal 6 (use -v to see invocation)
SIL verification failed: Operand of ref_to_unmanaged must have reference semantics: objectTy.isReferenceCounted(F.getModule())
Verifying instruction:
%6 = begin_borrow [lexical] %0 : $S // users: %7, %9
-> %7 = ref_to_unmanaged %6 : $S to $@sil_unmanaged S // user: %8
%8 = struct $Unmanaged<S> (%7 : $@sil_unmanaged S) // user: %10
In function:
// static S.== infix(_:_:)
// Isolation: unspecified
sil [ossa] @$sSo1SV4mainE2eeoiySbAB_ABtFZ : $@convention(method) (S, S, @thin S.Type) -> Bool {
// %0 "lhs" // users: %6, %3
// %1 "rhs" // users: %12, %4
// %2 "self" // user: %5
bb0(%0 : $S, %1 : $S, %2 : $@thin S.Type):
debug_value %0, let, name "lhs", argno 1 // id: %3
debug_value %1, let, name "rhs", argno 2 // id: %4
debug_value %2, let, name "self", argno 3 // id: %5
%6 = begin_borrow [lexical] %0 // users: %7, %9
%7 = ref_to_unmanaged %6 to $@sil_unmanaged S // user: %8
%8 = struct $Unmanaged<S> (%7) // user: %10
end_borrow %6 // id: %9
%10 = unchecked_trivial_bit_cast %8 to $UnsafeMutableRawPointer // user: %11
%11 = struct_extract %10, #UnsafeMutableRawPointer._rawValue // user: %18
%12 = begin_borrow [lexical] %1 // users: %13, %15
%13 = ref_to_unmanaged %12 to $@sil_unmanaged S // user: %14
%14 = struct $Unmanaged<S> (%13) // user: %16
end_borrow %12 // id: %15
%16 = unchecked_trivial_bit_cast %14 to $UnsafeMutableRawPointer // user: %17
%17 = struct_extract %16, #UnsafeMutableRawPointer._rawValue // user: %18
%18 = builtin "cmp_eq_RawPointer"(%11, %17) : $Builtin.Int1 // user: %19
%19 = struct $Bool (%18) // user: %20
return %19 // id: %20
} // end sil function '$sSo1SV4mainE2eeoiySbAB_ABtFZ'
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0. Program arguments: /home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/bin/swift-frontend -frontend -c -primary-file main.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -cxx-interoperability-mode=default -I . -color-diagnostics -empty-abi-descriptor -resource-dir /home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/lib/swift -Xcc -I/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/include -no-auto-bridging-header-chaining -module-name main -in-process-plugin-server-path /home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/lib/swift/host/libSwiftInProcPluginServer.so -plugin-path /home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/lib/swift/host/plugins -plugin-path /home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/local/lib/swift/host/plugins -parse-as-library -o /tmp/TemporaryDirectory.eunViy/main-1.o
1. Swift version 6.2-dev (LLVM 162ee50b401fff2, Swift 57288d13c9f3c02)
2. Compiling with effective version 5.10
3. While verifying SIL function "@$sSo1SV4mainE2eeoiySbAB_ABtFZ".
for '==(_:_:)' (at main.swift:4:11)
#0 0x00005f144b7bb498 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/bin/swift-frontend+0x8b29498)
#1 0x00005f144b7b8fbe llvm::sys::RunSignalHandlers() (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/bin/swift-frontend+0x8b26fbe)
#2 0x00005f144b7bbb31 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x0000794ebf645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x0000794ebf69eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x0000794ebf69eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x0000794ebf69eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x0000794ebf64527e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x0000794ebf6288ff abort ./stdlib/abort.c:81:7
#9 0x00005f1444faad51 (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/bin/swift-frontend+0x2318d51)
#10 0x00005f1444fdef24 (anonymous namespace)::SILVerifier::requireReferenceStorageCapableValue(swift::SILValue, llvm::Twine const&) SILVerifier.cpp:0:0
#11 0x00005f1444fbb852 swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) SILVerifier.cpp:0:0
#12 0x00005f1444fb494f (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) SILVerifier.cpp:0:0
#13 0x00005f1444fb2d5b (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) SILVerifier.cpp:0:0
#14 0x00005f1444faaf5b swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/bin/swift-frontend+0x2318f5b)
#15 0x00005f1444fae868 swift::SILModule::verify(swift::CalleeCache*, bool, bool) const (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/bin/swift-frontend+0x231c868)
#16 0x00005f1444fae71f swift::SILModule::verify(bool, bool) const (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/bin/swift-frontend+0x231c71f)
#17 0x00005f1443f18f84 swift::CompilerInstance::performSILProcessing(swift::SILModule*) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/bin/swift-frontend+0x1286f84)
#18 0x00005f1443bb6a97 performCompileStepsPostSILGen(swift::CompilerInstance&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#19 0x00005f1443bb59ea swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/bin/swift-frontend+0xf239ea)
#20 0x00005f1443bc729a withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) FrontendTool.cpp:0:0
#21 0x00005f1443bb88be performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#22 0x00005f1443bb79b5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/bin/swift-frontend+0xf259b5)
#23 0x00005f144395312b swift::mainEntry(int, char const**) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/bin/swift-frontend+0xcc112b)
#24 0x0000794ebf62a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#25 0x0000794ebf62a28b call_init ./csu/../csu/libc-start.c:128:20
#26 0x0000794ebf62a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#27 0x00005f1443952125 _start (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-03-14/usr/bin/swift-frontend+0xcc0125) |
19 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
I have a SWIFT_UNSAFE_REFERENCE type that I implemented an equality operator for via pointer comparison with Unmanaged.passUnretained( ... ).toOpaque().
Reproduction
Stack dump
Expected behavior
No crash, pointer comparison between SWIFT_UNSAFE_REFERENCE types should be allowed
Environment
This crashes on x86_64 Linux Swift version 6.2-dev (LLVM 162ee50b401fff2, Swift 57288d1) aka swiftly main-snapshot-2025-03-14
This same code does not crash on Xcode 16.3
Additional information
I'll update this issue with better repro steps once I clean up my branch. This reproduces for Ladybird.
The text was updated successfully, but these errors were encountered: