⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243277 in webkit


Ignore:
Timestamp:
Mar 20, 2019, 10:41:21 PM (7 years ago)
Author:
sbarati@apple.com
Message:

typeOfDoubleSum is wrong for when NaN can be produced
https://bugs.webkit.org/show_bug.cgi?id=196030

Reviewed by Filip Pizlo.

JSTests:

  • stress/double-add-sub-mul-can-produce-nan.js: Added.

(assert):
(noInline.sub):
(noInline):
(assert.mul):
(assert.add):

Source/JavaScriptCore:

We were using typeOfDoubleSum(SpeculatedType, SpeculatedType) for add/sub/mul.
It assumed that the only way the resulting type could be NaN is if one of
the inputs were NaN. However, this is wrong. NaN can be produced in at least
these cases:

Infinity - Infinity
Infinity + (-Infinity)
Infinity * 0

  • bytecode/SpeculatedType.cpp:

(JSC::typeOfDoubleSumOrDifferenceOrProduct):
(JSC::typeOfDoubleSum):
(JSC::typeOfDoubleDifference):
(JSC::typeOfDoubleProduct):

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r243265 r243277  
     12019-03-20  Saam Barati  <sbarati@apple.com>
     2
     3        typeOfDoubleSum is wrong for when NaN can be produced
     4        https://bugs.webkit.org/show_bug.cgi?id=196030
     5
     6        Reviewed by Filip Pizlo.
     7
     8        * stress/double-add-sub-mul-can-produce-nan.js: Added.
     9        (assert):
     10        (noInline.sub):
     11        (noInline):
     12        (assert.mul):
     13        (assert.add):
     14
    1152019-03-20  Yusuke Suzuki  <ysuzuki@apple.com>
    216
  • trunk/Source/JavaScriptCore/ChangeLog

    r243275 r243277  
     12019-03-20  Saam Barati  <sbarati@apple.com>
     2
     3        typeOfDoubleSum is wrong for when NaN can be produced
     4        https://bugs.webkit.org/show_bug.cgi?id=196030
     5
     6        Reviewed by Filip Pizlo.
     7
     8        We were using typeOfDoubleSum(SpeculatedType, SpeculatedType) for add/sub/mul.
     9        It assumed that the only way the resulting type could be NaN is if one of
     10        the inputs were NaN. However, this is wrong. NaN can be produced in at least
     11        these cases:
     12          Infinity - Infinity
     13          Infinity + (-Infinity)
     14          Infinity * 0
     15
     16        * bytecode/SpeculatedType.cpp:
     17        (JSC::typeOfDoubleSumOrDifferenceOrProduct):
     18        (JSC::typeOfDoubleSum):
     19        (JSC::typeOfDoubleDifference):
     20        (JSC::typeOfDoubleProduct):
     21
    1222019-03-20  Simon Fraser  <simon.fraser@apple.com>
    223
  • trunk/Source/JavaScriptCore/bytecode/SpeculatedType.cpp

    r242990 r243277  
    613613}
    614614
    615 SpeculatedType typeOfDoubleSum(SpeculatedType a, SpeculatedType b)
     615static SpeculatedType typeOfDoubleSumOrDifferenceOrProduct(SpeculatedType a, SpeculatedType b)
    616616{
    617617    SpeculatedType result = a | b;
     618
     619    if (result & SpecNonIntAsDouble) {
     620        // NaN can be produced by:
     621        // Infinity - Infinity
     622        // Infinity + (-Infinity)
     623        // Infinity * 0
     624        result |= SpecDoublePureNaN;
     625    }
     626
    618627    // Impure NaN could become pure NaN during addition because addition may clear bits.
    619628    if (result & SpecDoubleImpureNaN)
     
    625634}
    626635
     636SpeculatedType typeOfDoubleSum(SpeculatedType a, SpeculatedType b)
     637{
     638    return typeOfDoubleSumOrDifferenceOrProduct(a, b);
     639}
     640
    627641SpeculatedType typeOfDoubleDifference(SpeculatedType a, SpeculatedType b)
    628642{
    629     return typeOfDoubleSum(a, b);
     643    return typeOfDoubleSumOrDifferenceOrProduct(a, b);
    630644}
    631645
    632646SpeculatedType typeOfDoubleProduct(SpeculatedType a, SpeculatedType b)
    633647{
    634     return typeOfDoubleSum(a, b);
     648    return typeOfDoubleSumOrDifferenceOrProduct(a, b);
    635649}
    636650
Note: See TracChangeset for help on using the changeset viewer.