[PATCH] D25566: Fix for PR30687. Avoid dereferencing MBB.end().

David Kreitzer via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 13 08:42:33 PDT 2016


DavidKreitzer created this revision.
DavidKreitzer added reviewers: dexonsmith, rnk, hans.
DavidKreitzer added a subscriber: llvm-commits.

This bug is a consequence of

r279314 | dexonsmith | 2016-08-19 13:40:12 -0700 (Fri, 19 Aug 2016) | 110 lines

We hit the "Assertion `!NodePtr->isKnownSentinel()' failed" assertion, but only when inserting a stack probe call at the end of an MBB, which isn't necessarily a common situation.


https://reviews.llvm.org/D25566

Files:
  lib/Target/X86/X86FrameLowering.cpp
  test/CodeGen/X86/win_chkstk.ll


Index: lib/Target/X86/X86FrameLowering.cpp
===================================================================
--- lib/Target/X86/X86FrameLowering.cpp
+++ lib/Target/X86/X86FrameLowering.cpp
@@ -766,6 +766,9 @@
       ExpansionMBBI->setFlag(MachineInstr::FrameSetup);
   }
 
+  if (MBBI == MBB.end())
+    return nullptr;
+
   return &*MBBI;
 }
 
Index: test/CodeGen/X86/win_chkstk.ll
===================================================================
--- test/CodeGen/X86/win_chkstk.ll
+++ test/CodeGen/X86/win_chkstk.ll
@@ -63,3 +63,20 @@
   %array4096 = alloca [4096 x i8], align 16       ; <[4096 x i8]*> [#uses=0]
   ret i32 0
 }
+
+; PR30687: Avoid crashing when inserting a __chkstk call at the end of an MBB.
+define void @dont_crash() {
+entry:
+; WIN_X32:    calll __chkstk
+; WIN_X64:    callq __chkstk
+; WIN64_LARGE: movabsq $__chkstk, %r11
+; WIN64_LARGE: callq *%r11
+; MINGW_X32:  calll __alloca
+; MINGW_X64:  callq ___chkstk_ms
+; LINUX-NOT:  call __chkstk
+  %buffer = alloca [4096 x i8]
+  br label %ret
+
+ret:
+  ret void
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25566.74530.patch
Type: text/x-patch
Size: 1048 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161013/f59617af/attachment.bin>


More information about the llvm-commits mailing list