]> granicus.if.org Git - llvm/commitdiff
Fix undefined behaviour in PPCInstPrinter::printBranchOperand.
authorSean Fertile <sfertile@ca.ibm.com>
Tue, 12 Feb 2019 20:03:04 +0000 (20:03 +0000)
committerSean Fertile <sfertile@ca.ibm.com>
Tue, 12 Feb 2019 20:03:04 +0000 (20:03 +0000)
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

index 49e73891bc3049bed0701f1b6bd37ed36c459cba..77206494990bbbc17c45c8b7e181136a3ddc0098 100644 (file)
@@ -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;