From 53ce1eab3b71ca027ac0253df4b6f36ead5da8ac Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 26 Apr 2021 22:25:26 -0700 Subject: [PATCH] [ORC] Make LLVMOrcLLJITBuilderSetJITTargetMachineBuilder consume as advertised. This should fix some of the memory leaks seen in the ORC C API test case. --- include/llvm-c/Orc.h | 5 +++-- lib/ExecutionEngine/Orc/OrcV2CBindings.cpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/llvm-c/Orc.h b/include/llvm-c/Orc.h index 78f6f28a465..76692ba89de 100644 --- a/include/llvm-c/Orc.h +++ b/include/llvm-c/Orc.h @@ -635,8 +635,9 @@ LLVMErrorRef LLVMOrcJITTargetMachineBuilderDetectHost( * * This operation takes ownership of the given TargetMachine and destroys it * before returing. The resulting JITTargetMachineBuilder is owned by the client - * and must be passed to a consuming operation (e.g. LLVMOrcCreateLLJITBuilder) - * or disposed of by calling LLVMOrcDisposeJITTargetMachineBuilder. + * and must be passed to a consuming operation (e.g. + * LLVMOrcLLJITBuilderSetJITTargetMachineBuilder) or disposed of by calling + * LLVMOrcDisposeJITTargetMachineBuilder. */ LLVMOrcJITTargetMachineBuilderRef LLVMOrcJITTargetMachineBuilderCreateFromTargetMachine(LLVMTargetMachineRef TM); diff --git a/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp b/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp index 419f6e81e6e..5f9cb10be58 100644 --- a/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp +++ b/lib/ExecutionEngine/Orc/OrcV2CBindings.cpp @@ -513,7 +513,8 @@ void LLVMOrcDisposeLLJITBuilder(LLVMOrcLLJITBuilderRef Builder) { void LLVMOrcLLJITBuilderSetJITTargetMachineBuilder( LLVMOrcLLJITBuilderRef Builder, LLVMOrcJITTargetMachineBuilderRef JTMB) { - unwrap(Builder)->setJITTargetMachineBuilder(*unwrap(JTMB)); + unwrap(Builder)->setJITTargetMachineBuilder(std::move(*unwrap(JTMB))); + LLVMOrcDisposeJITTargetMachineBuilder(JTMB); } void LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator(