[llvm] r255998 - Fix error handling in LLVMGetBitcodeModuleInContext.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 18 05:58:05 PST 2015
Author: rafael
Date: Fri Dec 18 07:58:05 2015
New Revision: 255998
URL: http://llvm.org/viewvc/llvm-project?rev=255998&view=rev
Log:
Fix error handling in LLVMGetBitcodeModuleInContext.
It was not setting OutMessage.
Modified:
llvm/trunk/lib/Bitcode/Reader/BitReader.cpp
llvm/trunk/test/Bindings/llvm-c/invalid-bitcode.test
Modified: llvm/trunk/lib/Bitcode/Reader/BitReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitReader.cpp?rev=255998&r1=255997&r2=255998&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitReader.cpp Fri Dec 18 07:58:05 2015
@@ -71,17 +71,24 @@ LLVMBool LLVMGetBitcodeModuleInContext(L
LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutM,
char **OutMessage) {
+ LLVMContext &Ctx = *unwrap(ContextRef);
+ LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
+ Ctx.getDiagnosticHandler();
+ void *OldDiagnosticContext = Ctx.getDiagnosticContext();
+
std::string Message;
+ Ctx.setDiagnosticHandler(diagnosticHandler, &Message, true);
std::unique_ptr<MemoryBuffer> Owner(unwrap(MemBuf));
ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
- getLazyBitcodeModule(std::move(Owner), *unwrap(ContextRef));
+ getLazyBitcodeModule(std::move(Owner), Ctx);
Owner.release();
+ Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext, true);
- if (std::error_code EC = ModuleOrErr.getError()) {
+ if (ModuleOrErr.getError()) {
*OutM = wrap((Module *)nullptr);
if (OutMessage)
- *OutMessage = strdup(EC.message().c_str());
+ *OutMessage = strdup(Message.c_str());
return 1;
}
Modified: llvm/trunk/test/Bindings/llvm-c/invalid-bitcode.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/llvm-c/invalid-bitcode.test?rev=255998&r1=255997&r2=255998&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/llvm-c/invalid-bitcode.test (original)
+++ llvm/trunk/test/Bindings/llvm-c/invalid-bitcode.test Fri Dec 18 07:58:05 2015
@@ -1,3 +1,4 @@
; RUN: not llvm-c-test --module-dump < %S/Inputs/invalid.ll.bc 2>&1 | FileCheck %s
+; RUN: not llvm-c-test --lazy-module-dump < %S/Inputs/invalid.ll.bc 2>&1 | FileCheck %s
CHECK: Error parsing bitcode: Unknown attribute kind (52)
More information about the llvm-commits
mailing list