-
Notifications
You must be signed in to change notification settings - Fork 34
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
Validate stack height after unreachable #384
Conversation
Codecov Report
@@ Coverage Diff @@
## master #384 +/- ##
==========================================
+ Coverage 99.11% 99.32% +0.20%
==========================================
Files 42 42
Lines 12357 12489 +132
==========================================
+ Hits 12248 12405 +157
+ Misses 109 84 -25 |
c4fd3cb
to
9a68bb8
Compare
b965217
to
37756a2
Compare
5a2d02c
to
b2453a4
Compare
b2453a4
to
1e69b62
Compare
// Update code's max_stack_height using frame.stack_height of the previous instruction. | ||
// At this point frame.stack_height includes additional changes to the stack height | ||
// if the previous instruction is a call/call_indirect. | ||
// This way the update is skipped for end/else instructions (because their frame is | ||
// already popped/reset), but it does not matter, as these instructions do not modify | ||
// stack height anyway. | ||
code.max_stack_height = std::max(code.max_stack_height, frame.stack_height); | ||
} | ||
if (!frame.unreachable) |
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.
If we pull this max_stack_height
update out of outer if
, it looks like we can unify stack height update/checks for instructions and for calls, not sure if it's worth it. The error message for stack underflow would not be specific for calls then...
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.
I think this can be done in separate PR to confirm coverage of this version is full.
1e69b62
to
ffc11b9
Compare
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.
The final version looks good to me.
// Update code's max_stack_height using frame.stack_height of the previous instruction. | ||
// At this point frame.stack_height includes additional changes to the stack height | ||
// if the previous instruction is a call/call_indirect. | ||
// This way the update is skipped for end/else instructions (because their frame is | ||
// already popped/reset), but it does not matter, as these instructions do not modify | ||
// stack height anyway. | ||
code.max_stack_height = std::max(code.max_stack_height, frame.stack_height); | ||
} | ||
if (!frame.unreachable) |
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.
I think this can be done in separate PR to confirm coverage of this version is full.
ffc11b9
to
9b6d045
Compare
Squashed "simplify" commit. |
This applies the logic of Validation algorithm regarding unreachable to stack height checks.
Specifically
After unreachable any underflowing pop is ignored, but pushes add to stack growth.
When current frame is marked unreachable, stack height is reset.
"Simplify" commit is not squashed yet to show the different nested organization of nested ifs. I find the final one better.