Skip to content

Commit 871d3a5

Browse files
committed
MMIO rewriting must maintain type consistency
MMIO read functions may (have to) return values of varying types. Expression replacement must maintain, via type casts, consistency with whatever the type of the original expression was.
1 parent 79c1637 commit 871d3a5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

regression/cbmc/mm_io1/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int main()
1616
{
1717
long i=0x10;
1818
char *p=(char *)i;
19+
unsigned char u = *(unsigned char *)i;
1920
char some_var=100;
2021

2122
char z;

src/goto-programs/mm_io.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ void mm_io(
6262
source_locationt source_location = it->source_location();
6363
const code_typet &ct=to_code_type(mm_io_r.type());
6464

65-
if_exprt if_expr(integer_address(d.pointer()), mm_io_r_value, d);
65+
if_exprt if_expr(
66+
integer_address(d.pointer()),
67+
typecast_exprt::conditional_cast(mm_io_r_value, d.type()),
68+
d);
6669
replace_expr(d, if_expr, a_rhs);
6770

6871
const typet &pt=ct.parameters()[0].type();

0 commit comments

Comments
 (0)