Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang serialization unittests: fix some leaks #82773

Merged
merged 3 commits into from
Feb 26, 2024

Conversation

krasimirgg
Copy link
Contributor

No functional changes intended.

Fixes some leaks found by running under asan with --gtest_repeat=2.

No functional changes intended.

Fixes some leaks found by running under asan with --gtest_repeat=2.
@krasimirgg krasimirgg requested a review from d0k February 23, 2024 15:13
@krasimirgg krasimirgg marked this pull request as ready for review February 23, 2024 15:14
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:modules C++20 modules and Clang Header Modules labels Feb 23, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 23, 2024

@llvm/pr-subscribers-clang

Author: Krasimir Georgiev (krasimirgg)

Changes

No functional changes intended.

Fixes some leaks found by running under asan with --gtest_repeat=2.


Full diff: https://github.com/llvm/llvm-project/pull/82773.diff

2 Files Affected:

  • (modified) clang/unittests/Serialization/ModuleCacheTest.cpp (+14-4)
  • (modified) clang/unittests/Serialization/VarDeclConstantInitTest.cpp (+1)
diff --git a/clang/unittests/Serialization/ModuleCacheTest.cpp b/clang/unittests/Serialization/ModuleCacheTest.cpp
index c3e347ffec660c..76aeee60f5a435 100644
--- a/clang/unittests/Serialization/ModuleCacheTest.cpp
+++ b/clang/unittests/Serialization/ModuleCacheTest.cpp
@@ -88,6 +88,16 @@ class ModuleCacheTest : public ::testing::Test {
         }
     )cpp");
   }
+ 
+  std::unique_ptr<CompilerInvocation> createInvocationAndEnableFree(
+      ArrayRef<const char *> Args, CreateInvocationOptions Opts) {
+    std::unique_ptr<CompilerInvocation> Invocation =
+        createInvocation(Args, Opts);
+    if (Invocation)
+      Invocation->getFrontendOpts().DisableFree = false;
+
+    return Invocation;
+  }
 };
 
 TEST_F(ModuleCacheTest, CachedModuleNewPath) {
@@ -106,7 +116,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPath) {
                         MCPArg.c_str(), "-working-directory", TestDir.c_str(),
                         "test.m"};
   std::shared_ptr<CompilerInvocation> Invocation =
-      createInvocation(Args, CIOpts);
+      createInvocationAndEnableFree(Args, CIOpts);
   ASSERT_TRUE(Invocation);
   CompilerInstance Instance;
   Instance.setDiagnostics(Diags.get());
@@ -129,7 +139,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPath) {
                          "-Fframeworks",  MCPArg.c_str(), "-working-directory",
                          TestDir.c_str(), "test.m"};
   std::shared_ptr<CompilerInvocation> Invocation2 =
-      createInvocation(Args2, CIOpts);
+      createInvocationAndEnableFree(Args2, CIOpts);
   ASSERT_TRUE(Invocation2);
   CompilerInstance Instance2(Instance.getPCHContainerOperations(),
                              &Instance.getModuleCache());
@@ -156,7 +166,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPathAllowErrors) {
                         MCPArg.c_str(), "-working-directory", TestDir.c_str(),
                         "test.m"};
   std::shared_ptr<CompilerInvocation> Invocation =
-      createInvocation(Args, CIOpts);
+      createInvocationAndEnableFree(Args, CIOpts);
   ASSERT_TRUE(Invocation);
   CompilerInstance Instance;
   Instance.setDiagnostics(Diags.get());
@@ -173,7 +183,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPathAllowErrors) {
       TestDir.c_str(), "-Xclang",      "-fallow-pcm-with-compiler-errors",
       "test.m"};
   std::shared_ptr<CompilerInvocation> Invocation2 =
-      createInvocation(Args2, CIOpts);
+      createInvocationAndEnableFree(Args2, CIOpts);
   ASSERT_TRUE(Invocation2);
   CompilerInstance Instance2(Instance.getPCHContainerOperations(),
                              &Instance.getModuleCache());
diff --git a/clang/unittests/Serialization/VarDeclConstantInitTest.cpp b/clang/unittests/Serialization/VarDeclConstantInitTest.cpp
index 86ae929e7f17e4..7efa1c1d64a964 100644
--- a/clang/unittests/Serialization/VarDeclConstantInitTest.cpp
+++ b/clang/unittests/Serialization/VarDeclConstantInitTest.cpp
@@ -103,6 +103,7 @@ export namespace Fibonacci
   std::shared_ptr<CompilerInvocation> Invocation =
       createInvocation(Args, CIOpts);
   ASSERT_TRUE(Invocation);
+  Invocation->getFrontendOpts().DisableFree = false;
 
   CompilerInstance Instance;
   Instance.setDiagnostics(Diags.get());

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 23, 2024

@llvm/pr-subscribers-clang-modules

Author: Krasimir Georgiev (krasimirgg)

Changes

No functional changes intended.

Fixes some leaks found by running under asan with --gtest_repeat=2.


Full diff: https://github.com/llvm/llvm-project/pull/82773.diff

2 Files Affected:

  • (modified) clang/unittests/Serialization/ModuleCacheTest.cpp (+14-4)
  • (modified) clang/unittests/Serialization/VarDeclConstantInitTest.cpp (+1)
diff --git a/clang/unittests/Serialization/ModuleCacheTest.cpp b/clang/unittests/Serialization/ModuleCacheTest.cpp
index c3e347ffec660c..76aeee60f5a435 100644
--- a/clang/unittests/Serialization/ModuleCacheTest.cpp
+++ b/clang/unittests/Serialization/ModuleCacheTest.cpp
@@ -88,6 +88,16 @@ class ModuleCacheTest : public ::testing::Test {
         }
     )cpp");
   }
+ 
+  std::unique_ptr<CompilerInvocation> createInvocationAndEnableFree(
+      ArrayRef<const char *> Args, CreateInvocationOptions Opts) {
+    std::unique_ptr<CompilerInvocation> Invocation =
+        createInvocation(Args, Opts);
+    if (Invocation)
+      Invocation->getFrontendOpts().DisableFree = false;
+
+    return Invocation;
+  }
 };
 
 TEST_F(ModuleCacheTest, CachedModuleNewPath) {
@@ -106,7 +116,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPath) {
                         MCPArg.c_str(), "-working-directory", TestDir.c_str(),
                         "test.m"};
   std::shared_ptr<CompilerInvocation> Invocation =
-      createInvocation(Args, CIOpts);
+      createInvocationAndEnableFree(Args, CIOpts);
   ASSERT_TRUE(Invocation);
   CompilerInstance Instance;
   Instance.setDiagnostics(Diags.get());
@@ -129,7 +139,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPath) {
                          "-Fframeworks",  MCPArg.c_str(), "-working-directory",
                          TestDir.c_str(), "test.m"};
   std::shared_ptr<CompilerInvocation> Invocation2 =
-      createInvocation(Args2, CIOpts);
+      createInvocationAndEnableFree(Args2, CIOpts);
   ASSERT_TRUE(Invocation2);
   CompilerInstance Instance2(Instance.getPCHContainerOperations(),
                              &Instance.getModuleCache());
@@ -156,7 +166,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPathAllowErrors) {
                         MCPArg.c_str(), "-working-directory", TestDir.c_str(),
                         "test.m"};
   std::shared_ptr<CompilerInvocation> Invocation =
-      createInvocation(Args, CIOpts);
+      createInvocationAndEnableFree(Args, CIOpts);
   ASSERT_TRUE(Invocation);
   CompilerInstance Instance;
   Instance.setDiagnostics(Diags.get());
@@ -173,7 +183,7 @@ TEST_F(ModuleCacheTest, CachedModuleNewPathAllowErrors) {
       TestDir.c_str(), "-Xclang",      "-fallow-pcm-with-compiler-errors",
       "test.m"};
   std::shared_ptr<CompilerInvocation> Invocation2 =
-      createInvocation(Args2, CIOpts);
+      createInvocationAndEnableFree(Args2, CIOpts);
   ASSERT_TRUE(Invocation2);
   CompilerInstance Instance2(Instance.getPCHContainerOperations(),
                              &Instance.getModuleCache());
diff --git a/clang/unittests/Serialization/VarDeclConstantInitTest.cpp b/clang/unittests/Serialization/VarDeclConstantInitTest.cpp
index 86ae929e7f17e4..7efa1c1d64a964 100644
--- a/clang/unittests/Serialization/VarDeclConstantInitTest.cpp
+++ b/clang/unittests/Serialization/VarDeclConstantInitTest.cpp
@@ -103,6 +103,7 @@ export namespace Fibonacci
   std::shared_ptr<CompilerInvocation> Invocation =
       createInvocation(Args, CIOpts);
   ASSERT_TRUE(Invocation);
+  Invocation->getFrontendOpts().DisableFree = false;
 
   CompilerInstance Instance;
   Instance.setDiagnostics(Diags.get());

Copy link

github-actions bot commented Feb 23, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@krasimirgg krasimirgg merged commit b2ebd8b into llvm:main Feb 26, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants