Skip to content

Commit 3e8fb60

Browse files
adpaco-awsnchong-at-aws
authored andcommitted
Avoid strict type comparison in statement assignment (rust-lang#110)
* Workaround for issue rust-lang#95 * Print types in assert statement Co-authored-by: Nathan Chong <ncchong@amazon.com>
1 parent 6e03039 commit 3e8fb60

File tree

1 file changed

+22
-1
lines changed
  • compiler/rustc_codegen_llvm/src/gotoc/cbmc/goto_program

1 file changed

+22
-1
lines changed

compiler/rustc_codegen_llvm/src/gotoc/cbmc/goto_program/stmt.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use self::StmtBody::*;
44
use super::{BuiltinFn, Expr, Location};
55
use std::fmt::Debug;
6+
use tracing::debug;
67

78
///////////////////////////////////////////////////////////////////////////////////////////////
89
/// Datatypes
@@ -150,7 +151,27 @@ macro_rules! stmt {
150151
impl Stmt {
151152
/// `lhs = rhs;`
152153
pub fn assign(lhs: Expr, rhs: Expr, loc: Location) -> Self {
153-
assert_eq!(lhs.typ(), rhs.typ());
154+
//Temporarily work around https://github.com/model-checking/rmc/issues/95
155+
//by disabling the assert and soundly assigning nondet
156+
//assert_eq!(lhs.typ(), rhs.typ());
157+
if lhs.typ() != rhs.typ() {
158+
debug!(
159+
"WARNING: assign statement with unequal types lhs {:?} rhs {:?}",
160+
lhs.typ(),
161+
rhs.typ()
162+
);
163+
let assert_stmt = Stmt::assert_false(
164+
&format!(
165+
"Reached assignment statement with unequal types {:?} {:?}",
166+
lhs.typ(),
167+
rhs.typ()
168+
),
169+
loc.clone(),
170+
);
171+
let nondet_value = lhs.typ().nondet();
172+
let nondet_assign_stmt = stmt!(Assign { lhs, rhs: nondet_value }, loc.clone());
173+
return Stmt::block(vec![assert_stmt, nondet_assign_stmt]);
174+
}
154175
stmt!(Assign { lhs, rhs }, loc)
155176
}
156177

0 commit comments

Comments
 (0)