diff options
author | Peter Rong <peterrong96@gmail.com> | 2024-05-27 10:58:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-27 10:58:22 -0700 |
commit | 67aec0cd62d607b4e5b7198769be061454ce67b3 (patch) | |
tree | c6ce41aac85bfd3394a4940be88cad69bb8a7af6 /llvm/lib/Transforms/Utils/LowerSwitch.cpp | |
parent | d3ce1078186389ce39505f06c2a0100dce9187a5 (diff) | |
download | llvm-67aec0cd62d607b4e5b7198769be061454ce67b3.zip llvm-67aec0cd62d607b4e5b7198769be061454ce67b3.tar.gz llvm-67aec0cd62d607b4e5b7198769be061454ce67b3.tar.bz2 |
[LowerSwitch] Use unsigned integer for range comparison (#93237)
Commit 1db51d8eb2 switched from int64_t to `APInt` to prevent high precision integer overflow.
However, when comparing the "range" of switch cases, we should switch to unsigned integer to prevent overflow.
This patch fixes https://github.com/llvm/llvm-project/issues/93152.
Some test cases are added.
Signed-off-by: Peter Rong <PeterRong96@gmail.com>
Diffstat (limited to 'llvm/lib/Transforms/Utils/LowerSwitch.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LowerSwitch.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp index f5921e5..f4ef6d0 100644 --- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp +++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp @@ -208,7 +208,7 @@ BasicBlock *NewLeafBlock(CaseRange &Leaf, Value *Val, ConstantInt *LowerBound, PHINode *PN = cast<PHINode>(I); // Remove all but one incoming entries from the cluster APInt Range = Leaf.High->getValue() - Leaf.Low->getValue(); - for (APInt j(Range.getBitWidth(), 0, true); j.slt(Range); ++j) { + for (APInt j(Range.getBitWidth(), 0, false); j.ult(Range); ++j) { PN->removeIncomingValue(OrigBlock); } |