From 3b521a1e189b7eee051cf78c6981e7b869248eeb Mon Sep 17 00:00:00 2001 From: yujianfeng Date: Mon, 22 Mar 2021 09:14:36 +0800 Subject: [PATCH] Fix the case of negative index in GetitemDependReorder --- .../frontend/optimizer/irpass/item_tuple_or_list_eliminate.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/item_tuple_or_list_eliminate.h b/mindspore/ccsrc/frontend/optimizer/irpass/item_tuple_or_list_eliminate.h index 2e7ac661471..ad6657218d7 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/item_tuple_or_list_eliminate.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/item_tuple_or_list_eliminate.h @@ -370,7 +370,10 @@ class GetitemDependReorder : public AnfVisitor { int64_t idx = idx_value->value(); if (abs->isa()) { auto abs_tuple = abs->cast(); - if (LongToSize(idx) >= abs_tuple->elements().size() || idx < 0) { + if (idx < 0) { + idx += abs_tuple->elements().size(); + } + if (idx < 0 || LongToSize(idx) >= abs_tuple->elements().size()) { MS_LOG(EXCEPTION) << "The idx value " << idx << " of tuple_getitem node " << c_->DebugString() << " is out of range."; }