From 680b6c0b6a7d21cf09da1b8aa4afff793f87d2cf Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 29 Aug 2014 16:53:14 +0000 Subject: [PATCH] Provide a BuryPointer for unique_ptrs. In theory, it'd be nice if we could move to a case where all buried pointers were buried via unique_ptr to demonstrate that the program had finished with the value (that we could really have cleanly deallocated it) but instead chose to bury it. I think the main reason that's not possible right now is the various IntrusiveRefCntPtrs in the Frontend, sharing ownership for a variety of compiler bits (see the various similar "CompilerInstance::releaseAndLeak*" functions). I have yet to figure out their correct ownership semantics - but perhaps, even if the intrusiveness can be removed, the shared ownership may yet remain and that would lead to a non-unique burying as is there today. (though we could model that a little better - by passing in a shared_ptr, etc - rather than needing the two step that's currently used in those other releaseAndLeak* functions) This might be a bit more robust if BuryPointer took the boolean: BuryPointer(bool, unique_ptr) and the choice to bury was made internally - that way, even when DisableFree was not set, the unique_ptr would still be null in the caller and there'd be no chance of accidentally having a different codepath where the value is used after burial in !DisableFree, but it becomes null only in DisableFree, etc... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216742 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/CompilerInstance.h | 2 +- include/clang/Frontend/Utils.h | 3 +++ lib/CodeGen/BackendUtil.cpp | 2 +- lib/Frontend/CompilerInstance.cpp | 1 + lib/FrontendTool/ExecuteCompilerInvocation.cpp | 2 +- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index c6fa16226b..40e3069e66 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -461,7 +461,7 @@ public: } std::unique_ptr takeSema(); - void resetAndLeakSema() { BuryPointer(TheSema.release()); } + void resetAndLeakSema(); /// } /// @name Module Management diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h index 4c0a7b7a9c..ce1c9834c5 100644 --- a/include/clang/Frontend/Utils.h +++ b/include/clang/Frontend/Utils.h @@ -206,6 +206,9 @@ inline uint64_t getLastArgUInt64Value(const llvm::opt::ArgList &Args, // 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 void BuryPointer(std::unique_ptr Ptr) { + BuryPointer(Ptr.release()); +} } // end namespace clang diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 8829680314..4a8a1b331e 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -122,7 +122,7 @@ public: delete PerModulePasses; delete PerFunctionPasses; if (CodeGenOpts.DisableFree) - BuryPointer(TM.release()); + BuryPointer(std::move(TM)); } std::unique_ptr TM; diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 513a43c140..3d1a18e276 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -1605,3 +1605,4 @@ CompilerInstance::lookupMissingImports(StringRef Name, return false; } +void CompilerInstance::resetAndLeakSema() { BuryPointer(takeSema()); } diff --git a/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/lib/FrontendTool/ExecuteCompilerInvocation.cpp index de864f6535..79cf0049a7 100644 --- a/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -221,6 +221,6 @@ bool clang::ExecuteCompilerInvocation(CompilerInstance *Clang) { return false; bool Success = Clang->ExecuteAction(*Act); if (Clang->getFrontendOpts().DisableFree) - BuryPointer(Act.release()); + BuryPointer(std::move(Act)); return Success; } -- 2.40.0