diff options
author | Goktug Gokdogan <goktug@google.com> | 2024-09-04 18:28:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-05 01:28:49 +0000 |
commit | ad6a124969a9c6874484f0982c10d6f507388b20 (patch) | |
tree | 284a08f66b3a3f5fc5003033eeec27659518040c /src/passes/StringLowering.cpp | |
parent | 67bd84251222099aae542e3871955824499f514b (diff) | |
download | binaryen-ad6a124969a9c6874484f0982c10d6f507388b20.tar.gz binaryen-ad6a124969a9c6874484f0982c10d6f507388b20.tar.bz2 binaryen-ad6a124969a9c6874484f0982c10d6f507388b20.zip |
Only generate string.consts custom section if it is needed (#6893)
Diffstat (limited to 'src/passes/StringLowering.cpp')
-rw-r--r-- | src/passes/StringLowering.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/passes/StringLowering.cpp b/src/passes/StringLowering.cpp index 92e3268dc..349ba8cd0 100644 --- a/src/passes/StringLowering.cpp +++ b/src/passes/StringLowering.cpp @@ -235,7 +235,6 @@ struct StringLowering : public StringGathering { void makeImports(Module* module) { Index jsonImportIndex = 0; std::stringstream json; - json << '['; bool first = true; for (auto& global : module->globals) { if (global->init) { @@ -267,12 +266,16 @@ struct StringLowering : public StringGathering { } } - // Add a custom section with the JSON. - json << ']'; - auto str = json.str(); - auto vec = std::vector<char>(str.begin(), str.end()); - module->customSections.emplace_back( - CustomSection{"string.consts", std::move(vec)}); + auto jsonString = json.str(); + if (!jsonString.empty()) { + // If we are asserting UTF8, then we shouldn't be generating any JSON. + assert(!assertUTF8); + // Add a custom section with the JSON. + auto str = '[' + jsonString + ']'; + auto vec = std::vector<char>(str.begin(), str.end()); + module->customSections.emplace_back( + CustomSection{"string.consts", std::move(vec)}); + } } // Common types used in imports. |