blob: 276a5b7089c3e7e89327f5efa4ce70097ba8f238 [file] [log] [blame]
Andrew Walbran16937d02019-10-22 13:54:20 +01001//===- llvm/Support/BuryPointer.h - Memory Manipulation/Leak ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_SUPPORT_BURYPOINTER_H
10#define LLVM_SUPPORT_BURYPOINTER_H
11
12#include <memory>
13
14namespace llvm {
15
16// In tools that will exit soon anyway, going through the process of explicitly
17// deallocating resources can be unnecessary - better to leak the resources and
18// let the OS clean them up when the process ends. Use this function to ensure
19// the memory is not misdiagnosed as an unintentional leak by leak detection
20// tools (this is achieved by preserving pointers to the object in a globally
21// visible array).
22void BuryPointer(const void *Ptr);
23template <typename T> void BuryPointer(std::unique_ptr<T> Ptr) {
24 BuryPointer(Ptr.release());
25}
26
27} // namespace llvm
28
29#endif