Skip to content

Commit 4fc0590

Browse files
natebiggsCommit Queue
authored andcommitted
[dart2wasm] Add asserts ensuring exportable entities are only directly accessed from their own modules.
Change-Id: Ia5d5493e4db2710164d6966e97a0854fe2582f28 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391860 Commit-Queue: Nate Biggs <[email protected]> Reviewed-by: Ömer Ağacan <[email protected]>
1 parent 832bc1d commit 4fc0590

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

pkg/wasm_builder/lib/src/builder/instructions.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ class InstructionsBuilder with Builder<ir.Instructions> {
552552
final Try try_ = _topOfLabelStack as Try;
553553
assert(_verifyEndOfBlock(tag.type.inputs,
554554
trace: ['catch', tag], reachableAfter: try_.reachable, reindent: true));
555+
assert(tag.enclosingModule == module);
555556
try_.hasCatch = true;
556557
_reachable = try_.reachable;
557558
_add(ir.Catch(tag));
@@ -571,6 +572,7 @@ class InstructionsBuilder with Builder<ir.Instructions> {
571572
/// Emit a `throw` instruction.
572573
void throw_(ir.Tag tag) {
573574
assert(_verifyTypes(tag.type.inputs, const [], trace: ['throw', tag]));
575+
assert(tag.enclosingModule == module);
574576
_add(ir.Throw(tag));
575577
_reachable = false;
576578
}
@@ -650,6 +652,7 @@ class InstructionsBuilder with Builder<ir.Instructions> {
650652
void call_indirect(ir.FunctionType type, [ir.Table? table]) {
651653
assert(_verifyTypes([...type.inputs, ir.NumType.i32], type.outputs,
652654
trace: ['call_indirect', type, if (table != null) table.name]));
655+
assert(table == null || table.enclosingModule == module);
653656
_add(ir.CallIndirect(type, table));
654657
}
655658

@@ -716,6 +719,7 @@ class InstructionsBuilder with Builder<ir.Instructions> {
716719
void global_get(ir.Global global) {
717720
assert(_verifyTypes(const [], [global.type.type],
718721
trace: ['global.get', global]));
722+
assert(global.enclosingModule == module);
719723
_add(ir.GlobalGet(global));
720724
}
721725

@@ -724,6 +728,7 @@ class InstructionsBuilder with Builder<ir.Instructions> {
724728
assert(global.type.mutable);
725729
assert(_verifyTypes([global.type.type], const [],
726730
trace: ['global.set', global]));
731+
assert(global.enclosingModule == module);
727732
_add(ir.GlobalSet(global));
728733
}
729734

@@ -733,30 +738,35 @@ class InstructionsBuilder with Builder<ir.Instructions> {
733738
void table_get(ir.Table table) {
734739
assert(_verifyTypes(const [ir.NumType.i32], [table.type],
735740
trace: ['table.get', table.name]));
741+
assert(table.enclosingModule == module);
736742
_add(ir.TableGet(table));
737743
}
738744

739745
/// Emit a `table.set` instruction.
740746
void table_set(ir.Table table) {
741747
assert(_verifyTypes([ir.NumType.i32, table.type], const [],
742748
trace: ['table.set', table.name]));
749+
assert(table.enclosingModule == module);
743750
_add(ir.TableSet(table));
744751
}
745752

746753
/// Emit a `table.size` instruction.
747754
void table_size(ir.Table table) {
748755
assert(_verifyTypes(const [], const [ir.NumType.i32],
749756
trace: ['table.size', table.name]));
757+
assert(table.enclosingModule == module);
750758
_add(ir.TableSize(table));
751759
}
752760

753761
// Memory instructions
754762
void _addMemoryInstruction(
755-
ir.Instruction Function(ir.MemoryOffsetAlign memory) create,
756-
ir.Memory memory,
757-
{required int offset,
758-
required int align}) =>
759-
_add(create(ir.MemoryOffsetAlign(memory, offset: offset, align: align)));
763+
ir.Instruction Function(ir.MemoryOffsetAlign memory) create,
764+
ir.Memory memory,
765+
{required int offset,
766+
required int align}) {
767+
assert(memory.enclosingModule == module);
768+
_add(create(ir.MemoryOffsetAlign(memory, offset: offset, align: align)));
769+
}
760770

761771
/// Emit an `i32.load` instruction.
762772
void i32_load(ir.Memory memory, int offset, [int align = 2]) {
@@ -964,12 +974,14 @@ class InstructionsBuilder with Builder<ir.Instructions> {
964974
/// Emit a `memory.size` instruction.
965975
void memory_size(ir.Memory memory) {
966976
assert(_verifyTypes(const [], const [ir.NumType.i32]));
977+
assert(memory.enclosingModule == module);
967978
_add(ir.MemorySize(memory));
968979
}
969980

970981
/// Emit a `memory.grow` instruction.
971982
void memory_grow(ir.Memory memory) {
972983
assert(_verifyTypes(const [ir.NumType.i32], const [ir.NumType.i32]));
984+
assert(memory.enclosingModule == module);
973985
_add(ir.MemoryGrow(memory));
974986
}
975987

0 commit comments

Comments
 (0)