Fix yul codegen bug when using binary negatition.

This commit is contained in:
Mathias Baumann 2021-06-29 15:32:24 +02:00
parent ccad22bafa
commit c47d02066c
5 changed files with 25 additions and 8 deletions

View File

@ -14,6 +14,7 @@ Bugfixes:
* Code Generator: Fix internal compiler error when calling functions bound to calldata structs and arrays.
* Code Generator: Fix internal compiler error when passing zero to ``bytes.concat()``.
* Type Checker: Fix internal error and prevent static calls to unimplemented modifiers.
* Yul Code Generator: Fix internal compiler error when using a long literal with bitwise negation.
### 0.8.6 (2021-06-22)

View File

@ -658,12 +658,21 @@ void IRGeneratorForStatements::endVisit(Return const& _return)
appendCode() << "leave\n";
}
void IRGeneratorForStatements::endVisit(UnaryOperation const& _unaryOperation)
bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation)
{
setLocation(_unaryOperation);
Type const& resultType = type(_unaryOperation);
Token const op = _unaryOperation.getOperator();
if (resultType.category() == Type::Category::RationalNumber)
{
define(_unaryOperation) << formatNumber(resultType.literalValue(nullptr)) << "\n";
return false;
}
_unaryOperation.subExpression().accept(*this);
setLocation(_unaryOperation);
if (op == Token::Delete)
{
solAssert(!!m_currentLValue, "LValue not retrieved.");
@ -689,8 +698,6 @@ void IRGeneratorForStatements::endVisit(UnaryOperation const& _unaryOperation)
m_currentLValue->kind
);
}
else if (resultType.category() == Type::Category::RationalNumber)
define(_unaryOperation) << formatNumber(resultType.literalValue(nullptr)) << "\n";
else if (resultType.category() == Type::Category::Integer)
{
solAssert(resultType == type(_unaryOperation.subExpression()), "Result type doesn't match!");
@ -749,6 +756,8 @@ void IRGeneratorForStatements::endVisit(UnaryOperation const& _unaryOperation)
}
else
solUnimplementedAssert(false, "Unary operator not yet implemented");
return false;
}
bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)

View File

@ -105,7 +105,7 @@ public:
bool visit(Continue const& _continueStatement) override;
bool visit(Break const& _breakStatement) override;
void endVisit(Return const& _return) override;
void endVisit(UnaryOperation const& _unaryOperation) override;
bool visit(UnaryOperation const& _unaryOperation) override;
bool visit(BinaryOperation const& _binOp) override;
void endVisit(FunctionCall const& _funCall) override;
void endVisit(FunctionCallOptions const& _funCallOptions) override;

View File

@ -236,8 +236,6 @@ object "C_81" {
let expr_25 := checked_exp_t_rational_2_by_1_t_uint256(expr_24)
/// @src 0:187,200
let var_w_22 := expr_25
/// @src 0:214,215
let expr_29 := 0x02
/// @src 0:213,215
let expr_30 := 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
/// @src 0:212,216
@ -285,8 +283,6 @@ object "C_81" {
/// @src 0:303,313
var_w_22 := expr_56
let expr_57 := expr_56
/// @src 0:323,324
let expr_60 := 0x01
/// @src 0:322,324
let expr_61 := 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
/// @src 0:321,325

View File

@ -0,0 +1,11 @@
contract C {
function f() public returns (bool) {
return
0 <
~~84926290883049832306107864558384249403874903260938453235235091622489261765859;
}
}
// ====
// compileViaYul: also
// ----
// f() -> true