Skip to content

The optimizer incorrectly removes sstore instructions in initialization code when followed by a call to an undefined internal function #15707

@m4k2

Description

@m4k2

Description

The optimizer incorrectly removes sstore instructions in initialization code when followed by a call to an undefined internal function (foo()).

Environment

  • Compiler version: 0.8.28
  • Target EVM version (as per compiler settings): Cancun
  • Framework/IDE (e.g. Truffle or Remix): None
  • EVM execution environment / backend / blockchain client: None
  • Operating system: Linux

Steps to Reproduce

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

contract A {
    function() internal foo;

    constructor(uint256 x, bytes memory) {
        assembly {
            sstore(1, x)
        }

        foo();
    }
}
$ solc-select install 0.8.12 && solc-select use 0.8.12
Installing solc '0.8.12'...
Version '0.8.12' installed.
Switched global version to 0.8.12

$ solc --optimize --ir-optimized src/A.sol | grep sstore
            sstore(1, var_x)

$ solc-select install 0.8.13 && solc-select use 0.8.13
Installing solc '0.8.13'...
Version '0.8.13' installed.
Switched global version to 0.8.13

$ solc --optimize --ir-optimized src/A.sol | grep sstore
# (no match)

$ solc-select install 0.8.28 && solc-select use 0.8.28
Installing solc '0.8.28'...
Version '0.8.28' installed.
Switched global version to 0.8.28

$ solc --optimize --ir-optimized src/A.sol | grep sstore
# (no match)

Expected behavior: find sstore in the ir-optimized output.
Actual behavior: the sstore is missing from the ir-optimized output with solc 0.8.28.

It worked as expected in 0.8.12 but from 0.8.13 to 0.8.28, the sstore is missing from the ir-optimized output

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions