js/regress/is-string-fold-tricky.html and js/regress/is-string-fold.html are crashing
authorfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Apr 2015 23:02:33 +0000 (23:02 +0000)
committerfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Apr 2015 23:02:33 +0000 (23:02 +0000)
commit099511aa520898542132de0a186151622daa62c8
treece7634c56b84c3f2406ad743fba32c1b93d83a79
parent43ee723515b8a5bbc5815961beeae0e8912cdf06
js/regress/is-string-fold-tricky.html and js/regress/is-string-fold.html are crashing
https://bugs.webkit.org/show_bug.cgi?id=144463

Reviewed by Benjamin Poulain.

Source/JavaScriptCore:

Fixup phase was super cleverly folding an IsString(@x) when @x is predicted SpecString
into a Check(String:@x) followed by JSConstant(true). Then in these tests the
ValueAdd(IsString(@x), @stuff) would try to turn this into an integer add by cleverly
converting the boolean into an integer. But as part of doing that, it would try to
short-circuit any profiling by leveraging the fact that the IsString is now a constant,
and it would try to figure out if the addition might overflow. Part of that logic
involved checking if the immediate is either a boolean or a sufficiently small integer.
But: it would check if it's a sufficiently small integer before checking if it was a
boolean, so it would try to call asNumber() on the boolean.

All of this cleverness was very deliberate, but apparently the @stuff + booleanConstant
case was previously never hit until I wrote these tests, and so we never knew that
calling asNumber() on a boolean was wrong.

The fix is super simple: the expression should just check for boolean first.

This bug was benign in release builds. JSValue::asNumber() on a boolean would return
garbage, and that's OK, since we'd take the boolean case anyway.

* dfg/DFGGraph.h:
(JSC::DFG::Graph::addImmediateShouldSpeculateInt32):

LayoutTests:

Unskip now that the bug is fixed.

* TestExpectations:
* js/regress/script-tests/is-string-fold-tricky.js:
* js/regress/script-tests/is-string-fold.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183650 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/js/regress/script-tests/is-string-fold-tricky.js
LayoutTests/js/regress/script-tests/is-string-fold.js
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/dfg/DFGGraph.h