Skip to content

Commit 131046e

Browse files
committed
transpile: Make volatile post-increment assignment compile
Fixes #1064.
1 parent 03b949c commit 131046e

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
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

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

47-
47+
void volatile_stuff(void)
48+
{
49+
volatile int x1 = 0;
50+
int x2 = x1++;
51+
x2;
52+
}

0 commit comments

Comments
 (0)