-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Closed
Labels
Description
define i32 @foo(i1 signext noundef %cond, i32 noundef %y) {
%e = zext i1 %cond to i32
%r = sub i32 %y, %e
ret i32 %r
}
Compiling with
llc --march=wasm32 -filetype=obj {ll} -o {obj}
wasm-ld --no-entry --export-all --allow-undefined {obj} -o {wasm}
(module
(type (;0;) (func))
(type (;1;) (func (param i32 i32) (result i32)))
(func $__wasm_call_ctors (type 0))
(func $foo (type 1) (param i32 i32) (result i32)
local.get 1
local.get 0
i32.add)
(memory (;0;) 2)
(global $__stack_pointer (mut i32) (i32.const 66560))
(global (;1;) i32 (i32.const 1024))
(global (;2;) i32 (i32.const 1024))
(global (;3;) i32 (i32.const 1024))
(global (;4;) i32 (i32.const 66560))
(global (;5;) i32 (i32.const 1024))
(global (;6;) i32 (i32.const 66560))
(global (;7;) i32 (i32.const 131072))
(global (;8;) i32 (i32.const 0))
(global (;9;) i32 (i32.const 1))
(export "memory" (memory 0))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
(export "foo" (func $foo))
(export "__dso_handle" (global 1))
(export "__data_end" (global 2))
(export "__stack_low" (global 3))
(export "__stack_high" (global 4))
(export "__global_base" (global 5))
(export "__heap_base" (global 6))
(export "__heap_end" (global 7))
(export "__memory_base" (global 8))
(export "__table_base" (global 9)))
The first argument of the function should subtract the second argument, but in WASM, it appears to be performing addition.
signext
attribute leads this miscompilation. without signext
compilation is correct.