Skip to content

Commit a1f4ac7

Browse files
[SEH] Ignore EH pad check for internal intrinsics (llvm#79694)
Intrinsics like @llvm.seh.scope.begin and @llvm.seh.scope.end which do not throw do not need funclets in catchpads or cleanuppads. Fixes llvm#69428 Co-authored-by: Robert Cox <[email protected]> --------- Co-authored-by: Robert Cox <[email protected]>
1 parent 417a068 commit a1f4ac7

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4343,6 +4343,11 @@ void Verifier::visitEHPadPredecessors(Instruction &I) {
43434343
if (auto *II = dyn_cast<InvokeInst>(TI)) {
43444344
Check(II->getUnwindDest() == BB && II->getNormalDest() != BB,
43454345
"EH pad must be jumped to via an unwind edge", ToPad, II);
4346+
auto *CalledFn =
4347+
dyn_cast<Function>(II->getCalledOperand()->stripPointerCasts());
4348+
if (CalledFn && CalledFn->isIntrinsic() && II->doesNotThrow() &&
4349+
!IntrinsicInst::mayLowerToFunctionCall(CalledFn->getIntrinsicID()))
4350+
continue;
43464351
if (auto Bundle = II->getOperandBundle(LLVMContext::OB_funclet))
43474352
FromPad = Bundle->Inputs[0];
43484353
else

llvm/test/Verifier/pr69428.ll

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: llvm-as -disable-output %s
2+
3+
%struct._List_node_emplace_op2 = type { i8 }
4+
5+
@"?_List@@3HA" = global i32 0, align 4
6+
7+
define void @"?ExecutionEngineaddExecutableDependency@@YAXXZ"() personality ptr @__CxxFrameHandler3 {
8+
entry:
9+
%agg.tmp.ensured.i = alloca %struct._List_node_emplace_op2, align 1
10+
%0 = load i32, ptr @"?_List@@3HA", align 4
11+
%call.i = call noundef ptr @"??0?$_List_node_emplace_op2@H@@QEAA@H@Z"(ptr %agg.tmp.ensured.i, i32 %0)
12+
invoke void @llvm.seh.scope.begin()
13+
to label %invoke.cont.i unwind label %ehcleanup.i
14+
15+
invoke.cont.i: ; preds = %entry
16+
invoke void @llvm.seh.scope.end()
17+
to label %invoke.cont2.i unwind label %ehcleanup.i
18+
19+
invoke.cont2.i: ; preds = %invoke.cont.i
20+
call void @"??1?$_List_node_emplace_op2@H@@QEAA@XZ"(ptr %agg.tmp.ensured.i) #6
21+
unreachable
22+
23+
ehcleanup.i: ; preds = %invoke.cont.i, %entry
24+
%1 = cleanuppad within none []
25+
invoke void @llvm.seh.scope.begin()
26+
to label %invoke.cont.i.i unwind label %ehcleanup.i.i
27+
28+
invoke.cont.i.i: ; preds = %ehcleanup.i
29+
invoke void @llvm.seh.scope.end()
30+
to label %"??1?$_List_node_emplace_op2@H@@[email protected]" unwind label %ehcleanup.i.i
31+
32+
ehcleanup.i.i: ; preds = %invoke.cont.i.i, %ehcleanup.i
33+
%2 = cleanuppad within %1 []
34+
call void @"??1_Alloc_construct_ptr@@QEAA@XZ"(ptr %agg.tmp.ensured.i) #6 [ "funclet"(token %2) ]
35+
cleanupret from %2 unwind to caller
36+
37+
"??1?$_List_node_emplace_op2@H@@[email protected]": ; preds = %invoke.cont.i.i
38+
call void @"??1_Alloc_construct_ptr@@QEAA@XZ"(ptr %agg.tmp.ensured.i) #6 [ "funclet"(token %1) ]
39+
cleanupret from %1 unwind to caller
40+
}
41+
42+
declare i32 @__CxxFrameHandler3(...)
43+
declare void @llvm.seh.scope.begin()
44+
declare void @llvm.seh.scope.end()
45+
46+
declare void @"??1?$_List_node_emplace_op2@H@@QEAA@XZ"(ptr)
47+
declare void @"??1_Alloc_construct_ptr@@QEAA@XZ"(ptr)
48+
declare ptr @"??0?$_List_node_emplace_op2@H@@QEAA@H@Z"(ptr, i32)

0 commit comments

Comments
 (0)