Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: src/IceSwitchLowering.cpp

Issue 1247833003: Handle UINT64_MAX edge case in switch lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Make test more readable. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests_lit/llvm2ice_tests/adv-switch-opt.ll » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceSwitchLowering.cpp
diff --git a/src/IceSwitchLowering.cpp b/src/IceSwitchLowering.cpp
index 06894e6269b4ece4a51d9635c3f040f4db022d49..37e67c12c005651223b84d13b1738b9e2b149a9f 100644
--- a/src/IceSwitchLowering.cpp
+++ b/src/IceSwitchLowering.cpp
@@ -75,9 +75,13 @@ CaseClusterArray CaseCluster::clusterizeSwitch(Cfg *Func,
// Replace everything with a jump table
InstJumpTable *JumpTable =
InstJumpTable::create(Func, TotalRange, Inst->getLabelDefault());
- for (const CaseCluster &Case : CaseClusters)
- for (uint64_t I = Case.Low; I <= Case.High; ++I)
+ for (const CaseCluster &Case : CaseClusters) {
+ // Case.High could be UINT64_MAX which makes the loop awkward. Unwrap the
+ // last iteration to avoid wrap around problems.
+ for (uint64_t I = Case.Low; I < Case.High; ++I)
JumpTable->addTarget(I - MinValue, Case.Label);
+ JumpTable->addTarget(Case.High - MinValue, Case.Label);
+ }
CaseClusters.clear();
CaseClusters.emplace_back(MinValue, MaxValue, JumpTable);
« no previous file with comments | « no previous file | tests_lit/llvm2ice_tests/adv-switch-opt.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698