[spectec] Wasm 1.0: CVTOP typing accepts illegal conversion/operator combinations

Open
#2,302 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
66/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
wasm
Domain
compilers

Research direction

Start with the CVTOP typing rules in specification/wasm-1.0/6-typing.spectec and the syntax rule in specification/wasm-1.0/1-syntax.spectec. Compare the accepted combinations with the instruction forms listed in the issue's WebAssembly 1.0 PDF excerpt. Done means the rules reject illegal conversion and reinterpret combinations while accepting the listed legal forms; the issue does not name a test file.

Written by the indexing model from the issue text.

Description

The Wasm 1.0 SpecTec conversion typing rules accept arbitrary combinations of source type, destination type, and conversion operator.

In specification/wasm-1.0/6-typing.spectec:

;; TODO: move side conditions to syntax
rule Instr_ok/cvtop-reinterpret:
  C |- CVTOP nt_1 nt_2 REINTERPRET : nt_2 -> nt_1
  -- if $size(nt_1) = $size(nt_2)

rule Instr_ok/cvtop-convert:
  C |- CVTOP nt_1 nt_2 cvtop : nt_2 -> nt_1

The second rule admits every cvtop, including REINTERPRET, so it also bypasses the first rule’s check.

The syntax rule only requires distinct source and destination types:

| CVTOP valtype_1 valtype_2 cvtop
    hint(show %1.%3#_#%2)
  -- if valtype_1 =/= valtype_2

The PDF (2.4.1) restricts those combinations through syntax:

nn, mm ::= 32 | 64
sx     ::= u | s

instr ::= ...
        | i32.wrap_i64
        | i64.extend_i32_sx
        | inn.trunc_fmm_sx
        | f32.demote_f64
        | f64.promote_f32
        | fnn.convert_imm_sx
        | inn.reinterpret_fnn
        | fnn.reinterpret_inn
Dominant language
WebAssembly
Stars
3.5k
Forks
545
Avg merge
1d 4h
Merged PRs (30d)
25

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from WebAssembly/spec

All issues in WebAssembly/spec

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.