Fix error handling in LLVMGetBitcodeModuleInContext.

It was not setting OutMessage.

llvm-svn: 255998
This commit is contained in:
Rafael Espindola 2015-12-18 13:58:05 +00:00
parent 3aac36ad01
commit f382b8836a
2 changed files with 11 additions and 3 deletions

View File

@ -71,17 +71,24 @@ LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
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;
}

View File

@ -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)