[llvm-dev] MCJit and remove module memory leak?

Lang Hames via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 4 16:20:32 PDT 2016


Hi Koffie,

Kaleidoscope is no longer using MCJIT - it has been moved over to the
ORC-based KaleidoscopeJIT class (see
llvm/examples/Kaleidoscope/include/KaleidoscopeJIT.h). The removeModule
method there does not leak memory.

I've added documentation in r286026 to describe MCJIT removeModule's crazy
ownership contract.

This will be fixed properly when we kill off ExecutionEngine. :)

- Lang.


On Fri, Oct 28, 2016 at 4:10 AM, koffie drinker <gekkekoe at gmail.com> wrote:

> I'm on llvm 3.8.1 and was wondering if there's a memory leak in the
> removeModule impl of mcjit.
> In the tutorial http://llvm.org/releases/3.8.1/docs/tutorial/
> LangImpl4.html a module is removed from the Jit by invoking removeModule.
>
> According to the tutorial:
>
> "Its API is very simple:: addModule adds an LLVM IR module to the JIT,
> making its functions available for execution; removeModule removes a
> module, freeing any memory associated with the code in that module;"
>
> But when I look into the implementation of remove module, it only erases
> the ptr from AddedModules
> //return AddedModules.erase(M) || LoadedModules.erase(M) ||
> FinalizedModules.erase(M);
>
> When you add a module, the unique ptr is stripped, and the raw ptr is
> stored.
> //AddedModules.insert(M.release());
>
> This should imply that the person who is invoking removeModule also should
> invoke a delete on the ptr?
>
> Am I missing something here?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161104/558ea0a0/attachment.html>


More information about the llvm-dev mailing list