cgen: fix for prev commit - get usecache working with clang (fix duplicate symbols)

pull/13501/head
Joe Conigliaro 2022-02-17 22:24:58 +11:00
parent 6fc654821f
commit 07b15a209a
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
1 changed files with 7 additions and 7 deletions

View File

@ -4305,11 +4305,10 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) {
// 'extern' was used to fix the duplicate symbols with usecache && clang
// visibility_kw := if g.pref.build_mode == .build_module && g.is_builtin_mod { 'static ' }
visibility_kw := if
(g.pref.use_cache || (g.pref.build_mode == .build_module && g.module_built != node.mod))
(g.pref.use_cache || (g.pref.build_mode == .build_module && g.module_built != node.mod))
&& !util.should_bundle_module(node.mod) {
'extern '
}
else {
} else {
''
}
mut attributes := ''
@ -4331,20 +4330,21 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) {
g.definitions.write_string('$visibility_kw$styp $attributes $field.name')
if field.has_expr {
if field.expr.is_literal() && should_init {
g.definitions.write_string(' = ${g.expr_string(field.expr)}; // global')
g.definitions.write_string(' = ${g.expr_string(field.expr)}')
} else {
g.global_init.writeln('\t$field.name = ${g.expr_string(field.expr)}; // global')
}
} else {
default_initializer := g.type_default(field.typ)
if default_initializer == '{0}' && should_init {
g.definitions.writeln(' = {0}; // global')
g.definitions.write_string(' = {0}')
} else {
if field.name !in ['as_cast_type_indexes', 'g_memory_block', 'global_allocator'] {
g.global_init.writeln('\t$field.name = *($styp*)&(($styp[]){${g.type_default(field.typ)}}[0]); // global')
}
}
}
g.definitions.writeln('; // global')
}
}