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

[FIRRTL] Update LowerClasses to alter what PathInfo stores. #7522

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

mikeurbach
Copy link
Contributor

PathInfo stores a pointer to an Operation, which was problematic because that Operation may be deleted in updateInstanceInModule. The test case added in this patch would lead to a use-after-free.

This pointer was only really used for a few things, which can be handled differently to avoid needing to consider Operation lifetimes.

One use was the operator bool implementation, to check if a PathInfo is empty. In the one place this was used, an equivalent check is to query the PathInfoTable, and check if the key was not in the table.

Another use was adding the Operation's location in error messages and notes. We can safely store a Location directly for these messages.

The final use was to do an isa check while determining the target kind. This is where the use in the use-after-free would manifest. For this, we do the isa check early, and store the result in a bool.

In summary, we are able to simplify the data in PathInfo in order to avoid hanging on to an Operation pointer and needing to worry about its lifetime.

PathInfo stores a pointer to an Operation, which was problematic
because that Operation may be deleted in updateInstanceInModule. The
test case added in this patch would lead to a use-after-free.

This pointer was only really used for a few things, which can be
handled differently to avoid needing to consider Operation lifetimes.

One use was the operator bool implementation, to check if a PathInfo is
empty. In the one place this was used, an equivalent check is to query
the PathInfoTable, and check if the key was not in the table.

Another use was adding the Operation's location in error messages and
notes. We can safely store a Location directly for these messages.

The final use was to do an isa check while determining the target
kind. This is where the use in the use-after-free would manifest. For
this, we do the isa check early, and store the result in a bool.

In summary, we are able to simplify the data in PathInfo in order to
avoid hanging on to an Operation pointer and needing to worry about
its lifetime.
Copy link
Contributor

@dtzSiFive dtzSiFive left a comment

Choose a reason for hiding this comment

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

LGTM

assert(symRef && "symRef must not be null");
}

operator bool() const { return op != nullptr; }
/// The Location of the hardware component targeted by this path.
std::optional<Location> loc = std::nullopt;
Copy link
Member

Choose a reason for hiding this comment

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

Just double checking, since we're not using lookup anymore, do we need the PathInfo to be default constructible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm maybe not, I'm not sure if anything else still requires that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, default constructible is still required, at least for how we're using it when we add items with try_emplace. I will go ahead and merge this for now, and we could potentially keep reworking this.

Copy link
Member

@youngar youngar left a comment

Choose a reason for hiding this comment

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

💯

@mikeurbach mikeurbach merged commit 3821d74 into main Aug 15, 2024
4 checks passed
@mikeurbach mikeurbach deleted the mikeurbach/lower-classes-pathinfo-cleanup branch August 15, 2024 22:16
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.

3 participants