[llvm-bugs] [Bug 35205] New: Invalid WebAssembly module generation when using alloca

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Nov 4 22:41:51 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=35205

            Bug ID: 35205
           Summary: Invalid WebAssembly module generation when using
                    alloca
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: WebAssembly
          Assignee: unassignedbugs at nondot.org
          Reporter: talzion12 at gmail.com
                CC: llvm-bugs at lists.llvm.org

Following is a terminal session showing the problem:

$ cat code.ll
; ModuleID = "bridge-module:bridge-module"
target triple = "wasm32-unknown-unknown-wasm"
target datalayout = ""

declare i32 @"foo"() 

define external void @"hello_world"()
{
entry:
  %".2" = alloca i32
  %".3" = call i32 @"foo"()
  ret void
}

$ llc -filetype=obj code.ll
$ wasm2wast code.o
(module
  (type (;0;) (func))
  (type (;1;) (func (result i32)))
  (import "env" "__stack_pointer" (global (;0;) i32))
  (import "env" "foo" (func $foo (type 1)))
  (func $hello_world (type 0)
    (local i32)
    get_global 0
    i32.const 16
    i32.sub
    tee_local 0
    set_global 0
    call $foo
    drop
    get_local 0
    i32.const 16
    i32.add
    set_global 0)
  (table (;0;) 0 anyfunc)
  (memory (;0;) 0)
  (export "hello_world" (func $hello_world)))
$ node --version
v9.0.0-nightly2017103182790d84f2
$ node
> var module = new WebAssembly.Module(fs.readFileSync("code.o"))
CompileError: WebAssembly.Module(): Compiling wasm function #1:hello_world
failed: immutable global #0 cannot be assigned @+132

When I try commenting out either the alloca or the call instruction in the
hello_world function, everything works fine. It seems that the set_global
instruction in the resulting WebAssembly is what's causing node to throw an
error.

I'm not sure if this is a bug in LLVM or node.
wasm2wast is a tool from the wabt tools.
I grabbed node from
https://nodejs.org/download/nightly/v9.0.0-nightly2017103182790d84f2/

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171105/c9255440/attachment.html>


More information about the llvm-bugs mailing list