<?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>293107</bug_id>
          
          <creation_ts>2025-05-15 23:32:39 -0700</creation_ts>
          <short_desc>Wasm module compile error when a function contains `ref.null` after `return`</short_desc>
          <delta_ts>2025-05-31 03:01:41 -0700</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>Other</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>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>seyoon1705</reporter>
          <assigned_to name="Sosuke Suzuki">sosuke</assigned_to>
          <cc>d_degazio</cc>
    
    <cc>keith_miller</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2117558</commentid>
    <comment_count>0</comment_count>
      <attachid>475263</attachid>
    <who name="">seyoon1705</who>
    <bug_when>2025-05-15 23:32:39 -0700</bug_when>
    <thetext>Created attachment 475263
return_ref_null.js

Commit version: 9d02067f5de4b0402f58d6c83039e206439a8a8c
System: Ubuntu 20.04.6 LTS, x86_64

The following Wasm module contains three types and a function that includes `ref.null` after `return`.
```
;; return_ref_null.wat
(module
  (type $0 (func))
  (type $1 (func))
  (type $2 (func))
  (func
    (return)
    (ref.null $2)
    (drop)
  )
)
```
It is a valid Wasm module, so it must succeed to parse and validate.
However, when running `return_ref_null.js`, the equivalent JavaScript file, JavaScriptCore raises compile error.

```
$ jsc return_ref_null.js
Exception: Error: Wasm validate failure
module@return_ref_null.js:64:20
global code@return_ref_null.js:215:17
--&gt; CompileError: WebAssembly.Module doesn&apos;t parse at byte 5: can&apos;t get inline type for Block in unreachable context, in function at index 0
```

The bug is reproduced only when there are at least 3 types.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2117559</commentid>
    <comment_count>1</comment_count>
    <who name="">seyoon1705</who>
    <bug_when>2025-05-15 23:35:17 -0700</bug_when>
    <thetext>Oh, I forgot to mention one thing.
The compile error occurs when`ref.null` has immediate with type index larger than 2.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2117564</commentid>
    <comment_count>2</comment_count>
    <who name="">seyoon1705</who>
    <bug_when>2025-05-16 00:44:54 -0700</bug_when>
    <thetext>Additionally note: It doesn&apos;t have to be `return`. Same bug happens when `ref.null`  appears after `br`, `unreachable`, and `throw_ref`.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2119209</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-05-22 23:33:14 -0700</bug_when>
    <thetext>&lt;rdar://problem/151905390&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2120893</commentid>
    <comment_count>4</comment_count>
    <who name="Sosuke Suzuki">sosuke</who>
    <bug_when>2025-05-31 00:52:13 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/46164</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2120899</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-05-31 03:01:39 -0700</bug_when>
    <thetext>Committed 295644@main (d8a5f39bad4f): &lt;https://commits.webkit.org/295644@main&gt;

Reviewed commits have been landed. Closing PR #46164 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>475263</attachid>
            <date>2025-05-15 23:32:39 -0700</date>
            <delta_ts>2025-05-15 23:32:39 -0700</delta_ts>
            <desc>return_ref_null.js</desc>
            <filename>return_ref_null.js</filename>
            <type>application/x-javascript</type>
            <size>839</size>
            <attacher>seyoon1705</attacher>
            
              <data encoding="base64">J3VzZSBzdHJpY3QnOwoKZnVuY3Rpb24gbW9kdWxlKGJ5dGVzLCB2YWxpZCA9IHRydWUpIHsKICBs
ZXQgYnVmZmVyID0gbmV3IEFycmF5QnVmZmVyKGJ5dGVzLmxlbmd0aCk7CiAgbGV0IHZpZXcgPSBu
ZXcgVWludDhBcnJheShidWZmZXIpOwogIGZvciAobGV0IGkgPSAwOyBpIDwgYnl0ZXMubGVuZ3Ro
OyArK2kpIHsKICAgIHZpZXdbaV0gPSBieXRlcy5jaGFyQ29kZUF0KGkpOwogIH0KICBsZXQgdmFs
aWRhdGVkOwogIHRyeSB7CiAgICB2YWxpZGF0ZWQgPSBXZWJBc3NlbWJseS52YWxpZGF0ZShidWZm
ZXIpOwogIH0gY2F0Y2ggKGUpIHsKICAgIHRocm93IG5ldyBFcnJvcigiV2FzbSB2YWxpZGF0ZSB0
aHJvd3MiKTsKICB9CiAgaWYgKHZhbGlkYXRlZCAhPT0gdmFsaWQpIHsKICAgIGlmICghdmFsaWRh
dGVkKSBXZWJBc3NlbWJseS5jb21waWxlKGJ1ZmZlcikuY2F0Y2goZSA9PiBkZWJ1ZyhlKSk7CiAg
ICB0aHJvdyBuZXcgRXJyb3IoIldhc20gdmFsaWRhdGUgZmFpbHVyZSIgKyAodmFsaWQgPyAiIiA6
ICIgZXhwZWN0ZWQiKSk7CiAgfQogIHJldHVybiBuZXcgV2ViQXNzZW1ibHkuTW9kdWxlKGJ1ZmZl
cik7Cn0KCi8vIGJpbmFyeSBmb3JtYXQgb2YgcmV0dXJuX3JlZl9udWxsLndhdApsZXQgJCQxID0g
bW9kdWxlKCJceDAwXHg2MVx4NzNceDZkXHgwMVx4MDBceDAwXHgwMFx4MDFceDhhXHg4MFx4ODBc
eDgwXHgwMFx4MDNceDYwXHgwMFx4MDBceDYwXHgwMFx4MDBceDYwXHgwMFx4MDBceDAzXHg4Mlx4
ODBceDgwXHg4MFx4MDBceDAxXHgwMFx4MGFceDhjXHg4MFx4ODBceDgwXHgwMFx4MDFceDg2XHg4
MFx4ODBceDgwXHgwMFx4MDBceDBmXHhkMFx4MDJceDFhXHgwYiIpOwo=
</data>

          </attachment>
      

    </bug>

</bugzilla>