Skip to content
Merged
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 @@ -506,7 +506,7 @@ impl<'c> Translation<'c> {
) -> TranslationResult<Box<Expr>> {
let is_unsigned_integral_type = self
.ast_context
.index(ctype)
.resolve_type(ctype)
.kind
.is_unsigned_integral_type();

Expand Down
16 changes: 16 additions & 0 deletions c2rust-transpile/tests/snapshots/platform-specific/rnd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdint.h>
#include <stdlib.h>

uint32_t cur_rand_seed = 0;

void set_rand_seed(uint32_t s) {
cur_rand_seed = s;
}

uint32_t get_rand_seed() {
const uint32_t INCREMENT = 1;
const uint32_t MULTIPLIER = 0x015A4E35;
cur_rand_seed = MULTIPLIER * cur_rand_seed + INCREMENT;
uint32_t ret = abs((int32_t)cur_rand_seed);
return ret;
}
30 changes: 30 additions & 0 deletions c2rust-transpile/tests/snapshots/platform-specific/rnd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#![allow(
dead_code,
mutable_transmutes,
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
unused_assignments,
unused_mut
)]
extern "C" {
fn abs(_: std::ffi::c_int) -> std::ffi::c_int;
}
pub type __int32_t = std::ffi::c_int;
pub type __uint32_t = std::ffi::c_uint;
pub type int32_t = __int32_t;
pub type uint32_t = __uint32_t;
#[no_mangle]
pub static mut cur_rand_seed: uint32_t = 0 as std::ffi::c_int as uint32_t;
#[no_mangle]
pub unsafe extern "C" fn set_rand_seed(mut s: uint32_t) {
cur_rand_seed = s;
}
#[no_mangle]
pub unsafe extern "C" fn get_rand_seed() -> uint32_t {
let INCREMENT: uint32_t = 1 as std::ffi::c_int as uint32_t;
let MULTIPLIER: uint32_t = 0x15a4e35 as std::ffi::c_int as uint32_t;
cur_rand_seed = MULTIPLIER.wrapping_mul(cur_rand_seed).wrapping_add(INCREMENT);
let mut ret: uint32_t = abs(cur_rand_seed as int32_t) as uint32_t;
return ret;
}
37 changes: 37 additions & 0 deletions c2rust-transpile/tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
source: c2rust-transpile/tests/snapshots.rs
assertion_line: 80
expression: cat tests/snapshots/rnd.rs
input_file: c2rust-transpile/tests/snapshots/rnd.c
---
#![allow(
dead_code,
mutable_transmutes,
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
unused_assignments,
unused_mut
)]
extern "C" {
fn abs(_: std::ffi::c_int) -> std::ffi::c_int;
}
pub type __int32_t = std::ffi::c_int;
pub type __uint32_t = std::ffi::c_uint;
pub type int32_t = __int32_t;
pub type uint32_t = __uint32_t;
#[no_mangle]
pub static mut cur_rand_seed: uint32_t = 0 as std::ffi::c_int as uint32_t;
#[no_mangle]
pub unsafe extern "C" fn set_rand_seed(mut s: uint32_t) {
cur_rand_seed = s;
}
#[no_mangle]
pub unsafe extern "C" fn get_rand_seed() -> uint32_t {
let INCREMENT: uint32_t = 1 as std::ffi::c_int as uint32_t;
let MULTIPLIER: uint32_t = 0x15a4e35 as std::ffi::c_int as uint32_t;
cur_rand_seed = MULTIPLIER.wrapping_mul(cur_rand_seed).wrapping_add(INCREMENT);
let mut ret: uint32_t = abs(cur_rand_seed as int32_t) as uint32_t;
return ret;
}

35 changes: 35 additions & 0 deletions c2rust-transpile/tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
source: c2rust-transpile/tests/snapshots.rs
assertion_line: 80
expression: cat tests/snapshots/rnd.rs
input_file: c2rust-transpile/tests/snapshots/rnd.c
---
#![allow(
dead_code,
mutable_transmutes,
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
unused_assignments,
unused_mut
)]
extern "C" {
fn abs(_: std::ffi::c_int) -> std::ffi::c_int;
}
pub type int32_t = std::ffi::c_int;
pub type uint32_t = std::ffi::c_uint;
#[no_mangle]
pub static mut cur_rand_seed: uint32_t = 0 as std::ffi::c_int as uint32_t;
#[no_mangle]
pub unsafe extern "C" fn set_rand_seed(mut s: uint32_t) {
cur_rand_seed = s;
}
#[no_mangle]
pub unsafe extern "C" fn get_rand_seed() -> uint32_t {
let INCREMENT: uint32_t = 1 as std::ffi::c_int as uint32_t;
let MULTIPLIER: uint32_t = 0x15a4e35 as std::ffi::c_int as uint32_t;
cur_rand_seed = MULTIPLIER.wrapping_mul(cur_rand_seed).wrapping_add(INCREMENT);
let mut ret: uint32_t = abs(cur_rand_seed as int32_t) as uint32_t;
return ret;
}