-
Notifications
You must be signed in to change notification settings - Fork 284
Throw ArithmeticException whenever a division-by-zero is encountered #950
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
Throw ArithmeticException whenever a division-by-zero is encountered #950
Conversation
f6f4064 to
f74e4ba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure this shouldn't have some class type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm now using a class stub. Soon, we should have a proper model so that we can capture the class hierarchy (for now, this wouldn't be caught by a handler for, say, RuntimeException).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be the right place for this -- this should happen during conversion from program into goto-program.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think that this is a better place than the conversion to goto-program as the exception being thrown is language dependent. I assume we don't want to throw an exception for all input languages?
3ef77a1 to
85dd6b5
Compare
smowton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suspect object-factory needs replacing with a real constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Factor with java_bytecode_convert_classt::generate_class_stub?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we really nondet init it rather than calling a particular constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding an annotation here and then moving this to your existing instrumentation pass
|
Once #1019 is merged, this PR will need some major changes as the instrumentation added here also needs to be refactored out of bytecode convert. |
85dd6b5 to
dd811f1
Compare
dd811f1 to
6131121
Compare
|
Tested this with test case: I found that the way of initialising the exception object meant it could get thrown without being initialised. Made a couple of improvements here: https://github.com/smowton/cbmc/commits/smowton/feature/exceptions_improved |
|
Corresponding test-gen PR: https://github.com/diffblue/test-gen/pull/750 |
| i_it->statement=="checkcast" || | ||
| i_it->statement=="newarray" || | ||
| i_it->statement=="anewarray" || | ||
| i_it->statement==patternt("?div") || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only idiv and ldiv throw ArithmeticException, fdiv and ddiv do not. In addition irem and lrem throw, too.
| const source_locationt &original_loc) | ||
| { | ||
| symbolt exc_symbol; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as only integral div-by-zero throws, maybe add invariant for java_int_type or java_long_type
| expr.op0(), | ||
| expr.source_location()); | ||
| } | ||
| else if(expr.id()==ID_div) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs ID_mod, too, ID_rem is for float/double, if I understood correctly
peterschrammel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smowton, there are comments to address here.
|
I know, I'm currently working on resolving the remaining exception issues, which might subsume this in any event |
This is best merged after PR #912 which introduces the initial instrumentation for throwing runtime exceptions.