[PATCH] D52002: Switch optimization for known maximum switch values

Hans Wennborg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 23 05:11:09 PDT 2018


hans added a comment.

In https://reviews.llvm.org/D52002#1262645, @efriedma wrote:

> Anyone have any thoughts about potential security implications for this?  Normally, I wouldn't really care about assuming code never has undefined behavior, but an indirect jump to an arbitrary address is much easier to exploit than other sorts of undefined behavior.


It's an interesting question. An indirect jump like this does seem like a pretty powerful gadget.

On the other hand, if we really know that the default is unreachable, it should be safe, such as when the switch cases cover all possible inputs.

The scary case is really when default is unreachable because of UB, the typical case being a function ending without returning a value. But Clang is pretty good about warning about that, so I'm not too concerned.


https://reviews.llvm.org/D52002





More information about the llvm-commits mailing list