From 638090e32fa4c18e1251e265e2b16d990ff96e28 Mon Sep 17 00:00:00 2001 From: Sean Fertile Date: Tue, 12 Feb 2019 20:03:04 +0000 Subject: [PATCH] Fix undefined behaviour in PPCInstPrinter::printBranchOperand. Fix the undefined behaviour introduced by my previous patch r353865 (left shifting a potentially negative value), which was caught by the bots that run UBSan. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353874 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp b/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp index 49e73891bc3..77206494990 100644 --- a/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp +++ b/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp @@ -382,7 +382,7 @@ void PPCInstPrinter::printBranchOperand(const MCInst *MI, unsigned OpNo, // Branches can take an immediate operand. This is used by the branch // selection pass to print .+8, an eight byte displacement from the PC. O << "."; - int32_t Imm = MI->getOperand(OpNo).getImm() << 2; + int32_t Imm = SignExtend32<32>((unsigned)MI->getOperand(OpNo).getImm() << 2); if (Imm >= 0) O << "+"; O << Imm; -- 2.11.0