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)
commite46d3796fc7a7c766c5a6a943cfe8b162c320ca8
tree0f952ed2a45fde953a8f480ee05614f81e4191ed
parent97100e36c39dfea5b663423f8d78714ca602a18c
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.

llvm-svn: 240201
llvm/lib/Transforms/Utils/LowerSwitch.cpp