BuryPointer.h 1.0 KB

1234567891011121314151617181920212223242526272829
  1. //===- 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. #ifndef LLVM_SUPPORT_BURYPOINTER_H
  9. #define LLVM_SUPPORT_BURYPOINTER_H
  10. #include <memory>
  11. namespace llvm {
  12. // In tools that will exit soon anyway, going through the process of explicitly
  13. // deallocating resources can be unnecessary - better to leak the resources and
  14. // let the OS clean them up when the process ends. Use this function to ensure
  15. // the memory is not misdiagnosed as an unintentional leak by leak detection
  16. // tools (this is achieved by preserving pointers to the object in a globally
  17. // visible array).
  18. void BuryPointer(const void *Ptr);
  19. template <typename T> void BuryPointer(std::unique_ptr<T> Ptr) {
  20. BuryPointer(Ptr.release());
  21. }
  22. } // namespace llvm
  23. #endif