Skip to content

Commit d0c85d0

Browse files
committed
transpile: add statement expression test to macros.c snapshot
1 parent d6aa4a6 commit d0c85d0

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

c2rust-transpile/tests/snapshots/macros.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ struct S {
3838
#define TERNARY LITERAL_BOOL ? 1 : 2
3939
#define MEMBER LITERAL_STRUCT.i
4040

41+
#define STMT_EXPR \
42+
({ \
43+
int builtin = BUILTIN; \
44+
char indexing = INDEXING; \
45+
float mixed = MIXED_ARITHMETIC; \
46+
for (int i = 0; i < builtin; i++) { \
47+
mixed += (float)indexing; \
48+
} \
49+
mixed; \
50+
})
51+
4152
void local_muts() {
4253
int literal_int = LITERAL_INT;
4354
bool literal_bool = LITERAL_BOOL;
@@ -72,6 +83,7 @@ void local_muts() {
7283
const struct S *ref_struct = REF_LITERAL;
7384
int ternary = TERNARY;
7485
int member = MEMBER;
86+
float stmt_expr = STMT_EXPR;
7587
}
7688

7789
void local_consts() {
@@ -108,6 +120,7 @@ void local_consts() {
108120
const struct S *const ref_struct = REF_LITERAL;
109121
const int ternary = TERNARY;
110122
const int member = MEMBER;
123+
const float stmt_expr = STMT_EXPR;
111124
}
112125

113126
// TODO These are declared in the global scope and thus clash,
@@ -147,6 +160,7 @@ void local_static_consts() {
147160
static const struct S *const ref_struct = REF_LITERAL;
148161
static const int ternary = TERNARY;
149162
static const int member = MEMBER;
163+
static const float stmt_expr = STMT_EXPR;
150164
}
151165
#endif
152166

@@ -187,6 +201,7 @@ static const char *const global_static_const_ref_indexing = REF_MACRO;
187201
static const struct S *const global_static_const_ref_struct = REF_LITERAL;
188202
static const int global_static_const_ternary = TERNARY;
189203
static const int global_static_const_member = MEMBER;
204+
// static const float global_static_const_stmt_expr = STMT_EXPR; // Statement expression not allowed at file scope.
190205

191206
void global_static_consts() {
192207
// Need to use `static`s or else they'll be removed when translated.
@@ -223,6 +238,7 @@ void global_static_consts() {
223238
(void)global_static_const_ref_struct;
224239
(void)global_static_const_ternary;
225240
(void)global_static_const_member;
241+
// (void)global_static_const_stmt_expr;
226242
}
227243

228244
// global consts
@@ -260,6 +276,7 @@ const char *const global_const_ref_indexing = REF_MACRO;
260276
const struct S *const global_const_ref_struct = REF_LITERAL;
261277
const int global_const_ternary = TERNARY;
262278
const int global_const_member = MEMBER;
279+
// const float global_const_stmt_expr = STMT_EXPR; // Statement expression not allowed at file scope.
263280

264281
typedef unsigned long long U64;
265282

c2rust-transpile/tests/snapshots/[email protected]

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ pub const PTR_ARITHMETIC: *const std::ffi::c_char = unsafe {
7070
};
7171
pub const WIDENING_CAST: std::ffi::c_int = unsafe { LITERAL_INT };
7272
pub const CONVERSION_CAST: std::ffi::c_int = unsafe { LITERAL_INT };
73+
pub const STMT_EXPR: std::ffi::c_float = unsafe {
74+
({
75+
let mut builtin: std::ffi::c_int = (LITERAL_INT as std::ffi::c_uint).leading_zeros() as i32;
76+
let mut indexing: std::ffi::c_char =
77+
(*::core::mem::transmute::<&[u8; 6], &[std::ffi::c_char; 6]>(b"hello\0"))
78+
[LITERAL_FLOAT as std::ffi::c_int as usize];
79+
let mut mixed: std::ffi::c_float =
80+
(LITERAL_INT as std::ffi::c_double + NESTED_FLOAT * LITERAL_CHAR as std::ffi::c_double
81+
- true_0 as std::ffi::c_double) as std::ffi::c_float;
82+
let mut i: std::ffi::c_int = 0 as std::ffi::c_int;
83+
while i < builtin {
84+
mixed += indexing as std::ffi::c_float;
85+
i += 1;
86+
i;
87+
}
88+
mixed
89+
})
90+
};
7391
#[no_mangle]
7492
pub unsafe extern "C" fn local_muts() {
7593
let mut literal_int: std::ffi::c_int = LITERAL_INT;
@@ -124,6 +142,7 @@ pub unsafe extern "C" fn local_muts() {
124142
2 as std::ffi::c_int
125143
};
126144
let mut member: std::ffi::c_int = LITERAL_STRUCT.i;
145+
let mut stmt_expr: std::ffi::c_float = STMT_EXPR;
127146
}
128147
#[no_mangle]
129148
pub unsafe extern "C" fn local_consts() {
@@ -179,6 +198,7 @@ pub unsafe extern "C" fn local_consts() {
179198
2 as std::ffi::c_int
180199
};
181200
let member: std::ffi::c_int = LITERAL_STRUCT.i;
201+
let stmt_expr: std::ffi::c_float = STMT_EXPR;
182202
}
183203
static mut global_static_const_literal_int: std::ffi::c_int = LITERAL_INT;
184204
static mut global_static_const_literal_bool: bool = LITERAL_BOOL != 0;

0 commit comments

Comments
 (0)