Skip to content

Windows, FreeBSD: the pointer passed to _swift_willThrow cannot be weakly referenced #62985

Open
@grynspan

Description

@grynspan

Description
On Windows, the pointer passed to _swift_willThrow does not appear to be a valid heap object, and attempting to weakly reference it causes a crash.

Steps to reproduce
Implement a program that sets the _swift_willThrow hook to a function like so:

struct S {
  weak var error: AnyObject
}

func swiftWillThrowHandler(_ errorAddress: UnsafeMutableRawPointer) {
  let errorObject = unsafeBitCast(errorAddress, to: AnyObject.self)
  var s = S()
  s.error = errorObject // crash
}

Expected behavior
As on Darwin/Linux, this pointer should be safe to bitcast to an object and then weakly reference.

Environment

  • Swift compiler version info compnerd.org Swift version 5.8-dev (LLVM ab856b0fa3177ee, Swift 71c62c0)
  • Deployment target: x86_64-unknown-windows-msvc

Metadata

Metadata

Assignees

Labels

FreeBSDPlatform: FreeBSDWindowsPlatform: WindowsbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.error handling

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions