summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-06-24 11:32:37 -0700
committerGitHub <noreply@github.com>2021-06-24 11:32:37 -0700
commit1b0d724fd5938931e6924941641dd8924ad49938 (patch)
tree704722f4c2d6785289e712b66957a33757dbb484 /test
parent21711ffea3cea19cab52bbd989a1c8638b3dd9a7 (diff)
downloadbinaryen-1b0d724fd5938931e6924941641dd8924ad49938.tar.gz
binaryen-1b0d724fd5938931e6924941641dd8924ad49938.tar.bz2
binaryen-1b0d724fd5938931e6924941641dd8924ad49938.zip
Handle invokes of invalid function pointers. See #14174 (#3951)
PostEmscripten will turn an invoke of a constant function pointer index into a direct call. However, due to UB it is possible to have invalid function pointers, and we should not crash on that (and do nothing to optimize, of course). Mostly whitespace; to avoid deep nesting, I added more early returns.
Diffstat (limited to 'test')
-rw-r--r--test/passes/post-emscripten.txt17
-rw-r--r--test/passes/post-emscripten.wast15
2 files changed, 25 insertions, 7 deletions
diff --git a/test/passes/post-emscripten.txt b/test/passes/post-emscripten.txt
index 36f8a4dab..5acb7e355 100644
--- a/test/passes/post-emscripten.txt
+++ b/test/passes/post-emscripten.txt
@@ -1,14 +1,11 @@
(module
(type $i32_f32_=>_none (func (param i32 f32)))
- (type $none_=>_none (func))
(type $i32_i32_f32_=>_none (func (param i32 i32 f32)))
+ (type $none_=>_none (func))
(import "env" "invoke_vif" (func $invoke_vif (param i32 i32 f32)))
(memory $0 256 256)
(table $0 7 7 funcref)
- (elem (i32.const 0) $f1 $exc $other_safe $other_unsafe $deep_safe $deep_unsafe)
- (func $f1
- (nop)
- )
+ (elem (i32.const 1) $exc $other_safe $other_unsafe $deep_safe $deep_unsafe)
(func $exc
(call $other_safe
(i32.const 42)
@@ -34,6 +31,16 @@
(i32.const 42)
(f32.const 3.141590118408203)
)
+ (call $invoke_vif
+ (i32.const 0)
+ (i32.const 42)
+ (f32.const 3.141590118408203)
+ )
+ (call $invoke_vif
+ (i32.const 1337)
+ (i32.const 42)
+ (f32.const 3.141590118408203)
+ )
)
(func $other_safe (param $0 i32) (param $1 f32)
(nop)
diff --git a/test/passes/post-emscripten.wast b/test/passes/post-emscripten.wast
index 99fa3b57b..3c3eb6cdd 100644
--- a/test/passes/post-emscripten.wast
+++ b/test/passes/post-emscripten.wast
@@ -3,8 +3,7 @@
(import "env" "invoke_vif" (func $invoke_vif (param i32 i32 f32)))
(memory 256 256)
(table 7 7 funcref)
- (elem (i32.const 0) $f1 $exc $other_safe $other_unsafe $deep_safe $deep_unsafe)
- (func $f1)
+ (elem (i32.const 1) $exc $other_safe $other_unsafe $deep_safe $deep_unsafe)
(func $exc
(call $invoke_vif
(i32.const 2) ;; other_safe()
@@ -31,6 +30,18 @@
(i32.const 42)
(f32.const 3.14159)
)
+ ;; there is no function at index 0, so this cannot be optimized
+ (call $invoke_vif
+ (i32.const 0)
+ (i32.const 42)
+ (f32.const 3.14159)
+ )
+ ;; there is no function at index 1337, so this cannot be optimized
+ (call $invoke_vif
+ (i32.const 1337)
+ (i32.const 42)
+ (f32.const 3.14159)
+ )
)
(func $other_safe (param i32) (param f32)
)