]> granicus.if.org Git - clang/commitdiff
Provide a BuryPointer for unique_ptrs.
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 29 Aug 2014 16:53:14 +0000 (16:53 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 29 Aug 2014 16:53:14 +0000 (16:53 +0000)
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<T>)

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
include/clang/Frontend/Utils.h
lib/CodeGen/BackendUtil.cpp
lib/Frontend/CompilerInstance.cpp
lib/FrontendTool/ExecuteCompilerInvocation.cpp

index c6fa16226be72ee6134c73e94c32c43140dec214..40e3069e66b4e3c1436dee6808d33fea8b0ffc7c 100644 (file)
@@ -461,7 +461,7 @@ public:
   }
 
   std::unique_ptr<Sema> takeSema();
-  void resetAndLeakSema() { BuryPointer(TheSema.release()); }
+  void resetAndLeakSema();
 
   /// }
   /// @name Module Management
index 4c0a7b7a9c66a419f517124a7f17fe30d416bc2a..ce1c9834c5393c4d93dd3bcab7f580b17b16fb4f 100644 (file)
@@ -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 <typename T> void BuryPointer(std::unique_ptr<T> Ptr) {
+  BuryPointer(Ptr.release());
+}
 
 } // end namespace clang
 
index 8829680314b5045bb570eb08f0326a93188f4ab1..4a8a1b331eff74a0fb629bbebba9dfc994081429 100644 (file)
@@ -122,7 +122,7 @@ public:
     delete PerModulePasses;
     delete PerFunctionPasses;
     if (CodeGenOpts.DisableFree)
-      BuryPointer(TM.release());
+      BuryPointer(std::move(TM));
   }
 
   std::unique_ptr<TargetMachine> TM;
index 513a43c140764efb766e686b07d4294ad3e393f3..3d1a18e27654e60e6dc812d67c0efc1713862368 100644 (file)
@@ -1605,3 +1605,4 @@ CompilerInstance::lookupMissingImports(StringRef Name,
 
   return false;
 }
+void CompilerInstance::resetAndLeakSema() { BuryPointer(takeSema()); }
index de864f6535621bd36f8d017b06eb5de965af7702..79cf0049a7b20b3999754a3d1190109d02d7553d 100644 (file)
@@ -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;
 }