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

Assertion failure when emitting Obj-C header for function that uses C++ type #78190

Open
hamishknight opened this issue Dec 14, 2024 · 0 comments · May be fixed by #78219
Open

Assertion failure when emitting Obj-C header for function that uses C++ type #78190

hamishknight opened this issue Dec 14, 2024 · 0 comments · May be fixed by #78219
Assignees
Labels
assertion failure Bug → crash: An assertion failure bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@hamishknight
Copy link
Contributor

For e.g:

// cmodule.h
struct Foo {
  void *foo;
};
// module.modulemap
module CModule [system] {
  header "cmodule.h"
  requires cplusplus
  export *
}

The following hits an assertion failure when using -emit-objc-header:

import CModule

public func bar(x: Foo, y: UnsafeMutablePointer<UnsafeMutableRawPointer?>) {}
Assertion failed: (!s.isUnsupported()), function operator(), file PrintClangFunction.cpp, line 921.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /Users/hamish/src/swift-dev/build/Release/swift-macosx-arm64/bin/swift-frontend -typecheck /Users/hamish/src/swift-test-arena/main.swift -sdk /Users/hamish/src/MacOSX.sdk -debug-diagnostic-names -diagnostic-style=llvm -emit-objc-header -emit-objc-header-path /tmp/foo.h -I /Users/hamish/src/swift-test-arena/CModule -cxx-interoperability-mode=default
1.      Swift version 6.2-dev (LLVM 52a70e588b5dd9e, Swift dfe1f9cc53a1678)
2.      Compiling with effective version 5.10
3.      While generating Clang header
4.      While printing forward declarations needed by function 'bar(x:y:)' (at /Users/hamish/src/swift-test-arena/main.swift:577:8)
5.      While printing 'bar(x:y:)' (at /Users/hamish/src/swift-test-arena/main.swift:577:8)
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           0x00000001069575d0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001069558ec llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000106957c2c SignalHandler(int) + 292
3  libsystem_platform.dylib 0x00000001810b4184 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018107ef70 pthread_kill + 288
5  libsystem_c.dylib        0x0000000180f8b908 abort + 128
6  libsystem_c.dylib        0x0000000180f8ac1c err + 0
7  swift-frontend           0x00000001069e0a64 void llvm::function_ref<void (swift::LoweredFunctionSignature::GenericRequirementParameter const&)>::callback_fn<swift::DeclAndTypeClangFunctionPrinter::printFunctionSignature(swift::AbstractFunctionDecl const*, swift::LoweredFunctionSignature const&, llvm::StringRef, swift::Type, swift::DeclAndTypeClangFunctionPrinter::FunctionSignatureKind, swift::DeclAndTypeClangFunctionPrinter::FunctionSignatureModifiers)::$_8>(long, swift::LoweredFunctionSignature::GenericRequirementParameter const&) (.cold.1) + 0
8  swift-frontend           0x000000010113e9cc void llvm::function_ref<void (swift::LoweredFunctionSignature::IndirectParameter const&)>::callback_fn<swift::DeclAndTypeClangFunctionPrinter::printFunctionSignature(swift::AbstractFunctionDecl const*, swift::LoweredFunctionSignature const&, llvm::StringRef, swift::Type, swift::DeclAndTypeClangFunctionPrinter::FunctionSignatureKind, swift::DeclAndTypeClangFunctionPrinter::FunctionSignatureModifiers)::$_7>(long, swift::LoweredFunctionSignature::IndirectParameter const&) + 0
9  swift-frontend           0x000000010113daac void llvm::function_ref<void (swift::LoweredFunctionSignature::DirectParameter const&)>::callback_fn<swift::DeclAndTypeClangFunctionPrinter::printFunctionSignature(swift::AbstractFunctionDecl const*, swift::LoweredFunctionSignature const&, llvm::StringRef, swift::Type, swift::DeclAndTypeClangFunctionPrinter::FunctionSignatureKind, swift::DeclAndTypeClangFunctionPrinter::FunctionSignatureModifiers)::$_6>(long, swift::LoweredFunctionSignature::DirectParameter const&) + 820
10 swift-frontend           0x00000001013e37bc swift::LoweredFunctionSignature::visitParameterList(llvm::function_ref<void (swift::LoweredFunctionSignature::IndirectResultValue const&)>, llvm::function_ref<void (swift::LoweredFunctionSignature::DirectParameter const&)>, llvm::function_ref<void (swift::LoweredFunctionSignature::IndirectParameter const&)>, llvm::function_ref<void (swift::LoweredFunctionSignature::GenericRequirementParameter const&)>, llvm::function_ref<void (swift::LoweredFunctionSignature::MetadataSourceParameter const&)>, llvm::function_ref<void (swift::LoweredFunctionSignature::ContextParameter const&)>, llvm::function_ref<void (swift::LoweredFunctionSignature::ErrorResultValue const&)>) const + 504
11 swift-frontend           0x0000000101133bec swift::DeclAndTypeClangFunctionPrinter::printFunctionSignature(swift::AbstractFunctionDecl const*, swift::LoweredFunctionSignature const&, llvm::StringRef, swift::Type, swift::DeclAndTypeClangFunctionPrinter::FunctionSignatureKind, swift::DeclAndTypeClangFunctionPrinter::FunctionSignatureModifiers) + 4308
12 swift-frontend           0x0000000101119258 swift::DeclAndTypePrinter::Implementation::printCFunctionWithLoweredSignature(swift::AbstractFunctionDecl*, swift::DeclAndTypePrinter::Implementation::FunctionSwiftABIInformation const&, swift::Type, swift::AnyFunctionType*, llvm::StringRef, llvm::StringRef) + 216
13 swift-frontend           0x0000000101118698 swift::DeclAndTypePrinter::Implementation::printSwiftABIFunctionSignatureAsCxxFunction(swift::AbstractFunctionDecl*, std::__1::optional<swift::FunctionType*>, std::__1::optional<swift::NominalTypeDecl*>) + 540
14 swift-frontend           0x000000010110e960 swift::DeclAndTypePrinter::Implementation::visitFuncDecl(swift::FuncDecl*) + 256
15 swift-frontend           0x000000010110a59c swift::DeclAndTypePrinter::print(swift::Decl const*) + 96
16 swift-frontend           0x0000000101121f0c (anonymous namespace)::ModuleWriter::writeFunc(swift::FuncDecl const*) + 188
17 swift-frontend           0x000000010111f3d4 (anonymous namespace)::ModuleWriter::write() + 2060
18 swift-frontend           0x0000000101120e78 swift::printModuleContentsAsCxx(llvm::raw_ostream&, swift::ModuleDecl&, swift::SwiftToClangInteropContext&, bool, llvm::StringSet<llvm::MallocAllocator>&) + 1392
19 swift-frontend           0x0000000101130550 void llvm::function_ref<void ()>::callback_fn<swift::printAsClangHeader(llvm::raw_ostream&, swift::ModuleDecl*, llvm::StringRef, swift::FrontendOptions const&, swift::IRGenOptions const&, clang::HeaderSearch&)::$_2>(long) + 736
20 swift-frontend           0x000000010112bc8c emitCxxConditional(llvm::raw_ostream&, llvm::function_ref<void ()>, llvm::function_ref<void ()>) + 124
21 swift-frontend           0x000000010112ba24 swift::printAsClangHeader(llvm::raw_ostream&, swift::ModuleDecl*, llvm::StringRef, swift::FrontendOptions const&, swift::IRGenOptions const&, clang::HeaderSearch&) + 6392
22 swift-frontend           0x0000000100d78840 swift::withOutputPath(swift::DiagnosticEngine&, llvm::vfs::OutputBackend&, llvm::StringRef, llvm::function_ref<bool (llvm::raw_pwrite_stream&)>) + 152
23 swift-frontend           0x0000000100f60660 performEndOfPipelineActions(swift::CompilerInstance&) + 3732
24 swift-frontend           0x0000000100f5c95c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 732
25 swift-frontend           0x0000000100f5c190 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2204
26 swift-frontend           0x0000000100d53118 swift::mainEntry(int, char const**) + 3052
27 dyld                     0x0000000180cfc274 start + 2840
fish: Job 1, './swift -frontend -typecheck ~/…' terminated by signal SIGABRT (Abort)
@hamishknight hamishknight added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software assertion failure Bug → crash: An assertion failure labels Dec 14, 2024
Xazax-hun pushed a commit that referenced this issue Dec 16, 2024
This is not supported, of course. But now, instead of an assertion
failure we properly mark the declaration as unavailable.

Fixes #78190.

rdar://141492654
Xazax-hun pushed a commit that referenced this issue Dec 16, 2024
This is not supported, of course. But now, instead of an assertion
failure we properly mark the declaration as unavailable.

Fixes #78190.

rdar://141492654
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. c++ interop Feature: Interoperability with C++ compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants