Files
swift-mirror/test/Interop/Cxx/class/delete-operator-destructor-ref-irgen.swift
Alex Lorenz 96806f4d44 [cxx-interop] Windows: unify address-only logic and mark non-trivial loadable C++ types as unavailable
Windows logic for determining address-only type layout for a C++ type is now unified with other platforms.
However, this means that on Windows, a C++ type with a custom destructor, but a default copy constructor
is now loadable, even though it's non-trivial. Since Swift does not support such type operations at the
moment (it can't be yet destroyed), mark such type as unavailable in Swift instead, when building for
the Windows target.

This fixes the Windows miscompilation related to such types when they were passed indirectly to C++
functions even though they're actually passed directly.
2023-07-20 14:58:02 -07:00

74 lines
1.5 KiB
Swift

// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: %target-swiftxx-frontend -emit-ir -I %t/Inputs -validate-tbd-against-ir=none %t/test.swift | %FileCheck %s
//--- Inputs/module.modulemap
module DestroyedUsingDelete {
header "test.h"
requires cplusplus
}
//--- Inputs/test.h
extern void referencedSymbol();
inline void emittedIntoSwiftObject() { referencedSymbol(); }
class BaseClass {
public:
inline ~BaseClass() {
emittedIntoSwiftObject();
}
int x;
};
class Container {
public:
Container() : pointer(new BaseClass) {}
Container(const Container &other) : pointer(new BaseClass) {}
~Container() { delete pointer; }
inline int method() const {
return 42;
}
private:
BaseClass *pointer;
};
class ForwardClassDecl;
template<class T>
class ContainerWithForward {
public:
inline ~ContainerWithForward() {
if (sizeof(T) > 0)
referencedSymbol();
}
};
class ClassWithOutOfLineDestructor {
public:
~ClassWithOutOfLineDestructor();
ContainerWithForward<ForwardClassDecl> field;
};
ClassWithOutOfLineDestructor *getClassWithOutOfLineDestructorValue();
inline void testMethodDestructorFwdDecl() {
delete getClassWithOutOfLineDestructorValue();
}
//--- test.swift
import DestroyedUsingDelete
public func test() {
let i = Container()
i.method()
testMethodDestructorFwdDecl()
}
// Make sure we reach destructor accessible from `delete` statement.
// CHECK: define linkonce_odr{{( dso_local)?}} void @{{_Z22emittedIntoSwiftObjectv|"\?emittedIntoSwiftObject@@YAXXZ"}}