diff options
| author | 2019-01-31 13:58:33 +0000 | |
|---|---|---|
| committer | 2019-01-31 13:58:33 +0000 | |
| commit | 9942b38103fcaba2a6350d97f2f504b2c3a28bc6 (patch) | |
| tree | 20b0276ec03980d1b8ca4cac2edd0dc4c21c5276 | |
| parent | fcde77c303e19b7f4f734feb61fa58740d95d215 (diff) | |
| parent | 53a41ac9305f3c435cbb975d773bbdb5490d8321 (diff) | |
Merge "ART: Fix off-by-one error in BCE."
| -rw-r--r-- | compiler/optimizing/bounds_check_elimination.cc | 6 | ||||
| -rw-r--r-- | test/622-checker-bce-regressions/src/Main.java | 18 |
2 files changed, 22 insertions, 2 deletions
diff --git a/compiler/optimizing/bounds_check_elimination.cc b/compiler/optimizing/bounds_check_elimination.cc index 54a1ae9f9e..e35d50220e 100644 --- a/compiler/optimizing/bounds_check_elimination.cc +++ b/compiler/optimizing/bounds_check_elimination.cc @@ -845,8 +845,10 @@ class BCEVisitor : public HGraphVisitor { // make one more attempt to get a constant in the array range. ValueRange* existing_range = LookupValueRange(array_length, block); if (existing_range != nullptr && - existing_range->IsConstantValueRange()) { - ValueRange constant_array_range(&allocator_, lower, existing_range->GetLower()); + existing_range->IsConstantValueRange() && + existing_range->GetLower().GetConstant() > 0) { + ValueBound constant_upper(nullptr, existing_range->GetLower().GetConstant() - 1); + ValueRange constant_array_range(&allocator_, lower, constant_upper); if (index_range->FitsIn(&constant_array_range)) { ReplaceInstruction(bounds_check, index); return; diff --git a/test/622-checker-bce-regressions/src/Main.java b/test/622-checker-bce-regressions/src/Main.java index 6ba2644b97..595ade8ff6 100644 --- a/test/622-checker-bce-regressions/src/Main.java +++ b/test/622-checker-bce-regressions/src/Main.java @@ -42,8 +42,22 @@ public class Main { return j; } + static public void $noinline$regressionTest123284765(String str) { + try { + int l = str.length(); + if (l == 34) { + str.charAt(l); + fail(); + } + } catch (StringIndexOutOfBoundsException expected) { + expectEquals(34, str.length()); + } + } + public static void main(String[] args) { expectEquals(8, doNotVisitAfterForwardBCE(array)); + $noinline$regressionTest123284765("0123456789012345678901234567890123"); + $noinline$regressionTest123284765("012345678901"); System.out.println("passed"); } @@ -52,4 +66,8 @@ public class Main { throw new Error("Expected: " + expected + ", found: " + result); } } + + private static void fail() { + throw new Error("FAIL"); + } } |