Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libsolidity/codegen/ExpressionCompiler.cpp

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR needs a changelog entry. Something like:

* Evmasm Code Generator: Fix internal compiler error when `abi.encodeCall` is referenced but not called.

Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
solAssert(false, "min/max not available for the given type.");

}
else if ((std::set<std::string>{"encode", "encodePacked", "encodeWithSelector", "encodeWithSignature", "decode"}).count(member))
else if ((std::set<std::string>{"encode", "encodePacked", "encodeCall", "encodeWithSelector", "encodeWithSignature", "decode"}).count(member))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the issue at hand, but it would be good to also prevent it from happening in the future. We do have the list already under Kind::ABI in MagicType::nativeMembers(), so it should be reused here instead of being hard-coded.

We could refactor nativeMembers() to have a static overload taking just MagicType::Kind. Then initialize this set using that helper, filtering out non-function members (those may not be no-ops).

Alternatively, we could assert that it produces the same set. This would fail when we add a new member, but the advantage would be that we'd force them to have a look at this place and decide what to do. This would also make things more fool-proof by not excluding non-function members.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we have the same code in IRGeneratorForStatements.cpp (just without the bug):

else if (std::set<std::string>{"encode", "encodePacked", "encodeWithSelector", "encodeCall", "encodeWithSignature", "decode"}.count(member))

So that refactor should be done also there.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check why this assert is not triggered when the function is actually called? I'd expect that to enter here too.

{
// no-op
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ contract C {
function f() public pure {
abi.encode;
abi.encodePacked;
abi.encodeCall;
abi.encodeWithSelector;
abi.encodeWithSignature;
abi.decode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contract C {
function f() public pure {
abi.encodeCall;
}
}
// ----
// Warning 6133: (52-66): Statement has no effect.