Skip to content

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

Closed

Conversation

xbauch
Copy link
Contributor

@xbauch xbauch commented Oct 9, 2018

A simple iteration over goto-functions to check that it's base type is the same
as the one stored in the symbol table.

  • Each commit message has a non-empty body, explaining why the change was made.
  • My contribution is formatted in line with CODING_STANDARD.md.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

A simple iteration over goto-functions to check that it's base type is the same
as the one stored in the symbol table.
if(!base_type_eq(
it->second.type, symbol_table.lookup_ref(it->first).type, ns))
{
msg.error() << "error" << messaget::eom;
Copy link
Contributor

Choose a reason for hiding this comment

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

Say what's wrong!

Copy link
Contributor

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.

@@ -515,6 +515,10 @@ int cbmc_parse_optionst::doit()
if(get_goto_program_ret!=-1)
return get_goto_program_ret;

INVARIANT(
!goto_model.check_internal_invariants(*this),
Copy link
Contributor

Choose a reason for hiding this comment

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

check_consistency?

Copy link
Contributor

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.

Copy link
Contributor Author

@xbauch xbauch Oct 9, 2018

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

@NlightNFotis NlightNFotis left a 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.

if(!base_type_eq(
it->second.type, symbol_table.lookup_ref(it->first).type, ns))
{
msg.error() << "error" << messaget::eom;
Copy link
Contributor

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.

@@ -515,6 +515,10 @@ int cbmc_parse_optionst::doit()
if(get_goto_program_ret!=-1)
return get_goto_program_ret;

INVARIANT(
!goto_model.check_internal_invariants(*this),
Copy link
Contributor

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.

Copy link
Contributor

@allredj allredj left a 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.
Copy link
Contributor

@allredj allredj left a 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

@@ -515,6 +515,10 @@ int cbmc_parse_optionst::doit()
if(get_goto_program_ret!=-1)
return get_goto_program_ret;

INVARIANT(
!goto_model.check_internal_invariants(*this),
Copy link
Contributor

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.

namespacet ns(symbol_table);
forall_goto_functions(it, goto_functions)
{
if(!base_type_eq(
Copy link
Contributor

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.

danpoe and others added 2 commits October 10, 2018 13:59
Using DATA_CHECK instead of calling error handling directly.
Copy link
Contributor

@allredj allredj left a 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

@xbauch xbauch force-pushed the program_table_type_consistency branch from 408c810 to 7ceafcc Compare October 11, 2018 14:07
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.
@xbauch xbauch force-pushed the program_table_type_consistency branch from 7ceafcc to 00357ff Compare October 11, 2018 14:10
Copy link
Contributor

@allredj allredj left a 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) \

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.

@xbauch
Copy link
Contributor Author

xbauch commented Nov 12, 2018

Moved to #3118.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants