From 6a5cbb94fad9b375469d6433429521988b1de20b Mon Sep 17 00:00:00 2001
From: Keith Winstein <208955+keithw@users.noreply.github.com>
Date: Wed, 30 Oct 2024 20:00:59 -0700
Subject: Update testsuite (#2495)

The memory64 `table.wast` test has started to depend on
function-references and gc (which WABT doesn't support yet), so vendor
an older version of the test.
---
 src/binary-reader.cc    |  3 ++-
 src/error-formatter.cc  |  5 ++++-
 src/interp/interp.cc    |  8 ++++++++
 src/shared-validator.cc | 13 ++++++++++++-
 4 files changed, 26 insertions(+), 3 deletions(-)

(limited to 'src')

diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index a0b31787..33801a7d 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -3044,7 +3044,8 @@ Result BinaryReader::ReadModule(const ReadModuleOptions& options) {
                "function signature count != function body count");
   // This is checked in ReadDataSection, but it must be checked at the end too,
   // in case the data section was omitted.
-  ERROR_IF(num_data_segments_ == 0 && data_count_ != kInvalidIndex,
+  ERROR_IF(num_data_segments_ == 0 && data_count_ != kInvalidIndex &&
+               data_count_ != 0,
            "Data section missing but DataCount non-zero");
   CALLBACK0(EndModule);
 
diff --git a/src/error-formatter.cc b/src/error-formatter.cc
index 9a14cfac..13b2bfd1 100644
--- a/src/error-formatter.cc
+++ b/src/error-formatter.cc
@@ -62,7 +62,10 @@ std::string FormatError(const Error& error,
     result += '\n';
     result += indent_str;
 
-    size_t num_spaces = (loc.first_column - 1) - source_line.column_offset;
+    size_t num_spaces = 0;
+    if (loc.first_column > source_line.column_offset) {
+      num_spaces = (loc.first_column - 1) - source_line.column_offset;
+    }
     size_t num_carets = loc.last_column - loc.first_column;
     num_carets = std::min(num_carets, source_line.line.size() - num_spaces);
     num_carets = std::max<size_t>(num_carets, 1);
diff --git a/src/interp/interp.cc b/src/interp/interp.cc
index 97f35f81..a3dd9b4a 100644
--- a/src/interp/interp.cc
+++ b/src/interp/interp.cc
@@ -78,6 +78,14 @@ Result Match(const Limits& expected,
     }
   }
 
+  if (expected.is_64 && !actual.is_64) {
+    *out_msg = StringPrintf("expected i64 memory, but i32 memory provided");
+    return Result::Error;
+  } else if (actual.is_64 && !expected.is_64) {
+    *out_msg = StringPrintf("expected i32 memory, but i64 memory provided");
+    return Result::Error;
+  }
+
   return Result::Ok;
 }
 
diff --git a/src/shared-validator.cc b/src/shared-validator.cc
index f9c26807..914b5346 100644
--- a/src/shared-validator.cc
+++ b/src/shared-validator.cc
@@ -712,6 +712,11 @@ Result SharedValidator::OnCallIndirect(const Location& loc,
   TableType table_type;
   result |= CheckFuncTypeIndex(sig_var, &func_type);
   result |= CheckTableIndex(table_var, &table_type);
+  if (table_type.element != Type::FuncRef) {
+    result |= PrintError(
+        loc,
+        "type mismatch: call_indirect must reference table of funcref type");
+  }
   result |= typechecker_.OnCallIndirect(func_type.params, func_type.results,
                                         table_type.limits);
   return result;
@@ -1028,9 +1033,15 @@ Result SharedValidator::OnReturnCallIndirect(const Location& loc,
                                              Var sig_var,
                                              Var table_var) {
   Result result = CheckInstr(Opcode::CallIndirect, loc);
-  result |= CheckTableIndex(table_var);
   FuncType func_type;
+  TableType table_type;
   result |= CheckFuncTypeIndex(sig_var, &func_type);
+  result |= CheckTableIndex(table_var, &table_type);
+  if (table_type.element != Type::FuncRef) {
+    result |= PrintError(loc,
+                         "type mismatch: return_call_indirect must reference "
+                         "table of funcref type");
+  }
   result |=
       typechecker_.OnReturnCallIndirect(func_type.params, func_type.results);
   return result;
-- 
cgit v1.2.3