Skip to content

Commit 0153f8f

Browse files
committed
transpile: snapshots: add snapshot for #1024
this isn't how we want this code to be transpiled (it should use `wrapping_mul`), but it is how it transpiles now
1 parent c6cf1fd commit 0153f8f

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdint.h>
2+
#include <stdlib.h>
3+
4+
uint32_t cur_rand_seed = 0;
5+
6+
void set_rand_seed(uint32_t s) {
7+
cur_rand_seed = s;
8+
}
9+
10+
uint32_t get_rand_seed() {
11+
const uint32_t INCREMENT = 1;
12+
const uint32_t MULTIPLIER = 0x015A4E35;
13+
cur_rand_seed = MULTIPLIER * cur_rand_seed + INCREMENT;
14+
uint32_t ret = abs((int32_t)cur_rand_seed);
15+
return ret;
16+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![allow(
2+
dead_code,
3+
mutable_transmutes,
4+
non_camel_case_types,
5+
non_snake_case,
6+
non_upper_case_globals,
7+
unused_assignments,
8+
unused_mut
9+
)]
10+
extern "C" {
11+
fn abs(_: std::ffi::c_int) -> std::ffi::c_int;
12+
}
13+
pub type __int32_t = std::ffi::c_int;
14+
pub type __uint32_t = std::ffi::c_uint;
15+
pub type int32_t = __int32_t;
16+
pub type uint32_t = __uint32_t;
17+
#[no_mangle]
18+
pub static mut cur_rand_seed: uint32_t = 0 as std::ffi::c_int as uint32_t;
19+
#[no_mangle]
20+
pub unsafe extern "C" fn set_rand_seed(mut s: uint32_t) {
21+
cur_rand_seed = s;
22+
}
23+
#[no_mangle]
24+
pub unsafe extern "C" fn get_rand_seed() -> uint32_t {
25+
let INCREMENT: uint32_t = 1 as std::ffi::c_int as uint32_t;
26+
let MULTIPLIER: uint32_t = 0x15a4e35 as std::ffi::c_int as uint32_t;
27+
cur_rand_seed = (MULTIPLIER * cur_rand_seed).wrapping_add(INCREMENT);
28+
let mut ret: uint32_t = abs(cur_rand_seed as int32_t) as uint32_t;
29+
return ret;
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
source: c2rust-transpile/tests/snapshots.rs
3+
assertion_line: 80
4+
expression: cat tests/snapshots/rnd.rs
5+
input_file: c2rust-transpile/tests/snapshots/rnd.c
6+
---
7+
#![allow(
8+
dead_code,
9+
mutable_transmutes,
10+
non_camel_case_types,
11+
non_snake_case,
12+
non_upper_case_globals,
13+
unused_assignments,
14+
unused_mut
15+
)]
16+
extern "C" {
17+
fn abs(_: std::ffi::c_int) -> std::ffi::c_int;
18+
}
19+
pub type __int32_t = std::ffi::c_int;
20+
pub type __uint32_t = std::ffi::c_uint;
21+
pub type int32_t = __int32_t;
22+
pub type uint32_t = __uint32_t;
23+
#[no_mangle]
24+
pub static mut cur_rand_seed: uint32_t = 0 as std::ffi::c_int as uint32_t;
25+
#[no_mangle]
26+
pub unsafe extern "C" fn set_rand_seed(mut s: uint32_t) {
27+
cur_rand_seed = s;
28+
}
29+
#[no_mangle]
30+
pub unsafe extern "C" fn get_rand_seed() -> uint32_t {
31+
let INCREMENT: uint32_t = 1 as std::ffi::c_int as uint32_t;
32+
let MULTIPLIER: uint32_t = 0x15a4e35 as std::ffi::c_int as uint32_t;
33+
cur_rand_seed = (MULTIPLIER * cur_rand_seed).wrapping_add(INCREMENT);
34+
let mut ret: uint32_t = abs(cur_rand_seed as int32_t) as uint32_t;
35+
return ret;
36+
}
37+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
source: c2rust-transpile/tests/snapshots.rs
3+
assertion_line: 80
4+
expression: cat tests/snapshots/rnd.rs
5+
input_file: c2rust-transpile/tests/snapshots/rnd.c
6+
---
7+
#![allow(
8+
dead_code,
9+
mutable_transmutes,
10+
non_camel_case_types,
11+
non_snake_case,
12+
non_upper_case_globals,
13+
unused_assignments,
14+
unused_mut
15+
)]
16+
extern "C" {
17+
fn abs(_: std::ffi::c_int) -> std::ffi::c_int;
18+
}
19+
pub type int32_t = std::ffi::c_int;
20+
pub type uint32_t = std::ffi::c_uint;
21+
#[no_mangle]
22+
pub static mut cur_rand_seed: uint32_t = 0 as std::ffi::c_int as uint32_t;
23+
#[no_mangle]
24+
pub unsafe extern "C" fn set_rand_seed(mut s: uint32_t) {
25+
cur_rand_seed = s;
26+
}
27+
#[no_mangle]
28+
pub unsafe extern "C" fn get_rand_seed() -> uint32_t {
29+
let INCREMENT: uint32_t = 1 as std::ffi::c_int as uint32_t;
30+
let MULTIPLIER: uint32_t = 0x15a4e35 as std::ffi::c_int as uint32_t;
31+
cur_rand_seed = (MULTIPLIER * cur_rand_seed).wrapping_add(INCREMENT);
32+
let mut ret: uint32_t = abs(cur_rand_seed as int32_t) as uint32_t;
33+
return ret;
34+
}
35+

0 commit comments

Comments
 (0)