[llvm] r353874 - Fix undefined behaviour in PPCInstPrinter::printBranchOperand.

Sean Fertile via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 12 12:03:04 PST 2019


Author: sfertile
Date: Tue Feb 12 12:03:04 2019
New Revision: 353874

URL: http://llvm.org/viewvc/llvm-project?rev=353874&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp

Modified: llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp?rev=353874&r1=353873&r2=353874&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp Tue Feb 12 12:03:04 2019
@@ -382,7 +382,7 @@ void PPCInstPrinter::printBranchOperand(
   // 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;




More information about the llvm-commits mailing list