Skip to content

Commit 203b7f7

Browse files
authored
Merge pull request #1114 from WebAssembly/fuzz
Fuzz fixes
2 parents c821845 + 96e9398 commit 203b7f7

6 files changed

Lines changed: 56 additions & 2 deletions

File tree

src/passes/MergeBlocks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static void optimizeBlock(Block* curr, Module* module) {
213213
break;
214214
}
215215
}
216-
if (changed) curr->finalize();
216+
if (changed) curr->finalize(curr->type);
217217
}
218218

219219
void BreakValueDropper::visitBlock(Block* curr) {

src/wasm/wasm.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,20 @@ struct TypeSeeker : public PostWalker<TypeSeeker> {
109109
Name targetName;
110110
std::vector<WasmType> types;
111111

112+
112113
TypeSeeker(Expression* target, Name targetName) : target(target), targetName(targetName) {
113114
Expression* temp = target;
114115
walk(temp);
115116
}
116117

117118
void visitBreak(Break* curr) {
118-
if (curr->name == targetName) {
119+
if (curr->name == targetName && BranchUtils::isBranchTaken(curr)) {
119120
types.push_back(curr->value ? curr->value->type : none);
120121
}
121122
}
122123

123124
void visitSwitch(Switch* curr) {
125+
if (!BranchUtils::isBranchTaken(curr)) return;
124126
for (auto name : curr->targets) {
125127
if (name == targetName) types.push_back(curr->value ? curr->value->type : none);
126128
}

test/passes/merge-blocks.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,17 @@
8787
)
8888
)
8989
)
90+
(func $drop-block-squared-iloop (type $0)
91+
(drop
92+
(block $label$0 (result i32)
93+
(block $label$1
94+
(drop
95+
(loop $label$2
96+
(br $label$2)
97+
)
98+
)
99+
)
100+
)
101+
)
102+
)
90103
)

test/passes/merge-blocks.wast

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,18 @@
6969
)
7070
)
7171
)
72+
(func $drop-block-squared-iloop
73+
(drop
74+
(block $label$0 (result i32) ;; this block's type should not change, so the drop remains none and valid
75+
(drop
76+
(block $label$1
77+
(loop $label$2
78+
(br $label$2)
79+
)
80+
)
81+
)
82+
)
83+
)
84+
)
7285
)
7386

test/passes/remove-unused-brs.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,4 +1035,17 @@
10351035
)
10361036
)
10371037
)
1038+
(func $untaken-br-with-concrete-last-element (type $2) (result i32)
1039+
(block $label$8 (result i32)
1040+
(block $label$11 (result i32)
1041+
(block $label$14
1042+
(br_if $label$8
1043+
(br $label$11
1044+
(i32.const 103)
1045+
)
1046+
)
1047+
)
1048+
)
1049+
)
1050+
)
10381051
)

test/passes/remove-unused-brs.wast

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,5 +919,18 @@
919919
)
920920
)
921921
)
922+
(func $untaken-br-with-concrete-last-element (result i32)
923+
(block $label$8 (result i32)
924+
(block $label$11 (result i32)
925+
(block $label$14
926+
(br_if $label$14
927+
(br $label$11
928+
(i32.const 103)
929+
)
930+
)
931+
)
932+
)
933+
)
934+
)
922935
)
923936

0 commit comments

Comments
 (0)