Skip to content

Commit 6bd68cf

Browse files
authored
Merge pull request #227 from hewj03/ocl-open-80
[80] Extend llvm_shutdown to fix ManagedStatic memleak
2 parents 33cb76d + dd8e52d commit 6bd68cf

File tree

4 files changed

+31
-52
lines changed

4 files changed

+31
-52
lines changed

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ if(NOT USE_PREBUILT_LLVM)
9393
${LLVM_BASE_REVISION}
9494
${TARGET_BRANCH}
9595
ret)
96-
if(${ret})
97-
add_definitions(-DAPPLIED_LLVM_PATCHES)
98-
endif()
9996
apply_patches(${CLANG_SOURCE_DIR}
10097
${CMAKE_CURRENT_SOURCE_DIR}/patches/clang
10198
${CLANG_BASE_REVISION}

common_clang.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ static llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;
8989

9090
void CommonClangTerminate() {
9191
llvm::llvm_shutdown();
92-
#ifdef APPLIED_LLVM_PATCHES
93-
llvm::deleteManagedStaticMutex();
94-
#endif
9592
}
9693

9794
// This function mustn't be invoked from a static object constructor,

patches/llvm/0001-Adding-llvm-deleteManagedStaticMutex.patch

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
From fac953a33d6c8fbfc166373d0c50f414b7228245 Mon Sep 17 00:00:00 2001
2+
From: juanrod2 <>
3+
Date: Tue, 22 Dec 2020 08:50:05 +0800
4+
Subject: [PATCH] Memory leak fix for Managed Static Mutex
5+
6+
Cleaning a mutex inside ManagedStatic llvm class.
7+
---
8+
lib/Support/ManagedStatic.cpp | 6 +++++-
9+
1 file changed, 5 insertions(+), 1 deletion(-)
10+
11+
diff --git a/lib/Support/ManagedStatic.cpp b/lib/Support/ManagedStatic.cpp
12+
index 74f71a38502..a9e393ec49b 100644
13+
--- a/lib/Support/ManagedStatic.cpp
14+
+++ b/lib/Support/ManagedStatic.cpp
15+
@@ -78,8 +78,12 @@ void ManagedStaticBase::destroy() const {
16+
17+
/// llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
18+
void llvm::llvm_shutdown() {
19+
- MutexGuard Lock(*getManagedStaticMutex());
20+
+ getManagedStaticMutex()->lock();
21+
22+
while (StaticList)
23+
StaticList->destroy();
24+
+
25+
+ getManagedStaticMutex()->unlock();
26+
+ delete ManagedStaticMutex;
27+
+ ManagedStaticMutex = nullptr;
28+
}
29+
--
30+
2.29.2
31+

0 commit comments

Comments
 (0)