1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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

This commit is contained in:
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

View File

@ -4301,15 +4301,14 @@ fn (mut g Gen) const_decl_init_later(mod string, name string, expr ast.Expr, typ
} }
fn (mut g Gen) global_decl(node ast.GlobalDecl) { fn (mut g Gen) global_decl(node ast.GlobalDecl) {
// was static used here to to make code optimizable? it was removed when // was static used here to to make code optimizable? it was removed when
// 'extern' was used to fix the duplicate symbols with usecache && clang // '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.build_mode == .build_module && g.is_builtin_mod { 'static ' }
visibility_kw := if 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) { && !util.should_bundle_module(node.mod) {
'extern ' 'extern '
} } else {
else {
'' ''
} }
mut attributes := '' 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') g.definitions.write_string('$visibility_kw$styp $attributes $field.name')
if field.has_expr { if field.has_expr {
if field.expr.is_literal() && should_init { 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 { } else {
g.global_init.writeln('\t$field.name = ${g.expr_string(field.expr)}; // global') g.global_init.writeln('\t$field.name = ${g.expr_string(field.expr)}; // global')
} }
} else { } else {
default_initializer := g.type_default(field.typ) default_initializer := g.type_default(field.typ)
if default_initializer == '{0}' && should_init { if default_initializer == '{0}' && should_init {
g.definitions.writeln(' = {0}; // global') g.definitions.write_string(' = {0}')
} else { } else {
if field.name !in ['as_cast_type_indexes', 'g_memory_block', 'global_allocator'] { 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.global_init.writeln('\t$field.name = *($styp*)&(($styp[]){${g.type_default(field.typ)}}[0]); // global')
} }
} }
} }
g.definitions.writeln('; // global')
} }
} }