[llvm-bugs] [Bug 33624] New: Initializing an array of structs at compile time clang fails when targeting wasm32-unknown-unknown-wasm

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 28 08:00:51 PDT 2017


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

            Bug ID: 33624
           Summary: Initializing an array of structs at compile time clang
                    fails when targeting wasm32-unknown-unknown-wasm
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: wink at saville.com
                CC: llvm-bugs at lists.llvm.org

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:
https://github.com/winksaville/test-wasm-array-initialization

This was built using trunk as of the evening of June 27, 2017 PDST.

-- 
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/20170628/ec429032/attachment-0001.html>


More information about the llvm-bugs mailing list