-
Notifications
You must be signed in to change notification settings - Fork 274
Refactoring of the parsing of the --object-bits
command line argument
#5447
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
Refactoring of the parsing of the --object-bits
command line argument
#5447
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.
Looks OK to me
src/util/config.cpp
Outdated
@@ -776,8 +776,8 @@ configt::bv_encodingt parse_object_bits_encoding( | |||
const std::string &argument, | |||
const std::size_t pointer_width) | |||
{ | |||
const unsigned int object_bits = unsafe_string2unsigned(argument); | |||
if(object_bits <= 0 || object_bits >= pointer_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.
⛏️ Would be better if the case where parsing fails and the object_bits
are out of range were separated, also it would be helpful for debugging to put argument
in the error message (this makes it easier to find if for example you've messed up a command line when copy&pasting, e.g. --object-bits --function hello world 8
)
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.
Done.
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.
Looks OK to me
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.
Couple of simple fixes otherwise lgtm
^EXIT=1$ | ||
^SIGNAL=0$ | ||
-- | ||
Test parsing of an invalid non numeric object-bits setting. |
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 is a must-not-match, not a comment (similarly others)
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.
src/util/config.cpp
Outdated
const std::size_t pointer_width) | ||
{ | ||
const auto object_bits = string2optional<unsigned int>(argument); | ||
if(!object_bits || *object_bits <= 0 || *object_bits >= pointer_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.
Note <= 0
on an unsigned type
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 have swapped this to use == 0
, as this should be less misleading.
In order to ensure that this functionality is not broken by subsequent refactorings.
So that `bv_encodingt` can be more used without the need to explicitly initialise its members.
So the length of `configt::set` can be marginally reduced. So that this functionality can be documented. This would also support unit testing of this parsing if unit tests are added later.
So that direct usage of this function can be more succinct.
The previous use of `unsafe_string2unsigned` handled non numeric input based on the behaviour of 0 being returned by `unsafe_string2unsigned`, which is then caught by the subsequent range check. It was well defined behaviour of `std::strtoul`. However this was only discoverable, based on looking at the implementation of `unsafe_string2unsigned` and reading the documentation of `std::strtoul` or by using a debugger. The explict check in the refactored version makes the handling of this case clear from reading `parse_object_bits_encoding` only, without reference to other code or documentation.
It is easier to debug your invocation of a command line tool if the specific invalid argument and the reason why it is invalid is given.
`object_bits <= 0` suggests that `object_bits` could be below zero. This is not possible because `object_bits` is unsigned. Checking for equal to zero makes it explicit that we are checking for one specific value.
dd4dac9
to
8efa7cc
Compare
Codecov Report
@@ Coverage Diff @@
## develop #5447 +/- ##
========================================
Coverage 68.22% 68.22%
========================================
Files 1178 1178
Lines 97580 97579 -1
========================================
+ Hits 66573 66575 +2
+ Misses 31007 31004 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
As I was working on #5440, I found the entry point code less than straight forward to follow. I carried out this refactorings locally in order to make it easier for me to understand. I am raising this separate PR containing the refactoring work only as it was not required in order to implement the feature in the original PR, but should still improve maintainability.
The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/My commit message includes data points confirming performance improvements (if claimed).