Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/Backend/Chakra.Backend.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@
<ClCompile Include="$(MSBuildThisFileDirectory)arm\UnwindInfoManager.cpp">
<Filter>arm</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)arm64\EncoderMD.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)Inline.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)GlobOptSimd128.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)SwitchIRBuilder.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)arm64\EncoderMD.cpp">
<Filter>arm64</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="AgenPeeps.h" />
Expand Down Expand Up @@ -336,4 +338,4 @@
<Filter>arm</Filter>
</ARMASM>
</ItemGroup>
</Project>
</Project>
6 changes: 3 additions & 3 deletions lib/Backend/Lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14897,14 +14897,14 @@ Lowerer::GenerateFastStringLdElem(IR::Instr * ldElem, IR::LabelInstr * labelHelp
{
// Just use the offset to indirect into the string buffer
charIndirOpnd = IR::IndirOpnd::New(bufferOpnd, indirOpnd->GetOffset() * sizeof(wchar_t), TyUint16, this->m_func);
index32CmpOpnd = IR::IntConstOpnd::New(indirOpnd->GetOffset(), TyUint32, this->m_func);
index32CmpOpnd = IR::IntConstOpnd::New((uint32)indirOpnd->GetOffset(), TyUint32, this->m_func);
}

// Check if the index is in range of the string length
// CMP [baseOpnd + offset(length)], indexOpnd -- string length
// JBE $helper -- unsigned compare, and string length are at most INT_MAX - 1
// -- so that even if we have a negative index, this will fail
InsertCompareBranch(IR::IndirOpnd::New(baseOpnd, offsetof(Js::JavascriptString, m_charLength), TyInt32, this->m_func)
InsertCompareBranch(IR::IndirOpnd::New(baseOpnd, offsetof(Js::JavascriptString, m_charLength), TyUint32, this->m_func)
, index32CmpOpnd, Js::OpCode::BrLe_A, true, labelHelper, ldElem);

// Load the string buffer and make sure it is not null
Expand All @@ -14920,7 +14920,7 @@ Lowerer::GenerateFastStringLdElem(IR::Instr * ldElem, IR::LabelInstr * labelHelp
// MOV charOpnd, [bufferOpnd + index32Opnd]
// CMP charOpnd, 0x80
// JAE $helper
IR::RegOpnd * charOpnd = IR::RegOpnd::New(TyInt32, this->m_func);
IR::RegOpnd * charOpnd = IR::RegOpnd::New(TyUint32, this->m_func);
const IR::AutoReuseOpnd autoReuseCharOpnd(charOpnd, m_func);
InsertMove(charOpnd, charIndirOpnd, ldElem);
InsertCompareBranch(charOpnd, IR::IntConstOpnd::New(Js::CharStringCache::CharStringCacheSize, TyUint16, this->m_func),
Expand Down
20 changes: 20 additions & 0 deletions test/Strings/neg_index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

//reduced switches: -maxsimplejitruncount:1 -maxinterpretcount:1

var zibhbj;

for (i=0; i<10000; i++) {
zibhbj = 'u{3402e}'[-1];
}
if (zibhbj === undefined)
{
WScript.Echo("Passed");
}
else
{
WScript.Echo("FAILED");
}
5 changes: 5 additions & 0 deletions test/Strings/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@
<baseline>indexOf.baseline</baseline>
</default>
</test>
<test>
<default>
<files>neg_index.js</files>
</default>
</test>
<test>
<default>
<files>substring.js</files>
Expand Down