summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-11-07 10:09:45 -0800
committerGitHub <noreply@github.com>2024-11-07 10:09:45 -0800
commit88b36f5bbb0882f4861f3874d3a50cf7e8f2c7c2 (patch)
tree389cbc3e26225f607a3bfa717df84bd116f105f9
parente409660a5b4dff9891ddb7d4786cc510a5761d3e (diff)
downloadbinaryen-88b36f5bbb0882f4861f3874d3a50cf7e8f2c7c2.tar.gz
binaryen-88b36f5bbb0882f4861f3874d3a50cf7e8f2c7c2.tar.bz2
binaryen-88b36f5bbb0882f4861f3874d3a50cf7e8f2c7c2.zip
[wasm64] Fix Directize on indexes > 32 bits (#7063)
-rw-r--r--src/passes/Directize.cpp2
-rw-r--r--test/lit/passes/directize-wasm64.wast14
2 files changed, 15 insertions, 1 deletions
diff --git a/src/passes/Directize.cpp b/src/passes/Directize.cpp
index 7faf2e23a..93b3d04e7 100644
--- a/src/passes/Directize.cpp
+++ b/src/passes/Directize.cpp
@@ -130,7 +130,7 @@ private:
return CallUtils::Unknown{};
}
- Index index = c->value.getInteger();
+ Address index = c->value.getUnsigned();
// Check if index is invalid, or the type is wrong.
auto& flatTable = *table.flatTable;
diff --git a/test/lit/passes/directize-wasm64.wast b/test/lit/passes/directize-wasm64.wast
index 8c3a0623f..5a6b1f311 100644
--- a/test/lit/passes/directize-wasm64.wast
+++ b/test/lit/passes/directize-wasm64.wast
@@ -34,4 +34,18 @@
(i64.const 1)
)
)
+
+ ;; CHECK: (func $bar-32 (param $x i32) (param $y i32)
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ (func $bar-32 (param $x i32) (param $y i32)
+ ;; As above, but the constant has 2**32 added to it. If we operate on a 32-bit
+ ;; index, we might think we can optimize to a call to $foo. Instead, we should
+ ;; see that this traps, and optimize to that.
+ (call_indirect (type $ii)
+ (local.get $x)
+ (local.get $y)
+ (i64.const 4294967297)
+ )
+ )
)