Skip to content

Commit b14bf89

Browse files
authored
[Wasm64] Fix PostEmscripten::optimizeExceptions on invokes with an i64 argument (#6074)
In wasm64, function pointers are 64-bit like all pointers. fixes #6073
1 parent 1890834 commit b14bf89

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/passes/PostEmscripten.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ struct PostEmscripten : public Pass {
317317
// The first operand is the function pointer index, which must be
318318
// constant if we are to optimize it statically.
319319
if (auto* index = curr->operands[0]->dynCast<Const>()) {
320-
size_t indexValue = index->value.geti32();
320+
size_t indexValue = index->value.getInteger();
321321
if (indexValue >= flatTable.names.size()) {
322322
// UB can lead to indirect calls to invalid pointers.
323323
return;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
;; RUN: wasm-opt %s --post-emscripten -all -S -o - | filecheck %s
3+
4+
;; Test we do not error on invoke calls that take an i64 index (which is the
5+
;; case in wasm64). Nothing should change here.
6+
7+
(module
8+
;; CHECK: (type $0 (func (param i64)))
9+
10+
;; CHECK: (type $1 (func))
11+
12+
;; CHECK: (import "env" "invoke_v" (func $invoke (type $0) (param i64)))
13+
(import "env" "invoke_v" (func $invoke (param i64)))
14+
15+
;; CHECK: (table $0 269 269 funcref)
16+
(table $0 269 269 funcref)
17+
;; CHECK: (elem $0 (i32.const 1))
18+
(elem $0 (i32.const 1))
19+
20+
;; CHECK: (func $0 (type $1)
21+
;; CHECK-NEXT: (call $invoke
22+
;; CHECK-NEXT: (i64.const 42)
23+
;; CHECK-NEXT: )
24+
;; CHECK-NEXT: )
25+
(func $0
26+
(call $invoke
27+
(i64.const 42)
28+
)
29+
)
30+
)
31+

0 commit comments

Comments
 (0)