Path: blob/main/contrib/llvm-project/llvm/lib/Support/BuryPointer.cpp
35234 views
//===- BuryPointer.cpp - Memory Manipulation/Leak ---------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/Support/BuryPointer.h"9#include "llvm/Support/Compiler.h"10#include <atomic>1112namespace llvm {1314void BuryPointer(const void *Ptr) {15// This function may be called only a small fixed amount of times per each16// invocation, otherwise we do actually have a leak which we want to report.17// If this function is called more than kGraveYardMaxSize times, the pointers18// will not be properly buried and a leak detector will report a leak, which19// is what we want in such case.20static const size_t kGraveYardMaxSize = 16;21LLVM_ATTRIBUTE_USED static const void *GraveYard[kGraveYardMaxSize];22static std::atomic<unsigned> GraveYardSize;23unsigned Idx = GraveYardSize++;24if (Idx >= kGraveYardMaxSize)25return;26GraveYard[Idx] = Ptr;27}2829} // namespace llvm303132