From 33a51342229b66eec0b80e02432bc94f39066447 Mon Sep 17 00:00:00 2001 From: Mike Danes Date: Thu, 16 Mar 2017 23:38:45 +0200 Subject: [PATCH] Fix ValueNumStore::IsVNArrLenUnsignedBound checks VNFuncApp::m_func should be checked first to be sure that m_args[0] and m_args[1] contain valid VNs. It's not clear if m_func can ever be something other than a binary func in the case of a relop VN but the code doesn't look right as it is. Commit migrated from https://github.com/dotnet/coreclr/commit/54b1709d4625d9c70a42b2e1321ae9594c49f858 --- src/coreclr/src/jit/valuenum.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/src/jit/valuenum.cpp b/src/coreclr/src/jit/valuenum.cpp index b771bf6..98251f2 100644 --- a/src/coreclr/src/jit/valuenum.cpp +++ b/src/coreclr/src/jit/valuenum.cpp @@ -3182,10 +3182,10 @@ bool ValueNumStore::IsVNArrLenUnsignedBound(ValueNum vn, ArrLenUnsignedBoundInfo if (GetVNFunc(vn, &funcApp)) { - if (IsVNArrLen(funcApp.m_args[1])) + if ((funcApp.m_func == VNF_LT_UN) || (funcApp.m_func == VNF_GE_UN)) { // We only care about "(uint)i < (uint)a.len" and its negation "(uint)i >= (uint)a.len" - if ((funcApp.m_func == VNF_LT_UN) || (funcApp.m_func == VNF_GE_UN)) + if (IsVNArrLen(funcApp.m_args[1])) { info->vnIdx = funcApp.m_args[0]; info->cmpOper = funcApp.m_func; @@ -3193,10 +3193,10 @@ bool ValueNumStore::IsVNArrLenUnsignedBound(ValueNum vn, ArrLenUnsignedBoundInfo return true; } } - else if (IsVNArrLen(funcApp.m_args[0])) + else if ((funcApp.m_func == VNF_GT_UN) || (funcApp.m_func == VNF_LE_UN)) { // We only care about "(uint)a.len > (uint)i" and its negation "(uint)a.len <= (uint)i" - if ((funcApp.m_func == VNF_GT_UN) || (funcApp.m_func == VNF_LE_UN)) + if (IsVNArrLen(funcApp.m_args[0])) { info->vnIdx = funcApp.m_args[1]; // Let's keep a consistent operand order - it's always i < a.len, never a.len > i -- 2.7.4