cgen: fix fixed arrays assignment in translated code

pull/13930/head
Alexander Medvednikov 2022-04-04 06:20:54 +03:00
parent a55e930c00
commit 719a3b5de3
1 changed files with 5 additions and 2 deletions

View File

@ -211,8 +211,9 @@ fn (mut g Gen) gen_assign_stmt(node_ ast.AssignStmt) {
g.expr(val) g.expr(val)
g.writeln(';}') g.writeln(';}')
} }
} else if node.op == .assign } else if node.op == .assign && !g.pref.translated
&& (is_fixed_array_init || (right_sym.kind == .array_fixed && val is ast.Ident)) { && (is_fixed_array_init || (right_sym.kind == .array_fixed && val is ast.Ident)) {
// Fixed arrays
mut v_var := '' mut v_var := ''
arr_typ := styp.trim('*') arr_typ := styp.trim('*')
if is_fixed_array_init { if is_fixed_array_init {
@ -402,7 +403,9 @@ fn (mut g Gen) gen_assign_stmt(node_ ast.AssignStmt) {
} }
g.is_shared = var_type.has_flag(.shared_f) g.is_shared = var_type.has_flag(.shared_f)
if !cloned { if !cloned {
if is_fixed_array_var { if is_fixed_array_var && !g.pref.translated {
// TODO Instead of the translated check, check if it's a pointer already
// and don't generate memcpy &
typ_str := g.typ(val_type).trim('*') typ_str := g.typ(val_type).trim('*')
ref_str := if val_type.is_ptr() { '' } else { '&' } ref_str := if val_type.is_ptr() { '' } else { '&' }
g.write('memcpy(($typ_str*)') g.write('memcpy(($typ_str*)')