How to validate the ref.func instruction #1759
-
I'm working on a single pass validator and I'm a little bit confused as to how to validate the ref.func instruction. My understanding is that the function index in the instruction must exist in C.refs. I populate refs by adding all function indices found in a module with the exception of the start function index and also the current function index if we are currently validating a functions instruction. Which seemed correct looking at these two tests: (assert_invalid
(module (func $f (drop (ref.func $f))))
"undeclared function reference"
)
(assert_invalid
(module (start $f) (func $f (drop (ref.func $f))))
"undeclared function reference"
) However I'm failing this test from the table_grow script so I must be misunderstanding 😅 (module
(table $t 0x10 funcref)
(elem declare func $f)
(func $f (export "grow") (result i32)
(table.grow $t (ref.func $f) (i32.const 0xffff_fff0))
)
) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Why are you excluding the current function? |
Beta Was this translation helpful? Give feedback.
C.refs is initialised here:
This is saying that C.refs must only include function indices that occur outside any function. Hence, the latter example fails because the only occurrence of $f is inside a function, while in the other test, $f does also occur in an element segment, so outside a function.