Skip to content

Commit f00433e

Browse files
author
Meghana Gupta
committed
OS#19035235:Fix constant branch folding for BrOnObject
BrOnObject is true for non-primitives, false for primitives. We were relying on IsDefinite along with IsPrimitive check to constant fold BrOnObject. But this is not sufficient for a valueType like Null | Object. IsPrimitive returns false because it sees the Object bit, we cannot constant fold BrOnObject to true with just this check. Because the valueType can also be Null. This change fixes this.
1 parent 71a3562 commit f00433e

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

lib/Backend/GlobOpt.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6956,7 +6956,20 @@ GlobOpt::CanProveConditionalBranch(IR::Instr *instr, Value *src1Val, Value *src2
69566956
{
69576957
return false;
69586958
}
6959-
*result = !src1ValueInfo->IsPrimitive();
6959+
6960+
if (src1ValueInfo->IsPrimitive())
6961+
{
6962+
*result = false;
6963+
}
6964+
else
6965+
{
6966+
if (src1ValueInfo->HasBeenPrimitive())
6967+
{
6968+
return false;
6969+
}
6970+
*result = true;
6971+
}
6972+
69606973
break;
69616974
}
69626975
default:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[object Object]
2+
[object Object]
3+
[object Object]

test/Optimizer/bugconstfoldobject.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
function test0() {
7+
class class3 {
8+
constructor() {
9+
return '9'.match(/^(?=[a7])$/gim);
10+
}
11+
}
12+
strvar0 = new class3();
13+
new class3();
14+
WScript.Echo(strvar0);
15+
}
16+
test0();
17+
test0();
18+
test0();
19+

0 commit comments

Comments
 (0)