diff options
author | Kostya Serebryany <kcc@google.com> | 2013-12-27 08:11:08 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2013-12-27 08:11:08 +0000 |
commit | ce2c726e99b4fde2f6adff6772e8fa6396b9f332 (patch) | |
tree | 19d05e1f2cd84a70d98c1b170f1d5f475329c28e /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | e6ed0f255f0e5a7ace2ad5501e7ddf924f03a550 (diff) | |
download | bcm5719-llvm-ce2c726e99b4fde2f6adff6772e8fa6396b9f332.tar.gz bcm5719-llvm-ce2c726e99b4fde2f6adff6772e8fa6396b9f332.zip |
Bury leaked pointers in a global array to silence a leak detector in --disable-free mode
Summary:
This is an alternative to http://llvm-reviews.chandlerc.com/D2475
suggested by Chandler.
Reviewers: chandlerc, rnk, dblaikie
CC: cfe-commits, earthdok
Differential Revision: http://llvm-reviews.chandlerc.com/D2478
llvm-svn: 198073
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 71e6b74d38b..78a88f65f6b 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -28,6 +28,7 @@ #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" +#include "llvm/Support/Atomic.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" @@ -1827,4 +1828,19 @@ int getLastArgIntValue(const ArgList &Args, OptSpecifier Id, int Default, } return Res; } + +void BuryPointer(const void *Ptr) { + // This function may be called only a small fixed amount of times per each + // invocation, otherwise we do actually have a leak which we want to report. + // If this function is called more than kGraveYardMaxSize times, the pointers + // will not be properly buried and a leak detector will report a leak, which + // is what we want in such case. + static const size_t kGraveYardMaxSize = 16; + static const void *GraveYard[kGraveYardMaxSize]; + static llvm::sys::cas_flag GraveYardSize; + llvm::sys::cas_flag Idx = llvm::sys::AtomicIncrement(&GraveYardSize) - 1; + if (Idx >= kGraveYardMaxSize) + return; + GraveYard[Idx] = Ptr; +} } |