Skip to content

Commit 9f4e328

Browse files
pepyakinkripken
authored andcommitted
Add missing finalize() call to C API for call_indirect (#1184)
1 parent 5d27b20 commit 9f4e328

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/binaryen-c.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ BinaryenExpressionRef BinaryenCallIndirect(BinaryenModuleRef module, BinaryenExp
475475
}
476476
ret->fullType = type;
477477
ret->type = wasm->getFunctionType(ret->fullType)->result;
478+
ret->finalize();
478479
return static_cast<Expression*>(ret);
479480
}
480481
BinaryenExpressionRef BinaryenGetLocal(BinaryenModuleRef module, BinaryenIndex index, BinaryenType type) {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,19 @@ void test_core() {
278278
BinaryenModuleDispose(module);
279279
}
280280

281+
void test_unreachable() {
282+
BinaryenModuleRef module = BinaryenModuleCreate();
283+
BinaryenFunctionTypeRef i = BinaryenAddFunctionType(module, "i", BinaryenInt32(), NULL, 0);
284+
BinaryenFunctionTypeRef I = BinaryenAddFunctionType(module, "I", BinaryenInt64(), NULL, 0);
285+
286+
BinaryenExpressionRef body = BinaryenCallIndirect(module, BinaryenUnreachable(module), NULL, 0, "I");
287+
BinaryenFunctionRef fn = BinaryenAddFunction(module, "unreachable-fn", i, NULL, 0, body);
288+
289+
assert(BinaryenModuleValidate(module));
290+
BinaryenModulePrint(module);
291+
BinaryenModuleDispose(module);
292+
}
293+
281294
BinaryenExpressionRef makeCallCheck(BinaryenModuleRef module, int x) {
282295
BinaryenExpressionRef callOperands[] = { makeInt32(module, x) };
283296
return BinaryenCallImport(module, "check", callOperands, 1, BinaryenNone());
@@ -556,6 +569,7 @@ void test_tracing() {
556569
int main() {
557570
test_types();
558571
test_core();
572+
test_unreachable();
559573
test_relooper();
560574
test_binaries();
561575
test_interpret();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,16 @@ BinaryenFloat64: 4
536536
(nop)
537537
)
538538
)
539+
(module
540+
(type $i (func (result i32)))
541+
(type $I (func (result i64)))
542+
(memory $0 0)
543+
(func $unreachable-fn (type $i) (result i32)
544+
(call_indirect $I
545+
(unreachable)
546+
)
547+
)
548+
)
539549
raw:
540550
(module
541551
(type $v (func))

0 commit comments

Comments
 (0)