LowerSwitch: Avoid some undefined behaviour
authorJustin Bogner <mail@justinbogner.com>
Sat, 20 Jun 2015 00:28:25 +0000 (00:28 +0000)
committerJustin Bogner <mail@justinbogner.com>
Sat, 20 Jun 2015 00:28:25 +0000 (00:28 +0000)
commit4029c5944b7e3268fed212ac417323f6eae955b0
tree3d1e1ed690ca909ce5fe85136e5cccd3f0359c19
parentac9af6c151bb640071609aace1ff49572411dabb
LowerSwitch: Avoid some undefined behaviour

When a case of INT64_MIN was followed by a case that was greater than
zero, we were overflowing a signed integer here. Since we've sorted
the cases here anyway (and thus currentValue must be greater than
nextValue) it's simple enough to avoid this by using addition rather
than subtraction.

Found by UBSAN on existing tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240201 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Utils/LowerSwitch.cpp