Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgen: fix global struct init on tcc #22350

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -7352,6 +7352,11 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
} else {
'{'
}
$if windows {
if !typ.has_flag(.shared_f) && g.inside_global_decl {
init_str = '(${g.typ(typ)}){'
}
}
if sym.language in [.c, .v] {
for field in info.fields {
field_sym := g.table.sym(field.typ)
Expand Down
1 change: 1 addition & 0 deletions vlib/v/gen/c/testdata/global_initializer_windows.must_have
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Array_fixed_main__Foo_3 g_test_foo = {(main__Foo){.foo = 0,.bar = (main___VAnonStruct1){.a = 0,.b = 0,},}, (main__Foo){.foo = 0,.bar = (main___VAnonStruct1){.a = 0,.b = 0,},}, (main__Foo){.foo = 0,.bar = (main___VAnonStruct1){.a = 0,.b = 0,},}}; // global4
11 changes: 11 additions & 0 deletions vlib/v/gen/c/testdata/global_initializer_windows.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// vtest vflags: -enable-globals

struct Foo {
foo int
bar struct {
a int
b f64
}
}

__global g_test_foo = [3]Foo{}
23 changes: 23 additions & 0 deletions vlib/v/tests/global_init_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@[has_globals]
module main

interface IGameObject {
mut:
name string
}

struct Game {
mut:
objects []IGameObject
delete_objects []IGameObject
}

__global (
game Game
)

fn test_main() {
println('game: ${game}')
assert game.objects.len == 0
assert game.delete_objects.len == 0
}
Loading