From f6e09d63689e396dab4273a70d02bf36b00d554b Mon Sep 17 00:00:00 2001 From: Mathias Baumann Date: Tue, 5 Mar 2019 17:32:13 +0100 Subject: [PATCH] YulOpt: Extend StructuralSimplifier to work with all types --- libyul/optimiser/StructuralSimplifier.cpp | 4 ++-- .../switch_inline_no_match_mixed.yul | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/libyul/yulOptimizerTests/structuralSimplifier/switch_inline_no_match_mixed.yul diff --git a/libyul/optimiser/StructuralSimplifier.cpp b/libyul/optimiser/StructuralSimplifier.cpp index 34ee26a16..8010b7b22 100644 --- a/libyul/optimiser/StructuralSimplifier.cpp +++ b/libyul/optimiser/StructuralSimplifier.cpp @@ -59,7 +59,7 @@ boost::optional StructuralSimplifier::hasLiteralValue(Expression cons if (expr && expr->type() == typeid(Literal)) { Literal const& literal = boost::get(*expr); - return valueOfNumberLiteral(literal); + return valueOfLiteral(literal); } return boost::optional(); @@ -114,7 +114,7 @@ void StructuralSimplifier::simplify(std::vector& _statements) for (auto& _case: _switchStmt.cases) { - if (_case.value && valueOfNumberLiteral(*_case.value) == constExprVal) + if (_case.value && valueOfLiteral(*_case.value) == constExprVal) { matchingCaseBlock = &_case.body; break; diff --git a/test/libyul/yulOptimizerTests/structuralSimplifier/switch_inline_no_match_mixed.yul b/test/libyul/yulOptimizerTests/structuralSimplifier/switch_inline_no_match_mixed.yul new file mode 100644 index 000000000..8d90ca1f0 --- /dev/null +++ b/test/libyul/yulOptimizerTests/structuralSimplifier/switch_inline_no_match_mixed.yul @@ -0,0 +1,12 @@ +{ + // Used to cause assert error + let y := 200 + switch 3 + case "" { y := 8 } + case 1 { y := 9 } +} +// ---- +// structuralSimplifier +// { +// let y := 200 +// }