[llvm-branch-commits] [llvm] release/19.x: [Windows SEH] Fix crash on empty seh block (#107031) (PR #107466)
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Sep 12 23:05:57 PDT 2024
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/107466
>From f0010d131b79a1b401777aa32e96defc4a935c9d Mon Sep 17 00:00:00 2001
From: R-Goc <131907007+R-Goc at users.noreply.github.com>
Date: Wed, 4 Sep 2024 20:10:36 +0200
Subject: [PATCH] [Windows SEH] Fix crash on empty seh block (#107031)
Fixes https://github.com/llvm/llvm-project/issues/105813 and
https://github.com/llvm/llvm-project/issues/106915.
Adds a check for the end of the iterator, which can be a sentinel.
The issue was introduced in
https://github.com/llvm/llvm-project/commit/0efe111365ae176671e01252d24028047d807a84
from what I can see, so along with the introduction of /EHa support.
(cherry picked from commit 2e0ded3371f8d42f376bdfd4d70687537e36818e)
---
.../CodeGen/SelectionDAG/SelectionDAGISel.cpp | 4 ++++
.../CodeGen/WinEH/wineh-empty-seh-scope.ll | 18 ++++++++++++++++++
2 files changed, 22 insertions(+)
create mode 100644 llvm/test/CodeGen/WinEH/wineh-empty-seh-scope.ll
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index df3d207d85d351..b961d3bb1fec7f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -1453,6 +1453,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;
diff --git a/llvm/test/CodeGen/WinEH/wineh-empty-seh-scope.ll b/llvm/test/CodeGen/WinEH/wineh-empty-seh-scope.ll
new file mode 100644
index 00000000000000..5f382f10f180bc
--- /dev/null
+++ b/llvm/test/CodeGen/WinEH/wineh-empty-seh-scope.ll
@@ -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}
More information about the llvm-branch-commits
mailing list