[C++-Interop] Missing a matching ObjC ARC retain for C++ Copy Constructor to match C++ Destructor #59735
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
c++ interop
Feature: Interoperability with C++
Description
Case is where there is a C++ type that contains an ARC type such as an ObjC Block where the type is passed across the Swift/C++ language boundary by value. The default copy constructor generation needed to facilitate this doesn't seem to account for the ARC retain in the cctor but in the dtor there is an ARC release. The he ObjC release in the callee functions as a double free. I have attached sanitized IR comparing the pass by const ref and pass by value case to this issue as well.
There is a repro project at https://github.com/plotfi/cxx-interop-test/tree/_Block_copy that covers this repro as well.
Reproducer
C++ Header (CXX.h)
module.modulemap
Swift (main.swift)
Repro
Copy above files CXX.h, module.modulemap and main.swift respectively into a test directory, cd into that directory and run:
Expected
IR.zip
Actual
Mitigation
For now I see a mitigation as either implementing a manual copy constructor or passing by const ref. Without this the ObjC release in the callee functions as a double free.
The text was updated successfully, but these errors were encountered: