Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
kripken committed May 17, 2024
commit 60332739ae0bdd46772dff6319231e4ffb04d75e
20 changes: 9 additions & 11 deletions src/tools/fuzzing/fuzzing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,9 @@ void TranslateToFuzzReader::setupGlobals() {
auto type = getConcreteType();
auto mutability = oneIn(2) ? Builder::Mutable : Builder::Immutable;

// Usually make a const, but sometimes make a global.get (which may fail to
// find a suitable global, and if so it will make a constant instead).
Expression* init;
if (!oneIn(3)) {
init = makeConst(type);
} else {
init = makeGlobalGet(type);
}
// We can only make something trivial (like a constant) in a global
// initializer.
auto* init = makeTrivial(type);

if (!FindAll<RefAs>(init).list.empty()) {
// When creating this initial value we ended up emitting a RefAs, which
Expand Down Expand Up @@ -1483,9 +1478,12 @@ Expression* TranslateToFuzzReader::makeTrivial(Type type) {
// using it before it was set, which would trap.
if (funcContext && oneIn(type.isNonNullable() ? 10 : 2)) {
return makeLocalGet(type);
} else {
return makeConst(type);
}

// Either make a const, or a global.get (which may fail to find a suitable
// global, especially in a non-function context, and if so it will make a
// constant instead).
return oneIn(2) ? makeConst(type) : makeGlobalGet(type);
} else if (type == Type::none) {
return makeNop(type);
}
Expand Down Expand Up @@ -1915,7 +1913,7 @@ Expression* TranslateToFuzzReader::makeGlobalGet(Type type) {
: importedImmutableGlobalsByType);
auto it = relevantGlobals.find(type);
if (it == relevantGlobals.end() || it->second.empty()) {
return makeTrivial(type);
return makeConst(type);
}

auto name = pick(it->second);
Expand Down
52 changes: 26 additions & 26 deletions test/passes/fuzz_metrics_noprint.bin.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
total
[exports] : 50
[funcs] : 72
[exports] : 37
[funcs] : 60
[globals] : 9
[imports] : 4
[memories] : 1
[memory-data] : 2
[table-data] : 22
[table-data] : 23
[tables] : 1
[tags] : 0
[total] : 8564
[vars] : 237
Binary : 632
Block : 1451
Break : 298
Call : 318
CallIndirect : 81
Const : 1383
Drop : 93
GlobalGet : 681
GlobalSet : 565
If : 467
Load : 142
LocalGet : 606
LocalSet : 484
Loop : 198
Nop : 96
RefFunc : 22
Return : 66
Select : 57
Store : 72
Unary : 578
Unreachable : 274
[total] : 6655
[vars] : 169
Binary : 504
Block : 1108
Break : 211
Call : 209
CallIndirect : 54
Const : 1049
Drop : 70
GlobalGet : 562
GlobalSet : 421
If : 361
Load : 126
LocalGet : 482
LocalSet : 377
Loop : 145
Nop : 107
RefFunc : 23
Return : 84
Select : 40
Store : 58
Unary : 456
Unreachable : 208
77 changes: 39 additions & 38 deletions test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
total
[exports] : 2
[funcs] : 2
[exports] : 6
[funcs] : 16
[globals] : 24
[imports] : 5
[memories] : 1
[memory-data] : 20
[table-data] : 0
[table-data] : 2
[tables] : 1
[tags] : 1
[total] : 524
[vars] : 36
ArrayCopy : 1
ArrayFill : 1
ArrayGet : 2
ArrayLen : 4
ArrayNew : 19
AtomicNotify : 1
Binary : 71
Block : 30
Break : 2
Call : 5
Const : 135
Drop : 2
GlobalGet : 12
GlobalSet : 6
If : 16
[total] : 653
[vars] : 75
ArrayGet : 1
ArrayLen : 1
ArrayNew : 8
ArrayNewFixed : 4
Binary : 75
Block : 83
Break : 4
Call : 15
Const : 125
Drop : 4
GlobalGet : 52
GlobalSet : 40
If : 26
Load : 18
LocalGet : 66
LocalSet : 41
Loop : 2
Nop : 5
LocalGet : 46
LocalSet : 32
Loop : 5
Nop : 3
Pop : 3
RefAs : 14
RefAs : 6
RefCast : 1
RefNull : 12
RefTest : 2
Return : 1
Select : 1
Store : 2
StringConst : 4
StringEncode : 1
RefEq : 1
RefFunc : 5
RefI31 : 1
RefIsNull : 1
RefNull : 7
RefTest : 1
Return : 5
Select : 3
StringConst : 6
StringEq : 1
StringMeasure : 1
StructNew : 13
Try : 4
TupleExtract : 3
StringWTF16Get : 1
StructGet : 1
StructNew : 8
Try : 3
TupleExtract : 2
TupleMake : 11
Unary : 8
Unreachable : 3
Unary : 23
Unreachable : 21