summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-04-28 09:56:58 -0700
committerGitHub <noreply@github.com>2022-04-28 16:56:58 +0000
commit7ba0d8377dfaa9fbd24c0e5961fd2795d8349272 (patch)
tree94c74b52c30e62aa93035a1bc0bf10ed87363b63 /src
parent0b0581a2db2ea0f28e820957504e431881cb1f70 (diff)
downloadbinaryen-7ba0d8377dfaa9fbd24c0e5961fd2795d8349272.tar.gz
binaryen-7ba0d8377dfaa9fbd24c0e5961fd2795d8349272.tar.bz2
binaryen-7ba0d8377dfaa9fbd24c0e5961fd2795d8349272.zip
[NominalFuzzing] SignatureRefining can modify the IR while running a parallel analysis (#4620)
Normally ParallelFunctionAnalysis is just an analysis, and has no effects. However, in SignatureRefining we actually do have side effects, due to an internal limitation of the helper code it runs. This adds a template parameter to the class so users can note that they do modify the IR. The parameter is added in the middle as it is easier to add this param than to add the last one (the map).
Diffstat (limited to 'src')
-rw-r--r--src/ir/module-utils.cpp4
-rw-r--r--src/ir/module-utils.h12
-rw-r--r--src/passes/SignatureRefining.cpp4
3 files changed, 13 insertions, 7 deletions
diff --git a/src/ir/module-utils.cpp b/src/ir/module-utils.cpp
index a061782f9..7861bde54 100644
--- a/src/ir/module-utils.cpp
+++ b/src/ir/module-utils.cpp
@@ -115,8 +115,8 @@ Counts getHeapTypeCounts(Module& wasm) {
}
// Collect info from functions in parallel.
- ModuleUtils::ParallelFunctionAnalysis<Counts, InsertOrderedMap> analysis(
- wasm, [&](Function* func, Counts& counts) {
+ ModuleUtils::ParallelFunctionAnalysis<Counts, Immutable, InsertOrderedMap>
+ analysis(wasm, [&](Function* func, Counts& counts) {
counts.note(func->type);
for (auto type : func->vars) {
counts.note(type);
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h
index 845acda00..5030bf84f 100644
--- a/src/ir/module-utils.h
+++ b/src/ir/module-utils.h
@@ -303,10 +303,14 @@ template<typename T> inline void iterImports(Module& wasm, T visitor) {
// Helper class for performing an operation on all the functions in the module,
// in parallel, with an Info object for each one that can contain results of
// some computation that the operation performs.
-// The operation performend should not modify the wasm module in any way.
-// TODO: enforce this
+// The operation performed should not modify the wasm module in any way, by
+// default - otherwise, set the Mutability to Mutable. (This is not enforced at
+// compile time - TODO find a way - but at runtime in pass-debug mode it is
+// checked.)
template<typename K, typename V> using DefaultMap = std::map<K, V>;
-template<typename T, template<typename, typename> class MapT = DefaultMap>
+template<typename T,
+ Mutability Mut = Immutable,
+ template<typename, typename> class MapT = DefaultMap>
struct ParallelFunctionAnalysis {
Module& wasm;
@@ -331,7 +335,7 @@ struct ParallelFunctionAnalysis {
struct Mapper : public WalkerPass<PostWalker<Mapper>> {
bool isFunctionParallel() override { return true; }
- bool modifiesBinaryenIR() override { return false; }
+ bool modifiesBinaryenIR() override { return Mut; }
Mapper(Module& module, Map& map, Func work)
: module(module), map(map), work(work) {}
diff --git a/src/passes/SignatureRefining.cpp b/src/passes/SignatureRefining.cpp
index d094382c7..2c2146c3f 100644
--- a/src/passes/SignatureRefining.cpp
+++ b/src/passes/SignatureRefining.cpp
@@ -76,7 +76,9 @@ struct SignatureRefining : public Pass {
bool canModify = true;
};
- ModuleUtils::ParallelFunctionAnalysis<Info> analysis(
+ // This analysis also modifies the wasm as it goes, as the getResultsLUB()
+ // operation has side effects (see comment on header declaration).
+ ModuleUtils::ParallelFunctionAnalysis<Info, Mutable> analysis(
*module, [&](Function* func, Info& info) {
if (func->imported()) {
return;