-
Notifications
You must be signed in to change notification settings - Fork 109
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
Unreachable code detection #1385
base: master
Are you sure you want to change the base?
Unreachable code detection #1385
Conversation
…ure/jni-field-getter-setter
…o determine its signature
…er-without-signature Feature/jni field getter setter without signature
…e unecessary dispatch
That sounds like a bug in Viper, related to #1213. @Aurel300 once looked into that. Viper probably reports at most one error for each prusti-dev/prusti-viper/src/encoder/errors/position_manager.rs Lines 46 to 69 in c1d3447
|
Thanks for the info. I did not know the position's line/column can be any numbers. Did you mean I should change my code or the error_manager (I made a change in my code now)? BTW the issue would show up also when I have multiple refutes with the same line/column but none of them should fail - i.e. not some errors not being shown/triggered, but errors/warnings being triggered when they should not be. Although, I am not sure if this is not some edge case of the refute statement and how it is converted by the refute plugin. |
The error manager, because (1) the change in your code is harder to maintain and because (2) the change will probably fix #1213. |
The change to the error manager should fix that, right? |
Indeed :) Made a separate PR to separate the changes and keep it clean/simple to review. |
I uploaded the measured data (running times of the benchmark files) and the generated .vpr (with the unreachable code detection turned both on and off) to another branch into my repository - https://github.com/simon-hrabec/prusti-dev/tree/feature/unreachable-code-detection-measurements-and-vpr-data/dead-code-detection-measurements |
Description
This PR adds an optional flag
DETECT_UNREACHABLE_CODE
, which allows the user to detect code that cannot be reached.Implementation
The whole logic is based on adding refute false statements into basic blocks. Should the block be unreachable, the verification should fail. However, certain blocks are committed - an
assert
statement andunreachable!()
call generate code that we expect not to execute.However, there was an issue with locations/spans. Rust translates the code into more MIR basic blocks than a naive look would suggest. When creating an assert statement, a location/span needs to be provided. Multiple basic blocks can first statement that is registered for the same location. For some reason, when using the same location for multiple refute statements, the verification will fail on those statements. In such a case, the generated viper code/dump will verify without a problem. As a workaround, I use a HashSet to remember line/column (just remembering spans is not sufficient) to add only one refute statement referring to such position.
Performance analysis (benchmark running time - seconds)
Note: Knights_tour.rs had high variance - basically 8x 620 and 2x 2450.
dead-code-detection-measurements.zip
Note/Disclaimer
This flag works well when only one block is unreachable, however, in the current version, if the whole function is unreachable (i.g. contradictory preconditions), it will generate multiple warnings for different blocks.