<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[285452] branches/safari-612-branch</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/285452">285452</a></dd>
<dt>Author</dt> <dd>kocsen_chung@apple.com</dd>
<dt>Date</dt> <dd>2021-11-08 17:08:35 -0800 (Mon, 08 Nov 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/282212">r282212</a>. rdar://problem/85165960

    Differential testing: incorrect constant propagation around Uint8ClampedArray
    https://bugs.webkit.org/show_bug.cgi?id=229869

    JSTests:

    Reviewed by Saam Barati.

    * stress/Uint8ClampedArrayClampsInt52Positive.js: Added.
    (let.x.123.test):
    (noInline.test.int32pos1):
    (255.int32pos2):
    (1.int32neg1):
    (0.int32neg2):
    (0.int52pos1):
    (255.int52pos2):
    (255.int52neg1):
    (0.int52neg2):
    (0.int52neg3):
    (0.int52pos3):
    (255.int8):

    Source/JavaScriptCore:

    We casted int52 values to int32 before clamping, which caused any value with the 32nd bit
    set to be interpreted as negative. The fix is to check the full-size value when deciding to clamp.

    Reviewed by Saam Barati.

    * ftl/FTLLowerDFGToB3.cpp:
    (JSC::FTL::DFG::LowerDFGToB3::compileCompareStrictEq):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@282212 268f45cc-cd09-0410-ab3c-d52691b4dbfc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari612branchJSTestsChangeLog">branches/safari-612-branch/JSTests/ChangeLog</a></li>
<li><a href="#branchessafari612branchSourceJavaScriptCoreChangeLog">branches/safari-612-branch/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchessafari612branchSourceJavaScriptCoreftlFTLLowerDFGToB3cpp">branches/safari-612-branch/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari612branchJSTestsstressUint8ClampedArrayClampsInt52Positivejs">branches/safari-612-branch/JSTests/stress/Uint8ClampedArrayClampsInt52Positive.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari612branchJSTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/JSTests/ChangeLog (285451 => 285452)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/JSTests/ChangeLog     2021-11-09 01:08:32 UTC (rev 285451)
+++ branches/safari-612-branch/JSTests/ChangeLog        2021-11-09 01:08:35 UTC (rev 285452)
</span><span class="lines">@@ -1,3 +1,62 @@
</span><ins>+2021-11-08  Kocsen Chung  <kocsen_chung@apple.com>
+
+        Cherry-pick r282212. rdar://problem/85165960
+
+    Differential testing: incorrect constant propagation around Uint8ClampedArray
+    https://bugs.webkit.org/show_bug.cgi?id=229869
+    
+    JSTests:
+    
+    Reviewed by Saam Barati.
+    
+    * stress/Uint8ClampedArrayClampsInt52Positive.js: Added.
+    (let.x.123.test):
+    (noInline.test.int32pos1):
+    (255.int32pos2):
+    (1.int32neg1):
+    (0.int32neg2):
+    (0.int52pos1):
+    (255.int52pos2):
+    (255.int52neg1):
+    (0.int52neg2):
+    (0.int52neg3):
+    (0.int52pos3):
+    (255.int8):
+    
+    Source/JavaScriptCore:
+    
+    We casted int52 values to int32 before clamping, which caused any value with the 32nd bit
+    set to be interpreted as negative. The fix is to check the full-size value when deciding to clamp.
+    
+    Reviewed by Saam Barati.
+    
+    * ftl/FTLLowerDFGToB3.cpp:
+    (JSC::FTL::DFG::LowerDFGToB3::compileCompareStrictEq):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@282212 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-09  Justin Michaud  <justin_michaud@apple.com>
+
+            Differential testing: incorrect constant propagation around Uint8ClampedArray
+            https://bugs.webkit.org/show_bug.cgi?id=229869
+
+            Reviewed by Saam Barati.
+
+            * stress/Uint8ClampedArrayClampsInt52Positive.js: Added.
+            (let.x.123.test):
+            (noInline.test.int32pos1):
+            (255.int32pos2):
+            (1.int32neg1):
+            (0.int32neg2):
+            (0.int52pos1):
+            (255.int52pos2):
+            (255.int52neg1):
+            (0.int52neg2):
+            (0.int52neg3):
+            (0.int52pos3):
+            (255.int8):
+
</ins><span class="cx"> 2021-11-04  Russell Epstein  <repstein@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Cherry-pick r283512. rdar://problem/85034084
</span></span></pre></div>
<a id="branchessafari612branchJSTestsstressUint8ClampedArrayClampsInt52Positivejs"></a>
<div class="addfile"><h4>Added: branches/safari-612-branch/JSTests/stress/Uint8ClampedArrayClampsInt52Positive.js (0 => 285452)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/JSTests/stress/Uint8ClampedArrayClampsInt52Positive.js                                (rev 0)
+++ branches/safari-612-branch/JSTests/stress/Uint8ClampedArrayClampsInt52Positive.js   2021-11-09 01:08:35 UTC (rev 285452)
</span><span class="lines">@@ -0,0 +1,79 @@
</span><ins>+let x = 123
+
+function test(fn, expected) {
+    for (let i = 0; i < 10000; i++) {
+        const arr = new Uint8ClampedArray(1)
+        fn(arr)
+        x = arr[0]
+    } 
+    
+    if (x != expected)
+        throw new Error(`Clamping was done incorrectly ${x}, expected ${expected} in ${fn}`)
+}
+noInline(test)
+
+function int32pos1(arr) {
+    arr[0] = 0x70000001|0
+}
+noInline(int32pos1)
+test(int32pos1, 255)
+
+function int32pos2(arr) {
+    arr[0] = 0x800000001|0
+}
+noInline(int32pos2)
+test(int32pos2, 1)
+
+function int32neg1(arr) {
+    arr[0] = 0x80000001|0
+}
+noInline(int32neg1)
+test(int32neg1, 0)
+
+function int32neg2(arr) {
+    arr[0] = 0x80000000|0
+}
+noInline(int32neg2)
+test(int32neg2, 0)
+
+function int52pos1(arr) {
+    arr[0] = 0x80000001
+}
+noInline(int52pos1)
+test(int52pos1, 255)
+
+function int52pos2(arr) {
+    arr[0] = 0x80000000
+}
+noInline(int52pos2)
+test(int52pos2, 255)
+
+function int52neg1(arr) {
+    arr[0] = -0x80000001
+}
+noInline(int52neg1)
+test(int52neg1, 0)
+
+function int52neg2(arr) {
+    arr[0] = -0x80000000
+}
+noInline(int52neg2)
+test(int52neg2, 0)
+
+function int52neg3(arr) {
+    arr[0] = -0x0008_0000_0000_0000
+}
+noInline(int52neg3)
+test(int52neg3, 0)
+
+function int52pos3(arr) {
+    arr[0] = 0x0007_FFFF_FFFF_FFFF
+}
+noInline(int52pos3)
+test(int52pos3, 255)
+
+function int8(arr) {
+    arr[0] = 0x8000000fe - 0x800000000
+}
+noInline(int8)
+test(int8, 254)
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="branchessafari612branchSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/JavaScriptCore/ChangeLog (285451 => 285452)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/JavaScriptCore/ChangeLog       2021-11-09 01:08:32 UTC (rev 285451)
+++ branches/safari-612-branch/Source/JavaScriptCore/ChangeLog  2021-11-09 01:08:35 UTC (rev 285452)
</span><span class="lines">@@ -1,3 +1,54 @@
</span><ins>+2021-11-08  Kocsen Chung  <kocsen_chung@apple.com>
+
+        Cherry-pick r282212. rdar://problem/85165960
+
+    Differential testing: incorrect constant propagation around Uint8ClampedArray
+    https://bugs.webkit.org/show_bug.cgi?id=229869
+    
+    JSTests:
+    
+    Reviewed by Saam Barati.
+    
+    * stress/Uint8ClampedArrayClampsInt52Positive.js: Added.
+    (let.x.123.test):
+    (noInline.test.int32pos1):
+    (255.int32pos2):
+    (1.int32neg1):
+    (0.int32neg2):
+    (0.int52pos1):
+    (255.int52pos2):
+    (255.int52neg1):
+    (0.int52neg2):
+    (0.int52neg3):
+    (0.int52pos3):
+    (255.int8):
+    
+    Source/JavaScriptCore:
+    
+    We casted int52 values to int32 before clamping, which caused any value with the 32nd bit
+    set to be interpreted as negative. The fix is to check the full-size value when deciding to clamp.
+    
+    Reviewed by Saam Barati.
+    
+    * ftl/FTLLowerDFGToB3.cpp:
+    (JSC::FTL::DFG::LowerDFGToB3::compileCompareStrictEq):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@282212 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-09  Justin Michaud  <justin_michaud@apple.com>
+
+            Differential testing: incorrect constant propagation around Uint8ClampedArray
+            https://bugs.webkit.org/show_bug.cgi?id=229869
+
+            We casted int52 values to int32 before clamping, which caused any value with the 32nd bit
+            set to be interpreted as negative. The fix is to check the full-size value when deciding to clamp.
+
+            Reviewed by Saam Barati.
+
+            * ftl/FTLLowerDFGToB3.cpp:
+            (JSC::FTL::DFG::LowerDFGToB3::compileCompareStrictEq):
+
</ins><span class="cx"> 2021-11-04  Russell Epstein  <repstein@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Cherry-pick r284036. rdar://problem/85034297
</span></span></pre></div>
<a id="branchessafari612branchSourceJavaScriptCoreftlFTLLowerDFGToB3cpp"></a>
<div class="modfile"><h4>Modified: branches/safari-612-branch/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp (285451 => 285452)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-612-branch/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp 2021-11-09 01:08:32 UTC (rev 285451)
+++ branches/safari-612-branch/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp    2021-11-09 01:08:35 UTC (rev 285452)
</span><span class="lines">@@ -17857,15 +17857,26 @@
</span><span class="cx">     
</span><span class="cx">     LValue getIntTypedArrayStoreOperand(Edge edge, bool isClamped = false)
</span><span class="cx">     {
</span><del>-        LValue intValue;
</del><ins>+        LValue valueAsInt32;
+        LValue value;
+        LValue zero;
+        LValue byteMax;
+        
</ins><span class="cx">         switch (edge.useKind()) {
</span><span class="cx">         case Int52RepUse:
</span><span class="cx">         case Int32Use: {
</span><del>-            if (edge.useKind() == Int32Use)
-                intValue = lowInt32(edge);
-            else
-                intValue = m_out.castToInt32(lowStrictInt52(edge));
-
</del><ins>+            if (edge.useKind() == Int32Use) {
+                value = lowInt32(edge);
+                valueAsInt32 = value;
+                zero = m_out.int32Zero;
+                byteMax = m_out.constInt32(255);
+            } else {
+                value = lowStrictInt52(edge);
+                valueAsInt32 = m_out.castToInt32(value);
+                zero = m_out.int64Zero;
+                byteMax = m_out.constInt64(255);
+            }
+            
</ins><span class="cx">             if (isClamped) {
</span><span class="cx">                 LBasicBlock atLeastZero = m_out.newBlock();
</span><span class="cx">                 LBasicBlock continuation = m_out.newBlock();
</span><span class="lines">@@ -17873,19 +17884,19 @@
</span><span class="cx">                 Vector<ValueFromBlock, 2> intValues;
</span><span class="cx">                 intValues.append(m_out.anchor(m_out.int32Zero));
</span><span class="cx">                 m_out.branch(
</span><del>-                    m_out.lessThan(intValue, m_out.int32Zero),
</del><ins>+                    m_out.lessThan(value, zero),
</ins><span class="cx">                     unsure(continuation), unsure(atLeastZero));
</span><span class="cx">                             
</span><span class="cx">                 LBasicBlock lastNext = m_out.appendTo(atLeastZero, continuation);
</span><span class="cx">                             
</span><span class="cx">                 intValues.append(m_out.anchor(m_out.select(
</span><del>-                    m_out.greaterThan(intValue, m_out.constInt32(255)),
</del><ins>+                    m_out.greaterThan(value, byteMax),
</ins><span class="cx">                     m_out.constInt32(255),
</span><del>-                    intValue)));
</del><ins>+                    valueAsInt32)));
</ins><span class="cx">                 m_out.jump(continuation);
</span><span class="cx">                             
</span><span class="cx">                 m_out.appendTo(continuation, lastNext);
</span><del>-                intValue = m_out.phi(Int32, intValues);
</del><ins>+                valueAsInt32 = m_out.phi(Int32, intValues);
</ins><span class="cx">             }
</span><span class="cx">             break;
</span><span class="cx">         }
</span><span class="lines">@@ -17915,9 +17926,9 @@
</span><span class="cx">                 m_out.jump(continuation);
</span><span class="cx">                             
</span><span class="cx">                 m_out.appendTo(continuation, lastNext);
</span><del>-                intValue = m_out.phi(Int32, intValues);
</del><ins>+                valueAsInt32 = m_out.phi(Int32, intValues);
</ins><span class="cx">             } else
</span><del>-                intValue = doubleToInt32(doubleValue);
</del><ins>+                valueAsInt32 = doubleToInt32(doubleValue);
</ins><span class="cx">             break;
</span><span class="cx">         }
</span><span class="cx">                         
</span><span class="lines">@@ -17925,7 +17936,7 @@
</span><span class="cx">             DFG_CRASH(m_graph, m_node, "Bad use kind");
</span><span class="cx">         }
</span><span class="cx">         
</span><del>-        return intValue;
</del><ins>+        return valueAsInt32;
</ins><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     LValue doubleToInt32(LValue doubleValue, double low, double high, bool isSigned = true)
</span></span></pre>
</div>
</div>

</body>
</html>