[PATCH] D127712: Prevent crash when TurnSwitchRangeIntoICmp receives default unreachable destination

Samuel Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 15 22:38:14 PDT 2022


swamulism 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);
----------------
nikic wrote:
> 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.
It looks like this is optimized after anyways, but yeah ideally it shouldn't get to this point in the first place.


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