diff options
author | Alon Zakai <azakai@google.com> | 2021-09-02 09:17:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-02 09:17:37 -0700 |
commit | e84980dffb62d672c991960a701a3c7de8f8aa74 (patch) | |
tree | 8e130330f04c3cf10702bc24241061f33591b2f9 /src/passes/Print.cpp | |
parent | 4bf2d3bc3da17a28b65222d6e84f6126dcb9c553 (diff) | |
download | binaryen-e84980dffb62d672c991960a701a3c7de8f8aa74.tar.gz binaryen-e84980dffb62d672c991960a701a3c7de8f8aa74.tar.bz2 binaryen-e84980dffb62d672c991960a701a3c7de8f8aa74.zip |
Support specialized function types in element segments (#4109)
Before this, the element segments would be printed as having type
funcref, and then if their table had a specialized type, the element
type would not be a subtype of the table and validation would fail.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r-- | src/passes/Print.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 4fa38442c..616ce9759 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2735,12 +2735,9 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { } } void visitElementSegment(ElementSegment* curr) { - bool allElementsRefFunc = - std::all_of(curr->data.begin(), curr->data.end(), [](Expression* entry) { - return entry->is<RefFunc>(); - }); + bool usesExpressions = TableUtils::usesExpressions(curr, currModule); auto printElemType = [&]() { - if (allElementsRefFunc) { + if (!usesExpressions) { o << "func"; } else { printType(o, curr->type, currModule); @@ -2758,7 +2755,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { } if (curr->table.is()) { - if (!allElementsRefFunc || currModule->tables.size() > 1) { + if (usesExpressions || currModule->tables.size() > 1) { // tableuse o << " (table "; printName(curr->table, o); @@ -2768,7 +2765,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { o << ' '; visit(curr->offset); - if (!allElementsRefFunc || currModule->tables.size() > 1) { + if (usesExpressions || currModule->tables.size() > 1) { o << ' '; printElemType(); } @@ -2777,7 +2774,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { printElemType(); } - if (allElementsRefFunc) { + if (!usesExpressions) { for (auto* entry : curr->data) { auto* refFunc = entry->cast<RefFunc>(); o << ' '; |