-
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
More stack height validation #319
Conversation
49229ea
to
0ee5474
Compare
@@ -76,6 +91,23 @@ void update_caller_frame(ControlFrame& frame, const FuncType& func_type) | |||
frame.stack_height += stack_height_change; | |||
} | |||
|
|||
void validate_result_count(const ControlFrame& frame) |
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.
Why isn't this a helper or a constructor on ControlFrame
?
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.
Conceptually: because ControlFrame
is pure data type, and it does not know how to do validation.
Also: there is update_caller_frame()
.
This commit I think should be enough to get function arity information 5e86830 |
I'm leaving this for later, so we can parallelize validation and stack optimization PRs. |
@@ -87,7 +121,9 @@ parser_result<Code> parse_expr(const uint8_t* pos, const uint8_t* end, const Mod | |||
// For a block/if/else instruction the value is the block/if/else's immediate offset. | |||
std::stack<ControlFrame> control_stack; | |||
|
|||
control_stack.push({Instr::block}); // The function's implicit block. | |||
// TODO: Get function result arity from the function type in Module. |
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.
In a later PR?
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 validates if frames leave enough results they promised, however this check is missing for function frames (function type information is missing, but this is fixed in #312 - see a TODO comment). The situation where there is more results left is also not reported, but is easy to add - see TODO comment. This cannot be applied now because a lot of false positives when function result arity is so far assumed 0.
The frame
stack_height
now uses absolute values what will be useful for jump resolving in #312 and makes computing code's max stack height straight forward (as it is max value of anyframe.stack_height
).