LLVM  8.0.1
BuryPointer.cpp
Go to the documentation of this file.
1 //===- BuryPointer.cpp - Memory Manipulation/Leak ---------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/Support/Compiler.h"
12 #include <atomic>
13 
14 namespace llvm {
15 
16 void BuryPointer(const void *Ptr) {
17  // This function may be called only a small fixed amount of times per each
18  // invocation, otherwise we do actually have a leak which we want to report.
19  // If this function is called more than kGraveYardMaxSize times, the pointers
20  // will not be properly buried and a leak detector will report a leak, which
21  // is what we want in such case.
22  static const size_t kGraveYardMaxSize = 16;
23  LLVM_ATTRIBUTE_UNUSED static const void *GraveYard[kGraveYardMaxSize];
24  static std::atomic<unsigned> GraveYardSize;
25  unsigned Idx = GraveYardSize++;
26  if (Idx >= kGraveYardMaxSize)
27  return;
28  GraveYard[Idx] = Ptr;
29 }
30 
31 }
void BuryPointer(const void *Ptr)
Definition: BuryPointer.cpp:16
This class represents lattice values for constants.
Definition: AllocatorList.h:24
#define LLVM_ATTRIBUTE_UNUSED
Definition: Compiler.h:160