Skip to content
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

[Sol2Yul] Fixed an ICE on struct member copy #12579

Merged
merged 1 commit into from Jan 31, 2022
Merged

Conversation

hrkrshnn
Copy link
Member

@hrkrshnn hrkrshnn commented Jan 24, 2022

Closes #12220
Closes #12558

@hrkrshnn hrkrshnn force-pushed the fix-memory-copy-bug branch 2 times, most recently from aa99de4 to c3c5aac Compare January 24, 2022 11:46
@hrkrshnn hrkrshnn marked this pull request as ready for review January 24, 2022 11:47
@hrkrshnn hrkrshnn changed the title Fixed a ICE on calldata to struct member copy Fixed an ICE on struct member copy Jan 24, 2022
@hrkrshnn hrkrshnn force-pushed the fix-memory-copy-bug branch 2 times, most recently from c881e8f to a82eef9 Compare January 24, 2022 12:33
@hrkrshnn hrkrshnn changed the title Fixed an ICE on struct member copy [Sol2Yul] Fixed an ICE on struct member copy Jan 24, 2022
Copy link
Member

@ekpyron ekpyron left a comment

Choose a reason for hiding this comment

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

Mainly needs a changelog entry.

@hrkrshnn
Copy link
Member Author

@ekpyron Does it need a changelog entry? It's a change in Yul.

@ekpyron
Copy link
Member

ekpyron commented Jan 25, 2022

@ekpyron Does it need a changelog entry? It's a change in Yul.

Yes, but those have been added to the changelog for a while now.

@ekpyron
Copy link
Member

ekpyron commented Jan 25, 2022

So, can you add the entry ;-)?

@hrkrshnn hrkrshnn force-pushed the fix-memory-copy-bug branch 2 times, most recently from e485450 to b324ccc Compare January 26, 2022 12:14
Changelog.md Outdated Show resolved Hide resolved
Changelog.md Outdated
@@ -17,6 +17,7 @@ Bugfixes:
* Control Flow Graph: Perform proper virtual lookup for modifiers for uninitialized variable and unreachable code analysis.
* Immutables: Fix wrong error when the constructor of a base contract uses ``return`` and the parent contract contains immutable variables.
* IR Generator: Fix IR syntax error when copying storage arrays of structs containing functions.
* IR Generator: Fix IR syntax error when copying reference types in calldata and storage to struct members in memory.
Copy link
Member

@ekpyron ekpyron Jan 26, 2022

Choose a reason for hiding this comment

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

It's not only struct members, but also array elements, isn't it?
Might actually be worth another simple test case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually yeah, also array members, the test test/libsolidity/semanticTests/structs/copy_from_calldata.sol shows it.

Copy link
Member

Choose a reason for hiding this comment

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

We could add a few more tests, i.e. copying storage arrays to a memory array element, etc.... we can also consider that part of #12559, but we can also do it while we're at it...

Changelog.md Outdated
@@ -17,6 +17,7 @@ Bugfixes:
* Control Flow Graph: Perform proper virtual lookup for modifiers for uninitialized variable and unreachable code analysis.
* Immutables: Fix wrong error when the constructor of a base contract uses ``return`` and the parent contract contains immutable variables.
* IR Generator: Fix IR syntax error when copying storage arrays of structs containing functions.
* IR Generator: Fix IR syntax error when copying reference types in calldata and storage to struct members in memory.
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
* IR Generator: Fix IR syntax error when copying reference types in calldata and storage to struct members in memory.
* IR Generator: Fix IR syntax error when copying reference types in calldata and storage to struct or array members in memory.

@ekpyron would that work? I can commit and squash it afterwards.

Copy link
Member Author

@hrkrshnn hrkrshnn Jan 26, 2022

Choose a reason for hiding this comment

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

Hmm. Github is not rendering it properly! I'll add "or array" members.

bshastry
bshastry previously approved these changes Jan 26, 2022
Copy link
Contributor

@bshastry bshastry left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@ekpyron
Copy link
Member

ekpyron commented Jan 27, 2022

Changelog still needs to include the array part.

@hrkrshnn
Copy link
Member Author

@ekpyron sorry, will do this today.

@ekpyron
Copy link
Member

ekpyron commented Jan 31, 2022

Still missing the changelog entry change ;-).

@@ -0,0 +1,96 @@
pragma abicoder v2;

Copy link
Member Author

Choose a reason for hiding this comment

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

Added this example: @ekpyron

Copy link
Member Author

Choose a reason for hiding this comment

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

But this one surprisingly also compiles in other versions. So independent of the fix.

Copy link
Member

Choose a reason for hiding this comment

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

Hm... I'm pretty sure that there were cases that didn't work in other versions... let me see...

Copy link
Member

Choose a reason for hiding this comment

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

contract C {
        uint256[] x;

        function f() public {
                uint256[][] memory y = new uint256[][](1);
                y[0] = x;
        }
}

crashes on 0.8.11 with --experimental-via-ir --bin for me...

Copy link
Member

Choose a reason for hiding this comment

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

Actually, this test case you added also does, so it's fine - but it's not independent of the fix :-).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, my bad. Forgot to add --ir flag to the test. So yeah, it does crash!

@hrkrshnn hrkrshnn requested a review from ekpyron January 31, 2022 12:54
ekpyron
ekpyron previously approved these changes Jan 31, 2022
Copy link
Member

@ekpyron ekpyron left a comment

Choose a reason for hiding this comment

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

Code change and test look good, the changelog entry is still not really accurate, but I'm already approving.

Changelog.md Outdated
@@ -17,6 +17,7 @@ Bugfixes:
* Control Flow Graph: Perform proper virtual lookup for modifiers for uninitialized variable and unreachable code analysis.
* Immutables: Fix wrong error when the constructor of a base contract uses ``return`` and the parent contract contains immutable variables.
* IR Generator: Fix IR syntax error when copying storage arrays of structs containing functions.
* IR Generator: Fix IR syntax error when copying reference types in calldata and storage to struct or array members in memory.
Copy link
Member

Choose a reason for hiding this comment

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

Actually it wasn't really an IR syntax error, but a failing assertion, resp. it was unimplemented so far...

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixing this now.

Changelog.md Outdated
@@ -17,6 +17,7 @@ Bugfixes:
* Control Flow Graph: Perform proper virtual lookup for modifiers for uninitialized variable and unreachable code analysis.
* Immutables: Fix wrong error when the constructor of a base contract uses ``return`` and the parent contract contains immutable variables.
* IR Generator: Fix IR syntax error when copying storage arrays of structs containing functions.
* IR Generator: Fix ICE when copying reference types in calldata and storage to struct or array members in memory.
Copy link
Member Author

Choose a reason for hiding this comment

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

@ekpyron Changed to ICE.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, now it isn't sorted alphabetically anymore ;-D.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed!

ekpyron
ekpyron previously approved these changes Jan 31, 2022
@ekpyron
Copy link
Member

ekpyron commented Jan 31, 2022

It has a merge conflict now and something weird happened to CI (but looks like a weird CirecleCI issue independent of the PR) - so I'd hope a rebase will fix it...

@Assawal

This comment has been minimized.

@hrkrshnn hrkrshnn force-pushed the fix-memory-copy-bug branch 2 times, most recently from 3f400d1 to 58f8e52 Compare January 31, 2022 13:50
@hrkrshnn
Copy link
Member Author

Rebased @ekpyron :)

ekpyron
ekpyron previously approved these changes Jan 31, 2022
Changelog.md Outdated
@@ -18,6 +18,7 @@ Bugfixes:
* Immutables: Fix wrong error when the constructor of a base contract uses ``return`` and the parent contract contains immutable variables.
* IR Generator: Add missing cleanup during the conversion of fixed bytes types to smaller fixed bytes types.
* IR Generator: Add missing cleanup for indexed event arguments of value type.
* IR Generator: Fix ICE when copying reference types in calldata and storage to struct or array members in memory.
Copy link
Contributor

@chriseth chriseth Jan 31, 2022

Choose a reason for hiding this comment

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

We use ICE liberally, but the term is really difficult to understand without background and "internal error" is almost as short.

Copy link
Member Author

@hrkrshnn hrkrshnn Jan 31, 2022

Choose a reason for hiding this comment

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

I can fix this. There are liked 4 other ICEs in the same section! Will leave them untouched in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed!

@chriseth chriseth merged commit fd68cb1 into develop Jan 31, 2022
@chriseth chriseth deleted the fix-memory-copy-bug branch January 31, 2022 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants