[PATCH] D41358: [PowerPC] Fix minor bug to avoid a failure in createTailCallBranchInstr

Stefan Pintilie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 18 09:03:14 PST 2017

stefanp created this revision.
stefanp added reviewers: kbarton, nemanjai, inouehrs, sfertile, lei, syzaara, jtony, hfinkel, echristo.

It looks like `dl = MBBI->getDebugLoc();` is correctly guarded by `if (MBBI != MBB.end())` but later on in the same function `unsigned RetOpcode = MBBI->getOpcode();` is not guarded so it is possible to reach `unsigned RetOpcode = MBBI->getOpcode();` in a situation where `MBBI` is actually `MBB.end()`.

If `MBBI == MBB.end()` then we don't need to execute the function at all. Added a guard to do that.



Index: lib/Target/PowerPC/PPCFrameLowering.cpp
--- lib/Target/PowerPC/PPCFrameLowering.cpp
+++ lib/Target/PowerPC/PPCFrameLowering.cpp
@@ -1531,11 +1531,12 @@
 void PPCFrameLowering::createTailCallBranchInstr(MachineBasicBlock &MBB) const {
   MachineBasicBlock::iterator MBBI = MBB.getFirstTerminator();
-  DebugLoc dl;
-  if (MBBI != MBB.end())
-    dl = MBBI->getDebugLoc();
+  // If there is no first terminator then we should not continue.
+  if (MBBI == MBB.end())
+    return;
+  DebugLoc dl = MBBI->getDebugLoc();
   const PPCInstrInfo &TII = *Subtarget.getInstrInfo();
   // Create branch instruction for pseudo tail call return instruction

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41358.127370.patch
Type: text/x-patch
Size: 726 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171218/77117f74/attachment.bin>

More information about the llvm-commits mailing list