Skip to content

Commit b2ebd8b

Browse files
authored
clang serialization unittests: fix some leaks (#82773)
No functional changes intended. Fixes some leaks found by running under asan with `--gtest_repeat=2`.
1 parent 2730a5c commit b2ebd8b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

clang/unittests/Serialization/ModuleCacheTest.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ class ModuleCacheTest : public ::testing::Test {
8888
}
8989
)cpp");
9090
}
91+
92+
std::unique_ptr<CompilerInvocation>
93+
createInvocationAndEnableFree(ArrayRef<const char *> Args,
94+
CreateInvocationOptions Opts) {
95+
std::unique_ptr<CompilerInvocation> Invocation =
96+
createInvocation(Args, Opts);
97+
if (Invocation)
98+
Invocation->getFrontendOpts().DisableFree = false;
99+
100+
return Invocation;
101+
}
91102
};
92103

93104
TEST_F(ModuleCacheTest, CachedModuleNewPath) {
@@ -106,7 +117,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPath) {
106117
MCPArg.c_str(), "-working-directory", TestDir.c_str(),
107118
"test.m"};
108119
std::shared_ptr<CompilerInvocation> Invocation =
109-
createInvocation(Args, CIOpts);
120+
createInvocationAndEnableFree(Args, CIOpts);
110121
ASSERT_TRUE(Invocation);
111122
CompilerInstance Instance;
112123
Instance.setDiagnostics(Diags.get());
@@ -129,7 +140,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPath) {
129140
"-Fframeworks", MCPArg.c_str(), "-working-directory",
130141
TestDir.c_str(), "test.m"};
131142
std::shared_ptr<CompilerInvocation> Invocation2 =
132-
createInvocation(Args2, CIOpts);
143+
createInvocationAndEnableFree(Args2, CIOpts);
133144
ASSERT_TRUE(Invocation2);
134145
CompilerInstance Instance2(Instance.getPCHContainerOperations(),
135146
&Instance.getModuleCache());
@@ -156,7 +167,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPathAllowErrors) {
156167
MCPArg.c_str(), "-working-directory", TestDir.c_str(),
157168
"test.m"};
158169
std::shared_ptr<CompilerInvocation> Invocation =
159-
createInvocation(Args, CIOpts);
170+
createInvocationAndEnableFree(Args, CIOpts);
160171
ASSERT_TRUE(Invocation);
161172
CompilerInstance Instance;
162173
Instance.setDiagnostics(Diags.get());
@@ -173,7 +184,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPathAllowErrors) {
173184
TestDir.c_str(), "-Xclang", "-fallow-pcm-with-compiler-errors",
174185
"test.m"};
175186
std::shared_ptr<CompilerInvocation> Invocation2 =
176-
createInvocation(Args2, CIOpts);
187+
createInvocationAndEnableFree(Args2, CIOpts);
177188
ASSERT_TRUE(Invocation2);
178189
CompilerInstance Instance2(Instance.getPCHContainerOperations(),
179190
&Instance.getModuleCache());

clang/unittests/Serialization/VarDeclConstantInitTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export namespace Fibonacci
103103
std::shared_ptr<CompilerInvocation> Invocation =
104104
createInvocation(Args, CIOpts);
105105
ASSERT_TRUE(Invocation);
106+
Invocation->getFrontendOpts().DisableFree = false;
106107

107108
CompilerInstance Instance;
108109
Instance.setDiagnostics(Diags.get());

0 commit comments

Comments
 (0)