Skip to content

Commit

Permalink
[ARC] Prevent InstPrinter from crashing on unknown condition codes.
Browse files Browse the repository at this point in the history
Summary:
Instruction printer shouldn't crash with assertions due to incorrect input data. llvm_unreachable is not intended for runtime error handling.

Reviewers: petecoup

Reviewed By: petecoup

Differential Revision: https://reviews.llvm.org/D51728

llvm-svn: 341581
  • Loading branch information
tkrasnukha committed Sep 6, 2018
1 parent 95dd7a2 commit b5f4297
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.cpp
Expand Up @@ -20,7 +20,6 @@
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;
Expand All @@ -29,6 +28,12 @@ using namespace llvm;

#include "ARCGenAsmWriter.inc"

template <class T>
static const char *BadConditionCode(T cc) {
DEBUG(dbgs() << "Unknown condition code passed: " << cc << "\n");
return "{unknown-cc}";
}

static const char *ARCBRCondCodeToString(ARCCC::BRCondCode BRCC) {
switch (BRCC) {
case ARCCC::BREQ:
Expand All @@ -44,7 +49,7 @@ static const char *ARCBRCondCodeToString(ARCCC::BRCondCode BRCC) {
case ARCCC::BRHS:
return "hs";
}
llvm_unreachable("Unhandled ARCCC::BRCondCode");
return BadConditionCode(BRCC);
}

static const char *ARCCondCodeToString(ARCCC::CondCode CC) {
Expand Down Expand Up @@ -86,7 +91,7 @@ static const char *ARCCondCodeToString(ARCCC::CondCode CC) {
case ARCCC::Z:
return "z";
}
llvm_unreachable("Unhandled ARCCC::CondCode");
return BadConditionCode(CC);
}

void ARCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/MC/Disassembler/ARC/br.txt
Expand Up @@ -27,3 +27,5 @@
# CHECK: b -68
0xbd 0x07 0xcf 0xff

# CHECK: b{unknown-cc} 4096
0x00 0x00 0x9e 0x00

0 comments on commit b5f4297

Please sign in to comment.