From b5f42976ad8be39d7ab60cf091a5ca82a8e944a6 Mon Sep 17 00:00:00 2001 From: Tatyana Krasnukha Date: Thu, 6 Sep 2018 19:58:26 +0000 Subject: [ARC] Prevent InstPrinter from crashing on unknown condition codes. 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 --- llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Target') diff --git a/llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.cpp b/llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.cpp index 0c627d04698..f0625800ccc 100644 --- a/llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.cpp +++ b/llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.cpp @@ -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; @@ -29,6 +28,12 @@ using namespace llvm; #include "ARCGenAsmWriter.inc" +template +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: @@ -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) { @@ -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 { -- cgit v1.2.3