Skip to content

Commit 70ee732

Browse files
committed
transpile: Make volatile post-increment assignment compile
Fixes #1049. Fixes #1064.
1 parent c6610d5 commit 70ee732

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

c2rust-transpile/src/translator/operators.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ impl<'c> Translation<'c> {
797797
};
798798

799799
Ok(WithStmts::new(
800-
vec![save_old_val, mk().expr_stmt(assign_stmt)],
800+
vec![save_old_val, mk().semi_stmt(assign_stmt)],
801801
mk().ident_expr(val_name),
802802
))
803803
},

tests/ints/src/test_volatile.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
use crate::volatile::rust_entry3;
1+
use crate::volatile::{rust_entry3, rust_volatile_stuff};
22
use libc::{c_int, c_uint};
33

44
#[link(name = "test")]
55
extern "C" {
6+
fn volatile_stuff();
7+
68
fn entry3(_: c_uint, _: *mut c_int);
79
}
810

911
const BUFFER_SIZE: usize = 9;
1012

13+
pub fn test_compiles() {
14+
unsafe {
15+
volatile_stuff();
16+
rust_volatile_stuff();
17+
}
18+
}
19+
1120
pub fn test_buffer() {
1221
let mut buffer = [0; BUFFER_SIZE];
1322
let mut rust_buffer = [0; BUFFER_SIZE];

tests/ints/src/volatile.c

+19
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,23 @@ void entry3(const unsigned buffer_size, int buffer[])
4444
buffer[8] = s.buffer[3];
4545
}
4646

47+
void volatile_stuff(void)
48+
{
49+
// Non-volatile
50+
int x1 = 0;
51+
int x2 = x1++;
52+
x2;
53+
54+
// https://github.com/immunant/c2rust/issues/1049
55+
volatile int x3 = 0;
56+
int x4 = x3++;
57+
x4;
4758

59+
// https://github.com/immunant/c2rust/issues/1064
60+
volatile int x5 = 0;
61+
while (x5 < 5)
62+
{
63+
int x6 = x5++;
64+
x6;
65+
}
66+
}

0 commit comments

Comments
 (0)