summaryrefslogtreecommitdiff
path: root/test/wasm2c/tail-calls.txt
diff options
context:
space:
mode:
authorSoni L. <EnderMoneyMod@gmail.com>2024-09-23 17:01:18 -0300
committerGitHub <noreply@github.com>2024-09-23 13:01:18 -0700
commit0a2a59fae573c2d793501720a2faf986118ee4f4 (patch)
treea95fd371a30945944121f1ae816491b1daf1031e /test/wasm2c/tail-calls.txt
parentb287470b53ef074332c4b0056cfc05486a85c4a7 (diff)
downloadwabt-0a2a59fae573c2d793501720a2faf986118ee4f4.tar.gz
wabt-0a2a59fae573c2d793501720a2faf986118ee4f4.tar.bz2
wabt-0a2a59fae573c2d793501720a2faf986118ee4f4.zip
wasm2c: Use wrappers for function references (#2465)
Clang 17(?) tightened UBSAN checks, so that you now get this: ``` - test/wasm2c/spec/call_indirect.txt expected error code 0, got 1. STDERR MISMATCH: --- expected +++ actual @@ -0,0 +1,3 @@ +out/test/wasm2c/spec/call_indirect/call_indirect.0.c:2144:12: runtime error: call to function w2c_call__indirect__0__wasm_f0 through pointer to incorrect function type 'unsigned int (*)(void *)' +/home/runner/work/wabt/wabt/out/test/wasm2c/spec/call_indirect/call_indirect.0.c:1925: note: w2c_call__indirect__0__wasm_f0 defined here +SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior out/test/wasm2c/spec/call_indirect/call_indirect.0.c:2144:12 STDOUT MISMATCH: --- expected +++ actual @@ -1 +0,0 @@ -134/134 tests passed. ``` This happens because emitted functions use a typed module instance, while function references use a `void*` instance. It is UB in C to call the former with the latter, so clang is correct here. We had to pick one of two ways to fix this: either emit `void*` wrapper functions that do the appropriate downcasting for any module functions that go into a table (potentially including imported functions), or the approach that takes significantly less effort of changing everything to `void*` and downcasting internally. ~~We obviously chose the latter.~~ We eventually started emitting wrapper functions.
Diffstat (limited to 'test/wasm2c/tail-calls.txt')
-rw-r--r--test/wasm2c/tail-calls.txt6
1 files changed, 5 insertions, 1 deletions
diff --git a/test/wasm2c/tail-calls.txt b/test/wasm2c/tail-calls.txt
index b27d7417..bbc02c07 100644
--- a/test/wasm2c/tail-calls.txt
+++ b/test/wasm2c/tail-calls.txt
@@ -811,8 +811,12 @@ FUNC_TYPE_T(w2c_test_i32_f32) = "\x98\x89\x5c\xbd\x28\xfd\x0e\x4d\xc5\xdc\x68\x2
FUNC_TYPE_T(w2c_test_t1) = "\x36\xa9\xe7\xf1\xc9\x5b\x82\xff\xb9\x97\x43\xe0\xc5\xc4\xce\x95\xd8\x3c\x9a\x43\x0a\xac\x59\xf8\x4e\xf3\xcb\xfa\xb6\x14\x50\x68";
FUNC_TYPE_T(w2c_test_t2) = "\xe5\x11\x86\xc7\x24\xdb\x44\x80\xbe\xd1\xe0\x89\xbc\xc0\x20\xea\xfb\x1c\x9a\x27\xa5\xc3\xdb\xca\x5d\xb0\x05\x0f\x7c\x03\x74\x0a";
+static void wrap_w2c_spectest_print_i32_f32(void *instance, u32 var_0, f32 var_1) {
+ return w2c_spectest_print_i32_f32(instance, var_0, var_1);
+}
+
static const wasm_elem_segment_expr_t elem_segment_exprs_w2c_test_e0[] = {
- {RefFunc, w2c_test_i32_f32, (wasm_rt_function_ptr_t)w2c_spectest_print_i32_f32, {wasm_tailcall_w2c_spectest_print_i32_f32}, offsetof(w2c_test, w2c_spectest_instance)},
+ {RefFunc, w2c_test_i32_f32, (wasm_rt_function_ptr_t)wrap_w2c_spectest_print_i32_f32, {wasm_tailcall_w2c_spectest_print_i32_f32}, offsetof(w2c_test, w2c_spectest_instance)},
};
static void init_tables(w2c_test* instance) {