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

Weird Code Generation #23

Closed
willemneal opened this issue Jun 20, 2018 · 3 comments
Closed

Weird Code Generation #23

willemneal opened this issue Jun 20, 2018 · 3 comments

Comments

@willemneal
Copy link

I have a simple C file:

#include <webassembly.h>

export int contract_function(int bid) {
  return bid;
}

compiled with:

wa-compile --bare -o example.wasm example.c

Which generates:

(module
 (type $0 (func (param i32) (result i32)))
 (import "env" "memory" (memory $0 1))
 (table 0 anyfunc)
 (export "contract_function" (func $0))
 (func $0 (type $0) (param $var$0 i32) (result i32)
  (block $label$0 i32
   (i32.store offset=12
    (i32.sub
     (i32.load offset=4
      (i32.const 0)
     )
     (i32.const 16)
    )
    (get_local $var$0)
   )
   (get_local $var$0)
  )
 )
)

This generates a memory RuntimeError: memory access out of bounds when I try to load it.

However, when I compile using wasmfiddle I get:

(module
 (table 0 anyfunc)
 (memory $0 1)
 (export "memory" (memory $0))
 (export "contract_function" (func $contract_function))
 (func $contract_function (; 0 ;) (param $0 i32) (result i32)
  (get_local $0)
 )
)

Any ideas?

@xtuc
Copy link

xtuc commented Jun 20, 2018

I think it comes from LLVM, I already saw a similar error.

@willemneal
Copy link
Author

Hmm could it be that the precompiled binaries used are over a year old?

@dcodeIO
Copy link
Owner

dcodeIO commented Jun 20, 2018

Yes, the binaries are quite old.

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

3 participants