mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-17 00:50:58 +00:00
Use a non-fatal diag handler in the C API. FIxes PR22368.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227903 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
68697579bf
commit
d0d95dbf3c
@ -9,9 +9,11 @@
|
||||
|
||||
#include "llvm-c/BitReader.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#include "llvm/IR/DiagnosticPrinter.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
@ -30,8 +32,15 @@ LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
|
||||
LLVMMemoryBufferRef MemBuf,
|
||||
LLVMModuleRef *OutModule,
|
||||
char **OutMessage) {
|
||||
ErrorOr<Module *> ModuleOrErr =
|
||||
parseBitcodeFile(unwrap(MemBuf)->getMemBufferRef(), *unwrap(ContextRef));
|
||||
MemoryBufferRef Buf = unwrap(MemBuf)->getMemBufferRef();
|
||||
LLVMContext &Ctx = *unwrap(ContextRef);
|
||||
|
||||
std::string Message;
|
||||
raw_string_ostream Stream(Message);
|
||||
DiagnosticPrinterRawOStream DP(Stream);
|
||||
|
||||
ErrorOr<Module *> ModuleOrErr = parseBitcodeFile(
|
||||
Buf, Ctx, [&](const DiagnosticInfo &DI) { DI.print(DP); });
|
||||
if (std::error_code EC = ModuleOrErr.getError()) {
|
||||
if (OutMessage)
|
||||
*OutMessage = strdup(EC.message().c_str());
|
||||
|
BIN
test/Bindings/llvm-c/Inputs/invalid.ll.bc
Normal file
BIN
test/Bindings/llvm-c/Inputs/invalid.ll.bc
Normal file
Binary file not shown.
3
test/Bindings/llvm-c/invalid-bitcode.test
Normal file
3
test/Bindings/llvm-c/invalid-bitcode.test
Normal file
@ -0,0 +1,3 @@
|
||||
; RUN: not llvm-c-test --module-dump < %S/Inputs/invalid.ll.bc 2>&1 | FileCheck %s
|
||||
|
||||
CHECK: Error parsing bitcode: Corrupted bitcode
|
Loading…
Reference in New Issue
Block a user