Skip to content

Commit b11b897

Browse files
authored
Merge pull request #64493 from hyp/eng/destructor-delete-irgen
[interop] ensure IRGen reaches code referenced through destructor inv…
2 parents 78996db + 7320cd8 commit b11b897

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

lib/IRGen/GenClangDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class ClangDeclFinder
6767
return true;
6868
}
6969

70+
bool VisitCXXDeleteExpr(clang::CXXDeleteExpr *deleteExpr) {
71+
if (auto cxxRecord = deleteExpr->getDestroyedType()->getAsCXXRecordDecl())
72+
if (auto dtor = cxxRecord->getDestructor())
73+
callback(dtor);
74+
return true;
75+
}
76+
7077
bool VisitVarDecl(clang::VarDecl *VD) {
7178
if (auto cxxRecord = VD->getType()->getAsCXXRecordDecl())
7279
if (auto dtor = cxxRecord->getDestructor())
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: %target-swiftxx-frontend -emit-ir -I %t/Inputs -validate-tbd-against-ir=none %t/test.swift | %FileCheck %s
4+
5+
//--- Inputs/module.modulemap
6+
module DestroyedUsingDelete {
7+
header "test.h"
8+
requires cplusplus
9+
}
10+
//--- Inputs/test.h
11+
12+
extern void referencedSymbol();
13+
inline void emittedIntoSwiftObject() { referencedSymbol(); }
14+
15+
class BaseClass {
16+
public:
17+
inline ~BaseClass() {
18+
emittedIntoSwiftObject();
19+
}
20+
21+
int x;
22+
};
23+
24+
class Container {
25+
public:
26+
Container() : pointer(new BaseClass) {}
27+
~Container() { delete pointer; }
28+
29+
inline int method() const {
30+
return 42;
31+
}
32+
private:
33+
BaseClass *pointer;
34+
};
35+
36+
37+
//--- test.swift
38+
39+
import DestroyedUsingDelete
40+
41+
public func test() {
42+
let i = Container()
43+
i.method()
44+
}
45+
46+
// Make sure we reach destructor accessible from `delete` statement.
47+
48+
// CHECK: define linkonce_odr{{( dso_local)?}} void @{{_Z22emittedIntoSwiftObjectv|"\?emittedIntoSwiftObject@@YAXXZ"}}

0 commit comments

Comments
 (0)