Skip to content

Java frontend requires --simplify for constant casts #1015

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
smowton opened this issue Jun 15, 2017 · 8 comments
Closed

Java frontend requires --simplify for constant casts #1015

smowton opened this issue Jun 15, 2017 · 8 comments
Assignees

Comments

@smowton
Copy link
Contributor

smowton commented Jun 15, 2017

The Java frontend synthesises expressions like (signedbv_typet(32)) (integer_typet(50)), for example due to the bytecode op bipush 50, for which the parser makes an integer-typed constant for the 50 and then wraps it in a typecast for the bipush (see https://github.com/diffblue/cbmc/blob/master/src/java_bytecode/java_bytecode_convert_method.cpp#L1416)

Problem is, only simplify_expr actually understands that construct (at https://github.com/diffblue/cbmc/blob/master/src/util/simplify_expr.cpp#L451); in particular boolbvt::convert_typecast does not, and for input:

public class test {
  public void f() {
    int x = 50;
  }
}

with command line: cbmc test.class --no-simplify --function test.f --cover location

We get the predictable error:

warning: ignoring typecast
  * type: signedbv
      * width: 32
      * #c_type: signed_int
  0: constant
      * type: integer
      * value: 50

Therefore I say the Java frontend should forcibly simplify that expression immediately upon generating it, rather than hope for optional downstream passes to fix it up.

@martin-cs
Copy link
Collaborator

martin-cs commented Jun 15, 2017 via email

@smowton
Copy link
Contributor Author

smowton commented Jun 15, 2017

The use case was "trying to create a new driver program, failing to set 'simplify', wondering why the Java frontend produces illegal expressions"

@smowton
Copy link
Contributor Author

smowton commented Jun 15, 2017

And bipush semantics are to push a constant int -- the existence of the cast at all is just a convenience thing for the parser.

@smowton
Copy link
Contributor Author

smowton commented Jun 15, 2017

To phrase this another way, surely simplify should be doing what it says -- simplifying, making a downstream task easier rather than possible -- rather than eliminating certain expression forms that other passes fail to cover?

@tautschnig
Copy link
Collaborator

To phrase this another way, surely simplify should be doing what it says -- simplifying, making a downstream task easier rather than possible -- rather than eliminating certain expression forms that other passes fail to cover?

Yes, but as just said in #1016 (comment) I am wondering whether those expressions should exist in the first place?!

@martin-cs
Copy link
Collaborator

martin-cs commented Jun 15, 2017 via email

@martin-cs
Copy link
Collaborator

martin-cs commented Jun 15, 2017 via email

@smowton
Copy link
Contributor Author

smowton commented Jun 16, 2017

I don't think the semantics require them; the contexts where they're used already specify a byte or half-word or similar rather than an arbitrary integer, so going via a universal integer intermediate format is purely a convenience. Simplify-when-built: the attached PR does this.

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

No branches or pull requests

3 participants