summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2018-11-17 18:03:47 +0000
committerDavid Blaikie <dblaikie@gmail.com>2018-11-17 18:03:47 +0000
commitef543381ed713c1dce381d064812194bf3ae8e6b (patch)
tree3bf208cdece9575857aafbf09575f30acb23186e /llvm/lib/Support
parent0e1a9d5ee6747d4c8b91b74d5956f63adbc69916 (diff)
downloadbcm5719-llvm-ef543381ed713c1dce381d064812194bf3ae8e6b.tar.gz
bcm5719-llvm-ef543381ed713c1dce381d064812194bf3ae8e6b.zip
Move BuryPointer from Clang to LLVM for use in other LLVM tools
Specifically planning to use this in llvm-symbolizer to remove the cost of cleanup there. llvm-svn: 347140
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/BuryPointer.cpp31
-rw-r--r--llvm/lib/Support/CMakeLists.txt1
2 files changed, 32 insertions, 0 deletions
diff --git a/llvm/lib/Support/BuryPointer.cpp b/llvm/lib/Support/BuryPointer.cpp
new file mode 100644
index 00000000000..6c988b4a0ab
--- /dev/null
+++ b/llvm/lib/Support/BuryPointer.cpp
@@ -0,0 +1,31 @@
+//===- BuryPointer.cpp - Memory Manipulation/Leak ---------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/BuryPointer.h"
+#include "llvm/Support/Compiler.h"
+#include <atomic>
+
+namespace llvm {
+
+void BuryPointer(const void *Ptr) {
+ // This function may be called only a small fixed amount of times per each
+ // invocation, otherwise we do actually have a leak which we want to report.
+ // If this function is called more than kGraveYardMaxSize times, the pointers
+ // will not be properly buried and a leak detector will report a leak, which
+ // is what we want in such case.
+ static const size_t kGraveYardMaxSize = 16;
+ LLVM_ATTRIBUTE_UNUSED static const void *GraveYard[kGraveYardMaxSize];
+ static std::atomic<unsigned> GraveYardSize;
+ unsigned Idx = GraveYardSize++;
+ if (Idx >= kGraveYardMaxSize)
+ return;
+ GraveYard[Idx] = Ptr;
+}
+
+}
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 1446359f0cf..96d7f7c54b0 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -59,6 +59,7 @@ add_llvm_library(LLVMSupport
BinaryStreamWriter.cpp
BlockFrequency.cpp
BranchProbability.cpp
+ BuryPointer.cpp
CachePruning.cpp
circular_raw_ostream.cpp
Chrono.cpp
OpenPOWER on IntegriCloud