Skip to content

Commit 860fb95

Browse files
committed
feedback
1 parent b96fee8 commit 860fb95

6 files changed

Lines changed: 29 additions & 19 deletions

File tree

src/parser/context-decls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Result<Table*> ParseDeclsCtx::addTableDecl(Index pos,
8484
ImportNames* importNames,
8585
TableType type) {
8686
auto t = std::make_unique<Table>();
87-
t->indexType = type.type;
87+
t->indexType = type.indexType;
8888
t->initial = type.limits.initial;
8989
t->max = type.limits.max ? *type.limits.max : Table::kUnlimitedSize;
9090
if (name.is()) {
@@ -139,7 +139,7 @@ Result<Memory*> ParseDeclsCtx::addMemoryDecl(Index pos,
139139
ImportNames* importNames,
140140
MemType type) {
141141
auto m = std::make_unique<Memory>();
142-
m->indexType = type.type;
142+
m->indexType = type.indexType;
143143
m->initial = type.limits.initial;
144144
m->max = type.limits.max ? *type.limits.max : Memory::kUnlimitedSize;
145145
m->shared = type.shared;

src/parser/contexts.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct Limits {
4646
};
4747

4848
struct MemType {
49-
Type type;
49+
Type indexType;
5050
Limits limits;
5151
bool shared;
5252
};
@@ -57,7 +57,7 @@ struct Memarg {
5757
};
5858

5959
struct TableType {
60-
Type type;
60+
Type indexType;
6161
Limits limits;
6262
};
6363

@@ -947,7 +947,9 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx {
947947

948948
Limits getLimitsFromElems(Index elems) { return {elems, elems}; }
949949

950-
TableType makeTableType(Type type, Limits limits, TypeT) { return {type, limits}; }
950+
TableType makeTableType(Type indexType, Limits limits, TypeT) {
951+
return {indexType, limits};
952+
}
951953

952954
std::vector<char> makeDataString() { return {}; }
953955
void appendDataString(std::vector<char>& data, std::string_view str) {
@@ -959,8 +961,8 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx {
959961
return {size, size};
960962
}
961963

962-
MemType makeMemType(Type type, Limits limits, bool shared) {
963-
return {type, limits, shared};
964+
MemType makeMemType(Type indexType, Limits limits, bool shared) {
965+
return {indexType, limits, shared};
964966
}
965967

966968
Result<TypeUseT>
@@ -980,8 +982,10 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx {
980982
std::vector<Annotation>&&,
981983
Index pos);
982984

983-
Result<Table*>
984-
addTableDecl(Index pos, Name name, ImportNames* importNames, TableType limits);
985+
Result<Table*> addTableDecl(Index pos,
986+
Name name,
987+
ImportNames* importNames,
988+
TableType limits);
985989
Result<>
986990
addTable(Name, const std::vector<Name>&, ImportNames*, TableType, Index);
987991

src/parser/parsers.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ Result<typename Ctx::MemTypeT> memtypeContinued(Ctx& ctx, Type indexType) {
817817
return ctx.makeMemType(indexType, *limits, shared);
818818
}
819819

820-
// tabletype ::= limits32 reftype
820+
// tabletype ::= (limits32 | 'i32' limits32 | 'i64' limit64) reftype
821821
template<typename Ctx> Result<typename Ctx::TableTypeT> tabletype(Ctx& ctx) {
822822
Type indexType = Type::i32;
823823
if (ctx.in.takeKeyword("i64"sv)) {
@@ -828,7 +828,6 @@ template<typename Ctx> Result<typename Ctx::TableTypeT> tabletype(Ctx& ctx) {
828828
return tabletypeContinued(ctx, indexType);
829829
}
830830

831-
// tabletype ::= limits32 reftype
832831
template<typename Ctx>
833832
Result<typename Ctx::TableTypeT> tabletypeContinued(Ctx& ctx, Type indexType) {
834833
auto limits = indexType == Type::i32 ? limits32(ctx) : limits64(ctx);
@@ -3064,8 +3063,8 @@ template<typename Ctx> MaybeResult<> func(Ctx& ctx) {
30643063
}
30653064

30663065
// table ::= '(' 'table' id? ('(' 'export' name ')')*
3067-
// '(' 'import' mod:name nm:name ')'? tabletype ')'
3068-
// | '(' 'table' id? ('(' 'export' name ')')*
3066+
// '(' 'import' mod:name nm:name ')'? index_type? tabletype ')'
3067+
// | '(' 'table' id? ('(' 'export' name ')')* index_type?
30693068
// reftype '(' 'elem' (elemexpr* | funcidx*) ')' ')'
30703069
template<typename Ctx> MaybeResult<> table(Ctx& ctx) {
30713070
auto pos = ctx.in.getPos();
@@ -3146,10 +3145,10 @@ template<typename Ctx> MaybeResult<> table(Ctx& ctx) {
31463145
return Ok{};
31473146
}
31483147

3149-
// mem ::= '(' 'memory' id? ('(' 'export' name ')')* index_type?
3150-
// ('(' 'data' b:datastring ')' | memtype) ')'
3151-
// | '(' 'memory' id? ('(' 'export' name ')')*
3152-
// '(' 'import' mod:name nm:name ')' memtype ')'
3148+
// memory ::= '(' 'memory' id? ('(' 'export' name ')')* index_type?
3149+
// ('(' 'data' b:datastring ')' | memtype) ')'
3150+
// | '(' 'memory' id? ('(' 'export' name ')')*
3151+
// '(' 'import' mod:name nm:name ')' index_type? memtype ')'
31533152
template<typename Ctx> MaybeResult<> memory(Ctx& ctx) {
31543153
auto pos = ctx.in.getPos();
31553154
if (!ctx.in.takeSExprStart("memory"sv)) {

src/wasm/wasm-validator.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,12 +949,17 @@ void FunctionValidator::visitCallIndirect(CallIndirect* curr) {
949949
validateReturnCall(curr);
950950

951951
auto* table = getModule()->getTableOrNull(curr->table);
952+
if (!shouldBeTrue(!!table, curr, "call-indirect table must exist")) {
953+
return;
954+
}
955+
std::cerr << "got table " << table << "\n";
956+
std::cerr << table->indexType << "\n";
952957

953958
shouldBeEqualOrFirstIsUnreachable(
954959
curr->target->type,
955960
table->indexType,
956961
curr,
957-
"indirect call target must match the table index type");
962+
"call-indirect call target must match the table index type");
958963

959964
if (curr->target->type != Type::unreachable) {
960965
auto* table = getModule()->getTableOrNull(curr->table);

test/example/c-api-kitchen-sink.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,8 +1603,9 @@ void test_core() {
16031603

16041604
void test_unreachable() {
16051605
BinaryenModuleRef module = BinaryenModuleCreate();
1606+
BinaryenAddTable(module, "tab", 0, 100, BinaryenTypeFuncref());
16061607
BinaryenExpressionRef body = BinaryenCallIndirect(module,
1607-
"invalid-table",
1608+
"tab",
16081609
BinaryenUnreachable(module),
16091610
NULL,
16101611
0,

test/example/c-api-kitchen-sink.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,6 +2608,7 @@ BinaryenFeatureAll: 131071
26082608
(module
26092609
(type $0 (func (result i32)))
26102610
(type $1 (func (result i64)))
2611+
(table $tab 0 100 funcref)
26112612
(func $unreachable-fn (result i32)
26122613
(call_indirect (type $1)
26132614
(unreachable)

0 commit comments

Comments
 (0)