From da407c06333857f153f9fd1dba780dfbc64677bc Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 13 Sep 2016 17:50:17 -0700 Subject: drop if-else arms as necessary --- src/ast_utils.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ast_utils.h b/src/ast_utils.h index f883d5f66..4664f22ae 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -881,9 +881,21 @@ struct AutoDrop : public WalkerPassifFalse && isConcreteWasmType(curr->ifTrue->type)) { - curr->ifTrue = Builder(*getModule()).makeDrop(curr->ifTrue); + if (curr->ifFalse) { + if (!isConcreteWasmType(curr->type)) { + // if either side of an if-else not returning a value is concrete, drop it + if (isConcreteWasmType(curr->ifTrue->type)) { + curr->ifTrue = Builder(*getModule()).makeDrop(curr->ifTrue); + } + if (isConcreteWasmType(curr->ifFalse->type)) { + curr->ifFalse = Builder(*getModule()).makeDrop(curr->ifFalse); + } + } + } else { + // if without else does not return a value, so the body must be dropped if it is concrete + if (isConcreteWasmType(curr->ifTrue->type)) { + curr->ifTrue = Builder(*getModule()).makeDrop(curr->ifTrue); + } } } -- cgit v1.2.3