Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable not cleared #242

Open
zherczeg opened this issue Apr 19, 2024 · 1 comment
Open

Variable not cleared #242

zherczeg opened this issue Apr 19, 2024 · 1 comment

Comments

@zherczeg
Copy link
Collaborator

Test case:

(func (export "test10") (param i32) (result i32) (local i32).
   local.get 0
   if
     local.get 0
     i32.const 6
     i32.div_s
     local.set 1
   end

   local.get 1
)

Byte code dump:

     0 const32 dstOffset: 16 value: 6
    16 jump_if_false srcOffset: 0 dst: 48
    32 I32DivS src1: 0 src2: 16 dst: 8
    48 end resultOffsets: 8

It seems local 1 is not set to zero, and the function may return with garbage.

@kulcsaradam
Copy link
Contributor

Just so it does not get overlooked this is also present with br_table.

For example this code:

(func (export "f6") (param i32 ) (result i32)
  (local i32)

  (block $end
    (block
      (block
        local.get 0
        (br_table 0 1 2)
      )

      i32.const 1
      local.tee 1

      return
    )
    i32.const 2
    local.set 1
  )

  local.get 1
)

Local 1 should be initialized to zero but it is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants