From cfaa38627b3d315d47ddad295962fe0c92d74b84 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Sat, 25 Jun 2022 12:14:22 +0200 Subject: clang: enhance comment for EmitLLVMOnlyAction --- content/2022-06-18-libclang-c-to-llvm-ir/gen-ir.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/content/2022-06-18-libclang-c-to-llvm-ir/gen-ir.cc b/content/2022-06-18-libclang-c-to-llvm-ir/gen-ir.cc index a2055e4..3c251b6 100644 --- a/content/2022-06-18-libclang-c-to-llvm-ir/gen-ir.cc +++ b/content/2022-06-18-libclang-c-to-llvm-ir/gen-ir.cc @@ -81,6 +81,13 @@ int main() { cc.getPreprocessorOpts().addRemappedFile(code_fname, code_buffer.release()); // Create action to generate LLVM IR. + // + // If created with default arguments, the EmitLLVMOnlyAction will allocate + // an owned LLVMContext and free it once the action goes out of scope. + // + // To keep the context after the action goes out of scope, either pass a + // LLVMContext (borrowed) when creating the EmitLLVMOnlyAction or call + // takeLLVMContext() to move ownership out of the action. EmitLLVMOnlyAction action; // Run action against our compiler instance. if (!cc.ExecuteAction(action)) { -- cgit v1.2.3