Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 565df79

Browse files
committed
Address Duncan's comments on r164682:
- Finish assert messages with exclamation mark - Move overflow checking into ShouldBuildLookupTable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164692 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d0ac06d commit 565df79

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3302,8 +3302,8 @@ SwitchLookupTable::SwitchLookupTable(Module &M,
33023302
const SmallVector<std::pair<ConstantInt*, Constant*>, 4>& Values,
33033303
Constant *DefaultValue,
33043304
const TargetData *TD) {
3305-
assert(Values.size() && "Can't build lookup table without values.");
3306-
assert(TableSize >= Values.size() && "Can't fit values in table.");
3305+
assert(Values.size() && "Can't build lookup table without values!");
3306+
assert(TableSize >= Values.size() && "Can't fit values in table!");
33073307

33083308
// If all values in the table are equal, this is that value.
33093309
SingleValue = Values.begin()->second;
@@ -3431,6 +3431,8 @@ static bool ShouldBuildLookupTable(SwitchInst *SI,
34313431
// The table density should be at least 40%. This is the same criterion as for
34323432
// jump tables, see SelectionDAGBuilder::handleJTSwitchCase.
34333433
// FIXME: Find the best cut-off.
3434+
if (SI->getNumCases() > TableSize || TableSize >= UINT64_MAX / 10)
3435+
return false; // TableSize overflowed, or mul below might overflow.
34343436
if (SI->getNumCases() * 10 >= TableSize * 4)
34353437
return true;
34363438

@@ -3513,10 +3515,6 @@ static bool SwitchToLookupTable(SwitchInst *SI,
35133515
}
35143516

35153517
APInt RangeSpread = MaxCaseVal->getValue() - MinCaseVal->getValue();
3516-
// Be careful to avoid overflow when TableSize is used in
3517-
// ShouldBuildLookupTable.
3518-
if (RangeSpread.zextOrSelf(64).ugt(UINT64_MAX / 4 - 1))
3519-
return false;
35203518
uint64_t TableSize = RangeSpread.getLimitedValue() + 1;
35213519
if (!ShouldBuildLookupTable(SI, TableSize, TD, ResultTypes))
35223520
return false;

0 commit comments

Comments
 (0)