Skip to content

Commit 96ee4eb

Browse files
Merge pull request #69871 from nate-chandler/rdar118134637
[Test] Avoid LSAN report of leaked FunctionTest.
2 parents c768d36 + 73d57c9 commit 96ee4eb

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

include/swift/SIL/Test.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ class FunctionTest final {
151151
/// } // end namespace swift::test
152152
FunctionTest(StringRef name, Invocation invocation);
153153

154-
FunctionTest(StringRef name, NativeSwiftInvocation invocation);
154+
/// Creates a test that will run \p invocation and stores it in the global
155+
/// registry.
156+
static void createNativeSwiftFunctionTest(StringRef name,
157+
NativeSwiftInvocation invocation);
155158

156159
/// Computes and returns the function's dominance tree.
157160
DominanceInfo *getDominanceInfo();
@@ -254,6 +257,11 @@ class FunctionTest final {
254257
/// The vendor for dependencies provided to the test by TestRunner. Only
255258
/// non-null when FunctionTest::run is executing.
256259
Dependencies *dependencies;
260+
261+
public:
262+
/// Creates a test that will run \p invocation. For use by
263+
/// createNativeSwiftFunctionTest.
264+
FunctionTest(StringRef name, NativeSwiftInvocation invocation);
257265
};
258266

259267
/// Thunks for delaying template instantiation.

lib/SIL/Utils/SILBridging.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ void registerBridgedClass(BridgedStringRef bridgedClassName, SwiftMetatype metat
145145
//===----------------------------------------------------------------------===//
146146

147147
void registerFunctionTest(BridgedStringRef name, void *nativeSwiftInvocation) {
148-
new swift::test::FunctionTest(name.unbridged(), nativeSwiftInvocation);
148+
swift::test::FunctionTest::createNativeSwiftFunctionTest(
149+
name.unbridged(), nativeSwiftInvocation);
149150
}
150151

151152
bool BridgedTestArguments::hasUntaken() const {

lib/SIL/Utils/Test.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,14 @@ FunctionTest::FunctionTest(StringRef name, Invocation invocation)
8080
}
8181
FunctionTest::FunctionTest(StringRef name, NativeSwiftInvocation invocation)
8282
: invocation(invocation), pass(nullptr), function(nullptr),
83-
dependencies(nullptr) {
84-
Registry::get().registerFunctionTest(this, name);
83+
dependencies(nullptr) {}
84+
85+
void FunctionTest::createNativeSwiftFunctionTest(
86+
StringRef name, NativeSwiftInvocation invocation) {
87+
/// Statically allocate the tests to avoid triggering LSAN's "leak" detection.
88+
static SmallVector<FunctionTest, 4> tests;
89+
auto &test = tests.emplace_back(name, invocation);
90+
Registry::get().registerFunctionTest(&test, name);
8591
}
8692

8793
FunctionTest *FunctionTest::get(StringRef name) {

0 commit comments

Comments
 (0)