Skip to content

Commit 1e6810e

Browse files
committed
[MERGE #295] Uint32 constant
Merge pull request #295 from LouisLaf:intconst Properly cast to uint32 a TyUint32 offset to avoid having it sign extended to 64bit on x64.
2 parents bcae1ff + 3c03876 commit 1e6810e

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

lib/Backend/Chakra.Backend.vcxproj.filters

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@
102102
<ClCompile Include="$(MSBuildThisFileDirectory)arm\UnwindInfoManager.cpp">
103103
<Filter>arm</Filter>
104104
</ClCompile>
105-
<ClCompile Include="$(MSBuildThisFileDirectory)arm64\EncoderMD.cpp" />
106105
<ClCompile Include="$(MSBuildThisFileDirectory)Inline.cpp" />
107106
<ClCompile Include="$(MSBuildThisFileDirectory)GlobOptSimd128.cpp" />
108107
<ClCompile Include="$(MSBuildThisFileDirectory)SwitchIRBuilder.cpp" />
108+
<ClCompile Include="$(MSBuildThisFileDirectory)arm64\EncoderMD.cpp">
109+
<Filter>arm64</Filter>
110+
</ClCompile>
109111
</ItemGroup>
110112
<ItemGroup>
111113
<ClInclude Include="AgenPeeps.h" />
@@ -336,4 +338,4 @@
336338
<Filter>arm</Filter>
337339
</ARMASM>
338340
</ItemGroup>
339-
</Project>
341+
</Project>

lib/Backend/Lower.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14897,14 +14897,14 @@ Lowerer::GenerateFastStringLdElem(IR::Instr * ldElem, IR::LabelInstr * labelHelp
1489714897
{
1489814898
// Just use the offset to indirect into the string buffer
1489914899
charIndirOpnd = IR::IndirOpnd::New(bufferOpnd, indirOpnd->GetOffset() * sizeof(wchar_t), TyUint16, this->m_func);
14900-
index32CmpOpnd = IR::IntConstOpnd::New(indirOpnd->GetOffset(), TyUint32, this->m_func);
14900+
index32CmpOpnd = IR::IntConstOpnd::New((uint32)indirOpnd->GetOffset(), TyUint32, this->m_func);
1490114901
}
1490214902

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

1491014910
// Load the string buffer and make sure it is not null
@@ -14920,7 +14920,7 @@ Lowerer::GenerateFastStringLdElem(IR::Instr * ldElem, IR::LabelInstr * labelHelp
1492014920
// MOV charOpnd, [bufferOpnd + index32Opnd]
1492114921
// CMP charOpnd, 0x80
1492214922
// JAE $helper
14923-
IR::RegOpnd * charOpnd = IR::RegOpnd::New(TyInt32, this->m_func);
14923+
IR::RegOpnd * charOpnd = IR::RegOpnd::New(TyUint32, this->m_func);
1492414924
const IR::AutoReuseOpnd autoReuseCharOpnd(charOpnd, m_func);
1492514925
InsertMove(charOpnd, charIndirOpnd, ldElem);
1492614926
InsertCompareBranch(charOpnd, IR::IntConstOpnd::New(Js::CharStringCache::CharStringCacheSize, TyUint16, this->m_func),

test/Strings/neg_index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
//reduced switches: -maxsimplejitruncount:1 -maxinterpretcount:1
7+
8+
var zibhbj;
9+
10+
for (i=0; i<10000; i++) {
11+
zibhbj = 'u{3402e}'[-1];
12+
}
13+
if (zibhbj === undefined)
14+
{
15+
WScript.Echo("Passed");
16+
}
17+
else
18+
{
19+
WScript.Echo("FAILED");
20+
}

test/Strings/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@
133133
<baseline>indexOf.baseline</baseline>
134134
</default>
135135
</test>
136+
<test>
137+
<default>
138+
<files>neg_index.js</files>
139+
</default>
140+
</test>
136141
<test>
137142
<default>
138143
<files>substring.js</files>

0 commit comments

Comments
 (0)