-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
LLL: alloc issues round-up #2545
Conversation
Note that, alternatively,
The downside of this is that it removes the opportunity to do memory management between |
test/liblll/EndToEndTest.cpp
Outdated
{ | ||
char const* sourceCode = R"( | ||
(returnlll | ||
(return (- (msize) (alloc (calldataload 0x04))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is (msize) - (alloc..)
, right? So the resulting value should be how much was allocated.
Can you please add that as a comment somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is weird though it assumes that execution goes as:
- alloc
- msize
- sub
But the compiler could actually execute the two operands in a different order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Good spot. I've updated it to be resistant to changes in argument evaluation order. Ugly but effective.
b4ab7c7
to
6ccda04
Compare
test/liblll/EndToEndTest.cpp
Outdated
(returnlll | ||
(seq | ||
(mstore 0x00 0) ; reserve space for the result of the alloc | ||
(mstore 0x00 (alloc (calldataload 0x04))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation seems to be off here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaaagh... must fix my editor...
457f5ca
to
057c165
Compare
My only nitpicking is I like comments above statements (as opposed to next to them), but I guess it is more readable in this case, since it fits a single window. Please include your macro version as a comment in the macro section so it is not forgotten. Let's keep the native version for now and see if we can/should fix |
@@ -523,14 +523,24 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) | |||
requireSize(1); | |||
requireDeposit(0, 1); | |||
|
|||
m_asm.append(Instruction::MSIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment here explaining the rules:
- returns msize prior to expansion
- doesn't allocate in case of N = 0
- rounds N to a multiple of 32
- uses MLOAD to expand, which keeps memory untouched
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
057c165
to
3bc935d
Compare
Comments were mainly for my benefit; happy to keep them, move them, leave them...
Done. I put it at the top as some of the other macros could probably usefully be rewritten to use ALLOC now that it is reliable. I've squashed the commits into one for convenience. By the way, I wrote some docs. |
This is an attempt to move the LLL
alloc
issue on. It supersedes PRs #2489 and #2463, and resolves Issue #2465.The proposed change to the generated bytecode is the tightest code I can make that handles both the edge cases
(alloc 0)
andMSIZE
being initially zero.Notes:
(alloc 0)
does not allocate any memory. This is contra @chriseth, but in line with @axic.MLOAD
rather thanMSTORE8
to increaseMSIZE
. This is a belt-and-braces guard against memory corruption.MSIZE
being intially zero, which is a problem for @axic's approach in [WIP] LLL: change alloc to use mload and fix alloc(0) #2489.A bunch of test cases is included that should be comprehensive.
Fixes #2465.