<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Invalid WebAssembly module generation when using alloca"
   href="https://bugs.llvm.org/show_bug.cgi?id=35205">35205</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Invalid WebAssembly module generation when using alloca
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: WebAssembly
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>talzion12@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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
<span class="quote">> var module = new WebAssembly.Module(fs.readFileSync("code.o"))</span >
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
<a href="https://nodejs.org/download/nightly/v9.0.0-nightly2017103182790d84f2/">https://nodejs.org/download/nightly/v9.0.0-nightly2017103182790d84f2/</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>