ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
23.3k stars 5.77k forks source link

Strengthen storage variables being unassigned now that we have inline assembly #9651

Open chriseth opened 4 years ago

chriseth commented 4 years ago

Reported by @magnus237:

The following code does not report a warning because of the self-assignment:

function f() external pure {
    string storage s1;
    s1 = s1; // self-assignment
    string storage s2 = s1;
  }

Now that we have inline-assembly access to the slots, the following code would be a better (more explicit) way of saying "please ignore the warning":

function f() external pure {
    string storage s1;
    assembly { s1.slot := 0 }
    string storage s2 = s1;
  }

Can we change the control-flow-analyzer accordingly, i.e. do not take assignments from variables into account which are themselves not yet initialized?

ekpyron commented 2 years ago

Since by now this is not merely a warning, but an error, this becomes breaking - but still something we should do eventually.