Giter Club home page Giter Club logo

Comments (6)

cameel avatar cameel commented on May 25, 2024

Thanks for the report! It's a real issue, but we already have one covering it (#13969), so I'm going to close this one as a duplicate.

On 0.8.x and earlier it's best to consider the result of comparisons between internal function pointers undefined (i.e. it has a consistent value, but not across compilations; do not rely on this value staying the same regardless of compiler settings or releases). The pointer type has always been (intentionally) treated as opaque in the language. The underlying value cannot be obtained without using assembly and was only indirectly exposed via this kind of comparison. Its usefulness is questionable so hopefully this pattern is pretty rare. A proper fix is breaking so it's only going to be fixed in 0.9, but we're going to start issuing a warning about this pattern soon.

solc compiler ignored the effect of identifiers on the contract code when the optimizer was on, only cared about the function statements, and collapsed the storage if the function statements were consistent.

Well, the values of the storage variables are never used (statements a; and b; have no side-effects) so the optimizer is very likely to remove them and collapse the function bodies into one.

from solidity.

Xutp-F avatar Xutp-F commented on May 25, 2024

But I ran into the same problem in a similar example below:I can understand that when f3() is executed, the local variable has been released, so the optimizer considers it consistent.

pragma solidity ^0.8.18;

contract Test {

function c() public {uint a = 1;}
function b() public {bool a = true;}

function f3() external returns(bool) {
return c == b;
}
}

from solidity.

Xutp-F avatar Xutp-F commented on May 25, 2024

hello,I was wondering if you could still receive my comments after the issue is closed?

from solidity.

cameel avatar cameel commented on May 25, 2024

I mean, this issue is closed as a duplicate, but #13969 is still open. But I'm not sure what your question is here.

from solidity.

Xutp-F avatar Xutp-F commented on May 25, 2024

What I mean is that the original examples provided may not have significant functional differences, but in the following examples, the local variable "uint a = 1;" and "bool a = true;" should not generate the same error. However, in fact, they triggered the aforementioned error.
contract Test {
function c() public { uint a = 1;}
function b() public { bool a = true;}
function f3() external returns(bool) {
return c == b;
}
}

from solidity.

cameel avatar cameel commented on May 25, 2024

Why do you think they should not generate the same error? Both variable declarations are basically no-ops so the optimizer may remove them.

If you want something that won't get optimized out, it needs to affect the environment. Like, change the return value, write to storage, emit an event, revert, etc.

BTW, if you want to see what really happens, compile with --optimize --ir-optimized and look for the function in the output.

from solidity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.