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

using isKnownUniquelyReferenced seems to crash on C++ reference type #72676

Open
wtholliday opened this issue Mar 28, 2024 · 2 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ c++ to swift Feature → c++ interop: c++ to swift compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software IRGen LLVM IR generation swift 5.10

Comments

@wtholliday
Copy link

wtholliday commented Mar 28, 2024

Description

Code that uses isKnownUniquelyReferenced on C++ reference type (exposed via C++ interop) seems to cause crash

Reproduction

My attempt to create a simple repro results in unexpected link error, which could be a related bug.

Working on repro case.

Stack dump

1.	Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
2.	Compiling with the current language version
3.	While emitting IR SIL function "@$s13SculpturaBase8VolStoreC7collectyyF".
 for 'collect()' (at /Users/holliday/Sculptura/SculpturaBase/Sources/SculpturaBase/VolStore.swift:51:12)
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           0x0000000106757f3c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001067570f8 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000106758544 SignalHandler(int) + 360
3  libsystem_platform.dylib 0x000000018cdaf584 _sigtramp + 56
4  swift-frontend           0x0000000101451d8c swift::irgen::IRGenFunction::emitIsUniqueCall(llvm::Value*, swift::ReferenceCounting, swift::SourceLoc, bool) + 872
5  swift-frontend           0x0000000101451d8c swift::irgen::IRGenFunction::emitIsUniqueCall(llvm::Value*, swift::ReferenceCounting, swift::SourceLoc, bool) + 872
6  swift-frontend           0x0000000101591c3c (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 97852
7  swift-frontend           0x00000001015784fc swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 11556
8  swift-frontend           0x00000001013cc430 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&) + 2472
9  swift-frontend           0x000000010152d498 swift::performIRGeneration(swift::ModuleDecl*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::GlobalVariable**) + 2244
10 swift-frontend           0x000000010105c120 generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 260
11 swift-frontend           0x0000000101056294 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*) + 1892
12 swift-frontend           0x0000000101055a18 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2100
13 swift-frontend           0x0000000101059694 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1448
14 swift-frontend           0x00000001010576d0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4968
15 swift-frontend           0x0000000100fe6e8c swift::mainEntry(int, char const**) + 2612
16 dyld                     0x000000018c9f60e0 start + 2360

Expected behavior

Compiler doesn't crash

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

No response

@wtholliday wtholliday 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 Mar 28, 2024
@AnthonyLatsis AnthonyLatsis added c++ interop Feature: Interoperability with C++ c++ to swift Feature → c++ interop: c++ to swift swift 5.10 IRGen LLVM IR generation compiler The Swift compiler in itself and removed triage needed This issue needs more specific labels labels Mar 28, 2024
@wtholliday
Copy link
Author

Am I correct in assuming that emitIsUniqueCall has to do with isKnownUniquelyReferenced?

@wtholliday
Copy link
Author

I suppose that isKnownUniquelyReferenced can't work on something exposed from C++ because there is no way for Swift to actually get the reference count given this sort of interface:

struct SharedThing : public IntrusiveRefCounted<SharedThing> {

    static SharedThing* _Nonnull create();

    ~SharedThing();

private:
} SWIFT_SHARED_REFERENCE(retainSharedThing, releaseSharedThing);

void retainSharedThing(SharedThing * _Nonnull);
void releaseSharedThing(SharedThing * _Nonnull);

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. c++ interop Feature: Interoperability with C++ c++ to swift Feature → c++ interop: c++ to swift compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software IRGen LLVM IR generation swift 5.10
Projects
None yet
Development

No branches or pull requests

2 participants