[llvm-dev] reusing an ExecutionEngine instance

Geoff Levner via llvm-dev llvm-dev at lists.llvm.org
Tue Jun 5 08:56:04 PDT 2018

Well, if anybody out there comes across a similar problem, I found the
solution: create your own LLVMContext object and pass it to the
EmitLLVMOnlyAction constructor. If you don't, CodeGenAction creates a
temporary context and deletes it when the CodeGenAction is deleted. And the
LLVMContext destructor deletes the module that was created, even though you
may have a std::unique_ptr to it...


On 4 June 2018 at 14:51, Geoff Levner <glevner at gmail.com> wrote:

> Greetings, LLVM wizards,
> I am trying to use Clang to compile a function in memory once, then to
> execute it several times with different parameters. That is, I want to keep
> the resulting ExecutionEngine instance around and reuse it. (Or, if there
> is a better way to do this, I am open to suggestions.) (And if this is not
> the right mailing list for this kind of question, I am open to suggestions,
> too.)
> In the code below, the ExecutionEngine works fine if I use it immediately.
> But if I return from the function and use it afterward, I get memory
> corruption and crashes, presumably because it contains references to
> something that has been deleted. And in fact, if I change the code so that
> the CodeGenAction is not deleted, it seems to work.
> My question is: why should deleting the CodeGenAction corrupt the
> ExecutionEngine? Are there other things I should avoid deleting as well?
> (The following code was adapted from the clang-interpreter example in the
> v4.0.1 source code.)
> Geoff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180605/84c52f5d/attachment-0001.html>

More information about the llvm-dev mailing list