From 5ada2a7e27ff7247d2ef7c3338408733a264f976 Mon Sep 17 00:00:00 2001 From: James Molloy Date: Thu, 1 Sep 2011 22:01:14 +0000 Subject: [PATCH] Fix apparent build error caused by r138948 on certain versions of GCC with -Werror. Sorry for the inconvenience. llvm-svn: 138973 --- llvm/lib/MC/MCDisassembler/Disassembler.cpp | 35 +++++++++++-------- llvm/lib/MC/MCDisassembler/EDDisassembler.cpp | 28 +++++++++------ 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/llvm/lib/MC/MCDisassembler/Disassembler.cpp b/llvm/lib/MC/MCDisassembler/Disassembler.cpp index 87d8ca8679f0..603df94f99c0 100644 --- a/llvm/lib/MC/MCDisassembler/Disassembler.cpp +++ b/llvm/lib/MC/MCDisassembler/Disassembler.cpp @@ -135,21 +135,28 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes, MCInst Inst; const MCDisassembler *DisAsm = DC->getDisAsm(); MCInstPrinter *IP = DC->getIP(); - if (DisAsm->getInstruction(Inst, Size, MemoryObject, PC, - /*REMOVE*/ nulls()) != MCDisassembler::Success) { + MCDisassembler::DecodeStatus S; + S = DisAsm->getInstruction(Inst, Size, MemoryObject, PC, + /*REMOVE*/ nulls()); + switch (S) { + case MCDisassembler::Fail: + case MCDisassembler::SoftFail: // FIXME: Do something different for soft failure modes? return 0; + + case MCDisassembler::Success: { + SmallVector InsnStr; + raw_svector_ostream OS(InsnStr); + IP->printInst(&Inst, OS); + OS.flush(); + + assert(OutStringSize != 0 && "Output buffer cannot be zero size"); + size_t OutputSize = std::min(OutStringSize-1, InsnStr.size()); + std::memcpy(OutString, InsnStr.data(), OutputSize); + OutString[OutputSize] = '\0'; // Terminate string. + + return Size; } - - SmallVector InsnStr; - raw_svector_ostream OS(InsnStr); - IP->printInst(&Inst, OS); - OS.flush(); - - assert(OutStringSize != 0 && "Output buffer cannot be zero size"); - size_t OutputSize = std::min(OutStringSize-1, InsnStr.size()); - std::memcpy(OutString, InsnStr.data(), OutputSize); - OutString[OutputSize] = '\0'; // Terminate string. - - return Size; + } + return 0; } diff --git a/llvm/lib/MC/MCDisassembler/EDDisassembler.cpp b/llvm/lib/MC/MCDisassembler/EDDisassembler.cpp index 14d735dbc76a..68a201b96a91 100644 --- a/llvm/lib/MC/MCDisassembler/EDDisassembler.cpp +++ b/llvm/lib/MC/MCDisassembler/EDDisassembler.cpp @@ -239,20 +239,28 @@ EDInst *EDDisassembler::createInst(EDByteReaderCallback byteReader, MCInst* inst = new MCInst; uint64_t byteSize; - if (Disassembler->getInstruction(*inst, byteSize, memoryObject, address, - ErrorStream) != MCDisassembler::Success) { + MCDisassembler::DecodeStatus S; + S = Disassembler->getInstruction(*inst, byteSize, memoryObject, address, + ErrorStream); + switch (S) { + case MCDisassembler::Fail: + case MCDisassembler::SoftFail: // FIXME: Do something different on soft failure mode? delete inst; return NULL; - } - const llvm::EDInstInfo *thisInstInfo = NULL; - - if (InstInfos) { - thisInstInfo = &InstInfos[inst->getOpcode()]; - } - EDInst* sdInst = new EDInst(inst, byteSize, *this, thisInstInfo); - return sdInst; + case MCDisassembler::Success: { + const llvm::EDInstInfo *thisInstInfo = NULL; + + if (InstInfos) { + thisInstInfo = &InstInfos[inst->getOpcode()]; + } + + EDInst* sdInst = new EDInst(inst, byteSize, *this, thisInstInfo); + return sdInst; + } + } + return NULL; } void EDDisassembler::initMaps(const MCRegisterInfo ®isterInfo) {