<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>267381</bug_id>
          
          <creation_ts>2024-01-10 16:15:02 -0800</creation_ts>
          <short_desc>[Wasm-GC] Fix write barrier bug in BBQ array.set</short_desc>
          <delta_ts>2024-01-11 10:10:14 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebAssembly</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>247394</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Asumu Takikawa">asumu</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>bashorov</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2004260</commentid>
    <comment_count>0</comment_count>
    <who name="Asumu Takikawa">asumu</who>
    <bug_when>2024-01-10 16:15:02 -0800</bug_when>
    <thetext>A recent PR added JIT inlining for array ops, and also has write barriers for these situations. Unfortunately while the write barrier is in the right place, the condition to add them is slightly wrong.

Test case:

```
//@ runWebAssemblySuite(&quot;--useWebAssemblyTypedFunctionReferences=true&quot;, &quot;--useWebAssemblyGC=true&quot;, &quot;--useWebAssemblyExtendedConstantExpressions=true&quot;)                                                        
                                                                                                                                                                                                              
import * as assert from &quot;../assert.js&quot;;                                                                                                                                                                       
import { instantiate } from &quot;./wast-wrapper.js&quot;;                                                                                                                                                              
                                                                                                                                                                                                              
{                                                                                                                                                                                                             
  const m1 = instantiate(`                                                                                                                                                                                    
    (module     
      (type (struct (field i32)))
      (type (array (mut (ref null 0))))
      (func (export &quot;maker&quot;) (result (ref 1))
        (array.new_default 1 (i32.const 5))))
  `);           
                                                   
  const arr = m1.exports.maker();
  assert.isObject(arr);
                                                   
  // Do a GC to ensure the array is an old object.
  gc();            
                                                   
  const m2 = instantiate(`
    (module        
      (type (struct (field i32)))
      (type (array (mut (ref null 0))))
      (func (export &quot;set&quot;) (param (ref 1) i32)
        (array.set 1 (local.get 0) (local.get 1) (struct.new 0 (i32.const 42))))                       
      (func (export &quot;get&quot;) (param (ref 1) i32) (result i32)                                            
        (struct.get 0 0 (array.get 1 (local.get 0) (local.get 1)))))                                                                                                                                          
  `); 
                                                   
  for (var i = 0; i &lt; 5; i++)                                                                                                                                                                                 
    m2.exports.set(arr, i);                                                                                                                                                                                   
                                                                                                                                                                                                              
  // Do an eden GC to test write barriers.                                                                                                                                                                    
  edenGC();                                                                                                                                                                                                   
                                                                                                                                                                                                              
  for (var i = 0; i &lt; 5; i++)                                                                          
    assert.eq(m2.exports.get(arr, i), 42);
}     
```

The fix is straightforward (just fix the condition to check the right type).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2004263</commentid>
    <comment_count>1</comment_count>
    <who name="Asumu Takikawa">asumu</who>
    <bug_when>2024-01-10 16:27:12 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/22630</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2004480</commentid>
    <comment_count>2</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-01-11 10:09:39 -0800</bug_when>
    <thetext>Committed 272923@main (6decd847ff17): &lt;https://commits.webkit.org/272923@main&gt;

Reviewed commits have been landed. Closing PR #22630 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2004481</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-01-11 10:10:14 -0800</bug_when>
    <thetext>&lt;rdar://problem/120852672&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>