From e7ac60eb735b10998e460b9788284a0117da704b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 1 Nov 2023 14:18:48 -0700 Subject: [PATCH] fix #6073 --- src/passes/PostEmscripten.cpp | 2 +- test/lit/passes/post-emscripten-64.wast | 31 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/lit/passes/post-emscripten-64.wast diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp index 39bc3e8890b..6dc32eaa8b1 100644 --- a/src/passes/PostEmscripten.cpp +++ b/src/passes/PostEmscripten.cpp @@ -317,7 +317,7 @@ struct PostEmscripten : public Pass { // The first operand is the function pointer index, which must be // constant if we are to optimize it statically. if (auto* index = curr->operands[0]->dynCast()) { - size_t indexValue = index->value.geti32(); + size_t indexValue = index->value.getInteger(); if (indexValue >= flatTable.names.size()) { // UB can lead to indirect calls to invalid pointers. return; diff --git a/test/lit/passes/post-emscripten-64.wast b/test/lit/passes/post-emscripten-64.wast new file mode 100644 index 00000000000..5b1693381ec --- /dev/null +++ b/test/lit/passes/post-emscripten-64.wast @@ -0,0 +1,31 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; RUN: wasm-opt %s --post-emscripten -all -S -o - | filecheck %s + +;; Test we do not error on invoke calls that take an i64 index (which is the +;; case in wasm64). Nothing should change here. + +(module + ;; CHECK: (type $0 (func (param i64))) + + ;; CHECK: (type $1 (func)) + + ;; CHECK: (import "env" "invoke_v" (func $invoke (type $0) (param i64))) + (import "env" "invoke_v" (func $invoke (param i64))) + + ;; CHECK: (table $0 269 269 funcref) + (table $0 269 269 funcref) + ;; CHECK: (elem $0 (i32.const 1)) + (elem $0 (i32.const 1)) + + ;; CHECK: (func $0 (type $1) + ;; CHECK-NEXT: (call $invoke + ;; CHECK-NEXT: (i64.const 42) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $0 + (call $invoke + (i64.const 42) + ) + ) +) +