@@ -81,6 +81,10 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
8181 note (ptrp, wasm.getMemory (mem)->addressType );
8282 }
8383
84+ void noteTableIndex (Expression** indexp, Name table) {
85+ note (indexp, wasm.getTable (table)->addressType );
86+ }
87+
8488 void noteAny (Expression** childp) { self ().noteAnyType (childp); }
8589
8690 void noteAnyReference (Expression** childp) {
@@ -746,35 +750,43 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
746750 note (&curr->right , eqref);
747751 }
748752
749- void visitTableGet (TableGet* curr) { note (&curr->index , Type::i32 ); }
753+ void visitTableGet (TableGet* curr) {
754+ noteTableIndex (&curr->index , curr->table );
755+ }
750756
751757 void visitTableSet (TableSet* curr) {
752- note (&curr->index , Type:: i32 );
758+ noteTableIndex (&curr->index , curr-> table );
753759 note (&curr->value , wasm.getTable (curr->table )->type );
754760 }
755761
756762 void visitTableSize (TableSize* curr) {}
757763
758764 void visitTableGrow (TableGrow* curr) {
759765 note (&curr->value , wasm.getTable (curr->table )->type );
760- note (&curr->delta , Type:: i32 );
766+ noteTableIndex (&curr->delta , curr-> table );
761767 }
762768
763769 void visitTableFill (TableFill* curr) {
764770 auto type = wasm.getTable (curr->table )->type ;
765- note (&curr->dest , Type:: i32 );
771+ noteTableIndex (&curr->dest , curr-> table );
766772 note (&curr->value , type);
767- note (&curr->size , Type:: i32 );
773+ noteTableIndex (&curr->size , curr-> table );
768774 }
769775
770776 void visitTableCopy (TableCopy* curr) {
771- note (&curr->dest , Type::i32 );
772- note (&curr->source , Type::i32 );
773- note (&curr->size , Type::i32 );
777+ noteTableIndex (&curr->dest , curr->destTable );
778+ noteTableIndex (&curr->source , curr->sourceTable );
779+
780+ // The size depends on both dest and source.
781+ auto * sourceTable = wasm.getTable (curr->sourceTable );
782+ auto * destTable = wasm.getTable (curr->destTable );
783+ Type sizeType =
784+ sourceTable->is64 () && destTable->is64 () ? Type::i64 : Type::i32 ;
785+ note (&curr->size , sizeType);
774786 }
775787
776788 void visitTableInit (TableInit* curr) {
777- note (&curr->dest , wasm. getTable ( curr->table )-> addressType );
789+ noteTableIndex (&curr->dest , curr->table );
778790 note (&curr->offset , Type::i32 );
779791 note (&curr->size , Type::i32 );
780792 }
0 commit comments