Skip to content

Rearchitect var args support (making it actually work) [blocks: #4329] #4238

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 4 commits into from
May 15, 2019

Conversation

tautschnig
Copy link
Collaborator

Previously all the logic to access values of variable argument lists was put
into our va_arg() implementation. This required guessing what the parameters
could have been, and did not take into account the initial value passed to
va_start.

Now va_start triggers constructing an array of pointers to parameters, the first
of which is the original argument to va_start. The va_list is then just a
pointer to the first element of the array. va_arg just increments the pointer.
goto_program conversion places a side_effect_exprt where va_start was, and
goto-symex populates the array with the actual values applicable for a
particular invocation of the function.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • 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).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@tautschnig tautschnig changed the title Rearchitect var args support (making it actually work) Rearchitect var args support (making it actually work) [blocks: #4329] Feb 21, 2019
@tautschnig tautschnig self-assigned this Feb 21, 2019
@tautschnig tautschnig changed the title Rearchitect var args support (making it actually work) [blocks: #4329] Rearchitect var args support (making it actually work) [depends-on: #2068, blocks: #4329] Feb 21, 2019
@tautschnig
Copy link
Collaborator Author

Apologies for dragging in some many reviewers, that's just because I had to add the commits from #2068 to make things also work with the approach that Visual Studio uses for var args. Just the last three commits in this PR are actually new.

@tautschnig tautschnig force-pushed the var-args branch 2 times, most recently from 33cbaa7 to 6c85222 Compare February 22, 2019 20:05
@tautschnig tautschnig changed the title Rearchitect var args support (making it actually work) [depends-on: #2068, blocks: #4329] Rearchitect var args support (making it actually work) [blocks: #4329] Feb 26, 2019
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: ec8797e).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/102429546

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.

⚠️
This PR failed Diffblue compatibility checks (cbmc commit: 93ba1d6).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/102970072
Status will be re-evaluated on next push.
Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)

  • the author is not in the list of contributors (e.g. first-time contributors).

  • the compatibility was already broken by an earlier merge.

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.

⚠️
This PR failed Diffblue compatibility checks (cbmc commit: 7755806).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/102970915
Status will be re-evaluated on next push.
Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)

  • the author is not in the list of contributors (e.g. first-time contributors).

  • the compatibility was already broken by an earlier merge.

@tautschnig tautschnig force-pushed the var-args branch 2 times, most recently from 617c92a to 00f323d Compare March 12, 2019 12:30
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: 00f323d).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/104075038

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

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

Very little touches my areas of responsibility but those bits ae fine.

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: 0c5f08c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/105810019

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.

⚠️
This PR failed Diffblue compatibility checks (cbmc commit: dfd298a).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/108813088
Status will be re-evaluated on next push.
Common spurious failures include: the cbmc commit has disappeared in the mean time (e.g. in a force-push); the author is not in the list of contributors (e.g. first-time contributors); compatibility was already broken by an earlier merge.

^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment, say in the .desc file, how windows-preprocessed.i was produced?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was kind-of noted in the commit message, but I'll add a note in the .desc file as well!

else if(statement==ID_gcc_builtin_va_arg_next)
return convert_function(src, "gcc_builtin_va_arg_next");
else if(statement == ID_va_start)
return convert_function(src, CPROVER_PREFIX "va_start");
else
Copy link
Member

Choose a reason for hiding this comment

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

Does dumping still work with that change? Meaning do we still get a C program that gcc compiles?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The changes (in this PR) to goto-instrument/goto_program2code.cpp take care of this.

op_type.id() == ID_bool || op_type.id() == ID_c_enum ||
op_type.id() == ID_c_enum_tag || op_type.id() == ID_bv)
can_cast_type<bitvector_typet>(op_type) || op_type.id() == ID_c_enum ||
op_type.id() == ID_c_enum_tag)
{
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 ID_bool is not a bit vector type, i.e., this case is lost.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, thanks, fixed!

fits_slot,
typecast_exprt::conditional_cast(parameter_expr, void_ptr_type),
typecast_exprt::conditional_cast(
address_of_exprt{parameter_expr}, void_ptr_type)};
Copy link
Member

Choose a reason for hiding this comment

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

I am a bit surprised that this distinction needs to be a formula -- sure this isn't known at compile time?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe that almost always the simplifier will be able to take care of this - but apart from that this used to construct an object that doesn't even exist at compile time, so I'm not really sure what you'd like me to do?

Even floating-point values are ok to just be re-interpreted as bit strings.
This will aid debugging as Visual Studio mostly just uses macros to implement
the va_* functions.
We carry typedef names all the way now, there is no need for additional
annotations to preserve the typedef name of va_list for dump-c.
Previously all the logic to access values of variable argument lists was put
into our va_arg() implementation. This required guessing what the parameters
could have been, and did not take into account the initial value passed to
va_start.

Now va_start triggers constructing an array of pointers to parameters, the first
of which is the original argument to va_start. The va_list is then just a
pointer to the first element of the array. va_arg just increments the pointer.
goto_program conversion places a side_effect_exprt where va_start was, and
goto-symex populates the array with the actual values applicable for a
particular invocation of the function.
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: 18cbd69).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/111914482

@kroening kroening merged commit bc76446 into diffblue:develop May 15, 2019
@tautschnig tautschnig deleted the var-args branch May 16, 2019 08:39
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.

7 participants