aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--content/2022-06-18-libclang-c-to-llvm-ir/gen-ir.cc7
1 files changed, 7 insertions, 0 deletions
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)) {