generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 141
Closed
Labels
[C] BugThis is a bug. Something isn't working.This is a bug. Something isn't working.
Description
RMC is giving the wrong code location of assert!(false) statements.
I tried this code:
fn magic() -> i32 { // L1
5 // L2
} // L3
// L4
pub fn main() { // L5
if magic() == 5 { // L6
assert!(false); // L7
} // L8
println!("Magic!"); // L9
} // L10using the following command line invocation:
rmc --input dummy.rs
with RMC version:
The following output is printed:
[main.assertion.1] line 6 assertion failed: false: FAILURE
Note that the MIR is correct:
> rustc dummy.rs --emit mir
> grep panic dummy.mir
core::panicking::panic(const "assertion failed: false"); // scope 0 at dummy.rs:7:9: 7:24
Root cause:
The assert!() macro is translated to if !cond { begin_panic; }. However, for assert!(false), rustc optimizes the generated code and it only emit a panic statement.
During RMC code generation of panic statements, we assume that if the basic block only has one predecessor, it is an assertion. There are many cases that this is not true. See this code.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
[C] BugThis is a bug. Something isn't working.This is a bug. Something isn't working.