Skip to content

Commit

Permalink
transpile: Make volatile post-increment assignment compile
Browse files Browse the repository at this point in the history
Fixes #1064.
  • Loading branch information
GPHemsley committed Sep 21, 2024
1 parent 03b949c commit 131046e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion c2rust-transpile/src/translator/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ impl<'c> Translation<'c> {
};

Ok(WithStmts::new(
vec![save_old_val, mk().expr_stmt(assign_stmt)],
vec![save_old_val, mk().semi_stmt(assign_stmt)],
mk().ident_expr(val_name),
))
},
Expand Down
11 changes: 10 additions & 1 deletion tests/ints/src/test_volatile.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
use crate::volatile::rust_entry3;
use crate::volatile::{rust_entry3, rust_volatile_stuff};
use libc::{c_int, c_uint};

#[link(name = "test")]
extern "C" {
fn volatile_stuff();

fn entry3(_: c_uint, _: *mut c_int);
}

const BUFFER_SIZE: usize = 9;

pub fn test_compiles() {
unsafe {
volatile_stuff();
rust_volatile_stuff();
}
}

pub fn test_buffer() {
let mut buffer = [0; BUFFER_SIZE];
let mut rust_buffer = [0; BUFFER_SIZE];
Expand Down
7 changes: 6 additions & 1 deletion tests/ints/src/volatile.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ void entry3(const unsigned buffer_size, int buffer[])
buffer[8] = s.buffer[3];
}


void volatile_stuff(void)
{
volatile int x1 = 0;
int x2 = x1++;
x2;
}

0 comments on commit 131046e

Please sign in to comment.