Skip to content

Fix Java integers when --no-simplify is set #1016

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 2 commits into from
Jun 23, 2017

Conversation

smowton
Copy link
Contributor

@smowton smowton commented Jun 15, 2017

Fixes #1015

These are otherwise illegal expressions (at least to boolbvt), and so
get ignored. This problem usually doesn't show up as it requires
--no-simplify to escape subsequent incidental simplification.
@smowton smowton requested review from tautschnig and kroening June 15, 2017 09:00
// Force a simplify here in case we have --no-simplify
// because the simplifier is the only pass that knows how to
// deal with this cast from integer_typet:
results[0]=simplify_expr(typecast_exprt(arg0, java_int_type()), ns);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is an integer_typet being used in the first place? Does the Java standard state that these should be unbounded integers? Please clarify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing to do with me, that code predates Github, but basically it's just a parser simplicity thing-- the integer in the constant pool turns into a "universal" integer, then using it in an ipush instruction clarifies it ought to be considered an int32 or whatever

Copy link
Collaborator

Choose a reason for hiding this comment

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

I fully understand that this isn't a problem you had introduced - but I am questioning the fix. Looking at http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.1 the introduction of that integer_typet is just wrong and that is what ought to be fixed, instead of introducing the simplify_expr here.

Copy link
Contributor Author

@smowton smowton Jun 16, 2017

Choose a reason for hiding this comment

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

That's not quite the right bit of the language spec--- I think that concerns literals in the source, whereas this is a literal in bytecode (e.g. https://cs.au.dk/~mis/dOvs/jvmspec/ref-_bipush.html). At any rate converting the int8_t in the bytecode to an integer doesn't seem wrong, since it doesn't lose any information?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, my Java knowledge is rather limited -- I had assumed what was true in the source was also true of bytecode. Well, in fact the bytecode should have the bit width sorted out already, or at least your statement mentioning int8_t hints at that?

Yes, converting int8_t to integer shouldn't lose information, but it yields an expression that the backend cannot deal with.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. Either convert it back to a bitvector in the frontend (i.e. merge this PR) or have the parser create a bitvector to begin with (in which case I'll rewrite this Monday)

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 strongly vouch for creating a bitvector to begin with - the current approach is a very effective way of shooting oneself in the foot...

My apologies that you are getting all the backlash for code you haven't even written in the first place. I'll try to make up for that by contributing patches (it seems necessary to do a git grep integer_typet).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed an amended version that creates an integer directly in bytecode-convert-method. I didn't do it in the parser because that uses integer_typet everywhere, and making particular exceptions seemed uglier. Rather let's say the parser turns the bytecode format into a tree where integer members are represented as mp_integers (effectively), then convert-method produces valid codet expressions (and typecast-integer-to-bitvector is specifically not one).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll take a look; I have started to clear out most uses of integer_typet (in java_bytecode and elsewhere).

See issue cbmc#1015 for detail.
@smowton smowton force-pushed the smowton/fix/java_integers_without_simplify branch from 00f63e6 to e2e2360 Compare June 19, 2017 12:07
@tautschnig
Copy link
Collaborator

As much as I believe #1035 to be the more appropriate solution: I am not in a position to make that judgement. I'd suggest @kroening and @pkesseli weigh in on this.

@kroening kroening merged commit e0b4515 into master Jun 23, 2017
@smowton smowton deleted the smowton/fix/java_integers_without_simplify branch July 24, 2017 10:33
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.

3 participants