-
Notifications
You must be signed in to change notification settings - Fork 284
Function type consistency between goto programs and symbol table #3127
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
A simple iteration over goto-functions to check that it's base type is the same as the one stored in the symbol table.
src/goto-programs/goto_model.h
Outdated
| if(!base_type_eq( | ||
| it->second.type, symbol_table.lookup_ref(it->first).type, ns)) | ||
| { | ||
| msg.error() << "error" << messaget::eom; |
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.
Say what's wrong!
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, a better error message here would be good.
src/cbmc/cbmc_parse_options.cpp
Outdated
| return get_goto_program_ret; | ||
|
|
||
| INVARIANT( | ||
| !goto_model.check_internal_invariants(*this), |
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.
check_consistency?
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 find these a little bit confusing in design, both here and in #3118. Do you think it would be better if check_internal_invariants returned true by default, as the all is good case, and false otherwise? This invariant would also look cleaner as well, as it would just read as the internal invariants of the goto model should always hold, which this is what the invariant will check by essence of it returning true and not if this doesn't return false, then the internal invariants hold. Like, it's the double negative both in the condition here, and the return values of check_internal_invariants that's slightly confusing, as it's inverse logic to what's expected. But that's just me, certainly not required.
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.
@smowton Within this PR, yes. But we are preparing a larger collection of checks and not all of them target consistency.
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.
@NlightNFotis it was my understanding that we prefer returning true when things fail. It can of course be negated.
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.
@NlightNFotis My understanding is that linux programs return 0 to indicate no error and a non-zero integer to represent some kind of error. C programs copy this and return 0 to indicate no error. We follow this by returning false to indicate no error and true to indicate error. I find it confusing too.
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.
Yeah most functions return true on error and false on success. Let's stick with this convention for consistency for now.
NlightNFotis
left a comment
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 couple of comments.
src/goto-programs/goto_model.h
Outdated
| if(!base_type_eq( | ||
| it->second.type, symbol_table.lookup_ref(it->first).type, ns)) | ||
| { | ||
| msg.error() << "error" << messaget::eom; |
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, a better error message here would be good.
src/cbmc/cbmc_parse_options.cpp
Outdated
| return get_goto_program_ret; | ||
|
|
||
| INVARIANT( | ||
| !goto_model.check_internal_invariants(*this), |
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 find these a little bit confusing in design, both here and in #3118. Do you think it would be better if check_internal_invariants returned true by default, as the all is good case, and false otherwise? This invariant would also look cleaner as well, as it would just read as the internal invariants of the goto model should always hold, which this is what the invariant will check by essence of it returning true and not if this doesn't return false, then the internal invariants hold. Like, it's the double negative both in the condition here, and the return values of check_internal_invariants that's slightly confusing, as it's inverse logic to what's expected. But that's just me, certainly not required.
allredj
left a comment
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.
Passed Diffblue compatibility checks (cbmc commit: 8558e89).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/87310747
Now reports the id of violating function and the two inconsistent types.
allredj
left a comment
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.
Passed Diffblue compatibility checks (cbmc commit: 150cf46).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/87323737
src/cbmc/cbmc_parse_options.cpp
Outdated
| return get_goto_program_ret; | ||
|
|
||
| INVARIANT( | ||
| !goto_model.check_internal_invariants(*this), |
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.
Yeah most functions return true on error and false on success. Let's stick with this convention for consistency for now.
src/goto-programs/goto_model.h
Outdated
| namespacet ns(symbol_table); | ||
| forall_goto_functions(it, goto_functions) | ||
| { | ||
| if(!base_type_eq( |
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.
Could use the DATA_CHECK macros.
Using DATA_CHECK instead of calling error handling directly.
allredj
left a comment
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.
Passed Diffblue compatibility checks (cbmc commit: 43052d5).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/87497802
408c810 to
7ceafcc
Compare
Builds a goto model with one function and checks that: 1) with the right type in the table the validation succeeds, 2) with the wrong type the validation fails.
7ceafcc to
00357ff
Compare
allredj
left a comment
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.
Passed Diffblue compatibility checks (cbmc commit: 00357ff).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/87657183
| /// goto programs, expressions, instructions, etc. Based on the value of the | ||
| /// variable vm (the validation mode), it either uses DATA_INVARIANT() to check | ||
| /// those conditions, or throws an exception when a condition does not hold. | ||
| #define DATA_CHECK(condition, message) \ |
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'm unclear why we want this. Either something is an invariant or it isn't, I don't see the value in having a single construct for both cases.
|
Moved to #3118. |
A simple iteration over goto-functions to check that it's base type is the same
as the one stored in the symbol table.