Skip to content

Fix _Bool XML output #357

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

Merged
merged 5 commits into from
Jan 16, 2017
Merged

Conversation

peterschrammel
Copy link
Member

No description provided.

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

Looks good to me. (With the minor concern, which is just triggered by the commit, that this code does similar stuff as expr2ct while not actually sharing code.)

e.set_attribute("member_name",
id2string(to_union_expr(expr).get_component_name()));
e.set_attribute(
"member_name", id2string(to_union_expr(expr).get_component_name()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would have put the id2string(...) on a new line.

else if(type.id()==ID_c_bool)
{
result.name="integer";
result.set_attribute("c_type", "_Bool");
Copy link
Member

Choose a reason for hiding this comment

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

It is very confusing that an integer can be "FALSE" or "TRUE". Either there has to be a different result.name, or the value has to be 0/1.

Copy link
Member Author

@peterschrammel peterschrammel Dec 16, 2016

Choose a reason for hiding this comment

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

Currently, we have non-1 solutions for "true" in the counterexample, which comes from the fact that we are looking for a non-0 solution when translating the conditional:
// 26 file cover_line_input_boolean.c line 4 function foo
IF !(par != FALSE && a == 1) THEN GOTO 1

However, C99, at least, demands that the values of _Bool are 0 and 1 only. We can output the actual integer value provided that we force "true" to be 1 elsewhere...

This is failing:

void main()
{
  int x;
  _Bool y;
  if(y) 
  {  
    x=(int)y;
    assert(x==1);
  }
}

Copy link
Member

Choose a reason for hiding this comment

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

Note that the above has undefined behaviour, i.e., it's good that this fails!
If you do y=nondet_bool(), with _Bool nondet_bool(), you get the expected result.

Copy link
Member Author

Choose a reason for hiding this comment

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

We have to explicitly initialise all parameters passed to the entry function otherwise the following would still fail:

void foo(_Bool y)
{
  int x;
  if(y) 
  {  
    x=(int)y;
    assert(x==1);
  }
}

result.name="integer";
result.set_attribute("c_type", "_Bool");
result.set_attribute("binary", expr.get_string(ID_value));
mp_integer bool_constant;
Copy link
Member

Choose a reason for hiding this comment

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

The "binary" should be 0/1; the above yields true/false.

Copy link
Member Author

Choose a reason for hiding this comment

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

The binary is at least a byte...

Copy link
Member

Choose a reason for hiding this comment

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

Indeed; will merge once value inconsistency is fixed.

@kroening kroening self-assigned this Dec 16, 2016
@peterschrammel peterschrammel force-pushed the fix-c-bool-xml-output branch 2 times, most recently from fae71be to ace620d Compare January 7, 2017 17:10
@peterschrammel
Copy link
Member Author

@kroening, @tautschnig, updated.

mp_integer b;
to_integer(to_constant_expr(expr), b);
assert(b==mp_integer(0) || b==mp_integer(1));
result["data"]=json_stringt(integer2string(b));
Copy link
Member

Choose a reason for hiding this comment

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

The assertion is not guaranteed to hold; e.g., you can wreck this with a union, an uninitialised _Bool, or with a pointer typecast.

typecast_exprt(
side_effect_expr_nondett(unsignedbv_typet(bool_width)),
decl.symbol().type()));

Copy link
Member

Choose a reason for hiding this comment

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

Use side_effect_expr_nondett(bool_typet()) instead.

@kroening kroening merged commit ce9aa98 into diffblue:master Jan 16, 2017
smowton pushed a commit to smowton/cbmc that referenced this pull request May 9, 2018
…_traiting_of_models_lib_and_standard_lib

Python driver  improved traiting of models lib and Java standard lib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants