You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Panic and abort should stop the program execution #543
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.// SPDX-License-Identifier: Apache-2.0 OR MIT//// rmc-verify-failpubfnmain(){for i in0..4{if i == 1{panic!("This comes first");}if i == 2{panic!("This should never happen");}}}
using the following command line invocation:
rmc loop.rs
I expected to see this happen: The first assertion should fail but the second one should be unreachable. The panic call should abort the execution in the second iteration of the loop.
Instead, this happened: Both assertions fail. The trace for the second assertion includes the first panic call.
Note that the same behavior happens if we replace the panic!() statement by process::abort().
** Results:
test.c function main
[main.assertion.1] line 5 assertion x < 3: FAILURE
[main.assertion.2] line 6 assertion x < 4: FAILURE
** 2 of 2 failed (2 iterations)
VERIFICATION FAILED
Perhaps we can add an option, e.g. --assert-fail-aborts that changes to the behavior you described? We can document that using this option could lead to missing assertion failures during stack unwinding.
I think we should always abort for user asserts, since that is the semantics of assert in rust. Note that if you add an assert!(false); or a panic statement, the rust compiler considers everything else that is dominated by that statement as dead code and removes it.
For debug_assert and other checks that we add, we should not abort since the code after the failure may still reachable during a release execution.
Activity
celinval commentedon Oct 12, 2021
An easy fix right now would be to condegen these failures as:
However, this is not actually sound since we are ignoring the unwind path. I created #545 to handle unwind logic.
zhassan-aws commentedon Nov 30, 2021
This is also how CBMC behaves. For example, for:
Both assertions fail:
Perhaps we can add an option, e.g.
--assert-fail-abortsthat changes to the behavior you described? We can document that using this option could lead to missing assertion failures during stack unwinding.celinval commentedon Dec 1, 2021
I think we should always abort for user asserts, since that is the semantics of assert in rust. Note that if you add an
assert!(false);or apanicstatement, the rust compiler considers everything else that is dominated by that statement as dead code and removes it.For debug_assert and other checks that we add, we should not abort since the code after the failure may still reachable during a release execution.
celinval commentedon Dec 1, 2021
Note that assertions in C have different semantics since they can be enabled / disabled according to the value of NDEBUG. https://en.cppreference.com/w/cpp/error/assert
Fix assert!() and panic!() code generation.
Fix assert!() and panic!() code generation (#687)