Skip to content

Commit

Permalink
cgen: fix shared array fixed initializing with -cstrict (fix build …
Browse files Browse the repository at this point in the history
…of chip8-v project) (#23414)
  • Loading branch information
felipensp authored Jan 9, 2025
1 parent 0fd669d commit b0b08bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
22 changes: 14 additions & 8 deletions vlib/v/gen/c/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -498,15 +498,21 @@ fn (mut g Gen) zero_struct_field(field ast.StructField) bool {
g.write(g.type_default_sumtype(field.typ, sym))
return true
} else if sym.info is ast.ArrayFixed {
elem_is_option := sym.info.elem_type.has_flag(.option)
g.write('{')
for i in 0 .. sym.info.size {
if sym.info.elem_type.has_flag(.option) {
g.expr_with_opt(ast.None{}, ast.none_type, sym.info.elem_type)
} else {
g.write(g.type_default(sym.info.elem_type))
}
if i != sym.info.size - 1 {
g.write(', ')
if !elem_is_option && field.typ.has_flag(.shared_f) {
g.write('0')
} else {
default_str := g.type_default(sym.info.elem_type)
for i in 0 .. sym.info.size {
if elem_is_option {
g.gen_option_error(sym.info.elem_type, ast.None{})
} else {
g.write(default_str)
}
if i != sym.info.size - 1 {
g.write(', ')
}
}
}
g.write('}')
Expand Down
9 changes: 9 additions & 0 deletions vlib/v/tests/concurrency/shared_fixed_array_init_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct Foo {
mut:
bar shared [1024]bool
}

fn test_main() {
_ := Foo{}
assert true
}

0 comments on commit b0b08bc

Please sign in to comment.