Skip to content

Commit 0a76bfc

Browse files
committed
Invertloop issue.
When we invertloop in the bytecode gen time, we didn't copy the call node correctly. That triggerred the assert. Fixed the copynode code for the call node.
1 parent c391c55 commit 0a76bfc

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

lib/Parser/Parse.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11440,11 +11440,18 @@ ParseNode* Parser::CopyPnode(ParseNode *pnode) {
1144011440
return pnode;
1144111441
//PTNODE(knopFalse , "false" ,False ,None ,fnopLeaf)
1144211442
case knopFalse:
11443-
return CreateNodeT<knopFalse>(pnode->ichMin,pnode->ichLim);
11444-
break;
11443+
{
11444+
ParseNode* ret = CreateNodeT<knopFalse>(pnode->ichMin, pnode->ichLim);
11445+
ret->location = pnode->location;
11446+
return ret;
11447+
}
1144511448
//PTNODE(knopTrue , "true" ,True ,None ,fnopLeaf)
1144611449
case knopTrue:
11447-
return CreateNodeT<knopTrue>(pnode->ichMin,pnode->ichLim);
11450+
{
11451+
ParseNode* ret = CreateNodeT<knopTrue>(pnode->ichMin, pnode->ichLim);
11452+
ret->location = pnode->location;
11453+
return ret;
11454+
}
1144811455
//PTNODE(knopEmpty , "empty" ,Empty ,None ,fnopLeaf)
1144911456
case knopEmpty:
1145011457
return CreateNodeT<knopEmpty>(pnode->ichMin,pnode->ichLim);
@@ -11574,8 +11581,8 @@ ParseNode* Parser::CopyPnode(ParseNode *pnode) {
1157411581
//PTNODE(knopNew , "new" ,None ,Bin ,fnopBin)
1157511582
case knopNew:
1157611583
case knopCall:
11577-
return CreateCallNode(pnode->nop,CopyPnode(pnode->sxBin.pnode1),
11578-
CopyPnode(pnode->sxBin.pnode2),pnode->ichMin,pnode->ichLim);
11584+
return CreateCallNode(pnode->nop,CopyPnode(pnode->sxCall.pnodeTarget),
11585+
CopyPnode(pnode->sxCall.pnodeArgs),pnode->ichMin,pnode->ichLim);
1157911586
//PTNODE(knopQmark , "?" ,None ,Tri ,fnopBin)
1158011587
case knopQmark:
1158111588
return CreateTriNode(pnode->nop,CopyPnode(pnode->sxTri.pnode1),

test/Bugs/invertloop_bug.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// Triggering invertloop codepath and ensuring the copying of nodes happens correctly.
7+
8+
function foo() {
9+
for (var a = 0; a < 1; ++a) {
10+
for (var b = 0; b < 11; ++b) {
11+
(true());
12+
}
13+
};
14+
15+
};
16+
17+
try {
18+
foo();
19+
} catch(e) {
20+
print(e.message === 'Function expected' ? 'pass' : 'fail');
21+
}

test/Bugs/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,10 @@
324324
<compile-flags>-simdjs -asmjs -testtrace:asmjs -asmjsstoponerror</compile-flags>
325325
</default>
326326
</test>
327+
<test>
328+
<default>
329+
<files>invertloop_bug.js</files>
330+
<tags>exclude_dynapogo</tags>
331+
</default>
332+
</test>
327333
</regress-exe>

0 commit comments

Comments
 (0)