[llvm] 5a731d7 - Fix test: LLVMGetBitcodeModule takes ownership of memory buffer
Nicolai Hähnle via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 8 11:07:23 PDT 2022
Author: Nicolai Hähnle
Date: 2022-07-08T20:06:44+02:00
New Revision: 5a731d733c569a6518ca136d6e907fae19942f4b
URL: https://github.com/llvm/llvm-project/commit/5a731d733c569a6518ca136d6e907fae19942f4b
DIFF: https://github.com/llvm/llvm-project/commit/5a731d733c569a6518ca136d6e907fae19942f4b.diff
LOG: Fix test: LLVMGetBitcodeModule takes ownership of memory buffer
Clarify this behavior in the C interface header file and fix a related
bug in a test.
Differential Revision: https://reviews.llvm.org/D129113
Added:
Modified:
llvm/include/llvm-c/BitReader.h
llvm/tools/llvm-c-test/diagnostic.c
Removed:
################################################################################
diff --git a/llvm/include/llvm-c/BitReader.h b/llvm/include/llvm-c/BitReader.h
index 012c0e63d3bb9..088107468d4fb 100644
--- a/llvm/include/llvm-c/BitReader.h
+++ b/llvm/include/llvm-c/BitReader.h
@@ -61,8 +61,13 @@ LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
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);
diff --git a/llvm/tools/llvm-c-test/diagnostic.c b/llvm/tools/llvm-c-test/diagnostic.c
index d759097e8e962..0f9b48b2aa551 100644
--- a/llvm/tools/llvm-c-test/diagnostic.c
+++ b/llvm/tools/llvm-c-test/diagnostic.c
@@ -70,13 +70,8 @@ int llvm_test_diagnostic_handler(void) {
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");
More information about the llvm-commits
mailing list