Fix test: LLVMGetBitcodeModule takes ownership of memory buffer
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Mon, 4 Jul 2022 11:35:26 +0000 (13:35 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Fri, 8 Jul 2022 18:06:44 +0000 (20:06 +0200)
Clarify this behavior in the C interface header file and fix a related
bug in a test.

Differential Revision: https://reviews.llvm.org/D129113

llvm/include/llvm-c/BitReader.h
llvm/tools/llvm-c-test/diagnostic.c

index 012c0e6..0881074 100644 (file)
@@ -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);
index d759097..0f9b48b 100644 (file)
@@ -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");