@@ -1991,30 +1991,42 @@ impl<'tcx> GotocCtx<'tcx> {
1991
1991
let x = fargs. remove ( 0 ) ;
1992
1992
let y = fargs. remove ( 0 ) ;
1993
1993
1994
- // if(same_object(x, y)) {
1995
- // assert(x + 1 <= y || y + 1 <= x);
1996
- // assume(x + 1 <= y || y + 1 <= x);
1997
- // }
1998
- let one = Expr :: int_constant ( 1 , Type :: c_int ( ) ) ;
1999
- let non_overlapping =
2000
- x. clone ( ) . plus ( one. clone ( ) ) . le ( y. clone ( ) ) . or ( y. clone ( ) . plus ( one. clone ( ) ) . le ( x. clone ( ) ) ) ;
2001
- let non_overlapping_check = self . codegen_assert_assume (
2002
- non_overlapping,
2003
- PropertyClass :: SafetyCheck ,
2004
- "memory regions pointed to by `x` and `y` must not overlap" ,
2005
- loc,
2006
- ) ;
2007
- let non_overlapping_stmt =
2008
- Stmt :: if_then_else ( x. clone ( ) . same_object ( y. clone ( ) ) , non_overlapping_check, None , loc) ;
2009
-
2010
- // T t = *y; *y = *x; *x = t;
2011
1994
let deref_y = y. clone ( ) . dereference ( ) ;
2012
- let ( temp_var, assign_to_t) =
2013
- self . decl_temp_variable ( deref_y. typ ( ) . clone ( ) , Some ( deref_y) , loc) ;
2014
- let assign_to_y = y. dereference ( ) . assign ( x. clone ( ) . dereference ( ) , loc) ;
2015
- let assign_to_x = x. dereference ( ) . assign ( temp_var, loc) ;
1995
+ if deref_y. typ ( ) . sizeof ( & self . symbol_table ) == 0 {
1996
+ // do not attempt to dereference (and assign) a ZST
1997
+ Stmt :: skip ( loc)
1998
+ } else {
1999
+ // if(same_object(x, y)) {
2000
+ // assert(x + 1 <= y || y + 1 <= x);
2001
+ // assume(x + 1 <= y || y + 1 <= x);
2002
+ // }
2003
+ let one = Expr :: int_constant ( 1 , Type :: c_int ( ) ) ;
2004
+ let non_overlapping = x
2005
+ . clone ( )
2006
+ . plus ( one. clone ( ) )
2007
+ . le ( y. clone ( ) )
2008
+ . or ( y. clone ( ) . plus ( one. clone ( ) ) . le ( x. clone ( ) ) ) ;
2009
+ let non_overlapping_check = self . codegen_assert_assume (
2010
+ non_overlapping,
2011
+ PropertyClass :: SafetyCheck ,
2012
+ "memory regions pointed to by `x` and `y` must not overlap" ,
2013
+ loc,
2014
+ ) ;
2015
+ let non_overlapping_stmt = Stmt :: if_then_else (
2016
+ x. clone ( ) . same_object ( y. clone ( ) ) ,
2017
+ non_overlapping_check,
2018
+ None ,
2019
+ loc,
2020
+ ) ;
2021
+
2022
+ // T t = *y; *y = *x; *x = t;
2023
+ let ( temp_var, assign_to_t) =
2024
+ self . decl_temp_variable ( deref_y. typ ( ) . clone ( ) , Some ( deref_y) , loc) ;
2025
+ let assign_to_y = y. dereference ( ) . assign ( x. clone ( ) . dereference ( ) , loc) ;
2026
+ let assign_to_x = x. dereference ( ) . assign ( temp_var, loc) ;
2016
2027
2017
- Stmt :: block ( vec ! [ non_overlapping_stmt, assign_to_t, assign_to_y, assign_to_x] , loc)
2028
+ Stmt :: block ( vec ! [ non_overlapping_stmt, assign_to_t, assign_to_y, assign_to_x] , loc)
2029
+ }
2018
2030
}
2019
2031
}
2020
2032
0 commit comments