Skip to content

Commit a861f50

Browse files
authored
[WinEH] Fix asm in catchpad being turned into unreachable (llvm#138392)
1 parent 227e1ff commit a861f50

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

llvm/lib/CodeGen/WinEHPrepare.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,8 +1135,8 @@ void WinEHPrepareImpl::removeImplausibleInstructions(Function &F) {
11351135
// Skip call sites which are nounwind intrinsics or inline asm.
11361136
auto *CalledFn =
11371137
dyn_cast<Function>(CB->getCalledOperand()->stripPointerCasts());
1138-
if (CalledFn && ((CalledFn->isIntrinsic() && CB->doesNotThrow()) ||
1139-
CB->isInlineAsm()))
1138+
if (CB->isInlineAsm() ||
1139+
(CalledFn && CalledFn->isIntrinsic() && CB->doesNotThrow()))
11401140
continue;
11411141

11421142
// This call site was not part of this funclet, remove it.

llvm/test/CodeGen/WinEH/wineh-asm.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
; RUN: opt -win-eh-prepare < %s
2-
; RUN: opt -passes=win-eh-prepare < %s
1+
; RUN: opt < %s -passes=win-eh-prepare -S | FileCheck %s
32

43
target triple = "x86_64-pc-windows-msvc"
54

llvm/test/CodeGen/WinEH/wineh-asm2.ll

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -passes=win-eh-prepare -S | FileCheck %s
3+
4+
target triple = "x86_64-unknown-windows-msvc"
5+
6+
%rtti.TypeDescriptor2 = type { ptr, ptr, [3 x i8] }
7+
8+
$"??_R0H@8" = comdat any
9+
10+
@"??_7type_info@@6B@" = external constant ptr
11+
@"??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { ptr @"??_7type_info@@6B@", ptr null, [3 x i8] c".H\00" }, comdat
12+
13+
declare dso_local i32 @test0(i32) local_unnamed_addr
14+
15+
define dso_local i32 @test1(i32 %argc) local_unnamed_addr personality ptr @__CxxFrameHandler3 {
16+
; CHECK-LABEL: define dso_local i32 @test1(
17+
; CHECK-SAME: i32 [[ARGC:%.*]]) local_unnamed_addr personality ptr @__CxxFrameHandler3 {
18+
; CHECK-NEXT: [[ENTRY:.*:]]
19+
; CHECK-NEXT: [[CALL:%.*]] = invoke i32 @test0(i32 [[ARGC]])
20+
; CHECK-NEXT: to label %[[RETURN:.*]] unwind label %[[CATCH_DISPATCH:.*]]
21+
; CHECK: [[CATCH_DISPATCH]]:
22+
; CHECK-NEXT: [[TMP0:%.*]] = catchswitch within none [label %catch] unwind to caller
23+
; CHECK: [[CATCH:.*:]]
24+
; CHECK-NEXT: [[TMP1:%.*]] = catchpad within [[TMP0]] [ptr @"??_R0H@8", i32 0, ptr null]
25+
; CHECK-NEXT: call void asm "", ""()
26+
; CHECK-NEXT: catchret from [[TMP1]] to label %[[RETURN]]
27+
; CHECK: [[RETURN]]:
28+
; CHECK-NEXT: ret i32 0
29+
;
30+
entry:
31+
%call = invoke i32 @test0(i32 %argc)
32+
to label %return unwind label %catch.dispatch
33+
34+
catch.dispatch: ; preds = %entry
35+
%0 = catchswitch within none [label %catch] unwind to caller
36+
37+
catch: ; preds = %catch.dispatch
38+
%1 = catchpad within %0 [ptr @"??_R0H@8", i32 0, ptr null]
39+
call void asm "", ""()
40+
catchret from %1 to label %return
41+
42+
return: ; preds = %catch, %entry
43+
ret i32 0
44+
}
45+
46+
declare dso_local i32 @__CxxFrameHandler3(...)

0 commit comments

Comments
 (0)