diff options
author | Alon Zakai <azakai@google.com> | 2023-03-20 08:55:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-20 08:55:18 -0700 |
commit | f4b0ea75aa56349c970b9ae7c156e2f6fd87de3d (patch) | |
tree | f3c1945a85d6ef7d28367091a6f1a3d7b1ccf191 /src | |
parent | 8f57b66171f6166f35f8549ea5cf7c047a2a7a28 (diff) | |
download | binaryen-f4b0ea75aa56349c970b9ae7c156e2f6fd87de3d.tar.gz binaryen-f4b0ea75aa56349c970b9ae7c156e2f6fd87de3d.tar.bz2 binaryen-f4b0ea75aa56349c970b9ae7c156e2f6fd87de3d.zip |
Ensure a deterministic order in the type names section (#5590)
Before this PR we iterated over an unordered set. Replace that with an
iteration on a vector. (Also, the value in the set was not even used, so
this should even be faster.)
Add random names in the fuzzer to types, the lack of which is I believe
the reason this was not detected before.
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/fuzzing/fuzzing.cpp | 5 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index 73aff5acb..45cfbde0f 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -263,6 +263,11 @@ void TranslateToFuzzReader::setupHeapTypes() { // non-nullable bottom heap type). if (!type.isBottom() && !type.isBasic()) { interestingHeapTypes.push_back(type); + if (oneIn(2)) { + // Add a name for this type. + wasm.typeNames[type].name = + "generated_type$" + std::to_string(interestingHeapTypes.size()); + } } } } diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 5326972b0..89ad82abf 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -896,7 +896,7 @@ void WasmBinaryWriter::writeNames() { // type names { std::vector<HeapType> namedTypes; - for (auto& [type, _] : indexedTypes.indices) { + for (auto type : indexedTypes.types) { if (wasm->typeNames.count(type) && wasm->typeNames[type].name.is()) { namedTypes.push_back(type); } |