Skip to content

Duplicate tag position when compiling Yul code defining multiple functions with the same name #12090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
d-xo opened this issue Oct 5, 2021 · 3 comments · Fixed by #12139
Closed
Assignees
Labels
annoys users 😢 bug 🐛 should compile without error Error is reported even though it shouldn't. Source is fine.

Comments

@d-xo
Copy link
Contributor

d-xo commented Oct 5, 2021

Description

While updating dapptools to solc0.8.9 we noticed that the following yul program now produces a c++ exception when compiling with 0.8.9 (it was fine with 0.8.7).

> solc-0.8.9 --strict-assembly hi.yul
Warning: Yul is still experimental. Please use the output with care.

======= hi.yul (EVM) =======

Pretty printed source:
object "object" {
    code {
        calldatacopy(0, 0, 1024)
        {
            function z() -> x
            { x := y() }
            function y() -> x
            { x := z() }
        }
        {
            function z() -> x
            { x := y() }
            function y() -> x
            { x := z() }
        }
    }
}

Exception while assembling: /solidity/libevmasm/Assembly.cpp(720): Throw in function const solidity::evmasm::LinkerObject& solidity::evmasm::Assembly::assemble() const
Dynamic exception type: boost::wrapexcept<solidity::evmasm::AssemblyException>
std::exception::what: Duplicate tag position.
[solidity::util::tag_comment*] = Duplicate tag position.

Environment

  • Compiler version: 0.8.9
  • Target EVM version (as per compiler settings): london
  • Framework/IDE (e.g. Truffle or Remix): none
  • EVM execution environment / backend / blockchain client: none
  • Operating system: linux
@chriseth
Copy link
Contributor

chriseth commented Oct 5, 2021

Thanks for reporting! My first hunch is that a workaround could be to rename the functions so that the names are unique, but of course, this should also compile as is.

@cameel cameel changed the title C++ exception when compiling yul code Duplicate tag position when compiling Yul code defining multiple functions with the same name Oct 5, 2021
@cameel cameel added the should compile without error Error is reported even though it shouldn't. Source is fine. label Oct 5, 2021
@chriseth chriseth self-assigned this Oct 14, 2021
@cameel
Copy link
Member

cameel commented Oct 17, 2021

I found a case that triggers an assertion at a different position in the same file on 0.8.9. Seems to be related to this issue - it's caused by Yul functions with the same name and different returns defined in different Solidity functions:

contract.sol:

contract C {
    function f() external {
        assembly {
            function x(i) -> a {}
        }
    }
    function g() external {
        assembly {
            function x(i) {}
        }
    }
}
solc --bin --experimental-via-ir contract.sol
Exception during compilation: /solidity/libevmasm/Assembly.cpp(350): Throw in function solidity::evmasm::AssemblyItem solidity::evmasm::Assembly::namedTag(const string&, size_t, size_t, std::optional<long unsigned int>)
Dynamic exception type: boost::wrapexcept<solidity::evmasm::AssemblyException>
std::exception::what:
[solidity::util::tag_comment*] =

EDIT: The example above is actually inline assembly while this issue is about Yul but I think the cause might be the same and #12139 might be a fix too.

@cameel
Copy link
Member

cameel commented Oct 17, 2021

I decided to report this case as a separate issue after all (#12158) because maybe for inline assembly solution should be different (we don't necessarily have to disable named labels) and because it can't be triggered by only giving the functions the same name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
annoys users 😢 bug 🐛 should compile without error Error is reported even though it shouldn't. Source is fine.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants