Skip to content

Commit 5fe524d

Browse files
authored
cgen: fix bit-field generation for option/result types in minified st… (#26670)
* cgen: fix bit-field generation for option/result types in minified structs (fixes #26622) Option and result types are represented as structs in C, which cannot be used as bit-fields. Skip the bit-field optimization for these types in minified structs to avoid C compilation errors. Co-authored-by: iFlow CLI <iflow> (glm-5) * tests: skip minify_option_field test on MSVC MSVC handles bit-fields differently than GCC/Clang, causing the minify_option_field test to fail on Windows MSVC CI. - Add _not_msvc_windows.vv suffix pattern to skip logic - Rename test files to use the new suffix This follows the existing naming convention for platform/compiler- specific test handling (similar to _nix.vv, _msvc_windows.vv).
1 parent 5cfde2e commit 5fe524d

5 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎vlib/v/gen/c/coutput_test.v‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@ fn should_skip(relpath string) bool {
284284
return true
285285
}
286286
}
287+
$if msvc {
288+
if relpath.contains('_not_msvc_windows.vv') {
289+
eprintln('> skipping ${relpath} on msvc')
290+
return true
291+
}
292+
}
287293
} else {
288294
if relpath.contains('_windows.vv') {
289295
eprintln('> skipping ${relpath} on !windows')

‎vlib/v/gen/c/struct.v‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,8 @@ fn (mut g Gen) struct_decl(s ast.Struct, name string, is_anon bool, is_option bo
703703
field_name := c_name(field.name)
704704
volatile_prefix := if field.is_volatile { 'volatile ' } else { '' }
705705
mut size_suffix := ''
706-
if is_minify && !g.is_cc_msvc && !g.pref.output_cross_c {
706+
if is_minify && !g.is_cc_msvc && !g.pref.output_cross_c && !field.typ.has_flag(.option)
707+
&& !field.typ.has_flag(.result) {
707708
if field.typ == ast.bool_type_idx {
708709
size_suffix = ' : 1'
709710
} else {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
_option_bool optional;
2+
main__Status status : 2;
3+
_option_main__Priority priority;
4+
bool done : 1;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
active
2+
low
3+
false
4+
false
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Test that minified structs with option fields don't use bit-fields
2+
// Bit-fields can only have integral types in C, not struct types
3+
// Option types are represented as structs in C
4+
5+
module main
6+
7+
enum Status as u8 {
8+
pending
9+
active
10+
inactive
11+
}
12+
13+
enum Priority as u8 {
14+
low
15+
medium
16+
high
17+
}
18+
19+
@[minify]
20+
struct Task {
21+
status Status
22+
priority ?Priority
23+
done bool
24+
optional ?bool
25+
}
26+
27+
fn main() {
28+
task := Task{
29+
status: .active
30+
}
31+
println(task.status)
32+
println(task.priority or { Priority.low })
33+
println(task.done)
34+
println(task.optional or { false })
35+
}

0 commit comments

Comments
 (0)