Skip to content

Commit 76f0b17

Browse files
authored
Merge pull request #228 from hewj03/ocl-open-90
[90] Extend llvm_shutdown to fix ManagedStatic memleak, Fix llvm clone directory
2 parents 942b9eb + 3c6a948 commit 76f0b17

File tree

5 files changed

+32
-53
lines changed

5 files changed

+32
-53
lines changed

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ if(NOT USE_PREBUILT_LLVM)
132132
${LLVM_BASE_REVISION}
133133
${TARGET_BRANCH}
134134
ret)
135-
if(${ret})
136-
add_definitions(-DAPPLIED_LLVM_PATCHES)
137-
endif()
138135
apply_patches(${SPIRV_SOURCE_DIR}
139136
${CMAKE_CURRENT_SOURCE_DIR}/patches/spirv
140137
${SPIRV_BASE_REVISION}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ following:
2626
This can be done using the following commands:
2727
```
2828
cd <workspace>
29-
git clone https://github.com/llvm/llvm-project.git -b release/9.x
29+
git clone https://github.com/llvm/llvm-project.git . -b release/9.x
3030
git clone https://github.com/KhronosGroup/SPIRV-LLVM-Translator.git -b llvm_release_90
3131
git clone https://github.com/intel/opencl-clang.git -b ocl-open-90
3232
```

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 22377f4221d77c66cddf0df535609408317563b2 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+
llvm/lib/Support/ManagedStatic.cpp | 6 +++++-
9+
1 file changed, 5 insertions(+), 1 deletion(-)
10+
11+
diff --git a/llvm/lib/Support/ManagedStatic.cpp b/llvm/lib/Support/ManagedStatic.cpp
12+
index 28ceb1a70e4..9579000955e 100644
13+
--- a/llvm/lib/Support/ManagedStatic.cpp
14+
+++ b/llvm/lib/Support/ManagedStatic.cpp
15+
@@ -77,8 +77,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)