[PATCH] D129113: Fix test: LLVMGetBitcodeModule takes ownership of memory buffer
Nicolai Hähnle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 5 02:13:32 PDT 2022
nhaehnle created this revision.
nhaehnle added reviewers: efriedma, lattner.
Herald added a reviewer: deadalnix.
Herald added a subscriber: yaxunl.
Herald added a project: All.
nhaehnle requested review of this revision.
Herald added a project: LLVM.
Clarify this behavior in the C interface header file and fix a related
bug in a test.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129113
Files:
llvm/include/llvm-c/BitReader.h
llvm/tools/llvm-c-test/diagnostic.c
Index: llvm/tools/llvm-c-test/diagnostic.c
===================================================================
--- llvm/tools/llvm-c-test/diagnostic.c
+++ llvm/tools/llvm-c-test/diagnostic.c
@@ -70,13 +70,8 @@
LLVMModuleRef M;
int Ret = LLVMGetBitcodeModule2(MB, &M);
- if (Ret) {
- // We do not return if the bitcode was invalid, as we want to test whether
- // the diagnostic handler was executed.
- fprintf(stderr, "Error parsing bitcode: %s\n", msg);
- }
-
- LLVMDisposeMemoryBuffer(MB);
+ if (Ret)
+ LLVMDisposeMemoryBuffer(MB);
if (handlerCalled) {
fprintf(stderr, "Diagnostic handler was called while loading module\n");
Index: llvm/include/llvm-c/BitReader.h
===================================================================
--- llvm/include/llvm-c/BitReader.h
+++ llvm/include/llvm-c/BitReader.h
@@ -61,8 +61,13 @@
LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutM, char **OutMessage);
-/** Reads a module from the specified path, returning via the OutMP parameter a
- * module provider which performs lazy deserialization. Returns 0 on success. */
+/** Reads a module from the given memory buffer, returning via the OutMP
+ * parameter a * module provider which performs lazy deserialization.
+ *
+ * Returns 0 on success.
+ *
+ * Takes ownership of \p MemBuf if (and only if) the module was read
+ * successfully. */
LLVMBool LLVMGetBitcodeModuleInContext2(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutM);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129113.442212.patch
Type: text/x-patch
Size: 1645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220705/29ed1c6d/attachment.bin>
More information about the llvm-commits
mailing list