LLVM  14.0.0git
BuryPointer.cpp
Go to the documentation of this file.
1 //===- BuryPointer.cpp - 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 
10 #include "llvm/Support/Compiler.h"
11 #include <atomic>
12 
13 namespace llvm {
14 
15 void BuryPointer(const void *Ptr) {
16  // This function may be called only a small fixed amount of times per each
17  // invocation, otherwise we do actually have a leak which we want to report.
18  // If this function is called more than kGraveYardMaxSize times, the pointers
19  // will not be properly buried and a leak detector will report a leak, which
20  // is what we want in such case.
21  static const size_t kGraveYardMaxSize = 16;
22  LLVM_ATTRIBUTE_USED static const void *GraveYard[kGraveYardMaxSize];
23  static std::atomic<unsigned> GraveYardSize;
24  unsigned Idx = GraveYardSize++;
25  if (Idx >= kGraveYardMaxSize)
26  return;
27  GraveYard[Idx] = Ptr;
28 }
29 
30 } // namespace llvm
LLVM_ATTRIBUTE_USED
#define LLVM_ATTRIBUTE_USED
Definition: Compiler.h:144
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
Compiler.h
llvm::BuryPointer
void BuryPointer(const void *Ptr)
Definition: BuryPointer.cpp:15
BuryPointer.h