Skip to content

Commit

Permalink
Avoid strict type comparison in statement assignment (#110)
Browse files Browse the repository at this point in the history
* Workaround for issue #95

* Print types in assert statement

Co-authored-by: Nathan Chong <ncchong@amazon.com>
  • Loading branch information
adpaco-aws and nchong-at-aws committed Aug 6, 2021
1 parent cb40235 commit 5d1a7ca
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion compiler/rustc_codegen_llvm/src/gotoc/cbmc/goto_program/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use self::StmtBody::*;
use super::{BuiltinFn, Expr, Location};
use std::fmt::Debug;
use tracing::debug;

///////////////////////////////////////////////////////////////////////////////////////////////
/// Datatypes
Expand Down Expand Up @@ -150,7 +151,27 @@ macro_rules! stmt {
impl Stmt {
/// `lhs = rhs;`
pub fn assign(lhs: Expr, rhs: Expr, loc: Location) -> Self {
assert_eq!(lhs.typ(), rhs.typ());
//Temporarily work around https://github.com/model-checking/rmc/issues/95
//by disabling the assert and soundly assigning nondet
//assert_eq!(lhs.typ(), rhs.typ());
if lhs.typ() != rhs.typ() {
debug!(
"WARNING: assign statement with unequal types lhs {:?} rhs {:?}",
lhs.typ(),
rhs.typ()
);
let assert_stmt = Stmt::assert_false(
&format!(
"Reached assignment statement with unequal types {:?} {:?}",
lhs.typ(),
rhs.typ()
),
loc.clone(),
);
let nondet_value = lhs.typ().nondet();
let nondet_assign_stmt = stmt!(Assign { lhs, rhs: nondet_value }, loc.clone());
return Stmt::block(vec![assert_stmt, nondet_assign_stmt]);
}
stmt!(Assign { lhs, rhs }, loc)
}

Expand Down

0 comments on commit 5d1a7ca

Please sign in to comment.