Skip to content

Fix stubbed String constructor special case #4495

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

Conversation

antlechner
Copy link
Contributor

This PR fixes a bug that was caused/uncovered by #4483.
Generally JBMC should only be run on methods that include Strings if a model for String is loaded. However, --show-properties should work even without the model. After the changes in #4483, in the special case where the Java method includes a call to a String constructor and no model for it was loaded, we didn't check if the object had a string type, and a pointer to an unsignedbv ended up in the pointer case of the object factory, causing an invariant violation. This PR fixes the conditions in the struct case of the object factory so it always checks if the type is a String type, not only when skip_classid is false.

  • Each commit message has a non-empty body, explaining why the change was made. [except for the new test, which has a description in its .desc file]
  • 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/
  • n/a 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.

if(!is_sub &&
!skip_classid &&
update_in_place != update_in_placet::MUST_UPDATE_IN_PLACE)
// * Always if it has a string type (special case).
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ I don't think (special case) is necessary here. Rather an explanation of why strings are a special case would be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a few more lines, with a reference to the function that initialises string fields. Any further documentation should probably go to that function.

// * Always if it has a string type (special case).

const bool is_char_sequence =
java_string_library_preprocesst ::implements_java_char_sequence(
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ ❓ Is it customary to have a space before the double colon?

Copy link
Contributor

Choose a reason for hiding this comment

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

No :p

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh, clang-format did this, not sure why! I'll fix it as CI is failing with a linting error anyway.

@@ -801,12 +801,11 @@ void java_object_factoryt::gen_nondet_struct_init(
struct_type);
const bool has_length_and_data =
struct_type.has_component("length") && struct_type.has_component("data");
const bool skip_special_string_fields =
is_char_sequence && has_length_and_data;
const bool is_string_type = is_char_sequence && has_length_and_data;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Thanks for changing that. The name was really bad.

@antlechner antlechner force-pushed the antonia/stubbed-string-constructors branch from f471fd7 to c6e5552 Compare April 8, 2019 12:56
Antonia Lechner added 3 commits April 8, 2019 14:00
For a given struct, the object factory previously checked if it was a
string only in the case where skip_classid was set to false and the
update strategy was NO_UPDATE_IN_PLACE or MAY_UPDATE_IN_PLACE.
This missed some cases, for example the case where no model for String
is loaded and the Java method includes a call to a string constructor
that depends on a model. In this case the constructor is stubbed and
skip_classid is set to true in java_simple_method_stubst. Before this
fix, the object factory would go through the components of the string
expression as if it was a regular object expression, and hit an
invariant violation because the data component is stored as a pointer
to an unsignedbv, contradicting the assumption that all pointers point
to structs.
There are more decisions associated with this variable than whether or
not to skip the length and data fields.
@antlechner antlechner force-pushed the antonia/stubbed-string-constructors branch from c6e5552 to 9bc1a6e Compare April 8, 2019 13:00
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: 9bc1a6e).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/107467585
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.

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

@antlechner antlechner merged commit 20cd882 into diffblue:develop Apr 8, 2019
@antlechner antlechner deleted the antonia/stubbed-string-constructors branch April 8, 2019 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants