-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Closed
Labels
Description
; RUN: opt -S -inline < %s
define void @foo() personality i32 (...)* undef {
entry:
br i1 false, label %join, label %split
split: ; preds = %entry
br label %join
join: ; preds = %split, %entry
%phi = phi i64 [ 1, %split ], [ 0, %entry ]
%cmp = icmp ugt i64 1, %phi
br i1 %cmp, label %invoke1, label %exit
invoke1: ; preds = %join
invoke void undef()
to label %exit unwind label %cleanup1
cleanup1: ; preds = %invoke1
%pad1 = cleanuppad within none []
br label %cleanup1.cont
cleanup1.cont: ; preds = %invoke2, %cleanup1
br i1 undef, label %cleanupret, label %invoke2
invoke2: ; preds = %cleanup1.cont
invoke void undef()
to label %cleanup1.cont unwind label %cleanup2
cleanup2: ; preds = %invoke2
%pad2 = cleanuppad within none []
br label %cleanupret
cleanupret: ; preds = %cleanup2, %cleanup1.cont
cleanupret from %pad1 unwind to caller
exit: ; preds = %invoke1, %join
ret void
}
define void @test() personality i32 (...)* undef {
invoke void @foo()
to label %exit unwind label %cleanup
exit: ; preds = %0
ret void
cleanup: ; preds = %0
%pad = cleanuppad within none []
cleanupret from %pad unwind to caller
}
Asserts:
opt: /home/npopov/repos/llvm-project/llvm/include/llvm/Support/Casting.h:255: std::enable_if_t<(! llvm::is_simple_type<Y>::value), typename llvm::cast_retty<X, const Y>::ret_type> llvm::cast(const Y&) [with X = llvm::CleanupPadInst; Y = llvm::Use; std::enable_if_t<(! llvm::is_simple_type<Y>::value), typename llvm::cast_retty<X, const Y>::ret_type> = llvm::CleanupPadInst*; typename llvm::cast_retty<X, const Y>::ret_type = llvm::CleanupPadInst*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: build/bin/opt -S -inline -debug-only=inline test064.ll
#0 0x000000000316a451 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x0000000003167c2e SignalHandler(int) Signals.cpp:0:0
#2 0x00007ffabebb8750 __restore_rt (/lib64/libc.so.6+0x42750)
#3 0x00007ffabec0584c __pthread_kill_implementation (/lib64/libc.so.6+0x8f84c)
#4 0x00007ffabebb86a6 gsignal (/lib64/libc.so.6+0x426a6)
#5 0x00007ffabeba27d3 abort (/lib64/libc.so.6+0x2c7d3)
#6 0x00007ffabeba26fb _nl_load_domain.cold (/lib64/libc.so.6+0x2c6fb)
#7 0x00007ffabebb1396 (/lib64/libc.so.6+0x3b396)
#8 0x0000000003211cdf HandleInlinedEHPad(llvm::InvokeInst*, llvm::BasicBlock*, llvm::ClonedCodeInfo&) InlineFunction.cpp:0:0
#9 0x0000000003217fd3 llvm::InlineFunction(llvm::CallBase&, llvm::InlineFunctionInfo&, llvm::AAResults*, bool, llvm::Function*) (build/bin/opt+0x3217fd3)
#10 0x0000000002976948 llvm::InlinerPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (build/bin/opt+0x2976948)
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
nikic commentedon Jan 14, 2022
A possibly helpful variant is this:
This results in a verifier error rather than an assert, with the following IR produced for
@test()
:efriedma-quic commentedon Jan 14, 2022
The testcases given are not quite valid... missing required "funclet" marking on invoke in cleanup. Verifier should be checking for that, I think? Anyway, fixed testcase:
I think the inliner's code for updating the EH pads is getting confused because the inlined code is unreachable. The simplest way to fix this might be to just teach the inliner to erase unreachable code...
nikic commentedon Jan 28, 2022
I just looked into this a bit. The pruning function cloner will only clone blocks that are reachable -- the problem is that PHI nodes only get resolved and folded after that, and then there's a second pass for folding terminators and dropping dead blocks:
llvm-project/llvm/lib/Transforms/Utils/CloneFunction.cpp
Lines 718 to 727 in 14e8bed
But that code will only drop trivially dead blocks, not those that are in unreachable cycles.
nikic commentedon Jan 28, 2022
Candidate patch: https://reviews.llvm.org/D118449
[Inline][Cloning] Reliably remove unreachable blocks during cloning (…
[Inline][Cloning] Reliably remove unreachable blocks during cloning (…
[Inline][Cloning] Reliably remove unreachable blocks during cloning (…
[Inline][Cloning] Reliably remove unreachable blocks during cloning (…