#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/Utils.h"
#include "clang/Lex/ModuleLoader.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
}
void resetAndLeakFileManager() {
+ BuryPointer(FileMgr.getPtr());
FileMgr.resetWithoutRelease();
}
}
void resetAndLeakSourceManager() {
+ BuryPointer(SourceMgr.getPtr());
SourceMgr.resetWithoutRelease();
}
}
void resetAndLeakPreprocessor() {
+ BuryPointer(PP.getPtr());
PP.resetWithoutRelease();
}
}
void resetAndLeakASTContext() {
+ BuryPointer(Context.getPtr());
Context.resetWithoutRelease();
}
return getLastArgIntValue(Args, Id, Default, &Diags);
}
+// When Clang->getFrontendOpts().DisableFree is set we don't delete some of the
+// global objects, but we don't want LeakDetectors to complain, so we bury them
+// in a globally visible array.
+void BuryPointer(const void *Ptr);
+
} // end namespace clang
#endif
#include "clang/Basic/TargetOptions.h"
#include "clang/Frontend/CodeGenOptions.h"
#include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/Utils.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Bitcode/ReaderWriter.h"
delete PerModulePasses;
delete PerFunctionPasses;
if (CodeGenOpts.DisableFree)
- TM.take();
+ BuryPointer(TM.take());
}
llvm::OwningPtr<TargetMachine> TM;
#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"
}
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;
+}
}
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "clang/Frontend/LayoutOverrideSource.h"
+#include "clang/Frontend/Utils.h"
#include "clang/Frontend/MultiplexConsumer.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Preprocessor.h"
//
// FIXME: There is more per-file stuff we could just drop here?
if (CI.getFrontendOpts().DisableFree) {
- CI.takeASTConsumer();
+ BuryPointer(CI.takeASTConsumer());
if (!isCurrentFileAST()) {
- CI.takeSema();
+ BuryPointer(CI.takeSema());
CI.resetAndLeakASTContext();
}
} else {
#include "clang/Frontend/FrontendActions.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
+#include "clang/Frontend/Utils.h"
#include "clang/Rewrite/Frontend/FrontendActions.h"
#include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
#include "llvm/Option/OptTable.h"
return false;
bool Success = Clang->ExecuteAction(*Act);
if (Clang->getFrontendOpts().DisableFree)
- Act.take();
+ BuryPointer(Act.take());
return Success;
}
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/TextDiagnosticBuffer.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Frontend/Utils.h"
#include "clang/FrontendTool/Utils.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/LinkAllPasses.h"
if (Clang->getFrontendOpts().DisableFree) {
if (llvm::AreStatisticsEnabled() || Clang->getFrontendOpts().ShowStats)
llvm::PrintStatistics();
- Clang.take();
+ BuryPointer(Clang.take());
return !Success;
}