Author: dblaikie Date: Sat Nov 17 10:04:13 2018 New Revision: 347141 URL: http://llvm.org/viewvc/llvm-project?rev=347141&view=rev Log: Sink BuryPointer from Clang into LLVM for reuse there
Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h cfe/trunk/include/clang/Frontend/Utils.h cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/lib/Frontend/CompilerInstance.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/lib/Frontend/FrontendAction.cpp cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp cfe/trunk/tools/driver/cc1_main.cpp Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=347141&r1=347140&r2=347141&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original) +++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Sat Nov 17 10:04:13 2018 @@ -22,6 +22,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/BuryPointer.h" #include <cassert> #include <list> #include <memory> @@ -411,7 +412,7 @@ public: } void resetAndLeakFileManager() { - BuryPointer(FileMgr.get()); + llvm::BuryPointer(FileMgr.get()); FileMgr.resetWithoutRelease(); } @@ -431,7 +432,7 @@ public: } void resetAndLeakSourceManager() { - BuryPointer(SourceMgr.get()); + llvm::BuryPointer(SourceMgr.get()); SourceMgr.resetWithoutRelease(); } @@ -453,7 +454,7 @@ public: std::shared_ptr<Preprocessor> getPreprocessorPtr() { return PP; } void resetAndLeakPreprocessor() { - BuryPointer(new std::shared_ptr<Preprocessor>(PP)); + llvm::BuryPointer(new std::shared_ptr<Preprocessor>(PP)); } /// Replace the current preprocessor. @@ -471,7 +472,7 @@ public: } void resetAndLeakASTContext() { - BuryPointer(Context.get()); + llvm::BuryPointer(Context.get()); Context.resetWithoutRelease(); } Modified: cfe/trunk/include/clang/Frontend/Utils.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/Utils.h?rev=347141&r1=347140&r2=347141&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/Utils.h (original) +++ cfe/trunk/include/clang/Frontend/Utils.h Sat Nov 17 10:04:13 2018 @@ -226,14 +226,6 @@ inline uint64_t getLastArgUInt64Value(co return getLastArgUInt64Value(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); -template <typename T> void BuryPointer(std::unique_ptr<T> Ptr) { - BuryPointer(Ptr.release()); -} - // Frontend timing utils /// If the user specifies the -ftime-report argument on an Clang command line Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=347141&r1=347140&r2=347141&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original) +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Sat Nov 17 10:04:13 2018 @@ -37,6 +37,7 @@ #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/SubtargetFeature.h" #include "llvm/Passes/PassBuilder.h" +#include "llvm/Support/BuryPointer.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PrettyStackTrace.h" Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=347141&r1=347140&r2=347141&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Sat Nov 17 10:04:13 2018 @@ -38,6 +38,7 @@ #include "clang/Serialization/ASTReader.h" #include "clang/Serialization/GlobalModuleIndex.h" #include "llvm/ADT/Statistic.h" +#include "llvm/Support/BuryPointer.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/Errc.h" #include "llvm/Support/FileSystem.h" @@ -2132,7 +2133,7 @@ CompilerInstance::lookupMissingImports(S return false; } -void CompilerInstance::resetAndLeakSema() { BuryPointer(takeSema()); } +void CompilerInstance::resetAndLeakSema() { llvm::BuryPointer(takeSema()); } void CompilerInstance::setExternalSemaSource( IntrusiveRefCntPtr<ExternalSemaSource> ESS) { Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=347141&r1=347140&r2=347141&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Sat Nov 17 10:04:13 2018 @@ -3299,21 +3299,6 @@ uint64_t getLastArgUInt64Value(const Arg return getLastArgIntValueImpl<uint64_t>(Args, Id, Default, Diags); } -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; - LLVM_ATTRIBUTE_UNUSED static const void *GraveYard[kGraveYardMaxSize]; - static std::atomic<unsigned> GraveYardSize; - unsigned Idx = GraveYardSize++; - if (Idx >= kGraveYardMaxSize) - return; - GraveYard[Idx] = Ptr; -} - IntrusiveRefCntPtr<llvm::vfs::FileSystem> createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags) { Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=347141&r1=347140&r2=347141&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/FrontendAction.cpp (original) +++ cfe/trunk/lib/Frontend/FrontendAction.cpp Sat Nov 17 10:04:13 2018 @@ -26,6 +26,7 @@ #include "clang/Serialization/ASTDeserializationListener.h" #include "clang/Serialization/ASTReader.h" #include "clang/Serialization/GlobalModuleIndex.h" +#include "llvm/Support/BuryPointer.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" @@ -949,7 +950,7 @@ void FrontendAction::EndSourceFile() { if (DisableFree) { CI.resetAndLeakSema(); CI.resetAndLeakASTContext(); - BuryPointer(CI.takeASTConsumer().get()); + llvm::BuryPointer(CI.takeASTConsumer().get()); } else { CI.setSema(nullptr); CI.setASTContext(nullptr); @@ -974,7 +975,7 @@ void FrontendAction::EndSourceFile() { CI.resetAndLeakPreprocessor(); CI.resetAndLeakSourceManager(); CI.resetAndLeakFileManager(); - BuryPointer(CurrentASTUnit.release()); + llvm::BuryPointer(std::move(CurrentASTUnit)); } else { CI.setPreprocessor(nullptr); CI.setSourceManager(nullptr); Modified: cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp?rev=347141&r1=347140&r2=347141&view=diff ============================================================================== --- cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp (original) +++ cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp Sat Nov 17 10:04:13 2018 @@ -12,7 +12,6 @@ // //===----------------------------------------------------------------------===// -#include "clang/FrontendTool/Utils.h" #include "clang/ARCMigrate/ARCMTActions.h" #include "clang/CodeGen/CodeGenAction.h" #include "clang/Config/config.h" @@ -23,10 +22,12 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/FrontendPluginRegistry.h" #include "clang/Frontend/Utils.h" +#include "clang/FrontendTool/Utils.h" #include "clang/Rewrite/Frontend/FrontendActions.h" #include "clang/StaticAnalyzer/Frontend/FrontendActions.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" +#include "llvm/Support/BuryPointer.h" #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/ErrorHandling.h" using namespace clang; @@ -265,7 +266,7 @@ bool ExecuteCompilerInvocation(CompilerI return false; bool Success = Clang->ExecuteAction(*Act); if (Clang->getFrontendOpts().DisableFree) - BuryPointer(std::move(Act)); + llvm::BuryPointer(std::move(Act)); return Success; } Modified: cfe/trunk/tools/driver/cc1_main.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=347141&r1=347140&r2=347141&view=diff ============================================================================== --- cfe/trunk/tools/driver/cc1_main.cpp (original) +++ cfe/trunk/tools/driver/cc1_main.cpp Sat Nov 17 10:04:13 2018 @@ -13,10 +13,9 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Option/Arg.h" +#include "clang/Basic/Stack.h" #include "clang/CodeGen/ObjectFilePCHContainerOperations.h" #include "clang/Config/config.h" -#include "clang/Basic/Stack.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "clang/Frontend/CompilerInstance.h" @@ -29,8 +28,10 @@ #include "llvm/ADT/Statistic.h" #include "llvm/Config/llvm-config.h" #include "llvm/LinkAllPasses.h" +#include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" +#include "llvm/Support/BuryPointer.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" @@ -228,7 +229,7 @@ int cc1_main(ArrayRef<const char *> Argv // When running with -disable-free, don't do any destruction or shutdown. if (Clang->getFrontendOpts().DisableFree) { - BuryPointer(std::move(Clang)); + llvm::BuryPointer(std::move(Clang)); return !Success; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits