cgen: fix global struct init on tcc (fix #22300) (#22350)

This commit is contained in:
Felipe Pena 2024-09-30 23:03:51 -03:00 committed by GitHub
parent ce95787215
commit 1b812f6bdf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 40 additions and 0 deletions

View file

@ -7353,6 +7353,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)

View file

@ -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

View file

@ -0,0 +1,11 @@
// vtest vflags: -enable-globals
struct Foo {
foo int
bar struct {
a int
b f64
}
}
__global g_test_foo = [3]Foo{}

View file

@ -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
}