[llvm] a861f50 - [WinEH] Fix asm in catchpad being turned into unreachable (#138392)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 8 12:46:54 PDT 2025
Author: Ralender
Date: 2025-05-08T21:46:51+02:00
New Revision: a861f50030a9dac28a35654506bb28d2bc239b56
URL: https://github.com/llvm/llvm-project/commit/a861f50030a9dac28a35654506bb28d2bc239b56
DIFF: https://github.com/llvm/llvm-project/commit/a861f50030a9dac28a35654506bb28d2bc239b56.diff
LOG: [WinEH] Fix asm in catchpad being turned into unreachable (#138392)
Added:
llvm/test/CodeGen/WinEH/wineh-asm2.ll
Modified:
llvm/lib/CodeGen/WinEHPrepare.cpp
llvm/test/CodeGen/WinEH/wineh-asm.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp
index 74cef6c134736..43dd651a686b9 100644
--- a/llvm/lib/CodeGen/WinEHPrepare.cpp
+++ b/llvm/lib/CodeGen/WinEHPrepare.cpp
@@ -1135,8 +1135,8 @@ void WinEHPrepareImpl::removeImplausibleInstructions(Function &F) {
// Skip call sites which are nounwind intrinsics or inline asm.
auto *CalledFn =
dyn_cast<Function>(CB->getCalledOperand()->stripPointerCasts());
- if (CalledFn && ((CalledFn->isIntrinsic() && CB->doesNotThrow()) ||
- CB->isInlineAsm()))
+ if (CB->isInlineAsm() ||
+ (CalledFn && CalledFn->isIntrinsic() && CB->doesNotThrow()))
continue;
// This call site was not part of this funclet, remove it.
diff --git a/llvm/test/CodeGen/WinEH/wineh-asm.ll b/llvm/test/CodeGen/WinEH/wineh-asm.ll
index 7aa29bb2be457..0f3357546f98d 100644
--- a/llvm/test/CodeGen/WinEH/wineh-asm.ll
+++ b/llvm/test/CodeGen/WinEH/wineh-asm.ll
@@ -1,5 +1,4 @@
-; RUN: opt -win-eh-prepare < %s
-; RUN: opt -passes=win-eh-prepare < %s
+; RUN: opt < %s -passes=win-eh-prepare -S | FileCheck %s
target triple = "x86_64-pc-windows-msvc"
diff --git a/llvm/test/CodeGen/WinEH/wineh-asm2.ll b/llvm/test/CodeGen/WinEH/wineh-asm2.ll
new file mode 100644
index 0000000000000..2c424536dca09
--- /dev/null
+++ b/llvm/test/CodeGen/WinEH/wineh-asm2.ll
@@ -0,0 +1,46 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=win-eh-prepare -S | FileCheck %s
+
+target triple = "x86_64-unknown-windows-msvc"
+
+%rtti.TypeDescriptor2 = type { ptr, ptr, [3 x i8] }
+
+$"??_R0H at 8" = comdat any
+
+@"??_7type_info@@6B@" = external constant ptr
+@"??_R0H at 8" = linkonce_odr global %rtti.TypeDescriptor2 { ptr @"??_7type_info@@6B@", ptr null, [3 x i8] c".H\00" }, comdat
+
+declare dso_local i32 @test0(i32) local_unnamed_addr
+
+define dso_local i32 @test1(i32 %argc) local_unnamed_addr personality ptr @__CxxFrameHandler3 {
+; CHECK-LABEL: define dso_local i32 @test1(
+; CHECK-SAME: i32 [[ARGC:%.*]]) local_unnamed_addr personality ptr @__CxxFrameHandler3 {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[CALL:%.*]] = invoke i32 @test0(i32 [[ARGC]])
+; CHECK-NEXT: to label %[[RETURN:.*]] unwind label %[[CATCH_DISPATCH:.*]]
+; CHECK: [[CATCH_DISPATCH]]:
+; CHECK-NEXT: [[TMP0:%.*]] = catchswitch within none [label %catch] unwind to caller
+; CHECK: [[CATCH:.*:]]
+; CHECK-NEXT: [[TMP1:%.*]] = catchpad within [[TMP0]] [ptr @"??_R0H at 8", i32 0, ptr null]
+; CHECK-NEXT: call void asm "", ""()
+; CHECK-NEXT: catchret from [[TMP1]] to label %[[RETURN]]
+; CHECK: [[RETURN]]:
+; CHECK-NEXT: ret i32 0
+;
+entry:
+ %call = invoke i32 @test0(i32 %argc)
+ to label %return unwind label %catch.dispatch
+
+catch.dispatch: ; preds = %entry
+ %0 = catchswitch within none [label %catch] unwind to caller
+
+catch: ; preds = %catch.dispatch
+ %1 = catchpad within %0 [ptr @"??_R0H at 8", i32 0, ptr null]
+ call void asm "", ""()
+ catchret from %1 to label %return
+
+return: ; preds = %catch, %entry
+ ret i32 0
+}
+
+declare dso_local i32 @__CxxFrameHandler3(...)
More information about the llvm-commits
mailing list