Throw ArithmeticException whenever a division-by-zero is encountered#950
Throw ArithmeticException whenever a division-by-zero is encountered#950cristina-david wants to merge 2 commits intodiffblue:test-gen-supportfrom
Conversation
f6f4064 to
f74e4ba
Compare
There was a problem hiding this comment.
Sure this shouldn't have some class type?
There was a problem hiding this comment.
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.
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.
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.
Suspect object-factory needs replacing with a real constructor
There was a problem hiding this comment.
Factor with java_bytecode_convert_classt::generate_class_stub?
There was a problem hiding this comment.
Should we really nondet init it rather than calling a particular constructor?
There was a problem hiding this comment.
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.
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.
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.
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.
@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.