|
| 1 | +--- |
| 2 | +source: c2rust-transpile/tests/snapshots.rs |
| 3 | +expression: cat tests/snapshots/exprs.rs |
| 4 | +input_file: c2rust-transpile/tests/snapshots/exprs.c |
| 5 | +--- |
| 6 | +#![allow( |
| 7 | + dead_code, |
| 8 | + mutable_transmutes, |
| 9 | + non_camel_case_types, |
| 10 | + non_snake_case, |
| 11 | + non_upper_case_globals, |
| 12 | + unused_assignments, |
| 13 | + unused_mut |
| 14 | +)] |
| 15 | +extern "C" { |
| 16 | + fn puts(str: *const std::ffi::c_char) -> std::ffi::c_int; |
| 17 | +} |
| 18 | +unsafe extern "C" fn side_effect() -> std::ffi::c_int { |
| 19 | + puts(b"the return of side effect\0" as *const u8 as *const std::ffi::c_char); |
| 20 | + return 10 as std::ffi::c_int; |
| 21 | +} |
| 22 | +#[no_mangle] |
| 23 | +pub unsafe extern "C" fn unary_without_side_effect() { |
| 24 | + let mut i: std::ffi::c_int = 5 as std::ffi::c_int; |
| 25 | + -i; |
| 26 | + i; |
| 27 | + !i; |
| 28 | + (i == 0) as std::ffi::c_int; |
| 29 | + &mut i; |
| 30 | + i; |
| 31 | + i += 1; |
| 32 | + i; |
| 33 | + i -= 1; |
| 34 | + i; |
| 35 | + i -= 1; |
| 36 | + i; |
| 37 | + i += 1; |
| 38 | + i; |
| 39 | +} |
| 40 | +#[no_mangle] |
| 41 | +pub unsafe extern "C" fn unary_with_side_effect() { |
| 42 | + let mut arr: [*mut std::ffi::c_char; 1] = [0 as *mut std::ffi::c_char]; |
| 43 | + -side_effect(); |
| 44 | + side_effect(); |
| 45 | + !side_effect(); |
| 46 | + (side_effect() == 0) as std::ffi::c_int; |
| 47 | + &*(b"\0" as *const u8 as *const std::ffi::c_char).offset(::core::mem::transmute::< |
| 48 | + unsafe extern "C" fn() -> std::ffi::c_int, |
| 49 | + unsafe extern "C" fn() -> std::ffi::c_int, |
| 50 | + >(side_effect)() as isize) as *const std::ffi::c_char; |
| 51 | + *arr[side_effect() as usize]; |
| 52 | + arr[side_effect() as usize] = (arr[side_effect() as usize]).offset(1); |
| 53 | + arr[side_effect() as usize]; |
| 54 | + arr[side_effect() as usize] = (arr[side_effect() as usize]).offset(-1); |
| 55 | + arr[side_effect() as usize]; |
| 56 | + arr[side_effect() as usize] = (arr[side_effect() as usize]).offset(1); |
| 57 | + arr[side_effect() as usize]; |
| 58 | + arr[side_effect() as usize] = (arr[side_effect() as usize]).offset(-1); |
| 59 | + arr[side_effect() as usize]; |
| 60 | +} |
0 commit comments