Skip to content

Commit c47d020

Browse files
committed
Fix yul codegen bug when using binary negatition.
1 parent ccad22b commit c47d020

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Bugfixes:
1414
* Code Generator: Fix internal compiler error when calling functions bound to calldata structs and arrays.
1515
* Code Generator: Fix internal compiler error when passing zero to ``bytes.concat()``.
1616
* Type Checker: Fix internal error and prevent static calls to unimplemented modifiers.
17+
* Yul Code Generator: Fix internal compiler error when using a long literal with bitwise negation.
1718

1819

1920
### 0.8.6 (2021-06-22)

libsolidity/codegen/ir/IRGeneratorForStatements.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,21 @@ void IRGeneratorForStatements::endVisit(Return const& _return)
658658
appendCode() << "leave\n";
659659
}
660660

661-
void IRGeneratorForStatements::endVisit(UnaryOperation const& _unaryOperation)
661+
bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation)
662662
{
663663
setLocation(_unaryOperation);
664664
Type const& resultType = type(_unaryOperation);
665665
Token const op = _unaryOperation.getOperator();
666666

667+
if (resultType.category() == Type::Category::RationalNumber)
668+
{
669+
define(_unaryOperation) << formatNumber(resultType.literalValue(nullptr)) << "\n";
670+
return false;
671+
}
672+
673+
_unaryOperation.subExpression().accept(*this);
674+
setLocation(_unaryOperation);
675+
667676
if (op == Token::Delete)
668677
{
669678
solAssert(!!m_currentLValue, "LValue not retrieved.");
@@ -689,8 +698,6 @@ void IRGeneratorForStatements::endVisit(UnaryOperation const& _unaryOperation)
689698
m_currentLValue->kind
690699
);
691700
}
692-
else if (resultType.category() == Type::Category::RationalNumber)
693-
define(_unaryOperation) << formatNumber(resultType.literalValue(nullptr)) << "\n";
694701
else if (resultType.category() == Type::Category::Integer)
695702
{
696703
solAssert(resultType == type(_unaryOperation.subExpression()), "Result type doesn't match!");
@@ -749,6 +756,8 @@ void IRGeneratorForStatements::endVisit(UnaryOperation const& _unaryOperation)
749756
}
750757
else
751758
solUnimplementedAssert(false, "Unary operator not yet implemented");
759+
760+
return false;
752761
}
753762

754763
bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)

libsolidity/codegen/ir/IRGeneratorForStatements.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class IRGeneratorForStatements: public IRGeneratorForStatementsBase
105105
bool visit(Continue const& _continueStatement) override;
106106
bool visit(Break const& _breakStatement) override;
107107
void endVisit(Return const& _return) override;
108-
void endVisit(UnaryOperation const& _unaryOperation) override;
108+
bool visit(UnaryOperation const& _unaryOperation) override;
109109
bool visit(BinaryOperation const& _binOp) override;
110110
void endVisit(FunctionCall const& _funCall) override;
111111
void endVisit(FunctionCallOptions const& _funCallOptions) override;

test/cmdlineTests/exp_base_literal/output

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ object "C_81" {
236236
let expr_25 := checked_exp_t_rational_2_by_1_t_uint256(expr_24)
237237
/// @src 0:187,200
238238
let var_w_22 := expr_25
239-
/// @src 0:214,215
240-
let expr_29 := 0x02
241239
/// @src 0:213,215
242240
let expr_30 := 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
243241
/// @src 0:212,216
@@ -285,8 +283,6 @@ object "C_81" {
285283
/// @src 0:303,313
286284
var_w_22 := expr_56
287285
let expr_57 := expr_56
288-
/// @src 0:323,324
289-
let expr_60 := 0x01
290286
/// @src 0:322,324
291287
let expr_61 := 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
292288
/// @src 0:321,325
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
contract C {
2+
function f() public returns (bool) {
3+
return
4+
0 <
5+
~~84926290883049832306107864558384249403874903260938453235235091622489261765859;
6+
}
7+
}
8+
// ====
9+
// compileViaYul: also
10+
// ----
11+
// f() -> true

0 commit comments

Comments
 (0)