[PATCH] D127712: Prevent crash when TurnSwitchRangeIntoICmp receives default unreachable destination
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 15 02:06:01 PDT 2022
nikic added inline comments.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:5226
assert(DestA && DestB &&
"Single-destination switch should have been folded.");
assert(DestA != DestB);
----------------
As this assert indicates, this case was supposed to be handled earlier already, namely by the ConstantFoldTerminator call. The reason it doesn't handle it is that https://github.com/llvm/llvm-project/blob/4c2bccfda3892ae13e97b6bfdbc99ec8cf5d095d/llvm/lib/Transforms/Utils/Local.cpp#L194-L198 will pick the unreachable block as the "only dest" and eliminate all unreachable cases. But that then leaves us with the actual only destination, which would get folded by a second call to ConstantFoldTerminator. Possibly the function should be improved to always find the non-unreachable dest.
But in any case, adding a conservative bailout here is reasonable, though the assertion message here is a bit outdated.
================
Comment at: llvm/test/Transforms/SimplifyCFG/switch-range-to-icmp.ll:150
+
+define void @0(i8 %sw, i32* %p0) {
+; CHECK-LABEL: @0(
----------------
Please give this function a name (like pr53208_single_reachable_dest or something).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127712/new/
https://reviews.llvm.org/D127712
More information about the llvm-commits
mailing list