[X86] Fix to X86LoadValueInjectionRetHardeningPass for possible segfault
authorScott Constable <scott.d.constable@intel.com>
Sat, 11 Apr 2020 00:32:39 +0000 (17:32 -0700)
committerCraig Topper <craig.topper@gmail.com>
Sat, 11 Apr 2020 01:28:08 +0000 (18:28 -0700)
`MBB.back()` could segfault if `MBB.empty()`. Fixed by checking for `MBB.empty()` in the loop.

Differential Revision: https://reviews.llvm.org/D77584

llvm/lib/Target/X86/X86LoadValueInjectionRetHardening.cpp

index 9c36e86..6e1134a 100644 (file)
@@ -99,6 +99,9 @@ bool X86LoadValueInjectionRetHardeningPass::runOnMachineFunction(
 
   bool Modified = false;
   for (auto &MBB : MF) {
+    if (MBB.empty())
+      continue;
+
     MachineInstr &MI = MBB.back();
     if (MI.getOpcode() != X86::RETQ)
       continue;