<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 - Initializing an array of structs at compile time clang fails when targeting wasm32-unknown-unknown-wasm"
href="https://bugs.llvm.org/show_bug.cgi?id=33624">33624</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Initializing an array of structs at compile time clang fails when targeting wasm32-unknown-unknown-wasm
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</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>release blocker
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>wink@saville.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>There is a bug initializing arrays with structures such as `gBd` below:
$ cat src/ainit.h
struct bd {
char d;
};
extern struct bd gBd[];
$ cat src/ainit.c
#include "ainit.h"
struct bd gBd[2] = {{1}, {2}};
If this is compiled using clang -> llc -> s2wasm -> wast2wasm toolchain:
/home/wink/prgs/llvmwasm-builder/dist/bin/clang -emit-llvm --target=wasm32 -O3
-Weverything -Werror -std=c11 -DDBG=0 src/ainit.c -c -o out/src/ainit.c.bc
/home/wink/prgs/llvmwasm-builder/dist/bin/llc -asm-verbose=false
out/src/ainit.c.bc -o out/src/ainit.c.s
/home/wink/prgs/llvmwasm-builder/dist/bin/s2wasm out/src/ainit.c.s -o
out/src/ainit.c.wast
/home/wink/prgs/llvmwasm-builder/dist/bin/wast2wasm out/src/ainit.c.wast -o
out/src/ainit.c.wasm
The output is correct and we see the data section initialized with 0x01, 0x02
in consectutive memory:
$ cat out/src/ainit.c.wast
(module
(table 0 anyfunc)
(memory $0 1)
(data (i32.const 16) "\01\02")
(export "memory" (memory $0))
)
But if you use clang with --target=wasm32-unknown-unknown-wasm:
/home/wink/prgs/llvmwasm-builder/dist/bin/clang
--target=wasm32-unknown-unknown-wasm -O3 -Weverything -Werror -std=c11 -DDBG=0
src/ainit.c -c -o out/src/ainit.wasm
/home/wink/prgs/llvmwasm-builder/dist/bin/wasm2wast out/src/ainit.wasm -o
out/src/ainit.wast
The output is incorrect. Specifically in the data section the 0x01 and 0x02 are
not in consecutive locations:
$ cat out/src/ainit.wast
(module
(table (;0;) 0 anyfunc)
(memory (;0;) 1)
(global (;0;) i32 (i32.const 0))
(export "gBd" (global 0))
(data (i32.const 0) "\01\00\00\02\00\00"))
A git repo is here:
<a href="https://github.com/winksaville/test-wasm-array-initialization">https://github.com/winksaville/test-wasm-array-initialization</a>
This was built using trunk as of the evening of June 27, 2017 PDST.</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>