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

[SR-14058] Trying to coerce regular function to @convention(c) traps #56447

typesanitizer opened this issue Jan 16, 2021 · 2 comments


Copy link

typesanitizer commented Jan 16, 2021

Previous ID SR-14058
Radar rdar://problem/73274724
Original Reporter @typesanitizer
Type Sub-task
Additional Detail from JIRA
Votes 0
Labels Sub-task
Assignee None
Priority Medium

md5: 6b1c82e504bf1541b2e8303a32fbf741


  • SR-14169 ☂️ Compiler/runtime issues while converting functions with incompatible representations

relates to:

  • SR-14160 Runtime crash on passing functions with incompatible representations
  • SR-14051 [docs] Document allowed conversions between function types.

Issue Description:

I was wondering how the function subtyping works. I don't think it does.

let x : [@convention(c) () -> ()] = [ { print("Hello") }, { print("World") } ]
func callAll(_ xs: [() -> ()]) {
  for f in xs {

This crashes when compiled using recent main.

Could not cast value of type '@convention(c) () -> ()' (0x7fff88b22ba8) to '() -> ()' (0x7fff88b22d70).
PLEASE submit a bug report to and include the crash backtrace.

0  swift-frontend           0x00000001089cf245 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift-frontend           0x00000001089ce238 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x00000001089cf806 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff2053ad7d _sigtramp + 29
4  libsystem_malloc.dylib   0x00007fff20336eb7 _malloc_zone_calloc + 59
5  libsystem_c.dylib        0x00007fff20449720 abort + 120
6  libswiftCore.dylib       0x00007fff2cbeea15 swift::fatalError(unsigned int, char const*, ...) + 149
7  libswiftCore.dylib       0x00007fff2cbe6e87 swift::swift_dynamicCastFailure(void const*, char const*, void const*, char const*, char const*) + 71
8  libswiftCore.dylib       0x00007fff2cbe6efa swift::swift_dynamicCastFailure(swift::TargetMetadata<swift::InProcess> const*, swift::TargetMetadata<swift::InProcess> const*, char const*) + 106
9  libswiftCore.dylib       0x00007fff2cbe8adc swift_dynamicCastImpl(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetMetadata<swift::InProcess> const*, swift::DynamicCastFlags) + 4220
10 libswiftCore.dylib       0x00007fff2c8db5f8 $ss15_arrayForceCastySayq_GSayxGr0_lF + 616
11 libswiftCore.dylib       0x000000010b703067 $ss15_arrayForceCastySayq_GSayxGr0_lF + 18446603344255548631
12 swift-frontend           0x0000000103dfc559 llvm::orc::runAsMain(int (*)(int, char**), llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::Optional<llvm::StringRef>) + 1305

Not entirely sure if this is the compiler's fault or the runtime's fault.

Copy link

typesanitizer commented Jan 16, 2021

@swift-ci create

Copy link

airspeedswift commented Jan 24, 2021

This kind of cast isn't supported. The compiler should report this as an error though. This could be a starter bug for someone to either put a compilation error in place, or explore adding some kind of thunking to allow it to work if it'd be particularly useful (or even do the first thing, then the second).

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants