-
Notifications
You must be signed in to change notification settings - Fork 274
Factor out computation of maximum union member #5251
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
Conversation
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.
Cosmetic components
/// \return Pair of a member_exprt pointing to the maximum fixed bit-width | ||
/// member of \p union_type and the bit width of that member. | ||
static optionalt<std::pair<member_exprt, mp_integer>> | ||
find_maximum_union_component( |
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.
maximum -> widest?
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.
Fixed (and left-hand sides are renamed accordingly).
return {}; | ||
else | ||
return std::make_pair( | ||
member_exprt{union_expr, max_comp_name, max_comp_type}, max_width); |
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.
A bit surprising that a utility would make a member-expression, rather than just returning the widest component
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.
Good call - this makes one use slightly more work (having to construct the member_exprt
in place), but avoids a parameter that isn't really necessary and could be used in a wrong way.
Avoids duplicate code and enables future re-use.
c5b03fc
to
b44360c
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.
Happy enough for this to go in as it is, but just a mild query around the interface of find_widest_union_component
/// \return Pair of a componentt pointing to the maximum fixed bit-width | ||
/// member of \p union_type and the bit width of that member. | ||
static optionalt<std::pair<struct_union_typet::componentt, mp_integer>> | ||
find_widest_union_component(const union_typet &union_type, const namespacet &ns) |
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.
Is there any particular reason this returns an optional pair, rather than just an optional componentt
? Given that the componentt has the the appropriate type in it and the caller could just do pointer_offset_bits
themselves. If it's just to simplify future clients, then fine :-) But just wondering as I don't see any current clients using the second half of the pair, and having the extra ->first
or ->second
slightly reduces readability at the call sites.
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.
Yes, that second part is only used in #5252. I hope that's ok - I'll go ahead and merge.
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.
FWIW, you're of course right that the caller could compute the size themselves, but I thought duplicating work was not a good idea.
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.
Fine by me. I was reviewing in PR order so hadn't seen the followup PR at that point.
Avoids duplicate code and enables future re-use.
This is in preparation of further union support in byte-extract lowering. Refactoring is tested via existing unit tests.