Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transpile: Make volatile post-increment assignment compile #1135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 19 additions & 0 deletions tests/ints/src/volatile.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,23 @@ void entry3(const unsigned buffer_size, int buffer[])
buffer[8] = s.buffer[3];
}

void volatile_stuff(void)
{
// Non-volatile
int x1 = 0;
int x2 = x1++;
x2;

// https://github.com/immunant/c2rust/issues/1049
volatile int x3 = 0;
int x4 = x3++;
x4;

// https://github.com/immunant/c2rust/issues/1064
volatile int x5 = 0;
while (x5 < 5)
{
int x6 = x5++;
x6;
}
}
Loading