mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-26 05:32:25 +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-c/BitReader.h"
|
||||||
#include "llvm/Bitcode/ReaderWriter.h"
|
#include "llvm/Bitcode/ReaderWriter.h"
|
||||||
|
#include "llvm/IR/DiagnosticPrinter.h"
|
||||||
#include "llvm/IR/LLVMContext.h"
|
#include "llvm/IR/LLVMContext.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -30,8 +32,15 @@ LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
|
|||||||
LLVMMemoryBufferRef MemBuf,
|
LLVMMemoryBufferRef MemBuf,
|
||||||
LLVMModuleRef *OutModule,
|
LLVMModuleRef *OutModule,
|
||||||
char **OutMessage) {
|
char **OutMessage) {
|
||||||
ErrorOr<Module *> ModuleOrErr =
|
MemoryBufferRef Buf = unwrap(MemBuf)->getMemBufferRef();
|
||||||
parseBitcodeFile(unwrap(MemBuf)->getMemBufferRef(), *unwrap(ContextRef));
|
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 (std::error_code EC = ModuleOrErr.getError()) {
|
||||||
if (OutMessage)
|
if (OutMessage)
|
||||||
*OutMessage = strdup(EC.message().c_str());
|
*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