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

valid: Improve forward declaration validation #2232

Merged
merged 2 commits into from
Jan 31, 2023

Conversation

JCapucho
Copy link
Collaborator

This PR fixes an issue with the dependency code and adds dependency validation to function calls.

The handle validator had an issue that caused it to try to build a handle with a zero based index while type erasing handles, this would crash because the index must be a NonZeroU32 and it would also not be correct since the handle would be off by one from the original handle.

It also fixes the error message for the forward dependency not containing the subject's kind.

Lastly it adds a dependency check for function calls, to prevent forward declarations to pass to further stages and cause crashes (mitigates gfx-rs/wgpu#4477)

The handle dependency validation code was using the handle's index
directly while trying to erase the handle type. This would cause the
validator to crash while processing the first handle of the arena since
it would be trying to construct a `NonZeroU32` with a zero.

This commit fixes the issue by adding 1 to the index which not only
fixes this panic but also makes so that the created Handle is equal to
the passed handle (minus the type that was erased)

It also fixes the error message not including the subject's kind
This commit enforces the forward dependency rules on the IR across
functions and their calls, this fixes a crash in a later stage of the
validator.
Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

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

Good catch - thanks very much.

@jimblandy jimblandy merged commit 0074c68 into gfx-rs:master Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants