Skip to content

Commit

Permalink
Merge commit 37b7207651b4 from llvm-project (by zhongyunde@huawei.com):
Browse files Browse the repository at this point in the history
  [SimplifyCFG] Fix crash when there is unreachable large index (#88616)

  The large case index out of scope is dead code, but it is still be
  created for TableContents in SwitchLookupTable::SwitchLookupTable,
  so make sure the table size after growing should not get smaller.

  Fix llvm/llvm-project#88607

This should fix "Assertion failed: (idx < size()), function operator[]"
when building the science/dynare port.

PR:		276104, 278320
Reported by:	yuri
MFC after:	1 month
  • Loading branch information
DimitryAndric authored and bsdjhb committed Aug 9, 2024
2 parents cb7631f + 514c98b commit 2455887
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6710,9 +6710,11 @@ static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
return SwitchLookupTable::WouldFitInRegister(
DL, UpperBound, KV.second /* ResultType */);
})) {
// There may be some case index larger than the UpperBound (unreachable
// case), so make sure the table size does not get smaller.
TableSize = std::max(UpperBound, TableSize);
// The default branch is unreachable after we enlarge the lookup table.
// Adjust DefaultIsReachable to reuse code path.
TableSize = UpperBound;
DefaultIsReachable = false;
}
}
Expand Down

0 comments on commit 2455887

Please sign in to comment.