Skip to content

Commit

Permalink
[Windows SEH] Fix crash on empty seh block (#107031)
Browse files Browse the repository at this point in the history
Fixes #105813 and
#106915.
Adds a check for the end of the iterator, which can be a sentinel. 
The issue was introduced in
0efe111
from what I can see, so along with the introduction of /EHa support.
  • Loading branch information
R-Goc authored Sep 4, 2024
1 parent 6e60330 commit 2e0ded3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,10 @@ void SelectionDAGISel::reportIPToStateForBlocks(MachineFunction *MF) {
if (BB->getFirstMayFaultInst()) {
// Report IP range only for blocks with Faulty inst
auto MBBb = MBB.getFirstNonPHI();

if (MBBb == MBB.end())
continue;

MachineInstr *MIb = &*MBBb;
if (MIb->isTerminator())
continue;
Expand Down
18 changes: 18 additions & 0 deletions llvm/test/CodeGen/WinEH/wineh-empty-seh-scope.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc -mtriple=x86_64-pc-windows-msvc19.41.34120 < %s | FileCheck %s

define void @foo() personality ptr @__CxxFrameHandler3 {
; CHECK-LABEL: foo:
; CHECK: # %bb.0:
; CHECK-NEXT: nop # avoids zero-length function
call void @llvm.seh.scope.begin()
unreachable
}

declare i32 @__CxxFrameHandler3(...)

declare void @llvm.seh.scope.begin()

!llvm.module.flags = !{!0}

!0 = !{i32 2, !"eh-asynch", i32 1}

0 comments on commit 2e0ded3

Please sign in to comment.