From 0a6fc89da2e09b0ccf23196b7a97e71013aba7e0 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Wed, 7 Jul 2021 20:20:06 +0200 Subject: [PATCH] Fix negation function name collision. --- libsolidity/codegen/YulUtilFunctions.cpp | 2 +- .../externalContracts/prbmath_signed.sol | 6 +++--- .../semanticTests/viaYul/negation_bug.yul | 13 +++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 test/libsolidity/semanticTests/viaYul/negation_bug.yul diff --git a/libsolidity/codegen/YulUtilFunctions.cpp b/libsolidity/codegen/YulUtilFunctions.cpp index d7c31a72b..bd86dc9c2 100644 --- a/libsolidity/codegen/YulUtilFunctions.cpp +++ b/libsolidity/codegen/YulUtilFunctions.cpp @@ -4029,7 +4029,7 @@ string YulUtilFunctions::negateNumberWrappingFunction(Type const& _type) IntegerType const& type = dynamic_cast(_type); solAssert(type.isSigned(), "Expected signed type!"); - string const functionName = "negate_" + _type.identifier(); + string const functionName = "negate_wrapping_" + _type.identifier(); return m_functionCollector.createFunction(functionName, [&]() { return Whiskers(R"( function (value) -> ret { diff --git a/test/libsolidity/semanticTests/externalContracts/prbmath_signed.sol b/test/libsolidity/semanticTests/externalContracts/prbmath_signed.sol index 2936cf86f..77be50301 100644 --- a/test/libsolidity/semanticTests/externalContracts/prbmath_signed.sol +++ b/test/libsolidity/semanticTests/externalContracts/prbmath_signed.sol @@ -50,11 +50,11 @@ contract test { // compileViaYul: also // ---- // constructor() -// gas irOptimized: 1947094 +// gas irOptimized: 1965559 // gas legacy: 2602700 // gas legacyOptimized: 1874490 // div(int256,int256): 3141592653589793238, 88714123 -> 35412542528203691288251815328 -// gas irOptimized: 22222 +// gas irOptimized: 22244 // gas legacy: 22767 // gas legacyOptimized: 22282 // exp(int256): 3141592653589793238 -> 23140692632779268978 @@ -82,7 +82,7 @@ contract test { // gas legacy: 22807 // gas legacyOptimized: 22295 // pow(int256,uint256): 3141592653589793238, 5 -> 306019684785281453040 -// gas irOptimized: 22863 +// gas irOptimized: 22861 // gas legacy: 23508 // gas legacyOptimized: 22921 // sqrt(int256): 3141592653589793238 -> 1772453850905516027 diff --git a/test/libsolidity/semanticTests/viaYul/negation_bug.yul b/test/libsolidity/semanticTests/viaYul/negation_bug.yul new file mode 100644 index 000000000..6174eadd1 --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/negation_bug.yul @@ -0,0 +1,13 @@ +contract C { + function f() public pure { + -(int8(0)); + unchecked { + // Used to incorrectly use the checked unary negation function and revert. + (-(type(int8).min)); + } + } +} +// ==== +// compileViaYul: also +// ---- +// f() ->