diff options
author | Justin Bogner <mail@justinbogner.com> | 2015-06-20 00:28:25 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2015-06-20 00:28:25 +0000 |
commit | e46d3796fc7a7c766c5a6a943cfe8b162c320ca8 (patch) | |
tree | 0f952ed2a45fde953a8f480ee05614f81e4191ed /llvm/lib/Transforms/Utils/LowerSwitch.cpp | |
parent | 97100e36c39dfea5b663423f8d78714ca602a18c (diff) | |
download | bcm5719-llvm-e46d3796fc7a7c766c5a6a943cfe8b162c320ca8.tar.gz bcm5719-llvm-e46d3796fc7a7c766c5a6a943cfe8b162c320ca8.zip |
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
Diffstat (limited to 'llvm/lib/Transforms/Utils/LowerSwitch.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LowerSwitch.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp index a057f5d0c0f..b90a03c7976 100644 --- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp +++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp @@ -374,7 +374,8 @@ unsigned LowerSwitch::Clusterify(CaseVector& Cases, SwitchInst *SI) { // If the two neighboring cases go to the same destination, merge them // into a single case. - if ((nextValue-currentValue==1) && (currentBB == nextBB)) { + assert(nextValue > currentValue && "Cases should be strictly ascending"); + if ((nextValue == currentValue + 1) && (currentBB == nextBB)) { I->High = J->High; J = Cases.erase(J); } else { |