summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-05-11 10:56:22 -0700
committerGitHub <noreply@github.com>2022-05-11 10:56:22 -0700
commitbad3f9e8f058cfdaefb3d7d76a93e842665f8435 (patch)
tree840eb9c70df3b3475eb18f662d2375a9eda230f9
parente209fcbc3fc66db775ec65d85dbd64a6069c1681 (diff)
downloadbinaryen-bad3f9e8f058cfdaefb3d7d76a93e842665f8435.tar.gz
binaryen-bad3f9e8f058cfdaefb3d7d76a93e842665f8435.tar.bz2
binaryen-bad3f9e8f058cfdaefb3d7d76a93e842665f8435.zip
[NominalFuzzing] Fix SignaturePruning on types with a super (#4657)
Do not prune parameters if there is a supertype that is a signature. Without this we crash on an assertion in TypeBuilder when we try to recreate the types (as we try to make a a subtype with fewer fields than the super).
-rw-r--r--src/passes/SignaturePruning.cpp9
-rw-r--r--test/lit/passes/signature-refining.wast18
2 files changed, 27 insertions, 0 deletions
diff --git a/src/passes/SignaturePruning.cpp b/src/passes/SignaturePruning.cpp
index 033333758..4f142eb97 100644
--- a/src/passes/SignaturePruning.cpp
+++ b/src/passes/SignaturePruning.cpp
@@ -143,6 +143,15 @@ struct SignaturePruning : public Pass {
continue;
}
+ // A type with a signature supertype cannot be optimized: we'd need to
+ // remove the field from the super as well, which atm we don't attempt to
+ // do. TODO
+ if (auto super = type.getSuperType()) {
+ if (super->isSignature()) {
+ continue;
+ }
+ }
+
// Apply constant indexes: find the parameters that are always sent a
// constant value, and apply that value in the function. That then makes
// the parameter unused (since the applied value makes us ignore the value
diff --git a/test/lit/passes/signature-refining.wast b/test/lit/passes/signature-refining.wast
index c67e04917..19558d997 100644
--- a/test/lit/passes/signature-refining.wast
+++ b/test/lit/passes/signature-refining.wast
@@ -656,3 +656,21 @@
)
)
)
+
+(module
+ ;; CHECK: (type $A (func_subtype (param i32) func))
+ (type $A (func_subtype (param i32) func))
+ ;; CHECK: (type $B (func_subtype (param i32) $A))
+ (type $B (func_subtype (param i32) $A))
+
+ ;; CHECK: (func $bar (type $B) (param $x i32)
+ ;; CHECK-NEXT: (nop)
+ ;; CHECK-NEXT: )
+ (func $bar (type $B) (param $x i32)
+ ;; The parameter to this function can be pruned. But while doing so we must
+ ;; properly preserve the subtyping of $B from $A, which means we cannot just
+ ;; remove it - we'd need to remove it from $A as well, which we don't
+ ;; attempt to do in the pass atm. So we do not optimize here.
+ (nop)
+ )
+)