From 36bd13455b1e28c3918ced442f225e775363239e Mon Sep 17 00:00:00 2001 From: Ben Cheng Date: Mon, 25 Oct 2010 20:54:31 -0700 Subject: [PATCH] Fix for array lower-bound check for count-down loops. If the counted loop is composed as for (int i = hi; i >= lo; i--) { .. = array[i]; } The hoisted lower-bound check should be asserting "lo >= 0". On the other hand if the counted loop is composed as for (int i = hi; i > lo; i--) { .. = array[i]; } The hoisted lower-bound check should be asserting "lo + 1 >= 0". Previously these two checks are reversed. Bug: 3130818 Change-Id: Ibc5a6daa837880e9986e45bbc29d1a5e548be3ae --- vm/compiler/Loop.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vm/compiler/Loop.c b/vm/compiler/Loop.c index 78f57179e..918d95560 100644 --- a/vm/compiler/Loop.c +++ b/vm/compiler/Loop.c @@ -435,11 +435,12 @@ static void genHoistedChecks(CompilationUnit *cUnit) boundCheckMIR->dalvikInsn.vA = loopAnalysis->endConditionReg; boundCheckMIR->dalvikInsn.vB = globalMinC; /* - * If the end condition is ">", add 1 back to the constant field - * to reflect the fact that the smallest index value is - * "endValue + constant + 1". + * If the end condition is ">" in the source, the check in the + * Dalvik bytecode is OP_IF_LE. In this case add 1 back to the + * constant field to reflect the fact that the smallest index + * value is "endValue + constant + 1". */ - if (loopAnalysis->loopBranchOpcode == OP_IF_LT) { + if (loopAnalysis->loopBranchOpcode == OP_IF_LE) { boundCheckMIR->dalvikInsn.vB++; } dvmCompilerAppendMIR(entry, boundCheckMIR); -- 2.11.0